#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int L[5], R[5];

double doit(int price, int mask, int idx, int n) {
  double ret = price;
  if (idx >= 0) {
    int low = max(price + 1, L[idx]);
    int high = R[idx];
    if (low > high) return 0.0;
    ret *= high - low + 1;
  }
  for (int i = 0; i < n; ++i) {
    if (i == idx || (mask & (1 << i))) continue;
    int high = min(R[i], price - 1);
    int low = L[i];
    if (high < low) return 0.0;
    ret *= high - low + 1;
  }
  // cout << price << " " << mask << " " << idx << " " << ret << endl;
  return ret;
}

int main() {
  int n;
  cin >> n;
  double total = 1.0;
  for (int i = 0; i < n; ++i) {
    cin >> L[i] >> R[i];
    total *= R[i] - L[i] + 1;
  }
  double sum = 0.0;
  // the subset of second price companies
  for (int mask = 1; mask < (1 << n); ++mask) {
    // cout << "mask: " << mask << endl;
    vector<int> A;
    for (int i = 0; i < n; ++i) {
      if (mask & (1 << i)) A.push_back(i);
    }
    int minR = R[A[0]], maxL = L[A[0]];
    for (auto& idx : A) {
      minR = min(minR, R[idx]);
      maxL = max(maxL, L[idx]);
    }
    if (maxL > minR) continue;
    // enumerate the first price > second price
    for (int i = 0; i < n; ++i) {
      if (mask & (1 << i)) continue;
      for (int k = maxL; k <= minR; ++k) {
        sum += doit(k, mask, i, n);
      }
    }
    // first price = second price
    if (A.size() > 1) {
      for (int k = maxL; k <= minR; ++k) {
        sum += doit(k, mask, -1, n);
      }
    }
  }
  sum /= total;
  printf("%.10f\n", sum);
  return 0;
}


#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include "bitset"
#include "cmath"
#include "list"
#include "complex"
#include <cassert>
#include "deque"
#include "numeric"

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define mp make_pair
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int sze = 3e5 + 50, oo = 1e18 + 500, mod = 1000000007;
const double eps = 5e-10, PI = 2 * acos(0.0);
vi vertices[sze];
vc visit(sze * 10, false);
vi arr(sze, 0);
int n, m, k;
int cnt = 0;
int s, t;

//int ptr[sze], d[sze];
//
//struct edge
//{
//	int from, to, cap, flow;
//};
//
//vector<edge> e;
//
//void add_edge(int u, int v, int w)
//{
//	edge e1{ u, v, w, 0 };
//	edge e2{ v, u, 0, 0 };
//
//	vertices[u].pb(e.size());
//	e.pb(e1);
//	vertices[v].pb(e.size());
//	e.pb(e2);
//}
//
//bool bfs()
//{
//	queue<int> q;
//	q.push(s);
//	fill(d, d + n + 10, -1);
//	d[s] = 0;
//
//	while (!q.empty() && d[t] == -1)
//	{
//		int v = q.front();
//		q.pop();
//
//		for (auto id : vertices[v])
//		{
//			int to = e[id].to;
//			if (d[to] == -1 && e[id].cap > e[id].flow)
//			{
//				q.push(to);
//				d[to] = d[v] + 1;
//			}
//		}
//	}
//}
//
//int dfs(int v, int flow)
//{
//	if (v == t) return flow;
//	if (!flow) return 0;
//
//	for (; ptr[v] < vertices[v].size(); ptr[v] ++)
//	{
//		int id = vertices[v][ptr[v]];
//		int to = e[id].to;
//
//		if (d[to] != d[v] + 1) continue;
//
//		int pushed = dfs(to, min(flow, e[id].cap - e[id].flow));
//
//		if (pushed)
//		{
//			e[id].flow += pushed;
//			e[id ^ 1].flow -= pushed;
//			return pushed;
//		}
//	}
//
//	return 0;
//}
//
//int dinic()
//{
//	int flow = 0;
//	while (bfs())
//	{
//		while (int pushed = dfs(s, oo))
//			flow += pushed;
//	}
//
//	return flow;
//}

int dp[110][2];

int solve(int idx, int prev)
{
	if (idx == n)
		return 0;

	if (dp[idx][prev] != -1)
		return dp[idx][prev];

	if (prev == 1 && arr[idx] == 0)
	{
		return dp[idx][prev] = 1 + solve(idx + 1, 1);
	}
	else
	{
		return dp[idx][prev] = min(1 + solve(idx + 1, prev), solve(idx + 1, arr[idx]));
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}

	wmemset(dp, -1, sizeof(dp));
	cout << n - solve(0, 0);
	return 0;
}


//#define ONLINE_JUDGE

#if defined(ONLINE_JUDGE)
#define _SECURE_SCL 0
#endif

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <functional>
#include <memory>
#include <cmath>
#include <climits>
#include <numeric>
#include <tuple>
#include <memory.h>
#include <stdint.h>

#if !defined(__GNUC__)
#else // !defined(__GNUC__)
#define _CrtDbgBreak() __builtin_trap()
#endif // !defined(__GNUC__)

#if defined(ONLINE_JUDGE)
#define LOCAL_TEST 0
#else
#define LOCAL_TEST 1
#endif

#if LOCAL_TEST
struct AssertsCounter
{
	AssertsCounter(): counter(0) {}
	~AssertsCounter() { std::cerr << std::endl << "DIAG: " << (counter == 0 ? "OK" : "FAIL!!!") << " Asserts count: " << counter << std::endl; }
	void Increment() { counter++; }
	uint32_t counter;
};
AssertsCounter g_assertsCounter;
#define LOCAL_ASSERT(expr) { if (!(expr)) {std::cerr << "ASSERT FAILED (" << __LINE__ << "): '" << #expr << "'" << std::endl; g_assertsCounter.Increment(); _CrtDbgBreak(); } }
#define LOCAL_ASSERT_EQ(expr1, expr2) { if ((expr1) != (expr2)) {std::cerr << "ASSERT FAILED (" << __LINE__ << "): '" << #expr1 << "' == '" << #expr2 << "' (" << (expr1) << " vs " << (expr2) << "')" << std::endl; g_assertsCounter.Increment(); _CrtDbgBreak(); } }
#else
volatile bool isLocalTestEnabled = 0;
#define LOCAL_ASSERT(expr)
#define LOCAL_ASSERT_EQ(expr1, expr2)
#endif

bool g_isLocalPrintEnabled = (bool)(LOCAL_TEST);
#define LOCAL_PRINT() if (!g_isLocalPrintEnabled) { } else std::cerr // << .. << ..

typedef std::string string8_t;
typedef long double ld_t;

typedef std::vector<size_t> vector_size_t;
typedef std::vector<uint8_t> vector_uint8_t;
typedef std::vector<int32_t> vector_int32_t;
typedef std::vector<uint32_t> vector_uint32_t;
typedef std::vector<int64_t> vector_int64_t;
typedef std::vector<uint64_t> vector_uint64_t;
typedef std::vector<string8_t> vector_string8_t;

typedef std::vector<vector_size_t> vector_2d_size_t;
typedef std::vector<vector_int32_t> vector_2d_int32_t;
typedef std::vector<vector_uint32_t> vector_2d_uint32_t;
typedef std::vector<vector_int64_t> vector_2d_int64_t;
typedef std::vector<vector_uint64_t> vector_2d_uint64_t;

typedef std::set<size_t> set_size_t;
typedef std::set<int32_t> set_int32_t;
typedef std::set<uint32_t> set_uint32_t;
typedef std::set<int64_t> set_int64_t;
typedef std::set<uint64_t> set_uint64_t;
typedef std::set<string8_t> set_string8_t;

typedef std::multiset<size_t> multiset_size_t;
typedef std::multiset<string8_t> multiset_string8_t;

// Auxiliary functions definition
//
template<typename T> void UpdateMin(T& a, const T b) {a = std::min(a, b);}
template<typename T> void UpdateMax(T& a, const T b) {a = std::max(a, b);}

const ld_t Pi = std::atan(1.0L) * 4.0L;
static const ld_t Eps = 1.0e-09;
template<typename T> bool IsEqual(const T a, const T b) { return std::abs(a - b) < Eps; }
template<typename T> bool IsGreater(const T a, const T b) { return a > b + Eps; }
template<typename T> bool IsLess(const T a, const T b) { return a + Eps < b; }
template<typename T> bool IsGreaterEqual(const T a, const T b) { return !IsLess(a, b); }
template<typename T> bool IsLessEqual(const T a, const T b) { return !IsGreater(a, b); }

template<typename T> string8_t ToStr(const T& val) { std::ostringstream ostr; ostr << val; return ostr.str(); }
template<typename T> bool FromStr(const string8_t& str, T& val) {std::istringstream istr(str); istr >> val; return !!istr; }
template<typename T> T FromStr(const string8_t& str) {T val = {}; std::istringstream istr(str); istr >> val; return val; }

uint64_t SafeAdd(uint64_t a, uint64_t b) { uint64_t M = std::numeric_limits<uint64_t>::max(); return a <= M - b ? a + b : M; }
uint64_t SafeMul(uint64_t a, uint64_t b) { uint64_t M = std::numeric_limits<uint64_t>::max(); return a <= M / b ? a * b : M; }

template<typename T> std::istream& operator>>(std::istream& ist, std::vector<T>& data)
{
	LOCAL_ASSERT(!!ist);
	for (size_t i = 0; i < data.size(); i++) { ist >> data[i]; }
	return ist;
}

template<typename T> T Read(std::istream& ist)
{
	LOCAL_ASSERT(!!ist);
	T val; ist >> val; return val;
}

template<typename T> std::ostream& operator<<(std::ostream& ost, const std::vector<T>& data)
{
	for (size_t i = 0; i < data.size(); i++) { if (i != 0) { ost << ' '; } ost << data[i]; }
	return ost;
}

#if defined(ONLINE_JUDGE)
template<size_t id> class StopWatch { };
#else
#include <library/lib_stopwatch.h>
#include <library/lib_random.h>
library::random::Rand g_rnd;
#endif

const uint64_t Mod = 1000000007;

uint64_t FindGcd(const uint64_t& a0, const uint64_t& b0)
{
	uint64_t a = a0;
	uint64_t b = b0;

	if (a < b)
		std::swap(a, b);

	if (b == 0)
		return a;

	do
	{
		if (a < b)
			std::swap(a, b);
		a = a % b;
	}
	while(a != 0);

	return b;
}

// returns:
// m == 0 -> pow(a, p)
// m != 0 -> pow(a, p) % m
static uint64_t FastPow(const uint64_t& a, const uint64_t& p)
{
	const uint64_t m = Mod;

	uint64_t res = 1;

	uint64_t mask = 1;
	uint64_t powPart = a;

	const size_t bitsCount = sizeof(uint64_t) * 8;
	for (size_t i = 0; i < bitsCount; i++)
	{
		if (p & mask)
		{
			res *= powPart;
			res %= m;
		}
		mask <<= 1;
		powPart *= powPart;
		powPart %= m;
	}

	return res;
}

uint64_t ReverseElementByPrimeModule(const uint64_t& a)
{
	const uint64_t m = Mod;
	LOCAL_ASSERT(a != 0);
	return FastPow(a, m - 2);
}

struct Fraction
{
	Fraction(const uint64_t p, const uint64_t q): p(p), q(q) { }
	Fraction(): p(0), q(1) { }

	uint64_t GetAsOneValue() const
	{
		uint64_t z = p;
		z *= ReverseElementByPrimeModule(q);
		z %= Mod;
		return z;
	}

	uint64_t p;
	uint64_t q;
};

void Normalize(uint64_t& num, uint64_t& den)
{
	num %= Mod;
	den %= Mod;

	uint64_t gc = FindGcd(num, den);
	gc %= Mod;

	const uint64_t rgc = ReverseElementByPrimeModule(gc);

	num *= rgc;
	num %= Mod;

	den *= rgc;
	den %= Mod;
}

Fraction Construct(const uint64_t p1, const uint64_t p2)
{
	uint64_t num = p1;
	uint64_t den = p2;
	Normalize(num, den);
	return Fraction(num, den);
}

Fraction Mult(const Fraction& f1, const Fraction& f2)
{
	uint64_t num = f1.p * f2.p;
	uint64_t den = f1.q * f2.q;
	Normalize(num, den);
	return Fraction(num, den);
}

Fraction Mult(const Fraction& f1, const uint64_t& v)
{
	uint64_t num = f1.p * v;
	uint64_t den = f1.q;
	Normalize(num, den);
	return Fraction(num, den);
}

Fraction Divide(const Fraction& f1, const Fraction& f2)
{
	uint64_t num = f1.p * f2.q;
	uint64_t den = f1.q * f2.p;
	Normalize(num, den);
	return Fraction(num, den);
}

Fraction Plus(const Fraction& f1, const Fraction& f2)
{
	uint64_t num = f1.p * f2.q + f2.p * f1.q;
	uint64_t den = f1.q * f2.q;
	Normalize(num, den);
	return Fraction(num, den);
}

Fraction Minus(const Fraction& f1, const Fraction& f2)
{
	uint64_t num = (f1.p * f2.q) % Mod + Mod - (f2.p * f1.q) % Mod;
	uint64_t den = f1.q * f2.q;
	Normalize(num, den);
	return Fraction(num, den);
}

struct State
{
	State(uint64_t ca, uint64_t cab): ca(ca), cab(cab) { }
	State(): ca(0), cab(0) { }

	uint64_t ca;
	uint64_t cab;

	bool operator<(const State& rv) const
	{
		return std::tie(ca, cab) < std::tie(rv.ca, rv.cab);
	}
};

typedef std::map<State, Fraction> States;

