/** Micro Mezz Macro Flation -- Overheated Economy ., Last Update: Mar. 3th 2013 **/ //{ n  n /** Header .. **/ //{ n #define LOCAL n  n #include <functional> n #include <algorithm> n #include <iostream> n #include <fstream> n #include <sstream> n #include <iomanip> n #include <numeric> n #include <cstring> n #include <climits> n #include <cassert> n #include <cstdio> n #include <string> n #include <vector> n #include <bitset> n #include <queue> n #include <stack> n #include <cmath> n #include <ctime> n #include <list> n #include <set> n #include <map> n  n //#include <tr1/unordered_set> n //#include <tr1/unordered_map> n //#include <array> n  n using namespace std; n  n #define REP(i, n) for (int i=0;i<int(n);++i) n #define FOR(i, a, b) for (int i=int(a);i<int(b);++i) n #define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i) n #define REP_1(i, n) for (int i=1;i<=int(n);++i) n #define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i) n #define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i) n #define REP_C(i, n) for (int n____=int(n),i=0;i<n____;++i) n #define FOR_C(i, a, b) for (int b____=int(b),i=a;i<b____;++i) n #define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i>=a____;--i) n #define REP_N(i, n) for (i=0;i<int(n);++i) n #define FOR_N(i, a, b) for (i=int(a);i<int(b);++i) n #define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i) n #define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i) n #define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i) n #define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i) n #define REP_1_N(i, n) for (i=1;i<=int(n);++i) n #define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i) n #define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i) n #define REP_C_N(i, n) for (int n____=(i=0,int(n));i<n____;++i) n #define FOR_C_N(i, a, b) for (int b____=(i=0,int(b);i<b____;++i) n #define DWN_C_N(i, b, a) for (int a____=(i=b-1,int(a));i>=a____;--i) n #define REP_1_C_N(i, n) for (int n____=(i=1,int(n));i<=n____;++i) n #define FOR_1_C_N(i, a, b) for (int b____=(i=1,int(b);i<=b____;++i) n #define DWN_1_C_N(i, b, a) for (int a____=(i=b,int(a));i>=a____;--i) n  n #define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it) n #define REP_S(i, str) for (char*i=str;*i;++i) n #define REP_L(i, hd, nxt) for (int i=hd;i;i=nxt[i]) n #define REP_G(i, u) REP_L(i,hd[u],suc) n #define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; ) n #define REP_2(i, j, n, m) REP(i, n) REP(j, m) n #define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m) n #define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l) n #define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l) n #define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn) n #define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn) n  n #define ALL(A) A.begin(), A.end() n #define LLA(A) A.rbegin(), A.rend() n #define CPY(A, B) memcpy(A, B, sizeof(A)) n #define INS(A, P, B) A.insert(A.begin() + P, B) n #define ERS(A, P) A.erase(A.begin() + P) n #define BSC(A, x) (lower_bound(ALL(A), x) - A.begin()) n #define CTN(T, x) (T.find(x) != T.end()) n #define SZ(A) int((A).size()) n #define PB push_back n #define MP(A, B) make_pair(A, B) n #define PTT pair<T, T> n #define fi first n #define se second n  n #define Rush for(int ____T=RD(); ____T--;) n  n #define Display(A, n, m) {                        n  REP(i, n){                                n         REP(j, m) cout << A[i][j] <<    ;         n         cout << endl;                  n  }                            n } n  n #define Display_1(A, n, m) {          n  REP_1(i, n){                            n         REP_1(j, m) cout << A[i][j] <<    ;       n   cout << endl;                  n  }                            n } n  n #pragma comment(linker,  /STACK:36777216 ) n //#pragma GCC optimize ( O2 ) n  n string __file__(){ n     string res = __FILE__; n     int r = SZ(res) - 1; while (res[r] !=   . ) --r; n     int l = r - 1; while (res[l] !=     ) --l; ++l; n     return res.substr(l, r-l); n } n  n void Exec(string a, string b, string c){ n     if (b.empty()) b = __file__(); n     string cmd = a +     + b +  .  + c; n     system(cmd.c_str()); n } n  n void Ruby(string file =   ){Exec( ruby , file,  rb );} n void Python(string file =   ){Exec( python , file,  py );} n void Haskell(string file =   ){Exec( runghc , file,  hs );} n void Pascal(string file =   ){Exec( pascal , file,  pas );} n void Ocaml(string file =   ){Exec( ocaml , file,  ml );} n  n typedef long long LL; n //typedef long double DB; n typedef double DB; n typedef unsigned UINT; n typedef unsigned long long ULL; n  n typedef vector<int> VI; n typedef vector<char> VC; n typedef vector<string> VS; n typedef vector<LL> VL; n typedef vector<DB> VF; n typedef set<int> SI; n typedef set<string> SS; n typedef map<int, int> MII; n typedef map<string, int> MSI; n typedef pair<int, int> PII; n typedef pair<LL, LL> PLL; n typedef vector<PII> VII; n typedef vector<VI> VVI; n typedef vector<VII> VVII; n  n template<class T> inline T& RD(T &); n template<class T> inline void OT(const T &); n //inline int RD(){int x; return RD(x);} n inline LL RD(){LL x; return RD(x);} n inline DB& RF(DB &); n inline DB RF(){DB x; return RF(x);} n inline char* RS(char *s); n inline char& RC(char &c); n inline char RC(); n inline char& RC(char &c){scanf(  %c , &c); return c;} n inline char RC(){char c; return RC(c);} n //inline char& RC(char &c){c = getchar(); return c;} n //inline char RC(){return getchar();} n  n template<class T> inline T& RDD(T &x){ n     char c; for (c = getchar(); c <  - ; c = getchar()); n     if (c ==  - ){x =  0  - getchar(); for (c = getchar();  0  <= c && c <=  9 ; c = getchar()) x = x * 10 +  0  - c;} n     else {x = c -  0 ; for (c = getchar();  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;} n     return x; n } n  n inline LL RDD(){LL x; return RDD(x);} n  n template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;} n template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;} n 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;} n 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;} n 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;} n 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;} n template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);} n 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);} n 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);} n 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);} n 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);} n 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);} n inline char& RC(char &a, char &b){RC(a), RC(b); return a;} n inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;} n inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;} n 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;} n 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;} n 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;} n inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;} n inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;} n inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;} n 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;} n 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;} n 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;} n inline void RS(char *s1, char *s2){RS(s1), RS(s2);} n inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);} n template<class T0,class T1>inline void RDD(T0&a, T1&b){RDD(a),RDD(b);} n template<class T0,class T1,class T2>inline void RDD(T0&a, T1&b, T2&c){RDD(a),RDD(b),RDD(c);} n  n template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));} n template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));} n template<class T> inline void CLR(T &A){A.clear();} n  n template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);} n template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);} n 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);} n 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);} n 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);} n 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);} n template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);} n 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);} n 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);} n 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);} n 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);} n 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);} n template<class T> inline void CLR(priority_queue<T, vector<T>, less<T> > &Q){while (!Q.empty()) Q.pop();} n template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();} n template<class T> inline void CLR(stack<T> &S){while (!S.empty()) S.pop();} n  n  n template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);} n template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);} n 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);} n 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);} n 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);} n 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);} n template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);} n  n template<class T> inline bool EPT(T &a){return a.empty();} n template<class T> inline T& SRT(T &A){sort(ALL(A)); return A;} n template<class T> inline T& RVS(T &A){reverse(ALL(A)); return A;} n template<class T> inline T& UNQ(T &A){A.resize(unique(ALL(SRT(A)))-A.begin());return A;} n  n template<class T, class C> inline T& SRT(T &A, C B){sort(ALL(A), B); return A;} n  n //} n  n /** Constant List .. **/ //{ n  n const int MOD = int(1e9) + 7; n //int MOD = 99990001; n const int INF = 0x3f3f3f3f; n const LL INFF = 0x3f3f3f3f3f3f3f3fLL; n const DB EPS = 1e-9; n const DB OO = 1e20; n const DB PI = acos(-1.0); //M_PI; n  n const int dx[] = {-1, 0, 1, 0}; n const int dy[] = {0, 1, 0, -1}; n  n const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1}; n const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1}; n  n //} n  n /** Add On .. **/ //{ n // <<=  0. Nichi Joo ., //{ n template<class T> inline void checkMin(T &a,const T b){if (b<a) a=b;} n template<class T> inline void checkMax(T &a,const T b){if (a<b) a=b;} n template<class T> inline void checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);} n template<class T> inline void checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);} n template <class T, class C> inline void checkMin(T& a, const T b, C c){if (c(b,a)) a = b;} n template <class T, class C> inline void checkMax(T& a, const T b, C c){if (c(a,b)) a = b;} n template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);} n template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);} n template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));} n template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));} n template<class T> inline T sqr(T a){return a*a;} n template<class T> inline T cub(T a){return a*a*a;} n inline int ceil(int x, int y){return (x - 1) / y + 1;} n inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;} n inline int sgn(DB x, DB y){return sgn(x - y);} n  n inline DB cot(DB x){return (DB)1/tan(x);}; n inline DB sec(DB x){return (DB)1/cos(x);}; n inline DB csc(DB x){return (DB)1/sin(x);}; n  n //} n // <<=  1. Bitwise Operation ., //{ n namespace BO{ n  n inline bool _1(int x, int i){return bool(x&1<<i);} n inline bool _1(LL x, int i){return bool(x&1LL<<i);} n inline LL _1(int i){return 1LL<<i;} n inline LL _U(int i){return _1(i) - 1;}; n  n inline int reverse_bits(int x){ n     x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa); n     x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc); n     x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0); n     x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00); n     x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000); n     return x; n } n  n inline LL reverse_bits(LL x){ n     x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL); n     x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL); n     x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL); n     x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL); n     x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL); n     x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL); n     return x; n } n  n template<class T> inline bool odd(T x){return x&1;} n template<class T> inline bool even(T x){return !odd(x);} n template<class T> inline T low_bit(T x) {return x & -x;} n 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;} n template<class T> inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;} n template<class T> inline int cover_idx(T x){int p = 0; while (_1(p) < x ) ++p; return p;} n  n inline int clz(int x){return __builtin_clz(x);} n inline int clz(LL x){return __builtin_clzll(x);} n inline int ctz(int x){return __builtin_ctz(x);} n inline int ctz(LL x){return __builtin_ctzll(x);} n inline int lg2(int x){return !x ? -1 : 31 - clz(x);} n inline int lg2(LL x){return !x ? -1 : 63 - clz(x);} n inline int low_idx(int x){return !x ? -1 : ctz(x);} n inline int low_idx(LL x){return !x ? -1 : ctz(x);} n inline int high_idx(int x){return lg2(x);} n inline int high_idx(LL x){return lg2(x);} n inline int parity(int x){return __builtin_parity(x);} n inline int parity(LL x){return __builtin_parityll(x);} n inline int count_bits(int x){return __builtin_popcount(x);} n inline int count_bits(LL x){return __builtin_popcountll(x);} n  n } using namespace BO;//} n // <<=  2. Number Theory .,//{ n namespace NT{ n inline LL __lcm(LL a, LL b){return a*b/__gcd(a,b);} n inline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;} n inline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;} n inline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;} n inline int dff(int a, int b){a -= b; if (a < 0) a  += MOD; return a;} n inline void MUL(int &a, int b){a = (LL)a * b % MOD;} n inline int pdt(int a, int b){return (LL)a * b % MOD;} n  n inline int sum(int a, int b, int c){return sum(sum(a, b), c);} n inline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));} n inline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);} n inline int pdt(int a, int b, int c, int d){return pdt(pdt(pdt(a, b), c), d);} n  n inline int pow(int a, LL b){ n     int c(1); while (b){ n         if (b&1) MUL(c, a); n         MUL(a, a), b >>= 1; n     } n     return c; n } n  n template<class T> inline T pow(T a, LL b){ n     T c(1); while (b){ n         if (b&1) c *= a; n         a *= a, b >>= 1; n     } n     return c; n } n  n template<class T> inline T pow(T a, int b){ n     return pow(a, (LL)b); n } n  n inline int _I(int b){ n     int a = MOD, x1 = 0, x2 = 1, q; n     while (true){ n         q = a / b, a %= b; n         if (!a) return (x2 + MOD) % MOD; n         DEC(x1, pdt(q, x2)); n  n         q = b / a, b %= a; n         if (!b) return (x1 + MOD) % MOD; n         DEC(x2, pdt(q, x1)); n     } n } n  n inline void DIV(int &a, int b){MUL(a, _I(b));} n inline int qtt(int a, int b){return pdt(a, _I(b));} n  n struct Int{ n     int val; n  n     operator int() const{return val;} n  n     Int(int val = 0):val(val){ n         //val %= MOD; if (val < 0) val += MOD; n     } n     inline Int& operator +=(const int& rhs){ n         INC(val, rhs); n         return *this; n     } n     inline Int operator +(const int& rhs) const{ n         return sum(val, rhs); n     } n     inline Int& operator -=(const int& rhs){ n         DEC(val, rhs); n         return *this; n     } n     inline Int operator -(const int& rhs) const{ n         return dff(val, rhs); n     } n     inline Int& operator *=(const int& rhs){ n         MUL(val, rhs); n         return *this; n     } n     inline Int operator *(const int& rhs) const{ n         return pdt(val, rhs); n     } n     inline Int& operator /=(const int& rhs){ n         DIV(val, rhs); n         return *this; n     } n     inline Int operator /(const int& rhs) const{ n         return qtt(val, rhs); n     } n }; n  n const int PMAX = 1; n VI P; bitset<PMAX> isP; n void sieve(){ n     FOR(i, 2, PMAX){ n         if (!isP[i]) P.PB(i); n         for (int j=0;j<SZ(P)&&i*P[j]<PMAX;++j){ n             isP[i*P[j]]=1; if (!(i%P[j])) break; n         } n     } n } n  n inline int phi(int n){ n     int res = n; for (int i=2;sqr(i)<=n;++i) if (!(n%i)){ n         DEC(res, qtt(res, i)); n         do{n /= i;} while(!(n%i)); n     } n     if (n != 1) n         DEC(res, qtt(res, n)); n     return res; n } n  n } using namespace NT;//} n // <<=  7. Matrix Theory .,//{ n namespace MT{ n  n     const int N = 100; n     int n = 0; n  n     typedef int rec; n  n     struct matrix{ n         rec d[N][N]; n  n         void init(rec e = 0){RST(d); if(e) REP(i, n) d[i][i] = e;} n         matrix(rec e = 0){init(e);} n  n         matrix operator *(const matrix &rhs) const{ n             matrix res; //REP_3(i, j, k, n, n, n) res.d[i][j] += d[i][k] * rhs.d[k][j]; n             REP_2(i, j, n, n){ n                 LL tmp = 0; REP(k, n) tmp += (LL) d[i][k] * rhs.d[k][j]; n                 res.d[i][j] = tmp % MOD; n             } n             return res; n         } n  n         matrix& operator *=(const matrix& rhs){(*this) = (*this) * rhs;} n  n         inline int res(){ n             int res = 0; n             REP(i, n) INC(res, d[0][i]); n             //REP_2(i, j, n, n) INC(res, d[i][j]); n             return res; n         } n     }; n  n     /*inline matrix pow_sum(const matrix& a, LL nn){ n         if (nn == 1) return matrix(1); n         matrix t; REP_2(i, j, n, n) t.d[i][j] = t.d[i][j+n] = a.d[i][j]; n         FOR_C(i, n, n*2) t.d[i][i] = 1; n <<= 1; t = pow(t, nn), n >>= 1; n         REP_2(i, j, n, n) t.d[i][j] = t.d[i][j+n]; n         return t; n     }*/ n  n     inline matrix pow_sum(const matrix& a, LL nn){ n         if (nn == 1) return matrix(1); n         matrix t; REP_2(i, j, n, n) t.d[i][j] = a.d[i][j]; n         REP(i, n) t.d[i][i+n] = t.d[i+n][i+n] = 1; n <<= 1; t = pow(t, nn), n >>= 1; n         REP_2(i, j, n, n) t.d[i][j] = t.d[i][j+n]; n         return t; n     } n  n     template<class T> T pow_sum(T a, LL nn){ n         int _n = n; n = 1; matrix t; t.d[0][0] = a; n         t = pow_sum(t, nn), n = _n; n         return t.d[0][0]; n     } n  n } //using namespace MT;//} n // <<=  8. Stringology .,//{ n namespace SL{ n     namespace KMP{ n  n         void calc_pi(const char *P, int n, int *pi){ n             for (int i = 1, j = pi[0] = -1; i < n; ++i){ n                 while (j >= 0 && P[i] != P[j+1]) j = pi[j]; n                 if (P[i] == P[j+1]) ++j; n                 pi[i] = j; n             } n             //REP(i, n) cout << pi[i] <<    ; cout << endl; n         } n  n         bool run(const char *T, int n, const char *P, int m, const int *pi){ n             for (int i = 0, j = -1; i < n; ++i){ n                 while (j >= 0 && T[i] != P[j+1]) j = pi[j]; n                 if (T[i] == P[j+1]) ++j; n                 if (j == m - 1) return true; n             } n             return false; n         } n  n     } //using namespace KMP; n  n     namespace Z{ n         void calc_z(const char *P, int n, int *z){ n  n             z[0] = n; n  n             for (int i = 1, l = 0, r = 0; i < n; ++i){ n                 if (i > r){ n                     for(l = r = i; r < n && P[r] == P[r - l];) ++r; n                     z[i] = r - l, --r; n                 } n                 else { n                     if (z[i - l] < r - i + 1) z[i] = z[i - l]; n                     else { n                         for (l = i;r < n && P[r] == P[r - l];) ++r; n                         z[i] = r - l, --r; n                     } n                 } n             } n  n             //REP(i, n) cout << z[i] <<    ; cout << endl; n         } n  n         int run(const char *T, int n, const char *P, int m, const int *z){ n  n             int ex; REP_C_N(ex, min(n, m)) if (T[ex] != P[ex]) break; n  n             int res = ex == m; n  n             for (int i = 1, l = 0, r = 0; i < n; ++i){ n                 if (i > r){ n                     for (l = r = i; r < n && T[r] == P[r - l];) ++r; n                     ex = r - l, --r; n                 } n                 else { n                     if (z[i - l] < r - i + 1) ex = z[i - l]; n                     else { n                         for (l = i; r < n && T[r] == P[r - l];) ++r; n                         ex = r - l, --r; n                     } n                 } n                 if (ex == m) ++res; n             } n  n             return res; n         } n     } //using namespace Z; n  n     void Manacher(char s[], int n, int p[]){ n         const int NN = 0; n         static char ss[NN*2+2]; int nn = 2*n+2; n         ss[0] =  $ , ss[nn-1] =  # , ss[nn] = 0; n         REP(i, n) ss[i*2+1] = # , ss[i*2+2] = s[i]; n         int mx = 0, id = 0; FOR(i, 1, nn){ n             p[i] = mx > i ? min(p[2*id-i], mx - i) : 1; n             while (ss[i+p[i]] == ss[i-p[i]]) ++p[i]; n             if (i + p[i] > mx) mx = i + p[i], id = i; n         } n     } n  n } //using namespace SL;//} n // <<=  9. Comutational Geometry .,//{ n namespace CG{ n  n struct Po; struct Line; struct Seg; n  n struct Po{ n     DB x, y; Po(DB _x=0, DB _y=0):x(_x), y(_y){} n     friend istream& operator >>(istream& in, Po &p){return in >> p.x >> p.y;} n     friend ostream& operator <<(ostream& out, Po p){return out <<  (  << p.x <<  ,   << p.y <<  ) ;} n     bool operator ==(const Po& r)const{return !sgn(x-r.x) && !sgn(y-r.y);}; n     bool operator !=(const Po& r)const{return sgn(x-r.x) || sgn(y-r.y);} n     Po operator +(const Po& r)const{return Po(x+r.x, y+r.y);} n     Po operator -(const Po& r)const{return Po(x-r.x, y-r.y);} n     Po operator *(DB k)const{return Po(x*k,y*k);} n     Po operator /(DB k)const{return Po(x/k,y/k);} n     DB operator *(const Po&) const; n     DB operator ^(const Po&) const; n  n     bool operator <(const Po &r) const{return sgn(x,r.x)<0||!sgn(x,r.x)&&sgn(y,r.y)<0;} n     Po operator -()const{return Po(-x,-y);} n     Po& operator +=(const Po &r){x+=r.x,y+=r.y;return *this;} n     Po& operator -=(const Po &r){x-=r.x,y-=r.y;return *this;} n     Po& operator *=(DB k){x*=k,y*=k;return*this;} n     Po& operator /=(DB k){x/=k,y/=k;return*this;} n  n     DB length_sqr()const{return sqr(x)+sqr(y);} n     DB length()const{return sqrt(length_sqr());} n     Po unit()const{return *this/length();} n     bool dgt()const{return !sgn(x)&&!sgn(y);} n     DB atan()const{return atan2(y,x);} n     void rotate(DB alpha, const Po& o = Po()){ n         x -= o.x, y -= o.y; n         (*this) = Po(x * cos(alpha) - y * sin(alpha), y * cos(alpha) + x * sin(alpha)) + o; n     } n  n     void input(){RF(x,y);} n }; n  n Po operator *(DB k, Po a){return a * k;} n  n #define innerProduct dot n #define scalarProduct dot n #define outerProduct det n #define crossProduct det n  n inline DB dot(const DB &x1, const DB &y1, const DB &x2, const DB &y2){return x1 * x2 + y1 * y2;} n inline DB dot(const Po &a, const Po &b){return dot(a.x, a.y, b.x, b.y);} n inline DB dot(const Po &p0, const Po &p1, const Po &p2){return dot(p1 - p0, p2 - p0);} n  n inline DB det(const DB &x1, const DB &y1, const DB &x2, const DB &y2){return x1 * y2 - x2 * y1;} n inline DB det(const Po &a, const Po &b){return det(a.x, a.y, b.x, b.y);} n inline DB det(const Po &p0, const Po &p1, const Po &p2){return det(p1 - p0, p2 - p0);} n  n template<class T1, class T2> inline int dett(const T1 &x, const T2 &y){return sgn(det(x, y));} n template<class T1, class T2> inline int dott(const T1 &x, const T2 &y){return sgn(dot(x, y));} n 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));} n 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));} n 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));} n 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));} n  n  n  n inline int dist_sqr(const int &x1, const int &y1, const int &x2, const int &y2){ n     return sqr(x2-x1) + sqr(y2-y1); n } n  n inline DB dist_sqr(const DB &x, const DB &y){return sqr(x) + sqr(y);} n inline DB dist_sqr(const DB &x, const DB &y, const DB &z){return sqr(x) + sqr(y) + sqr(z);} n inline DB dist_sqr(const Po &a, const Po &b){return sqr(a.x - b.x) + sqr(a.y - b.y);} n  n template<class T1, class T2> inline DB dist(const T1 &x, const T2 &y){return sqrt(dist_sqr(x, y));} n 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));} n  n DB Po::operator *(const Po &r)const{return dot(*this, r);} n DB Po::operator ^(const Po &r)const{return det(*this, r);} n  n struct Line{ n     Po a, b; n  n     Line(DB x0=0, DB y0=0, DB x1=0, DB y1=0):a(Po(x0, y0)), b(Po(x1, y1)){} n     Line(const Po &a, const Po &b):a(a), b(b){} n     Line(const Line &l):a(l.a), b(l.b){} n  n     friend ostream& operator <<(ostream& out, Line p){return out << p.a <<  -  << p.b;} n     Line operator +(Po x)const{return Line(a + x, b + x);} n     DB length()const{return (b-a).length();} n     bool dgt()const{return (b-a).dgt();} n     void input(){a.input(), b.input();} n  n     int side(const Po& p){return dett(a, b, p);} n     bool same_side(const Po& p1, const Po& p2){return side(p1) == side(p2);} n     void getequation(DB& A, DB& B, DB& C) const{A = a.y - b.y, B = b.x - a.x, C = det(a, b);} n }; n  n struct Seg: Line{ n }; n  n inline DB dot(const Line &l1, const Line &l2){return dot(l1.b - l1.a, l2.b - l2.a);} n inline DB det(const Line &l1, const Line &l2){return det(l1.b - l1.a, l2.b - l2.a);} n  n 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();} n inline DB dist_sqr(const Po &p, const Seg &l){ n     Po v0 = l.b - l.a, v1 = p - l.a, v2 = p - l.b; n     if (sgn(dot(v0, v1)) * sgn(dot(v0, v2)) <= 0) return dist_sqr(p, Line(l)); n     else return min(v1.length_sqr(), v2.length_sqr()); n } n inline DB dist_sqr(Line l, Po p){return dist_sqr(p, l);} n inline DB dist_sqr(Seg l, Po p){return dist_sqr(p, l);} n inline DB dist_sqr(Line l1, Line l2){ n     if (sgn(det(l1, l2)) != 0) return 0; n     return dist_sqr(l1.a, l2); n } n inline DB dist_sqr(Line l1, Seg l2){ n     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); n     return sgn(c1) != sgn(c2) ? 0 : sqr(min(fabs(c1), fabs(c2))) / v0.length_sqr(); n } n  n bool isIntersect(Seg l1, Seg l2){ n  n     if (l1.a == l2.a || l1.a == l2.b || l1.b == l2.a || l1.b == l2.b) return true; n  n     return n         min(l1.a.x, l1.b.x) <= max(l2.a.x, l2.b.x) && n         min(l2.a.x, l2.b.x) <= max(l1.a.x, l1.b.x) && n         min(l1.a.y, l1.b.y) <= max(l2.a.y, l2.b.y) && n         min(l2.a.y, l2.b.y) <= max(l1.a.y, l1.b.y) && n     sgn( det(l1.a, l2.a, l2.b) ) * sgn( det(l1.b, l2.a, l2.b) ) <= 0 && n     sgn( det(l2.a, l1.a, l1.b) ) * sgn( det(l2.b, l1.a, l1.b) ) <= 0; n  n } n  n inline DB dist_sqr(Seg l1, Seg l2){ n     if (isIntersect(l1, l2)) return 0; n     else return min(dist_sqr(l1.a, l2), dist_sqr(l1.b, l2), dist_sqr(l2.a, l1), dist_sqr(l2.b, l1)); n } n  n inline bool isOnSide(const Po &p, const Seg &l){ n     return p == l.a || p == l.b; n } n  n inline bool isOnSeg(const Po &p, const Seg &l){ n     return sgn(det(p, l.a, l.b)) == 0 && n         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; n } n  n inline bool isOnSegg(const Po &p, const Seg &l){ n     return sgn(det(p, l.a, l.b)) == 0 && n         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; n } n  n inline Po intersect(const Line &l1, const Line &l2){ n     return l1.a + (l1.b - l1.a) * (det(l2.a, l1.a, l2.b) / det(l2, l1)); n } n  n // perpendicular foot n inline Po intersect(const Po & p, const Line &l){ n     return intersect(Line(p, p + Po(l.a.y - l.b.y, l.b.x - l.a.x)), l); n } n  n inline Po rotate(Po p, DB alpha, const Po &o = Po()){ n     p.rotate(alpha, o); n     return p; n } n  n } using namespace CG;//} n //} n  n template<class T> int LIS(int n, T* a){ n     VI b; b.PB(a[0]); FOR(i, 1, n){ n         if (b.back() < a[i]) b.PB(a[i]); n         else { n             b[lower_bound(ALL(b), a[i]) - b.begin()] = a[i]; n         } n     } n     return SZ(b); n } n  n template<class T, class C> int LIS(int n, T* a, C cmp){ n     vector<T> b; b.PB(a[0]); FOR(i, 1, n){ n         if (cmp(b.back(), a[i])) b.PB(a[i]); n         else { n             b[lower_bound(ALL(b), a[i], cmp) - b.begin()] = a[i]; n         } n     } n     return SZ(b); n } n  n  n template<class T> int LISS(int n, T* a, int* pre, int& lst){ n     VI b; b.PB(0); pre[0] = -1; FOR(i, 1, n){ n         if (a[b.back()] < a[i]) pre[i] = b.back(), b.PB(i); n         else { n             int l = 0, r = SZ(b); while (l < r){ n                 int m = l + r >> 1; n                 if (a[b[m]] < a[i]) l = m + 1; n                 else r = m; n             } n             pre[i] = !r ? -1 : b[r-1]; n             b[r] = i; n         } n     } n     lst = b.back(); n     return SZ(b); n } n  n template<class T, class C> int LISS(int n, T* a, int* pre, int& lst, C cmp){ n     VI b; b.PB(0); pre[0] = -1; FOR(i, 1, n){ n         if (cmp(a[b.back()], a[i])) pre[i] = b.back(), b.PB(i); n         else { n             int l = 0, r = SZ(b); while (l < r){ n                 int m = l + r >> 1; n                 if (cmp(a[b[m]], a[i])) l = m + 1; n                 else r = m; n             } n             pre[i] = !r ? -1 : b[r-1]; n             b[r] = i; n         } n     } n  n     lst = b.back(); n     return SZ(b); n } n  n /** Miscellaneous .. **/ //{ n // <<=  Random Event .. . //{ n namespace RNG{ n //srand((unsigned)time(NULL)); n inline unsigned int rand16(){return ((rand()) << 15) ^ rand();} n inline unsigned int rand32(){return (rand16() << 16) | rand16();} n inline ULL rand64(){return ((LL)rand32() << 32) | rand32();} n inline ULL random(LL l, LL r){return l == r ? l : rand64() % (r - l) + l;} n int dice(){return rand() % 6;} n bool coin(){return bool(rand() % 2);} n } using namespace RNG; n //} n // <<=  Clock .. . //{ n namespace CLOCK{ n DB s0, s1, rd, k, T; n inline DB getTime(){ n #ifdef LOCAL n     return 1.0 * clock() / CLOCKS_PER_SEC; n #else n     timeval tv; n     gettimeofday(&tv, 0); n     return tv.tv_sec + tv.tv_usec * 1e-6; n #endif n } n  n inline void st0(DB _T = 0.98){T = _T, s0 = getTime();} n inline void st1(DB _k = 1.618){k = _k, s1 = getTime();} n inline void ed1(){rd = getTime() - s1;} n inline DB elapsed(){return getTime() - s0;} n inline bool TLE(){return elapsed() + rd * k < T;} n } //using namespace CLOCK; n //} n // <<=  Temp .. . //{ n namespace TMP{ n template<class T> PTT operator+(const PTT &p1, const PTT &p2) { n  return PTT(p1.fi + p2.fi, p1.se + p2.se); n } n  n template<class T> PTT operator-(const PTT &p1, const PTT &p2) { n  return PTT(p1.fi - p2.fi, p1.se - p2.se); n } n  n template<class T> PTT operator*(const PTT &lhs, T k){ n     return PTT(lhs.fi * k, lhs.se * k); n } n } using namespace TMP; n //} n // <<=  Bignum ., //{ n namespace BIGNUM{ n  n const int __base = 1e8; n const int P10[] = {1, 10, int(1e2), int(1e3), int(1e4), int(1e5), int(1e6), int(1e7), int(1e8), int(1e9)}; n const int MAX_BUF_SIZE = 109; n char __buf[MAX_BUF_SIZE]; n  n class bignum{ n           friend istream& operator>>(istream&, bignum&); n           friend ostream& operator<<(ostream&, const bignum&); n           friend bignum operator +(const bignum&, const bignum&); n           friend bignum operator -(const bignum&, const bignum&); n           friend bignum operator *(const bignum&, const bignum&); n           friend bignum operator /(const bignum&, const bignum&); n           friend bignum operator %(const bignum&, const bignum&); n           friend bignum operator +(const bignum&, const int&); n           friend bignum operator -(const bignum&, const int&); n           friend bignum operator *(const bignum&, const int&); n           friend bignum operator /(const bignum&, const int&); n           friend bignum operator %(const bignum&, const int&); n           friend bool operator ==(const bignum&, const bignum&); n           friend bool operator !=(const bignum&, const bignum&); n           friend bool operator <(const bignum&, const bignum&); n           friend bool operator >(const bignum&, const bignum&); n           friend bool operator <=(const bignum&, const bignum&); n           friend bool operator >=(const bignum&, const bignum&); n           friend bool operator ==(const bignum&, const int&); n           friend bool operator !=(const bignum&, const int&); n           friend bool operator <(const bignum&, const int&); n           friend bool operator >(const bignum&, const int&); n           friend bool operator <=(const bignum&, const int&); n           friend bool operator >=(const bignum&, const int&); n           friend int do_comp(const bignum&, const int&); n           friend int do_comp(const bignum&, const bignum&); n           friend void divide(const bignum&, const bignum&, bignum&, bignum&); n           friend bignum pow(bignum, int); n           friend bignum pow(int, int); n     public: n         inline bignum(){}; n         inline bignum(int s){ n             while (s) data.PB(s%__base), s/=__base; n             if (data.empty()) data.PB(0); n         } n  n         inline bignum(long long s){ n             while (s) data.PB(int(s%__base)), s/=__base; n             if (data.empty()) data.PB(0); n         } n  n         inline bignum(string s){ n             int t, i; CLR(data); n             for (i=int(s.size())-8;i>0;i-=8){ n                 istringstream(s.substr(i, 8)) >> t; n                 data.PB(t); n             } n             istringstream(s.substr(0, i+8)) >> t; n             data.PB(t); n         } n  n         void input(){ n             CLR(data); RS(__buf); int t = 0, c = 0; n             DWN(i, strlen(__buf), 0){ n                 t += P10[c] * (int(__buf[i]) -  0 ), ++c; n                 if (c == 8) data.PB(t), c = t = 0; n             } n             if (c) data.PB(t); n         } n  n         void operator =(const int); n         void operator =(const string); n         void operator =(const bignum); n         bignum& operator +=(const bignum&); n         bignum& operator -=(const bignum&); n         bignum& operator *=(const bignum&); n         bignum& operator /=(const bignum&); n         bignum& operator %=(const bignum&); n         bignum& operator +=(const int&); n         bignum& operator -=(const int&); n         bignum& operator *=(const int&); n         bignum& operator /=(const int&); n         bignum& operator %=(const int&); n         bool undefined(); n         int do_try(const int&); n         int do_try(const bignum&); n         void do_trim(); n         list<int> data; n  n     int size(){ n         list<int>::iterator it; int res = 0; n         for (it=data.begin(); it!=data.end();it++) n             res += 8; n         it--; n         if (*it >= 10000) { n             if ( (*it) >= 1000000) {if (*it >=10000000) ; else res--;} n             else {if ((*it) >= 100000) res-=2; else res-=3;} n         } n         else n             if ( (*it) >= 100) {if (*it >=1000) res-=4; else res-=5;} n             else {if ((*it) >= 10) res-=6; else res-=7;} n  n         return res; n     } n  n     void do_reserve(int a){ n         if (a <= 0) return; n         list<int>::iterator it; n         for (it=data.begin(); it!=data.end() && a>0; it++) a-=8; n         if (it == data.end() && a>=0) return; n         a+=8, it--; int f = 1; n         for (int i=0;i<a;i++) f *= 10; (*it) %= f; n         data.erase(++it, data.end()); n         do_trim(); n     } n }; n  n inline void bignum::operator =(const bignum a){ n     data.clear(); n     for (list<int>::const_iterator i=a.data.begin();i!=a.data.end();i++){ n         data.PB(*i); n     } n } n inline void bignum::operator =(const string a){ n     (*this) = bignum(a); n } n inline void bignum::operator =(const int a){ n     (*this) = bignum(a); n } n  n inline istream& operator>>(istream& input, bignum& a){ n     string s; int t, i; input >> s; a.data.clear(); n     for (i=int(s.size())-8;i>0;i-=8){ n         istringstream(s.substr(i, 8)) >> t; n         a.data.PB(t); n     } n     istringstream(s.substr(0, i+8)) >> t; n     a.data.PB(t); n     return input; n } n  n inline ostream& operator<<(ostream& output, const bignum& a){ n     list<int>::const_reverse_iterator i=a.data.rbegin(); n     output << *i; n     for (i++;i!=a.data.rend();i++){ n         if (*i >= 10000) { n             if (*i >= 1000000) {if (*i>=10000000) cout << *i; else cout << 0 << *i;} n             else {if (*i>=100000) cout <<  00  << *i; else cout <<  000  << *i;} n         } n         else { n             if (*i >= 100) {if (*i>=1000)  cout <<  0000  << *i; else cout <<  00000  << *i;} n             else { if (*i>=10) cout <<  000000  << *i; else cout <<  0000000  << *i;} n         } n     } n     return output; n } n  n inline bool bignum::undefined(){ n     return data.empty(); n } n  n inline int do_comp(const bignum& a, const bignum& b){ n     if (a.data.size()<b.data.size()) return -1; if (a.data.size()>b.data.size()) return 1; n     list<int>::const_reverse_iterator i; list<int>::const_reverse_iterator j; n     for (i=a.data.rbegin(),j=b.data.rbegin(); j!=b.data.rend(); i++,j++){ n         if (*i<*j) return -1;              //!!!! n         if (*i>*j) return 1; n     } n     return 0; n } n inline int do_comp(const bignum& a, const int& b){ n     return do_comp(a, bignum(b)); n } n  n inline bool operator ==(const bignum& a, const bignum& b){ n     return do_comp(a, b) == 0; n } n inline bool operator !=(const bignum& a, const bignum& b){ n     return do_comp(a, b) != 0; n } n inline bool operator <(const bignum& a, const bignum& b){ n     return do_comp(a, b) == -1; n } n inline bool operator >(const bignum& a, const bignum& b){ n     return do_comp(a, b) == 1; n } n inline bool operator <=(const bignum& a, const bignum& b){ n     return do_comp(a, b) != 1; n } n inline bool operator >=(const bignum& a, const bignum& b){ n     return do_comp(a, b) != -1; n } n  n inline bool operator ==(const bignum& a, const int& b){ n     return do_comp(a, b) == 0; n } n inline bool operator !=(const bignum& a, const int& b){ n     return do_comp(a, b) != 0; n } n inline bool operator <(const bignum& a, const int& b){ n     return do_comp(a, b) == -1; n } n inline bool operator >(const bignum& a, const int& b){ n     return do_comp(a, b) == 1; n } n inline bool operator <=(const bignum& a, const int& b){ n     return do_comp(a, b) != 1; n } n inline bool operator >=(const bignum& a, const int& b){ n     return do_comp(a, b) != -1; n } n  n inline void bignum::do_trim(){ n     while (data.size()>1&&data.back()==0) data.pop_back(); n } n  n inline bignum& bignum::operator +=(const bignum& a){ n     list<int>::iterator i; list<int>::const_iterator j; int t = 0; n     for (i=data.begin(),j=a.data.begin(); i!=data.end()&&j!=a.data.end(); i++,j++){ n         *i+=*j+t; t=*i/__base; *i%=__base; n     } n     while (i!=data.end()) {*i+=t; t=*i/__base; *i%=__base; i++;} n     while (j!=a.data.end()) {data.PB(t+*j); t=data.back()/__base; data.back()%=__base; j++;} n     if (t!=0) data.PB(t); n     return *this; n } n  n inline bignum& bignum::operator -=(const bignum& a){ n     list<int>::iterator i; list<int>::const_iterator j; int t = 0; n     for (i=data.begin(),j=a.data.begin(); j!=a.data.end(); i++,j++){ n         *i -= t+*j; if (*i>=0) t=0; else *i+=__base, t=1; n     } n     while (i!=data.end()) {*i-=t; if (*i>=0) t=0;else *i+=__base, t=1; i++;} n     (*this).do_trim(); n     return *this; n } n  n inline bignum& bignum::operator +=(const int& a){ n     return (*this)+=bignum(a); n } n  n inline bignum& bignum::operator -=(const int& a){ n     return (*this)-=bignum(a); n } n  n inline bignum operator +(const bignum& a, const bignum& b){ n     list<int>::const_iterator i, j; bignum c; int t = 0; n     for (i=a.data.begin(),j=b.data.begin(); i!=a.data.end()&&j!=b.data.end(); i++,j++){ n         c.data.PB(t+*i+*j); n         t=c.data.back()/__base; c.data.back()%=__base; n     } n     while (i!=a.data.end()) {c.data.PB(t+*i); t=c.data.back()/__base; c.data.back()%=__base; i++;} n     while (j!=b.data.end()) {c.data.PB(t+*j); t=c.data.back()/__base; c.data.back()%=__base; j++;} n     if (t!=0) c.data.PB(t); n     return c; n } n  n inline bignum operator -(const bignum& a, const bignum& b){ n     list<int>::const_iterator i, j; bignum c; int t = 0; n     for (i=a.data.begin(),j=b.data.begin(); j!=b.data.end(); i++,j++){ n         t = *i - t; n         if (t>=*j) c.data.PB(t-*j), t=0; n         else c.data.PB(t+__base-*j), t=1; n     } n     while (i!=a.data.end()) {t=*i-t; if (t>=0) c.data.PB(t), t=0;else c.data.PB(t+__base), t=1; i++;} n     c.do_trim(); n     return c; n } n  n inline bignum operator *(const bignum& a, const bignum& b){ n     list<int>::const_iterator i, j; list<int>::iterator k, kk; bignum c; long long t = 0; n  n     for (int i=0;i<a.data.size()+b.data.size();i++) c.data.PB(0); n     for (i=a.data.begin(),k=c.data.begin(); i!=a.data.end(); i++,k++){ n         for (j=b.data.begin(),kk=k; j!=b.data.end(); j++,kk++){ n             t+=(long long)(*i)*(*j)+(*kk); n             *kk=int(t%__base); t/=__base; n         } n         *kk+=t; t=0; n     } n     c.do_trim(); n     return c; n } n  n inline int bignum::do_try(const bignum& a){ n     int l = 1, r = 99999999, m, t; n     while (l+2<r){ n         m = (l + r) / 2; n         t = do_comp(*this, a*bignum(m)); n         if (t==0) return m; n         if (t<0) r = m - 1; n         else l = m; n     } n     while (do_comp(*this, a*bignum(r))<0) r--; n     return r; n } n  n inline void divide(const bignum& a, const bignum& b, bignum& d, bignum& r){ n     list<int>::const_reverse_iterator i = a.data.rbegin(); int t; n     d = bignum(0); r = bignum(0); n     do { n         while (r<b&&i!=a.data.rend()){d.data.push_front(0);r.data.push_front(*i);r.do_trim();i++;} n         if (r>=b){ n             t = r.do_try(b); d.data.front() = t; n             r-=(b*bignum(t)); n         } n     } while (i!=a.data.rend()); n     d.do_trim(); n } n  n inline bignum operator /(const bignum& a, const bignum& b){ n     bignum d, r; n     divide(a, b, d, r); n     return d; n } n  n inline bignum operator %(const bignum& a, const bignum& b){ n     bignum d, r; n     divide(a, b, d, r); n     return r; n } n  n inline bignum operator +(const bignum& a, const int& b){ n     return a+bignum(b); n } n  n inline bignum operator -(const bignum& a, const int& b){ n     return a-bignum(b); n } n  n inline bignum operator *(const bignum& a, const int& b){ n     return a*bignum(b); n } n  n inline bignum operator /(const bignum& a, const int& b){ n     return a/bignum(b); n } n  n inline bignum operator %(const bignum& a, const int& b){ n     return a%bignum(b); n } n  n inline bignum& bignum::operator *=(const bignum& a){ n     (*this) = (*this) * a; n     return *this; n } n  n inline bignum& bignum::operator /=(const bignum& a){ n     (*this) = (*this) / a; n     return *this; n } n  n inline bignum& bignum::operator %=(const bignum& a){ n     (*this) = (*this) % a; n     return *this; n } n  n inline bignum& bignum::operator *=(const int& a){ n     return (*this)*=bignum(a); n } n  n inline bignum& bignum::operator /=(const int& a){ n     return (*this)/=bignum(a); n } n  n inline bignum& bignum::operator %=(const int& a){ n     return (*this)%=bignum(a); n } n  n inline bignum pow(bignum a,int b){ n     bignum c(1); n     while (b!=0) { n         if (b&1) c *= a; n         a = a * a; b >>= 1; n     } n     return c; n } n inline bignum pow(int a, int b){ n     return pow(bignum(a), b); n } n  n } //using namespace BIGNUM; n //} n //} n  n /** I/O Accelerator Interface .. **/ //{ n template<class T> inline T& RD(T &x){ n     //cin >> x; n     //scanf( %d , &x); n     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 ; n     //char c; c = getchar(); x = c -  0 ; for (c = getchar(); c >=  0 ; c = getchar()) x = x * 10 + c -  0 ; n     return x; n } n  n inline DB& RF(DB &x){ n     //cin >> x; n     scanf( %lf , &x); n     /*char t; while ((t=getchar())==   ||t==  n ); x = t -  0 ; n     while ((t=getchar())!=   &&t!=  n &&t!= . )x*=10,x+=t- 0 ; n     if (t== . ){DB l=1; while ((t=getchar())!=   &&t!=  n )l*=0.1,x += (t- 0 )*l;}*/ n     return x; n } n  n inline char* RS(char *s){ n     //gets(s); n     scanf( %s , s); n     return s; n } n  n LL last_ans; int Case; template<class T> inline void OT(const T &x){ n     //printf( Case %d: %d n , ++Case, x); n     printf( %lld  , x); n     //printf( %d n , x); n     //cout << x << endl; n     //last_ans = x; n } n //} n  n //}/* .................................................................................................................................. */ n  n const int N = int(2e3) + 9; n  n int Sun[N][N], Ray[N][N]; n int n, m; VI R; n  n bool inGrid(int x, int y){ n     return x >= 0 && y >= 0 && x < n && y < m; n } n  n const int _D = 4, _C = 10; n  n int dfss(int x, int y){ n     if (!Ray[x][y]) return 0; n     Ray[x][y] = 0; int res = 1; REP(i, 4){ n         int xx = x + dx[i], yy = y + dy[i]; n         if (inGrid(xx, yy) && Ray[xx][yy]) res += dfss(xx, yy); n     } n     return res; n } n  n int dfs(int x, int y){ n     Sun[x][y] = 0; int res = dfss(x, y) >= 10; REP(i, 4){ n         int xx = x + dx[i], yy = y + dy[i]; n         if (inGrid(xx, yy) && Sun[xx][yy]) res += dfs(xx, yy); n     } n     return res; n } n  n int main(){ n  n #ifndef ONLINE_JUDGE n     freopen( 01.in.txt ,  r , stdin); n     //freopen( out.txt ,  w , stdout); n #endif n  n     RD(n, m); REP_2(i, j, n, m) RD(Sun[i][j]); n  n  n     REP_2(i, j, n, m) if (Sun[i][j]){ n         int x, y, bj1, bj2; n  n         bj1 = bj2 = 0; REP_1(d, _D){ n             x = i + d, y = j; if (inGrid(x, y) && !Sun[x][y]) bj1 = 1; n             x = i - d, y = j; if (inGrid(x, y) && !Sun[x][y]) bj2 = 1; n         } n         if (bj1 && bj2){Ray[i][j] = 1; continue;} n  n         bj1 = bj2 = 0; REP_1(d, _D){ n             x = i, y = j + d; if (inGrid(x, y) && !Sun[x][y]) bj1 = 1; n             x = i, y = j - d; if (inGrid(x, y) && !Sun[x][y]) bj2 = 1; n         } n         if (bj1 && bj2){Ray[i][j] = 1; continue;} n     } n  n     REP_2(i, j, n, m) if (Sun[i][j]){ n         R.PB(dfs(i, j)); n     } n  n     /*REP_2(i, j, n, m){ n         cout << Ray[i][j]; n         if (j == m - 1) cout << endl; n     }*/ n  n     SRT(R); cout << SZ(R) <<endl; n     ECH(it, R) cout << (*it) <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int h; n long long n, des; n long long GetRes(long long l) { n   if (l == 1) return 0; n   if ((l + l / 2) % 2) { n     return 1 + GetRes(l / 2); n   } else { n     return pow(2, h - (int)(log2(l)) + 1) + GetRes(l / 2); n   } n } n int main() { n   while (cin >> h >> n) { n     des = pow(2, h) - 1 + n; n     cout << GetRes(des) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[1000]; n   int b[1000]; n   for (int i = 0; i < 1000; i++) a[i] = 1; n   int n, k, r = 1, fl; n   cin >> n >> k; n   for (int i = 0; i < k; i++) { n     cin >> b[i]; n     a[b[i]] = 0; n   } n   for (int i = 0; i < k; i++) { n     fl = 1; n     cout << b[i] <<    ; n     while (fl < n) { n       if (a[r] != 0) { n         cout << r <<    ; n         fl++; n         a[r] = 0; n       } n       r++; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 2e5 + 10; n const int inf = 0x3f3f3f3f; n const long long INF = 0x3f3f3f3f3f3f3f3f; n using namespace std; n int q, op, pos, r, x, len, l; n char ch[10], str[maxn]; n int tr[26][maxn]; n int lowbit(int x) { return x & (-x); } n void update(int x, int y, int n, int p) { n   for (int i = x; i <= n; i += lowbit(i)) tr[p][i] += y; n } n int getsum(int x, int p) { n   int ans = 0; n   for (int i = x; i; i -= lowbit(i)) ans += tr[p][i]; n   return ans; n } n int main() { n   str[0] =  a ; n   scanf( %s n%d , str + 1, &q); n   len = strlen(str); n   for (int i = 1; i < len; ++i) { n     update(i, 1, len, str[i] -  a ); n   } n   while (q--) { n     scanf( %d , &op); n     if (op == 1) { n       scanf( %d %s , &pos, ch); n       update(pos, -1, len, str[pos] -  a ); n       str[pos] = ch[0]; n       update(pos, 1, len, str[pos] -  a ); n     } else { n       scanf( %d %d , &l, &r); n       int ans = 0; n       for (int i = 0; i < 26; ++i) { n         if (getsum(r, i) - getsum(l - 1, i)) ++ans; n       } n       printf( %d n , ans); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Data { n   int sgn; n   long long delta; n   set<pair<long long, long long>> ranges; n   void flip(int a) { sgn = -sgn, delta = a - delta; } n   void trim(int l, int r) { n     if (l > r) return; n     long long xl = sgn * (l - delta), xr = sgn * (r - delta); n     if (sgn < 1) swap(xl, xr); n     while (!ranges.empty()) { n       pair<long long, long long> cur = *ranges.begin(); n       if (cur.first >= xl) break; n       ranges.erase(ranges.begin()); n       if (cur.second < xl) continue; n       ranges.insert(make_pair(xl, cur.second)); n     } n     while (!ranges.empty()) { n       pair<long long, long long> cur = *ranges.rbegin(); n       if (cur.second <= xr) break; n       ranges.erase(prev(ranges.end())); n       if (cur.first > xr) continue; n       ranges.insert(make_pair(cur.first, xr)); n     } n   } n   bool empty() { return ranges.empty(); } n   void add(int l, int r) { n     long long xl = sgn * (l - delta), xr = sgn * (r - delta); n     if (sgn == -1) swap(xl, xr); n     ranges.insert(make_pair(xl, xr)); n   } n   void add(int y) { n     long long x = sgn * (y - delta); n     ranges.insert({x, x}); n   } n   void clear() { n     ranges.clear(); n     sgn = 1; n     delta = 0; n   } n   bool contain(int y) { n     long long x = sgn * (y - delta); n     auto it = ranges.upper_bound({x, LLONG_MAX}); n     if (it == ranges.begin()) return 0; n     return (prev(it)->second) >= x && (prev(it)->first) <= x; n   } n }; n int n, a[500005]; n int solve() { n   int cnt = 0; n   Data Seg; n   Seg.clear(); n   for (int i = 0; i < n; i++) { n     Seg.trim(1, a[i] - 1); n     if (Seg.empty()) n       Seg.add(1, a[i] - 1); n     else n       cnt++; n     Seg.flip(a[i]); n     if (a[i] % 2 == 0) { n       int b = a[i] / 2; n       if (Seg.contain(b)) { n         cnt++; n         Seg.clear(); n       } n       Seg.add(b); n     } n   } n   return 2 * n - cnt; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int T; n   for (cin >> T; T--;) { n     cin >> n; n     for (int i = 0; i < n; i++) cin >> a[i]; n     cout << solve() << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n int n, k, m; n int a[1000000]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> k; n   int d = 0; n   if (n % 2 == 1) { n     d = (n / 2 + 1) * (n / 2 + 1); n     d += (n / 2) * (n / 2); n   } else { n     d = (n / 2) * (n / 2); n     d *= 2; n   } n   if (d < k) n     cout <<  NO ; n   else { n     cout <<  YES  << endl; n     int cnt = 0; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         if (cnt < k) { n           if (i % 2 == 1) { n             if (j % 2 == 1) n               cout <<  L , cnt++; n             else n               cout <<  S ; n           } else { n             if (j % 2 == 0) n               cout <<  L , cnt++; n             else n               cout <<  S ; n           } n         } else n           cout <<  S ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e4 + 100; n const int maxq = 2e4 + 100; n const int maxd = 15; n const int ha1 = 317, ha2 = 443, mod = 364417; n struct Que_Typ { n   int y, id; n   Que_Typ(int a = 0, int b = 0) { y = a, id = b; } n }; n int N, Que; n vector<Que_Typ> ope[maxn]; n long long Ans[maxq]; n struct Hash { n   int x, y; n   Hash(int a = 0, int b = 0) { x = a, y = b; } n   friend Hash operator+(const Hash &a, const Hash &b) { n     return Hash((a.x + b.x) % mod, (a.y + b.y) % mod); n   } n   friend Hash operator*(const Hash &a, const Hash &b) { n     return Hash((long long)a.x * b.x % mod, (long long)a.y * b.y % mod); n   } n   friend bool operator==(const Hash &a, const Hash &b) { n     return (a.x == b.x && a.y == b.y); n   } n   friend bool operator<(const Hash &a, const Hash &b) { n     if (a.x != b.x) return a.x < b.x; n     return a.y < b.y; n   } n   void printt() { printf( Hash %d %d n , x, y); } n }; n Hash po[(1 << maxd) + 10]; n struct Edge { n   int node, next, cha; n   Edge(int a = 0, int b = 0, int c = 0) { node = a, next = b, cha = c; } n } E[maxn * 2]; n int e_cnt, head[maxn]; n int bary[maxn]; n int siz[maxn], wei, minf; n struct Trie { n   int root, cnt, go[maxn][26], val[maxn]; n   long long sum[maxn], sum2[maxn]; n   map<Hash, int> Map; n   int create() { n     ++cnt; n     memset(go[cnt], 0, sizeof(go[cnt])); n     sum[cnt] = 0; n     sum2[cnt] = 0; n     val[cnt] = 0; n     return cnt; n   } n   void dfs(int last, int x, int p, Hash v, int d) { n     Map[v] = p; n     ++val[p]; n     for (int i = head[x]; i != -1; i = E[i].next) { n       int y = E[i].node, c = E[i].cha; n       if (bary[y] || y == last) continue; n       if (!go[p][c - 1]) go[p][c - 1] = create(); n       dfs(x, y, go[p][c - 1], v + Hash(c, c) * po[d], d + 1); n     } n   } n   void Pre_sum(int p, long long &ret) { n     sum[p] = ret; n     ret += val[p]; n     for (int i = (0), _i = (25); i <= _i; ++i) n       if (go[p][i]) Pre_sum(go[p][i], ret); n     sum2[p] = ret; n   } n   void build(int last, int x, int c = 0) { n     cnt = 0; n     root = create(); n     Map.clear(); n     if (c) { n       int p = root, d = 1; n       Hash v = Hash(0, 0); n       Map[v] = p; n       go[p][c - 1] = create(); n       dfs(last, x, go[p][c - 1], v + Hash(c, c) * po[d], d + 1); n     } else n       dfs(last, x, root, Hash(0, 0), 1); n     val[root] = 0; n     long long tt = 0; n     Pre_sum(root, tt); n   } n } Trie1, Trie2; n struct Tree { n   int wei, tim, id[maxn], fa[maxd][maxn]; n   Hash dtu[maxd][maxn], utd[maxd][maxn]; n   int siz[maxn], path[maxn], dep[maxn]; n   void get_skip_table(int x) { n     for (int j = (1), _j = (maxd - 1); j <= _j; ++j) { n       int y = fa[j - 1][x]; n       int z = fa[j - 1][y]; n       fa[j][x] = z; n       dtu[j][x] = dtu[j - 1][x] + dtu[j - 1][y] * po[1 << (j - 1)]; n       utd[j][x] = utd[j - 1][y] + utd[j - 1][x] * po[1 << (j - 1)]; n     } n   } n   int get_lca(int x, int y) { n     if (x == y) return x; n     if (id[x] > id[y]) swap(x, y); n     for (int j = (maxd - 1), _j = (0); j >= _j; --j) n       if (id[x] < id[fa[j][y]]) y = fa[j][y]; n     return fa[0][y]; n   } n   int skip(int x, int k) { n     for (; k; k -= (k & (-k))) { n       x = fa[__builtin_ctz(k)][x]; n     } n     return x; n   } n   int move(int x, int y, int k) { n     int lca = get_lca(x, y); n     int lenx = dep[x] - dep[lca]; n     int len = lenx + dep[y] - dep[lca]; n     return (k <= lenx ? skip(x, k) : skip(y, len - k)); n   } n   Hash get_dtu(int x, int k) { n     Hash ret = Hash(0, 0), s = Hash(1, 1); n     for (; k; k -= (k & (-k))) { n       int j = __builtin_ctz(k); n       ret = ret + dtu[j][x] * s; n       s = s * po[1 << j]; n       x = fa[j][x]; n     } n     return ret; n   } n   Hash get_utd(int x, int k) { n     Hash ret = Hash(0, 0); n     for (; k; k -= (k & (-k))) { n       int j = __builtin_ctz(k); n       ret = ret * po[1 << j] + utd[j][x]; n       x = fa[j][x]; n     } n     return ret; n   } n   void dfs(int last, int x) { n     siz[x] = 1; n     id[x] = ++tim; n     get_skip_table(x); n     for (int i = head[x]; i != -1; i = E[i].next) { n       int y = E[i].node, c = E[i].cha; n       if (y == last || bary[y]) continue; n       fa[0][y] = x; n       utd[0][y] = dtu[0][y] = Hash(c, c) * po[1]; n       dep[y] = dep[x] + 1; n       path[y] = c; n       dfs(x, y); n       siz[x] += siz[y]; n     } n   } n   void build(int x) { n     tim = 0; n     wei = x; n     fa[0][wei] = wei; n     utd[0][wei] = dtu[0][wei] = Hash(0, 0); n     dep[wei] = 0; n     path[wei] = 0; n     dfs(0, wei); n   } n } T0, T1; n void add_Edge(int x, int y, int c) { n   E[e_cnt] = Edge(y, head[x], c); n   head[x] = e_cnt++; n } n int compare(int x, int y, int wei) { n   int lca = T0.get_lca(x, y); n   int lenx = T0.dep[x] - T0.dep[lca]; n   int len = lenx + T0.dep[y] - T0.dep[lca]; n   int towei = T1.dep[x] - T1.dep[wei]; n   int le = 0, ri = min(towei, len) + 1; n   while (le + 1 < ri) { n     int mid = (le + ri) >> 1; n     Hash s1 = T1.get_dtu(x, mid); n     Hash s0 = (mid <= lenx ? T0.get_dtu(x, mid) n                            : T0.get_dtu(x, lenx) + n                                  T0.get_utd(T0.skip(y, len - mid), mid - lenx) * n                                      po[lenx]); n     (s1 == s0 ? le = mid : ri = mid); n   } n   if (le == towei) return 0; n   int c1 = T1.path[T1.skip(x, le)]; n   int c0 = n       (le < len n            ? T0.path[(le < lenx ? T0.skip(x, le) : T0.skip(y, len - le - 1))] n            : 0); n   return c1 - c0; n } n long long calc_cmp0(int x, int y, Trie &Tr, int &flag) { n   x = T0.move(x, y, T1.dep[x] - T1.dep[wei]); n   int lca = T0.get_lca(x, y); n   int lenx = T0.dep[x] - T0.dep[lca]; n   int len = lenx + T0.dep[y] - T0.dep[lca]; n   flag = (len > 0); n   int le = 0, ri = len + 1; n   while (le + 1 < ri) { n     int mid = (le + ri) >> 1; n     Hash s0 = (mid <= lenx ? T0.get_dtu(x, mid) n                            : T0.get_dtu(x, lenx) + n                                  T0.get_utd(T0.skip(y, len - mid), mid - lenx) * n                                      po[lenx]); n     (Tr.Map.find(s0) != Tr.Map.end() ? le = mid : ri = mid); n   } n   Hash s0 = n       (le <= lenx ? T0.get_dtu(x, le) n                   : T0.get_dtu(x, lenx) + n                         T0.get_utd(T0.skip(y, len - le), le - lenx) * po[lenx]); n   int c0 = n       (le < len n            ? T0.path[(le < lenx ? T0.skip(x, le) : T0.skip(y, len - le - 1))] n            : 0); n   int num = (le == 0 ? Tr.root : Tr.Map[s0]); n   long long ret = Tr.sum[num]; n   if (c0 == 0) return Tr.sum[num]; n   for (int i = (c0 - 1), _i = (25); i <= _i; ++i) n     if (Tr.go[num][i]) return Tr.sum[Tr.go[num][i]]; n   return Tr.sum2[num]; n } n void work(int last, int x, int &gg) { n   for (int i = (0), _i = (ope[x].size() - 1); i <= _i; ++i) { n     int y = ope[x][i].y, id = ope[x][i].id; n     int cmp = compare(x, y, wei); n     if (cmp < 0) { n       Ans[id] += gg; n     } else if (cmp == 0) { n       int flag; n       Ans[id] += calc_cmp0(x, y, Trie1, flag) - calc_cmp0(x, y, Trie2, flag); n       Ans[id] += flag; n     } n   } n   for (int i = head[x]; i != -1; i = E[i].next) { n     int y = E[i].node; n     if (bary[y] || y == last) continue; n     work(x, y, gg); n   } n } n void solve() { n   Trie1.build(0, wei); n   for (int i = (0), _i = (ope[wei].size() - 1); i <= _i; ++i) { n     int y = ope[wei][i].y, id = ope[wei][i].id; n     int flag; n     Ans[id] += calc_cmp0(wei, y, Trie1, flag); n   } n   for (int i = head[wei]; i != -1; i = E[i].next) { n     int y = E[i].node, c = E[i].cha; n     if (bary[y]) continue; n     Trie2.build(wei, y, c); n     int gg = T1.siz[wei] - T1.siz[y]; n     work(wei, y, gg); n   } n } n void find_bary(int last, int x, int &n) { n   siz[x] = 1; n   int maxf = 0; n   for (int i = head[x]; i != -1; i = E[i].next) { n     int y = E[i].node; n     if (y == last || bary[y]) continue; n     find_bary(x, y, n); n     siz[x] += siz[y]; n     maxf = max(maxf, siz[y]); n   } n   maxf = max(maxf, n - siz[x]); n   if (maxf < minf) minf = maxf, wei = x; n } n void vdc(int x, int n) { n   minf = N + 2, wei = x; n   find_bary(0, x, n); n   T1.build(wei); n   solve(); n   bary[wei] = 1; n   for (int i = head[wei]; i != -1; i = E[i].next) { n     int y = E[i].node; n     if (bary[y]) continue; n     vdc(y, siz[y]); n   } n } n int main() { n   po[0] = Hash(1, 1); n   po[1] = Hash(ha1, ha2); n   for (int i = (2), _i = ((1 << maxd)); i <= _i; ++i) po[i] = po[i - 1] * po[1]; n   for (; scanf( %d%d , &N, &Que) != EOF;) { n     e_cnt = 0; n     memset(head, 255, sizeof(head[0]) * (N + 2)); n     for (int i = (1), _i = (N - 1); i <= _i; ++i) { n       int x, y; n       char c[5]; n       scanf( %d%d%s , &x, &y, c); n       add_Edge(x, y, c[0] -  a  + 1); n       add_Edge(y, x, c[0] -  a  + 1); n     } n     for (int i = (1), _i = (N); i <= _i; ++i) ope[i].clear(); n     for (int i = (1), _i = (Que); i <= _i; ++i) { n       int x, y; n       scanf( %d%d , &x, &y); n       ope[x].push_back(Que_Typ(y, i)); n     } n     memset(bary, 0, sizeof(bary[0]) * (N + 2)); n     memset(Ans, 0, sizeof(Ans[0]) * (N + 2)); n     T0.build(1); n     vdc(1, N); n     for (int i = (1), _i = (Que); i <= _i; ++i) printf( %I64d n , Ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using std::cin; n using std::cout; n long long MOD = 998244353; n int main() { n   long long n, q; n   cin >> n >> q; n   for (int i = 0; i < q; i++) { n     long long curr; n     cin >> curr; n     string s; n     cin >> s; n     for (int c = 0; c < s.size(); c++) { n       long long bit = curr & -curr; n       if (s[c] ==  U ) { n         if (curr != (n + 1) / 2) { n           if (((curr - bit) & -(curr - bit)) != bit * 2) n             curr += bit; n           else n             curr -= bit; n         } n       } else if (s[c] ==  R ) { n         if (bit == 1) n           curr += 0; n         else n           curr += bit / 2; n       } else if (s[c] ==  L ) { n         if (bit == 1) n           curr += 0; n         else n           curr -= bit / 2; n       } n     } n     cout << curr <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NN = 100 * 1000 + 5; n map<pair<pair<int, long long>, int>, long long> dp; n vector<int> adj[NN]; n vector<long long> x; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int mod = (int)1e9 + 7; n int rec(int node, int parent, long long g, int state) { n   pair<pair<int, long long>, int> p = make_pair(make_pair(node, g), state); n   if (dp.find(p) != dp.end()) return dp[p]; n   long long& res = dp[p]; n   res = gcd(g, x[node]); n   res %= mod; n   long long new_g = gcd(g, x[node]); n   for (int child : adj[node]) { n     if (child == parent) continue; n     if (state == 0) { n       res += rec(child, node, g, 0); n       res %= mod; n     } n     res += rec(child, node, new_g, 1); n     res %= mod; n   } n   return res; n } n int main() { n   int n; n   scanf( %d , &n); n   x.resize(n); n   for (int i = 0; i < n; i++) { n     scanf( %lld , &x[i]); n   } n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--; n     b--; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   long long ans = rec(0, -1, 0, 0); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> graph[100001]; n bool vis[100001]; n vector<long long int> ans; n void dfs(long long int root) { n   vis[root] = true; n   ans.push_back(root); n   sort(graph[root].begin(), graph[root].end()); n   for (int i = 0; i < graph[root].size(); i++) { n     if (!vis[graph[root][i]]) dfs(graph[root][i]); n   } n } n void solve() { n   long long int a, b, c, d, i, j, k, l; n   cin >> a >> b; n   for (i = 0; i < b; i++) { n     cin >> c >> d; n     graph[c].push_back(d); n     graph[d].push_back(c); n   } n   memset(vis, false, sizeof(vis)); n   map<int, int> m; n   m[1] = 0; n   while (m.size()) { n     k = m.begin()->first; n     m.erase(k); n     ans.push_back(k); n     vis[k] = true; n     for (i = 0; i < graph[k].size(); i++) { n       if (!vis[graph[k][i]]) { n         m[graph[k][i]] = 0; n       } n     } n   } n   for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ; n } n int main() { n   int t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int cost; n   double amount; n   cin >> cost; n   string s[n]; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n   } n   int counter = 0; n   double sum = 0.0; n   for (int i = n - 1; i >= 0; i--) { n     if (s[i] ==  halfplus ) { n       counter++; n       sum = (sum + 0.5) * 2; n     } else if (s[i] ==  half ) { n       sum = sum * 2; n     } n   } n   double num; n   num = sum - (0.5 * counter); n   amount = cost * num; n   cout << (long long int)amount << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, y = 1; n   char ch =    ; n   for (; (ch !=  -  && (ch >  9  || ch <  0 )); ch = getchar()) n     ; n   if (ch ==  - ) y = -1, ch = getchar(); n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48; n   return x * y; n } n const int N = 1e6 + 10; n struct node { n   int to, nex; n } e[N << 1]; n int bgn[N], d[N], mx[N], son[N], ans[N], dfn[N], id[N], c[N]; n int n, cnt, tot; n void add(int x, int y) { n   e[++cnt] = (node){y, bgn[x]}; n   bgn[x] = cnt; n } n void dfs(int x, int fa) { n   mx[x] = d[x] = d[fa] + 1; n   for (register int i = bgn[x]; i; i = e[i].nex) { n     int y = e[i].to; n     if (y == fa) continue; n     dfs(y, x); n     if (mx[y] > mx[son[x]]) { n       son[x] = y; n       mx[x] = mx[y]; n     } n   } n } n void ins(int &p, int x, int k) { n   c[x] += k; n   if (c[x] > c[p] || c[x] == c[p] && p > x) p = x; n } n void solve(int x, int fa) { n   dfn[++tot] = x; n   id[x] = tot; n   if (son[x]) solve(son[x], x); n   int p = ans[son[x]]; n   for (register int i = bgn[x]; i; i = e[i].nex) { n     int y = e[i].to; n     if (y == fa || y == son[x]) continue; n     solve(y, x); n     for (register int j = 0; j <= mx[y] - d[y]; ++j) n       ins(p, id[x] + j + 1, c[id[y] + j]); n   } n   ins(p, id[x], 1); n   ans[x] = p; n } n int main() { n   int x, y, z, k; n   n = read(); n   for (register int i = 1; i < n; ++i) { n     x = read(); n     y = read(); n     add(x, y); n     add(y, x); n   } n   dfs(1, 0); n   solve(1, 0); n   for (register int i = 1; i <= n; ++i) printf( %d n , ans[i] - id[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool tep(pair<string, int> a, pair<string, int> b) { n   return a.second > b.second; n } n bool f(string s) { n   for (int i = 0; i < 10; i++) { n     if ((i == 2 || i == 5) && s[i] !=  - ) return 0; n     if ((i != 2 && i != 5) && s[i] ==  - ) return 0; n   } n   if (s.substr(6) !=  2013  && s.substr(6) !=  2014  && s.substr(6) !=  2015 ) n     return 0; n   if ((s[3] !=  0  && s[4] !=  0  && s[4] !=  1  && s[4] !=  2 ) || n       s[3] >  1  || (s[3] ==  0  && s[4] ==  0 )) n     return 0; n   if (s.substr(0, 2) ==  00 ) return 0; n   if (s.substr(3, 2) ==  02  && (s[0] >=  3  || (s[0] ==  2  && s[1] >  8 ))) n     return 0; n   if ((s.substr(3, 2) ==  04  || s.substr(3, 2) ==  06  || n        s.substr(3, 2) ==  09  || s.substr(3, 2) ==  11 ) && n       (s[0] >  3  || (s[0] ==  3  && s[1] >  0 ))) n     return 0; n   else if (s.substr(3, 2) !=  02  && n            (s[0] >  3  || (s[0] ==  3  && s[1] >  1 ))) n     return 0; n   return 1; n } n int main() { n   string str; n   vector<pair<string, int> > x; n   int xn = 0; n   cin >> str; n   for (int i = 0; i < str.length() - 9; i++) { n     string ss = str.substr(i, 10); n     if (f(ss)) { n       int j; n       for (j = 0; j < xn; j++) n         if (ss == x[j].first) { n           x[j].second++; n           break; n         } n       if (j == xn) { n         xn++; n         x.push_back(make_pair(ss, 1)); n       } n     } n   } n   pair<string, int> xx[xn]; n   for (int i = 0; i < xn; i++) { n     xx[i].first = x[i].first; n     xx[i].second = x[i].second; n   } n   sort(xx, xx + xn, tep); n   cout << xx[0].first << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double pie = 3.14159265358979323846; n bool isPowerOfTwo(long long int n) { n   if (n == 0) return false; n   return (ceill(log2l(n)) == floorl(log2l(n))); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int T, i, j, j1, k = 0, n, m, co = 0, check, mi, l, sum; n   long long int ans = 0; n   cin >> T; n   for (i = 0; i < T; i++) { n     string s, s1 =  twone , s2 =  two ; n     cin >> s; n     n = s.length(); n     set<long long int> second; n     for (j = 0; j < n - 4; j++) { n       co = 0; n       for (k = 0; k < 5; k++) { n         if (s[j + k] != s1[k]) { n           co = 1; n           break; n         } n       } n       if (co == 0) second.insert(j + 2); n     } n     for (j = 0; j < n - 2; j++) { n       co = 0; n       for (k = 0; k < 3; k++) { n         if (s[j + k] != s2[k]) { n           co = 1; n           break; n         } n       } n       if (co == 0 && second.find(j + 2) == second.end()) second.insert(j + 1); n     } n     s2 =  one ; n     for (j = 0; j < n - 2; j++) { n       co = 0; n       for (k = 0; k < 3; k++) { n         if (s[j + k] != s2[k]) { n           co = 1; n           break; n         } n       } n       if (co == 0 && second.find(j) == second.end()) second.insert(j + 1); n     } n     cout << second.size() << endl; n     for (auto w : second) { n       cout << w + 1 <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int ans = n; n   for (int i = 0; i < n / 2; i++) { n     string temp1 = s.substr(0, i + 1); n     string temp2 = s.substr(i + 1, i + 1); n     if (temp1 == temp2) ans = min(ans, n - i); n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n const int M = 2e3 + 50; n const int INF = 0x7fffffff; n const int mod = 1e9 + 7; n const int sz = 18; n const double eps = 1e-10; n const double pi = acos(-1); n long long n, m; n char str[N]; n int f[N]; n template <class T> n inline void read(T &x) { n   char c; n   x = 1; n   while ((c = getchar()) <  0  || c >  9 ) n     if (c ==  - ) x = -1; n   T res = c -  0 ; n   while ((c = getchar()) >=  0  && c <=  9 ) res = res * 10 + c -  0 ; n   x *= res; n } n int main() { n   int t; n   read(t); n   while (t--) { n     read(n); n     read(m); n     long long l, r; n     for (int i = 1; i <= n; i++) { n       long long tmp = 1ll * i * (i - 1) / 2; n       if (tmp >= m) { n         l = i; n         break; n       } n     } n     r = (l - 1) - ((l - 1) * l / 2 - m); n     l = n - l + 1; n     r = n - r + 1; n     for (int i = 1; i <= n; i++) { n       if (i == l || i == r) n         cout <<  b ; n       else n         cout <<  a ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   int n, m; n   scanf( %d%d , &n, &m); n   char c; n   scanf( %c , &c); n   int i, j; n   char word[n + 2][m + 2]; n   for (i = 0; i < n + 2; i++) n     for (j = 0; j < m + 2; j++) word[i][j] =  W ; n   int v[n + 1], h[m + 1]; n   for (i = 0; i <= n; i++) v[i] = 0; n   for (j = 0; j <= m; j++) h[j] = 0; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       scanf( %c , &word[i][j]); n       if (word[i][j] ==  B ) { n         v[i] += 1; n         h[j] += 1; n       } n     } n     scanf( %c , &c); n   } n   int left = m + 1, right = 0; n   for (j = 1; j <= m; j++) { n     if ((h[j] > 0) && (j < left)) left = j; n     if ((h[j] > 0) && (j > right)) right = j; n   } n   int up = 0, down = n + 1; n   for (i = 1; i <= n; i++) { n     if ((v[i] > 0) && (i > up)) up = i; n     if ((v[i] > 0) && (i < down)) down = i; n   } n   int notTrue = 0; n   for (i = down; i <= up; i++) { n     if (v[i] == 0) n       notTrue = 1; n     else { n       int black = 0; n       for (j = left; j <= right; j++) { n         if ((word[i][j] ==  B ) && (black == 0)) black = 1; n         if ((word[i][j] ==  W ) && (black == 1)) black = 2; n         if ((word[i][j] ==  B ) && (black == 2)) notTrue = 1; n       } n     } n   } n   for (j = left; j <= right; j++) { n     if (h[j] == 0) n       notTrue = 1; n     else { n       int black = 0; n       for (i = down; i <= up; i++) { n         if ((word[i][j] ==  B ) && (black == 0)) black = 1; n         if ((word[i][j] ==  W ) && (black == 1)) black = 2; n         if ((word[i][j] ==  B ) && (black == 2)) notTrue = 1; n       } n     } n   } n   while (up > down) { n     int lv = right, pv = left, ln = right, pn = left; n     for (j = left; j <= right; j++) { n       if ((word[up][j] ==  B ) && (lv > j)) lv = j; n       if ((word[up][j] ==  B ) && (pv < j)) pv = j; n       if ((word[down][j] ==  B ) && (ln > j)) ln = j; n       if ((word[down][j] ==  B ) && (pn < j)) pn = j; n     } n     if (lv > ln) lv = ln; n     if (ln > lv) ln = lv; n     if (pn < pv) pn = pv; n     if (pv < pn) pv = pn; n     if (((word[up][ln] ==  W ) && (word[up][pn] ==  B ) && n          (word[down][lv] ==  B ) && (word[down][pv] ==  W )) || n         ((word[down][lv] ==  W ) && (word[down][pv] ==  B ) && n          (word[up][ln] ==  B ) && (word[up][pn] ==  W ))) n       notTrue = 1; n     --up; n     ++down; n   } n   if (notTrue == 0) { n     printf( YES ); n   } else { n     printf( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(4) n using namespace std; n char _buf[100000], *_p1 = _buf, *_p2 = _buf; n inline int gi() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 3) + (x << 1) + (ch ^ 48); n     ch = getchar(); n   } n   return (f == 1) ? x : -x; n } n inline int max(int a, int b) { return a > b ? a : b; } n inline int min(int a, int b) { return a < b ? a : b; } n int T, n, m; n struct node { n   int x[3], y[3]; n   node(int a1, int b1, int a2, int b2, int a3, int b3) { n     x[0] = a1, x[1] = a2, x[2] = a3; n     y[0] = b1, y[1] = b2, y[2] = b3; n   } n   inline void output() { n     for (int i = 0; i <= 2; ++i) printf( %d %d  , x[i], y[i]); n   } n }; n const int maxn = 105; n vector<node> vec; n int a[maxn][maxn]; n char s[maxn]; n inline void init() { n   memset(a, 0, sizeof(a)); n   vec.clear(); n } n inline void input() { n   n = gi(), m = gi(); n   for (int i = 1; i <= n; ++i) { n     scanf( %s , s + 1); n     for (int j = 1; j <= m; ++j) a[i][j] = s[j] -  0 ; n   } n } n inline void change(int a1, int b1, int a2, int b2, int a3, int b3) { n   vec.push_back(node(a1, b1, a2, b2, a3, b3)); n   a[a1][b1] ^= 1, a[a2][b2] ^= 1, a[a3][b3] ^= 1; n } n inline void solve() { n   for (int i = 1; i <= n - 2; ++i) { n     for (int j = 1; j <= m - 1; ++j) { n       if (a[i][j] == 0 && a[i][j + 1] == 0) n         continue; n       else { n         if (a[i][j] == 0) { n           change(i, j + 1, i + 1, j, i + 1, j + 1); n         } else if (a[i][j + 1] == 1) { n           change(i, j, i, j + 1, i + 1, j); n         } else { n           change(i, j, i + 1, j, i + 1, j + 1); n         } n       } n     } n   } n   for (int i = 1; i <= m - 1; ++i) { n     if (a[n - 1][i] == 1 && a[n][i] == 1) { n       change(n - 1, i, n, i, n - 1, i + 1); n     } else if (a[n - 1][i] == 1) { n       change(n - 1, i, n, i + 1, n - 1, i + 1); n     } else if (a[n][i] == 1) { n       change(n, i, n - 1, i + 1, n, i + 1); n     } n   } n   if (a[n][m] == 1 && a[n - 1][m] == 1) { n     change(n - 1, m - 1, n - 1, m, n, m - 1); n     change(n - 1, m - 1, n, m - 1, n, m); n   } else if (a[n - 1][m] == 1) { n     change(n - 1, m, n - 1, m - 1, n, m - 1); n     change(n - 1, m - 1, n, m, n - 1, m); n     change(n, m - 1, n, m, n - 1, m); n   } else if (a[n][m] == 1) { n     change(n, m, n - 1, m - 1, n, m - 1); n     change(n - 1, m - 1, n, m, n - 1, m); n     change(n, m - 1, n, m, n - 1, m); n   } n   printf( %d n , (int)(vec.size())); n   for (auto x : vec) { n     x.output(); n     printf(  n ); n   } n } n int main() { n   T = gi(); n   while (T--) { n     init(); n     input(); n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long l, r, k, p, num; n   cin >> l >> r >> k; n   num = 1; n   int ans = 0; n   while (num <= r) { n     if (num >= l && num <= r) { n       cout << num; n       ans++; n     } n     num *= k; n     if (ans != 0) cout << endl; n     if (num % k != 0) break; n   } n   if (ans == 0) printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int ttt; n   cin >> ttt; n   for (int tttt = 0; tttt < ttt; tttt++) { n     long long n, m, a, b, x, y, xw1, yw1, xw2, yw2, xb1, yb1, xb2, yb2, n         sumw = 0, sumb = 0, tb, tw, x1, y1, x2, y2; n     cin >> n >> m; n     cin >> xw1 >> yw1 >> xw2 >> yw2; n     cin >> xb1 >> yb1 >> xb2 >> yb2; n     sumw = m * n / 2 + ((m * n) % 2); n     sumb = m * n / 2; n     x = xw2 - xw1 + 1; n     y = yw2 - yw1 + 1; n     if ((xw1 + yw1) % 2 == 0) { n       tw = x * y / 2 + ((x * y) % 2); n       tb = x * y / 2; n     } else { n       tb = x * y / 2 + ((x * y) % 2); n       tw = x * y / 2; n     } n     sumw += tb; n     sumb -= tb; n     x = xb2 - xb1 + 1; n     y = yb2 - yb1 + 1; n     if ((xb1 + yb1) % 2 == 0) { n       tw = x * y / 2 + ((x * y) % 2); n       tb = x * y / 2; n     } else { n       tb = x * y / 2 + ((x * y) % 2); n       tw = x * y / 2; n     } n     sumw -= tw; n     sumb += tw; n     x1 = max(xb1, xw1); n     y1 = max(yb1, yw1); n     x2 = min(xb2, xw2); n     y2 = min(yb2, yw2); n     x = x2 - x1 + 1; n     y = y2 - y1 + 1; n     if (x > 0 && y > 0) { n       if ((x1 + y1) % 2 == 0) { n         tw = x * y / 2 + ((x * y) % 2); n         tb = x * y / 2; n       } else { n         tw = x * y / 2; n         tb = x * y / 2 + ((x * y) % 2); n       } n       sumb += tb; n       sumw -= tb; n     } n     cout << sumw <<     << sumb << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n string s, p; n int cnt[26], cnt1[26], ans; n bool check() { n   for (int i = 0; i < 26; i++) n     if (cnt[i] > cnt1[i]) return false; n   return true; n } n int main() { n   cin >> s >> p; n   if (p.size() > s.size()) { n     cout << 0; n     return 0; n   } n   for (int i = 0; i < p.size(); i++) cnt1[p[i] -  a ]++; n   for (int i = 0; i < p.size(); i++) { n     if (s[i] !=  ? ) cnt[s[i] -  a ]++; n   } n   if (check() == true) ans++; n   for (int i = 1; i < s.size() - p.size() + 1; i++) { n     if (s[i - 1] !=  ? ) cnt[s[i - 1] -  a ]--; n     if (s[i + p.size() - 1] !=  ? ) cnt[s[i + p.size() - 1] -  a ]++; n     if (check()) ans++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string name[1001]; n int fen[1001]; n vector<pair<string, int> > old; n vector<pair<int, string> > xin; n vector<int> ff; n int main(int argc, char *argv[]) { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> name[i] >> fen[i]; n     old.push_back(make_pair(name[i], fen[i])); n   } n   sort(old.begin(), old.end()); n   for (int i = 0; i < (int)old.size(); i++) { n     if (i == (int)old.size() - 1 || old[i].first != old[i + 1].first) { n       xin.push_back(make_pair(old[i].second, old[i].first)); n     } n   } n   sort(xin.begin(), xin.end()); n   for (int i = 0; i < (int)xin.size(); i++) { n     ff.push_back(xin[i].first); n   } n   int sz = ff.size(), wz; n   cout << sz << endl; n   for (int i = 0; i < (int)xin.size(); i++) { n     wz = sz - (upper_bound(ff.begin(), ff.end(), ff[i]) - ff.begin()); n     if (wz * 2 > sz) { n       cout << xin[i].second <<   noob n ; n     } else if (wz * 5 > sz) { n       cout << xin[i].second <<   random n ; n     } else if (wz * 10 > sz) { n       cout << xin[i].second <<   average n ; n     } else if (wz * 100 > sz) { n       cout << xin[i].second <<   hardcore n ; n     } else { n       cout << xin[i].second <<   pro n ; n     } n   } n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 300; n char s[MAXN]; n int n; n void solve() { n   int maxv = 0, x = 0, y = 0, sum = 0, f = 0; n   s[n++] =  _ ; n   s[n] = 0; n   for (int i = 0; i < n; ++i) { n     if (!f) { n       if (s[i] ==  _ ) { n         x = 0; n       } else if (s[i] !=  ( ) { n         x++; n         maxv = max(maxv, x); n       } else { n         f = 1; n         x = 0; n       } n     } else { n       if (s[i] ==  _ ) { n         if (y) sum++; n         y = 0; n       } else if (s[i] !=  ) ) { n         y++; n       } else { n         if (y) sum++; n         f = 0, y = 0; n       } n     } n   } n   printf( %d %d n , maxv, sum); n } n int main() { n   while (~scanf( %d%s , &n, s)) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, num, maxs = INT_MIN, mins = INT_MAX, mins2 = INT_MAX; n   cin >> n >> m; n   vector<int> v1; n   vector<int> v2; n   for (int i = 0; i < n; i++) { n     cin >> num; n     v1.push_back(num); n     maxs = max(maxs, num); n     mins2 = min(mins2, num); n   } n   for (int i = 0; i < m; i++) { n     cin >> num; n     v2.push_back(num); n     if (num <= maxs) { n       cout <<  -1 ; n       return 0; n     } n     mins = min(mins, num); n   } n   for (int i = 0; i < n; i++) { n     if (2 * v1[i] <= maxs) { n       cout << maxs; n       return 0; n     } n   } n   for (int i = 0; i < n; i++) { n     if (2 * mins2 <= mins - 1) { n       cout << 2 * mins2; n       return 0; n     } n     if (2 * v1[i] <= mins - 1) { n       cout << mins - 1; n       return 0; n     } n   } n   cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, r = 0, m = 0; n   string s; n   cin >> n; n   while (!cin.eof()) { n     cin >> s; n     for (int i = 0; i < s.size(); i++) { n       if (int(s[i]) > 64 && int(s[i]) < 91) { n         r++; n       } n     } n     if (r > m) { n       m = r; n     } n     r = 0; n   } n   cout << m; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 212345, OFFSET = 3; n struct BITree { n   long long a[MAXN]; n   void clear() { memset(a, 0, sizeof(a)); } n   int lowbit(int i) { return (i & -i); } n   long long sum(int i) { n     long long ret = 0; n     for (i += OFFSET; i > 0; i -= lowbit(i)) ret += a[i]; n     return ret; n   } n   void add(int i, long long d) { n     for (i += OFFSET; i < MAXN; i += lowbit(i)) a[i] += d; n   } n } cnt, sum; n int h[MAXN]; n vector<pair<int, long long> > qq; n vector<int> H; n int find(int h) { return lower_bound(H.begin(), H.end(), h) - H.begin(); } n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   for (int i = 0; i < int(n); i++) scanf( %d , h + i); n   qq.resize(q); n   H = vector<int>(h, h + n); n   for (int i = 0; i < int(q); i++) { n     int t; n     scanf( %d , &t); n     if (t == 1) { n       int p, x; n       scanf( %d%d , &p, &x); n       qq[i].first = p - 1; n       qq[i].second = x; n       H.push_back(x); n     } else { n       long long v; n       scanf( %I64d , &v); n       qq[i].first = -1; n       qq[i].second = v; n     } n   } n   sort(H.begin(), H.end()); n   H.resize(unique(H.begin(), H.end()) - H.begin()); n   cnt.clear(); n   sum.clear(); n   for (int i = 0; i < int(n); i++) { n     h[i] = find(h[i]); n     cnt.add(h[i], 1); n     sum.add(h[i], H[h[i]]); n   } n   for (int i = 0; i < int(q); i++) { n     if (~qq[i].first) { n       int j = qq[i].first; n       cnt.add(h[j], -1); n       sum.add(h[j], -H[h[j]]); n       h[j] = find(qq[i].second); n       cnt.add(h[j], 1); n       sum.add(h[j], H[h[j]]); n     } else { n       long long v = qq[i].second; n       int l = 0, r = H.size() - 1; n       while (l < r) { n         int m = (l + r + 1) / 2; n         int tot = cnt.sum(m); n         long long vol = sum.sum(m); n         if (H[m] * (long long)tot - vol < v) n           l = m; n         else n           r = m - 1; n       } n       int tot = cnt.sum(l); n       long long vol = sum.sum(l); n       printf( %.10f n , n              H[l] + (v - (H[l] * (long long)tot - vol)) / (double)tot); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   cin >> n >> m; n   vector<long long> a(n); n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a.begin(), a.end()); n   long long sum = 0; n   for (long long i = 0; i < m; i++) { n     if (a[i] <= 0) sum += a[i]; n   } n   if (sum <= 0) { n     cout << abs(sum); n   } else { n     cout <<  0 ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000; n bool g[MAXN][MAXN]; n bool mh[MAXN], mv[MAXN]; n bool use[MAXN]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     g[a][b] = true; n     mv[a] = true; n     mh[b] = true; n   } n   int ans = 0; n   for (int i = 1; i < n - 1; i++) ans += !mh[i] + !mv[i]; n   if (n % 2 && !mh[n / 2] && !mv[n / 2]) ans--; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<long long int> > v, dp; n long long int ans, k; n void dfs(long long int u, long long int par) { n   long long int i; n   dp[u][0] = 1; n   for (auto it : v[u]) { n     if (it == par) continue; n     dfs(it, u); n     for (i = 1; i <= k; i++) ans += dp[it][i - 1] * dp[u][k - i]; n     for (i = 1; i <= k; i++) dp[u][i] += dp[it][i - 1]; n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t = 1; n   while (t--) { n     long long int n, i, x, y; n     cin >> n >> k; n     v.resize(n + 1); n     dp.resize(n + 1, vector<long long int>(k + 1)); n     ans = 0; n     for (i = 1; i < n; i++) { n       cin >> x >> y; n       v[x].push_back(y); n       v[y].push_back(x); n     } n     dfs(1, 0); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4e4 + 1; n int n, m, x[N], y[N], freq[N], q[N], vis[N], match[N], T, ans[N]; n vector<int> g[N]; n bool get(int u) { n   vis[u] = T; n   for (auto i : g[u]) { n     if (match[i] != -1 && vis[match[i]] == T) continue; n     if (match[i] == -1 || get(match[i])) { n       match[i] = u; n       return 1; n     } n   } n   return false; n } n int main() { n   scanf( %d%d , &n, &m); n   if (!m) return puts( 0 ), 0; n   memset(match, -1, sizeof match); n   for (int i = 0; i < m; i++) n     scanf( %d %d , x + i, y + i), x[i], y[i], freq[x[i]]++, freq[y[i]]++; n   int id = n + 1; n   for (int i = 0; i < m; i++) { n     g[x[i]].push_back(id); n     g[y[i]].push_back(id++); n   } n   int can = 0; n   queue<int> q; n   for (int i = 1; i <= n; i++) q.push(i); n   while (q.size()) { n     int x = q.front(); n     q.pop(); n     if (freq[x]) { n       freq[x]--; n       T++; n       if (get(x)) q.push(x), ans[x]++; n     } n   } n   for (int i = 1; i <= n; i++) can = max(can, ans[i]); n   printf( %d n , can); n   for (int i = 0; i < m; i++) n     if (match[i + n + 1] == y[i]) n       printf( %d %d n , y[i], x[i]); n     else n       printf( %d %d n , x[i], y[i]); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const int kMod = 998244353; n int inv(int b) { n   int e = kMod - 2; n   int r = 1; n   while (e) { n     if (e % 2) r = 1LL * r * b % kMod; n     b = 1LL * b * b % kMod; n     e /= 2; n   } n   return r; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, k, c; n   cin >> n >> k >> c; n   vector<int> a(n), mx(n, 0); n   int all = 0; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     for (int j = 0; j <= k; ++j) { n       mx[i] = max(mx[i], (a[i] ^ (a[i] - j))); n     } n     all ^= a[i]; n   } n   vector<int> order(n); n   iota(order.begin(), order.end(), 0); n   sort(order.begin(), order.end(), [&](int a, int b) { return mx[a] < mx[b]; }); n   vector<vector<int>> comb(2 * k + 1, vector<int>(2 * k + 1, 0)); n   for (int i = 0; i <= 2 * k; ++i) { n     comb[i][0] = comb[i][i] = 1; n     for (int j = 1; j < i; ++j) { n       comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % kMod; n     } n   } n   vector<vector<long long>> dp(k + 1, vector<long long>(1 << c, 0)); n   dp[0][0] = 1; n   int lim = 1; n   for (auto it : order) { n     for (int j = k; j >= 0; --j) { n       for (int i = 1; i + j <= k; ++i) { n         int val = (a[it] ^ (a[it] - i)) / 2; n         for (int x = 0; x < lim; ++x) n           dp[i + j][x ^ val] += comb[i + j][j] * dp[j][x]; n       } n     } n     for (int j = 0; j <= k; ++j) { n       int val = (a[it] ^ (a[it] - j)) / 2; n       while (lim <= val) lim *= 2; n     } n     for (int j = 0; j <= k; ++j) n       for (int x = 0; x < lim; ++x) dp[j][x] %= kMod; n   } n   int sub = 1, invn = inv(n); n   for (int i = 0; i < k; ++i) sub = 1LL * sub * invn % kMod; n   for (int i = 0; i < (1 << c); ++i) { n     int par = (k + all + i) % 2; n     if (par) n       cout << 0 <<    ; n     else n       cout << (dp[k][(i ^ all) / 2] * sub) % kMod <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int arr[n], odd = 0, even = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d , arr + i); n     if (arr[i] % 2) n       odd++; n     else n       even++; n   } n   sort(arr, arr + n); n   reverse(arr, arr + n); n   long long ans = 0; n   bool b = odd % 2; n   for (int i = 0; i < n; i++) { n     if (!b) { n       ans += arr[i]; n     } else { n       if (arr[i] % 2 && odd > 1) { n         ans += arr[i]; n         odd--; n       } else if (arr[i] % 2 == 0) { n         ans += arr[i]; n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(NULL); n   int m, n; n   cin >> m >> n; n   set<int> v[m]; n   for (int i = 0; i < m; i++) { n     int s; n     cin >> s; n     for (int j = 0; j < s; j++) { n       int x; n       cin >> x; n       v[i].insert(x); n     } n   } n   for (int i = 0; i < m; i++) { n     for (int j = i + 1; j < m; j++) { n       int cnt = 0; n       for (auto it : v[i]) { n         if (v[j].find(it) != v[j].end()) { n           cnt = 1; n           break; n         } n       } n       if (cnt == 0) { n         cout <<  impossible ; n         exit(0); n       } n     } n   } n   cout <<  possible ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   long long x, y; n   Point() {} n   Point(long long x0, long long y0) : x(x0), y(y0) {} n   void in() { scanf( %I64d %I64d , &x, &y); } n   long long operator*(Point pt) { return x * pt.y - y * pt.x; } n   Point operator-(Point pt) { return Point(x - pt.x, y - pt.y); } n   Point operator+(Point pt) { return Point(x + pt.x, y + pt.y); } n } p[1000010]; n int n; n long long solve(Point o) { n   long long ans = 0; n   int i, j; n   i = j = 1; n   while (i <= n) { n     while (i == j || (p[j + 1] - p[i]) * (o - p[i]) >= 0) j++; n     ans += (long long)(j - i) * (j - i - 1) / 2; n     i++; n   } n   return ans; n } n bool In_Polygon(Point o) { n   for (int i = 1; i <= n; i++) n     if ((p[i + 1] - p[i]) * (o - p[i]) <= 0) return false; n   return true; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) p[i].in(); n   for (int i = n + 1; i <= n + n; i++) p[i] = p[i - n]; n   reverse(p + 1, p + n + n + 1); n   int cas; n   scanf( %d , &cas); n   for (int cc = 1; cc <= cas; cc++) { n     Point o; n     o.in(); n     if (!In_Polygon(o)) n       cout << 0 << endl; n     else n       cout << (long long)n * (n - 1) * (n - 2) / 6 - solve(o) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> L[200005], W[200005]; n vector<pair<long long, int> > path; n int a[200005], add[200005], rmv[200005]; n int res[200005]; n void DFS(int u, long long dis) { n   int v, w, rem1 = 0, rem2 = 0; n   path.push_back(make_pair(dis, u)); n   for (int i = 0; i < L[u].size(); i++) { n     v = L[u][i]; n     w = W[u][i]; n     DFS(v, dis + W[u][i]); n     rem1 += add[v]; n     rem2 += rmv[v]; n   } n   int pos = lower_bound(path.begin(), path.end(), make_pair(dis - a[u], -1)) - n             path.begin(); n   if (pos != path.size() && path[pos].first >= dis - a[u]) { n     v = path[pos].second; n     rmv[v]--; n     add[u]++; n   } n   path.pop_back(); n   res[u] = rem1 + rem2; n   add[u] += rem1; n   rmv[u] += rem2; n } n int main() { n   int n, u, v, w; n   cin >> n; n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n - 1; i++) { n     u = i; n     scanf( %d%d , &v, &w); n     v--; n     L[v].push_back(u); n     W[v].push_back(w); n   } n   DFS(0, 0); n   for (int i = 0; i < n; i++) { n     if (i) printf(   ); n     printf( %d , res[i]); n   } n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n long long getint() { n   long long summ = 0, f = 1; n   char ch; n   for (ch = getchar(); !isdigit(ch) && ch !=  - ; ch = getchar()) n     ; n   if (ch ==  - ) { n     f = -1; n     ch = getchar(); n   } n   for (; isdigit(ch); ch = getchar()) n     summ = (summ << 3) + (summ << 1) + ch - 48; n   return summ * f; n } n long long n, m, a[200005], ans, k, s[200004]; n priority_queue<long long> q; n signed main() { n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   for (long long i = n; i; i--) { n     if (a[i] < 0) n       q.push(a[i]); n     else { n       while (!q.empty() && a[i] >= 0) { n         a[i] += q.top(); n         q.pop(); n       } n       if (a[i] < 0) q.push(a[i]); n     } n   } n   long long tot = 0; n   while (!q.empty()) { n     s[++tot] = q.top(); n     q.pop(); n   } n   for (long long i = 1; i <= tot; i++) { n     s[i] = -s[i] + s[i - 1]; n   } n   for (long long i = 1, x; i <= m; i++) { n     x = getint(); n     cout << tot + 1 - (upper_bound(s + 1, s + 1 + tot, x) - s) << endl; n   } n   return 0; n } n