#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:36777216 )   template <class T>   inline void RD(T &);   template <class T>   inline void OT(const T &);   template <class T>   inline T &_RD(T &x) {     RD(x);     return x;   }   inline int RD() {     int x;     return _RD(x);   }   inline void RF(double &x) { scanf( %lf , &x); }   inline double _RF(double &x) {     scanf( %lf , &x);     return x;   }   inline double RF() {     double x;     return _RF(x);   }   inline void RC(char &c) { scanf(  %c , &c); }   inline char _RC(char &c) {     scanf(  %c , &c);     return c;   }   inline char RC() {     char c;     return _RC(c);   }   inline void RS(char *s) { scanf( %s , s); }   template <class T0, class T1>   inline void RD(T0 &x0, T1 &x1) {     RD(x0), RD(x1);   }   template <class T0, class T1, class T2>   inline void RD(T0 &x0, T1 &x1, T2 &x2) {     RD(x0), RD(x1), RD(x2);   }   template <class T0, class T1, class T2, class T3>   inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {     RD(x0), RD(x1), RD(x2), RD(x3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void 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);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void 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);   }   template <class T0, class T1>   inline void OT(T0 &x0, T1 &x1) {     OT(x0), OT(x1);   }   template <class T0, class T1, class T2>   inline void OT(T0 &x0, T1 &x1, T2 &x2) {     OT(x0), OT(x1), OT(x2);   }   template <class T0, class T1, class T2, class T3>   inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {     OT(x0), OT(x1), OT(x2), OT(x3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);   }   template <class T>   inline void RST(T &A) {     memset(A, 0, sizeof(A));   }   template <class T0, class T1>   inline void RST(T0 &A0, T1 &A1) {     RST(A0), RST(A1);   }   template <class T0, class T1, class T2>   inline void RST(T0 &A0, T1 &A1, T2 &A2) {     RST(A0), RST(A1), RST(A2);   }   template <class T0, class T1, class T2, class T3>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {     RST(A0), RST(A1), RST(A2), RST(A3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {     RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {     RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {     RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);   }   template <class T>   inline void CLR(priority_queue<T, vector<T>, less<T> > &Q) {     while (!Q.empty()) Q.pop();   }   template <class T>   inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q) {     while (!Q.empty()) Q.pop();   }   template <class T>   inline void CLR(T &A) {     A.clear();   }   template <class T0, class T1>   inline void CLR(T0 &A0, T1 &A1) {     CLR(A0), CLR(A1);   }   template <class T0, class T1, class T2>   inline void CLR(T0 &A0, T1 &A1, T2 &A2) {     CLR(A0), CLR(A1), CLR(A2);   }   template <class T0, class T1, class T2, class T3>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);   }   template <class T>   inline void CLR(T &A, int n) {     for (int i = 0; i < int(n); ++i) CLR(A[i]);   }   template <class T>   inline void FLC(T &A, int x) {     memset(A, x, sizeof(A));   }   template <class T0, class T1>   inline void FLC(T0 &A0, T1 &A1, int x) {     FLC(A0, x), FLC(A1, x);   }   template <class T0, class T1, class T2>   inline void FLC(T0 &A0, T1 &A1, T2 &A2) {     FLC(A0), FLC(A1), FLC(A2);   }   template <class T0, class T1, class T2, class T3>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {     FLC(A0), FLC(A1), FLC(A2), FLC(A3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {     FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4);   }   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) {     FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5);   }   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) {     FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6);   }   template <class T>   inline void SRT(T &A) {     sort(A.begin(), A.end());   }   template <class T, class C>   inline void SRT(T &A, C B) {     sort(A.begin(), A.end(), B);   }   const int MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const long long INF_64 = 0x3f3f3f3f3f3f3f3fLL;   const double EPS = 1e-8;   const double OO = 1e15;   const double PI = acos(-1.0);   template <class T>   inline void checkMin(T &a, const T b) {     if (b < a) a = b;   }   template <class T>   inline void checkMax(T &a, const T b) {     if (b > a) a = b;   }   template <class T, class C>   inline void checkMin(T &a, const T b, C c) {     if (c(b, a)) a = b;   }   template <class T, class C>   inline void checkMax(T &a, const T b, C c) {     if (c(a, b)) a = b;   }   template <class T>   inline T min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline T min(T a, T b, T c, T d) {     return min(min(a, b), min(c, d));   }   template <class T>   inline T max(T a, T b, T c, T d) {     return max(min(a, b), max(c, d));   }   template <class T, class C>   inline T min_cp(T a, T b, C cp) {     return min(a, b, cp);   }   template <class T, class C>   inline T min_cp(T a, T b, T c, C cp) {     return min_cp(min_cp(a, b, cp), c, cp);   }   template <class T, class C>   inline T min_cp(T a, T b, T c, T d, C cp) {     return min_cp(min_cp(a, b, cp), min_cp(c, d, cp), cp);   }   template <class T, class C>   inline T max_cp(T a, T b, C cp) {     return max(a, b, cp);   }   template <class T, class C>   inline T max_cp(T a, T b, T c, C cp) {     return max_cp(max_cp(a, b, cp), c, cp);   }   template <class T, class C>   inline T max_cp(T a, T b, T c, T d, C cp) {     return max_cp(max_cp(a, b, cp), max_cp(c, d, cp), cp);   }   template <class T>   inline T sqr(T a) {     return a * a;   }   template <class T>   inline T cub(T a) {     return a * a * a;   }   int Ceil(int x, int y) { return (x - 1) / y + 1; }   inline bool _1(int x, int i) { return x & 1 << i; }   inline bool _1(long long x, int i) { return x & 1LL << i; }   inline long long _1(int i) { return 1LL << i; }   inline long long _U(int i) { return _1(i) - 1; };   template <class T>   inline T low_bit(T x) {     return x & -x;   }   template <class T>   inline T high_bit(T x) {     T p = low_bit(x);     while (p != x) x -= p, p = low_bit(x);     return p;   }   template <class T>   inline T cover_bit(T x) {     T p = 1;     while (p < x) p <<= 1;     return p;   }   inline int count_bits(int x) {     x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);     x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);     x = (x & 0x0f0f0f0f) + ((x & 0xf0f0f0f0) >> 4);     x = (x & 0x00ff00ff) + ((x & 0xff00ff00) >> 8);     x = (x & 0x0000ffff) + ((x & 0xffff0000) >> 16);     return x;   }   inline int count_bits(long long x) {     x = (x & 0x5555555555555555LL) + ((x & 0xaaaaaaaaaaaaaaaaLL) >> 1);     x = (x & 0x3333333333333333LL) + ((x & 0xccccccccccccccccLL) >> 2);     x = (x & 0x0f0f0f0f0f0f0f0fLL) + ((x & 0xf0f0f0f0f0f0f0f0LL) >> 4);     x = (x & 0x00ff00ff00ff00ffLL) + ((x & 0xff00ff00ff00ff00LL) >> 8);     x = (x & 0x0000ffff0000ffffLL) + ((x & 0xffff0000ffff0000LL) >> 16);     x = (x & 0x00000000ffffffffLL) + ((x & 0xffffffff00000000LL) >> 32);     return x;   }   int reverse_bits(int x) {     x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);     x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);     x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);     x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);     x = ((x >> 16) & 0x0000ffff) | ((x << 16) & 0xffff0000);     return x;   }   long long reverse_bits(long long x) {     x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);     x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);     x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);     x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);     x = ((x >> 16) & 0x0000ffff0000ffffLL) | ((x << 16) & 0xffff0000ffff0000LL);     x = ((x >> 32) & 0x00000000ffffffffLL) | ((x << 32) & 0xffffffff00000000LL);     return x;   }   using namespace std;   class bignum {     friend istream &operator>>(istream &, bignum &);     friend ostream &operator<<(ostream &, const bignum &);     friend bignum operator+(const bignum &, const bignum &);     friend bignum operator-(const bignum &, const bignum &);     friend bignum operator*(const bignum &, const bignum &);     friend bignum operator/(const bignum &, const bignum &);     friend bignum operator%(const bignum &, const bignum &);     friend bignum operator+(const bignum &, const int &);     friend bignum operator-(const bignum &, const int &);     friend bignum operator*(const bignum &, const int &);     friend bignum operator/(const bignum &, const int &);     friend bignum operator%(const bignum &, const int &);     friend bool operator==(const bignum &, const bignum &);     friend bool operator!=(const bignum &, const bignum &);     friend bool operator<(const bignum &, const bignum &);     friend bool operator>(const bignum &, const bignum &);     friend bool operator<=(const bignum &, const bignum &);     friend bool operator>=(const bignum &, const bignum &);     friend bool operator==(const bignum &, const int &);     friend bool operator!=(const bignum &, const int &);     friend bool operator<(const bignum &, const int &);     friend bool operator>(const bignum &, const int &);     friend bool operator<=(const bignum &, const int &);     friend bool operator>=(const bignum &, const int &);     friend int do_comp(const bignum &, const int &);     friend int do_comp(const bignum &, const bignum &);     friend void divide(const bignum &, const bignum &, bignum &, bignum &);     friend bignum pow(bignum, int);       public:     inline bignum(){};     inline bignum(int s) {       while (s != 0) {         data.push_back(s % 100000000);         s /= 100000000;       }       if (data.empty()) data.push_back(0);     }     inline bignum(long long s) {       while (s != 0) {         data.push_back(int(s % 100000000));         s /= 100000000;       }       if (data.empty()) data.push_back(0);     }     inline bignum(string s) {       int t, i;       data.clear();       for (i = int(s.size()) - 8; i > 0; i -= 8) {         istringstream(s.substr(i, 8)) >> t;         data.push_back(t);       }       istringstream(s.substr(0, i + 8)) >> t;       data.push_back(t);     }     void operator=(const int);     void operator=(const string);     void operator=(const bignum);     bignum &operator+=(const bignum &);     bignum &operator-=(const bignum &);     bignum &operator*=(const bignum &);     bignum &operator/=(const bignum &);     bignum &operator%=(const bignum &);     bignum &operator+=(const int &);     bignum &operator-=(const int &);     bignum &operator*=(const int &);     bignum &operator/=(const int &);     bignum &operator%=(const int &);     bignum &operator%=(const long long &);     bool undefined();     int do_try(const int &);     int do_try(const bignum &);     void do_trim();     list<int> data;     void add(const int a) {       list<int>::iterator it = data.end();       it--;       if ((*it) < 10)         (*it) = a;       else if ((*it) < 100)         (*it) = (*it) % 10 + 10 * a;       else if ((*it) < 1000)         (*it) = (*it) % 100 + 100 * a;       else if ((*it) < 10000)         (*it) = (*it) % 1000 + 1000 * a;       else if ((*it) < 100000)         (*it) = (*it) % 10000 + 10000 * a;       else if ((*it) < 1000000)         (*it) = (*it) % 100000 + 100000 * a;       else if ((*it) < 10000000)         (*it) = (*it) % 1000000 + 1000000 * a;       else if ((*it) < 100000000)         (*it) = (*it) % 10000000 + 10000000 * a;     }     void clear() { data.clear(); }     long long t() {       if (data.size() == 1)         return *data.begin();       else {         list<int>::iterator it = data.begin(), jt = data.begin();         ++it;         return (long long)(*it) * 100000000 + (*jt);       }     }     int size() {       list<int>::iterator it;       int res = 0;       for (it = data.begin(); it != data.end(); it++) res += 8;       it--;       if (*it >= 10000) {         if ((*it) >= 1000000) {           if (*it >= 10000000)             ;           else             res--;         } else {           if ((*it) >= 100000)             res -= 2;           else             res -= 3;         }       } else if ((*it) >= 100) {         if (*it >= 1000)           res -= 4;         else           res -= 5;       } else {         if ((*it) >= 10)           res -= 6;         else           res -= 7;       }       return res;     }     void do_reserve(int a) {       if (a <= 0) return;       list<int>::iterator it;       for (it = data.begin(); it != data.end() && a > 0; it++) a -= 8;       if (it == data.end() && a >= 0) return;       a += 8, it--;       int f = 1;       for (int i = 0; i < a; i++) f *= 10;       (*it) %= f;       data.erase(++it, data.end());       do_trim();     }     void output() {       list<int>::reverse_iterator i = data.rbegin();       printf( %d , *i);       for (i++; i != data.rend(); i++) printf( %08d , *i);     }   };   inline void bignum::operator=(const bignum a) {     data.clear();     for (list<int>::const_iterator i = a.data.begin(); i != a.data.end(); i++) {       data.push_back(*i);     }   }   inline void bignum::operator=(const string a) { (*this) = bignum(a); }   inline void bignum::operator=(const int a) { (*this) = bignum(a); }   inline istream &operator>>(istream &input, bignum &a) {     string s;     int t, i;     input >> s;     a.data.clear();     for (i = int(s.size()) - 8; i > 0; i -= 8) {       istringstream(s.substr(i, 8)) >> t;       a.data.push_back(t);     }     istringstream(s.substr(0, i + 8)) >> t;     a.data.push_back(t);     return input;   }   inline ostream &operator<<(ostream &output, const bignum &a) {     list<int>::const_reverse_iterator i = a.data.rbegin();     output << *i;     for (i++; i != a.data.rend(); i++) {       if (*i >= 10000) {         if (*i >= 1000000) {           if (*i >= 10000000)             cout << *i;           else             cout << 0 << *i;         } else {           if (*i >= 100000)             cout <<  00  << *i;           else             cout <<  000  << *i;         }       } else {         if (*i >= 100) {           if (*i >= 1000)             cout <<  0000  << *i;           else             cout <<  00000  << *i;         } else {           if (*i >= 10)             cout <<  000000  << *i;           else             cout <<  0000000  << *i;         }       }     }     return output;   }   inline bool bignum::undefined() { return data.empty(); }   inline int do_comp(const bignum &a, const bignum &b) {     if (a.data.size() < b.data.size()) return -1;     if (a.data.size() > b.data.size()) return 1;     list<int>::const_reverse_iterator i;     list<int>::const_reverse_iterator j;     for (i = a.data.rbegin(), j = b.data.rbegin(); j != b.data.rend(); i++, j++) {       if (*i < *j) return -1;       if (*i > *j) return 1;     }     return 0;   }   inline int do_comp(const bignum &a, const int &b) {     return do_comp(a, bignum(b));   }   inline bool operator==(const bignum &a, const bignum &b) {     return do_comp(a, b) == 0;   }   inline bool operator!=(const bignum &a, const bignum &b) {     return do_comp(a, b) != 0;   }   inline bool operator<(const bignum &a, const bignum &b) {     return do_comp(a, b) == -1;   }   inline bool operator>(const bignum &a, const bignum &b) {     return do_comp(a, b) == 1;   }   inline bool operator<=(const bignum &a, const bignum &b) {     return do_comp(a, b) != 1;   }   inline bool operator>=(const bignum &a, const bignum &b) {     return do_comp(a, b) != -1;   }   inline bool operator==(const bignum &a, const int &b) {     return do_comp(a, b) == 0;   }   inline bool operator!=(const bignum &a, const int &b) {     return do_comp(a, b) != 0;   }   inline bool operator<(const bignum &a, const int &b) {     return do_comp(a, b) == -1;   }   inline bool operator>(const bignum &a, const int &b) {     return do_comp(a, b) == 1;   }   inline bool operator<=(const bignum &a, const int &b) {     return do_comp(a, b) != 1;   }   inline bool operator>=(const bignum &a, const int &b) {     return do_comp(a, b) != -1;   }   inline void bignum::do_trim() {     while (data.size() > 1 && data.back() == 0) data.pop_back();   }   inline bignum &bignum::operator+=(const bignum &a) {     list<int>::iterator i;     list<int>::const_iterator j;     int t = 0;     for (i = data.begin(), j = a.data.begin();          i != data.end() && j != a.data.end(); i++, j++) {       *i += *j + t;       t = *i / 100000000;       *i %= 100000000;     }     while (i != data.end()) {       *i += t;       t = *i / 100000000;       *i %= 100000000;       i++;     }     while (j != a.data.end()) {       data.push_back(t + *j);       t = data.back() / 100000000;       data.back() %= 100000000;       j++;     }     if (t != 0) data.push_back(t);     return *this;   }   inline bignum &bignum::operator-=(const bignum &a) {     list<int>::iterator i;     list<int>::const_iterator j;     int t = 0;     for (i = data.begin(), j = a.data.begin(); j != a.data.end(); i++, j++) {       *i -= t + *j;       if (*i >= 0)         t = 0;       else         *i += 100000000, t = 1;     }     while (i != data.end()) {       *i -= t;       if (*i >= 0)         t = 0;       else         *i += 100000000, t = 1;       i++;     }     (*this).do_trim();     return *this;   }   inline bignum &bignum::operator+=(const int &a) { return (*this) += bignum(a); }   inline bignum &bignum::operator-=(const int &a) { return (*this) -= bignum(a); }   inline bignum operator+(const bignum &a, const bignum &b) {     list<int>::const_iterator i, j;     bignum c;     int t = 0;     for (i = a.data.begin(), j = b.data.begin();          i != a.data.end() && j != b.data.end(); i++, j++) {       c.data.push_back(t + *i + *j);       t = c.data.back() / 100000000;       c.data.back() %= 100000000;     }     while (i != a.data.end()) {       c.data.push_back(t + *i);       t = c.data.back() / 100000000;       c.data.back() %= 100000000;       i++;     }     while (j != b.data.end()) {       c.data.push_back(t + *j);       t = c.data.back() / 100000000;       c.data.back() %= 100000000;       j++;     }     if (t != 0) c.data.push_back(t);     return c;   }   inline bignum operator-(const bignum &a, const bignum &b) {     list<int>::const_iterator i, j;     bignum c;     int t = 0;     for (i = a.data.begin(), j = b.data.begin(); j != b.data.end(); i++, j++) {       t = *i - t;       if (t >= *j)         c.data.push_back(t - *j), t = 0;       else         c.data.push_back(t + 100000000 - *j), t = 1;     }     while (i != a.data.end()) {       t = *i - t;       if (t >= 0)         c.data.push_back(t), t = 0;       else         c.data.push_back(t + 100000000), t = 1;       i++;     }     c.do_trim();     return c;   }   inline bignum operator*(const bignum &a, const bignum &b) {     list<int>::const_iterator i, j;     list<int>::iterator k, kk;     bignum c;     long long t = 0;     for (int i = 0; i < a.data.size() + b.data.size(); i++) c.data.push_back(0);     for (i = a.data.begin(), k = c.data.begin(); i != a.data.end(); i++, k++) {       for (j = b.data.begin(), kk = k; j != b.data.end(); j++, kk++) {         t += (long long)(*i) * (*j) + (*kk);         *kk = int(t % 100000000);         t /= 100000000;       }       *kk += t;       t = 0;     }     c.do_trim();     return c;   }   inline int bignum::do_try(const bignum &a) {     int l = 1, r = 99999999, m, t;     while (l + 2 < r) {       m = (l + r) / 2;       t = do_comp(*this, a * bignum(m));       if (t == 0) return m;       if (t < 0)         r = m - 1;       else         l = m;     }     while (do_comp(*this, a * bignum(r)) < 0) r--;     return r;   }   inline void divide(const bignum &a, const bignum &b, bignum &d, bignum &r) {     list<int>::const_reverse_iterator i = a.data.rbegin();     int t;     d = bignum(0);     r = bignum(0);     do {       while (r < b && i != a.data.rend()) {         d.data.push_front(0);         r.data.push_front(*i);         r.do_trim();         i++;       }       if (r >= b) {         t = r.do_try(b);         d.data.front() = t;         r -= (b * bignum(t));       }     } while (i != a.data.rend());     d.do_trim();   }   inline bignum operator/(const bignum &a, const bignum &b) {     bignum d, r;     divide(a, b, d, r);     return d;   }   inline bignum operator%(const bignum &a, const bignum &b) {     bignum d, r;     divide(a, b, d, r);     return r;   }   inline bignum operator+(const bignum &a, const int &b) { return a + bignum(b); }   inline bignum operator-(const bignum &a, const int &b) { return a - bignum(b); }   inline bignum operator*(const bignum &a, const int &b) { return a * bignum(b); }   inline bignum operator/(const bignum &a, const int &b) { return a / bignum(b); }   inline bignum &bignum::operator*=(const bignum &a) {     (*this) = (*this) * a;     return *this;   }   inline bignum &bignum::operator/=(const bignum &a) {     (*this) = (*this) / a;     return *this;   }   inline bignum &bignum::operator%=(const bignum &a) {     (*this) = (*this) % a;     return *this;   }   inline bignum &bignum::operator*=(const int &a) { return (*this) *= bignum(a); }   inline bignum &bignum::operator/=(const int &a) { return (*this) /= bignum(a); }   inline bignum &bignum::operator%=(const long long &b) {     return (*this) %= bignum(b);   }   inline bignum pow(bignum a, int b) {     bignum c(1);     while (b != 0) {       if (b & 1) c *= a;       a = a * a;       b >>= 1;     }     return c;   }   inline int rand32() {     return (bool(rand() & 1) << 30) | (rand() << 15) + rand();   }   inline int random32(int l, int r) { return rand32() % (r - l + 1) + l; }   inline int random(int l, int r) { return rand() % (r - l + 1) + l; }   int dice() { return rand() % 6; }   bool coin() { return rand() % 2; }   template <class T>   inline void RD(T &x) {     char c;     for (c = getchar(); c <  0 ; c = getchar())       ;     x = c -  0 ;     for (c = getchar(); c >=  0 ; c = getchar()) x = x * 10 + c -  0 ;   }   template <class T>   inline void OT(const T &x) {     printf( %d n , x);   }   const int maxn = 2;   long long modo;   class Mat {    public:     int Matn, Matm;     long long a[maxn][maxn];     Mat() {       Matn = 0;       Matm = 0;       memset(a, 0, sizeof(a));     }     void output();     void init();     void initI();     Mat mul(const Mat &a);     Mat power(const Mat &a, long long k);   };   void Mat::output() {     for (int i = 0; i < Matn; ++i) {       for (int j = 0; j < Matm; ++j) {         if (j != 0) printf(   );         printf( %d , a[i][j]);       }       printf(  n );     }   }   void Mat::init() {     Matn = 0;     Matm = 0;     memset(a, 0, sizeof(a));   }   Mat Mat::mul(const Mat &A) {     Mat c;     c.Matn = Matn;     c.Matm = A.Matm;     for (int i = 0; i < Matn; ++i)       for (int j = 0; j < A.Matm; ++j) {         for (int k = 0; k < Matm; ++k) {           c.a[i][j] = (c.a[i][j] + (a[i][k] * A.a[k][j]) % modo) % modo;         }       }     return c;   }   void Mat::initI() {     memset(a, 0, sizeof(a));     for (int i = 0; i < Matn; ++i) a[i][i] = 1LL;   }   Mat Mat::power(const Mat &a, long long k) {     Mat c = a, b;     b.init();     b.Matn = a.Matn;     b.Matm = a.Matm;     b.initI();     while (k) {       if (k & 1LL) b = b.mul(c);       c = c.mul(c);       k >>= 1LL;     }     return b;   }   long long gao(long long t) {     if (t <= 1) return 1LL;     Mat a;     a.Matm = a.Matn = 2;     a.a[0][0] = 1LL, a.a[1][0] = 1LL, a.a[0][1] = 1LL;     a = a.power(a, t - 1LL);     return a.a[0][0];   }   long long l, r, k;   void solve() {     long long tmp, ans, tmp1;     if ((r - l) / k <= 2000000) {       for (long long i = (r - l) / (k - 1); i >= (r - l) / k; i--) {         if ((r / i - (l - 1) / i) >= k) {           ans = i;           break;         }       }     } else {       for (long long i = k - 1; i <= 2000000; i++) {         tmp = r / i;         tmp1 = tmp * (i - k + 1);         if (tmp1 >= l) {           ans = tmp;           break;         }       }     }     cout << gao(ans) % modo << endl;   }   int main() {     while (cin >> modo >> l >> r >> k) solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1005];   bool t[1005];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     memset(t, 0, sizeof(t));     int count = 0;     int taken = 0;     bool right = true;     while (1) {       if (right) {         for (int i = 0; i < n; i++) {           if (taken >= a[i] && !t[i]) {             t[i] = true;             taken++;           }         }       } else {         for (int i = n - 1; i >= 0; i--) {           if (taken >= a[i] && !t[i]) {             t[i] = true;             taken++;           }         }       }       if (taken == n) break;       count++;       right = !right;     }     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, speed, limit, t6, ans;   stack<int> st;   int main() {     cin >> N;     for (int t, i = 1; i <= N; i++) {       scanf( %d , &t);       if (t == 6) {         t6++;       } else if (t == 4) {         t6 = 0;       } else if (t == 2) {         ans += t6;         t6 = 0;       } else if (t == 1) {         scanf( %d , &speed);         while (!st.empty() && speed > st.top()) {           ans++;           st.pop();         }       } else if (t == 5) {         while (!st.empty()) st.pop();       } else if (t == 3) {         scanf( %d , &limit);         st.push(limit);         while (!st.empty() && speed > st.top()) {           ans++;           st.pop();         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const int N = 2e5 + 10;   const int M = 1e6 + 10;   const long long mod = 1e9 + 7;   const double PI = acos(-1);   int sq = 3000;   int cntq, cntc;   map<int, int> mp;   int vis[N];   int cnt[N];   int num[N];   int ans[N];   struct query {     int l, r, z, id;   } qq[N];   struct change {     int x, y;   } ch[N];   bool cmp1(query a, query b) {     if (a.l / sq == b.l / sq) {       if (a.r / sq == b.r / sq)         return a.z < b.z;       else         return a.r < b.r;     } else       return a.l < b.l;   }   void update(int x, int y) {     vis[cnt[num[x]]]--;     cnt[num[x]] += y;     vis[cnt[num[x]]]++;   }   void solve() {     int l = 1, r = 1, c = 0, res;     update(1, 1);     for (int i = 1; i <= cntq; ++i) {       while (r < qq[i].r) update(++r, 1);       while (r > qq[i].r) update(r--, -1);       while (l > qq[i].l) update(--l, 1);       while (l < qq[i].l) update(l++, -1);       while (c > qq[i].z) {         if (ch[c].x >= l && ch[c].x <= r) update(ch[c].x, -1);         swap(ch[c].y, num[ch[c].x]);         if (ch[c].x >= l && ch[c].x <= r) update(ch[c].x, 1);         c--;       }       while (c < qq[i].z) {         c++;         if (ch[c].x >= l && ch[c].x <= r) update(ch[c].x, -1);         swap(ch[c].y, num[ch[c].x]);         if (ch[c].x >= l && ch[c].x <= r) update(ch[c].x, 1);       }       res = 1;       while (vis[res]) res++;       ans[qq[i].id] = res;     }   }   int main() {     int n, q, tot = 0, x, op, l, r;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       if (mp[x])         num[i] = mp[x];       else         num[i] = mp[x] = ++tot;     }     for (int i = 1; i <= q; ++i) {       scanf( %d%d%d , &op, &l, &r);       if (op == 1) {         ++cntq;         qq[cntq] = {l, r, cntc, cntq};       } else {         ++cntc;         if (mp[r])           r = mp[r];         else           r = mp[r] = ++tot;         ch[cntc] = {l, r};       }     }     sort(qq + 1, qq + cntq + 1, cmp1);     solve();     for (int i = 1; i <= cntq; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > solve(int N) {     vector<vector<int> > res(2, vector<int>(1, 1));     for (int n = 2, r = 0; n <= N; ++n) {       res[r].push_back(n);       ++r;       if (r >= int((res).size())) {         vector<int> new_row;         for (const vector<int>& r : res) new_row.push_back(r.back());         res.push_back(new_row);         r = 0;       }     }     return res;   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int N;     cin >> N;     vector<vector<int> > res = solve(N);     cout << int((res).size()) <<   n ;     for (const vector<int>& row : res) {       for (int x : row) cout << x <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 505;   int n, m;   int v[MAXN];   int head[MAXN];   double e[MAXN * MAXN];   int a, b, c;   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 1; i <= n; i++) scanf( %d , &v[i]);       for (int i = 1; i <= m; i++) {         scanf( %d%d%d , &a, &b, &c);         e[i] = 1.0 * (v[a] + v[b]) / c;       }       double ans = 0.0;       for (int i = 1; i <= m; i++) ans = max(ans, e[i]);       printf( %.12lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } debug1;   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   inline ostream& operator<<(ostream& os, const vector<T>& v) {     bool first = true;     os <<  [ ;     for (typename vector<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {       if (!first) os <<  ,  ;       os << *ii;       first = false;     }     return os <<  ] ;   }   const long long inf = numeric_limits<long long>::min();   const int NN = 112345;   long long dp[NN][3], cnt[NN];   bool vis[NN][3];   long long f(int x, int last) {     last = ((cnt[x - 1] == 0 and last == 0) ? 2 : last);     if (cnt[x] == 0 and last == 0) return inf;     if (x > 100000) return 0LL;     if (vis[x][last]) return dp[x][last];     vis[x][last] = true;     long long ans = 0;     if (last == 0) {       ans = cnt[x] * (long long)x;       ans += f(x + 1, 1);     } else if (last == 1)       ans = f(x + 1, 2);     else {       ans = max(ans, f(x + 1, 0));       if (cnt[x] > 0) {         long long add = cnt[x] * (long long)x;         ans = max(ans, add + f(x + 1, 1));       }     }     dp[x][last] = ans;     return ans;   }   void solve() {     int n, num;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> num;       cnt[num]++;     }     long long ans = f(1, 2);     cout << ans <<   n ;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m, a, b;     cin >> n >> m >> a >> b;     int ans = 3;     if (a % m == 1 && b % m == 0) {       ans = min(ans, 1);     }     if (a % m == 1 || b % m == 0) {       ans = min(ans, 2);     }     int bf = (a - 1) / m;     int bs = (b - 1) / m;     if (bf == bs) {       ans = min(ans, 1);     }     if (bf + 1 == bs) {       ans = min(ans, 2);     }     if (a % m == 1 && b == n) {       ans = min(ans, 1);     }     if (b == n) {       ans = min(ans, 2);     }     int p1 = (a - 1) % m;     int p2 = (b - 1) % m;     if (p1 == p2 + 1) {       ans = min(ans, 2);     }     if (m == 1) {       ans = min(ans, 1);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   vector<int> g[N];   int deg[N];   int cnt[N];   void dfs(int v, int &l) {     for (int i = 0; i < g[v].size(); i++) {       cnt[g[v][i]] = l + 1;       l++;       dfs(g[v][i], l);       l--;     }   }   int main() {     ios_base::sync_with_stdio(), cout.tie(NULL), cin.tie(NULL);     ;     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> deg[i];       if (deg[i] != -1) {         g[deg[i]].push_back(i);       }     }     int ans = 1;     for (int i = 1; i <= n; i++) {       if (deg[i] == -1) {         int level = 1;         dfs(i, level);       }     }     for (int i = 1; i <= n; i++) {       ans = max(ans, cnt[i]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool getmin(T *a, const T &b) {     if (b < *a) {       *a = b;       return true;     }     return false;   }   template <class T>   inline bool getmax(T *a, const T &b) {     if (b > *a) {       *a = b;       return true;     }     return false;   }   template <class T>   inline void read(T *a) {     char c;     while (isspace(c = getchar())) {     }     bool flag = 0;     if (c ==  - )       flag = 1, *a = 0;     else       *a = c - 48;     while (isdigit(c = getchar())) *a = *a * 10 + c - 48;     if (flag) *a = -*a;   }   const int mo = 1000000007;   template <class T>   T pow(T a, T b, int c = mo) {     T res = 1;     for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c)       if (b & i) res = 1LL * res * a % c;     return res;   }   const int N = 100100;   int n;   int a[N];   int s1[N], s2[N];   pair<int, int> ans[N];   int check(int x) {     int j = 0, i = 1, num1 = 0, num2 = 0, last = 0;     while (i <= n) {       int l = i, r = n, res = 0;       while (l <= r) {         int mid = (l + r) >> 1;         if (max(s1[mid] - s1[j], s2[mid] - s2[j]) >= x)           res = mid, r = mid - 1;         else           l = mid + 1;       }       if (!res) return 0;       if (s1[res] - s1[j] == x)         ++num1, last = 1;       else         ++num2, last = 2;       j = res, i = res + 1;     }     if (num1 > num2 && last == 1)       return num1;     else if (num2 > num1 && last == 2)       return num2;     return 0;   }   int main() {     cin >> n;     for (int i = (1); i <= (n); ++i) {       read(a + i);       s1[i] = s1[i - 1] + (a[i] == 1);       s2[i] = s2[i - 1] + (a[i] == 2);     }     int m = 0;     for (int i = (1); i <= (n); ++i) {       int z = check(i);       if (z) ans[++m] = std::make_pair(z, i);     }     sort(ans + 1, ans + m + 1);     cout << m << endl;     for (int i = (1); i <= (m); ++i)       printf( %d %d n , ans[i].first, ans[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   int n, m, dis[55][55], fast[55], slow[55], g1, g2, s1, s2;   long long f[55][55][55];   bool cang[55], cans[55], canb[55];   long long work(int g, int b, int su, int sd) {     memset(f, 0, sizeof(f));     memset(cang, false, sizeof(cang));     memset(cans, false, sizeof(cans));     memset(canb, false, sizeof(canb));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) {           continue;         }         if (dis[i][j] <= g) {           cang[i] = true;         }         if (dis[i][j] > su && dis[i][j] < sd) {           cans[i] = true;         }         if (dis[i][j] >= b) {           canb[i] = true;         }       }     }     f[0][0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= i; j++) {         for (int k = 0; j + k <= i; k++) {           if (cang[i]) {             f[i][j + 1][k] += f[i - 1][j][k];           }           if (cans[i]) {             f[i][j][k + 1] += f[i - 1][j][k];           }           if (canb[i]) {             f[i][j][k] += f[i - 1][j][k];           }         }       }     }     long long res = 0;     for (int i = g1; i <= g2; i++) {       for (int j = s1; j <= s2; j++) {         res += f[n][i][j];       }     }     return res;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i < n; i++) {       for (int j = i + 1; j <= n; j++) {         dis[i][j] = dis[j][i] = inf;       }     }     for (int i = 0; i < m; i++) {       int x, y, w;       scanf( %d%d%d , &x, &y, &w);       dis[x][y] = dis[y][x] = w;     }     scanf( %d%d%d%d , &g1, &g2, &s1, &s2);     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (dis[i][j] < inf) {           dis[i][j] = dis[i][j] * n + i;         }       }     }     for (int i = 1; i <= n; i++) {       fast[i] = inf;       slow[i] = -inf;       for (int j = 1; j <= n; j++) {         if (i == j) {           continue;         }         fast[i] = min(fast[i], dis[i][j]);         slow[i] = max(slow[i], dis[i][j]);       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         ans += work(fast[i], slow[j], fast[i], slow[j]) -                work(fast[i] - 1, slow[j], fast[i], slow[j]) -                work(fast[i], slow[j] + 1, fast[i], slow[j]) +                work(fast[i] - 1, slow[j] + 1, fast[i], slow[j]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   stack<int> S;   int n, m, q, x, y;   struct rs_tree {     int hed[200005], ver[600005], nxt[600005], tot, cnt;     int dep[200005], fa[200005], top[200005], siz[200005], son[200005];     void push(int x, int y) {       ver[++tot] = y;       nxt[tot] = hed[x];       hed[x] = tot;     }     void dfs1(int now, int en) {       dep[now] = dep[en] + 1;       fa[now] = en;       for (int i = hed[now]; i; i = nxt[i]) {         if (ver[i] == en) continue;         dfs1(ver[i], now);         if (son[now] == 0 || siz[son[now]] < siz[ver[i]]) son[now] = ver[i];         siz[now] += siz[ver[i]];       }       return;     }     void dfs2(int now, int TOP) {       top[now] = TOP;       if (son[now]) dfs2(son[now], TOP);       for (int i = hed[now]; i; i = nxt[i]) {         if (ver[i] == fa[now] || ver[i] == son[now]) continue;         dfs2(ver[i], ver[i]);       }       return;     }     int find_lca(int x, int y) {       int sum = dep[x] + dep[y];       while (top[x] != top[y]) {         if (dep[top[x]] < dep[top[y]]) swap(x, y);         x = fa[top[x]];       }       if (dep[x] > dep[y]) swap(x, y);       sum -= (2 * dep[x] - 1);       return sum >> 1;     }   } RST;   struct graph {     int hed[100005], ver[1000005], nxt[1000005], tot;     int dfn[100005], low[100005], num, cnt, vis[100005];     void push(int x, int y) {       ver[++tot] = y;       nxt[tot] = hed[x];       hed[x] = tot;     }     void dfs(int now, int en) {       S.push(now);       dfn[now] = low[now] = ++cnt;       vis[now] = 1;       for (int i = hed[now]; i; i = nxt[i]) {         if (!dfn[ver[i]]) {           dfs(ver[i], now);           low[now] = min(low[now], low[ver[i]]);           if (low[ver[i]] >= dfn[now]) {             num++;             int z;             do {               z = S.top();               S.pop();               RST.push(z, num);               RST.push(num, z);               vis[z] = 0;             } while (z != ver[i]);             RST.push(now, num);             RST.push(num, now);           }         } else if (vis[ver[i]])           low[now] = min(low[now], dfn[ver[i]]);       }     }     void tarjan() {       num = n;       cnt = 0;       dfs(1, 0);     }   } G;   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       G.push(x, y);       G.push(y, x);     }     G.tarjan();     RST.dfs1(1, 0);     RST.dfs2(1, 1);     for (int i = 1; i <= q; i++) {       scanf( %d%d , &x, &y);       printf( %d n , RST.find_lca(x, y));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, m, n, p, q, r, ans, l, ch = 1;   string s;   int f;   vector<long long> v;   int main() {     cin >> s;     l = s.size();     f = s.find( bear , 0);     while (f >= 0) {       p = f + 1;       ch = abs(p - ch) + 1;       q = p + 3;       r = (l - q) + 1;       ans += (r * ch);       ch = p + 1;       f = s.find( bear , ch);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long num = 0, neg = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (isdigit(c)) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num * neg;   }   const long long mod = 998244353;   long long n, a[100010], m, g[300010], f[300010], ans;   inline long long qpow(long long x, long long k) {     long long res = 1;     while (k) {       if (k & 1) res = res * x % mod;       x = x * x % mod;       k >>= 1;     }     return res;   }   int main() {     n = read();     g[0] = n - 1;     for (int i = 1; i <= n; i++) a[i] = read(), m += a[i];     for (int i = 1; i <= m; i++)       g[i] = (m * (n - 1) % mod + (n - 1) * i % mod * g[i - 1] % mod) % mod *              qpow(m - i, mod - 2) % mod;     f[m] = g[m];     for (int i = m - 1; i >= 0; i--) f[i] = (f[i + 1] + g[i]) % mod;     for (int i = 1; i <= n; i++) ans = (ans + f[a[i]]) % mod;     ans = (ans - ((n - 1) * f[0] % mod) + mod) % mod;     printf( %lld n , ans * qpow(n, mod - 2) % mod);     return 0;   }


