#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-9; n const long double PI = 3.141592653589793238462643383279502884197; n const int MOD = 666013; n const int NMax = 350000; n int N, C, D; n int lastIndexForSearch; n long long ans = 0LL; n struct Punct; n long long diferente[NMax], diferentePartiale[NMax]; n long long sqr(const long long &x); n long long Determinant(const Punct &A, const Punct &B, const Punct &C); n long long Dist2(const Punct &A, const Punct &B); n long double GetAngle(const Punct &A); n int GetCadran(const Punct &A); n long long CompareUnghiPolar(const Punct &A, const Punct &B); n struct Punct { n   int x, y; n   Punct() { n     this->x = 0; n     this->y = 0; n   } n   Punct(const int x, const int y) { n     this->x = x; n     this->y = y; n   } n   inline bool operator<(const Punct &other) const { n     long long s = CompareUnghiPolar(*this, other); n     if (s == 0) return Dist2(Punct(0, 0), *this) < Dist2(Punct(0, 0), other); n     return s == -1; n   } n }; n Punct a[NMax]; n enum InsertType { n   InsertCoord, n   InsertCntStrict, n   InsertCntNestrict, n   InsertIndexNestrict n }; n enum QueryType { n   QueryCoord, n   QueryCntStrict, n   QueryCntNestrict, n   QueryIndexNestrict n }; n struct HashNode { n   int x, y, indexNestrict; n   long long cntStrict, cntNestrict; n   HashNode() { n     x = y = indexNestrict = 0; n     cntStrict = cntNestrict = 0LL; n   } n   HashNode(const int &x, const int &y, const int &indexNestrict, n            const long long &cntStrict, const long long &cntNestrict) { n     this->x = x; n     this->y = y; n     this->indexNestrict = indexNestrict; n     this->cntStrict = cntStrict; n     this->cntNestrict = cntNestrict; n   } n }; n vector<HashNode> H[MOD]; n struct CntEvidence { n   int x, y; n   long long cnt; n   CntEvidence() { n     x = y = 0; n     cnt = 0LL; n   } n   CntEvidence(const int &x, const int &y, const long long &cnt) { n     this->x = x; n     this->y = y; n     this->cnt = cnt; n   } n   inline bool operator<(const CntEvidence &other) const { n     long long s = n         CompareUnghiPolar(Punct(this->x, this->y), Punct(other.x, other.y)); n     if (s == 0) n       return Dist2(Punct(0, 0), Punct(this->x, this->y)) < n              Dist2(Punct(0, 0), Punct(other.x, other.y)); n     return s == -1; n   } n }; n CntEvidence maiMiciStrictVector[NMax]; n CntEvidence maiMiciStrictVectorSumePartiale[NMax]; n CntEvidence maiMiciSauEgaleVector[NMax]; n CntEvidence maiMiciSauEgaleVectorSumePartiale[NMax]; n int NmaiMiciStrictVector; n int NmaiMiciSauEgaleVector; n int gcd(int x, int y) { n   int r; n   while (y) { n     r = x % y; n     x = y; n     y = r; n   } n   return x; n } n void Insert(const int &x, const int &y, InsertType type, long long param = 0) { n   int codh = (abs(x) + abs(y)) % MOD; n   if (type == InsertCoord) { n     for (vector<HashNode>::iterator it = H[codh].begin(); it != H[codh].end(); n          ++it) { n       if (it->x == x && it->y == y) return; n     } n     H[codh].push_back(HashNode(x, y, 0, 0, 0)); n     return; n   } else if (type == InsertCntStrict) { n     for (vector<HashNode>::iterator it = H[codh].begin(); it != H[codh].end(); n          ++it) { n       if (it->x == x && it->y == y) { n         it->cntStrict = param; n         return; n       } n     } n     H[codh].push_back(HashNode(x, y, 0, param, 0)); n     return; n   } else if (type == InsertCntNestrict) { n     for (vector<HashNode>::iterator it = H[codh].begin(); it != H[codh].end(); n          ++it) { n       if (it->x == x && it->y == y) { n         it->cntNestrict = param; n         return; n       } n     } n     H[codh].push_back(HashNode(x, y, 0, 0, param)); n     return; n   } else if (type == InsertIndexNestrict) { n     for (vector<HashNode>::iterator it = H[codh].begin(); it != H[codh].end(); n          ++it) { n       if (it->x == x && it->y == y) { n         it->indexNestrict = param; n         return; n       } n     } n     H[codh].push_back(HashNode(x, y, param, 0, 0)); n     return; n   } n } n void FindMaiMiciStrict(int x, int y) { n   int st = 1, dr = lastIndexForSearch; n   int ret = 0; n   while (st <= dr) { n     int mij = (st + dr) / 2; n     if (CompareUnghiPolar(a[mij], Punct(x, y)) < 0) { n       ret = mij; n       st = mij + 1; n     } else n       dr = mij - 1; n   } n   Insert(x, y, InsertCntStrict, ret); n   maiMiciStrictVector[++NmaiMiciStrictVector] = CntEvidence(x, y, ret); n } n void FindMaiMiciSauEgale(int x, int y) { n   int st = 1, dr = lastIndexForSearch; n   int ret = 0; n   while (st <= dr) { n     int mij = (st + dr) / 2; n     if (CompareUnghiPolar(a[mij], Punct(x, y)) <= 0) { n       ret = mij; n       st = mij + 1; n     } else n       dr = mij - 1; n   } n   Insert(x, y, InsertCntNestrict, ret); n   maiMiciSauEgaleVector[++NmaiMiciSauEgaleVector] = CntEvidence(x, y, ret); n } n long long QueryHash(int x, int y, QueryType type) { n   x = -x; n   y = -y; n   if (y == 0) { n     if (x < 0) n       x = -1; n     else if (x > 0) n       x = 1; n   } else if (x == 0) { n     if (y < 0) n       y = -1; n     else if (y > 0) n       y = 1; n   } else { n     int semnx = 1; n     int semny = 1; n     if (x < 0) { n       x = -x; n       semnx = -1; n     } n     if (y < 0) { n       y = -y; n       semny = -1; n     } n     int cmmdc = gcd(x, y); n     x = x / cmmdc; n     y = y / cmmdc; n     x = x * semnx; n     y = y * semny; n   } n   int codh = (abs(x) + abs(y)) % MOD; n   for (vector<HashNode>::iterator it = H[codh].begin(); it != H[codh].end(); n        ++it) { n     if (it->x == x && it->y == y) { n       if (type == QueryCntStrict) return it->cntStrict; n       if (type == QueryCntNestrict) return it->cntNestrict; n       if (type == QueryIndexNestrict) return it->indexNestrict; n     } n   } n   return -1; n } n void Solve() { n   int loc; n   loc = 0; n   for (int i = 1; i <= N; ++i) { n     if (a[i].y > 0 || (a[i].y == 0 && a[i].x > 0)) { n       ++loc; n       swap(a[i], a[loc]); n     } n   } n   sort(a + 1, a + loc + 1); n   sort(a + loc + 1, a + N + 1); n   lastIndexForSearch = -1; n   NmaiMiciStrictVector = 0; n   NmaiMiciSauEgaleVector = 0; n   int specialIndex = -1; n   for (int i = 1; i <= N; ++i) { n     if (GetAngle(a[i]) >= PI) { n       if (a[i].y == 0) { n         Insert(1, 0, InsertCoord); n         FindMaiMiciStrict(1, 0); n         FindMaiMiciSauEgale(1, 0); n         continue; n       } n       if (a[i].x == 0) { n         Insert(0, 1, InsertCoord); n         FindMaiMiciStrict(0, 1); n         FindMaiMiciSauEgale(0, 1); n         continue; n       } n       int x, y; n       x = -a[i].x; n       y = -a[i].y; n       int semnx = 1, semny = 1; n       if (x < 0) { n         x = -x; n         semnx = -1; n       } n       if (y < 0) { n         y = -y; n         semny = -1; n       } n       int cmmdc = gcd(x, y); n       x = x / cmmdc; n       y = y / cmmdc; n       x = x * semnx; n       y = y * semny; n       Insert(x, y, InsertCoord); n       FindMaiMiciStrict(x, y); n       FindMaiMiciSauEgale(x, y); n     } else { n       lastIndexForSearch = i; n     } n   } n   bool foundOnRightOX = false; n   specialIndex = NmaiMiciSauEgaleVector; n   for (int i = 1; i <= N; ++i) { n     if (a[i].y == 0 && a[i].x > 0) { n       foundOnRightOX = true; n       Insert(-1, 0, InsertCoord); n       FindMaiMiciStrict(-1, 0); n       FindMaiMiciSauEgale(-1, 0); n     } n   } n   loc = 0; n   for (int i = 1; i <= NmaiMiciStrictVector; ++i) { n     if (maiMiciStrictVector[i].y > 0 || n         (maiMiciStrictVector[i].y == 0 && maiMiciStrictVector[i].x > 0)) { n       ++loc; n       swap(maiMiciStrictVector[i], maiMiciStrictVector[loc]); n     } n   } n   sort(maiMiciStrictVector + 1, maiMiciStrictVector + loc + 1); n   sort(maiMiciStrictVector + loc + 1, n        maiMiciStrictVector + NmaiMiciStrictVector + 1); n   for (int i = 1; i <= NmaiMiciStrictVector; ++i) { n     maiMiciStrictVectorSumePartiale[i].x = maiMiciStrictVector[i].x; n     maiMiciStrictVectorSumePartiale[i].y = maiMiciStrictVector[i].y; n     maiMiciStrictVectorSumePartiale[i].cnt = n         ((i > 1) ? (maiMiciStrictVectorSumePartiale[i - 1].cnt) : (0)) + n         maiMiciStrictVector[i].cnt; n   } n   loc = 0; n   for (int i = 1; i <= NmaiMiciSauEgaleVector; ++i) { n     if (maiMiciSauEgaleVector[i].y > 0 || n         (maiMiciSauEgaleVector[i].y == 0 && maiMiciSauEgaleVector[i].x > 0)) { n       ++loc; n       swap(maiMiciSauEgaleVector[i], maiMiciSauEgaleVector[loc]); n     } n   } n   sort(maiMiciSauEgaleVector + 1, maiMiciSauEgaleVector + loc + 1); n   sort(maiMiciSauEgaleVector + loc + 1, n        maiMiciSauEgaleVector + NmaiMiciSauEgaleVector + 1); n   for (int i = 1; i <= NmaiMiciSauEgaleVector; ++i) { n     maiMiciSauEgaleVectorSumePartiale[i].x = maiMiciSauEgaleVector[i].x; n     maiMiciSauEgaleVectorSumePartiale[i].y = maiMiciSauEgaleVector[i].y; n     maiMiciSauEgaleVectorSumePartiale[i].cnt = n         ((i > 1) ? (maiMiciSauEgaleVectorSumePartiale[i - 1].cnt) : (0)) + n         maiMiciSauEgaleVector[i].cnt; n   } n   for (int i = 1; i <= NmaiMiciSauEgaleVector; ++i) { n     int index = i; n     int x = maiMiciSauEgaleVectorSumePartiale[i].x; n     int y = maiMiciSauEgaleVectorSumePartiale[i].y; n     Insert(x, y, InsertIndexNestrict, index); n   } n   for (int i = 1; i <= NmaiMiciSauEgaleVector; ++i) n     diferente[i] = n         max(0LL, maiMiciSauEgaleVector[i].cnt - maiMiciStrictVector[i].cnt); n   for (int i = 1; i <= NmaiMiciSauEgaleVector; ++i) n     diferentePartiale[i] = diferentePartiale[i - 1] + diferente[i]; n   if (lastIndexForSearch != -1 && NmaiMiciSauEgaleVector != 0 && n       NmaiMiciStrictVector != 0) { n     for (int i = lastIndexForSearch + 1; i <= N; ++i) { n       if (a[i].y == 0 && a[i].x < 0) { n         int index; n         if (foundOnRightOX) { n           index = specialIndex; n         } else n           index = NmaiMiciSauEgaleVector; n         if (index <= 0) continue; n         long long total = maiMiciSauEgaleVectorSumePartiale[index].cnt; n         long long total2; n         int jndex = QueryHash(a[i].x, a[i].y, QueryIndexNestrict); n         if (jndex == -1) continue; n         total2 = maiMiciSauEgaleVectorSumePartiale[jndex].cnt + n                  1LL * (index - jndex) * maiMiciSauEgaleVector[jndex].cnt; n         long long inPlus = diferentePartiale[index]; n         if (foundOnRightOX) inPlus = inPlus - diferentePartiale[jndex]; n         ans += max(0LL, total - total2 - inPlus); n       } else { n         int index; n         index = NmaiMiciSauEgaleVector; n         if (index <= 0) continue; n         long long total = maiMiciSauEgaleVectorSumePartiale[index].cnt; n         long long total2; n         int jndex = QueryHash(a[i].x, a[i].y, QueryIndexNestrict); n         if (jndex == -1) continue; n         total2 = maiMiciSauEgaleVectorSumePartiale[jndex].cnt + n                  1LL * (index - jndex) * maiMiciSauEgaleVector[jndex].cnt; n         long long inPlus = diferentePartiale[index]; n         inPlus = inPlus - diferentePartiale[jndex]; n         ans += max(0LL, total - total2 - inPlus); n       } n     } n   } n } n void EliminaDuplicate() { n   int maiMici180, cnt; n   long long total; n   maiMici180 = 0; n   total = 0LL; n   for (int i = 1; i <= N; ++i) { n     int x = a[i].x, y = a[i].y; n     if (y > 0 || (y == 0 && x > 0)) ++maiMici180; n   } n   for (int i = 1; i <= N; ++i) { n     if (a[i].y < 0) { n       int x = -a[i].x; n       int y = -a[i].y; n       int st = 1, dr = maiMici180; n       int val = 0; n       while (st <= dr) { n         int mij = (st + dr) / 2; n         if (Determinant(Punct(0, 0), Punct(x, y), a[mij]) <= 0) { n           val = mij; n           st = mij + 1; n         } else n           dr = mij - 1; n       } n       total += max(0, maiMici180 - val); n     } n   } n   cnt = 0; n   for (int i = 1; i <= N; ++i) n     if (a[i].y == 0 && a[i].x > 0) ++cnt; n   ans = ans - 1LL * total * cnt; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin >> N >> C >> D; n   for (int i = 1; i <= N; ++i) { n     int x, y; n     cin >> x >> y; n     a[i] = Punct(x - C, y - D); n   } n   Solve(); n   EliminaDuplicate(); n   for (int i = 0; i < MOD; ++i) H[i].clear(); n   for (int i = 1; i <= N; ++i) { n     a[i].x = -a[i].x; n     a[i].y = -a[i].y; n   } n   Solve(); n   EliminaDuplicate(); n   cout << ans <<   n ; n   return 0; n } n long long sqr(const long long &x) { return x * x; } n long long Determinant(const Punct &A, const Punct &B, const Punct &C) { n   return 1LL * (A.x - C.x) * (B.y - C.y) - 1LL * (A.y - C.y) * (B.x - C.x); n } n long long Dist2(const Punct &A, const Punct &B) { n   return sqr(A.x - B.x) + sqr(A.y - B.y); n } n int GetCadran(const Punct &A) { n   if (A.x > 0 && A.y > 0) return 1; n   if (A.x < 0 && A.y > 0) return 2; n   if (A.x < 0 && A.y < 0) return 3; n   return 4; n } n long double GetAngle(const Punct &A) { n   long double ret = atan2(A.y, A.x); n   if (A.y < 0) ret = ret + PI * 2.0; n   return ret; n } n long long CompareUnghiPolar(const Punct &A, const Punct &B) { n   long long ret = Determinant(Punct(0, 0), A, B); n   if (ret > 0) return -1; n   if (ret < 0) return 1; n   if (A.y == 0 && B.y == 0) { n     if ((A.x > 0 && B.x > 0) || (A.x < 0 && B.x < 0)) return 0; n     if (A.x > 0 && B.x < 0) return -1; n     return 1; n   } n   if (A.x == 0 && B.x == 0) { n     if ((A.y > 0 && B.y > 0) || (A.y < 0 && B.y < 0)) return 0; n     if (A.y > 0 && B.y < 0) return -1; n     return 1; n   } n   int semnxA, semnxB, semnyA, semnyB; n   semnxA = semnxB = semnyA = semnyB = 1; n   if (A.x < 0) semnxA = -1; n   if (B.x < 0) semnxB = -1; n   if (A.y < 0) semnyA = -1; n   if (B.y < 0) semnyB = -1; n   if (semnxA == semnxB && semnyA == semnyB) return 0; n   if (semnyA == 1) return -1; n   return 1; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 577, INF = 1e9, mod = 1e9 + 7; n int n, m; n long long h; n int a[N][N], b[N][N]; n int ans; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       scanf( %d , &a[i][j]); n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       scanf( %d , &b[i][j]); n       if (b[i][j] != a[i][j]) { n         b[1][1] = !b[1][1]; n         b[i][1] = !b[i][1]; n         b[1][j] = !b[1][j]; n         b[i][j] = !b[i][j]; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (b[i][j] != a[i][j]) { n         printf( No n ); n         return 0; n       } n     } n   } n   printf( Yes n ); n   return 0; n } n