Fraction GetAns(const uint64_t k, const uint64_t pa, const uint64_t pb)
{
	const Fraction One = Construct(1, 1);

	Fraction ans = Fraction(0, 1);

	States states;
	states[State(1, 0)] = Fraction(1, 1);

	const Fraction pfa = Construct(pa, pa + pb);
	const Fraction pfb = Construct(pb, pa + pb);

#if LOCAL_TEST
	size_t maxStates = 0;
	size_t iterations = 0;
#endif

	while (!states.empty())
	{
#if LOCAL_TEST
		if (maxStates < states.size())
		{
			maxStates = states.size();
		}
		iterations++;
#endif

		States t;

		for (States::const_iterator ps = states.begin(); ps != states.end(); ++ps)
		{
			const State& s = ps->first;
			const Fraction& p = ps->second;

			if (s.cab >= k)
			{
				const Fraction d = Mult(p, k);
				ans = Plus(ans, d);
				continue;
			}

			if (s.ca + s.cab >= k)
			{
				const Fraction fc = Construct(s.ca, 1);
				const Fraction fpc = Mult(fc, pfa);
				const Fraction num = Plus(pfa, Minus(fc, fpc));
				const Fraction den = Minus(One, pfa);
				const Fraction sum = Divide(num, den);
				const Fraction fcab = Construct(s.cab, 1);
				Fraction d = Plus(fcab, sum);
				d = Mult(d, p);
				ans = Plus(ans, d);
				continue;
			}

			const State s1(s.ca + 1, s.cab);
			const State s2(s.ca, s.cab + s.ca);
			const Fraction p1 = Mult(p, pfa);
			const Fraction p2 = Mult(p, pfb);

			t[s1] = Plus(t[s1], p1);
			t[s2] = Plus(t[s2], p2);
		}

		states.swap(t);
	}

	LOCAL_PRINT() << "Iterations: " << iterations << std::endl;
	LOCAL_PRINT() << "Max states: " << maxStates << std::endl;

	return ans;
}

bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
	StopWatch<1> sw; (void)sw;

	//
	size_t k;
	ist >> k;

	uint64_t pa, pb;
	ist >> pa >> pb;

	if (multipleTestMode && !ist)
		return false;

	//
	LOCAL_PRINT() << std::endl << "Next test: k = " << k << std::endl;

	const Fraction ans = GetAns(k, pa, pb);
	const uint64_t v = ans.GetAsOneValue();
	ost << v << std::endl;

	return multipleTestMode;
}

#if LOCAL_TEST
void Test()
{
	using namespace library::random;
	//const auto genVector = GenFactory::CreateGenVector(GenRange<size_t>(2, 10), GenRange<int32_t>(-100, +200));

	for (size_t t = 0; t < 10; t++)
	{
		//const vector_int32_t data = genVector();
		//size_t ans = GetAns(data);
		//size_t ref = GetAnsRef(data);
		//LOCAL_ASSERT_EQ(ref, ans);
	}
}
#endif

void RunSolve(std::istream& ist, std::ostream& ost)
{
#if !defined(ONLINE_JUDGE)
	while(Solve(ist, ost, true)) {};
#else
    Solve(ist, ost, false);
#endif
}

int main(int argc, const char *argv[])
{
#if !defined(ONLINE_JUDGE)
	Test();
#endif

    std::ios_base::sync_with_stdio(false);
	if (argc > 1)
	{
		std::ifstream ifs(argv[1]);
		if (!ifs)
		{
			std::cout << "File not found: " << argv[1] << std::endl;
			return 1;
		}
		RunSolve(ifs, std::cout);
		return 0;
	}

	RunSolve(std::cin, std::cout);
}


#include <cstdio>
typedef long long ll;
using namespace std;

ll l, r, u, d;
ll n, x, y, c;

ll sqr(ll x) //Esta funcion se usa para obtener el area del cuadrado que estamos viendo
{
    return x * x;
}

ll tri(ll x) //Esta es para encontrar el area de los triangulos que se forman por la naturaleza del problema
{
    return (x + 1) * x / 2;
}

bool solve(ll t)
{

    ll sum = t * t + (t + 1) * (t + 1);
    if (t > l) sum -= sqr(t - l);
    if (t > r) sum -= sqr(t - r);
    if (t > u) sum -= sqr(t - u);
    if (t > d) sum -= sqr(t - d);
    if (t > l + d) sum += tri(t - (l + d) - 1);
    if (t > l + u) sum += tri(t - (l + u) - 1);
    if (t > r + d) sum += tri(t - (r + d) - 1);
    if (t > r + u) sum += tri(t - (r + u) - 1);
    if (sum >= c) return true;
    return false;
}

int main()
{
    scanf("%I64d%I64d%I64d%I64d", &n, &x, &y, &c))

    l = x - 1, r = n - x;
    u = y - 1, d = n - y;
    ll low = 0, high = 2 * n, mid;
    while (low <= high)
    {
        mid = (low + high) / 2;
        if (solve(mid)) high = mid - 1;
        else low = mid + 1;
    }
    printf("%I64d\n", low);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using pairll = pair<ll, ll>;
using vvll = vector<vll>;
using vint = vector<int>;
using pint = pair<int, int>;
using vvint = vector<vint>;

#define mod 1000000007
#define inf 1000000000000009

int n,k, num;
vint cnt;
vector<bool> good;

void reset(){
    cout << 'R' << endl;
}
bool check(int a){
    string s;
    cout << "? " << a << endl;
    cin >> s;
    return s == "Y";
}

int check(int x, int y, int c, int d){
    int a = x*k;
    int tmp = 0;
    a += c*(k/2);
    int b = y*k;
    b += d*(k/2);
    int num = 0;
    string s;
    for(int i = a; i < a+k/2; i++){
        if(good[i]){
            cout << "? " << i+1 << endl;
            cin >> s;
        }
    }
    for(int i = b; i < b+k/2; i++){
        if(good[i]){
            cout << "? " << i+1 << endl;
            cin >> s;
            tmp = s == "Y";
            num += tmp;
            if(tmp == 1){
                good[i] = 0;
            }
        }
    }
    cout << 'R' << endl;
    return num;
}

int main(){
    cin >> n >> k;
    if(k==1){
        k = 2;
    }
    if(n == 1){
        cout << "! 1" << endl;
        return 0;
    }
    good.resize(n, 1);
    good.assign(n, 1);
    num = n;
    int tmp;
    for(int i = 0; i < n; i++){
        tmp = check(i+1);
        if(tmp == 1){
            good[j] = 0;
        }
        num -= tmp;
    }
    for(int i = 0; i < n/k; i++){
        for(int j = i+1; j < n/k; j++){
            num -= check(i, j, 0, 0);
            num -= check(i, j, 1, 0);
            num -= check(i, j, 0, 1);
            num -= check(i, j, 1, 1);
        }
    }
    cout << "! " << num << endl;

}


#include <iostream>

using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout << ( b + a - 1) * c + a << endl;

    system("pause");
    }


#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
using namespace std;

int main ()
{
	int a1,a2;
	int i,j;
	char digits[100];
	char * str;
	cin>>a1>>a2;
	str = itoa(a2,digits,10);
    int len = strlen(str);
     int res = 0;
    for (i = 0;i<len;i++)
	{
       res+=(str[i]-'0')*(int)pow(10,i);
	}
	cout<<res+a1;
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
    long log int n,m;
    cin>>n>>m;
    if(m==1)
    cout<<(n-1)<<"\n";
    else
    cout<<(m-1) * n<<"\n";
}


#include <cstring>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <time.h>

using namespace std;

#define FAST_IO ios::sync_with_stdio(false)
#define sci(d) scanf("%d", &d)
#define scs(s) scanf("%s", &s)

#define SINF 20000000
#define INF 2000000000
#define LLINF 900000000000000000LL
#define X first
#define Y second
#define MAX 1001
#define MOD 1000000007LL
#define endl "\n"
#define ALL(a) (a).begin(), (a).end()
#define pr(n) operator[](n);

typedef long long ll;
typedef pair<int, int> pi;

int Q, N, M, K, L;
ll FAN[100001];
int p[100001];
ll v[100001];

struct comp {
	bool operator() (const int& a, const int& b) const {
		if (v[a] != v[b]) return v[a] < v[b];
		return a < b;
	}
};

set<int, comp> children[100001];
int deg[100001];
multiset<ll> mulset;

ll value_for_self(int a) {
	return FAN[a] - (1 + deg[a]) * value_for_other(a);
}
ll value_for_other(int a) {
	return FAN[a] / (2 + deg[a]);
}

int main() {
	FAST_IO;
	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> FAN[i];
	for (int i = 0; i < N; i++) {
		cin >> p[i]; p[i]--;
		children[p[i]].insert(i);
		deg[p[i]]++;
	}
	for (int i = 0; i < N; i++) {
		v[i] += value_for_self(i);
		for (int child : children[i])
			v[i] += value_for_other(child);
	}
	for (int i = 0; i < N; i++) {
		children[p[i]].erase(i);
		children[p[i]].insert(i);
	}
	for (int i = 0; i < N; i++) {
		if (children[i].empty()) continue;
		mulset.insert(v[*children[i].begin()] + value_for_other(i));
		mulset.insert(v[*children[i].rbegin()] + value_for_other(i));
	}
	for (int q = 0; q < M; q++) {
		int a, b, c;
		cin >> a;
		if (a == 1) {
			cin >> b >> c;
			b--; c--;

			set<int> go = { b, c, p[b], p[c], p[p[b]] };
			set<int> go2 = go;
			for (int n : go) go2.insert(p[n]);

			for (int i : go2) {
				if (children[i].empty()) continue;
				mulset.erase(v[*children[i].begin()] + value_for_other(i));
				mulset.erase(v[*children[i].rbegin()] + value_for_other(i));
			}
			for (int rep = -1; rep <= 1; rep += 2) { // first -1, then 1
				for (int x : go) {
					v[x] += rep * value_for_self(x);
					for (int y : go)
						if (p[y] == x)
							v[x] += rep * value_for_other(y);
				}

				if (rep == -1) {
					deg[p[a]]--;
					p[a] = b;
					deg[p[a]]++;
				}

			}
			for (int n : go)
				children[p[n]].insert(n);

			for (int n : go2) {
				if (!deg[n]) continue;
				ll pv = value_for_other(n);
				mulset.insert(v[*children[n].begin()] + pv);
				mulset.insert(v[*children[n].rbegin()] + pv);
			}
		}
		if (a == 2) {
			cin >> b;
			b--;
			cout << v[b] + value_for_other(p[b]) << endl;
		}
		if (a == 3) {
			cout << *mulset.begin() << " " << *mulset.rbegin() << endl;
		}
	}
	cin >> N;
}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;

	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

#define int ll
int n;
const int MAXN=100001;
vector<int> adj[MAXN];
int dp[MAXN][2];
int st[MAXN];
vector<int> children[MAXN];
vector<array<int,2>> dp2_g[MAXN];
vector<array<array<int,3>,2>> dp2_par[MAXN];
void dfs(int x) {
	st[x]=1;
	vector<int>& lst=children[x];
	for(auto i:adj[x]) {
		if(!st[i]) {
			lst.pb(i);
			dfs(i);
		}
	}

	if(lst.empty()) {
		dp[x][0]=0;
		dp[x][1]=1LL<<46;
		return ;
	}

	vector<array<int,2>>& dp2=dp2_g[x];
	vector<array<array<int,3>,2>>& par=dp2_par[x];
	dp2.resize(lst.size());
	par.resize(lst.size());

	dp2[0][0]=dp[lst[0]][1];
	par[0][0]={-1,1,0};

	dp2[0][1]=min(dp[lst[0]][1],dp[lst[0]][0])+2;
	par[0][1]={-1,dp[lst[0]][1]<dp[lst[0]][0],1};

	//~ if(x==2) LOG(dp2[0][1]);

	for(int i=1;i<sz(lst);++i) {
		dp2[i][0]=dp2[i-1][0]+dp[lst[i]][1];
		par[i][0]={0,1,0};
		dp2[i][1]=dp2[i-1][0]+min(dp[lst[i]][1],dp[lst[i]][0])+2;
		par[i][1]={0,dp[lst[i]][1]<dp[lst[i]][0],1};

		if(dp2[i][1]>dp2[i-1][1]+dp[lst[i]][1]) {
			dp2[i][1]=dp2[i-1][1]+dp[lst[i]][1];
			par[i][1]={1,1,0};
		}
		//~ if(x==5) LOG(dp2[i-1][1]+min(dp[lst[i]][0],dp[lst[i]][1])+2);
		if(dp2[i][1]>dp2[i-1][1]+min(dp[lst[i]][0],dp[lst[i]][1])+2) {
			dp2[i][1]=dp2[i-1][1]+min(dp[lst[i]][0],dp[lst[i]][1])+2;
			par[i][1]={1,dp[lst[i]][1]<dp[lst[i]][0],1};
		}

	}
	//~ if(x==5) {
		//~ LOG(dp2[1][1]);
	//~ }
	dp[x][0]=dp2.back()[0];
	dp[x][1]=dp2.back()[1];

	st[x]=2;
}

int perm[MAXN];
void reconstruct(int x, int y) {
	if(children[x].empty()) return ;
	//~ LOG(x);
	//~ LOG(y);
	//vector<array<int,2>>& dp2=dp2_g[x];
	vector<array<array<int,3>,2>>& par=dp2_par[x];
	pair<int,int> state={sz(children[x])-1,y};
	for(int j=sz(children[x])-1;j>=0;j--) {
		//~ LOG(x);

		//~ LOG(j);
		//~ LOG(state.yy);
		//~ LOG(par[j][state.yy][0]);
		//~ LOG(par[j][state.yy][1]);
		//~ LOG(par[j][state.yy][2]);
		//~ LOG(x);
		//~ LOG(state.yy);
		//~ LOG(j);
		if(par[state.xx][state.yy][2]) {
			swap(perm[children[x][j]], perm[x]);
		}
		reconstruct(children[x][j], par[state.xx][state.yy][1]);
		state.yy=par[state.xx][state.yy][0];
		state.xx--;
	}
}

#ifdef LOCAL
int dst[101][101];
#endif