#include <bits/stdc++.h>   const int pi = acos(-1);   const long long MOD = 1000000007;   const int M = 100005;   const int N = 1000006;   using namespace std;   int n, m, x, y, ans;   string s;   char a[55][55];   bool vis[55][55];   vector<string> v;   void calc(int i, string s) {     if (i == 4) {       v.push_back(s);       return;     }     bool u = 0, d = 0, l = 0, r = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  u ) u = 1;       if (s[i] ==  d ) d = 1;       if (s[i] ==  l ) l = 1;       if (s[i] ==  r ) r = 1;     }     if (!u) calc(i + 1, s +  u );     if (!d) calc(i + 1, s +  d );     if (!l) calc(i + 1, s +  l );     if (!r) calc(i + 1, s +  r );   }   int bfs(string k) {     map<char, char> lol;     lol[ 0 ] = k[0];     lol[ 1 ] = k[1];     lol[ 2 ] = k[2];     lol[ 3 ] = k[3];     queue<pair<int, pair<int, int> > > q;     q.push(make_pair(0, make_pair(x, y)));     while (!q.empty()) {       int x = q.front().second.first;       int y = q.front().second.second;       int i = q.front().first;       q.pop();       if (x < 0 || x >= n || y < 0 || y >= m) return 0;       if (a[x][y] ==  # ) return 0;       if (a[x][y] ==  E ) return 1;       if (i >= s.size()) return 0;       char lel = lol[s[i]];       if (lel ==  d ) q.push(make_pair(i + 1, make_pair(x + 1, y)));       if (lel ==  u ) q.push(make_pair(i + 1, make_pair(x - 1, y)));       if (lel ==  r ) q.push(make_pair(i + 1, make_pair(x, y + 1)));       if (lel ==  l ) q.push(make_pair(i + 1, make_pair(x, y - 1)));     }     return 0;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) scanf( %s , a[i]);     cin >> s;     calc(0,   );     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (a[i][j] ==  S ) {           x = i;           y = j;         }     for (int i = 0; i < v.size(); i++) ans += bfs(v[i]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   bool solve(int);   int main() {     int test = 0;     while (solve(test++))       ;     return 0;   }   const int N = 100 * 1000 + 5;   const int INF = int(1e9);   int n, b, m;   pair<int, int> a[N];   struct edge {     int to, f, c, rev;   };   const int V = 1000 * 1000 + 3;   vector<edge> g[V];   int lev[V];   int head, tail, q[V];   inline bool bfs(int s, int t) {     memset(lev, 63, sizeof(lev));     head = tail = 0;     lev[s] = 0;     q[head++] = s;     while (head != tail) {       int v = q[tail++];       for (int i = 0; i < int(int(g[v].size())); ++i)         if (g[v][i].f < g[v][i].c && lev[g[v][i].to] > lev[v] + 1) {           lev[g[v][i].to] = lev[v] + 1;           q[head++] = g[v][i].to;         }     }     return lev[t] < INF / 2;   }   inline void add(int from, int to, int c) {     edge f = {to, 0, c, int(g[to].size())};     edge b = {from, 0, 0, int(g[from].size())};     g[from].push_back(f);     g[to].push_back(b);   }   int ptr[V];   int dfs(int v, int t, int f) {     if (v == t) return f;     for (; ptr[v] < int(g[v].size()); ptr[v]++) {       edge& e = g[v][ptr[v]];       if (e.f == e.c || lev[e.to] != lev[v] + 1) continue;       int df = dfs(e.to, t, min(f, e.c - e.f));       if (df > 0) {         e.f += df;         g[e.to][e.rev].f -= df;         return df;       }     }     return 0;   }   inline int dinic(int s, int t) {     int ans = 0;     while (bfs(s, t)) {       memset(ptr, 0, sizeof(ptr));       for (int f; (f = dfs(s, t, INF)) != 0; ans += f)         ;     }     return ans;   }   int cnt5[N][5];   int calc(int r, int rem) { return cnt5[r][rem]; }   bool solve(int) {     if (!(cin >> m >> b >> n)) return false;     for (int i = 0; i < int(n); ++i) {       scanf( %d %d , &a[i].first, &a[i].second);       a[i].first++;     }     a[n++] = pair<int, int>(b + 1, m);     a[n++] = pair<int, int>(1, 0);     int cv = 5;     int S = cv++;     int T = cv++;     for (int i = 0; i < int(5); ++i) add(i, T, m / 5);     for (int i = 0; i < int(N - 1); ++i) {       for (int j = 0; j < int(5); ++j) cnt5[i + 1][j] = cnt5[i][j];       cnt5[i + 1][(i + 1) % 5]++;     }     sort(a, a + n);     for (int i = 0; i < int(n - 1); ++i) {       int lf = a[i].first;       int rg = a[i + 1].first;       int cnt = a[i + 1].second - a[i].second;       if (rg - lf < cnt || cnt < 0) {         puts( unfair );         return true;       }       if (cnt == 0) continue;       int v[5];       for (int i = 0; i < int(5); ++i) {         v[i] = calc(rg - 1, i) - calc(lf - 1, i);         add(cv, i, v[i]);       }       add(S, cv, cnt);       cv++;     }     puts(dinic(S, T) == m ?  fair  :  unfair );     return true;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[100];   long long ans;   long long getval() {     long long val = 0;     for (int i = 0; i < n; ++i) {       int mn = 100500;       for (int j = i; j < n; ++j) {         mn = min(mn, a[j]);         val += mn;       }     }     return val;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) {       a[i] = i + 1;     }     do {       long long val = getval();       ans = max(ans, val);     } while (next_permutation(a, a + n));     cerr <<  ans =   << ans <<   n ;     do {       long long val = getval();       if (val == ans) {         if (m == 1) {           for (int i = 0; i < n; ++i) {             cout << a[i] <<    ;           }           cout <<   n ;           return 0;         }         --m;       }     } while (next_permutation(a, a + n));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, t, x, y;     long long pos_ji, pos_ou;     while (~scanf( %lld%lld , &n, &t)) {       while (t--) {         scanf( %lld%lld , &x, &y);         long long ji = n / 2 * n + (n + 1) / 2 + 1;         long long ou = n / 2 * n + 1;         pos_ji = (x - 1) * n + y;         if (n % 2 != 0) {           if (pos_ji % 2 == 0)             printf( %lld n , ji + (pos_ji - 1) / 2);           else             printf( %lld n , (pos_ji + 1) / 2);         } else {           if (x % 2 != 0 && y % 2 != 0) {             printf( %lld n , (x / 2) * n + (y + 1) / 2);           } else if (x % 2 != 0 && y % 2 == 0) {             printf( %lld n , ou + (x / 2) * n + (y - 1) / 2);           } else if (x % 2 == 0 && y % 2 != 0) {             printf( %lld n , ou + n / 2 + (x - 2) / 2 * n + y / 2);           } else             printf( %lld n , n / 2 + (x - 2) / 2 * n + y / 2);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     ;     int precision = numeric_limits<double>::digits10;     ;     int n, a, b;     cin >> n >> a >> b;     cout << (a + b - 1 + 100 * n) % n + 1;   }