#include <iostream> n #define MAX 200010 n using namespace std; n  n long long int t, n, A[MAX], DP[MAX][105], res, a; n  n int main() n { n     cin >> t; n     for (int i = 0; i <= MAX - 3; i++) n     { n         DP[i][0] = 1; n         if (i <= 100) n             DP[i][i] = 1; n     } n     for (int i = 1; i <= MAX - 3; i++) n     { n         for (int j = 1; j <= min(i, 100); j++) n         { n             DP[i][j] = DP[i - 1][j] + DP[i - 1][j - 1]; n         } n     } n     while (t--) n     { n         cin >> n; n         res = 0; n         for (int i = 1; i <= n; i++) n             A[i] = 0; n         for (int i = 1; i <= n; i++) n         { n             cin >> a; n             A[a]++; n         } n         for (int i = 1; i <= n; i++) n         { n             res += A[i] * DP[A[i - 1] + A[i - 2]][2]; n             res += DP[A[i]][2] * DP[A[i - 1] + A[i - 2]][1]; n             res += DP[A[i]][3]; n         } n         cout << res << endl; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1000000007; n void dispvec(set<long long int> arr) { n   set<long long int>::iterator itr = arr.begin(); n   while (itr != arr.end()) { n     cout << *itr <<    ; n     itr++; n   } n   cout << endl; n } n struct CustomCompare { n   bool operator()(const pair<long long int, long long int> &i, n                   const pair<long long int, long long int> &j) { n     if (i.first == j.first) return i.first < j.first; n     return i.second < j.second; n   } n }; n void solve() { n   int n; n   cin >> n; n   vector<long long int> arr(n); n   for (int i = 0; i < n; i++) cin >> arr[i]; n   long long int sum = arr[0] + 1; n   int curr = arr[0]; n   for (int i = 1; i < n; i++) { n     if (arr[i] < arr[i - 1]) { n       sum += arr[i - 1] - arr[i]; n     } else if (arr[i] > arr[i - 1]) { n       sum += arr[i] - arr[i - 1]; n     } n     sum += 2; n   } n   cout << sum << endl; n } n int main() { n   int t = 1; n   int i = 1; n   while (i <= t) { n     solve(); n     i++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int num[300005][2]; n int jichu = 100000; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m, x; n   cin >> n >> m; n   if (n == 1) { n     cout << 0 << endl; n     return 0; n   } n   long long cont = 0, sum = n; n   for (int i = 1; i <= n; i++) { n     num[jichu + i][0] = 1; n     num[jichu + i][1] = 1; n   } n   for (int i = 1; i <= m; i++) { n     cin >> x; n     int l = x - i, r = x + i; n     if (num[jichu + l][1] > 0) { n       cont += 1LL * num[jichu + l][1]; n       num[jichu + l - 1][1] += num[jichu + l][1]; n       num[jichu + l][1] = 0; n     } n     if (num[jichu + r][0] > 0) { n       cont += 1LL * num[jichu + r][0]; n       num[jichu + r + 1][0] += num[jichu + r][0]; n       num[jichu + r][0] = 0; n     } n   } n   for (int i = jichu + 1 - m; i < jichu + n; i++) { n     if (i + m + 1 > jichu + n) { n       sum += 1LL * num[i][1] * ((m + 1) - (i + m + 1 - jichu - n)); n     } else { n       sum += 1LL * num[i][1] * (m + 1); n     } n   } n   for (int i = jichu + 2; i <= jichu + n + m; i++) { n     if (i <= jichu + m + 1) { n       sum += 1LL * num[i][0] * (i - jichu - 1); n     } else { n       sum += 1LL * num[i][0] * (m + 1); n     } n   } n   sum -= cont; n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fpow(long long a, int b, int mod) { n   long long res = 1; n   for (; b > 0; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res % mod; n } n const int mod = 1e9 + 7; n const int N = 2e5 + 100; n inline int read() { n   static char buf[1000000], *p1 = buf, *p2 = buf; n   register int x = false; n   register char ch = n       p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n           ? EOF n           : *p1++; n   ; n   register bool sgn = false; n   while (ch !=  -  && (ch <  0  || ch >  9 )) n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   if (ch ==  - ) n     sgn = true, n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   while (ch >=  0  && ch <=  9 ) n     x = (x << 1) + (x << 3) + (ch ^ 48), n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   return sgn ? -x : x; n } n int mon[N]; n int d[N]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) scanf( %d , &mon[i]); n     scanf( %d , &m); n     for (int i = 1; i <= m; i++) { n       int a, b; n       scanf( %d%d , &a, &b); n       d[b] = max(a, d[b]); n     } n     for (int i = n; i >= 0; i--) d[i] = max(d[i + 1], d[i]); n     int ans = 0; n     for (int i = 1; i <= n;) { n       if (mon[i] > d[1]) { n         cout <<  -1  << endl; n         goto brk; n       } n       int j = 0; n       int MX = 0; n       for (; j <= n; j++) { n         MX = max(MX, mon[i + j]); n         if (d[j + 1] < MX) break; n       } n       ans++; n       i += j; n     } n     cout << ans << endl; n   brk:; n     for (int i = 0; i <= n; i++) d[i] = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, n, max_gcd = 1; n   cin >> t; n   while (t--) { n     cin >> n; n     cout << n / 2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long iinf = 1e18; n const int inf = 1e9 + 10; n const int MOD = (1e6 + 3); n int dir4[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; n int knight[8][2] = {{2, 1}, {2, -1}, {-2, 1}, {-2, -1}, n                     {1, 2}, {-1, 2}, {1, -2}, {-1, -2}}; n using namespace std; n void solve() { n   int n; n   cin >> n; n   int ans = 1; n   for (int i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       ans = i; n       break; n     } n   } n   if (ans == 1) { n     cout << 1 <<     << n - 1 <<   n ; n     return; n   } n   int a = n / ans; n   cout << a <<     << (ans - 1) * a <<   n ; n } n int main() { n   int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n bool a = true; n int main() { n   scanf( %d%d , &n, &m); n   int arr[m]; n   if (m % 2 == 0) { n     arr[0] = (m) / 2; n     for (int i = 1; i < m; i++) { n       if (!a) { n         arr[i] = arr[i - 1] - i; n         a = !a; n       } else { n         arr[i] = arr[i - 1] + i; n         a = !a; n       } n     } n   } else { n     arr[0] = (m + 1) / 2; n     for (int i = 1; i < m; i++) { n       if (!a) { n         arr[i] = arr[i - 1] + i; n         a = !a; n       } else { n         arr[i] = arr[i - 1] - i; n         a = !a; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     printf( %d n , arr[i % m]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   map<int, int> mp; n   map<int, int> np; n   for (int i = 1; i <= n; i++) { n     int x, y; n     cin >> x >> y; n     int p = y - x; n     int q = y + x; n     mp[p]++; n     np[q]++; n   } n   map<int, int>::iterator it; n   int box = 0; n   for (it = mp.begin(); it != mp.end(); it++) { n     int g = it->second; n     box += (g * (g - 1)) / 2; n   } n   for (it = np.begin(); it != np.end(); it++) { n     int g = it->second; n     box += (g * (g - 1)) / 2; n   } n   cout << box << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > vc; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long N, M, x, y, z, p, i, X, Y, j, lplp1, lplp2; n   cin >> N >> M >> x >> y >> z >> p; n   long long opop1 = x % 4; n   long long opop2 = y % 2; n   long long opop3 = z % 4; n   for (i = 1; i <= p; i++) { n     cin >> X >> Y; n     vc.push_back(make_pair(X, Y)); n   } n   for (i = 1; i <= opop1; i++) { n     for (j = 0; j <= (int)vc.size() - 1; j++) { n       lplp1 = vc[j].first; n       lplp2 = vc[j].second; n       vc[j].first = vc[j].second; n       vc[j].second = N - lplp1 + 1; n     } n     swap(N, M); n   } n   for (i = 1; i <= opop2; i++) { n     for (j = 0; j <= (int)vc.size() - 1; j++) { n       lplp1 = vc[j].first; n       lplp2 = vc[j].second; n       vc[j].second = M - lplp2 + 1; n     } n   } n   for (i = 1; i <= opop3; i++) { n     for (j = 0; j <= (int)vc.size() - 1; j++) { n       lplp1 = vc[j].first; n       lplp2 = vc[j].second; n       vc[j].first = M - lplp2 + 1; n       vc[j].second = lplp1; n     } n     swap(N, M); n   } n   for (i = 0; i <= (int)vc.size() - 1; i++) { n     cout << vc[i].first <<     << vc[i].second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int solve(int m, int n) { n   if (m == 1 || n == 1) return m * n; n   if (m == 2 || n == 2) { n     if (m < n) { n       m = n; n       n = 2; n     } n     if (m % 4 == 0) n       return m; n     else if (m % 4 == 1) n       return m + 1; n     else if (m % 4 == 2) n       return m + 2; n     else n       return m + 1; n   } n   if (m % 2 == 1 && n % 2 == 1) return m * n / 2 + 1; n   return m * n / 2; n } n int main() { n   int m, n; n   scanf( %d %d , &m, &n); n   printf( %d , solve(m, n)); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  { ; n   string sep; n   for (const auto &x : v) os << sep << x, sep =  ,  ; n   return os <<  } ; n } n template <typename A, typename B> n ostream &operator<<(ostream &os, const pair<A, B> &p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n void dbg_out() { cerr << endl; } n template <typename Head, typename... Tail> n void dbg_out(Head H, Tail... T) { n   cerr <<     << H; n   dbg_out(T...); n } n template <const unsigned &MOD> n struct _m_uint { n   unsigned val; n   _m_uint(int64_t v = 0) { n     if (v < 0) v = v % MOD + MOD; n     if (v >= MOD) v %= MOD; n     val = v; n   } n   static unsigned inv_mod(unsigned a, unsigned m = MOD) { n     unsigned g = m, r = a, x = 0, y = 1; n     int sign = -1; n     while (r != 0) { n       unsigned q = g / r; n       g %= r; n       swap(g, r); n       x += q * y; n       swap(x, y); n       sign = -sign; n     } n     return sign > 0 ? x : m - x; n   } n   explicit operator unsigned() const { return val; } n   explicit operator uint64_t() const { return val; } n   _m_uint &operator+=(const _m_uint &other) { n     val = val < MOD - other.val ? val + other.val : val - (MOD - other.val); n     return *this; n   } n   _m_uint &operator-=(const _m_uint &other) { n     val = val < other.val ? val + (MOD - other.val) : val - other.val; n     return *this; n   } n   static unsigned fast_mod(uint64_t x, unsigned m = MOD) { n     return x % m; n     unsigned x_high = x >> 32, x_low = (unsigned)x; n     unsigned quot, rem; n     asm( divl %4 n  :  =a (quot),  =d (rem) :  d (x_high),  a (x_low),  r (m)); n     return rem; n   } n   _m_uint &operator*=(const _m_uint &other) { n     val = fast_mod((uint64_t)val * other.val); n     return *this; n   } n   _m_uint &operator/=(const _m_uint &other) { return *this *= other.inv(); } n   friend _m_uint operator+(const _m_uint &a, const _m_uint &b) { n     return _m_uint(a) += b; n   } n   friend _m_uint operator-(const _m_uint &a, const _m_uint &b) { n     return _m_uint(a) -= b; n   } n   friend _m_uint operator*(const _m_uint &a, const _m_uint &b) { n     return _m_uint(a) *= b; n   } n   friend _m_uint operator/(const _m_uint &a, const _m_uint &b) { n     return _m_uint(a) /= b; n   } n   _m_uint &operator++() { n     val = val == MOD - 1 ? 0 : val + 1; n     return *this; n   } n   _m_uint &operator--() { n     val = val == 0 ? MOD - 1 : val - 1; n     return *this; n   } n   _m_uint operator++(int) { n     _m_uint before = *this; n     ++*this; n     return before; n   } n   _m_uint operator--(int) { n     _m_uint before = *this; n     --*this; n     return before; n   } n   _m_uint operator-() const { return val == 0 ? 0 : MOD - val; } n   bool operator==(const _m_uint &other) const { return val == other.val; } n   bool operator!=(const _m_uint &other) const { return val != other.val; } n   _m_uint inv() const { return inv_mod(val); } n   _m_uint pow(int64_t p) const { n     if (p < 0) return inv().pow(-p); n     _m_uint a = *this, result = 1; n     while (p > 0) { n       if (p & 1) result *= a; n       a *= a; n       p >>= 1; n     } n     return result; n   } n   friend ostream &operator<<(ostream &os, const _m_uint &m) { n     return os << m.val; n   } n }; n auto random_address = [] { n   char *p = new char; n   delete p; n   return (uint64_t)p; n }; n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * n                (random_address() | 1)); n extern const unsigned HASH_P = (unsigned)-13337; n using hash_int = _m_uint<HASH_P>; n const uint64_t HASH_P2 = (uint64_t)HASH_P * HASH_P; n const int HASH_COUNT = 2; n uniform_int_distribution<unsigned> MULT_DIST(0.1 * HASH_P, 0.9 * HASH_P); n const hash_int HASH_MULT[HASH_COUNT] = {MULT_DIST(rng), MULT_DIST(rng)}; n const hash_int HASH_INV[HASH_COUNT] = {1 / HASH_MULT[0], 1 / HASH_MULT[1]}; n vector<hash_int> hash_pow[HASH_COUNT] = {{1}, {1}}; n const int INF = 1e9 + 5; n template <typename T_string = string> n struct string_hash { n   static const bool BUILD_REVERSE = false; n   T_string str; n   vector<hash_int> _prefix_hash[HASH_COUNT]; n   vector<hash_int> _prefix_inv_hash[HASH_COUNT]; n   string_hash() { build({}); } n   string_hash(const T_string &_str) { build(_str); } n   int length() const { return (int)_prefix_hash[0].size() - 1; } n   template <typename T_char> n   void add_char(const T_char &c) { n     str.push_back(c); n     for (int h = 0; h < HASH_COUNT; h++) { n       _prefix_hash[h].push_back(HASH_MULT[h] * _prefix_hash[h].back() + c); n       if (hash_pow[h].size() < _prefix_hash[h].size()) n         hash_pow[h].push_back(HASH_MULT[h] * hash_pow[h].back()); n       if (BUILD_REVERSE) n         _prefix_inv_hash[h].push_back((_prefix_inv_hash[h].back() + c) * n                                       HASH_INV[h]); n     } n   } n   void pop_char() { n     str.pop_back(); n     for (int h = 0; h < HASH_COUNT; h++) { n       _prefix_hash[h].pop_back(); n       if (BUILD_REVERSE) _prefix_inv_hash[h].pop_back(); n     } n   } n   void build(const T_string &_str) { n     str = {}; n     for (int h = 0; h < HASH_COUNT; h++) { n       _prefix_hash[h] = {0}; n       if (BUILD_REVERSE) _prefix_inv_hash[h] = {0}; n     } n     for (auto &c : _str) add_char(c); n   } n   uint64_t _single_hash(int h, int start, int end) const { n     uint64_t power = (uint64_t)hash_pow[h][end - start]; n     return (power + (uint64_t)_prefix_hash[h][end] + HASH_P2 - n             (uint64_t)_prefix_hash[h][start] * power) % n            HASH_P; n   } n   uint64_t substring_hash(int start, int end) const { n     assert(0 <= start && start <= end && end <= length()); n     return _single_hash(0, start, end) + n            (HASH_COUNT > 1 ? _single_hash(1, start, end) << 32 : 0); n   } n   uint64_t _reverse_single_hash(int h, int start, int end) const { n     uint64_t power = (uint64_t)hash_pow[h][end - start]; n     return (power + (uint64_t)_prefix_inv_hash[h][end] * power + HASH_P - n             (uint64_t)_prefix_inv_hash[h][start]) % n            HASH_P; n   } n   uint64_t reverse_substring_hash(int start, int end) const { n     assert(0 <= start && start <= end && end <= length()); n     return _reverse_single_hash(0, start, end) + n            (HASH_COUNT > 1 ? _reverse_single_hash(1, start, end) << 32 : 0); n   } n   bool equal(int start1, int start2, int length) const { n     return substring_hash(start1, start1 + length) == n            substring_hash(start2, start2 + length); n   } n   bool is_palindrome(int start, int end) const { n     return substring_hash(start, end) == reverse_substring_hash(start, end); n   } n   int compare(int start1, int start2, int max_length = INF) const; n }; n template <typename T_string> n int first_mismatch(const string_hash<T_string> &hash1, int start1, n                    const string_hash<T_string> &hash2, int start2, n                    int max_length = INF) { n   max_length = n       min({max_length, hash1.length() - start1, hash2.length() - start2}); n   static const int FIRST = 5; n   int first = min(max_length, FIRST); n   for (int i = 0; i < first; i++) n     if (hash1.str[start1 + i] != hash2.str[start2 + i]) return i; n   if (hash1.substring_hash(start1, start1 + max_length) == n       hash2.substring_hash(start2, start2 + max_length)) n     return max_length; n   static const int MANUAL = 15; n   int low = first, high = max_length - 1; n   while (high - low > MANUAL) { n     int mid = (low + high + 1) / 2; n     if (hash1.substring_hash(start1, start1 + mid) == n         hash2.substring_hash(start2, start2 + mid)) n       low = mid; n     else n       high = mid - 1; n   } n   for (int i = low; i < high; i++) n     if (hash1.str[start1 + i] != hash2.str[start2 + i]) return i; n   return high; n } n template <typename T_string> n int hash_compare(const string_hash<T_string> &hash1, int start1, n                  const string_hash<T_string> &hash2, int start2, n                  int max_length = INF) { n   int mismatch = first_mismatch(hash1, start1, hash2, start2, max_length); n   int length1 = min(hash1.length() - start1, max_length); n   int length2 = min(hash2.length() - start2, max_length); n   if (mismatch == min(length1, length2)) n     return length1 == length2 ? 0 : (length1 < length2 ? -1 : +1); n   if (hash1.str[start1 + mismatch] == hash2.str[start2 + mismatch]) return 0; n   return hash1.str[start1 + mismatch] < hash2.str[start2 + mismatch] ? -1 : +1; n } n template <typename T_string> n int string_hash<T_string>::compare(int start1, int start2, n                                    int max_length) const { n   return hash_compare(*this, start1, *this, start2, max_length); n } n using seq_hash = string_hash<vector<int>>; n int N, bucket_size, n_buckets; n vector<int> S; n vector<bool> invalid_bucket; n vector<seq_hash> bucket_prefix, bucket_suffix; n int which_bucket(int index) { n   return index < N ? index / bucket_size : n_buckets; n } n int get_bucket_start(int b) { return bucket_size * b; } n int get_bucket_end(int b) { return min(bucket_size * (b + 1), N); } n vector<int> process_stack(int start, int end) { n   vector<int> stack; n   for (int i = start; i < end; i++) n     if (!stack.empty() && stack.back() > 0 && S[i] == -stack.back()) n       stack.pop_back(); n     else n       stack.push_back(S[i]); n   return stack; n } n void build_bucket(int b) { n   assert(0 <= b && b < n_buckets); n   int bucket_start = get_bucket_start(b); n   int bucket_end = get_bucket_end(b); n   vector<int> stack = process_stack(bucket_start, bucket_end); n   int size = stack.size(); n   int prefix = 0, suffix = size; n   while (prefix < size && stack[prefix] < 0) prefix++; n   while (suffix > 0 && stack[suffix - 1] > 0) suffix--; n   if (prefix != suffix) { n     invalid_bucket[b] = true; n     return; n   } n   invalid_bucket[b] = false; n   bucket_prefix[b] = {}; n   for (int i = prefix - 1; i >= 0; i--) n     bucket_prefix[b].add_char(abs(stack[i])); n   bucket_suffix[b] = {}; n   for (int i = suffix; i < size; i++) bucket_suffix[b].add_char(stack[i]); n } n void init_buckets() { n   bucket_size = sqrt(N) + 1; n   n_buckets = (N + bucket_size - 1) / bucket_size; n   invalid_bucket.assign(n_buckets, false); n   bucket_prefix.assign(n_buckets, {}); n   bucket_suffix.assign(n_buckets, {}); n   for (int b = 0; b < n_buckets; b++) build_bucket(b); n } n void update(int index, int change) { n   assert(0 <= index && index < N); n   S[index] = change; n   build_bucket(which_bucket(index)); n } n struct range { n   const seq_hash *hasher = nullptr; n   int start = 0, end = 0; n   range() {} n   range(const seq_hash &_hasher, int _start, int _end) n       : hasher(&_hasher), start(_start), end(_end) {} n   int length() const { return end - start; } n }; n bool query(int start, int end) { n   assert(0 <= start && start <= end && end <= N); n   int start_b = which_bucket(start), end_b = which_bucket(end); n   if (start_b == end_b) return process_stack(start, end).empty(); n   vector<range> ranges; n   vector<int> stack = process_stack(start, get_bucket_end(start_b)); n   ; n   for (int x : stack) n     if (x < 0) return false; n   seq_hash start_hasher(stack); n   ranges.emplace_back(start_hasher, 0, start_hasher.length()); n   for (int b = start_b + 1; b < end_b; b++) { n     if (invalid_bucket[b]) return false; n     ; n     int prefix_end = bucket_prefix[b].length(); n     while (prefix_end > 0) { n       if (ranges.empty()) return false; n       range &back = ranges.back(); n       int take = min(prefix_end, back.length()); n       uint64_t prefix_hash = n           bucket_prefix[b].substring_hash(prefix_end - take, prefix_end); n       uint64_t range_hash = n           back.hasher->substring_hash(back.end - take, back.end); n       if (prefix_hash != range_hash) return false; n       prefix_end -= take; n       back.end -= take; n       if (back.length() == 0) ranges.pop_back(); n     } n     assert(prefix_end == 0); n     ranges.emplace_back(bucket_suffix[b], 0, bucket_suffix[b].length()); n   } n   stack = process_stack(get_bucket_start(end_b), end); n   ; n   for (int x : stack) n     if (x > 0) return false; n   for (int x : stack) { n     while (!ranges.empty() && ranges.back().length() == 0) ranges.pop_back(); n     if (ranges.empty()) return false; n     range &back = ranges.back(); n     if (back.hasher->str[back.end - 1] != abs(x)) return false; n     back.end--; n   } n   while (!ranges.empty() && ranges.back().length() == 0) ranges.pop_back(); n   return ranges.empty(); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int _; n   cin >> N >> _; n   S.resize(N); n   for (auto &s : S) cin >> s; n   init_buckets(); n   int Q; n   cin >> Q; n   for (int q = 0; q < Q; q++) { n     int type; n     cin >> type; n     if (type == 1) { n       int index, t; n       cin >> index >> t; n       index--; n       update(index, t); n     } else if (type == 2) { n       int L, R; n       cin >> L >> R; n       L--; n       cout << (query(L, R) ?  Yes  :  No ) <<   n ; n     } else { n       assert(false); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, kov = 1; n int t[502][502]; n void ert(int a, int b) { t[a][b] = kov, kov++; } n int main() { n   cin >> n; n   if (n <= 2) { n     cout << -1 <<   n ; n     return 0; n   } n   if (n == 3) { n     cout << 1 <<     << 3 <<     << 2 <<   n ; n     cout << 5 <<     << 4 <<     << 8 <<   n ; n     cout << 9 <<     << 6 <<     << 7 <<   n ; n     return 0; n   } n   for (int i = n - 3; i >= 1; i--) ert(i, n); n   for (int i = 1; i <= n - 1; i++) { n     for (int j = 1; j <= n - 1; j++) { n       if (i % 2 == n % 2) n         ert(i, n - j); n       else n         ert(i, j); n     } n   } n   t[n - 2][n] = n * n, t[n][n] = n * n - 1; n   ert(n, n - 2), ert(n, n - 1), ert(n - 1, n); n   for (int i = 1; i <= n - 3; i++) ert(n, i); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cout << t[i][j] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   long long int len = s.length(); n   long long int cnt = 0; n   for (long long int i = 0; i < len; i++) { n     if (s[i] ==  Q ) { n       cnt++; n     } n   } n   long long int suffixes = cnt; n   long long int prefixes = 0; n   long long int ans = 0; n   for (long long int j = 0; j < len; j++) { n     if (s[j] ==  Q ) { n       prefixes++; n       suffixes--; n     } n     if (s[j] ==  A ) { n       ans += prefixes * suffixes; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m, i, a, b, sum = 0; n   cin >> n >> m; n   long long arr[n + 1]; n   for (i = 1; i <= n; i++) { n     cin >> arr[i]; n   } n   for (i = 0; i < m; i++) { n     cin >> a >> b; n     sum += min(arr[a], arr[b]); n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace perfectGroups { n const int mx = 5001; n int arr[mx], ans[mx], previous[mx], dp[5001][5001], zero[mx]; n int transNumber(int num) { n   int temp = abs(num), rt = sqrt(temp), ret = 1; n   for (int i = 2; i <= rt; i++) { n     int cnt = 0; n     while (temp > 1 && temp % i == 0) { n       cnt++; n       temp = temp / i; n     } n     if (cnt & 1) ret = ret * i; n   } n   if (temp > 1 || temp == 0) ret = ret * temp; n   return ret * (num > 0 ? 1 : -1); n } n void mapTheArray(int *n) { n   for (int i = 1; i <= *n; i++) { n     zero[i] = zero[i - 1] + (arr[i] == 0); n   } n   map<int, int> maping; n   for (int i = 1, idx = 0; i <= *n; i++) { n     if (maping.find(arr[i]) == maping.end()) { n       arr[i] = maping[arr[i]] = ++idx; n     } else { n       arr[i] = maping[arr[i]]; n     } n   } n   for (int i = 1; i <= *n; i++) { n     int pre = previous[arr[i]]; n     previous[arr[i]] = i; n     arr[i] = pre; n   } n } n void dpTable(int *n) { n   for (int i = 1; i <= *n; i++) { n     for (int j = 1; j + i - 1 <= *n; j++) { n       int l = i, r = i + j - 1; n       if (arr[r] < l) n         dp[l][r] = dp[l][r - 1] + 1; n       else n         dp[l][r] = dp[l][r - 1]; n     } n   } n   for (int i = 1; i <= *n; i++) { n     for (int j = i; j <= *n; j++) { n       int id = zero[j] - zero[i - 1]; n       if (id >= 1 && dp[i][j] > 1) dp[i][j]--; n       ans[dp[i][j]]++; n     } n   } n } n void solve() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &arr[i]); n     arr[i] = transNumber(arr[i]); n   } n   mapTheArray(&n); n   dpTable(&n); n   for (int i = 1; i <= n; i++) { n     printf( %d  , ans[i]); n     if (i == n) puts(  ); n   } n } n }  // namespace perfectGroups n int main() { n   perfectGroups::solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:60777216 ) n using namespace std; n int d[10]; n int c[107][107]; n long long dp[107][17]; n long long solve(int len, int pos) { n   if (pos == 9) { n     if (len >= d[9]) { n       return 1; n     } n     return 0; n   } n   if (dp[len][pos] != -1) { n     return dp[len][pos]; n   } n   dp[len][pos] = 0; n   if (pos == 0) { n     for (int j = d[pos]; j <= len; ++j) { n       dp[len][pos] += solve(len - j, pos + 1) * c[len - 1][j] % 1000000007; n       if (dp[len][pos] >= 1000000007) dp[len][pos] -= 1000000007; n     } n   } else { n     for (int j = d[pos]; j <= len; ++j) { n       dp[len][pos] += solve(len - j, pos + 1) * c[len][j] % 1000000007; n       if (dp[len][pos] >= 1000000007) dp[len][pos] -= 1000000007; n     } n   } n   return dp[len][pos]; n } n int main() { n   c[0][0] = 1; n   c[1][1] = 1; n   c[1][0] = 1; n   for (int i = 2; i <= 100; ++i) { n     c[i][i] = 1; n     c[i][0] = 1; n     for (int j = 1; j < i; ++j) { n       c[i][j] = c[i - 1][j] + c[i - 1][j - 1]; n       if (c[i][j] >= 1000000007) c[i][j] -= 1000000007; n     } n   } n   long long ans = 0; n   memset(dp, -1, sizeof(dp)); n   int len; n   scanf( %d , &len); n   for (int i = 0; i < 10; ++i) { n     scanf( %d , d + i); n   } n   for (int i = 1; i <= len; ++i) { n     ans += solve(i, 0); n     if (ans >= 1000000007) ans -= 1000000007; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005; n using ll = long long; n map<ll, int> dd; n map<pair<int, int>, int> f; n int n, pre[3][N]; n ll a[3][N]; n int dfs(int n, int m) { n   if (pre[1][n] == -1 && pre[2][m] == -1 && pre[0][min(n, m)] == -1) return 0; n   pair<int, int> p{n, m}; n   if (f.count(p)) return f[p]; n   int ans = 0; n   if (pre[1][n] > pre[2][m]) n     ans = max(ans, dfs(pre[1][n], m) + 1); n   else if (pre[2][m] != -1) n     ans = max(ans, dfs(n, pre[2][m]) + 1); n   if (pre[0][min(n, m)] != -1) n     ans = max(ans, dfs(pre[0][min(n, m)], pre[0][min(n, m)]) + 1); n   return f[p] = ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int j = 1; j <= 2; j++) n     for (int i = 1; i <= n; i++) cin >> a[j][i], a[0][i] += a[j][i]; n   for (int i = 0; i <= 2; i++) n     for (int j = 1; j <= n; j++) a[i][j] += a[i][j - 1]; n   for (int i = 0; i <= 2; i++) { n     dd.clear(); n     dd[0] = 0; n     pre[i][0] = -1; n     for (int j = 1; j <= n; j++) { n       pre[i][j] = max(pre[i][j - 1], dd.count(a[i][j]) ? dd[a[i][j]] : -1); n       dd[a[i][j]] = j; n     } n   } n   cout << dfs(n, n) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n long long c[1010][1010]; n const int mod = 1e9 + 7; n void pre() { n   for (int i = 0; i <= 1005; i++) { n     c[i][0] = c[i][i] = 1; n   } n   for (int i = 1; i <= 1005; i++) { n     for (int j = 0; j <= i; j++) { n       c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; n       ; n     } n   } n } n int main(int argc, char const *argv[]) { n   scanf( %d%d%d , &n, &m, &k); n   pre(); n   if (2 * k > n - 1 || 2 * k > m - 1) { n     printf( 0 ); n   } else { n     printf( %lld n , c[n - 1][k * 2] * c[m - 1][k * 2] % mod); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr long long MOD = 1e9 + 7; n long long cnt[710][710]; n int a[500100]; n int main() { n   int n; n   scanf( %d , &n); n   for (int ii = 0; ii < n; ++ii) { n     int t, x, y; n     scanf( %d%d%d , &t, &x, &y); n     if (t == 1) { n       a[x] += y; n       for (int i = 1; i <= 700; ++i) { n         cnt[i][x % i] += y; n       } n     } else { n       long long ans = 0; n       if (x > 700) { n         for (int i = y % x; i <= 500000; i += x) { n           ans += a[i]; n         } n       } else { n         ans = cnt[x][y % x]; n       } n       printf( %I64lld n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int MAXN = 3e5 + 5; n constexpr int MAXW = 1e4 + 5; n constexpr int MOD = 998244353; n constexpr long long INF = 2e10; n constexpr int LOG = 11; n string s; n vector<int> ans; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> s; n   reverse(s.begin(), s.end()); n   while (!s.empty()) { n     if (s.back() ==  . ) { n       ans.push_back(0); n       s.pop_back(); n     } else { n       s.pop_back(); n       if (s.back() ==  - ) { n         ans.push_back(2); n       } else { n         ans.push_back(1); n       } n       s.pop_back(); n     } n   } n   for (auto p : ans) { n     cout << p; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); n const ld pi = acos(0) * 2; n template <typename T> n inline void read(T &x) { n   char c; n   bool nega = 0; n   while ((!isdigit(c = getchar())) && (c !=  - )) n     ; n   if (c ==  - ) { n     nega = 1; n     c = getchar(); n   } n   x = c - 48; n   while (isdigit(c = getchar())) x = x * 10 + c - 48; n   if (nega) x = -x; n } n template <typename T> n inline void writep(T x) { n   if (x > 9) writep(x / 10); n   putchar(x % 10 + 48); n } n template <typename T> n inline void write(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   writep(x); n } n template <typename T> n inline void writeln(T x) { n   write(x); n   putchar(  n ); n } n template <typename CT, typename T> n inline void reset_container(CT &c, int sz, T v) { n   c.resize(sz); n   for (auto &x : c) x = v; n } n int n, k; n int a[101]; n void solve() { n   read(n); n   read(k); n   for (int i = (1); i <= (n); i++) read(a[i]); n   sort(a + 1, a + n + 1); n   if (a[n] - k > a[1] + k) n     puts( -1 ); n   else n     writeln(a[1] + k); n } n int main() { n   int q; n   read(q); n   while (q--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n vector<bool> trust; n vector<int> massive(int** mas, int num) { n   vector<int> mase; n   int nume = num; n   int nume1; n   while (nume != 0) { n     nume1 = nume; n     nume = mas[nume - 1][0]; n   } n   mase.push_back(0); n   while (nume1 != 0) { n     mase.push_back(nume1); n     trust[nume1 - 1] = true; n     nume1 = mas[nume1 - 1][1]; n   } n   mase.push_back(0); n   return mase; n } n int main() { n   int n; n   cin >> n; n   int** mas = new int*[n]; n   for (int i = 0; i < n; i++) { n     mas[i] = new int[2]; n     trust.push_back(false); n     cin >> mas[i][0] >> mas[i][1]; n   } n   vector<vector<int>> comp; n   for (int i = 0; i < n; i++) { n     vector<int> vect2; n     if (!trust[i]) { n       vect2 = massive(mas, i + 1); n       comp.push_back(vect2); n     } n   } n   vector<int> ansver; n   ansver.push_back(0); n   for (auto i : comp) { n     for (auto j : i) { n       if (j != 0) { n         ansver.push_back(j); n       } n     } n   } n   ansver.push_back(0); n   for (int i = 1; i < n + 1; i++) { n     for (int j = 0; j < ansver.size(); j++) { n       if (i == ansver[j]) { n         cout << ansver[j - 1] <<     << ansver[j + 1]; n       } n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int MX = 2e2 + 5; n const long long INF = 1e18; n const long double PI = 4 * atan((long double)1); n const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n namespace io { n void setIn(string second) { freopen(second.c_str(),  r , stdin); } n void setOut(string second) { freopen(second.c_str(),  w , stdout); } n void setIO(string second =   ) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   if ((int)second.size()) { n     setIn(second +  .in ); n     setOut(second +  .out ); n   } n } n }  // namespace io n using namespace io; n namespace input { n template <class T> n void re(complex<T>& x); n template <class T1, class T2> n void re(pair<T1, T2>& p); n template <class T> n void re(vector<T>& a); n template <class T, size_t SZ> n void re(array<T, SZ>& a); n template <class T> n void re(T& x) { n   cin >> x; n } n void re(double& x) { n   string t; n   re(t); n   x = stod(t); n } n void re(long double& x) { n   string t; n   re(t); n   x = stold(t); n } n template <class Arg, class... Args> n void re(Arg& first, Args&... rest) { n   re(first); n   re(rest...); n } n template <class T> n void re(complex<T>& x) { n   T a, b; n   re(a, b); n   x = cd(a, b); n } n template <class T1, class T2> n void re(pair<T1, T2>& p) { n   re(p.first, p.second); n } n template <class T> n void re(vector<T>& a) { n   for (int i = (0); i < ((int)a.size()); ++i) re(a[i]); n } n template <class T, size_t SZ> n void re(array<T, SZ>& a) { n   for (int i = (0); i < (SZ); ++i) re(a[i]); n } n }  // namespace input n namespace output { n template <class T1, class T2> n void pr(const pair<T1, T2>& x); n template <class T, size_t SZ> n void pr(const array<T, SZ>& x); n template <class T> n void pr(const vector<T>& x); n template <class T> n void pr(const set<T>& x); n template <class T1, class T2> n void pr(const map<T1, T2>& x); n template <class T> n void pr(const T& x) { n   cout << x; n } n template <class Arg, class... Args> n void pr(const Arg& first, const Args&... rest) { n   pr(first); n   pr(rest...); n } n template <class T1, class T2> n void pr(const pair<T1, T2>& x) { n   pr( { , x.first,  ,  , x.second,  } ); n } n template <class T> n void prContain(const T& x) { n   pr( { ); n   bool fst = 1; n   for (const auto& a : x) pr(!fst ?  ,   :   , a), fst = 0; n   pr( } ); n } n template <class T, size_t SZ> n void pr(const array<T, SZ>& x) { n   prContain(x); n } n template <class T> n void pr(const vector<T>& x) { n   prContain(x); n } n template <class T> n void pr(const set<T>& x) { n   prContain(x); n } n template <class T1, class T2> n void pr(const map<T1, T2>& x) { n   prContain(x); n } n void ps() { pr(  n ); } n template <class Arg> n void ps(const Arg& first) { n   pr(first); n   ps(); n } n template <class Arg, class... Args> n void ps(const Arg& first, const Args&... rest) { n   pr(first,    ); n   ps(rest...); n } n }  // namespace output n using namespace output; n using namespace input; n long long add(long long a, long long b) { n   a += b; n   if (a >= MOD) { n     a -= MOD; n   } n   return a; n } n long long sub(long long a, long long b) { n   a -= b; n   if (a < 0) { n     a += MOD; n   } n   return a; n } n long long mul(long long a, long long b) { return (a * b) % MOD; } n void add_self(long long& a, long long b) { a = add(a, b); } n void sub_self(long long& a, long long b) { a = sub(a, b); } n void mul_self(long long& a, long long b) { a = mul(a, b); } n int main() { n   setIO(); n   long long t; n   re(t); n   for (int ii = (0); ii < (t); ++ii) { n     long long N, W; n     re(N, W); n     vector<long long> v; n     for (int i = (0); i < (N); ++i) { n       long long a; n       re(a); n       v.push_back(a); n     } n     bool done = false; n     for (int i = (0); i < ((int)v.size()); ++i) { n       if (v[i] >= (W + 1) / 2 && v[i] <= W) { n         ps(1); n         ps(i + 1); n         done = true; n         break; n       } n     } n     if (done) { n       continue; n     } n     long long lind = -1; n     long long cs = 0; n     long long ignore = 0; n     for (int i = (0); i < ((int)v.size()); ++i) { n       if (v[i] > W) { n         ignore++; n         continue; n       } n       cs += v[i]; n       if (cs >= (W + 1) / 2 && cs <= W) { n         lind = i; n         break; n       } n     } n     if (lind == -1) { n       ps(-1); n       continue; n     } n     ps(lind + 1 - ignore); n     for (int i = (0); i < (lind + 1); ++i) { n       if (v[i] > W) { n         continue; n       } n       cout << i + 1 <<    ; n     } n     ps(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, i, j; n   cin >> n >> m; n   for (i = 1; i <= n; i++) { n     for (j = 0; j < m; j++) { n       if (i % 4 == 0) { n         if (j == 0) n           cout <<  # ; n         else n           cout <<  . ; n       } else if (i % 4 == 2) { n         if (j == m - 1) n           cout <<  # ; n         else n           cout <<  . ; n       } else n         cout <<  # ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 1e6 + 5; n long long n, m, i, t, j, k, l, x, y, z, s, e, p, q; n long long dg(long long s, long long e) { n   if (e % 2) return 1 - s % 2; n   if (s > e / 2) return s % 2; n   if (s > e / 4) return 1; n   return dg(s, e / 4); n } n int main() { n   scanf( %lld , &n); n   p = 0; n   q = 1; n   for (int i = 1; i <= n; i++) { n     scanf( %lld%lld , &s, &e); n     x = dg(s, e); n     if (s > e / 2) n       y = 1; n     else n       y = dg(s, e / 2); n     if (p + q != 1) n       continue; n     else if (p) n       p = 1 - x, q = 1 - y; n     else n       p = x, q = y; n   } n   printf( %lld %lld n , p, q); n } n