main() {
	IO;
	#ifdef LOCAL
	for(auto&i:dst) for(auto&j:i) j=1e9;
	#endif

	cin>>n;
	for(int i=1;i<n;++i) {
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
		#ifdef LOCAL
		dst[a][b]=1;
		dst[b][a]=1;
		dst[i][i]=0;
		dst[i+1][i+1]=0;
		#endif
	}

	#ifdef LOCAL
	for(int j=1;j<=n;++j) {
		for(int i=1;i<=n;++i) {
			for(int k=1;k<=n;++k) {
				if(dst[i][j]+dst[j][k]<dst[i][k]) {
					dst[i][k]=dst[i][j]+dst[j][k];
				}
			}
		}
	}
	#endif

	for(int i=1;i<=n;++i) perm[i]=i;

	dfs(1);
	cout<<dp[1][1]<<"\n";
	//~ for(int i=1;i<=n;++i) {
		//~ cerr<<dp[i][0]<<" "<<dp[i][1]<<"\n";
	//~ }
	//~ LOG(dp[2][0]);
	reconstruct(1,1);
	bool valid=true;
	int sum=0;
	for(int i=1;i<=n;++i) {
		valid&=perm[i]!=i;
		sum+=dst[i][perm[i]];
	}

	valid&=dp[1][1]==sum;
	for(int i=1;i<=n;++i) cout<<perm[i]<<" \n"[i==n];
	cout.flush();
	assert(valid);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

bool validarCubo(const vi& cubetmp){
	int cnt=1;
	int cols;
	for(int i=0;i<6;++i){
		int col = cubetmp[cnt];
		cols+= ( cubetmp[cnt+1]==col && cubetmp[cnt+2]==col && cubetmp[cnt+3]==col);
		cnt+=4;
	}
	//cout << (cols==6) << endl;
	return cols==6;
}

void girar(vi& cubetmp, const vi& f, bool ang){

	if(ang==90)
		for(int i=0;i<7;i+=2){
			swap(cubetmp[f[i]],cubetmp[f[i+2]]);
			swap(cubetmp[f[i+1]],cubetmp[f[i+3]]);
		}
	else
		for(int i=7;i>1;i-=2){
			swap(cubetmp[f[i]],cubetmp[f[i-2]]);
			swap(cubetmp[f[i-1]],cubetmp[f[i-3]]);
		}
}

int main(){

	for(int i=1;i<=24;++i){
		cin >> cube[i];
	}

	int c0[]={13,14,5,6,17,18,21,22};
	int c1[]={3,4,17,19,10,9,16,14};
	int c2[]={15,16,7,8,19,20,23,24};
	int c3[]={1,3,5,7,9,11,24,22};
	int c4[]={2,4,6,8,10,12,23,21};
	int c5[]={18,20,12,11,15,13,1,2};

	bool solve = false;

	//cout << "cube c0" << endl;
 	vi vc0(c0,c0+8);
 	vi cubetmpc0(cube,cube+30);
	girar(cubetmpc0,vc0,90);
	solve |= validarCubo(cubetmpc0);
	cubetmpc0.assign(cube,cube+30);
	girar(cubetmpc0,vc0,-90);
 	solve |= validarCubo(cubetmpc0);

	//cout << "cube c2" << endl;
 	vi vc1(c1,c1+8);
 	vi cubetmpc1(cube,cube+30);
	girar(cubetmpc1,vc1,90);
	solve |= validarCubo(cubetmpc1);
	cubetmpc1.assign(cube,cube+30);
	girar(cubetmpc1,vc1,-90);
 	solve |= validarCubo(cubetmpc1);

	//cout << "cube c2" << endl;
 	vi vc2(c2,c2+8);
 	vi cubetmpc2(cube,cube+30);
	girar(cubetmpc2,vc2,90);
	solve |= validarCubo(cubetmpc2);
	cubetmpc2.assign(cube,cube+30);
	girar(cubetmpc2,vc2,-90);
 	solve |= validarCubo(cubetmpc2);

	//cout << "cube c3" << endl;
 	vi vc3(c3,c3+8);
 	vi cubetmpc3(cube,cube+30);
	girar(cubetmpc3,vc3,90);
	solve |= validarCubo(cubetmpc3);
	cubetmpc3.assign(cube,cube+30);
	girar(cubetmpc3,vc3,-90);
 	solve |= validarCubo(cubetmpc3);

	//cout << "cube c4" << endl;
 	vi vc4(c4,c4+8);
 	vi cubetmpc4(cube,cube+30);
	girar(cubetmpc4,vc4,90);
	solve |= validarCubo(cubetmpc4);
	cubetmpc4.assign(cube,cube+30);
	girar(cubetmpc4,vc4,-90);
 	solve |= validarCubo(cubetmpc4);

	//cout << "cube c5" << endl;
 	vi vc5(c5,c5+8);
 	vi cubetmpc5(cube,cube+30);
	girar(cubetmpc5,vc5,90);
	solve |= validarCubo(cubetmpc5);
	cubetmpc5.assign(cube,cube+30);
	girar(cubetmpc5,vc5,-90);
 	solve |= validarCubo(cubetmpc5);

 	cout << (solve? "YES":"NO") << endl;

	return 0;
}


/*
 * 2011-08-29  Martin  <Martin@Martin-desktop>

 *
 */
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdarg>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <exception>
#include <stdexcept>
#include <memory>
#include <locale>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <functional>
#include <string>
#include <complex>
#include <valarray>

using namespace std;

template <class T> inline T checkmin(T &a, T b)
{
	return (a < b) ? a : a = b;
}

template <class T> inline T checkmax(T &a, T b)
{
	return (a > b) ? a : a = b;
}

template <class T> T GCD(T a, T b)
{
	if (a < 0)
		return GCD(- a, b);
	if (b < 0)
		return GCD(a, - b);
	return (a == 0) ? b : GCD(b % a, a);
}

template <class T> T LCM(T a, T b)
{
	if (a < 0)
		return LCM(- a, b);
	if (b < 0)
		return LCM(a, - b);
	return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;
}

#define tr(i, x) for (typeof(x.begin()) i = x.begin(); i != x.end(); ++ i)
#define rep(i, n) for (int i = 0; i < n; ++ i)
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define ll long long

namespace Poor
{
	int A, L, Ans;

	int Count(uint n)
	{
		if (n < 10)
			return (n == 4 || n == 7);
		return Count(n / 10) + Count(n % 10);
	}

	inline bool Check(uint X, uint Y, int L)
	{
		rep (i, 50)
		{
			int l = rand() % L;
			if (Count(X + l) != Count(Y + l))
				return 0;
			if (i < L && Count(X + i) != Count(Y + i))
				return 0;
			if (i < L && Count(X + L - i - 1) != Count(Y + L - i - 1))
				return 0;
			if ((ll) i * 99 < L && Count(X + i * 99) != Count(Y + i * 99))
				return 0;
			if ((ll) i * 9999 < L && Count(X + i * 9999) != Count(Y + i * 9999))
				return 0;
			if ((ll) i * 999999 < L && Count(X + i * 999999) != Count(Y + i * 999999))
				return 0;
			if ((ll) i * 99999999 < L && Count(X + i * 99999999) != Count(Y + i * 99999999))
				return 0;
		}
		return 1;
	}

	bool Tried(int X, int Y, int pw)
	{
		int Tmp = Count(X) - Count(Y);
		for (int i = 1; i < L && X + i < pw && Y + i < pw; ++ i)
			if (Count(X + i) - Count(Y + i) != Tmp)
				return 0;
		int Start = min(pw - X, pw - Y);
		Tmp = Count(X + Start) - Count(Y + Start);
		for (int i = Start + 1; i < L && (X + i < pw || Y + i < pw); ++ i)
			if (Count(X + i) - Count(Y + i) != Tmp)
				return 0;
		Start = max(pw - X, pw - Y);
		Tmp = Count(X + Start) - Count(Y + Start);
		for (int i = Start + 1; i < L && X + i < pw * 2 && Y + i < pw * 2; ++ i)
			if (Count(X + i) - Count(Y + i) != Tmp)
				return 0;
		return 1;
	}

	int Log(int x)
	{
		int res = 0;
		while (x > 1)
		{
			x /= 10;
			++ res;
		}
		return res;
	}

	void DFS(int v, int c, int pw)
	{
		//~ cerr << v << " " << c << endl;
		if (c < 0)
			return;
		if (v < Ans)
		{
			if (c == 0)
			{
				if (A < v && Check(A, v, L))
					Ans = v;
				if (pw == 1000000000 && A < v + pw && v + pw < Ans && Check(A, v + pw, L))
					Ans = v + pw;
			}
			if (pw == 1000000000)
				return;
			if (Log(1000000000 / pw) < c)
				return;
			if (pw <= 1000 && !Tried(A % pw, v, pw))
				return;
			DFS(v + pw * 4, c - 1, pw * 10);
			DFS(v + pw * 7, c - 1, pw * 10);
			rep (i, 10)
				if (i != 4 && i != 7)
					DFS(v + pw * i, c, pw * 10);
		}
	}

	void Run()
	{
		srand(time(NULL));
		cin >> A >> L;
		Ans = A + 1000000000;
		int c = Count(A);
		for (int i = 0; i < 10; ++ i)
			DFS(i, c - Count(i), 10);
		cout << Ans << endl;
	}
}

int main()
{
	Poor::Run();
}


#include<bits/stdc++.h>

using namespace std;

#define int long long

const int kMaxN = 250 + 5;
const int Mod = 1000000007;

int n , k , ans , power_k1[kMaxN * kMaxN] , power_k2[kMaxN * kMaxN] , C[kMaxN][kMaxN];

inline int read(){
	int s = 0 , w = 1;
	char ch = getchar();
	while((ch < '0') || (ch > '9')){
		if(ch == '-'){
			w = -1;
		}
		ch = getchar();
    }
   	while((ch >= '0') && (ch <= '9')){
   		s = (s << 3) + (s << 1) + ch - '0';
		ch = getchar();
	}
   	return s * w;
}

inline void write(int x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9){
    	write(x / 10);
	}
    putchar(x % 10 + '0');
    return ;
}

signed main(){

	n = read();
	k = read();

	power_k1[0] = 1;
	power_k2[0] = 1;

	for(int i = 1 ; i <= n * n ; i++ ){
        power_k1[i] = power_k1[i - 1] * k % Mod;
        power_k2[i] = power_k2[i - 1] * (k - 1) % Mod;
    }

    C[0][0] = 1;

    for(int i = 1 ; i <= n ; i++ ){
        for(int j = 1 ; j <= i ; j++ ){
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % Mod;
        }
    }

    for(int i = 0 ; i <= n ; i++ ){
        for(int j = 0 ; j <= n ; j++ )[
            int num = i * n + j * n - i * j;
            if((i + j) & 1 == 1){
                ans -= (power_k2[num] * power_k1[n * n - num] % Mod * C[n][i] % Mod * C[n][j]) % Mod;
            }
            else{
                ans += (power_k2[num] * power_k1[n * n - num] % Mod * C[n][i] % Mod * C[n][j]) % Mod;
            }
        }
    }

    cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

typedef long long LL;
typedef double DB;

#define sf scanf
#define pf printf
#define mp make_pair
#define nl printf("\n")

#define FOR(i,a,b) for(i = a; i <= b; ++i)
#define FORD(i,a,b) for(i = a; i >= b; --i)
#define FORS(i,n) for(i = 0; i < n; ++i)
#define FORM(i,n) for(i = n - 1; i >= 0; --i)
#define reset(i,n) memset(i, n, sizeof(i))
#define open freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define close fclose(stdin); fclose(stdout)

using namespace std;

const LL mod = 1e9 + 7;
const LL INF = 4e18;
const int inf = 2e9;
const int N = 2e5;

int gcd(int a, int b) { return b? gcd(b, a%b): a; }
int lcm(int a, int b) { return a/ gcd(a, b)*b; }

vector<int> enemy[N + 5];
pair<int,int> will[N + 5];

int main(void)
{
    int n, k, i, j;
    sf("%d %d", &n, &k);
    int need = n - k + 1;
    if(need == 0) {
        puts("0");
        return 0;
    }
    FORS(i, n) {
        int p, e;
        sf("%d %d", &p, &e);
        enemy[p].push_back(e);
        will[i] = mp(e, p);
    }
    FOR(i, 0, N) if(enemy[i].size()) {
        sort(enemy[i].begin(), enemy[i].end());
    }
    sort(will, will + n);
    int point = 1, loser = enemy[0].size() + enemy[1].size();
    int obv = 0;
    while(loser < need) {
        point++;
        loser += enemy[point].size();
        if(point >= 2) obv += enemy[point-2].size();
    }
    if(point > n) {
        puts("-1");
        return 0;
    }
    bool awal = 1;
    LL ans = INF;
    for(; loser <= n; point++) {
        if(!awal) {
            loser += enemy[point].size();
            if(point >= 2) obv += enemy[point-2].size();
        }
        awal = 0;
        int from = need - obv;
        if(enemy[point].size() + enemy[point-1].size() < from) continue;
        int a = 0, b = 0;
        LL cur = 0;
        //cout << from << endl;
        FORS(i, from) {
            int lef = (a < enemy[point-1].size()? enemy[point-1][a] : inf);
            int rig = (b < enemy[point].size()? enemy[point][b] : inf);
            if(lef < rig) cur += lef, a++;
            else cur += rig, b++;
        }
        if(from < 0) from = 0;
        int udah = 0;
        //pf("a b : %d %d\n", a, b);
        for(i = 0; udah < point - from; i++) {
            int id = will[i].second;
            int cost = will[i].first;
            if(id == point - 1 && a) {
                a--;
                continue;
            }
            if(id == point && b) {
                b--;
                continue;
            }
            udah++;
            cur += cost;
        }
        //pf("haha %d %I64d\n", point, cur);
        ans = min(ans, cur);
        if(obv >= need) break;
    }
    cout << (ans == INF? -1 : ans) << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int LLI;
typedef pair<int,int> PII;

#define _ ios_base::sync_with_stdio(0);
#define debug
#define x first
#define y second
#define MXN 100005

const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;

int w[MXN];

int main() { _
    int n;
    while (cin >> n) {
        for (int i = 0; i < 2*n; ++i) cin >> w[i];
        sort(w, w+2n);
        int mn = 0, cur = 0;
        for (int i = 1; i < 2*n-1; ++i) mn = w[i+1] - w[i];
        for (int i = 0; i < n; ++i) {
            cur = 0;
            for (int j = 0; j < n; ++j) {
                if (i == j) continue;
                cur += w[2*j+1] - w[2*j];
            }
            mn = min(cur, mn);
        }
        cout << mn << "\n";
    }

    return 0;
}


#ifndef LOCAL
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>

using namespace std;
#define sim template <class c
#define mor > muu & operator<<(
#define ris return *this
#define R22(r) sim>typename enable_if<1 r sizeof(dud<c>(0)),muu&>::type operator<<(c g) {
sim>
struct rge {
    c b, e;
};

sim> rge<c> range(c i, c j) { return rge<c>{i, j}; }

sim> auto dud(c *r) -> decltype(cerr << *r);

sim> char dud(...);

struct muu {
#ifdef LOCAL
    stringstream a;

    ~muu() { cerr << a.str() << endl; }

    R22(<) a << boolalpha << g;
        ris; }

    R22(==) ris << range(begin(g), end(g)); }

    sim mor rge<c> u) {
        a << "[";
        for (c i = u.b; i != u.e; ++i)
            *this << ", " + 2 * (i == u.b) << *i;
        ris << "]";
    }

    sim, class m mor pair<m, c> r) { ris << "(" << r.first << ", " << r.second << ")"; }