#include <bits/stdc++.h>   using namespace std;   int q, tipe, temp, x, k, s;   vector<int> v;   set<int> cek;   int val[100000 + 5];   map<pair<int, pair<int, int> >, int> temp2;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &tipe);       if (tipe == 1) {         scanf( %d , &temp);         if (!val[temp]) {           val[temp] = true;           cek.insert(temp);           temp2.clear();         }       } else {         scanf( %d %d %d , &x, &k, &s);         if (x % k != 0 or x >= s)           printf( -1 n );         else {           if (temp2[make_pair(x, make_pair(k, s))]) {             printf( %d n , temp2[make_pair(x, make_pair(k, s))]);             continue;           }           int xam = -1;           int res = -1;           auto its = cek.upper_bound(s - x);           int it = *its;           if (it <= 0 or it < (s - x) / k) {             for (auto b = cek.begin(); b != its and (*b) + x <= s; ++b) {               if (xam < ((*b) ^ x) and gcd(*b, x) % k == 0) {                 xam = ((*b) ^ x);                 res = *b;               }             }           } else {             for (int i = k; i <= 100000 and i + x <= s; i += k) {               if (val[i] and xam < (i ^ x)) {                 xam = (i ^ x);                 res = i;               }             }           }           temp2[make_pair(x, make_pair(k, s))] = res;           printf( %d n , res);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   pair<double, double> A[MAXN];   int n, r, ord[MAXN], st[MAXN];   bool comp(int a, int b) {     if (A[a].first != A[b].first) return A[a].first < A[b].first;     return A[a].second < A[b].second;   }   int ccw(pair<double, double> a, pair<double, double> b,           pair<double, double> c) {     double tmp = a.first * b.second + b.first * c.second + c.first * a.second -                  a.second * b.first - b.second * c.first - c.second * a.first;     if (tmp > 0) return 1;     if (tmp < 0) return -1;     return 0;   }   int main() {     scanf( %d , &n);     int i, m, ni;     for (i = 1; i <= n; i++) scanf( %lf%lf , &A[i].first, &A[i].second);     ni = n;     scanf( %d , &m);     for (i = 1; i <= m; i++) scanf( %lf%lf , &A[n + i].first, &A[n + i].second);     n += m;     for (i = 1; i <= n; i++) ord[i] = i;     sort(ord + 1, ord + n + 1, comp);     st[++r] = ord[1];     st[++r] = ord[2];     for (i = 3; i <= n; i++) {       while (r >= 2 && ccw(A[st[r - 1]], A[st[r]], A[ord[i]]) > 0) r--;       st[++r] = ord[i];     }     for (i = n - 1; i >= 1; i--) {       while (r >= 2 && ccw(A[st[r - 1]], A[st[r]], A[ord[i]]) > 0) r--;       st[++r] = ord[i];     }     r--;     for (i = 1; i <= r; i++)       if (st[i] > ni) {         printf( NO n );         return 0;       }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200001], s1[200001];   int n, m, sum, gang, ans[200001], cnt;   int main() {     scanf( %s , s1 + 1);     m = strlen(s1 + 1);     for (int i = 1; i <= m; i++) {       if (s1[i] ==  (  || s1[i] ==  ) ) s[++n] = s1[i];       if (s1[i] ==  # ) {         s[++n] =  ) ;         s[++n] =  # ;         cnt++;       }     }     sum = 0;     int now = cnt + 1;     for (int i = n; i; i--) {       if (s[i] ==  ) ) {         gang++;       }       if (s[i] ==  ( ) {         if (gang)           gang--;         else           sum++;       }       if (s[i] ==  # ) {         if (sum > 0) ans[now] = sum;         sum = 0;         now--;       }       if ((now > cnt) && (sum > 0)) exit(puts( -1 ));     }     if (gang) exit(puts( -1 ));     ans[now] = sum;     sum = 0;     for (int i = 1; i <= cnt; i++) printf( %d n , ans[i] + 1);   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long Tree[1000001];   long long arr[200001];   void add(long long x, long long val) {     for (; x <= n; x += x & (-x)) Tree[x] += val;     return;   }   long long get(long long x) {     long long sum = 0;     for (; x > 0; x -= x & (-x)) sum += Tree[x];     return sum;   }   void solve() {     long long x = 1;     if (get(1) == 0) {       cout << 1 <<   n ;       return;     }     while (x < n) {       long long curr_val = get(x) * 2;       if (get(x + 1) == curr_val) {         cout << x + 1 <<   n ;         return;       }       long long lo = x + 1;       long long hi = n;       long long lo_bound;       while (lo <= hi) {         if (lo == hi) {           lo_bound = lo;           break;         }         long long mi = (lo + hi) / 2;         if (get(mi) < curr_val)           lo = mi + 1;         else           hi = mi;       }       long long k = lo_bound - 1;       x = (x == k) ? (k + 1) : k;     }     cout << -1 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long q;     memset(Tree, 0, sizeof Tree);     cin >> n >> q;     for (long long i = 1; i <= n; i++) {       cin >> arr[i];       add(i, arr[i]);     }     long long x, y;     while (q--) {       cin >> x >> y;       add(x, y - arr[x]);       arr[x] = y;       solve();     }     return 0;   }