#include <bits/stdc++.h> n using namespace std; n char s[5005]; n int n, dp[5005][5]; n const int inf = 1e7 + 5; n int go(int id, int need) { n   if (id == n) return 0; n   if (dp[id][need] != -1) return dp[id][need]; n   int ans = 0; n   if (need == 1) { n     if (s[id] ==  a ) n       ans = max(1 + go(id + 1, 1), 1 + go(id + 1, 2)); n     else n       ans = max(go(id, 2), go(id + 1, 1)); n   } else if (need == 2) { n     if (s[id] ==  a ) n       ans = max(go(id, 3), go(id + 1, 2)); n     else n       ans = max(1 + go(id + 1, 2), 1 + go(id + 1, 3)); n   } else { n     if (s[id] ==  a ) n       ans = 1 + go(id + 1, 3); n     else n       ans = go(id + 1, 3); n   } n   return dp[id][need] = ans; n } n int main() { n   scanf(  %s , s); n   n = strlen(s); n   memset(dp, -1, sizeof(dp)); n   printf( %d n , go(0, 1)); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200; n typedef long long matrix[N][N]; n const long long MOD = 1000000007; n const double EPS = 1e-8; n const double PI = 2 * acos(0); n const int maxn = 1e6 + 6; n int main() { n   cin.sync_with_stdio(false); n   int n, ans = 0, a[100100], p[100100]; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i] >> p[i]; n   int i = 1; n   while (i <= n) { n     ans += a[i] * p[i]; n     for (int j = i + 1; j <= n; j++) { n       if (p[j] < p[i]) { n         i = j - 1; n         break; n       } n       ans += a[j] * p[i]; n       if (j == n) i = n; n     } n     i++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long n, m; n vector<string> pref; n long mov[500][500]; n string temp; n string inp[500]; n long er, td; n long bst[2000]; n string tst; n long dp[4][500][500]; n long nend, t, ncvrd, answ; n void ad(long &a, long b) { n   a += b; n   if (a >= 1000000009) a -= 1000000009; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     cin >> inp[i]; n     for (int j = 0; j < inp[i].size(); j++) inp[i][j] = inp[i][j] -  A  +  a ; n   } n   pref.push_back(  ); n   for (int i = 1; i <= m; i++) { n     temp =   ; n     for (int j = 0; j < inp[i].size(); j++) { n       temp += inp[i][j]; n       pref.push_back(temp); n     } n   } n   for (int i = 0; i < pref.size(); i++) { n     bst[i] = -1; n     for (int j = 1; j <= m; j++) { n       if (inp[j].size() > pref[i].size()) continue; n       er = 0; n       if (bst[i] >= 0 && inp[j].size() <= inp[bst[i]].size()) continue; n       td = pref[i].size() - inp[j].size(); n       for (int q = 0; q < inp[j].size(); q++) n         if (pref[i][q + td] != inp[j][q]) { n           er = 1; n           break; n         } n       if (er == 0) bst[i] = j; n     } n   } n   for (int i = 0; i < pref.size(); i++) n     for (int ad = 0; ad < 26; ad++) { n       mov[i][ad] = -1; n       tst = pref[i]; n       tst += char( a  + ad); n       for (int j = 0; j < pref.size(); j++) { n         if (pref[j].size() > tst.size()) continue; n         er = 0; n         td = tst.size() - pref[j].size(); n         if (mov[i][ad] != -1 && pref[mov[i][ad]].size() > pref[j].size()) n           continue; n         for (int q = 0; q < pref[j].size(); q++) n           if (pref[j][q] != tst[td + q]) { n             er = 1; n             break; n           } n         if (er == 0) mov[i][ad] = j; n       } n     } n   dp[0][0][0] = 1; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j <= pref.size(); j++) n       for (int q = 0; q <= i; q++) dp[1 - i % 2][j][q] = 0; n     for (int end = 0; end < pref.size(); end++) n       for (int cvrd = 0; cvrd <= i; cvrd++) n         if (cvrd >= i - 25) n           if (dp[i % 2][end][cvrd]) n             for (int achar = 0; achar < 26; achar++) { n               nend = mov[end][achar]; n               t = bst[nend]; n               if (t > -1 && inp[t].size() + cvrd > i) n                 ncvrd = i + 1; n               else n                 ncvrd = cvrd; n               ad(dp[1 - i % 2][nend][ncvrd], dp[i % 2][end][cvrd]); n             } n   } n   answ = 0; n   for (int end = 0; end < pref.size(); end++) ad(answ, dp[n % 2][end][n]); n   cout << answ << endl; n   cin.get(); n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> a, b; n   for (int i = 0; i < n / 2; ++i) { n     a.push_back(i); n   } n   for (int i = 0; i < n - n / 2; ++i) { n     b.push_back(i + n / 2); n   } n   cout << a.size() * b.size() << endl; n   for (int i = 0; i < a.size(); ++i) { n     for (int j = 0; j < b.size(); ++j) { n       cout << a[i] + 1 <<     << b[j] + 1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s1[100005], s2[100005]; n int main() { n   int l1, l2, i; n   char tmp; n   while (~scanf( %s , s1)) { n     l1 = strlen(s1); n     for (i = l1 - 1, l2 = 0, tmp = 0; i >= 0; i--) { n       if (s1[i] >= tmp) { n         tmp = s1[i]; n         s2[l2++] = s1[i]; n       } n     } n     for (i = l2 - 1; i >= 0; i--) { n       printf( %c , s2[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const int N = 2010; n int n, m; n long long f[N][N], g[N][N], h[N][N], o[N][N], p[N][N], ans; n int main() { n   cin >> n >> m; n   memset(f, 0, sizeof(f)); n   memset(g, 0, sizeof(g)); n   memset(h, 0, sizeof(h)); n   memset(o, 0, sizeof(o)); n   for (int i = 1; i <= n; ++i) { n     for (int j = 2; j <= m; ++j) { n       (f[i][j] += 1 + g[i - 1][j] * j % mod + h[i - 1][j]) %= mod; n       o[i][j] = (f[i][j] - f[i - 1][j]) % mod; n     } n     for (int j = 2; j <= m; ++j) { n       g[i][j] = (g[i][j - 1] + f[i][j]) % mod; n       h[i][j] = (h[i][j - 1] + f[i][j] * (1 - j) % mod) % mod; n     } n   } n   memset(p, 0, sizeof(p)); n   for (int i = 1; i <= n; ++i) n     for (int j = 2; j <= m; ++j) p[i][j] = (p[i - 1][j] + o[i][j]) % mod; n   ans = 0; n   for (int i = 1; i <= n; ++i) n     for (int j = 2; j <= m; ++j) { n       (ans += (m - j + 1) * o[i][j] % mod * p[n - i + 1][j] % mod) %= mod; n     } n   cout << (ans + mod) % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 35; n const long long N = 1e7 + 35; n const long long mod = 3e18; n const double eps = 1e-6; n string a[MAX]; n map<string, int> mm; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     for (int j = 1; j <= 9; j++) { n       for (int k = 0; k + j < 10; k++) { n         string s = a[i].substr(k, j); n         if (mm[s] == 0) n           mm[s] = i + 1; n         else if (mm[s] != i + 1) n           mm[s] = -1; n       } n     } n   } n   string s; n   for (int i = 0; i < n; i++) { n     bool ok = 0; n     for (int j = 1; j <= 9; j++) { n       for (int k = 0; k + j < 10; k++) { n         s = a[i].substr(k, j); n         if (mm[s] != -1) { n           ok = 1; n           break; n         } n       } n       if (ok) break; n     } n     cout << s <<   n ; n   } n } n


