/** Micro Mezzo Macro Flation -- Overheated Economy ., Last Update: Dec. 24th 2012 **/ //{

/** Header .. **/ //{
#define LOCAL

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define REP(i, n) for (int i=0;i<int(n);++i)
#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)
#define REP_1(i, n) for (int i=1;i<=int(n);++i)
#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)
#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)
#define REP_C(i, n) for (int n____=int(n),i=0;i<n____;++i)
#define FOR_C(i, a, b) for (int b____=int(b),i=a;i<b____;++i)
#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i>=a____;--i)
#define REP_N(i, n) for (i=0;i<int(n);++i)
#define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)
#define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)
#define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i)
#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i)
#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i)
#define REP_1_N(i, n) for (i=1;i<=int(n);++i)
#define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)
#define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)
#define REP_C_N(i, n) for (int n____=(i=0,int(n));i<n____;++i)
#define FOR_C_N(i, a, b) for (int b____=(i=0,int(b);i<b____;++i)
#define DWN_C_N(i, b, a) for (int a____=(i=b-1,int(a));i>=a____;--i)
#define REP_1_C_N(i, n) for (int n____=(i=1,int(n));i<=n____;++i)
#define FOR_1_C_N(i, a, b) for (int b____=(i=1,int(b);i<=b____;++i)
#define DWN_1_C_N(i, b, a) for (int a____=(i=b,int(a));i>=a____;--i)

#define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)
#define REP_S(i, str) for (char*i=str;*i;++i)
#define REP_L(i, hd, nxt) for (int i=hd;i;i=nxt[i])
#define REP_G(i, u) REP_L(i,hd[u],suc)
#define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)
#define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)
#define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)

#define ALL(A) A.begin(), A.end()
#define LLA(A) A.rbegin(), A.rend()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#define BSC(A, x) (lower_bound(ALL(A), x) - A.begin())
#define CTN(T, x) (T.find(x) != T.end())
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)
#define PTT pair<T, T>
#define fi first
#define se second

#define Rush for(int ____T=RD(); ____T--;)

#define Display(A, n, m) {                      \
	REP(i, n){		                            \
        REP(j, m) cout << A[i][j] << " ";       \
        cout << endl;				            \
	}						                    \
}

#define Display_1(A, n, m) {				    \
	REP_1(i, n){		                        \
        REP_1(j, m) cout << A[i][j] << " ";     \
		cout << endl;		            		\
	}						                    \
}

#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize ("O2")
#define Ruby system("ruby main.rb")
#define Haskell system("runghc main.hs")
#define Python system("python main.py")
#define Pascal system("fpc main.pas")

typedef long long LL;
//typedef long double DB;
typedef double DB;
typedef unsigned UINT;
typedef unsigned long long ULL;

typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<DB> VF;
typedef set<int> SI;
typedef set<string> SS;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

template<class T> inline T& RD(T &);
template<class T> inline void OT(const T &);
inline LL RD(){LL x; return RD(x);}
inline DB& RF(DB &);
inline DB RF(){DB x; return RF(x);}
inline char* RS(char *s);
inline char& RC(char &c);
inline char RC();
inline char& RC(char &c){scanf(" %c", &c); return c;}
inline char RC(){char c; return RC(c);}
//inline char& RC(char &c){c = getchar(); return c;}
//inline char RC(){return getchar();}

template<class T> inline T& RDD(T &x){
    char c; for (c = getchar(); c < '-'; c = getchar());
    if (c == '-'){x = '0' - getchar(); for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + '0' - c;}
    else {x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';}
    return x;
}

inline LL RDD(){LL x; return RDD(x);}

template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
inline char& RC(char &a, char &b){RC(a), RC(b); return a;}
inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}
inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}
inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}
template<class T0,class T1>inline void RDD(const T0&a, const T1&b){RDD(a),RDD(b);}
template<class T0,class T1,class T2>inline void RDD(const T0&a, const T1&b, const T2&c){RDD(a),RDD(b),RDD(c);}

template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}
template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}
template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}
template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}
template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);}
template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);}
template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);}
template<class T> inline void CLR(priority_queue<T, vector<T>, less<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T> inline void CLR(T &A){A.clear();}
template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}
template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}
template<class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}
template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}

template<class T> inline T& SRT(T &A){sort(ALL(A)); return A;}
template<class T, class C> inline T& SRT(T &A, C B){sort(ALL(A), B); return A;}
template<class T> inline T& UNQ(T &A){A.resize(unique(ALL(SRT(A)))-A.begin());return A;}

//}

/** Constant List .. **/ //{

const int MOD = 1000000007;
//int MOD = 99990001;
const int INF = 0x3f3f3f3f;
const LL INFF = 1LL << 60;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

//}

/** Add On .. **/ //{
// <<= '0. Nichi Joo ., //{
template<class T> inline void checkMin(T &a,const T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a,const T b){if (a<b) a=b;}
template<class T> inline void checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);}
template<class T> inline void checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);}
template <class T, class C> inline void checkMin(T& a, const T b, C c){if (c(b,a)) a = b;}
template <class T, class C> inline void checkMax(T& a, const T b, C c){if (c(a,b)) a = b;}
template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T cub(T a){return a*a*a;}
inline int ceil(int x, int y){return (x - 1) / y + 1;}
inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
inline int sgn(DB x, DB y){return sgn(x - y);}
//}
// <<= '1. Bitwise Operation ., //{
namespace BO{

inline bool _1(int x, int i){return bool(x&1<<i);}
inline bool _1(LL x, int i){return bool(x&1LL<<i);}
inline LL _1(int i){return 1LL<<i;}
inline LL _U(int i){return _1(i) - 1;};

inline int reverse_bits(int x){
    x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);
    x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);
    x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);
    x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);
    x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000);
    return x;
}

inline LL reverse_bits(LL x){
    x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);
    x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);
    x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);
    x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);
    x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL);
    x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL);
    return x;
}

template<class T> inline bool odd(T x){return x&1;}
template<class T> inline bool even(T x){return !odd(x);}
template<class T> inline T low_bit(T x) {return x & -x;}
template<class T> inline T high_bit(T x) {T p = low_bit(x);while (p != x) x -= p, p = low_bit(x);return p;}
template<class T> inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;}

inline int low_idx(int x){return __builtin_ffs(x);}
inline int low_idx(LL x){return __builtin_ffsll(x);}
inline int high_idx(int x){return low_idx(reverse_bits(x));}
inline int high_idx(LL x){return low_idx(reverse_bits(x));}
inline int clz(int x){return __builtin_clz(x);}
inline int clz(LL x){return __builtin_clzll(x);}
inline int ctz(int x){return __builtin_ctz(x);}
inline int ctz(LL x){return __builtin_ctzll(x);}
inline int parity(int x){return __builtin_parity(x);}
inline int parity(LL x){return __builtin_parityll(x);}
inline int lg2(int a){return 31 - clz(a);}
inline int lg2(LL a){return 63 - clz(a);}
inline int count_bits(int x){return __builtin_popcount(x);}
inline int count_bits(LL x){return __builtin_popcountll(x);}

} using namespace BO;//}
// <<= '2. Number Theory .,//{
namespace NT{
inline LL __lcm(LL a, LL b){return a*b/__gcd(a,b);}
inline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;}
inline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;}
inline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;}
inline int dff(int a, int b){a -= b; if (a < 0) a  += MOD; return a;}
inline void MUL(int &a, int b){a = (LL)a * b % MOD;}
inline int pdt(int a, int b){return (LL)a * b % MOD;}

inline int sum(int a, int b, int c){return sum(sum(a, b), c);}
inline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));}
inline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);}
inline int pdt(int a, int b, int c, int d){return pdt(pdt(pdt(a, b), c), d);}