#include<bits/stdc++.h>   #include<unordered_map>   using namespace std;   typedef long long ll;   typedef vector<ll> vll;   const ll M = 1000000007;      bool compare(vll x, vll y) {       if (x[0] < y[0]) {           return true;       }       return false;   }   void solve() {       vector<vll> v(3);       ll n1, n2, n3;       cin >> n1 >> n2 >> n3;       vll v1(n1), v2(n2), v3(n3);       ll f1 = 0, f2 = 0;       ll tsum = 0;       for (ll i = 0; i < n1; i++) {           cin >> v1[i];           tsum += v1[i];       }       for (ll i = 0; i < n2; i++) {           cin >> v2[i];           tsum += v2[i];       }       for (ll i = 0; i < n3; i++) {           cin >> v3[i];           tsum += v3[i];       }       sort(v1.begin(), v1.end());       sort(v2.begin(), v2.end());       sort(v3.begin(), v3.end());       v[0] = v1;       v[1] = v2;       v[2] = v3;       sort(v.begin(), v.end(), compare);       // for (int i = 0; i < 3; i++) {           for (int j = 1; j < v[0].size(); j++) {               f1 += v[0][j];           }           for (int j = 1; j < v[1].size(); j++) {               f2 += v[1][j];           }       // }       ll sub = 0;       if (f1 == 0) {           sub = 2 * v[0][0];       } else if (f1 > 0 && f2 == 0) {           if (v[1][0] > f1) {               sub = 2 * v[0][0] + 2 * f1;           } else {               sub = 2 * v[1][0];           }       } else {           sub = 2 * min(f2, v[0][0]) + 2 * min(f1, v[1][0]);       }              if (v[2].size() == 1) {           sub = min(sub , 2 * v[2][0]);       }       cout << tsum - sub << endl;   }      int main() {       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);       // This macro supported by cc, cf, cses       #ifndef ONLINE_JUDGE           freopen( in.txt ,  r , stdin);           freopen( out.txt ,  w , stdout);       #endif       // int tt;       // cin >> tt;       // for(int i = 1; i <= tt; i++) {           solve();       // }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, s2;     cin >> s;     cin >> s2;     vector<char> v, t;     for (int i = 0; i < s.length(); i++) {       v.push_back(s[i]);     }     vector<char>::iterator it;     int i = 0;     for (it = v.end() - 1; it >= v.begin(); it--) {       t.push_back(*it);     }     int cnt = 0, n = s.length();     for (int i = 0; i < n; i++) {       if (t[i] == s2[i]) cnt++;     }     if (cnt == n)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, sum;     cin >> n >> sum;     long long temp = 0;     long long cnt = 0;     while (temp < sum) {       if (temp + n <= sum) {         temp += n;         cnt++;       } else {         n--;       }     }     cout << cnt <<   n ;     ;     return 0;   }