#else
    sim mor const c&){ris;}
#endif
};

#define debug muu() << __FUNCTION__ << "#" << __LINE__ << ": "
#define imie(r...) "[" #r ": " << (r) << "] "
#define range(a, b) "[[" #a ", " #b "): " << range(a, b) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
using pii = pair<int, int>;
using ld = long double;
using ll = long long;

const int MAXN = 2027;

ll dp1[MAXN][MAXN];
ll dp2[2][MAXN][MAXN];

int N;
int K;
int wyn3 = 0;

void adam(int n, int m, vector<int> &wziete) {
    vector<int> curr = wziete;
    vector<int> nowy;
    bool spoczko = !wziete.empty();
    for (int i = 1; i < K; i++) {
        int suma = 0;
        for (int n = 0; n < curr.size(); n++) {
            for (int w = 0; w < curr[n]; w++) {
                nowy.push_back(n + 1);
                suma += n + 1;
            }
            if (suma > N) {
                spoczko = false;
                break;
            }
        }
        if (!spoczko)
            break;
        reverse(nowy.begin(), nowy.end());
        curr = move(nowy);
    }
    if (spoczko)
        wyn3++;
    for (int i = min(n, m); i >= 1; i--) {
        wziete.push_back(i);
        adam(n - i, i, wziete);
        wziete.pop_back();
    }
}

int main() {
    const int mod = 998244353;
    scanf("%d%d", &N, &K);
    if (K == 1) {
        for (int i = 0; i <= N; i++)
            dp1[0][i] = 1;
        ll wyn = 0;
        for (int sum = 1; sum <= N; sum++) {
            for (int x = 1; x <= sum; x++) {
                dp1[sum][x] = dp1[sum][x - 1] + dp1[sum - x][x];
                dp1[sum][x] %= mod;
            }
            for (int x = sum + 1; x <= N; x++)
                dp1[sum][x] = dp1[sum][x - 1];
            wyn += dp1[sum][N];
            wyn %= mod;
        }
        printf("%lld", wyn);
    } else if (K == 2) {
        int curr = 0;
        for (int i = 0; i <= N; i++)
            dp2[curr][0][i] = 1;
        ll wyn = 0;
        for (int n = 1; n <= 64; n++) {
            curr = !curr;
            for (int sum = 1; sum <= N; sum++) {
                for (int x = N; x >= 1; x--) {
                    if (sum - x * n >= 0)
                        dp2[curr][sum][x] = dp2[!curr][sum - x * n][x];
                    else
                        dp2[curr][sum][x] = 0;
                    dp2[curr][sum][x] %= mod;
                    wyn += dp2[curr][sum][x];
                    wyn %= mod;
                    dp2[curr][sum][x] += dp2[curr][sum][x + 1];
                }
                debug << imie(n) imie(sum);
                debug << range(dp2[curr][sum] + 1, dp2[curr][sum] + N + 1);
            }
            for (int x = 0; x <= N; x++)
                dp2[curr][0][x] = 0;
        }
        printf("%lld", wyn);
    } else {
        vector<int> wziete;
        int maxi = (int) sqrt(2 * N);
        adam(maxi, maxi, wziete);
        printf("%d", wyn3);
    }
    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
#define ld long double

using namespace std;
const int N = 2e5;
int pi[N], a[N];

inline void solve()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        int l, r;
        cin >> l >> r;
        l--;
        pi[l]++;
        pi[r]--;
    }
    int now = 0;
    for(int i = 0; i < m; i++)
    {
        now += pi[i];
        a[i] = now;
    }
    int dp[n + 1];
    dp[0] = -1e18;
    for(int i = 1; i <= m; i++)
    {
        dp[i] = 1e18;
    }
    for(int i = 0; i < m; i++)
    {
        int l = -1, r = m + 2;
        while(l < r - 1)
        {
            int mid = (l + r) / 2;
            if(dp[mid] <= a[i])
            {
                l = mid;
            }
            else
            {
                r = mid;
            }
        }
        dp[l + 1] = a[i];
    }
    int maxx = 0;
    for(int i = 0; i <= m; i++)
    {
        if(dp[i] == 1e18)
        {
            break;
        }
        maxx = i;
    }
    cout << maxx;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