inline int pow(int a, int b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

inline int pow(int a, LL b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

template<class T> inline T pow(T a, LL b){
    T c(1); while (b){
        if (b&1) c *= a;
        a *= a, b >>= 1;
    }
    return c;
}

inline int _I(int b){
    int a = MOD, x1 = 0, x2 = 1, q;
    while (true){
        q = a / b, a %= b;
        if (!a) return (x2 + MOD) % MOD;
        DEC(x1, pdt(q, x2));

        q = b / a, b %= a;
        if (!b) return (x1 + MOD) % MOD;
        DEC(x2, pdt(q, x1));
    }
}

inline void DIV(int &a, int b){MUL(a, _I(b));}
inline int qtt(int a, int b){return pdt(a, _I(b));}

inline int phi(int n){
    int res = n; for (int i=2;sqr(i)<=n;++i) if (!(n%i)){
        DEC(res, qtt(res, i));
        do{n /= i;} while(!(n%i));
    }
    if (n != 1)
        DEC(res, qtt(res, n));
    return res;
}

} using namespace NT;//}

namespace SL{
    namespace KMP{

        void calc_pi(const char *P, int n, int *pi){
            for (int i = 1, j = pi[0] = -1; i < n; ++i){
                while (j >= 0 && P[i] != P[j+1]) j = pi[j];
                if (P[i] == P[j+1]) ++j;
                pi[i] = j;
            }
            //REP(i, n) cout << pi[i] << " "; cout << endl;
        }

        bool run(const char *T, int n, const char *P, int m, const int *pi){
            for (int i = 0, j = -1; i < n; ++i){
                while (j >= 0 && T[i] != P[j+1]) j = pi[j];
                if (T[i] == P[j+1]) ++j;
                if (j == m - 1) return true;
            }
            return false;
        }

    } //using namespace KMP;

    namespace Z{
        void calc_z(const char *P, int n, int *z){

            z[0] = n;

            for (int i = 1, l = 0, r = 0; i < n; ++i){
                if (i > r){
                    for(l = r = i; r < n && P[r] == P[r - l];) ++r;
                    z[i] = r - l, --r;
                }
                else {
                    if (z[i - l] < r - i + 1) z[i] = z[i - l];
                    else {
                        for (l = i;r < n && P[r] == P[r - l];) ++r;
                        z[i] = r - l, --r;
                    }
                }
            }

            //REP(i, n) cout << z[i] << " "; cout << endl;
        }

        int run(const char *T, int n, const char *P, int m, const int *z){

            int ex; REP_C_N(ex, min(n, m)) if (T[ex] != P[ex]) break;

            int res = ex == m;

            for (int i = 1, l = 0, r = 0; i < n; ++i){
                if (i > r){
                    for (l = r = i; r < n && T[r] == P[r - l];) ++r;
                    ex = r - l, --r;
                }
                else {
                    if (z[i - l] < r - i + 1) ex = z[i - l];
                    else {
                        for (l = i; r < n && T[r] == P[r - l];) ++r;
                        ex = r - l, --r;
                    }
                }
                if (ex == m) ++res;
            }

            return res;
        }
    } //using namespace Z;

    void Manacher(char s[], int n, int p[]){
        const int NN = 0;
        static char ss[NN*2+2]; int nn = 2*n+2;
        ss[0] = '$', ss[nn-1] = '#', ss[nn] = 0;
        REP(i, n) ss[i*2+1] ='#', ss[i*2+2] = s[i];
        int mx = 0, id = 0; FOR(i, 1, nn){
            p[i] = mx > i ? min(p[2*id-i], mx - i) : 1;
            while (ss[i+p[i]] == ss[i-p[i]]) ++p[i];
            if (i + p[i] > mx) mx = i + p[i], id = i;
        }
    }

} //using namespace SL;//}
// <<= '9. Comutational Geometry .,//{
namespace CG{

struct Po; struct Line; struct Seg;

struct Po{
    DB x, y; Po(DB _x=0, DB _y=0):x(_x), y(_y){}
    friend istream& operator >>(istream& in, Po &p){return in >> p.x >> p.y;}
    friend ostream& operator <<(ostream& out, Po p){return out << "(" << p.x << ", " << p.y << ")";}
    bool operator ==(const Po& r)const{return !sgn(x-r.x) && !sgn(y-r.y);};
    bool operator !=(const Po& r)const{return sgn(x-r.x) || sgn(y-r.y);}
    Po operator +(const Po& r)const{return Po(x+r.x, y+r.y);}
    Po operator -(const Po& r)const{return Po(x-r.x, y-r.y);}
    Po operator *(DB k)const{return Po(x*k,y*k);}
    Po operator /(DB k)const{return Po(x/k,y/k);}
    DB operator *(const Po&) const;
    DB operator ^(const Po&) const;

    bool operator <(const Po &r) const{return sgn(x,r.x)<0||!sgn(x,r.x)&&sgn(y,r.y)<0;}
    Po operator -()const{return Po(-x,-y);}
    Po& operator +=(const Po &r){x+=r.x,y+=r.y;return *this;}
    Po& operator -=(const Po &r){x-=r.x,y-=r.y;return *this;}
    Po& operator *=(DB k){x*=k,y*=k;return*this;}
    Po& operator /=(DB k){x/=k,y/=k;return*this;}

    DB length_sqr()const{return sqr(x)+sqr(y);}
    DB length()const{return sqrt(length_sqr());}
    Po unit()const{return *this/length();}
    bool dgt()const{return !sgn(x)&&!sgn(y);}
    DB atan()const{return atan2(y,x);}
    void rotate(DB alpha, const Po& o = Po()){
        x -= o.x, y -= o.y;
        (*this) = Po(x * cos(alpha) - y * sin(alpha), y * cos(alpha) + x * sin(alpha)) + o;
    }

    void input(){RF(x,y);}
};

Po operator *(DB k, Po a){return a * k;}

#define innerProduct dot
#define scalarProduct dot
#define outerProduct det
#define crossProduct det

inline DB dot(const DB &x1, const DB &y1, const DB &x2, const DB &y2){return x1 * x2 + y1 * y2;}
inline DB dot(const Po &a, const Po &b){return dot(a.x, a.y, b.x, b.y);}
inline DB dot(const Po &p0, const Po &p1, const Po &p2){return dot(p1 - p0, p2 - p0);}

inline DB det(const DB &x1, const DB &y1, const DB &x2, const DB &y2){return x1 * y2 - x2 * y1;}
inline DB det(const Po &a, const Po &b){return det(a.x, a.y, b.x, b.y);}
inline DB det(const Po &p0, const Po &p1, const Po &p2){return det(p1 - p0, p2 - p0);}

DB Po::operator *(const Po &r)const{return dot(*this, r);}
DB Po::operator ^(const Po &r)const{return det(*this, r);}

struct Line{
    Po a, b;
    Line(DB x0=0, DB y0=0, DB x1=0, DB y1=0):a(Po(x0, y0)), b(Po(x1, y1)){}
    Line(const Po &a, const Po &b):a(a), b(b){}
    Line(const Line &l):a(l.a), b(l.b){}

    friend ostream& operator <<(ostream& out, Line p){return out << p.a << "-" << p.b;}
    Line operator +(Po x)const{return Line(a + x, b + x);}
    DB length()const{return (b-a).length();}
    bool dgt()const{return (b-a).dgt();}
    void input(){a.input(), b.input();}
    void getequation(DB, DB, DB) const;
};

struct Seg: Line{
};

inline DB dot(const Line &l1, const Line &l2){return dot(l1.b - l1.a, l2.b - l2.a);}
inline DB det(const Line &l1, const Line &l2){return det(l1.b - l1.a, l2.b - l2.a);}

void Line::getequation(DB A, DB B, DB C) const{
    A = a.y - b.y, B = b.x - a.x, C = det(a, b);
}

template<class T1, class T2> inline DB dist(const T1 &x, const T2 &y){return sqrt(dist_sqr(x, y));}
template<class T1, class T2, class T3> inline DB dist(const T1 &x, const T2 &y, const T3 &z){return sqrt(dist_sqr(x, y, z));}

template<class T1, class T2> inline int dett(const T1 &x, const T2 &y){return sgn(det(x, y));}
template<class T1, class T2> inline int dott(const T1 &x, const T2 &y){return sgn(dot(x, y));}
template<class T1, class T2, class T3> inline int dett(const T1 &x, const T2 &y, const T3 &z){return sgn(det(x, y, z));}
template<class T1, class T2, class T3> inline int dott(const T1 &x, const T2 &y, const T3 &z){return sgn(dot(x, y, z));}
template<class T1, class T2, class T3, class T4> inline int dett(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(det(x, y, z, w));}
template<class T1, class T2, class T3, class T4> inline int dott(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(dot(x, y, z, w));}

inline DB dist_sqr(const DB &x, const DB &y){return sqr(x) + sqr(y);}
inline DB dist_sqr(const DB &x, const DB &y, const DB &z){return sqr(x) + sqr(y) + sqr(z);}
inline DB dist_sqr(const Po &a, const Po &b){return sqr(a.x - b.x) + sqr(a.y - b.y);}
inline DB dist_sqr(const Po &p, const Line &l){Po v0 = l.b - l.a, v1 = p - l.a; return sqr(fabs(det(v0, v1))) / v0.length_sqr();}
inline DB dist_sqr(const Po &p, const Seg &l){
    Po v0 = l.b - l.a, v1 = p - l.a, v2 = p - l.b;
    if (sgn(dot(v0, v1)) * sgn(dot(v0, v2)) <= 0) return dist_sqr(p, Line(l));
    else return min(v1.length_sqr(), v2.length_sqr());
}
inline DB dist_sqr(Line l, Po p){return dist_sqr(p, l);}
inline DB dist_sqr(Seg l, Po p){return dist_sqr(p, l);}
inline DB dist_sqr(Line l1, Line l2){
    if (sgn(det(l1, l2)) != 0) return 0;
    return dist_sqr(l1.a, l2);
}
inline DB dist_sqr(Line l1, Seg l2){
    Po v0 = l1.b - l1.a, v1 = l2.a - l1.a, v2 = l2.b - l1.a; DB c1 = det(v0, v1), c2 = det(v0, v2);
    return sgn(c1) != sgn(c2) ? 0 : sqr(min(fabs(c1), fabs(c2))) / v0.length_sqr();
}

bool isIntersect(Seg l1, Seg l2){

    if (l1.a == l2.a || l1.a == l2.b || l1.b == l2.a || l1.b == l2.b) return true;

    return
        min(l1.a.x, l1.b.x) <= max(l2.a.x, l2.b.x) &&
        min(l2.a.x, l2.b.x) <= max(l1.a.x, l1.b.x) &&
        min(l1.a.y, l1.b.y) <= max(l2.a.y, l2.b.y) &&
        min(l2.a.y, l2.b.y) <= max(l1.a.y, l1.b.y) &&
    sgn( det(l1.a, l2.a, l2.b) ) * sgn( det(l1.b, l2.a, l2.b) ) <= 0 &&
    sgn( det(l2.a, l1.a, l1.b) ) * sgn( det(l2.b, l1.a, l1.b) ) <= 0;

}

inline DB dist_sqr(Seg l1, Seg l2){
    if (isIntersect(l1, l2)) return 0;
    else return min(dist_sqr(l1.a, l2), dist_sqr(l1.b, l2), dist_sqr(l2.a, l1), dist_sqr(l2.b, l1));
}

inline bool isOnSide(const Po &p, const Seg &l){
    return p == l.a || p == l.b;
}

inline bool isOnSeg(const Po &p, const Seg &l){
    return sgn(det(p, l.a, l.b)) == 0 &&
        sgn(l.a.x, p.x) * sgn(l.b.x, p.x) <= 0 && sgn(l.a.y, p.y) * sgn(l.b.y, p.y) <= 0;
}

inline bool isOnSegg(const Po &p, const Seg &l){
    return sgn(det(p, l.a, l.b)) == 0 &&
        sgn(l.a.x, p.x) * sgn(l.b.x, p.x) < 0 && sgn(l.a.y, p.y) * sgn(l.b.y, p.y) < 0;
}

inline Po intersect(const Line &l1, const Line &l2){
    return l1.a + (l1.b - l1.a) * (det(l2.a, l1.a, l2.b) / det(l2, l1));
}

// perpendicular foot
inline Po intersect(const Po & p, const Line &l){
    return intersect(Line(p, p + Po(l.a.y - l.b.y, l.b.x - l.a.x)), l);
}

inline Po rotate(Po p, DB alpha, const Po &o = Po()){
    p.rotate(alpha, o);
    return p;
}

} using namespace CG;//}
//}

/** I/O Accelerator Interface .. **/ //{
template<class T> inline T& RD(T &x){
    //cin >> x;
    scanf("%d", &x);
    //char c; for (c = getchar(); c < '0'; c = getchar()); x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
    //char c; c = getchar(); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';
    return x;
}

inline DB& RF(DB &x){
    scanf("%lf", &x);
    /*char t; while ((t=getchar())==' '||t=='\n'); x = t - '0';
    while ((t=getchar())!=' '&&t!='\n'&&t!='.')x*=10,x+=t-'0';
    if (t=='.'){DB l=1; while ((t=getchar())!=' '&&t!='\n')l*=0.1,x += (t-'0')*l;}*/
    return x;
}

inline char* RS(char *s){
    //gets(s);
    scanf("%s", s);
    return s;
}

int Case; template<class T> inline void OT(const T &x){
    //printf("Case %d: %d\n", ++Case, x);
    //printf("%.2lf\n", x);
    printf("%d\n", x);
    //cout << x << endl;
}
//}

//}/* .................................................................................................................................. */

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int,double> PIF;

struct line{
    Po x, y;

    line(){}
    line(Po _x,Po _y):x(_x),y(_y){}

    void input(){x.input(), y.input();}
};

struct node{
    string c;vector<int> a;double sz;
    node(string _c,double _sz=0):c(_c),sz(_sz){}
    void add(int x){a.pb(x);}
};

    Po med(Po a,Po b,Po c)
    {
            /*if(a<b)if(b<c)return b;else if(a<c)return c;else return a;
            else if(a<c)return a;else if(b<c)return c;else return b;*/
            return __median(a, b, c);
    }
    int getcrs(line a,line b,Po&c)
    {
            double A=a.y.y-a.x.y,B=a.x.x-a.y.x,C=a.x.x*A+a.x.y*B;
            double D=b.y.y-b.x.y,E=b.x.x-b.y.x,F=b.x.x*D+b.x.y*E;
            if(fabs(A*E-B*D)<EPS)return -1;
            c=Po((C*E-F*B)/(A*E-D*B),(C*D-F*A)/(B*D-E*A));
            if(med(a.x,a.y,c)!=c||med(b.x,b.y,c)!=c)return -1;
            return 0;
    }
    bool online(Po p,line a)
    {
            if(med(a.x,a.y,p)!=p)return 0;
            double A=a.y.y-a.x.y,B=a.x.x-a.y.x,C=a.x.x*A+a.x.y*B;
            return abs(A*p.x+B*p.y-C)<EPS;
    }
    double ang(Po a,Po b)
    {
            double S=atan2(b.y-a.y,b.x-a.x)*180/PI;
            if(S<EPS)S+=360;
            return S;
    }
    bool cmpid(const PIF&a,const PIF&b){return a.fi<b.fi;}
    bool equid(const PIF&a,const PIF&b){return a.fi==b.fi;}
    bool cmpang(const PIF&a,const PIF&b){return a.se<b.se;}
    double getsz(vector<Po> p)
    {
            double S=0;
            for(int i=0;i<(int)p.size();i++)
            {
                    int j=(i+1)%(int)p.size();
                    S+=p[i].x*p[j].y-p[j].x*p[i].y;
            }
            return -S/2;
    }
    double crs(Po a,Po b,Po c)
    {
            return (b.y-a.y)*(c.x-a.x)-(b.x-a.x)*(c.y-a.y);
    }
    int inpoly(Po p,vector<Po> a)
    {
            int n=(int)a.size();a.pb(a[0]);
            for(int i=0;i<n;i++)
                    if(online(p,line(a[i],a[i+1])))return 0;
            int w=0;
            for(int i=0;i<n;i++)
                    if(a[i].y<=p.y&&a[i+1].y>p.y&&crs(a[i],a[i+1],p)<0)++w;else
                    if(a[i].y>p.y&&a[i+1].y<=p.y&&crs(a[i],a[i+1],p)>0)--w;
            return w;
    }
    int w,h,n,m,p;

    vector<Po> po;
    vector<vector<PIF> > pa;
    vector<node> gr;
    vector<int> bl;
    vector<Po> fl;
    vector<vector<Po> > pl;

    void bfs(int x,string c)
    {
            string d=gr[x].c;
            queue<int> q;vector<bool> v((int)gr.size(),0);
            v[x]=1,q.push(x);
            while(!q.empty())
            {
                    int x=q.front();q.pop();
                    gr[x].c=c;
                    for(int i=0;i<(int)gr[x].a.size();i++)
                            if(!v[gr[x].a[i]]&&gr[gr[x].a[i]].c==d)
                                    q.push(gr[x].a[i]),v[gr[x].a[i]]=1;
            }
    }
    int main()
    {

        #ifndef ONLINE_JUDGE
            freopen("in.txt", "r", stdin);
            //freopen("out.txt", "w", stdout);
        #endif

            RD(w, h, n);

            vector<line> l0(n);

            REP(i, n) l0[i].input();

            //for(int i=0;i<n;i++)l0[i].get();
            for(int i=0;i<n;i++)po.pb(l0[i].x),po.pb(l0[i].y);
            for(int i=0;i<n;i++)
                    for(int j=i+1;j<n;j++)
                    {
                            Po p;
                            if(getcrs(l0[i],l0[j],p)!=-1)po.pb(p);
                    }
            sort(po.begin(),po.end()),
            po.erase(unique(po.begin(),po.end()),po.end());
            m=(int)po.size();
            pa.resize(m);

            for(int i=0;i<n;i++)
            {
                    vector<int> vp;
                    for(int j=0;j<m;j++)
                            if(online(po[j],l0[i]))vp.pb(j);
                    for(int j=1;j<(int)vp.size();j++)
                            pa[vp[j-1]].pb(mp(vp[j],ang(po[vp[j-1]],po[vp[j]]))),
                            pa[vp[j]].pb(mp(vp[j-1],ang(po[vp[j]],po[vp[j-1]])));
            }

            for(int i=0;i<m;i++)
                    sort(pa[i].begin(),pa[i].end(),cmpid),
                    pa[i].erase(unique(pa[i].begin(),pa[i].end(),equid),pa[i].end()),
                    sort(pa[i].begin(),pa[i].end(),cmpang);
            gr.pb(node("white",w*h));
            fl.pb(Po(0.0,0.0));
            bl.resize(m,-1);
            for(int i=0;i<m;i++)if(bl[i]==-1)
            {
                    queue<int> q;
                    q.push(i);
                    gr.pb(node("black",0.0));
                    bl[i]=++p,fl.pb(po[i]);
                    while(!q.empty())
                    {
                            int x=q.front();q.pop();
                            for(int j=0;j<(int)pa[x].size();j++)
                                    if(bl[pa[x][j].fi]==-1)
                                            q.push(pa[x][j].fi),
                                            bl[pa[x][j].fi]=p;
                    }
            }
            pl.resize(p+1);
            vector<vector<bool> > chk(m);
            for(int i=0;i<m;i++)chk[i].resize((int)pa[i].size(),0);
            for(int i=0;i<m;i++)
                    for(int j=0;j<(int)pa[i].size();j++)
                    {
                            if(chk[i][j])continue;
                            vector<Po> vp;
                            int i0=i,j0=j;
                            while(!chk[i0][j0])
                            {
                                    vp.pb(po[i0]);
                                    chk[i0][j0]=1;
                                    int i1=pa[i0][j0].fi,j1=-1;
                                    for(int j=0;j<(int)pa[i1].size();j++)
                                            if(pa[i1][j].fi==i0){j1=(j+1)%(int)pa[i1].size();break;}
                                    i0=i1,j0=j1;
                            }
                            double sz=getsz(vp);
                            if(sz>0)
                            {
                                    pl.pb(vp);
                                    gr.pb(node("white",sz));
                                    int r=bl[i];
                                    gr[r].add((int)gr.size()-1),
                                    gr[(int)gr.size()-1].add(r);
                                    gr[r].sz-=sz;
                            }
                    }
            for(int i=1;i<=p;i++)
            {
                    int fa=0;
                    for(int j=(int)pl.size()-1;j>p;j--)
                            if(inpoly(fl[i],pl[j])){fa=j;break;}
                    gr[fa].add(i),gr[i].add(fa),gr[fa].sz+=gr[i].sz,gr[i].sz=0;
            }

        int _;scanf("%d",&_);
        while(_--){

            Po x; x.input();string c;char s[100];scanf("%s",s),c=s;

            for(int i=0;i<m;i++)
                for(int j=0;j<(int)pa[i].size();j++)

            if(online(x,line(po[i],po[pa[i][j].fi]))){bfs(bl[i],c);goto end;}
            for(int i=(int)pl.size()-1;i>p;i--)
                if(inpoly(x,pl[i])){bfs(i,c);goto end;}
            bfs(0,c);
            end:;
        }

        map<string,double> S;
        for(int i=0;i<(int)gr.size();i++)
            S[gr[i].c]+=gr[i].sz;
        //for(map<string,double>::iterator i=S.begin();i!=S.end();i++)

    ECH(it, S){
        printf("%s %.9lf\n", it->first.c_str(), it->second);
    }
    return 0;
}


# include <iostream>
# include <queue>
# include <cmath>
# include <algorithm>
# include <cstring>
using namespace std;

char s1[1000],s2[1000];

int dp[500][210][210];

struct Node{
	int pi,pj,pk;
	char c;
}ans[500][210][210];

const int inf = 1e9;

void dfs(int k,int i,int j)
{
	// cout<<k<<" "<<i<<" "<<j<<endl;
	if (i==0&&j==0&&k==0) return ;
	struct Node a = ans[k][i][j];
	dfs(a.pk,a.pi,a.pj);
	printf("%c",a.c);
}

int main(void)
{
	// freopen("aaa.in","r",stdin);
	scanf("%s",s1);
	scanf("%s",s2);
	int len1=strlen(s1),len2=strlen(s2);
	// cout<<len1<<endl;
	for (int i=0;i<=len1;i++)
		for (int j=0;j<=len2;j++)
			for (int k=0;k<=400;k++)
				dp[k][i][j] = inf;

	dp[0][0][0] = 0;
	for (int i=0;i<=len1;i++)
		for (int j=0;j<=len2;j++)
			for (int k=0;k<=400;k++)
			{
				if (dp[k][i][j]==inf) continue;

				int li = i+((s1[i]=='(')?1:0);
				int lj = j+((s2[j]=='(')?1:0);
				if (dp[k+1][li][lj]>dp[k][i][j]+1)
				{
					ans[k+1][li][lj].pi = i;
					ans[k+1][li][lj].pj = j;
					ans[k+1][li][lj].pk = k;
					ans[k+1][li][lj].c = '(';
					dp[k+1][li][lj] = dp[k][i][j]+1;
				}
				li = i+((s1[i]==')')?1:0);
				lj = j+((s2[j]==')')?1:0);
				if (k>0 && dp[k-1][li][lj]>dp[k][i][j]+1)
				{
					ans[k-1][li][lj].pi = i;
					ans[k-1][li][lj].pj = j;
					ans[k-1][li][lj].pk = k;
					ans[k-1][li][lj].c = ')';
					dp[k-1][li][lj] = dp[k][i][j]+1;
				}
			}
	int an = dp[0][len1][len2],ph = 0;
	for (int i=0;i<=400;i++)
	{
		if (dp[i][len1][len2]+i<an)
		{
			an = dp[i][len1][len2]+i;
			ph = i;
		}
	}
	dfs(ph,len1,len2);
	for (int i=1;i<=ph;i++) printf(')');
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7,M=20; bool fl[N],rev[N],tg;
int n,k,va,vb,opt,tot,q[N],w[N],h[N],dp[N],gt[N],ft[N],fa[N],st[N],col[N],dep[N],cnt[N],e[N][M]; vector<int>v[N],vw[N]; vector<pair<int,int>>f[N];
struct edge {int u,t;}g[N];
inline int read(){
	int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); return num;
}
inline int lca(int u,int t){
	if(dep[u]<dep[t]) swap(u,t); int z=dep[u]-dep[t];
	for(int i=19;i>=0;i--) if((1<<i)&z) u=e[u][i]; if(u==t) return u;
	for(int i=19;i>=0;i--) if(e[u][i]!=e[t][i]) u=e[u][i],t=e[t][i]; return fa[u];
}
inline int jmp(int u,int t){
	for(int i=19;i>=0;i--) if((1<<i)&t) u=e[u][i]; return u;
}
inline void dfs(int u){
	st[++st[0]]=u,e[u][0]=fa[u];
	for(int z=1;z<=19;z++) e[u][z]=e[e[u][z-1]][z-1];
	for(int i=0;i<v[u].size();i++){
		int x=v[u][i]; if(fa[u]==x) continue; fa[x]=u,dep[x]=dep[u]+1,dfs(x);
	}
}
inline void bfs(int u){
	q[q[0]=1]=u;
	for(int i=1;i<=q[0];i++){
//		cout<<u<<" "<<col[u]<<"cccc"<<endl;
		u=q[i]; if(col[u]) vb=max(vb,dp[ft[u]]); else va=max(va,dp[ft[u]]);
		for(int z=0;z<vw[u].size();z++){
			int x=vw[u][z];
			if(col[x]==-1) col[x]=col[u]^1,q[++q[0]]=x;
			else if(col[u]==col[x]) tg=1;
		}
	}
}
inline void bfg(int k){
	for(int i=1;i<=q[0];i++){
		int u=q[i]; if(col[u]==k) rev[ft[u]]^=1;
	}
}
inline bool check(int d){
	memset(dp,0,sizeof(dp));
	for(int s=n;s>=1;s--){
		int u=st[s],opt=1; ft[1]=fa[u]; int suma=0,sumb=0;
//		cout<<u<<":"<<endl;
		for(int i=0;i<v[u].size();i++){
			int x=v[u][i]; if(fa[u]==x) continue; gt[x]=++opt,ft[opt]=x;
		}
		for(int i=1;i<=opt;i++) vw[i].resize(0);
		for(int i=0;i<f[u].size();i++){
			vw[gt[f[u][i].first]].push_back(gt[f[u][i].second]);
			vw[gt[f[u][i].second]].push_back(gt[f[u][i].first]);
//			cout<<u<<" "<<f[u][i].first<<" "<<f[u][i].second<<"wwwwww"<<endl;
			fl[gt[f[u][i].first]]=1,fl[gt[f[u][i].second]]=1;
		}
		for(int i=0;i<v[u].size();i++){
			int x=v[u][i]; if(fa[u]==x||!w[x]) continue;
			vw[1].push_back(gt[x]),vw[gt[x]].push_back(1),fl[gt[x]]=1;
		}
		va=0,vb=0,col[1]=0,bfs(1),suma=vb,sumb=va; int vc=0,vd=0;
		for(int i=1;i<=opt;i++)
			if((col[i]==-1&&h[ft[i]])||i==1){
				va=0,vb=0,col[i]=0,bfs(i);
				if(va<vb) swap(va,vb);
				vc=max(vc,va),vd=max(vd,vb);
			}
		for(int i=1;i<=opt;i++) col[i]=-1,vw[i].resize(0),fl[i]=0;
		if(max(vc,suma)+max(vd,sumb)+1>d&&max(vc,sumb)+max(vd,suma)+1>d) return false;
		dp[u]=1919810;
//		cout<<u<<" "<<suma<<" "<<sumb<<" "<<w[u]<<" "<<h[u]<<endl;
		if(max(vc,suma)+max(vd,sumb)+1<=d||u==1) dp[u]=min(dp[u],max(vc,suma));
		if(max(vc,sumb)+max(vd,suma)+1<=d||u==1) dp[u]=min(dp[u],max(vd,suma)); dp[u]++;
	}
	return true;
}
inline void solve(int d){
	for(int s=n;s>=1;s--){
		int u=st[s],opt=1; ft[1]=0; int suma=0,sumb=0;
		for(int i=0;i<v[u].size();i++){
			int x=v[u][i]; if(fa[u]==x) continue; gt[x]=++opt,ft[opt]=x;
		}
		for(int i=1;i<=opt;i++) vw[i].resize(0);
		for(int i=0;i<f[u].size();i++){
			vw[gt[f[u][i].first]].push_back(gt[f[u][i].second]);
			vw[gt[f[u][i].second]].push_back(gt[f[u][i].first]);
			fl[gt[f[u][i].first]]=1,fl[gt[f[u][i].second]]=1;
		}
		for(int i=0;i<v[u].size();i++){
			int x=v[u][i]; if(fa[u]==x||!w[x]) continue;
			vw[1].push_back(gt[x]),vw[gt[x]].push_back(1),fl[gt[x]]=1;
		}
		va=0,vb=0,bfs(1),bfg(1),suma=vb,sumb=va; int vc=0,vd=0;
		for(int i=1;i<=opt;i++)
			if((col[i]==-1&&h[ft[i]])){
				va=0,vb=0,col[i]=0,bfs(i);
				if(dp[u]-1>=va&&vb+dp[u]<=d) bfg(0);
				else if(dp[u]-1>=vb&&va+dp[u]<=d) bfg(1);
				else cout<<"fail"<<endl;
			}
		for(int i=1;i<=opt;i++) col[i]=-1,vw[i].resize(0),fl[i]=0;
	}
}
int main(){
	n=read(),k=read(); int u,t,c;
	for(int i=1;i<=n;i++) col[i]=-1; int p,q;
	for(int i=1;i<n;i++) u=read(),t=read(),v[u].push_back(t),v[t].push_back(u); dfs(1);
	for(int i=1;i<=k;i++){
		u=read(),t=read(),c=lca(u,t); int a=0,b=0;
		if(i==1) p=u,q=t;
		h[u]++,h[t]++,h[c]-=2;
		if(c!=u) a=jmp(u,dep[u]-dep[c]-1),w[u]++,w[a]--;
		if(c!=t) b=jmp(t,dep[t]-dep[c]-1),w[t]++,w[b]--;
		if(a>0&&b>0) f[c].push_back(make_pair(a,b));
	}
	for(int s=n;s>=1;s--){
		u=st[s],opt=1;
		for(int i=0;i<v[u].size();i++){
			int x=v[u][i]; if(fa[u]==x) continue; w[u]+=w[x],h[u]+=h[x]; gt[x]=++opt;
		}
		for(int i=1;i<=opt;i++) vw[i].resize(0);
		for(int i=0;i<f[u].size();i++){
			vw[gt[f[u][i].first]].push_back(gt[f[u][i].second]);
			vw[gt[f[u][i].second]].push_back(gt[f[u][i].first]);
			fl[gt[f[u][i].first]]=1,fl[gt[f[u][i].second]]=1;
		}
		for(int i=0;i<v[u].size();i++){
			int x=v[u][i]; if(fa[u]==x||!w[x]) continue;
			vw[1].push_back(gt[x]),vw[gt[x]].push_back(1),fl[gt[x]]=1;
		}
		for(int i=1;i<=opt;i++) if(col[i]==-1) col[i]=0,bfs(i);
		for(int i=1;i<=opt;i++) col[i]=-1,vw[i].resize(0),fl[i]=0;
	}
	if(tg) {puts("-1"); return 0;}
	int l=1,r=n,ans=-1;
	while(l<=r){
		int d=(l+r)>>1; if(check(d)) ans=d,r=d-1; else l=d+1;
	}
	check(ans),solve(ans);
	cout<<ans<<endl;
	for(int s=1;s<=st[0];s++){
		int u=st[s];
		for(int i=0;i<v[u].size();i++){
			int x=v[u][i]; if(fa[u]==x||!h[x]) continue;
			rev[x]^=rev[u];
			if(rev[x]) tot++,g[tot].u=u,g[tot].t=x;
			else tot++,g[tot].u=x,g[tot].t=u;
		}
	}
	q[0]=0;
	memset(dp,0,sizeof(dp));
	for(int s=1;s<=n;s++) v[s].resize(0);
	for(int s=1;s<=tot;s++) cnt[g[s].t]++,v[g[s].u].push_back(g[s].t);
	for(int s=1;s<=n;s++) if(!cnt[s]) q[++q[0]]=s;
	for(int s=1;s<=q[0];s++){
		int u=q[s]; dp[u]++;
		for(int i=0;i<v[u].size();i++){
			int x=v[u][i];
			dp[x]=max(dp[x],dp[u]); cnt[x]--; if(!cnt[x]) q[++q[0]]=x;
		}
	}
	if(ans==10002){
		int c=lca(p,q);
		while(p!=c) printf("%d ",dp[p]),p=fa[p];
		cout<<endl;
		for(int s=1;s<=n;s++) printf("%d ",dp[s]);
	}
}


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

struct Enemy {
  int x, y, d, t, e;
};

vector<pair<int,int>> atpos[500][500];
vector<Enemy> enemy;

int w, h, n;

ll mem[500][500][500][2];
ll f(int x, int y, int xstreak, int ystreak) {
  if (x == w-1 && y == h-1) return 0;
  if (x >= w || y >= h) return 1e18;
  ll&memo = mem[y][x][xstreak+ystreak][!!xstreak];
  if (!memo) {
    ll ans = min(f(x+1,y,xstreak+1,0), f(x,y+1,0,ystreak+1));
    for (auto pi : atpos[y][x]) {
      Enemy&e = enemy[pi.first];
      int t0 = pi.second;
      if (x+y >= t0 && (x+y-t0)%4 == 0) {
	if (t0-e.t == 3 && e.d%4 == 3 && ystreak >= e.d) continue;
	if (t0-e.t == 2 && e.d%4 == 2 && xstreak >= e.d) continue;
	if (t0-e.t == 2 && e.d%4 == 1 && ystreak >= e.d) continue;
	ans += e.e;
      }
    }
    memo = ans+1;
  }
  return memo-1;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> w >> h >> n;

  for (int i = 0; i < n; i++) {
    int x, y, d, t, e;
    cin >> x >> y >> d >> t >> e;
    enemy.push_back({x,y,d,t,e});
    pair<int,int> list[4] = {{x,y},{x+d,y-d},{x+d,y},{x,y+d}};
    for (auto p : list) {
      int nx,ny;
      tie(nx,ny) = p;
      atpos[ny][nx].push_back({i,t++});
    }
  }
  cout << f(0,0,0,0) << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int M=998244353,B=720720;
int g[B], ng[B];
long long result;
long long s;
int n,a,x,y,k,MOD;

int main () {
    cin>>n>>a>>x>>y>>k>>MOD;
	for(int i=0;i<(1<<k);i++) {
		int sum=0,mul=1;
		for(int j=0;j<k;j++) {
			if((i>>j)&1) sum++;
			else mul = (1ll*mul*(n-1))%M;
		}
		s = (s+sum*mul)%M;
	}
	for(int i=0;i<n;i++) {
		if(i) a=(1ll*a*x+y)%MOD;
		result = (result + 1ll*s*(a-(a%B)))M;
		g[a%B]++;
	}
	for(int i=0;i<B;i++) if(g[i]) {
		result = (result + 1ll*g[i]*i)%M;
	}
	for(int i=2;i<=k;i++) {
		result = (result*n)%M;
		memset(ng,0,sizeof(ng));
		for(int j=0;j<B;j++) {
			new_g[j%i] = (new_g[j%i]+g[j])%M;
			new_g[j] = (1ll*new_g[j] + 1ll*g[j]*(n-1))%M;
		}
		for(int j=0;j<B;j++) {
			result = (result + 1ll*new_g[j]*j)%M;
		}
		memcpy(g,ng,sizeof(ng));
	}
	printf("%lld\n", result);
}


//*
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <functional>
#define MOD 1000000007
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

ll n[3];

pii a[3][200005];
vector<int> edge[3][200005];

ll par[3][200005][20];
ll depth[3][200005];

ll down[3][200005];
ll up[3][200005];
ll down2[3][200005];
ll up2[3][200005];
ll d2[3][200005];
ll md2[3];
ll down3[3][200005][2];
ll up3[3][200005];
ll real[3][200005];
ll inhab[3];

ll cdown(ll z, ll now, ll parent)
{
    ll i;
    ll sum=0;
    for(i=0;i<edge[z][now].size();i++)
    {
        if(edge[z][now][i] == parent) continue;
        sum+=cdown(z, edge[z][now][i], now);
    }
    return (down[z][now]=sum+1);
}

void cup(ll z, ll now, ll parent)
{
    ll i;
    if(parent != -1)
    {
        up[z][now]=up[z][parent]+down[z][parent]-down[z][now];
    }
    for(i=0;i<edge[z][now].size();i++)
    {
        if(edge[z][now][i] == parent) continue;
        cup(z, edge[z][now][i], now);
    }
}

ll cdown2(ll z, ll now, ll parent)
{
    ll i;
    ll sum=0;
    for(i=0;i<edge[z][now].size();i++)
    {
        if(edge[z][now][i] == parent) continue;
        sum+=cdown2(z, edge[z][now][i], now);
    }
    return down2[z][now]=down[z][now]-1+sum;
}

void cup2(ll z, ll now, ll parent)
{
    ll i;
    if(parent != -1)
    {
        up2[z][now]=up[z][now]+up2[z][parent]+down2[z][parent]-(down2[z][now]+down[z][now]);
    }
    for(i=0;i<edge[z][now].size();i++)
    {
        if(edge[z][now][i] == parent) continue;
        cup2(z, edge[z][now][i], now);
    }
}

void calcdepth(ll z, ll now, ll parent)
{
    if(parent != -1) depth[z][now]=depth[z][parent]+1;
    ll i;
    for(i=0;i<edge[z][now].size();i++)
    {
        if(edge[z][now][i] == parent) continue;
        calcdepth(z, edge[z][now][i], now);
    }
}

void calcpar(ll z, ll now, ll parent)
{
    ll i, j;
    par[z][now][0]=parent;
    for(i=1;i<20;i++)
    {
        par[z][now][i]=par[z][par[z][now][i-1]][i-1];
    }
    for(i=0;i<edge[z][now].size();i++)
    {
        if(edge[z][now][i] == parent) continue;
        calcpar(z, edge[z][now][i], now);
    }
}

ll calcdis(ll z, ll x, ll y)
{
    ll i;
    if(depth[z][x] < depth[z][y]) swap(x, y);
    ll chai=depth[z][x]-depth[z][y];
    for(i=19;i>=0;i--)
    {
        if(chai&(1<<i)) x=par[z][x][i];
    }
    if(x == y) return chai;
    for(i=19;i>=0;i--)
    {
        if(par[z][x][i] != par[z][y][i]) chai+=2*(1<<i), x=par[z][x][i], y=par[z][y][i];
    }
    return chai+2;
}

ll calcd1d2(ll z, ll x, ll y, ll x1, ll x2)
{
    return d2[z][x]*x1+d2[z][y]*x2+calcdis(z, x, y)*x1*x2;
}

void cdown3(ll z, ll now, ll parent, ll x1, ll x2)
{
    ll i;
    if(z == 0 && now == 1)
    {
        z=z;
    }
    ll sum=0;
    ll max1=-1, max2=-1, maxi1=-1, maxi2=-1;
    for(i=0;i<edge[z][now].size();i++)
    {
        if(edge[z][now][i] == parent) continue;
        cdown3(z, edge[z][now][i], now, x1, x2);
        ll tmp=calcd1d2(z, now, down3[z][edge[z][now][i]][0], x1, x2);
        if(max1 < tmp)
        {
            max2=max1;
            maxi2=maxi1;
            max1=tmp;
            maxi1=down3[z][edge[z][now][i]][0];
        }
        else if(max2 < tmp)
        {
            max2=tmp;
            maxi2=down3[z][edge[z][now][i]][0];
        }
    }
    if(max1 == -1) down3[z][now][0]=now;
    else down3[z][now][0]=maxi1;
    if(max2 == -1) down3[z][now][1]=now;
    else down3[z][now][1]=maxi2;
}

ll isin(ll z, ll x, ll y)
{
    ll i;
    if(depth[z][x] < depth[z][y]) return 0;
    ll chai=depth[z][x]-depth[z][y];
    for(i=19;i>=0;i--)
    {
        if(chai&(1<<i)) x=par[z][x][i];
    }
    if(x == y) return 1;
    return 0;
}

void cup3(ll z, ll now, ll parent, ll x1, ll x2)
{
    ll i;
    ll sum=0;
    ll max=-1, maxi;
    if(parent != -1)
    {
        if(up3[z][parent] != -1)
        {
            ll u1=calcd1d2(z, now, up3[z][parent], x1, x2);
            if(max < u1)
            {
                max=u1;
                maxi=up3[z][parent];
            }
        }
        ll u2, u3;
        if(!isin(z, down3[z][parent][0], now)) u3=down3[z][parent][0];
        else u3=down3[z][parent][1];
        if(u3 != -1)
        {
            u2=calcd1d2(z, now, u3, x1, x2);
            if(max < u2)
            {
                max=u2;
                maxi=u3;
            }
        }
        up3[z][now]=maxi;
    }
    else up3[z][now]=-1;
    for(i=0;i<edge[z][now].size();i++)
    {
        if(edge[z][now][i] == parent) continue;
        cup3(z, edge[z][now][i], now, x1, x2);
    }
}

void calcinhab(ll z, ll now, ll parent)
{
    ll i;
    for(i=0;i<edge[z][now].size();i++)
    {
        if(edge[z][now][i] == parent) continue;
        inhab[z]+=up[z][edge[z][now][i]]*down[z][edge[z][now][i]];
        calcinhab(z, edge[z][now][i], now);
    }
}

ll main()
{
    ll i, j, k;
    scanf("%d%d%d", &n[0], &n[1], &n[2]);
    for(i=0;i<3;i++)
    {
        for(j=0;j<n[i]-1;j++)
        {
            ll x, y;
            scanf("%d%d", &x, &y);
            x--, y--;
            a[i][j]=pii(x, y);
            edge[i][x].push_back(y);
            edge[i][y].push_back(x);
        }
    }
    for(i=0;i<3;i++)
    {
        cdown(i, 0, -1);
        cup(i, 0, -1);
    }
    for(i=0;i<3;i++)
    {
        cdown2(i, 0, -1);
        cup2(i, 0, -1);
        for(j=0;j<n[i];j++) d2[i][j]=down2[i][j]+up2[i][j];
    }
    for(i=0;i<3;i++)
    {
        calcpar(i, 0, -1);
        calcdepth(i, 0, -1);
    }
    for(i=0;i<3;i++)
    {
        cdown3(i, 0, -1, n[(i+1)%3], n[(i+2)%3]);
        cup3(i, 0, -1, n[(i+1)%3], n[(i+2)%3]);
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<n[i];j++)
        {
            ll maxx=-1, maxi=-1;
            if(up3[i][j] != -1) maxx=max(maxx, calcd1d2(i, j, up3[i][j], n[(i+1)%3], n[(i+2)%3]));
            maxx=max(maxx, calcd1d2(i, j, down3[i][j][0], n[(i+1)%3], n[(i+2)%3]));
            real[i][j]=maxx;
        }
    }
    for(i=0;i<3;i++)
    {
        ll maxx=-1;
        for(j=0;j<n[i];j++)
        {
            if(maxx < d2[i][j]) maxx=d2[i][j];
        }
        md2[i]=maxx;
    }
    for(i=0;i<3;i++)
    {
        calcinhab(i, 0, -1);
    }
    ll rmax=0;
    for(i=0;i<3;i++)
    {
        ll tmax=0;
        ll x, y, z;
        x=i, y=(i+1)%3, z=(i+2)%3;
        for(j=0;j<3;j++) tmax+=inhab[j];
        tmax+=n[0]*n[1]+n[1]*n[2]+n[2]*n[0];
        tmax+=n[x]*n[z];
        tmax+=md2[x]*n[y]+md2[z]*n[y]+md2[x]*n[z]+md2[z]*n[x];
        ll ttmax=0;
        for(j=0;j<n[y];j++)
        {
            if(ttmax < real[y][j]) ttmax=real[y][j];
        }
        tmax+=ttmax;
        if(rmax < tmax) rmax=tmax;
    }
    printf("%I64d", rmax);

    return 0;
}
//*/


#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cctype>

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include <iterator>
#include <functional>

using namespace std;

template<typename T> struct Point
{
	T x, y; Point(){} Point(T xx, T yy): x(xx), y(yy){}
};
template<typename T> bool operator <(const Point<T> &p1, const Point<T> &p2)
{
	return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y;
}
template<typename T> Point<T> operator -(const Point<T> &p1, const Point<T> &p2)
{
	return Point<T>(p1.x - p2.x, p1.y - p2.y);
}
template<typename T> T operator ^(const Point<T> &p1, const Point<T> &p2)
{
	return p1.x*p2.y - p2.x*p1.y;
}

#define mp make_pair
#define pb push_back
#define forn(i, n) for(int (i)=0; (i)<n; i++)
#define all(x) x.begin(), x.end()
#define zero(a) memset(a, 0, sizeof(a))

typedef long long int64;
typedef vector<int> vint;
typedef Point<int> pint;

const int MAXN = 32768;
const char LESS = '<', MORE = '>', EQUAL = '=';
const char TN = 'N', TF = 'f', TI = 'I', TE = 'E', TS = 'S';
const int PLUS = 10000001;
const int MINUS = 10000002;
const int MUL = 10000003;
const int DIV = 10000004;

vector<int> values;

void execute(int n);

struct Aryfm
{
	char Type;
	int num;
	vector<Aryfm> v;

	Aryfm()
	{

	}
	Aryfm(string s, char type = TE)
	{
		string ts;
		Type = type;
		forn(i, s.size())
		{
			Aryfm a;
			if (s[i] == 'f')
			{
				int si = i+2;
				for(; s[i]!=')'; i++) ;
				a = Aryfm(s.substr(si, i-si), TF);
			}
			else if (s[i] == 'n')
			{
				a.Type = TN;
			}
			else if (isdigit(s[i]))
			{
				ts = "";
				for(;i<s.size() && isdigit(s[i]); i++) ts+=s[i];
				i--;
				a.Type = TI;
				a.num = atol(ts.c_str());
			}
			else if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/')
			{
				a.Type = TS;
				if (s[i] == '+') a.num = PLUS;
				if (s[i] == '-') a.num = MINUS;
				if (s[i] == '*') a.num = MUL;
				if (s[i] == '/') a.num = DIV;
			}
			v.push_back(a);
		}
	}
	int Calc(int n)
	{
		if (Type == TN)
			return n;
		else if (Type == TI || Type == TS)
			return num;

		vector<int> c;
		forn(i, v.size())
		{
			c.push_back(v[i].Calc(n));
		}
		forn(i,c.size())
		{
			if (c[i] == MUL)
			{
				c[i-1] = (c[i-1]*c[i+1])%MAXN;
				c.erase(c.begin()+i);
				c.erase(c.begin()+i);
				i--;
			}
			else if (c[i] == DIV)
			{
				c[i-1] = (c[i-1]/c[i+1])%MAXN;
				c.erase(c.begin()+i);
				c.erase(c.begin()+i);
				i--;
			}
		}
		forn(i,c.size())
		{
			if (c[i] == PLUS)
			{
				c[i-1] = (c[i-1]+c[i+1])%MAXN;
				c.erase(c.begin()+i);
				c.erase(c.begin()+i);
				i--;
			}
			else if (c[i] == MINUS)
			{
				c[i-1] = (c[i-1]-c[i+1])%MAXN;
				c.erase(c.begin()+i);
				c.erase(c.begin()+i);
				i--;
			}
		}

		int res = c[0];
		if (Type == TF)
		{
			execute(res);
			res = values[res];
		}
		return res;
	}
};

struct Cond
{
	char cond;
	Aryfm l, r, ret;
};

vector<Cond> f;

void execute(int n)
{
	if (values[n]!=-1)
		return;

	forn(i, f.size())
	{
		int l = f[i].l.Calc(n);
		int r = f[i].r.Calc(n);
		if (f[i].cond == MORE && l>r ||
			f[i].cond == LESS && l<r ||
			f[i].cond == EQUAL && l==r)
		{
			values[n] = f[i].ret.Calc(n);
			return;
		}
	}
}

string ts, s;
void Parse()
{
	forn(i, ts.size())
	{
		if (ts[i] == '{')
		{
			ts = ts.substr(i+1);
			break;
		}
	}
	s = "";
	forn(i, ts.size())
	{
		if (!isspace(ts[i]))
		{
			if (ts[i] == '}')
				break;

			if (ts[i] == 'r')
			{
				s+="i(0==0)";
			}
			else if (ts[i] == 'i')
			{
				ts[++i] = 'i';
			}

			for(; ts[i]!=';'; i++)
			{
				if (!isspace(ts[i]))
				{
					if (ts[i] == 'r')
					{
						for(; ts[i]!='n'; i++);
						ts[i] = '#';
					}
					s+=ts[i];
				}
			}

			i++;
		}
	}
	forn(i, s.size())
	{
		Cond c;

		for(;s[i]!='('; i++);

		ts = "";
		int si = ++i;
		for(;s[i]!='<' && s[i]!='>' && s[i]!='='; i++) ts+=s[i];
		c.l = Aryfm(ts);

		if (s[i] == '=') c.cond = EQUAL;
		if (s[i] == '<') c.cond = LESS;
		if (s[i] == '>') c.cond = MORE;
		if (s[i] == '=') i++;

		ts = "";
		si = ++i;
		for(;s[i]!='#'; i++) ts+=s[i];
		ts.pop_back();
		c.r = Aryfm(ts);

		ts = "";
		si = ++i;
		for(;i<s.size() && s[i]!='i'; i++) ts+=s[i];
		c.ret = Aryfm(ts);

		f.push_back(c);
	}
}

int main()
{
	values.assign(MAXN, -1);
	int fn;
	cin >> fn;
	ts = "";
	while(getline(cin, s))
	{
		ts+=" "+s;
	}
	Parse();

	forn(i, MAXN)
	{
		execute(i);
	}
	for(int i = values.size()-1; i>=0; i--)
	{
		if (values[i] == fn)
		{
			cout << i;
			return 0;
		}
	}
	cout << -1;

	return 0;
}
/*

*/


#include<bits/stdc++.h>
using namespace std;
int p,n;
__int128 x,y,mo;
string s;
map<__int128,int>mp;
__int128 mul(__int128 x,__int128 y)
{
	__int128 ans=0;
	for (int i=0;i<n-1;i++) if (y>>i&1) ans^=x<<i;
	for (int i=n+n-4;i>=n-1;i--) if (ans>>i&1) ans^=mo<<(i-n+1);
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>s;
	while (!s.empty() && s[0]=='0') s.erase(s.begin()),p++;
	p++;
	if (s.empty())
	{
		cout<<-1;
		return 0;
	}
	while (s.back()=='0') s.pop_back();
	n=s.size();
	for (int i=0;i<n;i++) mo+=(s[i]-'0')*(1ll<<i);
	x=1;
	for (int i=0;i<(1<<18);i++,x=mul(x,2)) mp[x]=i;
	y=x;
	for (long long i=1;i<=(1<<18);i++,y=mul(y,x))
	if (mp.count(y))
	{
		cout<<p<<' '<<p+(i<<18)-mp[y];
		break;
	}
	return 0;
}


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

const int mod = 998244353;

int mul(int a, int b) {
	return (1LL * a * b) % mod;
}

int pw(int a, int b) {
	if (b == 0) return 1;
	if (b & 1) return mul(a, pw(a, b - 1));
	int res = pw(a, b / 2);
	return mul(res, res);
}

int sub(int a, int b) {
	int s = a - b;
	if (s < 0) s += mod;
	return s;
}

int add(int a, int b) {
	int s = a + b;
	if (s >= mod) s -= mod;
	return s;
}

void fft(vector<int>& a, bool inv) {
	int n = (int)a.size();
	for (int i = 1, j = 0; i < n; i++) {
		int bit = n >> 1;
		for (; j >= bit; bit >>= 1) j -= bit;
		j += bit;
		if (i < j) swap(a[i], a[j]);
	}
	for (int len = 2; len <= n; len <<= 1) {
		int wlen = inv ? 208611436 : 646;
		for (int i = len; i < (1 << 20); i <<= 1) wlen = int(wlen * 1ll * wlen % mod);
		for (int i = 0; i < n; i += len) {
			int w = 1;
			for (int j = 0; j < len / 2; j++) {
				int u = a[i + j], v = int(a[i + j + len / 2] * 1ll * w % mod);
				a[i + j] = u + v < mod ? u + v : u + v - mod;
				a[i + j + len / 2] = u - v >= 0 ? u - v : u - v + mod;
				w = int(w * 1ll * wlen % mod);
			}
		}
	}
	if (inv) {
		int nrev = pw(n, mod - 2);
		for (int i = 0; i < n; i++) a[i] = int(a[i] * 1ll * nrev % mod);
	}
}

void polysq(vector<int>& a) {
	int s = 2 * a.size();
	int r = 1;
	while (r < s) r *= 2;
	a.resize(r);
	fft(a, false);
	for (int i = 0; i < r; i++) a[i] = mul(a[i], a[i]);
	fft(a, true);
	while (!a.empty() && (a.back() == 0)) a.pop_back();
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k, f;
	cin >> n >> k >> f;
	vector<int> dp(k + 1, 1);
	for (int i = 1; i < n; i++) {
		polysq(dp);
		dp.resize(2 * k + 1);
		vector<int> ndp(k + 1);
		int alls = 0;
		for (auto v : dp) alls = add(alls, v);
		int cur = 0;
		for (int j = 0; j <= k; j++) {
			cur = add(cur, dp[j]);
			ndp[j] = nul(k - j + 1, dp[j]);
			ndp[j] = sum(ndp[j], sub(alls, cur));
		}
		dp = ndp;
	}
	polysq(dp);
	if (f >= (int)dp.size()) cout << 0 << '\n';
	else cout << dp[f] << '\n';
	return 0;
}


#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,d,m; ll l,r;
ll pw[105],a[30],dp[2][60][60][2],bs[60];

ll shift(ll x,int t){return (x>>t)|((x&((1ll<<t)-1))<<(m-t));}

ll getans(vector<ll> b,ll dep,ll now){
	if(now>r) return 0;
	ll res=0;
	if(b.size()==1){
		for(int i=0;i<m;i++){
			if(b[0]&(1ll<<i)){
				int ttmp=0;
				if(now<=r%pw[dep]) res+=dp[0][dep][i][0]+dp[0][dep][i][1];
				else res+=dp[0][dep][i][0];
				if(now<=l%pw[dep]) res-=dp[1][dep][i][0]+dp[1][dep][i][1];
				else res-=dp[1][dep][i][0];
			}
		}
		return res;
	}
	for(int i=0;i<d;i++){
		vector<ll> nb(0);
		int tmp=i; ll mask=(1ll<<m)-1;
		for(int j=0;j<b.size();j++){
			mask&=shift(b[j],a[tmp]);
			tmp++;
			if(tmp==d){
				tmp=0;
				nb.push_back(mask);
				mask=(1ll<<m)-1;
			}
		}
		if(tmp!=0) nb.push_back(mask);
		res+=getans(nb,dep+1,now+pw[dep]*i);
	}
	return res;
}

void getdp(ll x,int t){
	int cnt=0;
	memset(bs,0,sizeof(bs));
	for(;x;x/=d) bs[cnt++]=x%d;
	cnt=59;
	dp[t][cnt][0][1]=1;
	for(int i=cnt;i>=1;i--)
		for(int j=0;j<m;j++)
			for(int c=0;c<=1;c++)
				for(int num=0;num<(c?bs[i-1]+1:d);num++)
					dp[t][i-1][(j+a[num])%m][c&(num==bs[i-1])]+=dp[t][i][j][c];
}

int main(){
	d=readint(); m=readint();
	pw[0]=1;
	for(int i=1;pw[i-1]<=1e18/d;i++) pw[i]=pw[i-1]*d;
	for(int i=0;i<d;i++) a[i]=readint();
	n=readint();
	vector<ll> b(0);
	for(int i=1;i<=n;i++) b.push_back((1ll<<(readint()+1))-1);
	l=readint()-2; r=readint()-n;
	getdp(r,0); getdp(l,1);
	printf("%lld\n",getans(b,0,0));
	return 0;
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="stack" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/stack" 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/stack" 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 />
			<debugger />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <ctime>
#include <list>
#include <queue>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;

mt19937 ran(time(0));

ll mod = 1000012121;
ll inf = 2e18;

int n, m;
int k;
vector<int>p;
vector<vector<int>>g;
vector<ll>dist;
vector<bool>used;
queue<pair<int, int>>q;
vector<int>how;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>n>>m;
	g.resize(n);
	cnt.resize(n);
	used.resize(n, false);
	int u, v;
	dist.resize(n, -1);
	how.resize(n);
	for(int i = 0; i < m ;i++){
		cin>>u>>v;
		u--;
		v--;
		g[v].push_back(u);
	}
	cin>>k;
	p.resize(k);
	for(int i = 0; i < k; i++){
		cin>>p[i];
		p[i]--;
	}
	q.push(make_pair(p[k-1], 0));
	used[p[k-1]] = cnt[p[k-1]] = 1;
	int cur, d;
	dist[p[k-1]] = 0;
	while(!q.empty()){
		cur = q.front().first;
		d = q.front().second;
		q.pop();
		for(int i = 0; i < g[cur].size(); i++){
			v = g[cur][i];
			if(!used[v] || dist[v] == d + 1){
				how[v]++;
			}
			if(!used[v]){
				used[v] = true;
				dist[v] = d + 1;
				q.push(make_pair(v, d + 1));
			}
		}
	}
	ll ma = 0, mi = 0;
	how[p[k-1]] = 1;
	for(int i = 1; i < k; i++){
		if(dist[p[i]] == dist[p[i-1]]){
			mi++;
			ma++;
		}
		else if (dist[p[i]] < dist[p[i-1]] && how[p[i-1]] > 1){
			ma++;
		}
		else if (dist[p[i]] > dist[p[i-1]] && 1 < how[p[i]]){
			ma++;
		}
	}
	cout<<mi<<" "<<ma;
	//system("pause>nul");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstddef>
#include <complex>
#include <ctime>
#include <climits>

#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <functional>
#include <iterator>
#include <typeinfo>
#include <utility>
#include <memory>

#include <cassert>

#if __cplusplus >= 201103L
#include <tuple>
#include <ratio>
#include <array>
#include <forward_list>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long int64;
const int inf = 2000000000;
static inline int Rint()
{
	struct X{ int dig[256]; X(){
	for(int i = '0'; i <= '9'; ++i) dig[i] = 1; dig['-'] = 1;
	}};
	static 	X fuck;int s = 1, v = 0, c;
	for (;!fuck.dig[c = getchar()];);
	if (c == '-') s = 0; else if (fuck.dig[c]) v = c ^ 48;
	for (;fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48));
	return s ? v : -v;
}
typedef vector<int> vi;
typedef map<int, int> mii;
typedef set<int> si;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i, s, e) for (int i = (s); i < (e); ++i)

