malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   void Max(T &a, U b) {     if (a < b) a = b;   }   template <class T, class U>   void Min(T &a, U b) {     if (a > b) a = b;   }   template <class T, class U>   void add(T &a, U b) {     a += b;     if (a >= 1000000007) a -= 1000000007;   }   template <class T, class U>   int min(T a, U b) {     return a >= b ? b : a;   }   int ans, first[50010], second[50010], a[50010], b[50010], res[50010], g[10240];   void out(int i, int j) {     cout <<  ?   << i <<     << j <<   n ;     cin >> ans;     fflush(stdout);   }   int main() {     int i, j, k, ca = 0, n, T, m = 0, K;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       out(i, i);       b[i] = ans;       out(i, 0);       a[i] = ans;     }     ans = 0;     int M = 4096 * 2;     for (int i = 0; i < n; i++) {       first[i] = 0;       for (int j = 0; j < n; j++) g[j] = -1;       int ok = 1;       for (int j = 0; j < n; j++) {         k = a[i] ^ a[j];         if (k >= n) {           ok = 0;           break;         }         g[k] = j;       }       if (!ok) continue;       for (int j = 0; j < n; j++) {         if (g[j] == -1) {           ok = 0;           break;         }         k = g[j];         first[k] = j;       }       if (!ok) continue;       for (int j = 0; j < n; j++) second[first[j]] = j;       for (int j = 0; j < n; j++) {         if ((first[j] ^ second[j]) != b[j]) {           ok = 0;           break;         }       }       if (!ok) continue;       for (int j = 0; j < n; j++) {         if ((first[j] ^ second[0]) != a[j]) {           ok = 0;           break;         }       }       if (!ok) continue;       ans++;       for (int j = 0; j < n; j++) res[j] = first[j];     }     printf( ! n%d n , ans);     for (int i = 0; i < n; i++) printf( %d  , res[i]);     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int n, A[5001], B[5001], S[5001], ma, man;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         S[A[j]]++;         if (S[A[j]] > ma || (S[A[j]] == ma && A[j] < man)) {           ma = S[A[j]];           man = A[j];         }         B[man]++;       }       ma = 0;       for (int j = 1; j <= n; j++) S[j] = 0;     }     for (int i = 1; i <= n; i++) cout << B[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 132222;   const long long mod = 1000000007;   char s[maxn];   int main() {     int n;     cin >> n;     cin >> s + 1;     int len = strlen(s + 1);     int l = -1, r = -1;     for (int i = (1); i < (len + 1); i++) {       if (s[i] ==  L  && l == -1) l = i;       if (s[i] ==  R  && r == -1) r = i;     }     if (l != -1 && r == -1) {       int x;       for (int i = len; i >= 1; i--) {         if (s[i] ==  L ) {           x = i;           break;         }       }       cout << x <<     << l - 1 << endl;       return 0;     }     if (l == -1 && r != -1) {       int x;       for (int i = len; i >= 1; i--) {         if (s[i] ==  R ) {           x = i;           break;         }       }       cout << r <<     << x + 1 << endl;       return 0;     }     if (l != -1 && r != -1) {       cout << r <<     << l - 1 << endl;       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 5e2 + 10;   const int P = 239017;   const int INF = 1e9;   const int MOD = 1e9 + 7;   int dp[MaxN][MaxN][2], n, m, q;   char s[MaxN][MaxN];   int get(int xl, int yl, int xr, int yr, int c) {     if (c == 0 && xl > xr) {       return 0;     }     if (c == 1 && yl > yr) {       return 0;     }     return dp[xr][yr][c] + dp[xl - 1][yl - 1][c] - dp[xr][yl - 1][c] -            dp[xl - 1][yr][c];   }   int main() {     scanf( %d%d n , &n, &m);     for (int i = 1; i <= n; ++i) {       gets(s[i] + 1);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         dp[i][j][0] = dp[i - 1][j][0] + dp[i][j - 1][0] - dp[i - 1][j - 1][0] +                       (s[i - 1][j] == s[i][j] && s[i][j] ==  . );         dp[i][j][1] = dp[i - 1][j][1] + dp[i][j - 1][1] - dp[i - 1][j - 1][1] +                       (s[i][j - 1] == s[i][j] && s[i][j] ==  . );       }     }     scanf( %d , &q);     while (q-- > 0) {       int xl, yl, xr, yr;       scanf( %d%d%d%d , &xl, &yl, &xr, &yr);       printf( %d n , get(xl + 1, yl, xr, yr, 0) + get(xl, yl + 1, xr, yr, 1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   const int maxn = 210000;   vector<int> e[maxn];   int h[maxn];   void dfsh(int v, int p) {     h[v] = 0;     for (int u : e[v]) {       if (u == p) continue;       dfsh(u, v);       uax(h[v], h[u] + 1);     }     sort((e[v]).begin(), (e[v]).end(), [&](int u, int w) { return h[u] > h[w]; });   }   vector<int> ord;   void dfsord(int v, int p, int l) {     bool anyc = false;     for (int u : e[v]) {       if (u == p) continue;       if (!anyc)         dfsord(u, v, l + 1), anyc = true;       else         dfsord(u, v, 1);     }     int r = !anyc ? l : 0;     ord.push_back(r);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     int n, k;     cin >> n >> k;     for (int i = 0; i < (int)(n - 1); ++i) {       int u, v;       cin >> u >> v;       --u;       --v;       e[u].push_back(v);       e[v].push_back(u);     }     dfsh(0, -1);     dfsord(0, -1, 1);     sort((ord).rbegin(), (ord).rend());     long long W = n;     long long ans = -1LL * (n / 2) * (n - n / 2);     for (int i = 0; i < (int)(k); ++i) {       W -= ord[i];       long long b = n / 2, r = i + 1;       long long res = 1e18;       if (b <= W) uin(res, (n - r - b) * (r - b));       if (b + 1 <= W) uin(res, (n - r - b - 1) * (r - b - 1));       uin(res, (n - r - W) * (r - W));       uax(ans, res);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 510;   const int MOD = 1e9 + 7;   long long dp[2][maxn][maxn];   int N, M;   char s[maxn][maxn];   void add(long long &x, long long y) {     x += y;     if (x >= MOD) x -= MOD;   }   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) scanf( %s , s[i] + 1);     dp[0][1][N] = (s[1][1] == s[N][M]);     int cur = 0;     for (int step = 1; step <= (M + N - 2) / 2; step++) {       cur ^= 1;       for (int i = 0; i <= N; i++)         for (int j = 1; j <= N; j++) dp[cur][i][j] = 0;       for (int x1 = 1; x1 <= N && x1 - 1 <= step; x1++) {         for (int x2 = N; x2 >= 1 && N - x2 <= step; x2--) {           int y1 = 1 + step - (x1 - 1);           int y2 = M - (step - (N - x2));           if (s[x1][y1] != s[x2][y2]) continue;           add(dp[cur][x1][x2], dp[cur ^ 1][x1][x2]);           add(dp[cur][x1][x2], dp[cur ^ 1][x1][x2 + 1]);           add(dp[cur][x1][x2], dp[cur ^ 1][x1 - 1][x2]);           add(dp[cur][x1][x2], dp[cur ^ 1][x1 - 1][x2 + 1]);         }       }     }     long long ans = 0;     for (int i = 1; i <= N; i++) {       add(ans, dp[cur][i][i]);     }     if ((N + M) % 2) {       for (int i = 1; i < N; i++) add(ans, dp[cur][i][i + 1]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, mod = 1e9 + 7;   const long long infl = LLONG_MAX / 2;   int n, ans, h[N];   vector<int> g[N], L;   void dfs(int u = 0, int p = -1) {     bool leaf = 1;     for (int x : g[u])       if (x - p) {         h[x] = h[u] + 1;         dfs(x, u);         leaf = 0;       }     if (leaf) L.push_back(h[u]);     if (h[u] == 1) {       sort(L.begin(), L.end());       int now = 0;       for (int i = 0; i < L.size(); ++i) {         now = max(now + 1, L[i]);       }       ans = max(ans, now - 1);       L.clear();     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int u, v;       scanf( %d %d , &u, &v);       --u;       --v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs();     cout << ans + 1;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y, z;     int a = 0, c = 0;     cin >> x;     cin >> y;     cin >> z;     for (int i = 0; i < x.length(); i++) {       for (int j = 0; j < z.length(); j++) {         if (x[i] == z[j]) {           c += 1;           z[j] =  1 ;           break;         }       }     }     for (int i = 0; i < y.length(); i++) {       for (int j = 0; j < z.length(); j++) {         if (y[i] == z[j]) {           a += 1;           z[j] =  1 ;           break;         }       }     }     if (c + a == z.length() && a == y.length() && c == x.length())       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   long long comb(long long n, long long r) {     if (r < 0 || r > n) return 0;     if ((n - r) < r) r = n - r;     long long vec = 1;     for (long long i = n; i > n - r; --i) {       vec = vec * i;     }     for (long long i = 1; i < r + 1; ++i) {       vec = vec / i;     }     return vec;   }   template <typename T>   void press(T &v) {     v.erase(unique(v.begin(), v.end()), v.end());   }   long long small(vector<long long> &vec, long long first) {     return lower_bound(vec.begin(), vec.end(), first) - vec.begin();   }   long long osmall(vector<long long> &vec, long long first) {     return upper_bound(vec.begin(), vec.end(), first) - vec.begin();   }   long long big(vector<long long> &vec, long long first) {     return vec.size() - osmall(vec, first);   }   long long obig(vector<long long> &vec, long long first) {     return vec.size() - small(vec, first);   }   long long freq(vector<long long> &vec, long long first) {     return upper_bound(vec.begin(), vec.end(), first) -            lower_bound(vec.begin(), vec.end(), first);   }   long long maxa(vector<long long> &vec) {     return max_element(vec.begin(), vec.end()) - vec.begin();   }   long long mina(vector<long long> &vec) {     return min_element(vec.begin(), vec.end()) - vec.begin();   }   long long Set(long long qq, long long pos) { return (qq | (1 << pos)); }   long long chk(long long qq, long long pos) { return (qq & (1 << pos)); }   long long bits(long long qq) { return __builtin_popcount(qq); }   long long p2[32];   long long modpow(long long first, long long n, long long m) {     if (n == 0) return 1 % m;     long long u = modpow(first, n / 2, m);     u = (u * u) % m;     if (n % 2 == 1) u = (u * first) % m;     return u;   }   long long _pow(long long vec, long long b) {     if (!b) return 1;     long long temp = _pow(vec, b / 2);     temp = (temp * temp);     if (b % 2) return (vec * temp);     return temp;   }   long long cl(long long vec, long long b) {     if (vec % b) return 1 + vec / b;     return vec / b;   }   long long dx[] = {0, 0, -1, 1};   long long dy[] = {1, -1, 0, 0};   const long long MOD = 1e9 + 7;   const long long inf = 1e18;   const long long N = 1e4 + 5;   const long long K = 1e3 + 10;   void solve() {     vector<long long> v;     long long n, ans = 0;     cin >> n;     if (n == 1) {       cin >> n;       cout << 0 << endl;       return;     }     for (long long i = 0; i < n; i++) {       long long val;       long long s = v.size();       cin >> val;       while (s > 1 && v[s - 1] <= val && v[s - 1] <= v[s - 2]) {         ans += min(val, v[s - 2]);         v.pop_back();         s--;       }       v.push_back(val);     }     sort(v.begin(), v.end());     for (long long i = 0; i < v.size() - 2; i++) ans += v[i];     cout << ans << endl;   }   signed main() {     for (long long i = 0; i < 32; i++) p2[i] = (1 << i);     cout << fixed << setprecision(12);     long long t;     t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   char s1[200010], s2[200010];   long long cal[200010][26], cal2[200010][26];   int main() {     int i, j, k, n;     long long qq = 0;     scanf( %d%s%s , &n, s1, s2);     for (i = 1; i <= n; i++) qq += (long long)i * i;     cal[0][s2[0] -  A ] = 1;     for (i = 1; i < n; i++) {       for (j = 0; j < 26; j++) cal[i][j] = cal[i - 1][j];       cal[i][s2[i] -  A ] += i + 1;     }     cal2[n - 1][s2[n - 1] -  A ] = 1;     for (i = n - 2; i >= 0; i--) {       for (j = 0; j < 26; j++) cal2[i][j] = cal2[i + 1][j];       cal2[i][s2[i] -  A ] += n - i;     }     long double res = 0;     for (i = 0; i < n; i++) {       res += (i + 1) * cal2[i][s1[i] -  A ];       if (i) res += (n - i) * cal[i - 1][s1[i] -  A ];     }     printf( %.12lf n , (double)(res / qq));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   bool a[20][2][1 << 17];   int ans = 1234, ami, apl;   void solve(int ind, int mx, int mi, int pl, int res) {     if (ind > 18) {       return;     }     if (mx == 0) {       if (res < ans) {         ans = res;         ami = mi;         apl = pl;       }       return;     }     for (int j = 0; j < (int)(2); ++j)       for (int i = 0; i < (int)(mx + 1); ++i) {         a[ind + 1][j][i] = false;       }     bool ok = true;     for (int j = 0; j < (int)(2); ++j)       for (int i = 1; i <= mx; i += 2)         if (a[ind][j][i]) {           ok = false;         }     int nmx = 0;     if (ok) {       for (int j = 0; j < (int)(2); ++j)         for (int i = 0; i < (int)(mx + 1); ++i)           if (a[ind][j][i]) {             int ni = i >> 1;             if (ni != 0) {               a[ind + 1][j][ni] = true;               nmx = max(nmx, ni);             }           }       solve(ind + 1, nmx, mi, pl, res);     } else {       for (int i = 0; i < (int)(mx + 1); ++i)         if (a[ind][0][i]) {           int ni = i >> 1;           if (ni != 0) {             a[ind + 1][0][ni] = true;             nmx = max(nmx, ni);           }         }       for (int i = 0; i < (int)(mx + 1); ++i)         if (a[ind][1][i]) {           int ni = i;           if (ni & 1) {             ++ni;           }           ni >>= 1;           if (ni != 0) {             a[ind + 1][1][ni] = true;             nmx = max(nmx, ni);           }         }       solve(ind + 1, nmx, mi, pl | (1 << ind), res + 1);       nmx = 0;       for (int j = 0; j < (int)(2); ++j)         for (int i = 0; i < (int)(mx + 1); ++i) {           a[ind + 1][j][i] = false;         }       for (int i = 0; i < (int)(mx + 1); ++i)         if (a[ind][1][i]) {           int ni = i >> 1;           if (ni != 0) {             a[ind + 1][1][ni] = true;             nmx = max(nmx, ni);           }         }       for (int i = 0; i < (int)(mx + 1); ++i)         if (a[ind][0][i]) {           int ni = i;           if (ni & 1) {             ++ni;           }           ni >>= 1;           if (ni != 0) {             a[ind + 1][0][ni] = true;             nmx = max(nmx, ni);           }         }       solve(ind + 1, nmx, mi | (1 << ind), pl, res + 1);     }   }   int main() {     scanf( %d , &n);     int mx = 0;     for (int i = 0; i < (int)(n); ++i) {       int x;       scanf( %d , &x);       if (x > 0) {         a[0][0][x] = true;         mx = max(mx, x);       }       if (x < 0) {         a[0][1][-x] = true;         mx = max(mx, -x);       }     }     solve(0, mx, 0, 0, 0);     printf( %d n , ans);     for (int i = 0; i < (int)(20); ++i)       if (apl & (1 << i)) {         printf( %d  , 1 << i);       } else if (ami & (1 << i)) {         printf( %d  , -(1 << i));       }     return 0;   }
#include <bits/stdc++.h>   const int oo = 1073741819;   using namespace std;   int f[200][500], n, t[500], w[500];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> t[i] >> w[i];     memset(f, 61, sizeof(f));     f[0][0] = 0;     for (int i = 1; i <= n; i++)       for (int j = 0; j <= i * 2; j++) {         if (j >= t[i]) f[i][j] = min(f[i][j], f[i - 1][j - t[i]]);         f[i][j] = min(f[i][j], f[i - 1][j] + w[i]);       }     int ans = 1073741819;     for (int j = 0; j <= n * 2; j++)       if (f[n][j] <= j) ans = min(ans, j);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   template <class T>   inline T bigmod(T p, T e, T M) {     if (e == 0) return 1;     if (e % 2 == 0) {       long long int t = bigmod(p, e / 2, M);       return (T)((t * t) % M);     }     return (T)((long long int)bigmod(p, e - 1, M) * (long long int)p) % M;   }   template <class T>   inline T bigexp(T p, T e) {     if (e == 0) return 1;     if (e % 2 == 0) {       long long int t = bigexp(p, e / 2);       return (T)((t * t));     }     return (T)((long long int)bigexp(p, e - 1) * (long long int)p);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   int dx4[] = {1, 0, -1, 0};   int dy4[] = {0, 1, 0, -1};   int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};   int nx8[] = {1, 1, -1, -1, 2, 2, -2, -2};   int ny8[] = {2, -2, 2, -2, 1, -1, 1, -1};   int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int n, a[100005], b[100005], c, com;   vector<int> v[100005];   map<int, int> m;   bool bl[100005];   void dfs(int p) {     if (bl[p]) return;     bl[p] = true;     v[com].push_back(p);     dfs(b[p]);   }   int main() {     scanf( %d , &n);     for (__typeof(n) i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (__typeof(n) i = (1); i <= (n); i++) b[i] = a[i];     sort(b + 1, b + n + 1);     for (__typeof(n) i = (1); i <= (n); i++) m[b[i]] = ++c;     for (__typeof(n) i = (1); i <= (n); i++) b[i] = m[a[i]];     for (int i = 1; i <= n; i++) {       if (bl[i] == false) {         ++com;         dfs(i);       }     }     cout << com, printf(  n );     for (__typeof(com) i = (1); i <= (com); i++) {       printf( %d , (int)v[i].size());       for (int j = 0; j < (int)v[i].size(); j++) printf(  %d , v[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int t;   int n;   string a, b;   int op[N];   int opb[N];   int bp = 0;   int ans = 0;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       ans = 0;       cin >> a;       cin >> b;       if (a == b) {         cout << 0 << endl;         continue;       }       char st = a[0];       for (int i = 1; i < n; i++) {         if (a[i] != st) {           op[++ans] = i;           st = a[i];         }       }       if (a[n - 1] ==  0 ) op[++ans] = n;       st = b[0];       bp = 0;       for (int i = 1; i < n; i++) {         if (b[i] != st) {           opb[++bp] = i;           st = b[i];         }       }       if (b[n - 1] ==  0 ) opb[++bp] = n;       cout << ans + bp;       for (int i = 1; i <= ans; i++) cout <<     << op[i];       for (int i = bp; i >= 1; i--) cout <<     << opb[i];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     if (n > 5 * m) {       cout <<  YES ;       return 0;     }     bool dp[n][m + 1];     for (int i = 0; i <= m; i++) dp[0][i] = false;     for (int i = 0; i < n; i++) dp[i][0] = true;     if (arr[0] % m == 0)       dp[0][m] = true;     else       dp[0][arr[0] % m] = true;     for (int i = 1; i < n; i++) {       for (int j = 1; j <= m; j++)         dp[i][j] = dp[i - 1][j] || dp[i - 1][(j - (arr[i] % m) + m) % m];     }     if (dp[n - 1][m])       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   long long __gcd(long long a, long long b) {     while (a != 0) {       long long __t = b % a;       b = a;       a = __t;     }     return b;   }   bool isSimple(unsigned x) {     for (unsigned i = 2; i < x; i++)       if (x % i == 0) return false;     return true;   }   int main() {     cin.tie(0);     cout.tie(0);     cerr.tie(0);     ios_base::sync_with_stdio(false);     long long x;     cin >> x;     cout << x - x / 2 - x / 3 - x / 5 - x / 7 + x / 6 + x / 10 + x / 14 + x / 15 +                 x / 21 + x / 35 - x / 30 - x / 42 - x / 70 - x / 105 + x / 210;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b;     while (~scanf( %d%d , &n, &b)) {       int a[2050];       int m = -999;       for (int i = 0; i < n; i++) scanf( %d , a + i);       for (int i = 0; i < n - 1; i++) {         int z = b / a[i];         for (int j = i + 1; j < n; j++) {           m = max(m, (a[j] - a[i]) * z + b);         }       }       if (m > b)         printf( %d n , m);       else         printf( %d n , b);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int get(int a, int b) {     if (a < b) return get(b, a);     if (a % b == 0) {       return a / b;     }     int c = a / b;     return get(b, a % b) + c;   }   int main() {     int N;     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int a, b;       scanf( %d%d , &a, &b);       printf( %d n , get(a, b));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200001];   long long a[26];   long long cnt = 0;   int main() {     long long i, j, k, l, m, n, t;     cin >> t;     cin >> s;     l = strlen(s);     for (i = 0; i < 26; i++) a[i] = 0;     for (i = 1; i < l; i = i + 2) {       if ((s[i - 1] - 97) != (s[i] - 65)) {         if (a[s[i] - 65] > 0) {           a[s[i] - 65]--;           a[s[i - 1] - 97]++;         } else {           cnt++;           a[s[i - 1] - 97]++;         }       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[101];   int res = 0;   void solve() {     for (int i = 2; i < n; ++i) {       if (a[i] == 0) {         if (a[i - 1] == 1 && a[i + 1] == 1 && a[i + 2] == 0 && a[i + 3] == 1 &&             i - 1 > 0) {           a[i + 1] = 0;           ++res;           i += 2;         } else if (a[i + 1] == 1 && a[i - 1] == 1 && i - 1 > 0) {           a[i + 1] = 0;           ++res;           ++i;         }       }     }     cout << res << endl;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans[1010][1010];   pair<int, int> a[1010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i].first), a[i].second = i;     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       int j = i;       while (a[i].first--) ans[j][a[i].second] = 1, j = (j + n) % (n + 1);     }     printf( %d n , n + 1);     for (int i = 0; i <= n; i++, puts(  ))       for (int j = 1; j <= n; j++) printf( %d , ans[i][j]);   }