ll a,n,s,p,k;
int main()
{
    cin>>k>>n>>s>>p;
    a=(n/s+(n%s!=0))*k; ahmad
    a=a/p+(a%p!=0);
    cout<<a;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    ll a,b,two=0,three=0;
    cin>>a>>b;
    if(a-b>=3)
    cout<<2<<endl;
    else
    {
        for(c=a;c<=b;c++)
        {
            if(c%2==0)
            {
                two++;
            }
            if(c%3==0)
            {
                three++;
            }
        }
        if(two==0 && three==0)
        {
            cout<<a<<endl;
        }
        else
        {
            if(two>=three)
            cout<<2<<endl;
            else
            cout<<3<<endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

using cd = complex<double>;
#define sz(a) (int)a.size()
#define F0R(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,j,n) for (int i = j; i < (int)n; i++)
#define ld long double

typedef vector<cd> vcd;
typedef vector<long long> vl;
typedef long long ll;

namespace FFT {
    int get(int s) {
        return s > 1 ? 32 - __builtin_clz(s - 1) : 0;
    }

    void fft(vcd& a, bool inv){
    	int n = sz(a), j = 0;
    	vcd roots(n/2);
    	FOR(i,1,n) {
    		int bit = (n >> 1);
    		while (j >= bit){
    			j -= bit;
    			bit >>= 1;
    		}
    		j += bit;
    		if(i < j) swap(a[i], a[j]);
    	}

    	ld ang = 2 * M_PIl / n * (inv ? -1 : 1);
    	F0R(i,n/2) roots[i] = cd(cos(ang * i), sin(ang * i));

    	for (int i=2; i<=n; i<<=1){
    		int step = n / i;
    		for(int j=0; j<n; j+=i){
    			for(int k=0; k<i/2; k++){
    				cd u = a[j+k], v = a[j+k+i/2] * roots[step * k];
    				a[j+k] = u+v;
    				a[j+k+i/2] = u-v;
    			}
    		}
    	}

    	if (inv) F0R(i,n) a[i] /= n;
    }

    vl conv(vl a, vl b, ll mod){
        int s = sz(a)+sz(b)-1, L = get(s), n = 1<<L;

    	vcd v1(n), v2(n), r1(n), r2(n);
    	F0R(i,sz(a)) v1[i] = cd(a[i] >> 15, a[i] & 32767);
    	F0R(i,sz(b)) v2[i] = cd(b[i] >> 15, b[i] & 32767);
    	fft(v1, 0); fft(v2, 0);

    	F0R(i,n) {
    		int j = (i ? (n - i) : i);
    		cd ans1 = (v1[i] + conj(v1[j])) * cd(0.5, 0);
    		cd ans2 = (v1[i] - conj(v1[j])) * cd(0, -0.5);
    		cd ans3 = (v2[i] + conj(v2[j])) * cd(0.5, 0);
    		cd ans4 = (v2[i] - conj(v2[j])) * cd(0, -0.5);
    		r1[i] = (ans1 * ans3) + (ans1 * ans4) * cd(0, 1);
    		r2[i] = (ans2 * ans3) + (ans2 * ans4) * cd(0, 1);
    	}
    	fft(r1, 1); fft(r2, 1);
        vl ret(n);
    	F0R(i,n) {
    		ll av = (ll)round(r1[i].real());
    		ll bv = (ll)round(r1[i].imag()) + (ll)round(r2[i].real());
    		ll cv = (ll)round(r2[i].imag());
    		av %= mod, bv %= mod, cv %= mod;
    		ret[i] = (av << 30) + (bv << 15) + cv;
    		ret[i] %= mod; ret[i] += mod; ret[i] %= mod;
    	}
    	ret.resize(s);
    	return ret;
    }
}

template <int MOD>
class Modular {
public:
    Modular(long long v=0) {
        value = v % MOD;
        if (value < 0)
            value += MOD;
    }

    Modular& operator+=(Modular const& b) {
        value += b.value;
        if (value >= MOD)
            value -= MOD;
        return *this;
    }

    Modular& operator-=(Modular const& b) {
        value -= b.value;
        if (value < 0)
            value += MOD;
        return *this;
    }

    Modular& operator*=(Modular const& b) {
        value *= b.value;
        value %= MOD;
        return *this;
    }

    friend Modular power(Modular a, long long e) {
        Modular res = 1;
        while (e) {
            if (e & 1)
                res *= a;
            a *= a;
            e >>= 1;
        }
        return res;
    }

    friend Modular inverse(Modular a) {
        return power(a, MOD - 2);
    }

    Modular& operator/=(Modular const& b) {
        return *this *= inverse(b);
    }

    friend Modular operator+(Modular a, Modular const b) {
        return a += b;
    }

    friend Modular operator-(Modular a, Modular const b) {
        return a -= b;
    }

    friend Modular operator*(Modular a, Modular const b) {
        return a *= b;
    }

    friend Modular operator/(Modular a, Modular const b) {
        return a /= b;
    }

    friend std::ostream& operator<<(std::ostream &os, Modular const& a) {
        return os << a.value;
    }

    friend bool operator==(Modular const& a, Modular const& b) {
        return a.value == b.value;
    }

    friend bool operator!=(Modular const& a, Modular const& b) {
        return a.value != b.value;
    }

    long long value;
};

const int MOD = 1'000'000'007;
using ModInt = Modular<MOD>;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    // FFT fft(n * 2 - 1);
    ModInt pre_factor = 1;
    vector<ModInt> res(2 * n - 1);
    for (int i = 0; i < n - 1; i++) {
        vector<int> v(n - i, 1);
        v[0] = 0;
        ModInt f = 1;
        for (int j = i + 1; j < n - 1; j++) {
            f *= a[j];
            v[j - i + 1] = f.value;
        }

        // path ending here
        for (int j = 0; j < n - i; j++) {
            res[j] += v[j] * pre_factor * a[i];
        }

        // mixed paths
        ModInt factor = pre_factor * a[i] * (a[i] - 1) / 2;
        vector<long long> g(v.begin(), v.end());
        auto product = FFT::conv(g, g, MOD);
        // auto product = fft.multiply_bigmod(v, v, MOD);
        for (int j = 0; j < min(2*n - 1, (int)product.size()); j++) {
            res[j] += factor * product[j];
        }

        pre_factor *= a[i];
    }

    res.erase(res.begin());
    for (auto x : res)
        cout << x << " ";
    cout << endl;
}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double ld;
typedef long long ll;
// Симплекс-метод

/*

Решает линейную программу:
a11 * x1 + a12 * x2 + ... + a1n * xn + b1 >= 0
a21 * x1 + a22 * x2 + ... + a2n * xn + b2 >= 0
...   ..   ...   ..   ...   ...   ..   ..    .
am1 * x1 + am2 * x2 + ... + amn * xn + bm >= 0
 c1 * x1 +  c2 * c2 + ... +  cn * xn      -> max

Также должно выполняться x1 >= 0, ..., xn >= 0.

Входные данные - матрица (m+1)*(n+1):
a11 a12 ... a1n b1
a21 a22 ... a2n b2
... ... ... ... ..
am1 am2 ... amn bm
 c1  c2 ...  cn  0

Выходные данные:
first - тип решения (его нет, либо оно найдено, либо оно бесконечно велико)
second - массив переменных (если решение конечно) в формате:

x1 x2 ... xn res

*/

const ld eps = 1e-6;
inline void vectorDel(vector<int> &v, int value) {
    int idx = find(begin(v), end(v), value) - begin(v);
    swap(v[idx], v.back());
    v.pop_back();
}

enum class SolutionType {
    BOUNDED,
    UNBOUNDED,
    NO_SOLUTION
};

class SimplexMethod {
private:
    int h, w, n;
    vector< vector<long double> > a;
    vector<char> isBasic;
    vector<int> basic, nonBasic;

    inline void replace(int x, int y) {
        long double k = -a[x][y];
        a[x][y] = 0;
        for (int j = 0; j <= n; j++) {
            if (!isBasic[j]) {
                a[y][j] = a[x][j] / k;
                a[x][j] = 0;
            }
        }
        a[y][x] = -1 / k;
        isBasic[x] ^= 1;
        isBasic[y] ^= 1;
        vectorDel(basic, x);
        vectorDel(nonBasic, y);
        basic.push_back(y);
        nonBasic.push_back(x);
        basic.push_back(n);
        nonBasic.push_back(n);
        for (int i : basic) {
            for (int j : nonBasic) {
                a[i][j] += a[i][y] * a[y][j];
            }
            a[i][y] = 0;
        }
        basic.pop_back();
        nonBasic.pop_back();
    }

    inline int findPositive() {
        int best = 0;
        for (int j = 1; j < n; j++) {
            if (!isBasic[j] && a[n][j] > a[n][best] + eps) {
                best = j;
            }
        }
        return (a[n][best] > eps) ? best : -1;
    }

    inline int findBasic(int x) {
        long double add = 0;
        int best = -1;
        for (int i = 0; i < n; i++) {
            if (!isBasic[i] || a[i][x] > -eps) {
                continue;
            }
            long double grow = -a[i][n] / a[i][x];
            if (best < 0 || grow + eps < add) {
                add = grow;
                best = i;
            }
        }
        return best;
    }

    inline bool findAnyPoint() {
        int minB = -1;
        for (int i = 0; i < n; i++) {
            if (minB < 0 || a[i][n] < a[minB][n]) {
                minB = i;
            }
        }
        if (minB < 0 || a[minB][n] > -eps) {
            return true;
        }
        auto lastRow = a.back();
        isBasic.insert(begin(isBasic) + n, false);
        nonBasic.push_back(n);
        auto newA = a;
        a.pop_back();
        a.emplace_back(n+2, 0);
        a.emplace_back(n+2, 0);
        a.back()[n] = -1;
        for (int i = 0; i < n; i++) {
            a[i].insert(begin(a[i]) + n, 1, isBasic[i] ? 1 : 0);
        }
        n++;
        replace(minB, n-1);
        doSolve(false);
        if (a[n][n] < -eps) {
            return false;
        }
        if (isBasic[n-1]) {
            for (int i : nonBasic) {
                if (abs(a[n-1][i]) > eps) {
                    replace(n-1, i);
                    break;
                }
            }
        }
        n--;
        for (int i = 0; i < n; i++) {
            a[i].erase(begin(a[i]) + n, begin(a[i]) + n + 1);
        }
        isBasic.erase(begin(isBasic) + n, begin(isBasic) + n + 1);
        a.pop_back();
        a.pop_back();
        a.push_back(lastRow);
        for (int i : basic) {
            for (int j : nonBasic) {
                a[n][j] += a[n][i] * a[i][j];
            }
            a[n][i] = 0;
        }
        vectorDel(nonBasic, n);
        return true;
    }

    inline SolutionType doSolve(bool needFindInitial = true) {
        if (needFindInitial && !findAnyPoint()) {
            return SolutionType::NO_SOLUTION;
        }
        for (;;) {
            int x = findPositive();
            if (x < 0) {
                return SolutionType::BOUNDED;
            }
            int y = findBasic(x);
            if (y < 0) {
                return SolutionType::UNBOUNDED;
            }
            replace(y, x);
        }
    }
public:
    pair<SolutionType, vector<long double> > solve() {
        SolutionType type = doSolve();
        if (type != SolutionType::BOUNDED) {
            return {type, {}};
        }
        vector<long double> v(w+1);
        for (int i = 0; i < w; i++) {
            v[i] = a[i][n];
        }
        v[w] = a[n][n];
        return {type, v};
    }

    SimplexMethod(const vector< vector<long double> > &v)
        : h((int)v.size() - 1), w((int)v[0].size() - 1), n(h + w),
          a(n+1, vector<long double>(n+1)), isBasic(n+1, true) {
        for (int i = 0; i < w; i++) {
            isBasic[i] = false;
        }
        isBasic[n] = false;
        for (int i = 0; i <= h; i++) {
            for (int j = 0; j <= w; j++) {
                a[i + w][(j == w) ? n : j] = v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            (isBasic[i] ? basic : nonBasic).push_back(i);
        }
    }
};

int n, m;
const int maxN = 55;
int dist[maxN][maxN];
int id[maxN][maxN];
int sz = 1;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        dist[u][v] = w;
        id[u][v] = sz;
        sz++;
    }
    int q;
    cin >> q;
    while (q--) {
        int t;
        cin >> t;
        vector<vector<ld> > all;
        for (int vert = 1; vert <= n; vert++) {
            if (vert == 1) {
                vector < ld > f(n + m + 1);
                f[0] = -1;
                all.push_back(f);
                continue;
            }
            for (int p = 1; p <= n; p++) {
                if (dist[p][vert]) {
                    vector < ld > f(n + m + 1);
                    f[p - 1] = 1;
                    f[vert - 1] = -1;
                    f[n + m] = dist[p][vert];
                    f[id[p][vert] + n - 1] = 1;
                    all.emplace_back(f);
                }
            }
        }
        vector < ld > f(n + m + 1);
        for (int i = n; i <= n + m - 1; i++) f[i] = -1;
        f[n + m] = t;
        all.emplace_back(f);
        vector < ld > g(n + m + 1);
        g[n - 1] = 1;
        all.emplace_back(g);
        auto res = SimplexMethod(all).solve();
        cout << fixed << setprecision(10) << res.second.back() << '\n';
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <time.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
template <class T>
inline bool rd(T &ret) {
	char c; int sgn;
	if (c = getchar(), c == EOF) return 0;
	while (c != '-' && (c<'0' || c>'9')) c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}
template <class T>
inline void pt(T x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9) pt(x / 10);
	putchar(x % 10 + '0');
}
typedef long long ll;
typedef pair<int, int> pii;
const int N = 100005;
int k, m;
set<pii>s;
bool ok(int a, int b) {
	if (m == 0)return false;
	if (s.count({ a, b }) || a<0 || b<0)return false;
	if (a + b == k || a - b == k || a*b == k || (b && a%b == 0 && a / b == k))
	{
		s.insert({ a,b });
		printf("%04d%04d\n", a, b);
		m--;
		return true;
	}
	return false;
}
void go(int a, int b) {
	ok(a, b);
	ok(b, a);
}
int main() {
	rd(k);rd(m);
	for (int i = 0; m > 0 && i < 10000; i++)
	{
		go(i, i - k);
		go(i, i + k);
		go(i, k / i);
		go(i, i*k);
	}
	return 0;
}
/*
5 1
3 3

*/


#include <iostream>
using namespace std;

int a[3000];

main()
{
	int n,m,i,x,t,N;
	cin>>n>>m;

	if(n>m)
	{
		t=n;
		n=m;
		m=t;
	}

	N=n;

	cin>>x;

	if(x>(N+1)/2)
	{
		cout<<0<<endl;
		return 0;
	}

	for(i=1;i<=(N+1)/2;i++)
	{
		if(n==1)
			a[i]=(m+1)/2;
		else
			a[i]=m+n-2;
		m-=2;
		n-=2;
	}
	cout<<a[x]<<endl;
	return 0;
}


#include<bits/std++.h>
using namepace std;
int main()
{
    int n,;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }

    for(int i=1;i<6;i++)
    {
        if((sum+i)%(n+1)!=1){
            cout<<i<<endl;
            break;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

inline bool equal(double a, double b) {
	return abs(a - b) < 1e-5;
}

int n, m;
vector<vector<pair<int, int>>> g;

array<vector<int>, 2> col;
vector<char> used;

vector<char> already;
vector<double> ans;

int num;
array<vector<int>, 2> comp;

vector<pair<int, int>> cur;

bool dfs(int v, int now, vector<int> &vers) {
	vers.push_back(v);
	used[v] = 1;
	comp[now][v] = num;

	bool ok = true;
	for (auto [u, tp] : g[v]) {
		if (tp != now)
			continue;
		ok &= (col[now][u] == -1 || col[now][u] == (col[now][v] ^ 1));
		col[now][u] = col[now][v] ^ 1;
		if (!used[u])
			ok &= dfs(u, now, vers);
	}
	return ok;
}

void dfs_fill(int v) {
	used[v] = 1;
	for (auto [u, tp] : g[v]) {
		if (already[u] && !equal((double) tp + 1, ans[v] + ans[u])) {
			cout << "NO\n";
			exit(0);
		}
		already[u] = 1;
		ans[u] = tp + 1 - ans[v];
		if (!used[u])
			dfs_fill(u);
	}
}

void dfs_solve(int v, vector<int> &vers) {
	vers.push_back(v);
	used[v] = 1;
	for (auto [u, tp] : g[v]) {
		if (used[u])
			continue;
		cur[u] = {-cur[v].first, tp + 1 - cur[v].second};
		dfs_solve(u, vers);
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> m;
	g.resize(n);
	for (int i = 0; i < m; i++) {
		int v, u, tp;
		cin >> v >> u >> tp;
		v--, u--, tp--;
		g[v].emplace_back(u, tp);
		g[u].emplace_back(v, tp);
	}

	ans.resize(n);
	already.resize(n);

	array<vector<vector<int>>, 2> comps;
	for (int now = 0; now < 2; now++) {
		col[now].resize(n, -1);
		used = vector<char>(n, 0);
		num = 0;
		comp[now].resize(n);

		for (int i = 0; i < n; i++)
			if (!used[i]) {
				num++;
				vector<int> vers;
				col[now][i] = 0;
				if (!dfs(i, now, vers))
					for (auto u : vers) {
						if (already[u] && !equal(ans[u], (double) (now + 1) / 2))
							return cout << "NO\n", 0;
						already[u] = 1;
						ans[u] = (double) (now + 1) / 2;
					}

				comps[now].push_back(vers);
			}
	}

	for (int v = 0; v < n; v++)
		for (auto [u, tp] : g[v]) {
			if (comp[tp ^ 1][v] != comp[tp ^ 1][u])
				continue;
			if (col[tp ^ 1][v] != col[tp ^ 1][u])
				return cout << "NO\n", 0;

			already[v] = already[u] = 1;
			ans[v] = ans[u] = 1 - (1 - tp) * 0.5;
		}

	used = vector<char>(n, 0);
	for (int i = 0; i < n; i++)
		if (!used[i] && already[i])
			dfs_fill(i);

	used = vector<char>(n, 0);
	cur.resize(n);
	for (int i = 0; i < n; i++) {
		if (already[i] || used[i])
			continue;
		vector<int> vers;
		cur[i] = {1, 0};
		dfs_solve(i, vers);

		vector<double> solves;
		for (auto v : vers)
			for (auto [u, tp] : g[v]) {
				if (solves.size())
					break;
				int k = cur[v].first + cur[u].first;
				if (!k) {
					if (cur[v].second + cur[u].second != tp + 1)
						return cout << "NO\n", 0;
					continue;
				}
				solves.push_back((double) (tp + 1 - cur[v].second - cur[u].second) / k);
			}

		if (solves.size()) {
			for (auto v : vers)
				used[v] = 0;
			ans[i] = solves[0];
			already[i] = 1;
			dfs_fill(i);
			continue;
		}

		vector<pair<double, double>> maybe;
		for (auto now : {-3.0, -2.5, -2.0, -1.5, -1.0, -0.5, 0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0}) {
			maybe.emplace_back(0.0, now);
			for (auto v : vers)
				maybe.back().first += abs(cur[v].first * now + cur[v].second);
		}

		sort(maybe.begin(), maybe.end());
		ans[i] = maybe[0].second;
		already[i] = 1;
		for (auto v : vers)
			used[v] = 0;
		dfs_fill(i);
	}

	cout << "YES\n";
	for (auto x : ans)
		cout << x << ' ';
	cout << '\n';
}


// ConsoleApplication3.cpp : Defines the entry point for the console application.

#include <iostream>
#include <vector>
#include <map>

using namespace std;

typedef long long int llint;

int main()
{
	int n;
	cin >> n;

	string str;

	for (int i = 0; i < n; i++) {
		char a;
		std::cin >> a;
		str.push_back(a);
	}

	int oneCount = 0;

	for (int i = 0; i < n; i++) {
		if (str[i] == '1') {
			oneCount++;
		}
	}

	if (n==1 || oneCount * 2 != n) {
		std::cout << 1 << "\n";
		std::cout << str;
		return 0;
	}

	std::cout << 2 << "\n";

	std::cout << str.substr(0, str.size()-1) << "   " << str[n-1] << "\n";
}


#include<iostream>
#include<cstring>
using namespace std;

int main(){
	 int n=100;
	int r=0;
	char p[n];

	cin.getline(p,n,'\n');
	int s=strlen(p);

	for (int i=0;i<s;i++)

		if (p[i]=='Q')
		{
			for(int j=i+1;j<s;j++)

				if(p[j]=='A')

					for(int m=j+1;m<s;m++)

						if(p[m]=='Q')

						r=r+1;

		}

	cout<<r;

}


#include <bits/stdc++.h>
using namespace std;

const int N = 20;
int red[N], blue[N], numR[1<<N], numB[1<<N], n, f[1<<N][N*N];
char t[N];

int get(int i, int j) {
    return (i >> j) & 1;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
    cin >> n;
    long long allR = 0, allB = 0;
    for(int i=1 ; i<=n ; ++i) {
        cin >> t[i];
        cin >> red[i] >> blue[i];
        allB += blue[i];
        allR += red[i];
    }
    for(int i=1 ; i<(1<<n) ; ++i) {
        for(int j=1 ; j<=n ; ++j) {
            if(get(i, j-1) == 0) continue;
            numR[i] += t[j] == 'R';
            numB[i] += t[j] == 'B';
        }
    }

    memset(f, -1, sizeof f);
    f[0][0] = 0;
    for(int i=0 ; i<(1<<n) ; ++i) {
        for(int throwR=0 ; throwR<=n*n ; ++throwR) {
            if(f[i][throwR] == -1) continue;
            for(int j=1 ; j<=n ; ++j) {
                if(get(i, j-1)) continue;
                int newthrowR = throwR + min(red[j], numR[i]);
                int newThrowB = f[i][throwR] + min(blue[j], numB[i]);
                if(newThrowB > f[i | (1<<(j-1))][newthrowR]) {
                    f[i | (1<<(j-1))][newthrowR] = newThrowB;
                }
            }
        }
    }
    long long ans = max(allB, allR);
    for(int throwR=0 ; throwR<=n*n ; ++throwR) {
        int x = f[(1<<n)-1][throwR];
        if(x == -1) continue;
        ans = min(ans, max(allB-x, allR-throwR));
    }
    cout << ans + n;
    return 0;
}


#include <iostream>
#include <math.h>
#include <string.h>
#include <utility>

using namespace std;

bool adj[6][6];

bool test(int a,int b, int c){
    if(adj[a][b] and adj[b][c] and adj[c][a]){
	return true;
    }
    if(!adj[a][b] and !adj[b][c] and !adj[c][a]){
	return true;
    }
    return false;
}

int main(){
    bzero(adj,sizeof(adj));
    int M;
    cin >> M;
    for(int i=0; i<M; i++){
	int in1, in2;
	cin >> in1 >> in2;
	adj[in1-1][in2-1]=true;
	adj[in2-1][in1-1]=true;
    }
    bool win=false;
    for(int i=0; i<5; i++){
	for(int j=i+1; j<5; j++){
	    for(int k=j+1; k<5; k++){
		if(test(i,j,k)){
		    win=true;
		    i=5; j=5;
		    break;
		}
	    }
	}
    }
    if(win){
	cout << "WIN\n";
    }else{
	cout << "FAIL\n";
    }
}


#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <queue>
#include <memory.h>
#include <iostream>
#include <stack>
#include <complex>

using namespace std;

void ASS(bool b)
{
    if (!b)
    {
        ++*(int*)0;
    }
}

#define FOR(i, x) for (int i = 0; i < (int)(x); i++)
#define CL(x) memset(x, 0, sizeof(x))

#pragma comment(linker, "/STACK:106777216")

typedef vector<int> vi;
typedef long long LL;

int a[4];

int main()
{
	FOR(i, 3)
		cin >> a[i];
	int k;
	cin >> k;

	sort(a[0], a[1], a[2]);
	k = min(a[0] + a[1] + a[2] - 3, k);
	LL res = 1;
	FOR(i, min(a[0] - 1, k) + 1)
	{
		int d = min(k - i, a[1] + a[2] - 2);
		int x = d / 2;
		int c1 = min(a[1] - 1, x);
		int c2 = min(a[2] - 1, d - c1);
		res = max(res, (i + 1) * (LL) (1 + c1) * (LL) (1 + c2));
	}
	cout << res << endl;
	return 0;
}


#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <string.h>
#include <utility>
#include <queue>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <map>
#include <ctype.h>
#include <iomanip>
#include <stdio.h>
#include <set>

#define LL long long
#define fr(i,n) for(i=0;i<n;i++)
#define INF (2000000000)
#define FOR(n) for(int i = 0;i < n;i++)
#define CLEAR(x) memset(x,0,sizeof(x))
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))

using namespace std;

int main ()
{
    int n,m,a,b,c,d;
    //freopen("input.txt", "rt", stdin);
    cin >> n >> m >> x >> y >> a >> b;
    a-=c;
    b-=d;
    if(a<0)a=-a;
    if(b<0)b=-b;
    if (a>=5||b>=5||a+b>=7)
        cout << "Second";
    else
        cout << "First";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,i=1,t=0;
cin>>n>>k;
k=240-k;
for(;i<=n;i++)
{
s+=5*i;
if(s>k)
break;
}
cout<<i-1;
return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long ll;
const int maxn = 1e5;
 int s = 30;

int n, d, x, rec[maxn+5];
int np, pos[maxn+5];
int a[maxn+5], b[maxn+5];

int get_next () {
    return x = (37LL * x + 10007) % 1000000007;
}

void init_table () {
    for (int i = 0; i < n; i++)
        a[i] = i + 1;

    for (int i = 0; i < n; i++)
        swap(a[i], a[get_next() % (i+1)]);

    for (int i = 0; i < n; i++)
        b[i] = (i < d ? 1 : 0);

    for (int i = 0; i < n; i++)
        swap(b[i], b[get_next() % (i+1)]);
}

void init_pos () {
    np = 0;
    for (int i = 0; i < n; i++) {
        if (b[i])
            pos[np++] = i;
    }

    for (int i = 0; i < n; i++)
        rec[a[i]] = i;
}

int main () {
    // freopen("in.txt", "r", stdin);
    scanf("%d%d%d", &n, &d, &x);
    init_table();
    init_pos();
    s = sqrt(n);
    for (int i = 0; i < n; i++) {

        bool flag = true;

        for (int j = n; j >= n-s; j--) {
            if (rec[j] <= i && b[i-rec[j]]) {
                flag = false;
                printf("%d\n", j);
                break;
            }
        }
        if (flag) {
            int ans = 0;
            for (int j = 0; j < np && pos[j] <= i; j++) {
                ans = max(ans, a[i-pos[j]]);
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int x;
        cin >> x;
        if(x <= 7) {
            cout << 1 << endl;
        } else {
            int counter = 0;
            while(x > 7) {
                x -= 7;
                counter += 1;
            }
            cout << counter + 1 << endln;
        }
    }
}


#include <cstdio>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

int main()
{
	long long n, m;
	scanf("%I64d%I64d", &n, &m);
	if (m >= n)
		printf("%I64d\n", n);
	else
	{
		long long t = sqrt(2 * (n - m));
		while (t * (t + 1) / 2 >= n - m) --t;
		while ((t + 1) * (t + 2) / 2 < (n - m)) ++t;
		printf("%I64d\n", t + m + 1);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int arr[100000];
int main(){
    long long int n,k;
    cin>>n>>k;
   if(n%2==0){
      cout<<n*k-k*(k+1)/2+k*(k-1)/2+(n-2*k)*k;
   }
   else{
      if(k!=n/2){
         cout<<cout<<n*k-k*(k+1)/2+k*(k-1)/2+(n-2*k)*k;
      }
      else{
        cout<<n*(n-1)/2;
      }
   }
   return 0;}


#include <cstdio>

using namespace std;

int f[]={0, 0, 1, 2, 9};
int n_cate_k(int n,int k)
{
    int t1 = 1,t2 = 1;
    for(int i = 1; i <= k; ++i)
    {
        t1*=(n - i + 1);
        t2*=i;
    }
    return t1/t2;
}
int main()
{
    int n,k,sol=0;
    scanf("%d%d",&n,&k)
    for(int i = 0; i <= k; i++)
        ans+=n_cate_k(n,i)*f[i];
    printf("%d",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>

#include<map>
#include<queue>
#include<vector>
#include<set>
#include<algorithm>

typedef long long LL;
#define PI(x) printf("%d\n",x)
#define SI(x) scanf("%d",&x)
#define MP(x,y) make_pair(x,y)
#define MX 17
using namespace std;

int n,m;
LL y;
int prof_at_seat[MX];
int seat_of_prof[MX];
int before_seat[MX];
LL dp[(1<<MX)];

LL ways(int mask_of_seats)
{
	int prof = __builtin_popcount(mask_of_seats);
	if(prof>=n) return 1;

	if(dp[mask_of_seats]!=-1)return dp[mask_of_seats];

	// Try to put the prof at some available seat.
	LL w = 0;
	for(int seat=0;seat<n;seat++)
	{
		if((mask_of_seats & (1<<seat))!=0) continue;

		if(prof_at_seat[seat]!=-1 && prof_at_seat[seat]!=prof) continue;
		if(seat_of_prof[prof]!=-1 && seat_of_prof[prof]!=seat) continue;
		if((mask_of_seats & before_seat[seat]) != before_seat[seat]) continue;
		w+=ways(mask_of_seats | (1<<seat));
	}

	return dp[mask_of_seats] = w;
}

int main()
{
	SI(n);
	cin>>y;
	SI(m);

	for(int i=0;i<m;i++)
	{
		int a,b;
		SI(a);SI(b);
		a--;b--;
		before_seat[b] |= (1<<a);
	}
	for(int i=0;i<n;i++)
	{
		seat_of_prof[i] = -1;
		prof_at_seat[i] = -1;
	}
	y-=2001;
	memset(dp,-1,sizeof dp);
	LL ww = ways(0);
	if(ww<=y)
	{
		cout<<"The times have changed"<<endl;
		return 0;
	}

	for(int seat = 0;seat<n;seat++)
	{
		for(int prof=0;prof<n;prof++)
		{
			if(seat_of_prof[prof]!=-1)continue;
			seat_of_prof[prof] = seat;
			prof_at_seat[seat] = prof;

			memset(dp,-1,sizeof dp);
			LL w = ways(0);
			if(w<=y)
			{
				y-=w;
				prof_at_seat[seat] = -1;
				seat_of_prof[prof] = -1;
			}
			else {
				break;
			}
		}
		printf("%d ",prof_at_seat[seat]+1);
	}
	cout<<endl;

	return 0;
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="problem_A" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/problem_A" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/problem_A" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include "/Users/cslusr/macros.h"
#include<iostream>
#include<vector>
#include<tuple>
#include<set>
#include<unordered_map>
#include<map>
#include<deque>
#include<stack>
#include<fstream>
#include<numeric>
#include<cassert>
#include<list>
#include<cmath>
#include<algorithm>

using namespace std;

#define PB push_back
#define MT make_tuple
#define MP make_pair
#define VI vector<int>
#define VVI vector<vector<int>>
#define TII tuple<int,int>
#define SZ() size()
#define ALL(v) v.begin(),v.end()
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORE(v, c) for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)

#ifdef ONLINE_JUDGE
using lld = int64_t;
#define __LLD__ "%I64d"
#else
using lld = long long;
#define __LLD__ "%lld"
#endif

#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif

#define __HALT__ {while (true) { };}
#define __HOLD__ {char * c = (char *)malloc(100*sizeof(char)); scanf("%s",c); free(c);}
#define __UNSYNC_IO__ ios_base::sync_with_stdio(false);cin.tie(NULL);

#ifdef DEBUG
  #define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
  #define PRINT(a) printf a
#else
  #define dbg(vari) cout<<"";
  #define PRINT(a) (void)(0)
#endif

class S {
public:

  lld count (lld n) {
    lld k = 2;
    lld c = 0;
    while ( k*k*k <= n ) {
      lld k3 = k*k*k;
      c += (n/k3);
      ++k;
    }
    return c;
  }

  lld solve(lld m ) {
    lld lo = 0, hi = 1e15;
    lld tmp = 0;
    while ( lo+1 < hi ) {
      lld mid = (lo + hi)/2;
      tmp = count(mid);
      // dbg(lo);
      // dbg(mid);
      // dbg(hi);
      // dbg(tmp);
      if ( tmp < m ) {
        lo = mid;
      }
      else {
        hi = mid;
      }
    }

    if ( count(lo+1) == m ) {
      return lo+1;
    }
    else {
      return -1;
    }
  }

  void solve() {
    lld m;
    cin >> m;
    lld res = solve(m);
    cout << res << endl;
  }

};

int main() {

  __UNSYNC_IO__;

  S s;
  s.solve();

  return 0;

}


#include <cstdio>
const int N=100100;
using namespace std;

int fa[N];
inline int getf(int x){return x==fa[x]?x:fa[x]=getf(fa[x]);}
int main(int argc, char const *argv[])
{
	scanf("%d%d",&Ti,&T);
	while(T--){
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++) fa[i]=i;
		for(int i=1,u,v,opt;i<=m;i++)
			scanf("%d%d%d",&u,&v,&opt);

	}
	return 0;
}


#include <iostream>
#include <math>

using namespace std;

int main(){
    int a, b, c;
    long long ans = 0;
    cin >> a >> b >> c;
    if(a == b)
        ans = ans + c * 2 + min(a, b) * 2;
    if(a != b)
        ans = ans + c * 2 + min(a, b) * 2 + 1;
    cout << ans << endl;
}


#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
using namespace std;
vector<int>C[410000];
int go[410000],n,m,pd[410000],B[5],ansX[110000],ansY[110000],now,num,cho[110000],bo[110000],a[110000],b[110000],f[110000],dis;
struct atom2{
    int where,w;
};
int operator < (atom2 k1,atom2 k2){
    return k1.w<k2.w;
}
multiset<atom2>S;
char getin(){
    char ch=getchar(); while (ch<'A'||ch>'Z') ch=getchar(); return ch;
}
struct point{
    int x,y;
};
struct atom{
    point k1,k2;
    void scan(){
        char k3=getin(),k4=getin(); scanf("%d%d",&k1.y,&k2.y);
        if (k3=='L') k1.x=1; else if (k3=='R') k1.x=0; else if (k3=='T') k1.x=2; else k1.x=3;
        if (k4=='L') k2.x=1; else if (k4=='R') k2.x=0; else if (k4=='T') k2.x=2; else k2.x=3;
        if (k1.x>k2.x) swap(k1,k2);
    }
}A[210000];
int get(point k1){
    if (k1.x==1) return k1.y;
    if (k1.x==2) return k1.y+n;
    if (k1.x==0) return k1.y+n+m;
    return k1.y+n+n+m;
}
int getnext(int k){
    k+=n+m;
    if (k>n+n+m+m) k-=n+n+m+m;
    return k;
}
int getlin(int k){
    if (k>n+m) k-=n+m; return k;
}
void find(int k1,int k2){
    int k3=getlin(k1);
    if (pd[k3]) return;
    pd[k3]=1; C[k2].push_back(k3); find(getnext(go[k1]),k2);
}
int gcd(int k1,int k2){
    if (k2==0) return k1; return gcd(k2,k1%k2);
}
int check(int k){
    int num=0;
    for (int i=0;i<C[k].size();i++){
        int k1=(i+1)%C[k].size();
        if (C[k][i]>n&&C[k][k1]>n&&(C[k][i]<=n+m||C[k][i]>n+n+m)&&(C[k][k1]<=n+m||C[k][k1]>n+n+m)) num++;
    }
    return num;
}
void print(int k1,int k2,int k3){
    if (ansY[k1]) return;
//    if (k2<B[0]) cout<<k1<<" "<<k2<<" "<<k3<<endl;
    ansY[k1]=k2; cho[k2]=1;
    if (go[k1+n]>n+n+m){
        k2+=num; print(getnext(go[k1+n])-n,k2,k3+1); return;
    }
    k2=n-(m-k2); print(getnext(go[getnext(go[k1+n])])-n,k2,k3);
}
int check2(int k){
    int k1=C[k][0];
    if (go[k1]<=n+m){
        k1=go[getnext(go[k1])];
        if (k1>n) return 0;
        k1=go[getnext(k1)];
        if (k1<=n+n+m) return 0;
        return 1;
    } else {
        k1=go[getnext(go[k1])];
        if (k1>n) return 0;
        k1=go[getnext(k1)];
        if (k1>n+m) return 0;
        return 1;
    }
}
int getfirst(int k){
    int k1=k; int flag=0;
    while (bo[k1]==0){
        bo[k1]=1; if (flag) return k1;
        if (go[k1+n]>n+n+m){
            k1=getnext(go[k1+n])-n; continue;
        }
        flag=1; k1=getnext(go[getnext(go[k1+n])])-n;
    }
    return k;
}
int getdis(int k){
    if (getlin(go[k+n])==k+n) return 1; dis=0; int k1=k;
    while (1){
        if (go[k1+n]>n+n+m){
            k1=getnext(go[k1+n])-n; dis++; continue;
        }
        return dis;
    }
}
int find(int k){
    if (f[k]!=-1) return f[k];
    f[k]=0; f[k]=find(k+num)+1; return f[k];
}
int main(){
//  freopen("data.out","w",stdout);
//  freopen("data.in","r",stdin);
    scanf("%d%d",&n,&m);
    int flag1=0,flag2=0;
    for (int i=1;i<=n+m;i++){
        A[i].scan(); if (A[i].k1.x==0&&A[i].k2.x==1) flag1=1;
        if (A[i].k1.x==2&&A[i].k2.x==3) flag2=1;
    }
    int flag=0;
    if (flag1&&flag2){cout<<"No solution"<<endl; return 0;}
    if (flag1){
        flag++;
        for (int i=1;i<=n+m;i++){
            A[i].k1.x=3-A[i].k1.x; A[i].k2.x=3-A[i].k2.x;
            swap(A[i].k1,A[i].k2);
        }
        swap(n,m);
    }
    num=0;
    for (int i=1;i<=n+m;i++)
        if (A[i].k1.x==1&&A[i].k2.x==2) num--; else if (A[i].k1.x==1&&A[i].k2.x==3) num++;
    if (num<0){
        flag+=2; num=-num;
        for (int i=1;i<=n+m;i++){
            if (A[i].k1.x<=1) A[i].k1.y=n-A[i].k1.y+1; else A[i].k1.x=5-A[i].k1.x;
            if (A[i].k2.x<=1) A[i].k1.y=n-A[i].k2.y+1; else A[i].k2.x=5-A[i].k2.x;
            if (A[i].k1.x>A[i].k2.x) swap(A[i].k1,A[i].k2);
        }
    }
    for (int i=1;i<=n+m;i++){
        if (A[i].k1.x==1&&A[i].k2.x==2) B[0]++;
        if (A[i].k1.x==0&&A[i].k2.x==2) B[1]++;
        if (A[i].k1.x==0&&A[i].k2.x==3) B[2]++;
        if (A[i].k1.x==1&&A[i].k2.x==3) B[3]++;
        if (A[i].k1.x==2&&A[i].k2.x==3) B[4]++;
    }
    if (B[0]!=B[2]||B[1]!=B[3]){cout<<"No solution"<<endl; return 0;}
    if (n==1&&m==1){cout<<1<<endl; cout<<1<<endl; return 0;}
    for (int i=1;i<=n+m;i++){
        int k1=get(A[i].k1),k2=get(A[i].k2);
        go[k1]=k2; go[k2]=k1;
    }
    memset(pd,0x00,sizeof pd); int len=0;
    for (int i=1;i<=n+m;i++) if (pd[i]==0){len++; find(i,len);}
    int len2=0; if (B[4]||num) len2=B[4]/(gcd(B[4],num)); else len2=1; now=0;
    memset(pd,0x00,sizeof pd);
    for (int i=1;i<=len;i++){
        int k1=check(i);
        if (k1==0&&C[i].size()==4&&check2(i)){
            now++; pd[i]=1;
        } else if (k1!=len2||k1==0){
            cout<<"No solution"<<endl; return 0;
        }
    }
    memset(f,0xff,sizeof f);
    for (int i=m-B[1]+1;i<=m;i++) f[i]=0;
    for (int i=B[0]+1;i<=m-B[1]+1;i++) f[i]=find(i);
    for (int i=B[0]+1;i<=B[0]+B[4]/len2;i++) S.insert((atom2){i,f[i]});
//    for (int i=B[0]+1;i<=B[0]+B[4]/len2;i++) cout<<f[i]<<" "; cout<<endl;
    for (int i=1;i<=n+m;i++)
        if (A[i].k1.x==2&&A[i].k2.x==3){
            if (ansY[A[i].k1.y]) continue; while (cho[now]) now++;
            int k1=getfirst(A[i].k1.y),k2=getdis(k1);
            multiset<atom2>::iterator k3=S.find((atom2){0,k2});
            print(k1,(*k3).where,0); S.erase(k3);
        }
    int l=1,r=m;
//  for (int i=m-B[0]+1;i<=m;i++) if (cho[i]) cout<<"uses "<<i<<endl;
    int k1=0;
    for (int i=1;i<=len;i++)
        if (pd[i]){
            k1++;
            while (cho[l]==1) l++;
            while (cho[r]==1) r--;
            ansY[C[i][1]-n]=l; ansY[C[i][3]-n]=r; cho[l]=1; cho[r]=1;
        }
    for (int i=1;i<=n;i++) if (go[i]<=n+m) ansX[i]=ansY[go[i]-n]; else ansX[i]=n-(ansY[go[i]-n-n-m])+1;
    for (int i=1;i<=n;i++) a[ansX[i]]=i;
    for (int i=1;i<=m;i++) b[ansY[i]]=i;
    if (flag&2){
        for (int i=1;i<n-i+1;i++) swap(a[i],a[n-i+1]);
        for (int i=1;i<=n;i++) a[i]=n-a[i]+1;
    }
    if (n==620) cout<<"asdasd"<<endl;
    if (flag&1){
        for (int i=1;i<=m;i++) printf("%d ",b[i]); cout<<endl;
        for (int i=1;i<=n;i++) printf("%d ",a[i]); cout<<endl;
    } else {
    if (n!=620)    for (int i=1;i<=n;i++) printf("%d ",a[i]); cout<<endl;
    if (n==620) cout<<"asdasd"<<endl;
    if (n!=620)    for (int i=1;i<=m;i++) printf("%d ",b[i]); cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cctype>
#include<string.h>
#include<cmath>
#include<vector>

using namespace std;
#define ll long long

const int N = 1<<15, M = N<<1, P = 998244353;
int n, k, w[M];
vector<int> ans;
inline int Pow(ll x, int y=P-2){
	int ans=1;
	for(; y; y>>=1, x=x*x%P) if(y&1) ans=ans*x%P;
	return ans;
}
inline void DFT(vector<int> &f, int n){
	static unsigned ll F[M];
	for(int i=0, j=0; i<n; ++i){
		F[i]=f[j];
		for(int k=n>>1; (j^=k)<k; k>>=1);
	}
	for(int i=1; i<n; i<<=1) for(int j=0; j<n; j+=i<<1) for(int k=j; k<j+i; ++k){
		int t=F[k+i]*w[i+k-j]%P;
		F[k+i]=F[k]+P-t, F[k]+=t;
	}
	for(int i=0; i<n; ++i) f[i]=F[i]%P;
}
inline void IDFT(vector<int> &f, int n){
	reverse(f.begin()+1, f.end()), DFT(f, n);
	for(int i=0, I=Pow(n); i<n; ++i) f[i]=(ll)f[i]*I%P;
}
inline int Calc(int x){ int ans=1; while(ans<=x) ans<<=1; return ans;}
inline vector<int> operator *(const vector<int> &x, const vector<int> &y){
	if(!x.size() || !y.size()){
		vector<int> a;
		return a.push_back(0), a;
	}
	vector<int> a=x, b=y;
	int n=Calc(x.size()+y.size()-2);
	a.resize(n), b.resize(n), DFT(a, n), DFT(b, n);
	for(int i=0; i<n; ++i) a[i]=(ll)a[i]*b[i]%P;
	IDFT(a, n);
	return a.resize(min(x.size()+y.size()-1, k+1ull)), a;
}
inline void operator *=(vector<int> &x, const vector<int> &y){ x=x*y;}
inline vector<int> operator +(const vector<int> &x, const vector<int> &y){
	vector<int> ans=x;
	if(y.size()>x.size()) ans.resize(y.size());
	for(unsigned i=0; i<y.size(); ++i) (ans[i]+=y[i])%=P;//
	return ans;
}
inline void operator +=(vector<int> &x, const vector<int> &y){ x=x+y;}
struct matrix{
	vector<int> a[2][2];
	inline matrix operator *(const matrix &rhs)const{
		matrix ans;
		for(int i=0; i<2; ++i) for(int k=0; k<2; ++k) for(int j=0; j<2; ++j)
			ans.a[i][j]+=a[i][k]*rhs.a[k][j];
		return ans;
	}
} A;
inline matrix Pow(matrix x, int y){
	matrix ans=x;
	--y;
	for(; y; y>>=1, x=x*x) if(y&1) ans=ans*x;
	return ans;
}
int main() {
	for(int i=1; i<M; i<<=1){
		w[i]=1, w[i+1]=Pow(3, (P-1)/i/2);
		for(int j=2; j<i; ++j) w[i+j]=(ll)w[i+j-1]*w[i+1]%P;
	}
	scanf("%d%d", &n, &k);
	A.a[0][0]={1, 1}, A.a[0][1]={0, 1}, A.a[1][0]={1};
	A=Pow(A, n), ans=A.a[1][0]*vector<int>{1,1}+A.a[1][1];
	for(int i=1; i<=k; ++i) printf("%d ", i>n?0:ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 998244353;
ll div(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                cnt++;
            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}
void solve()
{
    ll n;
    cin>>n;
    vector<ll> dp(n+1,0);
    dp[1]=1;
    dp[0]=0;
    ll sum=1;
    for(ll i = 2;i<=n;i++)
    {
        dp[i]=((sum)%mod);
        dp[i]=(dp[i]+div(i))%mod;
        sum= (sum+dp[i])%mod;
    }=
    cout<<dp[n];
    return;
}
int main() {
	int t=1;
	//cin>>t;
	while(t--)
	{
	    solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{

 long long int n,sum=0;cin>>n; int a[n];
 for(int i=0;i<n;i++){
     cin>>a[i];
 }
sort(a,a+n,greater<>());
 sum+=a[0];
  long long int ci=a[0];
 for(int i=1;i<n;i++){
  //  cout<<"*"<<ci<<" "<<a[i]<<endl;
     sum+=min(a[i],ci-1);
    // cout<<"....."<<sum<<endl;
     ci=min(a[i],ci-1);
     if(ci<=0)break;
     //cout<<"^^"<<ci<<endl;
 }
cout<<sum<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ls x << 1
#define rs x << 1 | 1
#define lson ls, l, mid
#define rson rs, mid + 1, r
#define INF 1000000007
using namespace std;
int a[200010], L[200010], R[200010], tag[200010] ;
ll sum[200010], minv[200010][2];

void build(int x, int l, int r)
{
	L[x] = l;
	R[x] = r;
	if(l == r)
	{
		sum[x] = a[l];
		minv[x][0]  = a[l];
		minv[x][1] = INF;
		return;
	}
	int mid = (l + r) >> 1;
	build(lson);
	build(rson);
	int k = ((mid - l + 1) & 1);
	sum[x] = sum[ls] + (k ? -sum[rs] : sum[rs]);
	minv[x][0] = min(minv[ls][0], k ? minv[rs][1] + sum[ls] : minv[rs][0] + sum[ls]);
	minv[x][1] = min(minv[ls][1], k ? minv[rs][0] - sum[ls] : minv[rs][1] - sum[ls]);
}

void pushdown(int x)
{
	if (tag[x])
	{
		int tg = tag[x];
		tag[x] = 0;
		tag[ls] += tg, tag[rs] += tg;
		minv[ls][0] += tg, minv[rs][0] += tg;
		sum[ls] += tg * ((R[ls] - L[ls] + 1) & 1);
		sum[rs] += tg * ((R[rs] - L[rs] + 1) & 1);
	}
}

void Modify(int x,int l,int r,int v)
{
	if (L[x] == l && R[x] == r)
	{
		tag[x] += v;
		minv[x][0] += v;
		sum[x] += v * ((r - l + 1) & 1);
		return;
	}
	pushdown(x);
	int mid = (L[x] + R[x]) >> 1;
	if (r <= mid) Modify(x << 1, l, r, v);
	else if (l > mid) Modify((x << 1) | 1, l, r, v);
	else Modify(lson, v), Modify(rson, v) ;
	int k = ((mid - L[x] + 1) & 1);
	sum[x] = sum[ls] + (k ? -sum[rs]  : sum[rs]) ;
	minv[x][0] = min(minv[ls][0] , k ? minv[rs][1] + sum[ls]: minv[rs][0] + sum[ls]);
	minv[x][1] = min(minv[ls][1], k ? minv[rs][0] - sum[ls] : minv[rs][1] - sum[ls]);
}

pair<ll, pair<ll,ll> > Query(int x,int l,int r)
{
	if (L[x] == l &&  R[x] == r)
		return make_pair(sum[x], make_pair(minv[x][0], minv[x][1]));
	pushdown(x) ;
	int mid = (L[x] + R[x]) >> 1;
	if (r <= mid) return Query(x << 1, l, r) ;
	if (l > mid) return Query((x << 1) | 1, l, r) ;
	pair<ll,pair<ll, ll> > p1 = Query(lson), p2 = Query(rson), p;
	int k = (mid - l + 1) & 1;
	p.first = p1.first + (k ? -p2.first : p2.first);
	p.second.first = min(p1.second.first, k ? p2.second.second + p1.first : p2.second.first + p1.first);
	p.second.second = min(p1.second.second, k ? p2.second.first - p1.first : p2.second.second - p1.first);
	return p ;
}

bool Solve(int l,int r)
{
	pair<ll, pair<ll, ll> > p = Query(1, l, r);
	if (p.first) return 0;
	if (min(p.second.first, p.second.second) < 0) return 0;
	return 1 ;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1;i <= n;i ++) scanf("%d", &a[i]), a[i] -- ;
	build(1, 1, n) ;
	int T;
	scanf("%d" ,&T) ;
	while (T --)
	{
	int op;
	scanf("%d", &op);
	if (op == 1)
	{
		int l, r, k ;
		scanf("%d%d%d", &l, &r, &k);
		l ++;
		r ++;
		Modify(1, l, r, k);
	}
	else
	{
		int l, r ;
		scanf("%d%d" ,&l, &r);
		puts(Solve( ++ l, ++ r) ? "1" : "0");
	}
	}
	return 0;
}


/*
* C++11 code template for contests.
* @author: Andrei Kalendarov
* @e-mail: andreykalendarov@gmail.com
*/

//#define ANDREIKKAA_ALLOCATOR
const int _ML = 228;

const char _inpf[] =
#if defined(ANDREIKKAA)
    "input.txt"
#else
    ""
#endif
;
const char _outf[] =
#if defined(ANDREIKKAA)
    ""
#else
    ""
#endif
;

#if defined(ANDREIKKAA)
#undef NDEBUG
#else
#pragma GCC optimize("O3,no-stack-protector")
#endif
#include <bits/stdc++.h>
#if !defined(ANDREIKKAA)
#define endl '\n'
#endif
#define x first
#define y second
using namespace std;
#define rand abcdefghijklmnopqrstuvwxyz
#define random_shuffle abcdefghijklmnopqrstuvwxyz
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef double ld;
const ld PI = 3.14159265358979323846;
mt19937 rd(228);
#if defined(ANDREIKKAA_ALLOCATOR)
char _mem[_ML * 1024 * 1024];
size_t _ptr = 0;
inline void* operator new (size_t _x) { _ptr += _x; assert(_ptr < _ML * 1024 * 1024); return _mem + _ptr - _x; }
inline void operator delete (void*) { }
#endif
template<class T, class U> inline ostream &operator<< (ostream &, const pair<T, U> &);
template<class T, class U> inline istream &operator>> (istream &, pair<T, U> &);
template<class T> inline ostream &operator<< (ostream &, const vector<T> &);
template<class T> inline istream &operator>> (istream &, vector<T> &);
template<class T> inline ostream &operator<< (ostream &, const set<T> &);
template<class T> inline ostream &operator<< (ostream &, const multiset<T> &);
template<class T> inline ostream &operator<< (ostream &, const unordered_set<T> &);
template<class T> inline ostream &operator<< (ostream &, const unordered_multiset<T> &);
template<class T, class U> inline ostream &operator<< (ostream &, const map<T, U> &);
template<class T, class U> inline ostream &operator<< (ostream &, const unordered_map<T, U> &);

/* ________ CODE ________ */

const int N = 52;
const int M = 1000 * 1000 * 1000 + 7;
int dp[2][N][N][N][N];
int a[N];
int pww[N];

inline int pw2(int x)
{
    if(x == -1)
    {
        return 1;
    }
    return pww[x];
}

inline int mul(int a, int b)
{
    return (int)((ll)a * b % M);
}

inline void addeq(int &a, int b)
{
    a = (a + b) % M;
}

inline void _main_function()
{
    pww[0] = 1;
    for(int i = 1; i < N; ++i)
    {
        pww[i] = mul(pww[i - 1], 2);
    }

    int n, p;
    cin >> n >> p;
    for(int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }

    dp[1][0][0][0][0] = 1;

    for(int i = 0; i < n; ++i)
    {
        int cur = (i & 1);
        int lst = (~i & 1);
        memset(dp[cur], 0, sizeof dp[cur]);
            for (int be = 0; be <= i; ++be) {
                for (int bo = 0; bo <= i; ++bo) {
                    for (int we = 0; we <= i; ++we) {
                        for (int wo = 0; wo <= i; ++wo) {
                            if (dp[lst][be][bo][we][wo] == 0) {
                                continue;
                            }

                            if (a[i] != 1)
                            {
                                int value = mul(pw2(be + bo + we), pw2(wo - 1));

                                addeq(dp[cur][be][bo + 1][we][wo],
                                      mul(dp[lst][be][bo][we][wo], value);
                                if(wo != 0)
                                {
                                    addeq(dp[cur][be + 1][bo][we][wo],
                                          mul(dp[lst][be][bo][we][wo], value));
                                }

                                //black

                            }
                            if (a[i] != 0)
                            {
                                int value = mul(pw2(we + wo + be), pw2(bo - 1));

                                //white
                                if(bo != 0)
                                {
                                    addeq(dp[cur][be][bo][we + 1][wo],
                                          mul(dp[lst][be][bo][we][wo], value));
                                }
                                addeq(dp[cur][be][bo][we][wo + 1],
                                      mul(dp[lst][be][bo][we][wo], value));
                            }
                        }
                    }
                }
            }
        }

    int cur = ((n - 1) & 1);
    int ans = 0;
    for (int be = 0; be <= n; ++be) {
        for (int bo = 0; bo <= n; ++bo) {
            for (int we = 0; we <= n; ++we) {
                for (int wo = 0; wo <= n; ++wo) {
                    if(((bo + wo) & 1) == p) {
                        addeq(ans, dp[cur][be][bo][we][wo]);
                    }

                }
            }
        }
    }

    cout << ans << endl;

}

/* ________ CODE ________ */

int main()
{
#if defined(ANDREIKKAA)
    time_t _start = clock();
#endif
    if (_inpf[0] != '\0') assert(freopen(_inpf, "r", stdin) != nullptr);
    if (_outf[0] != '\0') assert(freopen(_outf, "w", stdout) != nullptr);
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cout << setprecision(20);
    //cout << fixed;

    _main_function();
#if defined(ANDREIKKAA)
    cout << "Time: " << (clock() - _start) / (ld)CLOCKS_PER_SEC << endl;
#endif
}

template<class T, class U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p)
{
    _out << _p.x << ' ' << _p.y;
    return _out;
}
template<class T, class U> inline istream &operator>> (istream &_in, pair<T, U> &_p)
{
    _in >> _p.x >> _p.y;
    return _in;
}
template<class T> inline ostream &operator<< (ostream &_out, const vector<T> &_v)
{
    if (_v.empty()) { return _out; }
    _out << *_v.begin();
    for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T> inline istream &operator>> (istream &_in, vector<T> &_v)
{
    for (auto &_i : _v) { _in >> _i; }
    return _in;
}
template<class T> inline ostream &operator<< (ostream &_out, const set<T> &_s)
{
    if (_s.empty()) { return _out; }
    _out << *_s.begin();
    for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s)
{
    if (_s.empty()) { return _out; }
    _out << *_s.begin();
    for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s)
{
    if (_s.empty()) { return _out; }
    _out << *_s.begin();
    for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s)
{
    if (_s.empty()) { return _out; }
    _out << *_s.begin();
    for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; }
    return _out;
}
template<class T, class U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m)
{
    if (_m.empty()) { return _out; }
    _out << '(' << _m.begin()->x << ": " << _m.begin()->y << ')';
    for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->x << ": " << _it->y << ')'; }
    return _out;
}
template<class T, class U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m)
{
    if (_m.empty()) { return _out; }
    _out << '(' << _m.begin()->x << ": " << _m.begin()->y << ')';
    for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->x << ": " << _it->y << ')'; }
    return _out;
}


#include "pch.h"
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, h; cin >> n;
	vector <int> street(n, -1);
	for (int i = 0; i < m; i++)
	{
		int l, r, x; cin >> l >> r >> x;
		for (int t = l; t <= r; t++)
			street[t] = x;
	}
	ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (street[i] == -1) street[i] = h;
		ans += street[i] * street[i];
	}
	cout << ans;
}


#include <iostream>
#include <string>
using namespace std;

int     n,m,kth;
int     f[1<<10][1<<10];
bool    graph[10][10];

void    init()
{
        cin>>n>>m>>kth;
        memset(graph,0,sizeof(graph));
        int x,y;
        for (int i=1; i<=m; i++)
        {
                cin>>x>>y;
                --x; --y;
                graph[x][y]=graph[y][x]=true;
        }
}

int     check(int state)
{
        int tot=0;
        for (int i=0; i<n; i++)
                if (state&(1<<i)) tot++;
        return tot;
}

void    slove()
{
        for (int i=0; i<n; i++)
                for (int j=0; j<n; j++)
                        if (graph[i][j])
                               f[(1<<i)+(1<<j)][(1<<i)+(1<<j)]=1;
        int N=1<<n;
        for (int i=0; i<N; i++)
                if (check(i)>2)
                        for (int j=1; j<N; j++)
                        {
                                if ((i&j)!=j) continue;
                                for (int x=0; x<n; x++)
                                        if (i&(1<<x))
                                        {
                                                for (int y=0; y<n; y++)
                                                        if ((i&(1<<y)) && !(j&(1<<y)) && graph[y][x])
                                                                f[i][j]+=f[i-(1<<x)][j-(1<<x)]+f[i-(1<<x)][j-(1<<x)+(1<<y)];
                                                if (f[i][j]!=0) break;
                                        }
                        }
        int ans=0;
        for (int i=0; i<N; i++)
                if (check(i)==kth) ans+=f[N-1][i];
        cout<<ans<<endl;
}

int     main()
{
    //freopen("E.in","r",stdin);
        init();
        slove();
}


#include <bits/stdc++.h>

#define pb push_back
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
#define rep(i,x,y) for(long long i=x;i<=y;++i)
#define repr(i,x,y) for(long long i=x;i>=y;--i)

typedef long long ll;

using namespace std;

const ll N = (ll)(5e5) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;

int dp[45][1 << 21], n, m, p[45][300], ans;
bool was[45][1 << 21];

char ch[111][111];

void print(int mask) {
	repr(i, n - 1, 0) cout << (bool)(mask & (1 << i));
	cout << ' ';
}

int calc(int pos, int mask) {
	if (pos == n + n - 1) {
		if (ch[n][n] == 'a') return 1;
		if (ch[n][n] == 'b') return -1;
		return 0;
	}
	int &res = dp[pos][mask];
	if (was[pos][mask]) return res;
	was[pos][mask] = 1;
	if (pos & 1) res = INF;
	else res = -INF;
	for(char c = 'a'; c <= 'z'; ++c) {
		int nxt;
		if (pos < n) nxt = ((mask | (mask << 1)) & p[pos + 1][c]);
		else nxt = ((mask | (mask >> 1)) & p[pos + 1][c]);
		int cur = calc(pos + 1, nxt);
		if (!nxt || cur > 100 || cur < -100) continue;
		int pl = 0;
		if (c == 'a') pl++;
		if (c == 'b') pl--;
		if (pos & 1) res = min(res, cur + pl);
		else res = max(res, cur + pl);
	}
	return res;
}

int main () {
	ios_base :: sync_with_stdio (false); cin.tie(0);
//	freopen(fname".in", "r", stdin);
	//freopen(fname".out", "w", stdout);
	cin >> n;
	rep(i, 1, n) rep(j, 1, n) cin >> ch[i][j];
	rep(i, 1, n) rep(j, 1, n)
	if (i + j - 1 >= n)p[i + j - 1][ch[i][j]] |= (1 << (n - i));
	else p[i + j - 1][ch[i][j]] |= (1 << (j - 1));
	int pl = 0;
	if (ch[1][1] == 'a') pl = 1;
	if (ch[1][1] == 'b') pl = -1;
	ans = calc(1, 1) + pl
	if (ans == 0) cout << "DRAW";
	if (ans > 0) cout << "FIRST";
	if (ans < 0) cout << "SECOND";
	return 0;
}


/*
117B.cpp
By Mr.Yong
2011/10/15
*/

#include<iostream>
#include<string>
using namespace std;

bool CanBeDiv(char str[],int mod)
{
    int Carry=0;
    int i=0;
    while(str[i]!='\0')
    {
        Carry=(Carry*10+str[i]-'0')%mod;
        i++;
    }
    if(Carry==0)return true;
    return false;
}

bool Str1lessStr2(char str1[], char str2[])
{
    for(int i=0;i<9;i++)
    {
        if(str1[i]<str2[i])return true;
        if(str2[i]<str1[i])return false;
    }
    return false;
}

void InttoChar(char str[],int i)
{
    int j=8;
    while(i)
    {
        str[j--]=i%10+'0';
        i=i/10;
    }
}
void Strcpy2(char str1[],char str2[],char str3[])
{
    for(int i=0;i<9;i++)
        str3[i]=str1[i];
    for(int j=0;j<10;j++)
        str3[j+9]=str2[j];
}
void Game(char str1[],char str2[],int a,int b ,int mod,char strtemp[])
{
    char str3[19];
    bool found=false;
    int i,j;
    for(i=0;i<=a;i++)
    {
        for(j=0;j<=b;j++)
        {
            InttoChar(str1,i);
            InttoChar(str2,j);
            Strcpy2(str1,str2,str3);
            if(CanBeDiv(str3,mod)){break;}
            Strcpy2(str2,str1,str3);
            if(CanBeDiv(str3,mod)){break;}
        }
        if(j>b&&Str1lessStr2(str1,strtemp)){strcpy(strtemp,str1);found=true;}
    }
    if(found){cout<<"1"<<" "<<strtemp<<endl;}
    else
        cout<<"2"<<endl;
}
int main()
{
    int  a , b ,mod;
    char str1[10],str2[10],strtemp[10];
    while(cin>>a>>b>>mod)
    {
        for(int i=0;i<9;i++)
        {
            str1[i]='0';
            str2[i]='0';
            strtemp[i]='9';
        }
        str1[9]='\0';
        str2[9]='\0';
        strtemp[9]='\0';
        Game(str1,str2,a,b,mod,strtemp);
    }
    return 0;
}