#if __cplusplus >= 201103L
#define foreach(iter, c) for(auto& iter : c)
#else
#define foreach(itr, c) for(__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++itr)
#endif

template<typename T> static inline void cmax(T& a, const T& b){if(b>a)a=b;}
template<typename T> static inline void cmin(T& a, const T& b){if(b<a)a=b;}
#define SL static inline

#define dbg(x) cerr << (#x) << " = " << (x) << endl

const int maxn = 100005;
int64 h;
int n, m, k;

int64 pos[maxn];
int treasure[maxn];
int flag[maxn];

int64 D[10005];

int64 allk[32];
int top;

struct Pt
{
	int64 t, p, id;
	int operator < (const Pt& o) const
	{
		if (t != o.t) return t < o.t;
		if (p != o.p) return p > o.p;
		return id < o.id;
	}
};

void fix(priority_queue<Pt>& pq)
{
	set<pair<int64, int> > st;

	for (int i = 0; i < k; ++i)
	if (D[i] != -1)
	st.insert({D[i], i});

	while (!st.empty())
	{
		auto where = st.begin();
		auto curr = *where;
		st.erase(where);
		if (D[curr.second] != curr.first) continue;
		for (int i = top-1; i < top; ++i)
		{
			int64 val = curr.first;
			for (int coe = 1; coe < k; ++coe)
			{
				val += allk[i];
				if (val > h) break;

				int next = val % k;

				if (next == curr.second)
				{
					break;
				}

				if (D[next] == -1)
				{
					D[next] = val;
					st.insert({D[next], next});
				}
				else if (D[next] > val)
				{
					D[next] = val;
					st.insert({D[next], next});
				}
			}
		}
	}

	for (int i = 1; i <= n; ++i) if (flag[i] == 0)
	{
		const int bucket = pos[i] % k;
		if (D[bucket] != -1)
		{
			if (pos[i] >= D[bucket])
			{
				pq.push({treasure[i], pos[i], i});
				flag[i] = 1;
			}
		}
	}
}