#include <bits/stdc++.h>   namespace competitive_programming {   inline namespace utility {}   namespace debugging {}   namespace io {}   }  // namespace competitive_programming   namespace competitive_programming::utility {   class timer {    private:     std::chrono::time_point<std::chrono::steady_clock> begin, end;       public:     timer() : begin(), end() {}     ~timer() {}   };   }  // namespace competitive_programming::utility   constexpr bool test_cases = true;   void yes() { std::cout <<  YES n ; }   void no() { std::cout <<  NO n ; }   auto solve() -> void {     int64_t x, y;     std::cin >> x >> y;     if (x - y < 2)       no();     else       yes();   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.precision(10);     std::cerr.precision(10);     std::cout << std::fixed << std::boolalpha;     std::cerr << std::fixed << std::boolalpha;     competitive_programming::timer t;     int32_t cases = 1;     if (test_cases) std::cin >> cases;     while (cases--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string s[2000];   string t[2000];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int j = 0; j < m; j++) {       bool flag = true;       for (int i = 0; i < n - 1; i++) {         if (s[i][j] > s[i + 1][j]) {           flag = false;           break;         }       }       if (flag) {         for (int i = 0; i < n; i++) t[i] += s[i][j];         for (int k = j + 1; k < m; k++) {           flag = true;           for (int f = 0; f < n - 1; f++)             if (t[f] + s[f][k] > t[f + 1] + s[f + 1][k]) {               flag = false;               break;             }           if (flag) {             for (int f = 0; f < n; f++) t[f] += s[f][k];           }         }         break;       }     }     cout << m - t[0].length();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       long long a[n][m], f1 = 0;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           cin >> a[i][j];           if (a[i][j] > 4) f1 = 1;         }       }       if (f1) {         cout <<  NO  << endl;         continue;       }       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           long long c = a[i][j];           if ((i == 0 && j == 0) || (i == 0 && j == m - 1) ||               (i == n - 1 && j == m - 1) || (i == n - 1 && j == 0)) {             if (c > 2)               f1 = 1;             else               a[i][j] = 2;           } else if ((i == n - 1 || i == 0 || j == 0 || j == m - 1)) {             if (a[i][j] > 3)               f1 = 1;             else               a[i][j] = 3;           } else             a[i][j] = 4;         }       }       if (f1) {         cout <<  NO  << endl;         continue;       } else {         cout <<  YES  << endl;         for (long long i = 0; i < n; i++) {           for (long long j = 0; j < m; j++) {             cout << a[i][j] <<    ;           }           cout << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, k, i;     cin >> n >> k;     vector<long long int> num(k + 1);     long long int maxi = 1e18;     long long int ind = -1;     for (i = 1; i <= k; i++) {       cin >> num[i];       if (n % num[i] < maxi) {         maxi = n % num[i];         ind = i;       }     }     cout << ind <<     << n / num[ind] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int sz = 2e5 + 10;   int pr[sz], si[sz], ar[sz][3];   bool us[sz];   bool comp(int a, int b) { return ar[a][2] > ar[b][2]; }   int find_se(int v) {     if (pr[v] == v)       return v;     else {       pr[v] = find_se(pr[v]);       return pr[v];     }   }   void unite(int v, int v2) {     if (v != v2) {       if (si[v] < si[v2]) swap(v, v2);       pr[v2] = v, si[v] += si[v2];     }   }   int main() {     int n, m, an = 0;     cin >> n >> m;     int p[m];     for (int a = 0; a < n; a++) {       pr[a] = a, si[a] = 1, us[a] = 0;     }     for (int a = 0; a < m; a++) {       p[a] = a;       for (int b = 0; b < 3; b++) scanf( %d , &ar[a][b]);       ar[a][0]--, ar[a][1]--;     }     sort(p, p + m, comp);     for (int a = 0; a < m; a++) {       int i = p[a];       int l = find_se(ar[i][0]), r = find_se(ar[i][1]), va = ar[i][2];       if (l == r) {         if (us[l] == 0) {           us[l] = 1, an += va;         }       } else if (us[l] == 1 and us[r] == 0) {         us[r] = 1, an += va;       } else if (us[l] == 0 and us[r] == 1) {         us[l] = 1, an += va;       } else if (us[l] == 0 and us[r] == 0) {         unite(l, r), an += va;       }     }     cout << an;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y;   int a[1000];   bool inrange(int v) { return (v >= x && v <= y); }   int main() {     ios ::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] = a[i - 1] + a[i];     }     cin >> x >> y;     for (int i = 1; i <= n; i++)       if (inrange(a[i - 1]) && inrange(a[n] - a[i - 1])) {         cout << i;         return 0;       }     cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, kangaroo[500000];   int main() {     cin >> n;     for (int _n = n, i = 0; i < _n; ++i) cin >> kangaroo[i];     sort(kangaroo, kangaroo + n);     int middle = (n / 2) - !(n % 2);     int i = middle, j = n - 1;     while (i >= 0 && j > middle) {       if (kangaroo[i] * 2 <= kangaroo[j]) j--;       i--;     }     cout << j + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const long double PI = 3.141592653589793;   int main() {     ios_base::sync_with_stdio(false);     long long int t;     cin >> t;     long long int l = 0, r = 0;     set<long long int> le, ri;     vector<long long int> v(2e5 + 10);     while (t--) {       char a;       long long int b;       cin >> a >> b;       if (l == 0 && r == 0) {         v[b] = 1;         l++;         r++;         continue;       }       if (a ==  L ) {         l++;         le.insert(b);         v[b] = l;       } else if (a ==  R ) {         r++;         ri.insert(b);         v[b] = r;       } else {         auto k = le.find(b);         if (k != le.end())           cout << min(l - (v[b] - 1), r + (v[b] - 1)) - 1;         else           cout << min(r - (v[b] - 1), l + (v[b] - 1)) - 1;         cout <<   n ;       }     }     cerr <<  Time Lapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int c[104][104];   long long int dp[104][104 * 104];   long long int mul[104][104];   long long int pw(long long int x, long long int y) {     long long int ans(1);     while (y) {       if (y & 1) ans = (ans * x) % 1000000007;       x = (x * x) % 1000000007;       y >>= 1;     }     return ans;   }   int main() {     long long int n, m, k;     cin >> n >> m >> k;     c[1][0] = c[1][1] = 1;     for (long long int i(2); i <= 100; ++i) {       c[i][i] = c[i][0] = 1;       c[i][1] = i;       for (long long int j(2); j < i; ++j) {         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007;       }     }     for (long long int i(0); i < n; ++i) {       for (long long int j(0); j <= n; ++j) {         mul[i][j] = pw(c[n][j], (m - i - 1) / n + 1);       }     }     dp[0][0] = 1;     for (long long int i(0); i < n; ++i) {       for (long long int j(0); j <= k; ++j) {         if (dp[i][j] == 0) continue;         for (long long int kk(0); kk <= n && j + kk <= k; ++kk) {           dp[i + 1][j + kk] =               (dp[i + 1][j + kk] + dp[i][j] * mul[i][kk]) % 1000000007;         }       }     }     cout << dp[n][k] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, len1, len2, ans;   string s;   int main() {     cin >> n;     getline(cin, s), getline(cin, s);     while (len1 < s.size()) {       len2 = len1 + n - 1;       while (len2 > len1)         if (s[len2] ==  .  || s[len2] ==  ?  || s[len2] ==  ! ) {           len1 = len2 + 2;           break;         } else           len2--;       if (len2 == len1) return puts( Impossible ), 0;       ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   int n, ip[MAXN], p[MAXN], q[MAXN];   int tree[4 * MAXN], flag[4 * MAXN];   void push(int i, int L, int R) {     if (L < R) {       flag[2 * i] += flag[i];       flag[2 * i + 1] += flag[i];     }     tree[i] += flag[i];     flag[i] = 0;   }   void update(int i, int L, int R, int u, int v, int val) {     push(i, L, R);     if (R < u || v < L) return;     if (u <= L && R <= v) {       flag[i] += val;       push(i, L, R);       return;     }     int mid = (L + R) / 2;     update(2 * i, L, mid, u, v, val);     update(2 * i + 1, mid + 1, R, u, v, val);     tree[i] = max(tree[2 * i], tree[2 * i + 1]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       p[i]--;       ip[p[i]] = i;     }     int j = n - 1;     update(1, 0, n - 1, 0, ip[j], 1);     for (int i = 0; i < n; i++) {       scanf( %d , &q[i]);       q[i]--;       if (i > 0) printf(   );       printf( %d , j + 1);       if (i != n - 1) {         update(1, 0, n - 1, 0, q[i], -1);         while (true) {           if (tree[1] > 0) {             break;           } else {             j--;             update(1, 0, n - 1, 0, ip[j], 1);           }         }       }     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   struct Node {     int p;     vector<int> v;     Node() { p = 0, v = {1}; }     inline int size() { return v.size(); }   };   vector<int> G[maxn];   int ans[maxn];   void merge(Node& a, Node b) {     b.v.push_back(0);     if (a.size() < b.size()) swap(a, b);     int shift = a.size() - b.size();     for (int i = 0; i < b.size(); i++) {       a.v[i + shift] += b.v[i];       if (a.v[i + shift] >= a.v[a.p]) a.p = i + shift;     }   }   Node dfs(int u, int fa) {     Node cur;     for (auto& v : G[u]) {       if (v != fa) {         merge(cur, dfs(v, u));       }     }     ans[u] = cur.size() - cur.p - 1;     return cur;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v), G[v].push_back(u);     }     dfs(1, 0);     for (int i = 1; i <= n; i++) {       cout << ans[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int sad = 0;   int* visited;   vector<int>* adj;   void dfs(int curr, int prev) {     visited[curr] = 1;     for (auto& e : adj[curr]) {       if (e == prev) continue;       if (visited[e])         sad++;       else         dfs(e, curr);     }   }   int main() {     int n, k;     cin >> n >> k;     visited = new int[n];     memset(visited, 0, n * sizeof(int));     adj = new vector<int>[n];     unordered_set<string> chk;     int dups = 0;     for (int i = 0; i < k; i++) {       int a, b;       scanf( %d%d , &a, &b);       int tmp = min(a, b);       int tmp2 = max(a, b);       string key = to_string(tmp) + to_string(tmp2);       if (chk.count(key)) {         dups++;         continue;       }       chk.insert(key);       adj[a - 1].push_back(b - 1);       adj[b - 1].push_back(a - 1);     }     for (int i = 0; i < n; i++) {       if (visited[i]) continue;       dfs(i, -1337);     }     cout << sad / 2 + dups;   }


