malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long inf = 2000000002;   pair<long long, long long> p[100005];   long long minl[100005], maxl[100005], minr[100005], maxr[100005];   int main() {     int i, j, n, a, b;     while (~scanf( %d , &n)) {       for (i = 0; i < n; i++) {         scanf( %d%d , &a, &b);         p[i] = make_pair(a - b, a + b);       }       sort(p, p + n);       minl[0] = maxl[0] = p[0].second;       for (i = 1; i < n; i++)         minl[i] = min(minl[i - 1], p[i].second),         maxl[i] = max(maxl[i - 1], p[i].second);       minr[n - 1] = maxr[n - 1] = p[n - 1].second;       for (i = n - 2; i >= 0; i--)         minr[i] = min(minr[i + 1], p[i].second),         maxr[i] = max(maxr[i + 1], p[i].second);       long long l = 0, r = 4 * inf;       while (l < r) {         long long s = (l + r) / 2;         bool can = 0;         j = 0;         for (i = 0; i < n; i++) {           while (j < n - 1 && p[j + 1].first - p[i].first <= s) j++;           if (i == 0 && j == n - 1) {             can = true;             break;           }           long long miny = inf, maxy = -inf;           if (i > 0) miny = min(minl[i - 1], miny), maxy = max(maxl[i - 1], maxy);           if (j < n - 1)             miny = min(miny, minr[j + 1]), maxy = max(maxr[j + 1], maxy);           if (maxy - miny <= s) can = true;           if (can) break;         }         if (can)           r = s;         else           l = s + 1;       }       double t = l * 0.5;       printf( %.8lf n , t);     }     return 0;   }
#include <bits/stdc++.h>   int map[2001][2001] = {0};   int ans[2001] = {0};   int n, m, k;   char ss[2001];   void show() {     int i, j;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         printf( %d , map[i][j]);       }       printf(  n );     }   }   int main() {     int i, j, k;     scanf( %d %d %d , &n, &m, &k);     for (i = 0; i < n; i++) {       scanf( %s , ss);       for (j = 0; j < m; j++) {         if (ss[j] ==  . ) {           map[i][j] = 0;         } else if (ss[j] ==  L ) {           map[i][j] = 1;         } else if (ss[j] ==  R ) {           map[i][j] = 2;         } else if (ss[j] ==  U ) {           map[i][j] = 4;         } else {           map[i][j] = 8;         }       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (map[i][j] == 1) {           if (i <= j) ans[j - i]++;         } else if (map[i][j] == 2) {           if (i < m - j) ans[i + j]++;         } else if (map[i][j] == 4) {           if (!(i & 1)) ans[j]++;         } else if (map[i][j] == 8) {         }       }     }     printf( %d , ans[0]);     for (i = 1; i < m; i++) {       printf(  %d , ans[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;   int main() {     int n, m, array1[100][100], mini, maxi = -OO, i, j;     scanf( %d %d , &n, &m);     for (i = 0; i < n; ++i) {       for (j = 0; j < m; ++j) {         scanf(  %d , &array1[i][j]);       }     }     for (i = 0; i < n; ++i) {       mini = OO;       for (j = 0; j < m; ++j) {         mini = min(mini, array1[i][j]);       }       maxi = max(maxi, mini);     }     printf( %d , maxi);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long i, j, k, l, n, m;     long long t;     cin >> t;     while (t--) {       cin >> n >> m;       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           if (i == 1 && j == 1)             cout <<  B ;           else if (i == 1 && j >= 2)             cout <<  W ;           else             cout <<  B ;         }         cout <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > bord(312345);   vector<int> ans;   int main() {     std::ios::sync_with_stdio(false);     int n, a, b, k;     cin >> n >> a >> b >> k;     string s;     cin >> s;     int i, sumi = 0, counter = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  1 ) {         counter++;       } else {         bord[counter].push_back(i + 1);       }     }     for (i = 0; i < counter + 1; i++) {       sumi += bord[i].size() / b;     }     sumi -= a;     sumi++;     cout << sumi << endl;     for (i = 0; i < counter + 1; i++) {       int val = bord[i].size();       int j = b - 1;       while (sumi) {         if (j < val) {           ans.push_back(bord[i][j]);           j += b;           sumi--;         } else {           break;         }       }     }     for (i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 10;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const double eps = 1e-10;   const double pi = acos(-1);   int T, cases, n, m;   int main() {     ios::sync_with_stdio(false);     ;     cin >> n >> m;     int ans;     if (n == 1 || m == 1)       ans = n * m;     else if (n == 2 || m == 2) {       if (m == 2) swap(n, m);       if (m % 4 == 1)         ans = m / 4 * 4 + 2;       else         ans = (m + 3) / 4 * 4;     } else       ans = max((n * m) / 2, (n * m) - (n * m / 2));     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1610;   typedef int MAP[maxn][maxn];   int n, m;   MAP A, B, flag, used;   int total;   int num[maxn * maxn], que[maxn * maxn * 2];   MAP temp;   int px[] = {0, 0, 1, -1, 0}, py[] = {1, -1, 0, 0, 0};   bool isok(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }   void zoomin(MAP X) {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int value = 1;         for (int x = 0; x < 5; x++)           if (isok(i + px[x], j + py[x]) && X[i + px[x]][j + py[x]] == 0)             value = 0;         temp[i][j] = value;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) X[i][j] = temp[i][j];   }   void zoomout(MAP X) {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int value = 0;         for (int x = 0; x < 5; x++)           if (isok(i + px[x], j + py[x]) && X[i + px[x]][j + py[x]] == 1)             value = 1;         temp[i][j] = value;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) X[i][j] = temp[i][j];   }   void bfs(int x, int y, int& index) {     index++;     int start = 1, tail = 0, sum = 0;     que[++tail] = x;     que[++tail] = y;     used[x][y] = 1;     while (start <= tail) {       x = que[start++];       y = que[start++];       flag[x][y] = index;       sum++;       for (int i = 0; i < 4; i++)         if (isok(x + px[i], y + py[i]) && !used[x + px[i]][y + py[i]] &&             B[x + px[i]][y + py[i]] == 1) {           used[x + px[i]][y + py[i]] = 1;           que[++tail] = x + px[i];           que[++tail] = y + py[i];         }     }     if (sum < 100) index--;   }   void bfs(int x, int y) {     int start = 1, tail = 0, sum = 0, index = 0;     que[++tail] = x;     que[++tail] = y;     used[x][y] = 1;     while (start <= tail) {       x = que[start++];       y = que[start++];       sum++;       for (int i = 0; i < 4; i++)         if (isok(x + px[i], y + py[i]) && !used[x + px[i]][y + py[i]] &&             A[x + px[i]][y + py[i]] == 1) {           if (!flag[x + px[i]][y + py[i]]) {             used[x + px[i]][y + py[i]] = 1;             que[++tail] = x + px[i];             que[++tail] = y + py[i];           } else {             index = flag[x + px[i]][y + py[i]];           }         }     }     if (sum > 2) num[index]++;   }   int main() {     scanf( %d%d , &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++) B[i][j] = A[i][j];     for (int i = 1; i <= 3; i++) zoomin(B);     for (int i = 1; i <= 4; i++) zoomout(B);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (!used[i][j] && B[i][j]) bfs(i, j, total);     memset(used, 0, sizeof(used));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (!used[i][j] && A[i][j] && !flag[i][j]) bfs(i, j);     sort(num + 1, num + 1 + total);     cout << total << endl;     for (int i = 1; i <= total; i++) cout << num[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int n, sum = 0;     scanf( %d , &n);     getchar();     char str[n];     gets(str);     for (int i = 0; i < n; i++) {       if (str[i] ==  + )         sum++;       else if (str[i] ==  -  && sum != 0)         sum--;     }     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int a[n], s = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         s += a[i];       }       if (s >= m)         cout << m << endl;       else         cout << s << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, inf = 0x3f3f3f3f;   int sa[N];   int rk[N];   int tmp[N];   int lcp[N];   char s[N], t[N];   int n, k;   bool cmp(int i, int j) {     if (rk[i] != rk[j])       return rk[i] < rk[j];     else {       int ri = i + k <= n ? rk[i + k] : -1;       int rj = j + k <= n ? rk[j + k] : -1;       return ri < rj;     }   }   void build(char *s, int *sa) {     n = strlen(s);     for (int i = 0; i <= n; i++) {       sa[i] = i;       rk[i] = i < n ? s[i] : -1;     }     for (k = 1; k <= n; k *= 2) {       sort(sa, sa + n + 1, cmp);       tmp[sa[0]] = 0;       for (int i = 1; i <= n; i++) {         tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);       }       for (int i = 0; i <= n; i++) {         rk[i] = tmp[i];       }     }   }   void LCP(char *s, int *sa, int *lcp) {     n = strlen(s);     for (int i = 0; i <= n; i++) rk[sa[i]] = i;     int h = 0;     lcp[0] = 0;     for (int i = 0; i < n; i++) {       int j = sa[rk[i] - 1];       for (h ? h-- : 0; j + h < n && i + h < n && s[j + h] == s[i + h]; h++)         ;       lcp[rk[i] - 1] = h;     }   }   int st[N], pos[N];   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %s , s);       int n = strlen(s);       build(s, sa);       LCP(s, sa, lcp);       for (int i = 0; i < n; i++) {       }       int now = 0;       lcp[n] = 0;       long long ans = 0;       for (int i = 1; i <= n; i++) {         int newpos = i, len = lcp[i];         while (now > 0 && st[now] > len) {           long long v1 = st[now] - max(st[now - 1], len);           long long v2 = i - pos[now] + 1;           ans += v1 * v2 * v2;           newpos = pos[now--];         }         st[++now] = len;         pos[now] = newpos;       }       for (int i = 0; i < n; i++) {         ans += n - i - max(lcp[rk[i] - 1], lcp[rk[i]]);       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2000;   int n, m, k, t, a[MAX_N + 1], b[MAX_N + 1], p[MAX_N + 1];   vector<int> x;   vector<int> y;   int main() {     int i, j, ans = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , a + i);     for (i = 1; i <= n; i++) scanf( %d , b + i), p[b[i]] = i;     for (i = 1; i <= n; i++) {       for (k = i;; k++)         if (p[a[k]] == i) break;       while (k != i) {         for (j = i; j <= k; j++)           if (p[a[j]] >= k) {             x.push_back(k);             y.push_back(j);             ans += k - j;             swap(a[j], a[k]);             k = j;           }       }     }     printf( %d n%d n , ans, x.size());     for (i = 0; i < x.size(); i++) printf( %d %d n , x[i], y[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char c;   int v[300], a;   int main() {     v[ > ] = 0;     v[ < ] = 1;     v[ + ] = 2;     v[ - ] = 3;     v[ . ] = 4;     v[ , ] = 5;     v[ [ ] = 6;     v[ ] ] = 7;     while (cin >> c) a = (a * 16 + 8 + v[c]) % 1000003;     cout << a << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   long long mod = 1000000007LL;   long long mod2 = 998244353LL;   int n, m, k;   bool a[1000005];   int main() {     cin >> n >> m >> k;     memset(a, false, sizeof(a));     for (int i = 1; i <= n; ++i) {       int ai;       scanf( %d , &ai);       a[ai] = true;     }     int ans = 0;     deque<int> dq;     for (int i = 1; i <= 1000001; ++i) {       if (a[i]) {         dq.push_back(i);       }       while (!dq.empty() && i - dq.front() >= m) {         dq.pop_front();       }       if (i >= m) {         int det = dq.size() - (k - 1);         if (det > 0) {           for (int j = 1; j <= det; ++j) {             dq.pop_back();             ans++;           }         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[5005][5005];   int len;   char st[5005];   bool palin[5005][5005];   void updateFreq(int r, int c) {     int cc;     while (r <= len) {       cc = c;       while (cc <= len) {         cnt[r][cc]++;         cc += (cc & (-cc));       }       r += (r & (-r));     }   }   int readFreq(int r, int c) {     int ret = 0;     int cc;     while (r > 0) {       cc = c;       while (cc > 0) {         ret += cnt[r][cc];         cc -= (cc & (-cc));       }       r -= (r & (-r));     }     return ret;   }   int main() {     scanf( %s , st + 1);     len = strlen(st + 1);     int q;     scanf( %d , &q);     for (int d = 0, lets_stop_here = (int)len + 1; d < lets_stop_here; d++) {       for (int i = 1, lets_stop_here = (int)len; i <= lets_stop_here; i++) {         int j = i + d;         if (j > len) break;         if (i == j)           palin[i][j] = true;         else if (j - i == 1)           palin[i][j] = st[i] == st[j] ? true : false;         else if (palin[i + 1][j - 1])           palin[i][j] = st[i] == st[j] ? true : false;         else           palin[i][j] = false;         if (palin[i][j]) updateFreq(i, j);       }     }     while (q--) {       int l, r;       scanf( %d %d , &l, &r);       int ans = readFreq(r, r) - readFreq(r, l - 1) - readFreq(l - 1, r) +                 readFreq(l - 1, l - 1);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e5 + 51;   const int mod1 = 1e9 + 7;   const int mod2 = 1e9 + 9;   std::vector<std::pair<int, int>> g[maxn];   int dfn[maxn], idx = 0;   int f[maxn], fw[maxn];   int xr;   std::vector<std::vector<int>> V;   void dfs(int u, int fa) {     dfn[u] = ++idx;     for (auto x : g[u]) {       int v = x.first, w = x.second;       if (v == fa) continue;       if (!dfn[v]) {         f[v] = u, fw[v] = w;         dfs(v, u);       } else if (dfn[v] > dfn[u]) {         std::vector<int> vec;         int cur = w;         for (int now = v; now ^ u; now = f[now]) cur ^= fw[now];         vec.push_back(cur ^ w);         for (int now = v; now ^ u; now = f[now]) vec.push_back(cur ^ fw[now]);         xr ^= cur;         V.push_back(vec);       }     }   }   int add(int x, int y, const int& mod) {     x += y;     return (x >= mod) ? x - mod : x;   }   int dec(int x, int y, const int& mod) {     x -= y;     return (x < 0) ? x + mod : x;   }   int n, m;   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);     std::cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v, w;       std::cin >> u >> v >> w;       g[u].push_back({v, w});       g[v].push_back({u, w});       xr ^= w;     }     dfs(1, 0);     static int a[1 << 17 | 3], b[1 << 17 | 3];     auto fwt = [&](int* f, int lim, const int& inv, const int& mod) {       for (int len = 1; len < lim; len <<= 1) {         for (int i = 0; i < lim; i += len << 1) {           for (int j = 0; j < len; j++) {             int x = f[i + j], y = f[i + j + len];             f[i + j] = add(x, y, mod);             f[i + j + len] = dec(x, y, mod);             if (inv > 1)               f[i + j] = 1ll * f[i + j] * inv % mod,                     f[i + j + len] = 1ll * f[i + j + len] * inv % mod;           }         }       }     };     a[xr] = 1, b[xr] = 1;     fwt(a, 1 << 17, 1, mod1);     fwt(b, 1 << 17, 1, mod2);     static int c[1 << 17 | 3], d[1 << 17 | 3];     for (auto v : V) {       memset(c, 0, sizeof(c));       memset(d, 0, sizeof(d));       for (auto x : v) c[x]++, d[x]++;       fwt(c, 1 << 17, 1, mod1);       fwt(d, 1 << 17, 1, mod2);       for (int i = 0; i < (1 << 17); i++) {         a[i] = 1ll * a[i] * c[i] % mod1;         b[i] = 1ll * b[i] * d[i] % mod2;       }     }     fwt(a, 1 << 17, (mod1 + 1) >> 1, mod1);     fwt(b, 1 << 17, (mod2 + 1) >> 1, mod2);     for (int i = 0; i < (1 << 17); i++)       if (a[i] || b[i]) {         std::cout << i <<     << a[i] <<   n ;         return 0;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9;   const long long mod = 998244353;   long long dp[N][1 << 7];   int s[N][1 << 7], st[N], Log[1 << 7];   struct node {     int v, id;   } a[N];   bool cmp(node a, node b) { return a.v > b.v; }   void upd(long long &a, long long b) {     if (a < b) a = b;   }   int main() {     int n, p, k;     for (int i = (1); i < (N); ++i) st[i] = st[i >> 1] + (i & 1);     for (int i = (0); i < (7); ++i) Log[1 << i] = i;     scanf( %d%d%d , &n, &p, &k);     for (int i = (1); i < (n + 1); ++i) {       scanf( %d , &a[i].v);       a[i].id = i;     }     sort(a + 1, a + 1 + n, cmp);     int op = (1 << p) - 1;     for (int i = (1); i < (n + 1); ++i)       for (int j = (0); j < (p); ++j) scanf( %d , &s[i][j]);     for (int i = (1); i < (p + k + 1); ++i) {       for (int mask = (0); mask < (1 << p); ++mask) {         if (st[mask] > i - 1) continue;         upd(dp[i - st[mask]][mask], dp[i - st[mask] - 1][mask] + a[i].v);         int pos = op ^ mask;         while (pos) {           upd(dp[i - st[mask] - 1][mask | ((pos) & (-pos))],               dp[i - st[mask] - 1][mask] + s[a[i].id][Log[((pos) & (-pos))]]);           pos ^= ((pos) & (-pos));         }       }     }     for (int i = (p + k + 1); i < (n + 1); ++i) {       for (int mask = (1 << p) - 1; mask >= (0); --mask) {         int pos = mask;         while (pos) {           upd(dp[k][mask],               dp[k][mask ^ ((pos) & (-pos))] + s[a[i].id][Log[((pos) & (-pos))]]);           pos ^= ((pos) & (-pos));         }       }     }     printf( %lld , dp[k][op]);   }
#include <bits/stdc++.h>   using namespace std;   long long ans[100010];   long long ans2[100010];   int main() {     int n, p;     int l, r;     while (cin >> n >> p) {       for (int i = 0; i < n; i++) {         scanf( %d%d , &l, &r);         ans[i] = r / p - l / p;         ans2[i] = r - l + 1;         if (l % p == 0) ans[i]++;       }       ans[n] = ans[0];       ans2[n] = ans2[0];       double anss = 0;       for (int i = 0; i < n; i++)         anss += ((ans[i] * (ans2[i + 1] - ans[i + 1]) +                   (ans2[i] - ans[i]) * ans[i + 1] + ans[i] * ans[i + 1]) *                  1.0) /                 (ans2[i] * ans2[i + 1] * 1.0) * 2000;       printf( %.10llf , anss);     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int IT_MAX = 1 << 17;   const long long MOD = 5000000;   const int INF = 1034567891;   const long long LL_INF = 1234567890123456789ll;   const double PI = 3.141592653589793238;   const double ERR = 1E-11;   int in[200050];   int lr[200050][2];   int v[200050];   int main() {     int N, T, K, i, j;     scanf( %d %d %d , &N, &T, &K);     for (i = 1; i <= T; i++) scanf( %d , &in[i]);     in[0] = 1;     for (i = 1; i < T; i++) {       lr[i][1] = in[i] - 1;       lr[i][0] = max(0, in[i] - in[i + 1]);     }     lr[T][0] = lr[T][1] = in[T];     int mn = 0, mx = 0;     for (i = 1; i <= T; i++) mn += lr[i][0], mx += lr[i][1];     if (K < mn || mx < K) return !printf( -1 n );     int t = K - mn;     for (i = 1; i <= T; i++) {       int t2 = min(t, lr[i][1] - lr[i][0]);       t -= t2;       v[i] = in[i] - (lr[i][0] + t2);     }     v[0] = 1;     printf( %d n , N);     int pst = 1;     for (i = 1; i <= T; i++) {       int st = pst + in[i - 1];       for (j = 0; j < v[i - 1]; j++) printf( %d %d n , pst + j, st + j);       for (j = v[i - 1]; j < in[i]; j++) printf( %d %d n , pst, st + j);       pst = st;     }     return 0;   }
#include<bits/stdc++.h>   #define LL long long   #define dl double   #define P pair<int,int>   using namespace std;      const int N = 2e5 + 10;      int n;   struct ghb{     int a,b;     bool operator < (const ghb &o)const{       return min(a,b) < min(o.a,o.b);     }   }f[N];   LL ans;   int mx;      int main(){     // freopen( in.txt , r ,stdin);     // freopen( o.txt , w ,stdout);     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n;     for(int i = 1;i <= n;i++)cin >> f[i].a;     for(int i = 1;i <= n;i++)cin >> f[i].b;     for(int i = 1;i <= n;i++)ans += abs(f[i].a - f[i].b);     sort(f + 1,f + n + 1);     int mx_1 = 0,mx_2 = 0;     for(int i = 1;i <= n;i++){       if(f[i].a > f[i].b){         if(mx_1)mx = max(mx,min(mx_1,f[i].a) - f[i].b);         mx_2 = max(mx_2,f[i].a);       }       else {         if(mx_2)mx = max(mx,min(mx_2,f[i].b) - f[i].a);         mx_1 = max(mx_1,f[i].b);       }     }     cout << ans - 2 * mx << endl;     return 0;   }   /**/
#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); }   bool isPrime(int x) {     for (int i = 2; i <= sqrt(x); i++)       if (x % i == 0) return 0;     return 1;   }   bool C[26];   int main() {     int n, a;     cin >> n >> a;     vector<int> v(n);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);     }     int ans = 0;     if (a - 1 < n - a) {       reverse(v.begin(), v.end());       a = n - a + 1;     }     a--;     for (int i = 0; i < a + 1; i++) {       if (v[i] == 1 && ((2 * a - i) >= n || i == a))         ans++;       else if (v[i] == 1 && v[2 * a - i] == 1)         ans += 2;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b;   long long c, d;   int main() {     while (cin >> a >> b) {       cin >> c >> d;       for (int i = 0; i <= 1000; ++i) {         for (int j = 0; j <= 1000; ++j) {           if ((b + a * i) == (d + c * j)) {             cout << b + a * i << endl;             return 0;           }         }       }       cout <<  -1  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int mid, i, j;       string a;       cin >> a;       if ((a.length()) % 2) {         cout <<  NO n ;         continue;       }       mid = (a.length()) / 2;       j = mid;       i = 0;       while (i < mid) {         if (a[i] == a[j]) {           i++;           j++;         } else {           cout <<  NO n ;           break;         }       }       if (i == mid) {         cout <<  YES n ;       }     }   }
#include <bits/stdc++.h>   const int N = 100100;   const long long mod = 1e9 + 7;   using namespace std;   int n, Xa, Ya, Xb, Yb;   int Smallest(int a, int b, int c, int d) {     int min_ = a;     if (min_ > b) min_ = b;     if (min_ > c) min_ = c;     if (min_ > d) min_ = d;     return min_;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> Xa >> Ya >> Xb >> Yb;     if ((Xa == Xb && (Xa == 0 || Xa == n)) || (Ya == Yb && (Ya == 0 || Ya == n)))       cout << abs(Xa - Xb) + abs(Ya - Yb) <<   n ;     else       cout << Smallest(abs(0 - Xa) + abs(0 - Ya) + abs(0 - Xb) + abs(0 - Yb),                        abs(0 - Xa) + abs(n - Ya) + abs(0 - Xb) + abs(n - Yb),                        abs(n - Xa) + abs(0 - Ya) + abs(n - Xb) + abs(0 - Yb),                        abs(n - Xa) + abs(n - Ya) + abs(n - Xb) + abs(n - Yb))            <<   n ;     return 0;   }