malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX / 3;   const double EPS = 1e-14;   template <typename U, typename T>   void chmin(U &x, T y) {     x = min(x, y);   }   template <typename U, typename T>   void chmax(U &x, T y) {     x = max(x, y);   }   const long long int PRIMEMAX = 1e6;   long long int FACTOR[PRIMEMAX];   vector<long long int> Primes;   void sieve(long long int upb) {     FACTOR[0] = FACTOR[1] = -1;     for (long long int n = 2; n < upb; ++n) {       if (FACTOR[n] != 0) continue;       Primes.push_back(n);       long long int kn = n * n;       while (kn < PRIMEMAX) {         FACTOR[kn] = n;         kn += n;       }     }   }   bool is_prime(int n) {     if (PRIMEMAX > n) {       return FACTOR[n] == 0;     } else {       for (int p : Primes) {         if (n % p == 0) return false;       }       return true;     }   }   int main() {     cout << fixed << setprecision(12);     sieve(PRIMEMAX);     int n;     cin >> n;     vector<int> ps;     ps.push_back(n % 2 == 0 ? 2 : 3);     n -= ps[0];     if (n == 0) {       cout << 1 << endl;       cout << ps[0] << endl;       return 0;     }     if (is_prime(n)) {       cout << 2 << endl;       cout << ps[0] <<     << n << endl;       return 0;     }     for (int x : Primes) {       int y = n - x;       if (is_prime(y)) {         ps.push_back(x);         ps.push_back(y);         break;       }     }     cout << 3 << endl;     for (int i = 0; i < (3); i++) {       if (i > 0) cout <<    ;       cout << ps[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Get(int &T) {     char C;     bool F = 0;     for (; C = getchar(), C <  0  || C >  9 ;)       if (C ==  - ) F = 1;     for (T = C -  0 ; C = getchar(), C >=  0  && C <=  9 ; T = T * 10 + C -  0 )       ;     F && (T = -T);   }   int N, M;   int X[10005];   int Y[10005];   int G[1005][1005];   int A[10005];   void Debug() {     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= N; j++) printf( %d  , G[i][j]);       puts(  );     }   }   void Init() {     Get(N);     Get(M);     for (int i = 2; i < N; i++) Get(A[i]);     for (int k = 1; k <= N; k++) {       Get(X[k]);       X[k] *= M;       Get(Y[k]);       Y[k] *= M;     }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++)         if (i != j)           G[i][j] = std::abs(X[i] - X[j]) + std::abs(Y[i] - Y[j]) - A[i];   }   int Ans;   void Work() {     for (int k = 1; k <= N; k++)       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++)           if (G[i][j] > G[i][k] + G[k][j]) G[i][j] = G[i][k] + G[k][j];     Ans = G[1][N];   }   void Output() { printf( %d n , Ans); }   int main() {     Init();     Work();     Output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char f[1111][1111];   bool black[1111][1111];   bool is_free(int i, int j) {     return f[i][j] !=  .  && (f[i][j] <  a  || f[i][j] >  d );   }   bool can_hor(int i, int j) {     return (is_free(i, j) && is_free(i, j + 1) && is_free(i, j + 2)) &&            !black[i][j] && black[i][j + 1] && !black[i][j + 2];   }   bool can_vec(int i, int j) {     return (is_free(i, j) && is_free(i + 1, j) && is_free(i + 2, j)) &&            !black[i][j] && black[i + 1][j] && !black[i + 2][j];   }   bool place_hor(int i, int j) {     if (can_hor(i, j)) {       char fr = 0;       for (char cur =  a ; cur <=  d ; cur++) {         bool can = true;         for (int kj = j; kj <= j + 2; kj++) {           if (f[i - 1][kj] == cur || f[i + 1][kj] == cur || f[i][j - 1] == cur ||               f[i][j + 3] == cur) {             can = false;             break;           }         }         if (can) {           fr = cur;           break;         }       }       if (!fr) return false;       for (int kj = j; kj <= j + 2; kj++) {         f[i][kj] = fr;       }       return true;     }     return false;   }   bool place_vec(int i, int j) {     if (can_vec(i, j)) {       char fr = 0;       for (char cur =  a ; cur <=  d ; cur++) {         bool can = true;         for (int ki = i; ki <= i + 2; ki++) {           if (f[ki][j - 1] == cur || f[ki][j + 1] == cur || f[i - 1][j] == cur ||               f[i + 3][j] == cur) {             can = false;             break;           }         }         if (can) {           fr = cur;           break;         }       }       if (!fr) return false;       for (int ki = i; ki <= i + 2; ki++) {         f[ki][j] = fr;       }       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     memset(f,  . , sizeof(f));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> f[i][j];         if (f[i][j] ==  b )           black[i][j] = 1;         else if (f[i][j] ==  w )           black[i][j] = 0;         if (f[i][j] !=  . ) f[i][j] =    ;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (!is_free(i, j)) continue;         if (!place_hor(i, j)) {           if (!place_vec(i, j)) {             cout <<  NO ;             return 0;           }         }       }     }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cout << f[i][j];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000 + 7;   const double esp = 1e-13;   const double pi = 3.141592653589;   int n, m, f[100 + 10][100 + 10];   char a[100 + 10][100 + 10];   int main() {     ios ::sync_with_stdio(false);     cin >> n >> m;     for (int i = (1), _b = (n); i <= _b; i++)       for (int j = (1), _b = (m); j <= _b; j++) cin >> a[i][j];     memset(f, 0, sizeof(f));     for (int i = (1), _b = (n); i <= _b; i++)       for (int j = (1), _b = (m); j <= _b; j++) {         for (int k = (1), _b = (m); k <= _b; k++)           if (a[i][j] == a[i][k] && j != k) f[i][j] = 1, f[i][k] = 1;         for (int k = (1), _b = (n); k <= _b; k++)           if (a[i][j] == a[k][j] && i != k) f[i][j] = 1, f[k][j] = 1;       }     for (int i = (1), _b = (n); i <= _b; i++)       for (int j = (1), _b = (m); j <= _b; j++)         if (f[i][j] == 0) cout << a[i][j];   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, a[N], to[N];   vector<int> idx[N];   int is[N];   bool ok() {     for (int i = 0; i < n; ++i) is[a[i]] ^= 1;     bool prv = 0;     for (int i = 1; i <= n; ++i) {       if (!is[i]) continue;       if (prv) return 0;       prv = 1;     }     return 1;   }   bool plind() {     for (int i = 0; i * 2 + 1 < n; ++i)       if (a[i] != a[n - i - 1]) return 0;     return 1;   }   bool vis[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       idx[a[i]].push_back(i);     }     if (!ok()) return cout << 0, 0;     if (plind()) return cout << 1ll * n * (n + 1) / 2, 0;     int indx = n / 2;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j * 2 + 1 < idx[i].size(); ++j) {         to[idx[i][j]] = idx[i][idx[i].size() - j - 1];         to[idx[i][idx[i].size() - j - 1]] = idx[i][j];       }       if (idx[i].size() % 2 == 0) continue;       indx = idx[i][idx[i].size() / 2];       to[idx[i][idx[i].size() / 2]] = n / 2;     }     for (int i = 0; i < n; ++i)       if (to[i] == n - i - 1) vis[i] = 1;     int prel = 0;     while (a[prel] == a[n - prel - 1]) ++prel;     int prer = prel;     if (n % 2 && indx != n / 2) prer = max(prer, indx);     if (n % 2 && indx == n / 2) vis[n / 2] = 1;     for (int i = n - 1; i >= 0; --i)       if (to[i] >= 0 && !vis[i]) {         prer = max(prer, to[i]);         vis[to[i]] = 1;       }     long long ans = 1ll * (prel + 1) * (n - prer);     int sufr = n - 1;     while (a[sufr] == a[n - sufr - 1]) --sufr;     int sufl = sufr;     if (n % 2 && indx != n / 2) sufl = min(sufl, indx);     memset(vis, 0, sizeof vis);     if (n % 2 && indx == n / 2) vis[n / 2] = 1;     for (int i = 0; i < n; ++i)       if (to[i] == n - i - 1) vis[i] = 1;     for (int i = 0; i < n; ++i)       if (to[i] >= 0 && !vis[i]) {         sufl = min(sufl, to[i]);         vis[to[i]] = 1;       }     if (sufl <= prel) return cout << ans, 0;     ans += 1ll * (n - sufr) * (sufl - prel);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 51123987;   char str[152];   int a[152];   int dp[152][52][52][52];   int nxt[152][3];   signed main() {     int n;     scanf( %d , &n);     cin >> str + 1;     for (int i = 1; i <= n; i++) a[i] = str[i] -  a ;     nxt[n + 1][0] = nxt[n + 1][1] = nxt[n + 1][2] = n + 1;     for (int i = n; i >= 1; i--) {       nxt[i][0] = nxt[i + 1][0];       nxt[i][1] = nxt[i + 1][1];       nxt[i][2] = nxt[i + 1][2];       nxt[i][a[i]] = i;     }     int ans = 0;     dp[1][0][0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j1 = 0; j1 <= (n + 2) / 3; j1++)         for (int j2 = 0; j2 <= (n + 2) / 3; j2++)           for (int j3 = 0; j3 <= (n + 2) / 3; j3++) {             (dp[nxt[i][0]][j1 + 1][j2][j3] += dp[i][j1][j2][j3]) %= mod;             (dp[nxt[i][1]][j1][j2 + 1][j3] += dp[i][j1][j2][j3]) %= mod;             (dp[nxt[i][2]][j1][j2][j3 + 1] += dp[i][j1][j2][j3]) %= mod;             if (j1 + j2 + j3 == n && abs(j1 - j2) <= 1 && abs(j1 - j3) <= 1 &&                 abs(j2 - j3) <= 1)               ans += dp[i][j1][j2][j3], ans %= mod;           }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int ar[n];       for (int i = 0; i < n; i++) cin >> ar[i];       for (int i = n - 1; i >= 0; i--) cout << ar[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 10;   long long a[maxn], pre[maxn];   long long dp[maxn][maxn];   int main() {     int n, m, k;     while (~scanf( %d%d%d , &n, &m, &k)) {       for (int i = 1; i < n + 1; i++) {         scanf( %lld , &a[i]);         pre[i] = pre[i - 1] + a[i];       }       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= i / m; ++j)           dp[i][j] = max(dp[i - 1][j], dp[i - m][j - 1] + pre[i] - pre[i - m]);       cout << dp[n][k] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 110;   const int inf = 1000000000;   int main() {     int n, m, g[M][M] = {0};     double f[M][M] = {0.0};     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         g[i][j] = inf;         f[i][j] = 0;       }       g[i][i] = 0;     }     while (m--) {       int u, v;       cin >> u >> v;       g[u][v] = 1, f[u][v] = 1;       g[v][u] = 1, f[v][u] = 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= n; k++) {           if (g[j][k] > g[j][i] + g[i][k]) {             g[j][k] = g[j][i] + g[i][k];             f[j][k] = f[j][i] * f[i][k];           } else {             if (g[j][k] == g[j][i] + g[i][k]) {               f[j][k] += f[j][i] * f[i][k];             }           }         }       }     }     double ans = 1.0;     for (int i = 2; i < n; i++)       if (g[1][n] == g[1][i] + g[i][n])         ans = max(ans, (((double)2.0 * (f[1][i] * f[i][n])) / f[1][n]));     printf( %.20lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char op[20];   char s[205];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     getchar();     cin.getline(op, 15);     int dir;     if (op[3] ==  h ) {       dir = 0;     } else {       dir = 1;     }     scanf( %s , s);     int dir2 = m < k ? 0 : 1;     int len = strlen(s);     bool flag = false;     int t = 0;     for (int i = 0; i < len; ++i) {       ++t;       int lastk = k;       if (dir == 0) {         --k;         if (k == 0) k = 2, dir = 1;       } else {         ++k;         if (k == n + 1) k = n - 1, dir = 0;       }       if (s[i] ==  0 ) {         if (dir == 0) {           if (m > lastk && m < n)             ++m;           else if (m < lastk && m > 1)             --m;         } else {           if (m < lastk && m > 1)             --m;           else if (m > lastk && m < n)             ++m;         }       } else if (i != len - 1) {         if (dir == 0)           m = n;         else           m = 1;       }       if (m == k && i != len - 1) {         flag = true;         break;       }     }     if (!flag) {       puts( Stowaway );     } else {       printf( Controller %d n , t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int Inf = 1e9 + 5;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       ll sum = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         sum += a[i];       }       ll mx = 0, s = 0;       for (int i = 1; i < n; i++) {         s += a[i];         if (s < 0) s = 0;         mx = max(mx, s);       }       bool f1 = 0;       if (sum > mx) {         f1 = 1;       }       mx = 0;       s = 0;       for (int i = 0; i < n - 1; i++) {         s += a[i];         if (s < 0) s = 0;         mx = max(mx, s);       }       if (sum > mx && f1) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int kN = int(2E5 + 10), kInf = int(1E9 + 10), kC = int(1E6 + 10);   struct seg_tree {     long long int val[kN << 2], flag[kN << 2];     void init() {       memset(val, 0, sizeof(val));       memset(flag, 0, sizeof(flag));       return;     }     void addtag(int n, long long int x) {       flag[n] += x;       val[n] += x;     }     void push(int n) {       if (flag[n]) {         addtag(n << 1, flag[n]);         addtag(n << 1 | 1, flag[n]);         flag[n] = 0;       }       return;     }     void pull(int n) {       val[n] = max(val[n << 1], val[n << 1 | 1]);       return;     }     void fix(int n, int l, int r, int L, int R, long long int x) {       if (L <= l && r <= R)         addtag(n, x);       else if (!(l > R || L > r)) {         int mid = (l + r) >> 1;         push(n);         fix(n << 1, l, mid, L, R, x);         fix(n << 1 | 1, mid + 1, r, L, R, x);         pull(n);       }       return;     }   };   pair<int, int> wep[kN], eqi[kN];   pair<pair<int, int>, int> mon[kN];   int pos[kC];   seg_tree sg;   int main() {     int n, m, p, now = 1;     long long int ans;     scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; i++) scanf( %d%d , &wep[i].first, &wep[i].second);     for (int i = 1; i <= m; i++) scanf( %d%d , &eqi[i].first, &eqi[i].second);     for (int i = 1; i <= p; i++)       scanf( %d%d%d , &mon[i].first.first, &mon[i].first.second, &mon[i].second);     sort(wep + 1, wep + n + 1);     sort(eqi + 1, eqi + m + 1);     sort(mon + 1, mon + p + 1);     sg.init();     for (int i = 1; i <= m; i++) sg.fix(1, 1, m, i, i, -eqi[i].second);     for (int i = 0; i < kC; i++) {       while (now <= m) {         if (eqi[now].first <= i)           now++;         else           break;       }       pos[i] = now;     }     ans = -wep[1].second - eqi[1].second;     now = 1;     for (int i = 1; i <= n; i++) {       while (now <= p) {         if (mon[now].first.first < wep[i].first) {           if (pos[mon[now].first.second] <= m)             sg.fix(1, 1, m, pos[mon[now].first.second], m, mon[now].second);           now++;         } else           break;       }       ans = max(ans, sg.val[1] - wep[i].second);     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int n, a[25], d[25][25], f[1 << 25], ans = INT_MAX;   int popcnt(int x) {     int cnt = 0;     while (x > 0) cnt += (x & 1), x >>= 1;     return cnt;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       for (int j = 0; j < i; ++j) d[i][j] = -1;       for (int j = 0; j < i; ++j)         for (int k = j; k < i; ++k)           if (a[j] + a[k] == a[i]) d[i][j] = k, d[i][k] = j;     }     f[1] = true;     for (int i = 1; i < n; ++i)       for (int j = 1 << (i - 1); j < (1 << i); ++j)         if (f[j] == true)           for (int k = 0; k < i; ++k)             if (j & (1 << k) && d[i][k] >= 0 && (j & (1 << d[i][k]))) {               for (int l = 0; l <= i; ++l) f[(j & (~(1 << l))) | (1 << i)] = true;               break;             }     for (int i = 1 << (n - 1); i < (1 << n); ++i)       if (f[i] == true) ans = min(ans, popcnt(i));     if (ans == INT_MAX)       cout << -1;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double pi = 3.1415926535897932384626;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const int maxn = 1e2 + 5;   int t, n;   char s1[maxn], s2[maxn];   int main() {     t = read();     while (t--) {       n = read();       scanf( %s%s , s1, s2);       int minv = inf;       for (int i = 0; i < n; ++i) {         int k = i;         for (int j = 0; j < n; ++j) {           if (k < n && s1[j] == s2[k]) ++k;           minv = min(minv, n - k + i);         }       }       sort(s1, s1 + n);       sort(s2, s2 + n);       if (strcmp(s1, s2))         printf( -1 n );       else         printf( %d n , minv);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int ppl, s = 0, maxn = 0;     cin >> ppl;     int wel[ppl];     for (int j = 0; j < ppl; j++) {       cin >> wel[j];       if (maxn < wel[j]) {         maxn = wel[j];       }     }     for (int i = 0; i < ppl; i++) {       s = s + maxn - wel[i];     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, size = 1 << 20;   template <class o>   void qr(o &x) {     char c = getchar();     x = 0;     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     x *= f;   }   template <class o>   void qw(o x) {     if (x / 10) qw(x / 10);     putchar(x % 10 +  0 );   }   template <class o>   void pr1(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     putchar(   );   }   template <class o>   void pr2(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     puts(  );   }   int T, n, last, tot, f[N], b[N], c[N];   char s[N];   long long ans;   struct node {     int fa, len, v[26];   } tr[N];   void add(int c) {     int p = last, x = last = ++tot;     tr[x].len = tr[p].len + 1;     for (; p && tr[p].v[c] == 0; p = tr[p].fa) tr[p].v[c] = x;     if (!p)       tr[x].fa = 1;     else {       int q = tr[p].v[c], y;       if (tr[p].len + 1 == tr[q].len)         tr[x].fa = q;       else {         tr[y = ++tot] = tr[q];         tr[y].len = tr[p].len + 1;         tr[q].fa = tr[x].fa = y;         for (; p && tr[p].v[c] == q; p = tr[p].fa) tr[p].v[c] = y;       }     }   }   void init() {     memset(tr + 1, 0, tot * 28 << 2);     memset(f + 1, 0, tot << 2);     memset(c, 0, n + 1 << 2);     last = tot = 1;     ans = n = 0;   }   int main() {     qr(T);     while (T--) {       init();       scanf( %s , s + 1);       for (int i = 1; s[i]; i++) n++, add(s[i] -=  a ), f[last]++;       for (int i = 1; i <= tot; i++) c[tr[i].len]++;       for (int i = 1; i <= n; i++) c[i] += c[i - 1];       for (int i = tot; i; i--) b[c[tr[i].len]--] = i;       for (int i = tot, j; i; i--) {         j = b[i];         f[tr[j].fa] += f[j];         ans += (long long)f[j] * f[j] * (tr[j].len - tr[tr[j].fa].len);       }       pr2(ans);     }     return 0;   }
#include <bits/stdc++.h>   int H[10];   int main() {     memset(H, 0, sizeof(H));     for (int _n = 6, i = 0; i < _n; i++) {       int v;       scanf( %d , &v);       H[v]++;     }     bool n6, n4, n5, n2;     n6 = n4 = n5 = n2 = false;     for (int _n = 10, i = 0; i < _n; i++)       if (H[i] == 4)         n4 = true;       else if (H[i] == 6)         n6 = true;       else if (H[i] == 5)         n5 = true;       else if (H[i] == 2)         n2 = true;     if (n6 || (n4 && n2))       printf( Elephant n );     else if ((n4 && !n2) || n5)       printf( Bear n );     else       printf( Alien n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k;     cin >> n;     long long int a[n], b[n], c[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = 1;       c[i] = 1;     }     long long int ans = 1;     for (int i = 1; i < n; i++) {       if (a[i] > a[i - 1]) b[i] = b[i - 1] + 1;       ans = max(ans, b[i]);     }     c[n - 1] = 1;     for (int i = n - 2; i >= 0; i--) {       if (a[i + 1] > a[i]) c[i] = c[i + 1] + 1;       ans = max(ans, c[i]);     }     for (int i = 1; i <= n - 2; i++)       if (a[i + 1] > a[i - 1]) ans = max(ans, c[i + 1] + b[i - 1]);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int i;     map<string, string> mp1to2;     map<string, string> mp2to1;     map<string, int> mp1p;     map<string, int> mp2p;     for (i = 1; i <= m; i++) {       string w1, w2;       cin >> w1 >> w2;       mp1to2[w1] = w2;       mp2to1[w2] = w1;       mp1p[w1]++;       mp2p[w2]++;     }     for (i = 1; i <= n; i++) {       string word;       cin >> word;       if (mp1p[word] > 0) {         int len1 = word.length();         int len2 = mp1to2[word].length();         if (len1 <= len2) {           printf( %s  , word.c_str());         } else {           printf( %s  , mp1to2[word].c_str());         }       } else {         int len1 = mp2to1[word].length();         int len2 = word.length();         if (len1 <= len2) {           printf( %s  , mp2to1[word].c_str());         } else {           printf( %s  , word.c_str());         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long fact(long long n) {     if (n == 0 || n == 1)       return 1;     else       return n * fact(n - 1);   }   long long gcd(long long a, long long b) {     if (a < 0) a = -a;     if (b < 0) b = -b;     if (a == 1 || b == 1)       return 1;     else if (a == 0)       return b;     else if (b == 0)       return a;     else {       long long r = a > b ? a % b : b % a;       if (r == 0)         return min(a, b);       else         return gcd(min(a, b), r);     }   }   bool Comparator(int a, int b) { return (a >= b); }   long long M = 1e9 + 7;   long long solve() {     int n;     cin >> n;     vector<int> inf(n, 0), tt(n, 0), ans(n, 0);     for (long long i = 1; i < n; i++) {       cin >> inf[i];       inf[i]--;     }     tt[1] = 1;     for (long long i = 2; i < n; i++) {       tt[i] = tt[inf[i]] + 1;     }     for (long long i = 0; i < n; i++) {       ans[tt[i]]++;     }     long long sum = 0;     for (long long i = 0; i < n; i++) {       sum += ans[i] % 2;     }     return sum;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       cout << solve() <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, x = 0;     char arra[10];     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , arra);       if (arra[0] ==  +  || arra[1] ==  + )         x = x + 1;       else if (arra[0] ==  -  || arra[1] ==  - )         x = x - 1;     }     printf( %d n , x);   }