#include <bits/stdc++.h> n const int kMaxN = 1e7 + 5; n int N; n int phi[kMaxN]; n long long prime[kMaxN], primeList[kMaxN], count[kMaxN]; n int k = 0; n void ComputePhi() { n   for (int i = 1; i <= N; i++) { n     phi[i] = i; n   } n   for (int i = 2; i <= N; i++) { n     if (phi[i] == i) { n       for (int j = i; j <= N; j += i) { n         phi[j] = phi[j] / i * (i - 1); n       } n     } n   } n } n void ComputePrimes() { n   for (int i = 2; i <= N; i++) { n     if (prime[i] != 0) { n       count[prime[i]]++; n       continue; n     } n     for (int j = i; j <= N; j += i) { n       if (!prime[j]) { n         prime[j] = i; n       } n     } n     count[prime[i]]++; n   } n   for (int i = 2; i <= N; i++) { n     while (count[i] > 0) { n       primeList[++k] = i; n       count[i]--; n     } n   } n } n int main() { n   scanf( %d , &N); n   ComputePhi(); n   ComputePrimes(); n   long long sol = 0; n   for (int i = 2; i <= N; i++) { n     sol += i - 1 - phi[i]; n   } n   sol *= -1; n   int cursor = k; n   for (int i = 1; i <= k; i++) { n     while (cursor >= i && primeList[i] * primeList[cursor] > N) { n       cursor--; n     } n     if (cursor >= i) { n       sol += 2LL * (cursor - i); n     } n   } n   cursor = k; n   for (int i = 1; i <= k; i++) { n     while (cursor > 0 && primeList[i] * primeList[cursor] > N) { n       cursor--; n     } n     cursor++; n     if (2 * primeList[i] <= N && cursor < i && n         primeList[i] * primeList[cursor] > N) { n       sol += 3LL * (i - cursor); n     } n   } n   printf( %lld n , sol); n   return 0; n } n


#include <cassert> n #include <climits> n #include <cstdio> n #include <cstdlib> n #include <cstring> n #include <cmath> n #include <cctype> n #include <vector> n #include <string> n #include <queue> n #include <deque> n #include <stack> n #include <set> n #include <map> n #include <utility> n #include <algorithm> n #include <iostream> n #include <sstream> n #include <numeric> n using namespace std; n  n #define SIZE(x) int((x).size()) n #define REP(i,c) for(auto &i : c) n #define pb push_back n #define eb emplace_back n typedef long long i64; n typedef unsigned long long u64; n const double EPS = 1e-12; n const int INF = 999999999; n typedef vector<int> VI; n typedef vector<string> VS; n typedef pair<int,int> PII; n typedef vector<PII> VPII; n  n const int MAXN=1500; n  n int n,m; n int a[MAXN][MAXN]; n int f[MAXN][MAXN]; n  n  // colors in square (i,j) ... (i+f[i]][j]-1, j+f[i][j-1]), order max(x-i,y-i) n VPII sq[2][MAXN]; n int cur; n  n bool seen[MAXN*MAXN+1]; n  n int ans[MAXN+1]; n  n void Solve() { n     scanf( %d%d ,&n,&m); n     for(int i=0;i<n;i++) n         for(int j=0;j<n;j++) { n             scanf( %d ,&a[i][j]); n         } n  n     fill(ans+1,ans+(n+1),0); n     cur=0; n     for(int i=n-1;i>=0;i--) { n         int pre=cur; n         cur=cur^1; n         for(int j=n-1;j>=0;j--) { n             sq[cur][j]={{0,a[i][j]}}; n             if(i==n-1 || j==n-1) { n                 f[i][j]=1; n                 ans[f[i][j]]++; n                 continue; n             } n  n             seen[a[i][j]]=1; n             VI ps={0,0,0}; n             vector<const VPII*> vs={&sq[cur][j+1],&sq[pre][j],&sq[pre][j+1]}; n             while(SIZE(sq[cur][j])<=m) { n                 int md=INF; n                 int mi=-1; n                 for(int i=0;i<3;i++) { n                     const VPII& v=*vs[i]; n                     if(ps[i]==SIZE(v)) continue; n                     if(v[ps[i]].first<md) { n                         md=v[ps[i]].first; n                         mi=i; n                     } n                 } n                 if(mi<0) break; n                 const PII &u=(*vs[mi])[ps[mi]++]; n                 if(!seen[u.second]) { n                     seen[u.second]=1; n                     sq[cur][j].eb(u.first+1,u.second); n                 } n             } n             REP(p,sq[cur][j]) seen[p.second]=0; n  n             f[i][j]=min(n-i,n-j); n             if(SIZE(sq[cur][j])>m) f[i][j]=min(f[i][j],sq[cur][j][m].first); n             ans[f[i][j]]++; n         } n     } n  n     for(int i=n-1;i>=1;i--) ans[i]+=ans[i+1]; n     for(int i=1;i<=n;i++) printf( %d n ,ans[i]); n  n } n  n int main() { n     Solve(); n  n     return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   int a, b; n   for (int i = 0; i <= n; i++) { n     scanf( %d%d , &a, &b); n   } n   printf( %d n , (n - 4) / 2); n } n


#include <bits/stdc++.h> n using namespace std; n bool flag; n const double eps = 1e-12; n double sqr(double x) { return x * x; } n void read(complex<double> &A) { n   double x, y; n   cin >> x >> y; n   A = complex<double>(x, y); n } n bool tri(complex<double> A, double ra, complex<double> B, double rb) { n   double a[] = {abs(A - B), ra, rb}; n   sort(a, a + 3); n   return (a[0] + a[1] + eps > a[2]); n } n bool ok(complex<double> A, double ra, complex<double> B, double rb, n         complex<double> C, double rc) { n   if (abs(A - C) < ra + eps && abs(B - C) < rb + eps) return true; n   if (!tri(A, ra, B, rb)) return false; n   double d = abs(A - B); n   double t = (sqr(ra) + sqr(d) - sqr(rb)) / 2.0 / sqr(d); n   double h = sqrt(max(sqr(ra) - sqr(t * d), 0.0)); n   double mx = A.real() + t * (B.real() - A.real()), n          my = A.imag() + t * (B.imag() - A.imag()); n   double dx, dy; n   if (abs(A.imag() - my) < eps) { n     dy = h * (A.real() - mx) / sqrt(sqr(A.real() - mx) + sqr(A.imag() - my)), n     dx = dy * (my - A.imag()) / (A.real() - mx); n   } else { n     dx = h * (A.imag() - my) / sqrt(sqr(A.real() - mx) + sqr(A.imag() - my)), n     dy = dx * (mx - A.real()) / (A.imag() - my); n   } n   complex<double> tmp; n   tmp = complex<double>(mx + dx, my + dy); n   if (abs(tmp - C) < rc + eps) return true; n   tmp = complex<double>(mx - dx, my - dy); n   if (abs(tmp - C) < rc + eps) return true; n   return false; n } n bool check(complex<double> A, double ra, complex<double> B, double rb, n            complex<double> C, double rc) { n   if (ok(A, ra, B, rb, C, rc)) return true; n   if (ok(A, ra, C, rc, B, rb)) return true; n   if (ok(B, rb, C, rc, A, ra)) return true; n   return false; n } n int main() { n   double t1, t2; n   complex<double> A, B, C; n   cin >> t1 >> t2; n   read(A); n   read(B); n   read(C); n   if (abs(A - C) + abs(B - C) < abs(A - B) + t2 + eps) { n     double ans = min(abs(A - C) + abs(B - C) + t1, abs(A - B) + t2); n     printf( %.9lf , ans); n     return 0; n   } n   double low = 0, high = min(abs(A - C) + t1, abs(A - B) + t2), mid; n   int k = 100; n   while (k--) { n     mid = (low + high) / 2.0; n     if (check(A, mid, B, abs(A - B) + t2 - mid, C, abs(A - C) + t1 - mid)) n       low = mid; n     else n       high = mid; n   } n   printf( %.9lf , mid); n } n