#include <bits/stdc++.h>   using namespace std;   int vis[10100];   int dist[10100];   int pre[10100], cntt[30];   char str[10100];   struct Edge {     int u, v, c, cost, next;   } edge[1000100];   int anss, head[10100], cnt;   void init() {     cnt = 0;     memset(head, -1, sizeof(head));   }   void addedge(int u, int v, int c, int cost) {     edge[cnt].u = u;     edge[cnt].v = v;     edge[cnt].cost = cost;     edge[cnt].c = c;     edge[cnt].next = head[u];     head[u] = cnt++;     edge[cnt].u = v;     edge[cnt].v = u;     edge[cnt].cost = -cost;     edge[cnt].c = 0;     edge[cnt].next = head[v];     head[v] = cnt++;   }   bool spfa(int begin, int end) {     int u, v;     queue<int> q;     for (int i = 0; i <= end + 2; i++) {       pre[i] = -1;       vis[i] = 0;       dist[i] = 99999999;     }     vis[begin] = 1;     dist[begin] = 0;     q.push(begin);     while (!q.empty()) {       u = q.front();       q.pop();       vis[u] = 0;       for (int i = head[u]; i != -1; i = edge[i].next) {         if (edge[i].c > 0) {           v = edge[i].v;           if (dist[v] > dist[u] + edge[i].cost) {             dist[v] = dist[u] + edge[i].cost;             pre[v] = i;             if (!vis[v]) {               vis[v] = true;               q.push(v);             }           }         }       }     }     return dist[end] != 99999999;   }   int MCMF(int begin, int end) {     int ans = 0, flow;     int flow_sum = 0;     while (spfa(begin, end)) {       flow = 99999999;       for (int i = pre[end]; i != -1; i = pre[edge[i].u])         if (edge[i].c < flow) flow = edge[i].c;       for (int i = pre[end]; i != -1; i = pre[edge[i].u]) {         edge[i].c -= flow;         edge[i ^ 1].c += flow;       }       ans += dist[end] * flow;       flow_sum += flow;     }     anss = flow_sum;     return ans;   }   int main() {     int n, m, a, b, c, cost, i, j, cc, len;     scanf( %s , str);     len = strlen(str);     init();     for (i = 0; i < strlen(str); i++) cntt[str[i] - 97]++;     scanf( %d , &n);     for (i = n + 1; i <= n + 26; i++) addedge(i, n + 27, cntt[i - n - 1], 0);     for (i = 1; i <= n; i++) {       scanf( %s%d , str, &cc);       addedge(0, i, cc, i);       memset(cntt, 0, sizeof(cntt));       for (j = 0; j < strlen(str); j++) cntt[str[j] - 97]++;       for (j = 0; j < 26; j++) addedge(i, n + 1 + j, cntt[j], 0);     }     int z = MCMF(0, n + 27);     if (anss == len)       printf( %d n , z);     else       printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100;   char s[N];   int n, m, t[N];   int a[N * 4], b[N * 4], ab[N * 4], ba[N * 4], aba[N * 4], tag[N * 4];   void pushup(int now) {     a[now] = max(a[(now << 1)], a[(now << 1 | 1)]);     b[now] = min(b[(now << 1)], b[(now << 1 | 1)]);     ab[now] = max(ab[(now << 1)],                   max(ab[(now << 1 | 1)], a[(now << 1)] - 2 * b[(now << 1 | 1)]));     ba[now] = max(ba[(now << 1)],                   max(ba[(now << 1 | 1)], a[(now << 1 | 1)] - 2 * b[(now << 1)]));     aba[now] = max(max(aba[(now << 1)], aba[(now << 1 | 1)]),                    max(ab[(now << 1)] + a[(now << 1 | 1)],                        ba[(now << 1 | 1)] + a[(now << 1)]));   }   void build(int now, int l, int r) {     if (l + 1 == r) {       a[now] = b[now] = t[l];       ab[now] = ba[now] = -t[l];       return;     }     int mid = (l + r) >> 1;     build((now << 1), l, mid);     build((now << 1 | 1), mid, r);     pushup(now);   }   void down(int now, int val) {     a[now] += val;     b[now] += val;     ab[now] -= val;     ba[now] -= val;     tag[now] += val;   }   void pushdown(int now) {     down((now << 1), tag[now]);     down((now << 1 | 1), tag[now]);     tag[now] = 0;   }   void Insert(int now, int l, int r, int a, int b, int val) {     if (a <= l && b >= r - 1) {       down(now, val);       return;     }     int mid = (l + r) >> 1;     pushdown(now);     if (a < mid) Insert((now << 1), l, mid, a, b, val);     if (b >= mid) Insert((now << 1 | 1), mid, r, a, b, val);     pushup(now);   }   int main() {     int x, y, z;     scanf( %d%d , &n, &m);     n = n * 2 - 2;     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) {       if (s[i] ==  ( )         t[i] = t[i - 1] + 1;       else         t[i] = t[i - 1] - 1;       Insert(1, 1, n + 1, i, i, t[i]);     }     printf( %d n , aba[1]);     for (int i = 0; i < m; ++i) {       scanf( %d%d , &x, &y);       if (x > y) swap(x, y);       if (s[x] ==  ( )         z = -2;       else         z = 2;       Insert(1, 1, n + 1, x, y - 1, z);       swap(s[x], s[y]);       printf( %d n , aba[1]);     }     return 0;   }


