#include <bits/stdc++.h>   using namespace std;   struct var {     char name[20], type[20];   } v[1010];   int vcnt;   struct func {     char name[20];     char para[50][20];     int paracnt;   } f[1010];   int fcnt;   int n;   char str[110], name[110], para[110][110], cnt;   int main() {     scanf( %d , &fcnt);     gets(str);     for (int i = 1; i <= fcnt; ++i) {       gets(str);       int j = 0, l = 0, len = strlen(str);       while (str[j] !=  d ) ++j;       ++j;       while (!isalpha(str[j]) && !isdigit(str[j])) ++j;       while (isalpha(str[j]) || isdigit(str[j])) f[i].name[l++] = str[j++];       f[i].name[l] =   0 ;       j++;       while (!isalpha(str[j]) && !isdigit(str[j]) && (j < len)) ++j;       while (j < len) {         l = 0;         f[i].paracnt++;         while (isalpha(str[j]) || isdigit(str[j]))           f[i].para[f[i].paracnt][l++] = str[j++];         f[i].para[f[i].paracnt][l] =   0 ;         while (!isalpha(str[j]) && !isdigit(str[j]) && (j < len)) ++j;       }     }     scanf( %d , &vcnt);     gets(str);     for (int i = 1; i <= vcnt; ++i) {       gets(str);       int j = 0, len = strlen(str), l = 0;       while (!isalpha(str[j]) && !isdigit(str[j])) ++j;       while (isdigit(str[j]) || isalpha(str[j])) v[i].type[l++] = str[j++];       v[i].type[l] =   0 ;       while (!isalpha(str[j]) && !isdigit(str[j])) ++j;       l = 0;       while (isdigit(str[j]) || isalpha(str[j])) v[i].name[l++] = str[j++];       v[i].name[l] =   0 ;     }     scanf( %d , &n);     gets(str);     while (n--) {       gets(str);       int j = 0, l = 0, len = strlen(str);       while (!isalpha(str[j]) && !isdigit(str[j])) ++j;       while (isalpha(str[j]) || isdigit(str[j])) name[l++] = str[j++];       name[l] =   0 ;       j++;       cnt = 0;       while (!isalpha(str[j]) && !isdigit(str[j]) && (j < len)) ++j;       while (j < len) {         l = 0;         cnt++;         while (isalpha(str[j]) || isdigit(str[j])) para[cnt][l++] = str[j++];         para[cnt][l] =   0 ;         while (!isalpha(str[j]) && !isdigit(str[j]) && (j < len)) ++j;       }       bool flag = true;       for (int i = 1; i <= cnt; ++i) {         bool find = false;         for (int j = 1; j <= vcnt; ++j)           if (!strcmp(para[i], v[j].name)) {             strcpy(para[i], v[j].type);             find = true;             break;           }         if (!find) {           flag = false;           break;         }       }       if (!flag) {         printf( 0 n );         continue;       }       int res = 0;       for (int i = 1; i <= fcnt; ++i)         if ((strcmp(f[i].name, name) == 0) && (cnt == f[i].paracnt)) {           bool okay = true;           for (int j = 1; j <= cnt; ++j)             if (strcmp(f[i].para[j],  T ) && strcmp(f[i].para[j], para[j])) {               okay = false;               break;             }           res += okay;         }       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nxt[500005], to[500005], head[500005], fa[500005], f[500005][22],       dep[500005], ru[500005], tot;   bool vis[500005], used[500005];   queue<int> q;   vector<int> ei[500005];   void add(int u, int v) {     nxt[++tot] = head[u];     head[u] = tot;     to[tot] = v;     nxt[++tot] = head[v];     head[v] = tot;     to[tot] = u;   }   void dfs(int u, int p) {     dep[u] = dep[p] + 1;     f[u][0] = p;     for (int i = 1; i <= 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       dfs(v, u);     }   }   int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = 20; i >= 0; i--) {       if (dep[f[x][i]] >= dep[y]) {         x = f[x][i];       }     }     if (x == y) return x;     for (int i = 20; i >= 0; i--) {       if (f[x][i] != f[y][i]) {         x = f[x][i];         y = f[y][i];       }     }     return f[x][0];   }   int find(int x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   struct sad {     int x, y;   } a[500005];   int main() {     int n, x, y, u, v;     cin >> n;     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= n - 1; i++) {       scanf( %d%d , &x, &y);       add(x, y);     }     for (int i = 1; i <= n - 1; i++) {       scanf( %d%d , &a[i].x, &a[i].y);       ru[a[i].x]++;       ru[a[i].y]++;       ei[a[i].x].push_back(i);       ei[a[i].y].push_back(i);     }     dfs(1, 0);     for (int i = 1; i <= n - 1; i++) {       if (ru[a[i].x] == 1 || ru[a[i].y] == 1) {         used[i] = 1;         q.push(i);       }     }     int ans = 0;     cout << n - 1 << endl;     while (!q.empty()) {       int eg = q.front();       q.pop();       u = a[eg].x;       v = a[eg].y;       if (ru[u] != 1) swap(u, v);       int z = lca(u, v);       int p = find(u);       if (dep[p] > dep[z]) {         ans++;         fa[p] = find(f[p][0]);         printf( %d %d %d %d n , p, f[p][0], a[eg].x, a[eg].y);       } else {         int t = v;         for (int i = 20; i >= 0; i--)           if (dep[f[t][i]] > dep[z] && find(f[t][i]) != p) t = f[t][i];         fa[t] = find(f[t][0]);         printf( %d %d %d %d n , t, f[t][0], a[eg].x, a[eg].y);       }       ru[u]--;       ru[v]--;       if (ru[v] == 1) {         int mm = ei[v].size();         for (int i = 0; i < mm; i++) {           int ey = ei[v][i];           if (used[ey] == 0) q.push(ey), used[ey] = 1;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f;   const long long MAXN = 0x7fffffff;   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   void file() {}   void pr(bool num) { cout << (num == 1 ?  YES  :  NO ) <<   n ; }   signed main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     long long t, n;     cin >> t;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       long long ans = min(a, b);       ans = min(ans, c);       a -= ans;       b -= ans;       c -= ans;       long long num = min(a, b);       a -= num;       b -= num;       long long sum = a + b + c;       if (num <= sum)         ans += num;       else {         ans += sum;         num -= sum;         ans += num / 3 * 2;         if (num % 3 == 2) ans++;       }       cout << ans <<   n ;     }     return 0;   }


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     scanf( %d , &N);     int neg = 0, sum = 0;     int mini = 1005;     for (int i = 1; i < 2 * N; i++) {       int x;       scanf( %d , &x);       neg ^= x < 0;       x = abs(x);       mini = min(mini, x);       sum += x;     }     printf( %d n , sum - (neg && !(N % 2) ? 2 * mini : 0));     return 0;   }


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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