int main()
{
	scanf("%I64d", &h);
	n = Rint(), m = Rint(), k = Rint();

	for (int i = 1; i <= n; ++i)
	scanf("%I64d %d", pos+i, treasure+i);

	memset(D, -1, sizeof D);
	D[1%k] = 1;

	priority_queue<Pt> pq;

	for (int i = 1; i <= n; ++i)
	{
		const int bucket = pos[i] % k;
		if (D[bucket] != -1)
		{
			if (pos[i] >= D[bucket])
			{
				pq.push({treasure[i], pos[i], i});
				flag[i] = 1;
			}
		}
	}

	for (int id = 0; id < m; ++id)
	{
		const int cmd = Rint();
		if (cmd == 3)
		{
			while (!pq.empty())
			{
				auto curr = pq.top();
				if (treasure[curr.id] != curr.t)
				{
					pq.pop();
				}
				else
				{
					break;
				}
			}
			int64 ans = 0;
			if (!pq.empty())
			{
				ans = pq.top().t;
				treasure[pq.top().id] = -1;
				//dbg(pq.top().id);
				//dbg(pq.top().p);
				pq.pop();
			}
			printf("%I64d\n", ans);
		}
		else if (cmd == 2)
		{
			const int x = Rint();
			const int c = Rint();
			treasure[x] -= c;
			if (c != 0 && flag[x])
			{
				pq.push({treasure[x], pos[x], x});
			}
		}
		else
		{
			int64 x; scanf("%I64d", &x);
			int ok = 1;
			//for (int i = 0; i < top; ++i)
			//if (x % allk[i] == 0) ok = 0;
			//if (x % k == 0) ok = 0;
			if (ok)
			{
				allk[top++] = x;
				fix(pq);
				#if 0
				for (int i = 1; i <= n; ++i)
				if (flag[i])
				cerr << pos[i] << " " << treasure[i] << endl;
				cerr << endl;

				for (int i = 0; i < k; ++i)
				cerr << i << " " << D[i] << endl;
				cerr << endl;
				#endif
			}
		}
	}

	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
ll xx,yy,x,y,rr,cc,n,m,k,c,r,xa,ya,xb,yb,p,ans;
ll posw(ll x){
	ll tt=1,t=k;
	while(x){
		if(x&1)tt=tt*t%MOD;
		x>>=1;
		t=t*t%MOD;
	//	cout<<tt<<"ALB"<<t<<"NNN"<<x<<endl;
	}
	return tt;
}
ll sz(ll a,ll b){
	if(a%b==0)return a/b;
	else return a/b+1;
}
int main(){
	scanf("%I64d%I64d%I64d%I64d%I64d",&n,&m,&k,&r,&c);
	scanf("%I64d%I64d%I64d%I64d",&xa,&ya,&xb,&yb);
	if(xa>=xb&&ya>=yb){
	swap(xa,xb);swap(ya,yb);
	}
	if(xa==xb&&ya==yb){
		cout<<pow(n*m)<<endl;return 0;
	}
	if(xb>xa+r-1||yb>ya+c-1){
		ans=posw(n*m-r*c);
	}
	else{
		xx=abs(xa-xb);yy=abs(ya-yb);
		x=sz(r,xx)-1;y=sz(c,yy)-1;
		p=min(x,y);
		rr=r-p*xx;cc=c-p*yy;
		ans=2*(p-1)*xx*yy-rr*cc+(r-(p-1)*xx)*(c-(p-1)*yy);
	//	cout<<ans<<"CNM"<<endl;
		ans+=m*n-(r+xx)*(c+yy)+2*xx*yy;
	//	cout<<ans<<"YSS"<<k<<"IYSD"<<posw(ans)<<endl;
		ans=posw(ans);
	}
	cout<<ans<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
LL f[55][2][2],K;int a[55],n;
#define cl(f) memset(f,-1,sizeof f)
#define F (f[l][rev][inv])
LL calc(int l,int r,int e1,int e2){
   if (l>r)return 1;if(~F)return F;F=0;
   for(int i=0;i<2;++i)for(int j=0;j<2;++j)if(a[l]!=(!i)&&a[r]!=(!j)&&(l<r||i==j)&&(e1||i<=j)&&(e2||i<=(!j)))F+=calc(l+1,r-1,e1||(i<j),e2||(i<!j));
   return F;
}
int main(){
    scanf("%d%I64d",&n,&K);cl(a);a[1]=0;cl(f);
    if (calc(1,n,0,0)<++K){puts("-1");return 0;}
    for(int i=2;i<=n;++i){a[i]=0,cl;LL d=calc(1,n,0,0);K-=(a[i]=(d<K))*d;}
    for(int i=1;i<=n;++i)printf("%d",a[i]);puts("");
}


#include <stdio.h>
#include <string>
#include <algorithm>

bool primo(int n) {
    if (n == 2)
        return true;

    for (int i = 2; i < n / 2; ++i)
        if (n % i == 0)
            return false;
    return true;
}

int reversa(int n) {
    std::string str = std::to_string(n);
    std::reverse(str.begin(), str.end());
    return atoi(str.c_str());
}

int main() {
    int n;
    scanf("%d", &n);

    int k = 0;
    int i = 0;
    while (true) {
        if (primo(i)) {
            int rev = reversa(i);
            if (rev != i) {
                if (primo(rev)) {
                    ++k;
                    if (k == n) {
                        printf("%d", i);
                        break;
                    }
                }
            }
        }
        ++i;
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#define N 1510
using namespace std;
typedef long long LL;

struct Node {
    LL to, nxt;
}e[N << 1];

struct Point {
    LL x, y, id;
}p[N], pp[N], poi;

LL cnt, n, lst[N], ans[N], size[N];

bool cmp(Point a, Point b) {//按极角排序
    LL ax = a.x - poi.x, ay = a.y - poi.y, bx = b.x - poi.x, by = b.y - poi.y;
    if (ax >= 0 && bx <= 0) return 1;
    if (ax <= 0 && bx >= 0) return 0;
    return (ax * by > bx * ay);
}

inline void add(LL u, LL v) {
    e[++cnt].to = v;
    e[cnt].nxt = lst[u];
    lst[u] = cnt;
}

void predfs(LL x, LL fa) {//预处理出子树大小
    size[x] = 1;
    for (int i = lst[x]; i; i = e[i].nxt) {
        if (e[i].to == fa) continue;
        predfs(e[i].to, x);
        size[x] += size[e[i].to];
    }
}

void dfs(LL l, LL r, LL x, LL fa)//对区间进行分治
    LL mini = l;
    for (int i = l + 1; i <= r; ++i)
        if (p[i].y < p[mini].y || p[i].y == p[mini].y && p[i].x < p[mini].x) mini = i;
    swap(p[l], p[mini]);
    ans[p[l].id] = x;
    poi = p[l];
    sort(p + l + 1, p + r + 1, cmp);
    LL now = l + 1;
    for (LL i = lst[x]; i; i = e[i].nxt) {
        if (e[i].to == fa) continue;
        dfs(now, now + size[e[i].to] - 1, e[i].to, x);
        now += size[e[i].to];
    }
}

int main() {
    scanf("%lld", &n);
    for (LL i = 1; i < n; ++i) {
        LL a, b;
        scanf("%lld%lld", &a, &b);
        add(a, b);
        add(b, a);
    }
    for (LL i = 1; i <= n; ++i) {
        scanf("%lld%lld", &p[i].x, &p[i].y);
        p[i].id = i;
    }
    predfs(1, 1);
    dfs(1, n, 1, 1);
    for (LL i = 1; i < n; ++i) {
        printf("%lld ", ans[i]);
    }
    printf("%lld\n", ans[n]);
    return 0;
}//


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#define pb push_back
#define rep(i,j,k) for(int i=(j);i<=(int)k;i++)
#define per(i,j,k) for(int i=(j);i>=(int)k;i--)
#define lowbit(x) ((x)&(-(x)))
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
typedef long long LL;
typedef double db;
map<pii,bool>fuck;
int n,m;
char s[5];
int x,y;
LL ans;
int dx,dy;
int main()
{   scanf("%d%d",&n,&m);
    scanf("%d%d",&x,&y);
    scanf("%s",s+1);
    if(s[1]=='U')dx=-1;  else dx=1;
    if(s[2]=='L')dy=-1;  else dy=1;
    int fis=0;
    int test=1000000;
    while(test--)
    {   pii now=pii(x,y);
        if(!fuck[now])
        {   fuck[now]=1;
            fis++;
        }
        if(fis==n+m-2)
        {   printf("%I64d",ans+1);
            return 0;
        }
        int xl,yl,l;
        int ex,ey;
        if(dx==-1)xl=x-1; else xl=n-x;
        if(dy==-1)yl=y-1; else yl=m-y;
        if(xl<yl)
        {   ex=-dx;ey=dy;l=xl; }
        else
        {
	 	  if(xl>yl) { ey=-dy; ex=dx;  l=yl;}
          else      { ex=-dx; ey=-dy; l=yl;}
        }
		x+=dx*l;y+=dy*l;
        ans+=1ll*l;
        dx=ex;dy=ey;
    }
    printf("-1\n");
    return 0;


#include <bits/stdc++.h>
#define L first
#define R second
#define MP make_pair
#define PB push_back

using namespace std;

long long n, m, k;
vector<pair<pair<long long, long long>, long long> > E;
long long d[2][20];

bool chk(long long mask) {
	memset(d, 0, sizeof d);
	for(long long i = 0;i < E.size();i ++)
		if(mask & (1<<i))
			d[0][E[i].L.L] ++, d[1][E[i].L.R] ++;
	for(long long i = 1;i <= n;i ++)
		if(d[0][i] > 1 || d[1][i] > 1)
			return false;
	return true;
}

long long ans(long long mask) {
	long long ret = 0;
	for(long long i = 0;i < E.size();i ++)
		if(mask & (1<<i))
			ret += E[i].R;
	return ret;
}

main() {
	cin >> n >> m >> k;
	long long fi, se, w;
	for(long long i = 0;i < m;i ++)
		cin >> fi >> se >> w, E.PB(MP(MP(fi, se), w));
	vector<long long> Q(0);
	for(long long mask = 0;mask < (1<<E.size());mask ++) {
		if(chk(mask))
			Q.PB(ans(mask));
	}
	sort(Q.begin(), Q.end());
	cout << Q[k - 1] << endl;
	return 0;
}


#include <bits/stdc++.h>
#define endl "\n"
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#define FORR(x, y, z) for (int x = (y); x > (z); --x)
#define GET(a, n) for (int i = 0; i < (n); ++i) cin >> a[i];
#define GETM(a, n, m) for (int i = 0; i < (n); ++i) for (int j = 0; j < m; ++j) cin >> a[i][j];
#define PRINTM(a, n, m) for (int i = 0; i < (n); ++i) { for (int j = 0; j < m; ++j) cout << a[i][j] << " ";  cout << endl; };
#define PRINT(a, n) for (int i = 0; i < (n); ++i) cout << a[i] << " ";
#define IT(a) a.begin(), a.end()
#define CASE(a, s) cout << "Case #" << a << ": " << s << endl;
#define DEB(a) cout << #a << " = " << (a) << endl; cout.flush();
#define DEBA(a) for (auto i: a) cout << i << " "; cout << endl;
#define IFDEB(b, a) if (b) { cout << #a << " = " << a << endl; cout.flush(); }
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
typedef vector <vector <int>> VVI;
typedef pair <int, int> PII;
const int MOD = 1000000007;
template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; FOR(i, 0, n) sum += v[i]; return sum; }
struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio;

vector <int> v;

int check(vector <int> &start)
{
    FOR (i, 0, start.size()) {
        if (start[i] != start[start[i]]) {
            return 0;
        }
    }
    return 1;
}

LL lcm(LL a, LL b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    int n;
    cin >> n;
    v.resize(n);
    GET(v, n);
    for (auto &i: v) {
        --i;
    }
    vector <int> start(n);
    FOR (i, 0, n) {
        start[i] = i;
    }
    vector <int> a = start;
    vector <int> cycle_first;
    FOR (j, 0, n) {
        FOR (i, 0, n) {
            start[i] = v[start[i]];
        }
        //if (check(start)) {
            //cout << j + 1 << endl;
        //    goto A;
            //return 0;
        //}
    }
A:
    vector <int> stac(n);
    FOR (i, 0, n) {
        if (v[start[i]] == start[i]) {
            stac[i] = 1;
        }
    }
    vector <int> cycle(n);
    FOR (i, 0, n) {
        int t = start[i];
        int c = 0;
        do {
            t = v[t];
            ++c;
        } while (t != start[i]);
        cycle[i] = c;
    }
    vector <int> used(n);
    FOR (j, 0, n) {
        FOR (i, 0, n) {
            start[i] = v[start[i]];
            used[start[i]] = 1;
        }
    }
    FOR (i, 0, used.size()) {
        if (used[i] == 0) {
            cycle[i] = 0;
        }
    }
    FOR (i, 0, n) {
        start[i] = i;
    }
    vector <int> predc(n, -1);
    FOR (j, 0, n + 2) {
        FOR (i, 0, n) {
            if (used[start[i]] && predc[i] == -1) {
                predc[i] = j;
            }
            start[i] = v[start[i]];
        }
    }
    //DEBA(cycle);
    //DEBA(used);
    //DEBA(predc);
    int maxpr = *max_element(IT(predc));
    int lcm1 = 1;
    FOR (i, 0, n) {
        if (cycle[i] != 0) {
            lcm1 = lcm(lcm1, cycle[i]);
        }
    }
    int lcm2 = lcm1;
    while (lcm2 < maxpr) {
        lcm2 += lcm1;
    }
    cout << lcm2;
}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend

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

const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 2e9 + 9;
const ll Q = 47;

using namespace std;

void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}
vector <int> sarr;
vector <int> order;

void build_sarr(string& s)
{
    int n = s.size() + 1;
    vector <int> cls(n);
    for (int i = 0; i < n - 1; ++i)
        cls[i] = s[i] - 'a';
    cls.back() = -1;
    vector <pair<pii, int>> tmp(n);

    for (int i = 1; i < n; i *= 2)
    {
        for (int j = 0; j < n; ++j)
            tmp[j] = {{cls[j], cls[(j + i) % n]}, j};
        stable_sort(tmp.B(), tmp.E());

        int last = 0;
        for (int j = 0; j < n; ++j)
        {
            if (j && tmp[j].F != tmp[j - 1].F)
                ++last;
            cls[tmp[j].S] = last;
        }
    }

    for (int i = 0; i < n - 1; ++i)
        sarr[cls[i] - 1] = i;
}

const int MAXN = 8e5 + 1;
int tree[MAXN];

int nlcp;

void build_lcp(int v, int l, int r, vector <int>& data)
{
    if (l == r)
    {
        tree[v] = data[l];
        return;
    }
    int m = (l + r) / 2;

    build_lcp(2 * v, l, m, data);
    build_lcp(2 * v + 1, m + 1, r, data);

    tree[v] = min(tree[2 * v], tree[2 * v + 1]);
}

int query(int v, int cl, int cr, int l, int r)
{
    if (cl >= l && cr <= r)
        return tree[v];
    if (r < cl || cr < l)
        return INF;
    int cm = (cl + cr) / 2;
    return min(query(2 * v, cl, cm, l, r), query(2 * v + 1, cm + 1, cr, l, r));
}

int query_lcp(int l, int r)
{
    if (l > r)
        return 0;
    if (order[r] < order[l])
        swap(l, r);
    return query(1, 0, nlcp - 1, min(order[l], order[r] - 1), max(order[l], order[r] - 1));
}

void divide(int l, int r, string& s, vector <int>& tandem)
{
    if (l > r)
        return;
    if (l == r)
    {
        tandem[l] = 0;
        return;
    }

    int m = (l + r) / 2;
    divide(l, m, s, tandem);
    divide(m + 1, r, s, tandem);
}

void build_tandem(string& s, vector<int>& tandem)
{
    fill(tandem.B(), tandem.E(), s.size());
    for (int i = 0; i < s.size(); ++i)
    {
        for (int j = i + 1; j < s.size(); ++j)
            if (query_lcp(i, j) >= j - i)
            {
                tandem[i] = j - i;
                break;
            }
    }
}

void build_rtandem(string& s, vector<int>& tandem)
{
    fill(tandem.B(), tandem.E(), s.size());
    for (int i = 0; i < s.size(); ++i)
    {
        for (int j = i + 1; j < s.size(); ++j)
            if (query_lcp(i, j) >= j - i)
            {
                tandem[j + j - i - 1] = min(tandem[j + j - i - 1], j - i);
            }
    }
}

signed main()
{
    hello();

    int n;
    string s;
    cin >> n >> s;

    sarr.resize(n);
    build_sarr(s);
    vector <int> lcp(n, -1);
    order.resize(n);
    int last = 0;

    for (int i = 0; i < n; ++i)
        order[sarr[i]] = i;

    for (int i = 0; i < n; ++i)
    {
        if (last)
            --last;
        if (order[i] == n - 1)
            continue;
        int v = i, u = sarr[order[i] + 1];
        while (max(v, u) + last < n && s[v + last] == s[u + last])
            ++last;
        lcp[order[i]] = last;
    }

    lcp.pop_back();
    nlcp = lcp.size();
    build_lcp(1, 0, nlcp - 1, lcp);
    vector <int> tandem(n), rtandem(n);
    build_tandem(s, tandem);
    build_rtandem(s, rtandem);

    vector <int> left(n), right(n);
    int sz = 500;

    vector <int> lst(26, -1);
    for (int i = 0; i < n; ++i)
    {
        right[i] = lst[s[i] - 'a'];
        lst[s[i] - 'a'] = i;
    }
    fill(lst.B(), lst.E(), n);
    for (int i = n - 1; i >= 0; --i)
    {
        left[i] = lst[s[i] - 'a'];
        lst[s[i] - 'a'] = i;
    }

    int q;
    cin >> q;
    // show(sarr);
    // show(lcp);
    // show(tandem);
    // show(rtandem);
    for (int v = 0; v < min(q, 300); ++v)
    {
        int l, r;
        cin >> l >> r;
        --l; --r;

        bool flag = 1;
        for (int i = l; i <= r; ++i)
            if (left[i] <= r)
                flag = 0;
        if (flag)
        {
            cout << -1 << endl;
            continue;
        }

        int len = r - l + 1;

        for (int val = 1; val * val <= len; ++val)
        {
            if (len % val)
                continue;
            if (query_lcp(l, l + val) == len - val)
            {
                flag = 1;
            }
            if (val == 1)
                continue;
            if (query_lcp(l, l + len / val) == len - len / val)
            {
                flag = 1;
            }
        }

        if (flag)
        {
            cout << 1 << endl;
            continue;
        }

        if (l + 2 * tandem[l] - 1 <= r)
        {
            cout << 2 << endl;
            continue;
        }
        if (r - 2 * rtandem[r] + 1 >= l)
        {
            cout << 2 << endl;
            continue;
        }

        for (int pos = 1; pos < sz; ++pos)
        {
            if (r - pos + 1 == l)
                break;
            if (query_lcp(l, r - pos + 1) >= pos)
            {
                flag = 1;
                break;
            }
        }
        int minn = INF;
        for (int pos = order[l]; pos < order[l] + sz; ++pos)
        {
            if (pos + 1 >= n)
                break;
            minn = min(minn, lcp[pos]);
            if (sarr[pos + 1] + minn - 1 >= r && sarr[pos + 1] <= r && sarr[pos + 1] >= l)
            {
                flag = 1;
                break;
            }
        }
        for (int pos = order[l] - 1; pos > order[l] - sz; --pos)
        {
            if (pos < 0)
                break;
            minn = min(minn, lcp[pos]);
            if (sarr[pos] + minn - 1 >= r && sarr[pos] <= r && sarr[pos] >= l)
            {
                flag = 1;
                break;
            }
        }

        if (flag)
        {
            cout << 2 << endl;
            continue;
        }

        if (left[l] <= r)
        {
            cout << 3 << endl;
            continue;
        }

        if (right[r] >= l)
        {
            cout << 3 << endl;
            continue;
        }

        for (int i = l; i <= r; ++i)
        {
            if (i + 2 * tandem[i] - 1 <= r)
                flag = 1;
        }

        if (flag)
        {
            cout << 3 << endl;
            continue;
        }
        cout << 4 << endl;

    }
}


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

int main()
{
	int n,m;
	cin>>m>>n;
	if(n==1)
	{
        cout<<-1;
        return 0;
	}
	if(n==2&&m==3)
	{
        cout<<11;
        return 0;
	}
	if(n==3&&m==5)
	{
        cout<<11;
        return 0;
	}
	int sol=0;
	while(1)
	{
		if(n>=m+m)
		{
            cout<<sol+1;
            break;
		}
		if(n==m)
		{
            cout<<sol+5;
            break;
		}
		if(n>m)
		{
            cout<<sol+3;
            break;
		}
		if(ok==1)
		    {
		        m-=n-2;
		        sol+=4;
                ok=0;
		    }
		else
		{
			if(n/2==1)
			{
                cout<<-1;
                break;
			}
			m-=(n/2-1);
			sol+=2;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const long long mod = 998244353;

long long pow(long long a, long long b) {
    if (b == 0)return 1;
    if (b % 2 == 1) {
        return (pow(a, b - 1) * a) % mod;
    } else {
        long long y = pow(a, b / 2);
        return (y * y) % mod;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    long long n, k;
    cin >> n >> k;
    long long c[n + 1][n + 1];
    for (int i = 0; i < n + 1; ++i) {
        for (int j = 0; j < n + 1; ++j) {
            c[i][j] = 0;
        }
    }
    for (int m = 0; m < n + 1; ++m) {
        c[0][m] = 1;
    }
    for (int l = 1; l < n + 1; ++l) {
        for (int i = 1; i < n + 1; ++i) {
            c[l][i] = (c[l][i - 1] + c[l - 1][i - 1]) % mod;
        }
    }
    long long h[n];
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    long long hh[n];
    hh[n - 1] = h[0];
    for (int j = n - 2; j >= 0; --j) {
        hh[j] = h[j + 1];
    }
    long long eq = 0;
    vector<long long> a;
    vector<long long> aa;
    for (int i = 0; i < n; ++i) {
        if (h[i] == hh[i]) {
            eq++;
        } else {
            a.push_back(h[i]);
            aa.push_back(hh[i]);
        }
    }
    if (a.size() == 0) {
        cout << 0;
        exit(0);
    }
    long long ans = 0;
    for (long long cor = 0; cor <= (a.size() - 1) / 2; ++cor) {
        long long o = c[cor][a.size()];
        long long res = pow(k - 1, a.size() - cor);
        for (long long i = 0; i <= cor; ++i) {
            res -= (c[i][a.size() - cor] * pow(k - 2, a.size() - cor - i)) % mod;
            res %= mod;
        }
        ans += o * (res + mod) % mod;
        ans %= mod;
    }
    cout << (ans * pow(k, eq)) % mod;
}


//In The Name Of God;

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#defin181De F first
#define S second
#define mp make_pair

const ll Maxn = 1e5 + 7;
const ll Max = 1e3 + 7;
const ll Mod = 1e9 + 7;
const ll Inf = 1e9 ;

int dp[Maxn],ans,sum = 1;
int n,k;
string s,t;

main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
    cin>>s>>t>>k;
    n=s.size();
    dp[0]=1;
    for(int i=1;i<=k;i++){
        int s=0;
        for(int j=0;j<n;j++){
            dp[j]=sum-dp[j]+Mod;
            dp[j]%=Mod;
            s+=dp[j];
            s%=Mod;
        }
        sum=s;
    }
    string ss="";
    for(int i=n-1;i>=0;i--){
        ss=s[n-1];
        for(int j=0;j<n-1;j++)ss+=s[j];
        if(ss==t)
            ans+=dp[i],ans%=Mod;
        s=ss;
    }
    cout<<ans<<endl;
}


#ifndef ONPC
  #define _FORTIFY_SOURCE 0
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("no-stack-protector")
  #pragma GCC optimize("unroll-loops")
  #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
  #pragma GCC optimize("fast-math")
#endif

#include <bits/stdc++.h>

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif

const int MAXN = 100;
//#define int long long
const int INF = 1e9;

vector<vector<int>> g;

int ans = 0;
vector<int> to;

int ctr = 0;
int n;
vector<int> sz;

int dfs(int v, int p=-1){
	int tsz = 1;
	for (int i : g[v]){
		if (i == p) continue;
		tsz += dfs(i, v);
	}
	sz[v] = tsz;
	return tsz;
}

void fnd(int v, int p=-1) {
	for (int i : g[v]){
		if (i == p) continue;
		if (sz[i] * 2 >= n) {
			fnd(i, v);
			return;
		}
	}
	ctr = v;
}

vector<int> c;
void cdfs(int v, int p, int cl){
	c[v] = cl;
	for (int i : g[v]){
		if (i == p) continue;
		cdfs(i, v, cl);
	}
}

vector<int> d;
void ddfs(int v, int p = -1, int dd = 0){
	d[v] = dd;
	for (int i : g[v]){
		if (i == p) continue;
		ddfs(i, v, dd+1);
	}
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

	cin >> n;
	g.assign(n, vector<int> ());
	to.assign(n, 0);
	int a, b;
	for (int i =0 ; i < n-1; i++){
		cin >> a >> b;
		a--, b--;
		g[a].eb(b);
		g[b].eb(a);
	}

	sz.assign(n, 0);
	dfs(0);
	fnd(0);

	d.assign(n, 0);
	ddfs(ctr);

	dfs(ctr);

	c.assign(n, 0);
	int curc = 0;
	for (int i : g[ctr]){
		assert(sz[i] * 2 <= n);

		cdfs(i, ctr, curc);
		curc++;
	}
	c[ctr] = curc;

	vector<vector<int>> vs(curc);
	for (int i = 0; i < n; i++){
		if (i == ctr) continue;
		vs[c[i]].eb(i);
	}

	stable_sort(vs.begin(), vs.end(), [](const vector<int>& a, const vector<int>& b){
		return a.size() < b.size();
	});

	int tsz = 0;
	for (int i = 0; i < (int)vs.size(); i++){
		assert((int)vs[i].size() * 2 <= n);
		assert(i == 0 || vs[i].size() >= vs[i-1].size());
		//cout << "SX: " << vs[i].size() << '\n';
		tsz += (int)vs[i].size();
	}
	assert(tsz + 1 == n);

	assert(vs.size() >= g[ctr].size());

	set<pair<int, int>> s;
	for (int i = 0; i < (int)vs.size(); i++){
		s.insert(mp(-(int)vs[i].size(), i));
	}

	while ((int)s.size() > 1){
		auto r1 = *s.begin();
		s.erase(s.begin());
		auto r2 = *s.begin();
		s.erase(s.begin());

		int l = r1.ss;
		int r = r2.ss;

		int vl = vs[l].back();
		vs[l].pop_back();
		int vr = vs[r].back();
		vs[r].pop_back();

		to[vl] = vr;
		to[vr] = vl;
		assert(c[vl] != c[vr]);

		ans += d[vr] + d[vl] + d[vr] + d[vl];

		if (vs[l].size())
	    s.insert(mp(-(int)vs[l].size(), l));
	    if (vs[r].size())
	    s.insert(mp(-(int)vs[r].size(), r));
		//cerr << l << ' ' << r << '\n';
	}

	if (s.empty()){

		int v1 = 0;
		if (ctr == v1) v1++;
		int v2 = to[v1];

		to[ctr] = v1;
		//to[v1] = v2;
		to[v2] = ctr;

		//ans -= d[v1] + d[v1] + d[v2] + d[v2];
		//ans += d[v1];

	} else {
		assert((int)vs[l].size() < 2);
		int l = s.begin()->ss;
		int vv = vs[l][0];
		to[vv] = ctr;
		to[ctr] = vv;
		ans += (d[vv] << 1);
	}

	cout << ans << '\n';
	for (auto i : to) cout << i+1 << ' ';
	cout << '\n';

    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <ctime>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long double ld;

int BUBEN = 30;
int BUBEN2 = 5;
int BUBEN3 = 20;

class TaskH {
 public:
  void solveOne(istream &in, ostream &out) {
    ld start = clock() / (ld) CLOCKS_PER_SEC;

    int n;
    in >> n;
    vector<int> x(n + 1);
    vector<int> y(n + 1);
    for (int i = 0; i <= n; ++i) {
      in >> x[i] >> y[i];
    }
    vector<ld> offset;
    vector<ld> len;
    vector<ld> dx;
    vector<ld> dy;
    offset.push_back(0);
    for (int i = 0; i < n; ++i) {
      ld vx = x[i + 1] - x[i];
      ld vy = y[i + 1] - y[i];
      ld z = hypotl(vx, vy);
      dx.push_back(vx / z);
      dy.push_back(vy / z);
      len.push_back(z);
      offset.push_back(offset.back() + z);
    }
    auto ternary = [&](const auto& func, ld left, ld right) {
      while (right - left > 1e-12 * max((ld) 1.0, right)) {
        ld mleft = (2 * left + right) / 3;
        ld mright = (left + 2 * right) / 3;
        ld vleft = func(mleft);
        ld vright = func(mright);
        if (vleft > vright) {
          right = mright;
        } else {
          left = mleft;
        }
      }
      return func((left + right) / 2);
    };
    ld total = offset.back();

    auto where = [&](ld pos) {
      int i = lower_bound(all(offset), pos) - offset.begin() - 1;
      if (i < 0) i = 0;
      if (i >= n) i = n - 1;
      return i;
    };

    auto evalBefore = [&](ld pos) {
      int i = where(pos);
      ld xi = x[i] + dx[i] * (pos - offset[i]);
      ld yi = y[i] + dy[i] * (pos - offset[i]);

      ld bestBefore = 1;
      for (int j = 0; j < i; ++j) {
        auto eval2 = [&](ld t) {
          ld xj = x[j] + dx[j] * t;
          ld yj = y[j] + dy[j] * t;
          ld direct = pos - (offset[j] + t);
          return direct / max((ld) 1e-7, hypotl(xi - xj, yi - yj));
        };
        ld cur = ternary(eval2, 0, len[j]);
        bestBefore = max(bestBefore, cur);
      }
      return bestBefore;
    };

    auto evalAfter = [&](ld pos) {
      int i = where(pos);
      ld xi = x[i] + dx[i] * (pos - offset[i]);
      ld yi = y[i] + dy[i] * (pos - offset[i]);

      ld bestAfter = 1;
      for (int j = i + 1; j < n; ++j) {
        auto eval2 = [&](ld t) {
          ld xj = x[j] + dx[j] * t;
          ld yj = y[j] + dy[j] * t;
          ld direct = (offset[j] + t) - pos;
          return direct / max((ld) 1e-7, hypotl(xi - xj, yi - yj));
        };
        ld cur = ternary(eval2, 0, len[j]);
        bestAfter = max(bestAfter, cur);
      }
      return bestAfter;
    };

    auto eval = [&](ld pos) {
      return min(evalBefore(pos), evalAfter(pos));
    };

    ld STEP = total;
    vector<tuple<ld, int, ld>> best;
    while (best.size() < 1e6 && clock() / (ld) CLOCKS_PER_SEC < start + 1) {
      STEP *= 0.5;
      for (ld at = STEP; at <= total; at += STEP * 2) {
        best.emplace_back(eval(at), where(at), at);
      }
    }
    sort(all(best));

    auto reduce = [&]() {
      sort(all(best), [](const auto& a, const auto& b) {
        return get<0>(a) > get<0>(b);
      });
      int got = 0;
      vector<int> gotIn(n);
      for (int i = 0; i < best.size(); ++i) {
        if (got < BUBEN3 && gotIn[get<1>(best[i])] < BUBEN2) {
          best[got] = best[i];
          ++got;
          ++gotIn[get<1>(best[i])];
        }
      }
      best.resize(got);
    };

    while (clock() / (ld) CLOCKS_PER_SEC < start + 3) {
      reduce();
      STEP *= 0.5;
      sort(all(best), [](const auto& a, const auto& b) {
        return get<2>(a) < get<2>(b);
      });
      int old = best.size();
      ld prev = 0;
      for (int i = 0; i <= old; ++i) {
        ld cur;
        if (i == old) {
          cur = total;
        } else {
          cur = get<2>(best[i]);
        }
        if (cur - prev > 3 * STEP) {
          ld at = prev + STEP;
          best.emplace_back(eval(at), where(at), at);
          at = cur - STEP;
          best.emplace_back(eval(at), where(at), at);
        } else if (cur - prev > 2 * STEP) {
          ld at = (2 * prev + cur) / 3;
          best.emplace_back(eval(at), where(at), at);
          at = (prev + 2 * cur) / 3;
          best.emplace_back(eval(at), where(at), at);
        } else if (cur - prev > STEP) {
          ld at = (prev + cur) / 2;
          best.emplace_back(eval(at), where(at), at);
        }
        prev = cur;
      }
    }

    cerr << STEP << endl;

    ld res = 0;
    for (const auto& x : best) {
      res = max(res, get<0>(x));
    }
    out << res << "\n";
  }

  void solve(std::istream &in, std::ostream &out) {
    out.precision(20);
    int nt = 1;
    for (int it = 0; it < nt; ++it) {
      solveOne(in, out);
    }
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskH solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long LL;

struct par { LL x, y; };

LL modu, period;

inline LL M (LL x, LL y) {
	LL r(0);
	y = (y % modu + modu) % modu;
	for (; y; y >>= 1, x = (x + x) % modu) if (y & 1) r = (r + x) % modu;
	return r;
}

par getFib (LL x) // (F[x], F[x + 1])
{
	if (x == 0) return (par){0, 1};
	par y;
	if (x & 1)
	{
		y = getFib(x - 1);
		return (par){y.y, (y.x + y.y) % modu};
	}
	else
	{
		y = getFib(x / 2);
		return (par){M(y.x, y.y * 2 - y.x), (M(y.x, y.x) + M(y.y, y.y)) % modu};
	}
}

int main ()
{
	LL cx; cin >> cx;
	vector<LL> vpre, vcur;
	modu = 10; period = 60;
//	cout << '#' << endl;
	for (int i = 0; i < period; ++i)
		if (getFib(i).x == cx % modu) vcur.push_back(i);
	for (int _ = 2; _ <= 13; ++_)
	{
//		cout << _ << endl;
		vpre = vcur;
		vcur.clear();
		modu *= 10;
		LL f = (_ <= 3) ? 5 : 10;
		for(typeof vpre.begin() x:vpre){}
		for (LL x : vpre) for (LL i = 0, j; i < f; ++i)
			if (getFib(j = x + i * period).x == cx % modu)
				vcur.push_back(j);
		period *= f;
	}
	if (vcur.size())
		cout << *min_element(vcur.begin(), vcur.end()) << endl;
	else
		cout << -1 << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int i,j;
    cout<<"Inter the numbers"<<endl;
    cin>>i>>j;
    float temp1 = (i*30 + j/2) mode 360;
    int temp2 = (j*6) mode 360;

    cout<<"the answer is"<<endl;
    cout<<temp1<<":"<<temp2<<endl;
}