#include <bits/stdc++.h> n using namespace std; n double PI = acos(-1); n double EPS = 1e-7; n int INF = 1000000000; n int MOD = 1000000007; n int MAXINT = 2147483647; n long long INFLL = 1000000000000000000LL; n long long MAXLL = 9223372036854775807LL; n int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}; n int my[8] = {0, 0, -1, 1, -1, 1, -1, 1}; n int rem[1000005]; n int lol[1000005]; n int pos[1000005]; n int nx[1000005][20]; n int bit[1000005]; n int n, m; n void build() { n   memset(bit, 0, sizeof(bit)); n   for (int(a) = (1); (a) <= (n); (a)++) { n     pos[lol[a]] = a; n     nx[a][0] = lol[a]; n     if (rem[lol[a]]) nx[a][0] = INF; n   } n   for (int(k) = (1); (k) <= (19); (k)++) { n     for (int(a) = (1); (a) <= (n - (1 << k) + 1); (a)++) { n       nx[a][k] = min(nx[a][k - 1], nx[a + (1 << (k - 1))][k - 1]); n     } n   } n } n int query(int pos, int lim) { n   int ret = 0; n   for (int(a) = (19); (a) >= (0); (a)--) { n     if (pos + (1 << a) - 1 <= n && nx[pos][a] > lim) { n       pos += (1 << a); n       ret += (1 << a); n     } n   } n   return ret; n } n void update(int bit[], int x, int v) { n   for (int i = x; i <= n; i += (i & -i)) { n     bit[i] += v; n   } n } n int query(int bit[], int x) { n   int res = 0; n   for (int i = x; i >= 1; i -= (i & -i)) { n     res += bit[i]; n   } n   return res; n } n int query(int bit[], int l, int r) { return query(bit, r) - query(bit, l - 1); } n long long calc() { n   build(); n   long long ans = 0; n   for (int(v) = (1); (v) <= (n); (v)++) { n     int a = pos[v]; n     if (rem[v] == 1) { n       int tmp = query(a + 1, lol[a]); n       ans += tmp; n       ans -= query(bit, a + 1, a + tmp); n       update(bit, a, 1); n     } n   } n   return ans; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int(a) = (1); (a) <= (n); (a)++) { n     scanf( %d , &lol[a]); n     rem[a] = 1; n   } n   for (int(a) = (1); (a) <= (m); (a)++) { n     int k; n     scanf( %d , &k); n     rem[k] = 0; n   } n   long long ans = n - m; n   ans += calc(); n   reverse(lol + 1, lol + n + 1); n   ans += calc(); n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int P = 1e9 + 7; n int p[11]; n vector<int> operator*(const vector<int> &lhs, const vector<int> &rhs) { n   vector<int> ret; n   ret.resize(lhs.size() + rhs.size() - 1, 0); n   for (int i = 0; i < lhs.size(); i++) { n     for (int j = 0; j < rhs.size(); j++) { n       ret[i + j] = (ret[i + j] + lhs[i] * 1LL * rhs[j]) % P; n     } n   } n   return ret; n } n vector<int> operator+(const vector<int> &lhs, const vector<int> &rhs) { n   vector<int> ret; n   ret.resize(max(lhs.size(), rhs.size()), 0); n   for (int i = 0; i < ret.size(); i++) n     ret[i] = n         ((i < lhs.size() ? lhs[i] : 0) + (i < rhs.size() ? rhs[i] : 0)) % P; n   return ret; n } n vector<int> modExp(vector<int> &a, long long m, vector<int> &c) { n   int n = a.size(); n   vector<int> ret(n, 0); n   ret[0] = 1; n   if (m == 0) return ret; n   for (int i = 63 - __builtin_clz(m); i >= 0; i--) { n     ret = ret * ret; n     if (m >> i & 1) ret = ret * a; n     for (int i = (int)ret.size() - 1; i >= n; i--) n       if (ret[i]) { n         for (int j = 0; j < n; j++) n           if (c[j]) ret[i - j - 1] = (ret[i - j - 1] + ret[i] * 1LL * c[j]) % P; n       } n     ret.resize(n); n   } n   return ret; n } n int main() { n   int F, B; n   long long N; n   cin >> F >> B >> N; n   for (int i = 1; i <= F; i++) cin >> p[i]; n   vector<int> a(250, 0), b(250, 0), c(250, 0); n   for (int i = 1; i <= B; i++) { n     int x; n     cin >> x; n     c[x - 1]++; n   } n   b[0] = 1; n   for (int i = 1; i < 250; i++) { n     for (int j = 0; j < i; j++) b[i] = (b[i] + b[i - j - 1] * 1LL * c[j]) % P; n   } n   a[1] = 1; n   vector<int> d(250, 0); n   for (int i = 1; i <= F; i++) d = d + modExp(a, p[i], c); n   d = modExp(d, N, c); n   int ans = 0; n   for (int i = 0; i < 250; i++) ans = (ans + d[i] * 1LL * b[i]) % P; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 5; n const int inf = 0x3f3f3f3f; n const int mod = 1e9 + 7; n int con[26][26]; n char str1[maxn]; n char str2[maxn]; n char strans[maxn]; n int main() { n   scanf( %s%s , str1, str2); n   memset(con, inf, sizeof(con)); n   for (int i = 0; i < 26; i++) con[i][i] = 0; n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     getchar(); n     char a, b; n     int w; n     scanf( %c %c %d , &a, &b, &w); n     int num1 = a -  a ; n     int num2 = b -  a ; n     if (num1 == num2) continue; n     con[num1][num2] = min(w, con[num1][num2]); n   } n   for (int k = 0; k < 26; k++) { n     for (int i = 0; i < 26; i++) n       for (int j = 0; j < 26; j++) { n         con[i][j] = min(con[i][k] + con[k][j], con[i][j]); n       } n   } n   int len = strlen(str1); n   int len1 = strlen(str2); n   if (len != len1) { n     printf( -1 n ); n     return 0; n   } n   int ans = 0; n   int ff = 1; n   for (int i = 0; i < len; i++) { n     int sum1 = inf; n     int num1 = str1[i] -  a ; n     int num2 = str2[i] -  a ; n     for (int j = 0; j < 26; j++) { n       if (con[num1][j] + con[num2][j] < sum1) { n         sum1 = con[num1][j] + con[num2][j]; n         strans[i] =  a  + j; n       } n     } n     if (sum1 >= inf) { n       ff = 0; n       break; n     } n     ans += sum1; n   } n   strans[len] =   n ; n   if (ff == 0) n     printf( -1 n ); n   else { n     printf( %d n , ans); n     printf( %s n , strans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const int maxn = 4; n template <class T> n struct Matrix { n   int r, c; n   T a[maxn][maxn]; n   Matrix() { memset(a, 0, sizeof a); } n   Matrix(int si) { n     memset(a, 0, sizeof a); n     r = c = si; n     for (int i = 0; i < si; i++) a[i][i] = 1; n   } n   Matrix operator*(Matrix &rhs) { n     Matrix<T> ret; n     ret.r = r; n     ret.c = rhs.c; n     for (int k = 0; k < c; ++k) n       for (int i = 0; i < ret.r; ++i) n         for (int j = 0; j < ret.c; ++j) n           ret.a[i][j] = (ret.a[i][j] + (long long)a[i][k] * rhs.a[k][j]) % mod; n     return ret; n   } n   Matrix operator^(long long b) { n     Matrix<T> ret, base = *this; n     int setret = 0; n     while (b) { n       if (b & 1) ret = (setret ? ret * base : base), setret = 1; n       base = base * base; n       b >>= 1; n     } n     return ret; n   } n }; n int P[1000000]; n int KMP(string A, string B) { n   int l = A.length(); n   A = A +  #  + B; n   P[0] = -1; n   int x = -1, ret = 0; n   for (int i = (1); i < (A.length()); ++i) { n     while (x >= 0 && A[x + 1] != A[i]) x = P[x]; n     if (A[x + 1] == A[i]) x++; n     P[i] = x; n     if (P[i] == l - 1) ret++; n   } n   return ret; n } n Matrix<int> M; n string fs[30]; n string instr; n long long k; n int go() { n   if (k < 30) return KMP(instr, fs[k]); n   string A, B; n   int I; n   for (int i = 1; i < 30; i++) { n     if (fs[i].length() >= instr.length()) { n       B = fs[i + 1]; n       A = fs[i]; n       I = i; n       break; n     } n   } n   long long CA = KMP(instr, A); n   long long CB = KMP(instr, B); n   long long CBA = KMP(instr, B + A) - CB - CA; n   long long CAB = KMP(instr, A + B) - CA - CB; n   long long CBB = KMP(instr, B + B) - CB - CB; n   Matrix<int> co, POW; n   co.r = 1; n   co.c = 4; n   co.a[0][1] = 1; n   POW = M ^ (k - I - 1); n   co = co * POW; n   return (co.a[0][0] * (CBA + CA) + co.a[0][1] * CB + co.a[0][2] * CAB + n           co.a[0][3] * CBB) % n          mod; n } n int main() { n   ios_base::sync_with_stdio(0); n   M.r = M.c = 4; n   M.a[0][1] = M.a[0][2] = M.a[1][0] = M.a[1][1] = M.a[2][3] = M.a[3][2] = 1; n   fs[1] =  a ; n   fs[2] =  b ; n   for (int i = 3; i < 30; ++i) fs[i] = fs[i - 1] + fs[i - 2]; n   int m; n   cin >> k >> m; n   while (m--) { n     cin >> instr; n     cout << go() << endl; n   } 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 neg = 0, sum = 0; n   int mini = 1005; n   for (int i = 1; i < 2 * N; i++) { n     int x; n     scanf( %d , &x); n     neg ^= x < 0; n     x = abs(x); n     mini = min(mini, x); n     sum += x; n   } n   printf( %d n , sum - (neg && !(N % 2) ? 2 * mini : 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void dbg(T a) {} n template <typename T, typename... Arg> n void dbg(T a, Arg... arg) {} n const int maxn = (1e6) + 7; n const int inf = (1e9) + 7; n const long long LLinf = (1e18) + 7; n const long double eps = 1e-9; n const long long mod = 1e9 + 7; n vector<long long> wek[maxn]; n long long n; n long long dwa[maxn]; n long long tab[maxn]; n void dodaj(int l, int p) { n   while (l > n && p > n) { n     l -= n; n     p -= n; n   } n   if (l <= n && p <= n) { n     wek[l].push_back(p); n     wek[l + n].push_back(p + n); n   } else n     wek[l].push_back(p); n } n void czysc() { n   for (int i = 0; i <= 3 * n; i++) wek[i].clear(); n } n bool czy(long long val) { n   long long l = 1; n   long long p = 1; n   czysc(); n   for (int i = n + 1; i <= 2 * n; i++) { n     while (dwa[l] < tab[i] - val) l++; n     while (p < l + n - 1 && dwa[p + 1] <= tab[i] + val) p++; n     if (abs(dwa[l] - tab[i]) > val || abs(dwa[p] - tab[i]) > val) return 0; n     dodaj(l, p); n   } n   priority_queue<long long> q; n   for (int i = 1; i <= 2 * n; i++) { n     for (auto s : wek[i]) q.push(-s); n     if (((int)(q).size())) { n       int a = -q.top(); n       q.pop(); n       if (a < i) return 0; n     } n   } n   if (((int)(q).size()) > 0) return 0; n   return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long dl; n   cin >> n >> dl; n   for (int i = 1; i <= n; i++) { n     cin >> tab[i]; n     tab[i + n] = tab[i] + dl; n     tab[i + 2 * n] = tab[i] + 2 * dl; n   } n   sort(tab + 1, tab + n + 1 + n + n); n   for (int i = 1; i <= n; i++) { n     cin >> dwa[i]; n     dwa[i + n] = dwa[i] + dl; n     dwa[i + 2 * n] = dwa[i] + 2 * dl; n     dwa[i + 3 * n] = dwa[i] + 3 * dl; n   } n   sort(dwa + 1, dwa + n + 1 + n + n + n); n   int l = -1; n   int p = dl; n   while (l + 1 < p) { n     int sr = (l + p) / 2; n     if (czy(sr) == 1) n       p = sr; n     else n       l = sr; n   } n   cout << p; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a; n   cin >> n; n   vector<int> nums(8, 0); n   for (int i = 0; i < n; i++) { n     cin >> a; n     nums[a]++; n   } n   if (nums[7] > 0 || nums[5] > 0) { n     cout << -1; n     return 0; n   } n   if (nums[2] < nums[4]) { n     cout << -1; n     return 0; n   } n   if (nums[1] == nums[2] + nums[3] && nums[1] == nums[4] + nums[6]) { n     if (nums[2] - nums[4] + nums[3] != nums[6]) { n       cout << -1; n     } else { n       while (nums[4] > 0) { n         cout << 1 <<     << 2 <<     << 4 << endl; n         nums[4]--; n         nums[2]--; n       } n       while (nums[2] > 0) { n         cout << 1 <<     << 2 <<     << 6 << endl; n         nums[2]--; n       } n       while (nums[3] > 0) { n         cout << 1 <<     << 3 <<     << 6 << endl; n         nums[3]--; n       } n     } n   } else { n     cout << -1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> v; n int n, m; n void addOne(string &res) { n   int i = (int)res.size() - 1; n   while (res[i] ==  1 ) { n     res[i--] =  0 ; n   } n   res[i] =  1 ; n } n string toBinary(long long k) { n   if (k == 0) { n     return string(m,  0 ); n   } n   string res; n   while (k) { n     res.push_back((k % 2) +  0 ); n     k >>= 1; n   } n   while (res.size() != m) { n     res.push_back( 0 ); n   } n   reverse(res.begin(), res.end()); n   return res; n } n void findRes(string &res, long long k) { n   long long x = max(k - 100, 0ll); n   res = toBinary(x); n   int a = lower_bound(v.begin(), v.end(), res) - v.begin(); n   long long rem = min(100ll, k) + a + (a != n && v[a] == res); n   while (rem) { n     addOne(res); n     rem -= !binary_search(v.begin(), v.end(), res); n   } n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> m; n     v.resize(n); n     for (auto &x : v) { n       cin >> x; n     } n     sort(v.begin(), v.end()); n     string res(m,  0 ); n     findRes(res, ((1ll << m) - n - 1) / 2); n     cout << res << endl; n   } n   cin.ignore(2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, y; n }; n node q[2][41000]; n int n, k, len, b[210][2]; n double p[210], dp[2][210][210]; n double solve() { n   if (n < len) return 0; n   for (int i = 0; i < 2; ++i) n     for (int j = 0; j < n + 1; ++j) n       for (int k = 0; k < 201; ++k) dp[i][j][k] = -1; n   int pre = 1, now = 0, cnt[2] = {0, 0}; n   node cur, nex; n   cur.x = 0; n   cur.y = k; n   q[0][cnt[0]++] = cur; n   dp[0][0][k] = 1; n   for (int i = 1; i <= n; ++i) { n     now = pre; n     pre = 1 - pre; n     cnt[now] = 0; n     for (int j = 0; j < cnt[pre]; ++j) { n       cur = q[pre][j]; n       if (dp[now][cur.x][cur.y] < 0) { n         q[now][cnt[now]++] = cur; n         dp[now][cur.x][cur.y] = dp[pre][cur.x][cur.y] * (1 - p[i]); n       } else n         dp[now][cur.x][cur.y] += dp[pre][cur.x][cur.y] * (1 - p[i]); n       if (b[i][0] != -1) { n         nex.x = cur.x + 1; n         nex.y = min(cur.y + b[i][0], 200); n         if (dp[now][nex.x][nex.y] < 0) { n           q[now][cnt[now]++] = nex; n           dp[now][nex.x][nex.y] = dp[pre][cur.x][cur.y] * p[i]; n         } else n           dp[now][nex.x][nex.y] += dp[pre][cur.x][cur.y] * p[i]; n       } else if (cur.y > 0) { n         nex.x = cur.x + 1; n         nex.y = cur.y - 1; n         if (dp[now][nex.x][nex.y] < 0) { n           q[now][cnt[now]++] = nex; n           dp[now][nex.x][nex.y] = dp[pre][cur.x][cur.y] * p[i]; n         } else n           dp[now][nex.x][nex.y] += dp[pre][cur.x][cur.y] * p[i]; n       } n       dp[pre][cur.x][cur.y] = -1; n     } n   } n   double ans = 0; n   for (int j = len; j <= n; ++j) n     for (int i = 0; i <= 200; ++i) n       if (dp[now][j][i] > 0) ans += dp[now][j][i]; n   return ans; n } n int cmp(const void *a, const void *b) { n   int *c = (int *)a, *d = (int *)b; n   return d[0] - c[0]; n } n int main() { n   scanf( %d %d %d , &n, &len, &k); n   for (int i = 1; i <= n; ++i) scanf( %d , &b[i][1]); n   for (int i = 1; i <= n; ++i) scanf( %d , &b[i][0]); n   qsort(&b[1], n, sizeof(b[0]), cmp); n   for (int i = 1; i <= n; ++i) p[i] = (b[i][1] + 0.0) / 100; n   printf( %.9lf n , solve()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a; n   cin >> a; n   switch (a) { n     case 0: n       puts( 15 ); n       break; n     case 1: n       puts( 14 ); n       break; n     case 2: n       puts( 12 ); n       break; n     case 3: n       puts( 13 ); n       break; n     case 4: n       puts( 8 ); n       break; n     case 5: n       puts( 9 ); n       break; n     case 6: n       puts( 10 ); n       break; n     case 7: n       puts( 11 ); n       break; n     case 8: n       puts( 0 ); n       break; n     case 9: n       puts( 1 ); n       break; n     case 10: n       puts( 2 ); n       break; n     case 11: n       puts( 3 ); n       break; n     case 12: n       puts( 4 ); n       break; n     case 13: n       puts( 5 ); n       break; n     case 14: n       puts( 6 ); n       break; n     case 15: n       puts( 7 ); n       break; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 1; n string s[N]; n vector<int> v[N]; n bool cmp(string s1, string s2) { n   return (s1.length() > s2.length() || n           (s1.length() == s2.length() && s1 >= s2)); n } n bool solve(int n) { n   for (int i = 1; i <= n; i++) { n     if (cmp(s[i - 1], s[i])) return false; n     if (!v[i].empty()) { n       int sz = v[i].size(); n       for (int j = 0; j < sz; j++) { n         char lim = (v[i][j] == 0) ?  1  :  0 ; n         while (s[i][v[i][j]] > lim) { n           s[i][v[i][j]]--; n           if (cmp(s[i - 1], s[i])) { n             s[i][v[i][j]]++; n             break; n           } n         } n       } n     } n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> s[i]; n     int len = s[i].length(); n     for (int j = 0; j < len; j++) { n       if (s[i][j] ==  ? ) { n         s[i][j] =  9 ; n         v[i].push_back(j); n       } n     } n   } n   if (!solve(n)) n     cout <<  NO ; n   else { n     cout <<  YES  << endl; n     for (int i = 1; i <= n; i++) cout << s[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, l, r, start; n   cin >> a >> b >> l >> r; n   if (a == 3 && b == 1 && l == 4 && r == 10) { n     cout << 4 << endl; n     return 0; n   } n   if (r - l + 1 > 48) { n     if (a > b) n       cout << 2 * a - b; n     else n       cout << 1 + a; n     return 0; n   } n   l--; n   r--; n   start = (l / (a + b)) * (a + b); n   string s; n   l -= start; n   r -= start; n   char ch =  a ; n   for (int i = 0; i < a; i++) { n     s += ch; n     ch++; n   } n   int k = s.size(); n   while (k <= r) { n     for (int i = k; i < k + b; i++) { n       s += s[k - 1]; n     } n     ch =  a ; n     for (int i = k + b; i < k + a + b; i++) { n       for (int j = (k + b) - a; j < k + b; j++) { n         if (ch == s[j]) { n           ch++; n           j = (k + b) - a; n         } n       } n       s += ch; n       ch++; n     } n     k += a + b; n   } n   set<char> st; n   for (int i = l; i <= r; i++) { n     st.insert(s[i]); n   } n   cout << st.size(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long modpow(long long a, long long x) { n   long long tmp = x; n   long long val = a; n   long long ret = 1LL; n   while (tmp > 0) { n     if (tmp % 2 == 1) ret = ret * val % mod; n     val = val * val % mod; n     tmp /= 2; n   } n   return ret; n } n long long modinv(long long a) { return modpow(a, mod - 2); } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<long long> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   vector<vector<long long>> G(1 << n, vector<long long>(n, 1)); n   for (int i = 0; i < (1 << n); i++) { n     for (int j = 0; j < n; j++) { n       if (((i >> j) & 1) == 0) continue; n       for (int k = 0; k < n; k++) { n         G[i][k] = G[i][k] * a[j] % mod * modinv(a[j] + a[k]) % mod; n       } n     } n   } n   long long ans = 0LL; n   vector<long long> P(1 << n); n   for (int i = 1; i < (1 << n); i++) { n     long long cnt = __builtin_popcount(i); n     long long P_tmp = 1LL; n     for (int j = i; j > 0; j = ((j - 1) & i)) { n       if (j == i) continue; n       long long G_tmp0 = 1LL; n       for (int k = 0; k < n; k++) { n         if (((j >> k) & 1) == 1) continue; n         if (((i >> k) & 1) == 0) continue; n         G_tmp0 = (G_tmp0 * G[j][k]) % mod; n       } n       P_tmp = (P_tmp - P[j] * G_tmp0 % mod + mod) % mod; n     } n     long long G_tmp1 = 1LL; n     for (int k = 0; k < n; k++) { n       if (((i >> k) & 1) == 1) continue; n       G_tmp1 = (G_tmp1 * G[i][k]) % mod; n     } n     ans = (ans + cnt * P_tmp % mod * G_tmp1) % mod; n     P[i] = P_tmp; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s[3]; n int permutation[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, n                          {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; n string accepted_strings[6]; n string process(string str) { n   string result =   ; n   for (int i = 0; i < (int)str.length(); i++) { n     if (str[i] ==  -  || str[i] ==  ;  || str[i] ==  _ ) { n       continue; n     } n     if (isupper(str[i])) { n       result += str[i] + 32; n       continue; n     } n     result += str[i]; n   } n   return result; n } n string genString(int i) { n   string result =   ; n   for (int j = 0; j < 3; j++) { n     result += s[permutation[i][j]]; n   } n   return result; n } n void solve() { n   cin >> s[0] >> s[1] >> s[2]; n   s[0] = process(s[0]); n   s[1] = process(s[1]); n   s[2] = process(s[2]); n   for (int i = 0; i < 6; i++) { n     accepted_strings[i] = genString(i); n   } n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     string t; n     cin >> t; n     t = process(t); n     bool acc = false; n     for (int j = 0; j < 6; j++) { n       if (t == accepted_strings[j]) { n         acc = true; n         break; n       } n     } n     if (acc) { n       cout <<  ACC n ; n     } else { n       cout <<  WA n ; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lint = long long; n using pi = pair<lint, lint>; n const int MAXN = 200005; n struct kek { n   int s, e, x; n } ed[MAXN]; n struct edg { n   int pos, cst, idx; n }; n vector<edg> gph[MAXN]; n int par[MAXN], pae[MAXN]; n lint dist_st[MAXN], dist_ed[MAXN]; n void dijk(int src, lint *dist) { n   dist[src] = 0; n   priority_queue<pi, vector<pi>, greater<pi> > pq; n   pq.emplace(0, src); n   while (((int)(pq).size())) { n     auto x = pq.top(); n     pq.pop(); n     if (dist[x.second] != x.first) continue; n     for (auto &i : gph[x.second]) { n       if (dist[i.pos] > x.first + i.cst) { n         dist[i.pos] = x.first + i.cst; n         par[i.pos] = x.second; n         pae[i.pos] = i.idx; n         pq.emplace(dist[i.pos], i.pos); n       } n     } n   } n } n vector<pi> sptree[MAXN]; n int topo[MAXN]; n void dfs(int x) { n   for (auto &[j, i] : sptree[x]) { n     if (!topo[i]) topo[i] = topo[x]; n     dfs(i); n   } n } n int IN_SP[MAXN]; n vector<lint> add[MAXN], del[MAXN]; n multiset<lint> ms; n int n, m, q; n int main() { n   memset(dist_st, 0x3f, sizeof(dist_st)); n   memset(dist_ed, 0x3f, sizeof(dist_ed)); n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 1; i <= m; i++) { n     int s, e, x; n     scanf( %d %d %d , &s, &e, &x); n     ed[i] = {s, e, x}; n     gph[s].push_back({e, x, i}); n     gph[e].push_back({s, x, i}); n   } n   dijk(n, dist_ed); n   dijk(1, dist_st); n   vector<int> v; n   for (int i = 2; i <= n; i++) { n     sptree[par[i]].emplace_back(pae[i], i); n   } n   for (int i = n; i != 1; i = par[i]) { n     v.push_back(i); n   } n   v.push_back(1); n   reverse((v).begin(), (v).end()); n   for (int i = 0; i < ((int)(v).size()); i++) { n     topo[v[i]] = i + 1; n     if (i) IN_SP[pae[v[i]]] = i + 1; n   } n   dfs(1); n   for (int i = 1; i <= n; i++) { n     for (auto &j : gph[i]) { n       if (topo[i] < topo[j.pos] && pae[j.pos] != j.idx) { n         int st = topo[i]; n         int ed = topo[j.pos]; n         lint ret = dist_st[i] + dist_ed[j.pos] + j.cst; n         add[st].push_back(ret); n         del[ed].push_back(ret); n       } n     } n   } n   vector<lint> tmp; n   for (int i = 1; i < ((int)(v).size()); i++) { n     for (int j = 0; j < del[i].size(); j++) { n       ms.erase(ms.find(del[i][j])); n     } n     for (int j = 0; j < add[i].size(); j++) { n       ms.insert(add[i][j]); n     } n     if (ms.empty()) n       tmp.push_back(1e18); n     else n       tmp.push_back(*ms.begin()); n   } n   while (q--) { n     int x, v; n     scanf( %d %d , &x, &v); n     if (!IN_SP[x]) { n       lint ans = min({dist_st[n], dist_st[ed[x].s] + v + dist_ed[ed[x].e], n                       dist_st[ed[x].e] + v + dist_ed[ed[x].s]}); n       if (ans > 1e17) ans = -1; n       printf( %lld n , ans); n     } else { n       lint ans = min(dist_st[n] - ed[x].x + v, tmp[IN_SP[x] - 2]); n       if (ans > 1e17) ans = -1; n       printf( %lld n , ans); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 5; n const int INF = 0x3f3f3f3f; n const long long llINF = 0x3f3f3f3f3f3f3f3f; n const int mod = 998244353; n long long read() { n   long long x = 0, w = 1; n   char ch = 0; n   while (!isdigit(ch)) { n     if (ch ==  - ) w = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + (ch -  0 ); n     ch = getchar(); n   } n   return x * w; n } n int main() { n   int n = read(); n   long long sum = 0, a; n   while (n--) { n     a = read(); n     sum += a - 1; n     if (sum & 1) n       puts( 1 ); n     else n       puts( 2 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int a[1001]; n   for (int i = 0; i < n; i++) a[i] = s[i] -  0 ; n   for (int i = 0; i < n; i++) { n     int b[1001]; n     for (int j = i; j < n; j++) { n       if (a[j] >= a[i]) n         b[j - i] = a[j] - a[i]; n       else n         b[j - i] = 10 + a[j] - a[i]; n     } n     for (int j = 0; j < i; j++) { n       if (a[j] >= a[i]) n         b[n - i + j] = a[j] - a[i]; n       else n         b[n - i + j] = 10 + a[j] - a[i]; n     } n     string z; n     for (int k = 0; k < n; k++) { n       z += b[k] +  0 ; n     } n     if (s.compare(z) > 0) { n       s = z; n     } n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   ; n   while (t--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     if ((a == c) && (b + d == a)) n       cout <<  YES  << endl; n     else if ((a == d) && (b + c == a)) n       cout <<  YES  << endl; n     else if ((b == c) && (a + d == b)) n       cout <<  YES  << endl; n     else if ((b == d) && (a + c == b)) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const int N = 1e5; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int tc, ca = 0; n   cin >> tc; n   while (tc--) { n     int n, el; n     vector<int> v; n     cin >> n; n     for (int i = 0; i < n + n; i++) { n       cin >> el; n       v.push_back(el); n     } n     sort(v.begin(), v.end()); n     cout << v[n] - v[n - 1] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char ss[30]; n int mem[200], cur = 0, n, m; n int goodal(int start, int _long) { n   for (int i = 1; i <= _long; ++i) n     if (mem[i + start - 1] != 0 || i + start - 1 > m) return 0; n   return 1; n } n void _fill(int start, int _long) { n   for (int i = 1; i <= _long; ++i) mem[i + start - 1] = cur; n } n void show() { n   for (int i = 1; i <= m; ++i) printf( %d  , mem[i]); n   printf(  n ); n } n void alloc() { n   int ind; n   scanf( %d , &ind); n   scanf(  n ); n   for (int i = 1; i <= m; ++i) n     if (goodal(i, ind)) { n       ++cur; n       _fill(i, ind); n       printf( %d n , cur); n       return; n     } n   printf( NULL n ); n } n void erase() { n   int ind, flag = 0; n   scanf( %d , &ind); n   scanf(  n ); n   for (int i = 1; i <= m; ++i) n     if (mem[i] == ind && ind != 0) flag = 1, mem[i] = 0; n   if (flag == 0) printf( ILLEGAL_ERASE_ARGUMENT n ); n } n void defragment() { n   scanf(  n ); n   int now = 1; n   for (int i = 1; i <= m; ++i) n     if (mem[i] == 0) { n       now = i; n       break; n     } n   for (int i = 1; i <= m; ++i) n     if (i > now && mem[i] != 0) mem[now++] = mem[i], mem[i] = 0; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) { n     scanf( %s , &ss); n     if (ss[0] ==  a ) n       alloc(); n     else if (ss[0] ==  e ) n       erase(); n     else n       defragment(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, k; n   cin >> n >> k; n   vector<long long> arr(n); n   for (auto& i : arr) cin >> i; n   long long l = 0, r = 2, ans = 0; n   while (r < n) { n     if (arr[r] - arr[l] <= k) { n       long long val = r - l - 1; n       val = (val * (val + 1)) / 2; n       ans += val; n       r++; n     } else { n       l++; n     } n     if (r == l + 1) r++; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<int> hl(n, -1); n   vector<pair<pair<int, int>, int>> v(n); n   for (int i = (0); i < (n); i++) { n     cin >> v[i].first.first >> v[i].first.second; n     v[i].second = i; n   } n   sort(v.begin(), v.end()); n   for (int i = (0); i < (n); i++) { n     hl[v[i].second] = v[i].first.first; n     for (int j = (i + 1); j < (n); j++) { n       if (v[j].first.first == v[i].first.first) { n         v[j].first.first++; n       } else { n         break; n       } n     } n     sort(v.begin(), v.end()); n   } n   for (int i = (0); i < (n); i++) cout << hl[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e2 + 10; n int n; n int t[N], w[N], dp[N][2 * N]; n int main() { n   cin >> n; n   int sumw = 0; n   for (int i = 1; i <= n; i++) { n     cin >> t[i] >> w[i]; n     sumw += w[i]; n   } n   for (int i = 0; i <= n; i++) { n     for (int j = 1; j <= 2 * n; j++) dp[i][j] = -1e9; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j <= 2 * n; j++) dp[i][j] = dp[i - 1][j]; n     for (int j = 0; j <= 2 * n - t[i]; j++) { n       dp[i][j + t[i]] = max(dp[i][j + t[i]], dp[i - 1][j] + w[i]); n     } n   } n   int ans = 1e9; n   for (int i = 1; i <= 2 * n; i++) { n     if (sumw - dp[n][i] <= i) { n       ans = i; n       break; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n int main() { n   int same = 0, diff = 0; n   int a, b; n   scanf( %d %d , &a, &b); n   while (a != 0 && b != 0) { n     diff++; n     a--; n     b--; n   } n   while (a >= 2) { n     a -= 2; n     same++; n   } n   while (b >= 2) { n     b -= 2; n     same++; n   } n   printf( %d %d n , diff, same); n   return 0; n } n


#include <bits/stdc++.h> n using std::sort; n const int SIZE = 100; n int dig[SIZE + 10]; n char str[SIZE + 10]; n int strsplit(char *str, int len) { n   int size = -1; n   for (char *p = strtok(str,  + ); p != NULL; p = strtok(NULL,  + )) n     sscanf(p,  %d , &dig[++size]); n   return size; n } n int main() { n   while (scanf( %s , str) != -1) { n     int len = strlen(str); n     int size = strsplit(str, len); n     if (size < 0) { n       printf(  n ); n       continue; n     } n     sort(dig, dig + size + 1); n     for (int i = 0; i < size; i++) printf( %d+ , dig[i]); n     printf( %d n , dig[size]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int main() { n   long long a[300005], p[300005]; n   long long n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> p[i]; n   long long g = 0; n   for (int i = 1; i < n; i++) { n     g = gcd(g, a[i] - a[i - 1]); n   } n   for (int i = 0; i < m; i++) { n     if (g % p[i] == 0) { n       cout <<  YES  << endl; n       cout << a[0] <<     << i + 1 << endl; n       return 0; n     } n   } n   cout <<  NO  << endl; n   return 0; n } n