#include  bits/stdc++.h    using namespace std;   using ll = long long;   using pii = pair<int,int>;   using pll = pair<ll,ll>;   template<typename T>   int sz(const T &a){return int(a.size());}   const int MN=601;   int dist[MN];   bool used[MN];   int arr[MN][MN];   int main(){       cin.tie(NULL);       ios_base::sync_with_stdio(false);       int n,m,a,b,c;       cin>>n>>m;       for(int i=0;i<n;i++)for(int j=0;j<n;j++)arr[i][j]=INT_MAX;       for(int i=1;i<=m;i++){           cin>>a>>b>>c;           arr[a][b]=c;       }       for(int i=0;i<n;i++){           for(int j=0;j<n;j++)dist[j]=INT_MAX,used[j]=false;           dist[i]=0;           for(int level=1;level<n;level++){               int cur=-1;               for(int j=0;j<n;j++){                   if(!used[j]&&(cur==-1||dist[j]<dist[cur]))cur=j;               }               used[cur]=true;               int mi=INT_MAX;               for(int j=0;j<n;j++)if(arr[cur][(j-dist[cur]%n+n)%n]!=INT_MAX)mi=min(mi,arr[cur][(j-dist[cur]%n+n)%n]+n-1-j);               for(int j=0;j<n;j++){                   mi=min(mi+1,arr[cur][(j-dist[cur]%n+n)%n]);                   dist[j]=min(dist[j],dist[cur]+mi);               }           }           for(int j=0;j<n;j++)printf( %d%c ,dist[j],   n [j==n-1]);       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   const int MAXN = 1e6 + 5;   int n, m, t;   int v[MAXN];   char s[MAXN];   int main() {     cin >> t;     while (t--) {       cin >> n >> s + 1;       int sum1 = 0, sum2 = 0, now = 0;       for (int i = 1; i <= n * 2; i++) {         if (s[i] ==  1 )           now++;         else {           sum1 += max(now - 1, 0);           now = 0;         }       }       if (now) sum1 += now - 1;       now = 0;       for (int i = 1; i <= n * 2; i++) {         if (s[i] ==  0 )           now++;         else {           sum2 += max(now - 1, 0);           now = 0;         }       }       if (now) sum2 += now - 1;       cout << max(sum1, sum2) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 300005;   pair<int, int> seg[2 * MAX];   void update(int l, int r, int fight, int value) {     for (l += MAX, r += MAX; l < r; l >>= 1, r >>= 1) {       if (l & 1) seg[l++] = make_pair(fight, value);       if (r & 1) seg[--r] = make_pair(fight, value);     }   }   int query(int p) {     pair<int, int> res = make_pair(INT_MAX, 0);     for (p += MAX; p > 1; p >>= 1) res = min(res, seg[p]);     return res.second;   }   int main() {     int n, m;     cin >> n >> m;     vector<pair<pair<int, int>, int> > v;     for (int i = 0; i < 2 * MAX; i++) seg[i] = make_pair(INT_MAX, 0);     for (int i = 0; i < m; i++) {       int a, b, x;       cin >> a >> b >> x;       v.push_back(make_pair(make_pair(a, b), x));     }     for (int i = m - 1; i >= 0; i--) {       int l = v[i].first.first;       int r = v[i].first.second;       int win = v[i].second;       update(l - 1, win - 1, i, win);       update(win, r, i, win);     }     for (int i = 0; i < n; i++) cout << query(i) <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int *c;   int main() {     int a, b, t, f, n, m, d, g, sum = 0;     int mas[4];     cin >> mas[0] >> mas[1] >> mas[2] >> mas[3] >> a >> b;     c = min_element(mas, mas + 4);     *c = min(*c, b + 1);     if (*c - a >= 0)       cout << *c - a;     else       cout <<  0 ;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int t, n, m, x = 0, y = 0, flag = 0, cnt = 0, sum = 0, sum1 = 0, sum0 = 0,                  flag1 = 0;     int a1, a2, a3, b1, b2, b3;     vector<int> d;     cin >> t;     int a[t];     for (int i = 0; i < t; i++) {       cin >> a[i];     }     x = t - 1;     while (x > 0 && a[x - 1] < a[x]) {       x--;     }     cout << x <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, tab[70], p;   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &tab[i]);     sort(tab, tab + n);     if (k > n) {       printf( -1 n );       return 0;     }     printf( %d %d n , tab[n - k], tab[n - k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = int(1e6) + 10;   const int MAX_M = 21;   int n, r, c;   int a[MAX_N], b[MAX_N];   int f[MAX_N][MAX_M];   char buffer[MAX_N * 6];   int main() {     scanf( %d%d%d n , &n, &r, &c);     c++;     gets(buffer);     int m = strlen(buffer);     buffer[m++] =    ;     for (int i = 0, j = 0; i < n; i++, j++) {       b[i] = j;       for (a[i] = 0; j < m && buffer[j] !=    ; j++, a[i]++)         ;     }     b[n] = m;     for (int i = 0, j = 0, sum = 0; i < n; i++) {       for (; j < n && sum + a[j] + 1 <= c; sum += a[j++] + 1)         ;       f[i][0] = j - i;       if (i < j) {         sum -= a[i] + 1;       } else {         j++;       }     }     for (int j = 1; 1 << j <= r; j++) {       for (int i = 0; i < n; i++) {         f[i][j] = f[i][j - 1] + f[i + f[i][j - 1]][j - 1];       }     }     int result = 0, start = 0, l = 0;     for (; 1 << l <= r; l++)       ;     for (int i = 0; i < n; i++) {       int sum = 0, tmp = r;       for (int k = l; k >= 0; k--) {         if (tmp - (1 << k) >= 0) {           sum += f[i + sum][k];           tmp -= 1 << k;         }       }       if (sum > result) {         result = sum;         start = i;       }     }     for (int i = 0, p = start; i < r; i++) {       int sum = 0;       for (; p < n && (sum + a[p] + 1) <= c; sum += a[p++] + 1) {         if (sum > 0) {           putchar(   );         }         for (int j = b[p]; j < b[p + 1] - 1; j++) {           putchar(buffer[j]);         }       }       if (sum > 0) {         puts(  );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int s[n + 1];     s[0] = 0;     for (int i = 1; i <= n; i++) cin >> s[i];     int dp[n + 1][n + 1];     memset(dp, 0, sizeof(dp));     int ans = 0;     for (int i = 1; i <= n; i++) {       int prev = 0;       for (int j = 0; j < i; j++) {         dp[i][j] = dp[j][prev] + 1;         if (s[i] == s[j]) prev = j;         ans = max(ans, dp[i][j]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int32_t MAX = 1000000 + 1;   int64_t ans[MAX];   int main(int argc, char *argv[]) {     ios_base::sync_with_stdio(false);     ifstream in( input.txt );     ofstream out( output.txt );     int64_t n, q, k = 0, type, evenSh = 0, oddSh = 0, parity = 0, lastSh = 0;     scanf( %I64d , &n);     scanf( %I64d , &q);     for (int32_t t = 0; t < q; ++t) {       scanf( %I64d , &type);       if (type == 1) {         scanf( %I64d , &k);         evenSh += k;         oddSh += k;         lastSh += k;       } else {         if ((parity + lastSh) % 2 == 0) {           lastSh = 0;           parity = 1;           evenSh -= 1;           oddSh += 1;         } else {           lastSh = 0;           parity = 0;           evenSh += 1;           oddSh -= 1;         }       }     }     if (oddSh < 0) oddSh = n - ((-oddSh) % n);     if (evenSh < 0) evenSh = n - ((-evenSh) % n);     for (int64_t i = 0; i < n; ++i)       if ((i + 1) % 2 == 1)         ans[(i + oddSh) % n] = i + 1;       else         ans[(i + evenSh) % n] = i + 1;     for (int64_t i = 0; i < n; ++i) printf( %I64d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 101010;   int n, ans;   int pa[N << 1], ns[N], nt[N], ma[N], pos[N];   vector<pair<int, int> > res;   char s[N], sr[N];   void Manacher(char *s, int n, int *pa) {     pa[0] = 1;     for (int i = 1, j = 0; i < (n << 1) - 1; ++i) {       int p = i >> 1, q = i - p, r = ((j + 1) >> 1) + pa[j] - 1;       pa[i] = r < q ? 0 : min(r - q + 1, pa[(j << 1) - i]);       while (0 <= p - pa[i] && q + pa[i] < n && s[p - pa[i]] == s[q + pa[i]])         pa[i]++;       if (q + pa[i] - 1 > r) j = i;     }     for (int i = (0); i < (n); ++i) pa[i] = pa[i << 1];   }   void kmp(char *s, int *ns, char *t, int *nt) {     int lens = strlen(s);     int lent = strlen(t);     nt[0] = -1;     for (int i = 0, j = -1; i < lens; ++i) {       while (j >= 0 && s[i] != t[j + 1]) j = nt[j];       if (s[i] == t[j + 1]) ++j;       ns[i] = j;       if (j + 1 == lent) j = nt[j];     }   }   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     cin >> s;     n = strlen(s);     Manacher(s, n, pa);     for (int i = (0); i < (n); ++i) sr[i] = s[n - 1 - i];     sr[n] =   0 ;     kmp(sr + 1, nt + 1, sr, nt);     kmp(s, ns, sr, nt);     for (int i = (0); i < (n); ++i)       if (~ns[i]) ++ns[i];     ma[0] = ns[0];     pos[0] = 0;     for (int i = (1); i < (n); ++i) {       ma[i] = ma[i - 1];       pos[i] = pos[i - 1];       if (ma[i] < ns[i]) {         ma[i] = ns[i];         pos[i] = i;       }     }     for (int i = (0); i < (n); ++i) {       int k = i - pa[i];       int t = max(0, min(k < 0 ? 0 : ma[k], n - i - pa[i]));       int c = pa[i] * 2 - 1 + t * 2;       if (ans < c) {         ans = c;         res.clear();         res.push_back(make_pair(i - pa[i] + 1, pa[i] * 2 - 1));         if (t) {           res.push_back(make_pair(n - t, t));           int o = pos[k] - 2 * ns[pos[k]] + t + 1;           res.push_back(make_pair(o, t));         }       }     }     sort(res.begin(), res.end());     cout << (int)res.size() <<   n ;     for (auto u : res) cout << u.first + 1 <<     << u.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int a[maxn], b[maxn];   int main() {     int n, i, j;     cin >> n;     for (i = 0; i < n; i++) cin >> j, a[j] = i;     multiset<int> s;     for (i = 0; i < n; i++) cin >> b[i], s.insert(i - a[b[i]]);     for (int i = 0; i < n; i++) {       multiset<int>::iterator it = s.lower_bound(i);       int ans = maxn;       if (it != s.end()) ans = min(ans, *it - i);       if (it != s.begin()) ans = min(ans, i - *(--it));       printf( %d n , ans);       it = s.find(i - a[b[i]]);       s.erase(it);       s.insert(i - a[b[i]] + n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int sq = 320;   int n, q, p[N], r[N], dp[N];   int f(int x) {     int y = x;     for (int i = 0; i < sq; i++) x = p[x];     return dp[y] = x;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> q;     for (int i = 1; i <= n; i++) {       cin >> p[i];       r[p[i]] = i;     }     for (int i = 1; i <= n; i++) f(i);     while (q--) {       int t, x, y;       cin >> t >> x >> y;       if (t == 1) {         swap(r[p[x]], r[p[y]]);         swap(p[x], p[y]);         vector<int> v = {x, y};         for (int au : v) {           int nxt = f(au);           for (int i = 0; i < sq; i++) {             dp[au] = nxt;             au = r[au];             nxt = r[nxt];           }         }       } else {         while (y >= sq) {           y -= sq;           x = dp[x];         }         while (y) {           y--;           x = p[x];         }         cout << x <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     map<char, long long> mp;     for (long long i = 0; i < n; i++) {       char x;       cin >> x;       mp[x]++;     }     vector<pair<long long, char>> v;     for (auto it : mp) {       pair<long long, char> p;       p.first = it.second;       p.second = it.first;       v.push_back(p);     }     sort(v.begin(), v.end(), greater<pair<long long, char>>());     long long ans = 0;     for (long long i = 0; i < v.size() && k > 0; i++) {       long long x = min(k, v[i].first);       ans += (x * x);       k -= x;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[] =  GB ;   int main() {     int n, k, a, b;     scanf( %d%d%d%d , &n, &k, &a, &b);     if (a < b) {       swap(a, b);       swap(s[0], s[1]);     }     int num = (a - 1) / k + 1;     if (b < num - 1) {       puts( NO );       return 0;     }     while (num--) {       int cnt = min(a, k);       a -= cnt;       while (cnt--) {         putchar(s[0]);       }       cnt = 0;       while (cnt < k && b > 0 && b > num - 1) {         putchar(s[1]);         ++cnt;         --b;       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, a, b;     scanf( %d , &t);     while (t--) {       scanf( %d%d , &a, &b);       double output;       if (b == 0) {         printf( 1 n );         continue;       } else if (a == 0) {         printf( 0.5 n );         continue;       }       if (a < 4 * b)         output = (double)(a + 8 * b) / 16.0 / b;       else         output = (double)(a - b) / (double)a;       printf( %lf n , output);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, kol = 0;     vector<int> a, b;     cin >> n;     for (i = 0; i < n; i++) {       cin >> j;       a.push_back(j);       b.push_back(j);     }     sort(b.begin(), b.end());     for (i = 0; i < n; i++)       if (a[i] != b[i]) kol++;     if (kol == 0 || kol == 2)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 200005;   int nn;   int x[MAXN];   long long tt;   long long a[MAXN];   long long mi[MAXN], mx[MAXN];   long long ans[MAXN];   int tag[MAXN];   int main() {     using namespace std;     ios::sync_with_stdio(false);     cin.tie(0);     cin >> nn >> tt;     for (int i = 1; i <= nn; i++) {       cin >> a[i];       mi[i] = a[i] + tt;       mx[i] = (long long)6e18;     }     for (int i = 1; i <= nn; i++) {       cin >> x[i];       if (x[i] < i) {         cout <<  No n ;         return 0;       }       if (x[i] != nn) mx[x[i]] = a[x[i] + 1] + tt - 1;       tag[i]++;       tag[x[i]]--;     }     for (int i = 1; i <= nn; i++) {       tag[i] += tag[i - 1];       if (tag[i] > 0 && i != nn) mi[i] = a[i + 1] + tt;       if (mi[i] > mx[i] || ans[i - 1] + 1 > mx[i]) {         cout <<  No n ;         return 0;       }       ans[i] = max(mi[i], ans[i - 1] + 1);     }     cout <<  Yes n ;     for (int i = 1; i <= nn; i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }