malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include<iostream>   #include<algorithm>   #include<vector>   #include<bitset>   #include<time.h>   using namespace std;   #define R register int   bitset<200000>S[60];   bool c[60];   int main(){    srand(time(0));    int n,m,p,q;    cin>>n>>m>>p;    q=n-1>>1;    string s;    for(R i=0;i!=n;i++){     cin>>s;     for(R j=0;j!=m;j++){      if(s[j]== 1 ){       S[j][i]=1;      }     }    }    vector<int>A,E;    for(int i=0;i!=m;i++){     c[i]=false;     if(S[i].count()>q){      A.push_back(i);     }    }    if(A.empty()==true){     for(R i=0;i!=m;i++){      cout<<0;     }     return 0;    }    p=0;    while(clock()<2950){     bitset<200000>B=S[A[p]];     vector<int>C,D;     D.push_back(A[p]);     for(R i=A.size()-1;i!=-1;i--){      if(i!=p){       C.push_back(A[i]);      }     }     random_shuffle(C.begin(),C.end());     for(vector<int>::iterator T=C.begin();T!=C.end();T++){      if((B&S[*T]).count()>q){       B&=S[*T];       D.push_back(*T);      }     }     if(D.size()>E.size()){      E=D;     }     p++;     if(p==A.size()){      p=0;     }    }    for(vector<int>::iterator T=E.begin();T!=E.end();T++){     c[*T]=true;    }    for(R i=0;i!=m;i++){     if(c[i]==true){      cout<<1;     }else{      cout<<0;     }    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const long long INF = 1000000000;   void solve() {     long long n;     string s;     cin >> n;     vector<long long> p(n);     vector<long long> ans(n);     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       p[--x] = i;     }     cin >> s;     long long ones = 1;     long long nuls = 1;     for (long long i = 0; i < n; i++)       if (s[i] ==  0 ) ++nuls;     for (long long i = 0; i < n; i++) {       if (s[p[i]] ==  0 ) {         ans[p[i]] = ones;         ++ones;       } else {         ans[p[i]] = nuls;         ++nuls;       }     }     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;     cout << endl;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;       #define send {ios_base::sync_with_stdio(false);}   #define help {cin.tie(NULL);}   #define f first   #define s second   #define pb push_back   #define vi vector<long long>   #define vii vector<pair<long long,long long>>   #define dict unordered_map<long long, long long>   #define contains(d,x) (d.find(x)!=d.end())      typedef long long ll;   typedef long double lld;   typedef unsigned long long ull;      const lld pi = 3.14159265358979323846;   const ll mod = 1000000007;   // const ll mod = 998244353;       ll n, m, k, l, p, q, r, x, y, z, sz;   const ll template_array_size = 1e6 + 5;   ll a[template_array_size];   ll b[template_array_size];   ll c[template_array_size];   string s, t;   ll ans = 0;   ll ts[5000000];      ll power(int x, int y){    if(!y) return 1;    ll temp = power(x, y/2);    temp = (temp*temp)%mod;    if(y&1){     return (temp*x)%mod;    }    return temp;   }      int find(int i, ll rep[]) {    int t = i;    while(rep[i]!=i){     i = rep[i];    }    while(rep[t]!=t){     t = rep[t];     rep[t] = i;    }    return i;   }      int onion(int i, int j, ll rep[]){    i = find(i,rep);    j = find(j,rep);    rep[j] = i;    return i!=j;   }      void solve(int tc = 0) {    cin >> n >> m;    vector<vii> adj(m+1);    vi chosen;    for(int i=0; i<m+1; i++) a[i] = i;    for(int i=0; i<n; i++) {     cin >> x;     if (x==1) {      cin >> y;      x = 0;     } else {      cin >> x >> y;     }     if(onion(x,y,a)){      chosen.pb(i+1);     }    }    p = chosen.size();    ans = power(2,p);    cout << ans <<     << p << endl;    for(int i : chosen) cout << i <<   ;    cout << endl;   }       int main() {           send help       // int tc = 1;    // cin >> tc;    // for (int t = 0; t < tc; t++) solve(t);    solve();   }
#include <bits/stdc++.h>   int main() {     int n, k, s = 0;     scanf( %d%d , &n, &k);     int a[n];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int j = 0; j < n; j++) {       if (n == k && a[j] >= a[k - 1] && a[j] > 0)         s++;       else if (a[j] >= a[k - 1] && a[j] > 0)         s++;     }     printf( %d , s);   }
#include <bits/stdc++.h>   using namespace std;   int a, b, m[1000];   int s = 0;   int main() {     int n;     cin >> n;     int z = n;     while (n > 0) {       s = 0;       cin >> a >> b;       while (a > 0 && b > 0) {         if (a >= b) {           int t = a / b;           a = a % b;           s += t;         } else {           int t = b / a;           b = b % a;           s += t;         }       }       m[z - n + 1] = s;       --n;     }     int j;     for (j = 1; j <= z; ++j) cout << m[j] << endl;   }
#include <bits/stdc++.h>   using namespace std;   void doRoutine() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     srand(322179);   }   const int C = 5010;   int tr[C * 8];   bool cross(pair<pair<int, int>, int> hor, pair<int, pair<int, int> > vert) {     return (vert.second.first <= hor.second &&             hor.second <= vert.second.second) &&            (hor.first.first <= vert.first && vert.first <= hor.first.second);   }   void init() {     for (int i = 0; i < C * 8; ++i) {       tr[i] = 0;     }   }   int get(int l, int r, int lb = -C, int rb = C, int v = 0) {     if (l == lb && r == rb) {       return tr[v];     } else {       int mb = (lb + rb) / 2;       if (r <= mb) {         return get(l, r, lb, mb, v * 2 + 1);       } else if (l >= mb) {         return get(l, r, mb, rb, v * 2 + 2);       } else {         return get(l, mb, lb, mb, v * 2 + 1) + get(mb, r, mb, rb, v * 2 + 2);       }     }   }   void add(int i, int x, int lb = -C, int rb = C, int v = 0) {     if (lb + 1 == rb) {       tr[v] += x;     } else {       int mb = (lb + rb) / 2;       if (i < mb) {         add(i, x, lb, mb, v * 2 + 1);       } else if (i >= mb) {         add(i, x, mb, rb, v * 2 + 2);       }       tr[v] = tr[v * 2 + 1] + tr[v * 2 + 2];     }   }   signed main() {     doRoutine();     int n;     cin >> n;     vector<pair<int, pair<int, int> > > verts;     vector<pair<pair<int, int>, int> > hors;     for (int i = 0; i < n; ++i) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x1 > x2) {         swap(x1, x2);       }       if (y1 > y2) {         swap(y1, y2);       }       if (x1 == x2) {         verts.push_back({x1, {y1, y2}});       } else {         hors.push_back({{x1, x2}, y1});       }     }     sort(verts.begin(), verts.end());     long long ans = 0;     for (int i = 0; i < verts.size(); ++i) {       vector<pair<int, int> > events;       for (auto seg : hors) {         if (cross(seg, verts[i])) {           events.push_back({seg.first.second, seg.second});         }       }       if (!events.empty()) {         sort(events.begin(), events.end());         reverse(events.begin(), events.end());         int ptr = 0;         init();         for (int j = (int)verts.size() - 1; j > i; --j) {           while ((ptr < events.size() && events[ptr].first >= verts[j].first)) {             add(events[ptr].second, 1);             ++ptr;           }           int cnt = get(verts[j].second.first, verts[j].second.second + 1);           ans += cnt * (cnt - 1) / 2;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( O3 )   #pragma GCC target( avx )   const long long INF = numeric_limits<long long>::max();   const long double PI = 3.1415926535898;   const long long MOD = 1000000007;   const long long LIM = 100005;   long long fpow(long long x, long long y) {     long long temp;     if (y == 0) return 1;     temp = fpow(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else       return x * temp * temp;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long modInverse(long long n, long long p) { return fpow(n, p - 2); }   map<long long, long long> primeFactors(long long n) {     map<long long, long long> mp;     while (n % 2 == 0) {       if (mp.count(2) == 1)         mp[2]++;       else         mp.insert({2, 1});       n = n / 2;     }     for (long long i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         if (mp.count(i) == 1)           mp[i]++;         else           mp.insert({i, 1});         n = n / i;       }     }     if (n > 2) {       if (mp.count(n) == 1)         mp[n]++;       else         mp.insert({n, 1});     }     return mp;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     for (long long tt = 1; tt <= t; ++tt) {       long long n, ans = 0;       cin >> n;       vector<long long> t(n + 1);       for (long long i = 1; i <= n; i++) cin >> t[i];       t[0] = 0;       sort(t.begin(), t.end());       ;       long long dp[n + 1][2 * n + 1];       for (long long i = 0; i <= n; i++)         for (long long j = 0; j <= 2 * n; j++) dp[i][j] = INF;       for (long long i = 0; i <= 2 * n; i++) dp[0][i] = 0;       for (long long i = 1; i <= n; i++) {         for (long long j = i; j <= 2 * n; j++) {           dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + abs(t[i] - j));         }       }       ans = dp[n][2 * n];       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[11][11];   int f[8][20][20];   int dx[] = {0, 1, -1, -1, 1, 1, 0, -1}, dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};   bool check() {     memset(f, 0, sizeof f);     for (int i = 1; i <= 10; i++)       for (int j = 1; j <= 10; j++) {         if (str[i][j] !=  X ) continue;         for (int k = 0; k < 4; k++) f[k][i][j] = f[k][i + dy[k]][j + dx[k]] + 1;       }     for (int i = 10; i >= 1; i--)       for (int j = 10; j >= 1; j--) {         if (str[i][j] !=  X ) continue;         for (int k = 4; k < 8; k++) f[k][i][j] = f[k][i + dy[k]][j + dx[k]] + 1;       }     for (int i = 1; i <= 10; i++)       for (int j = 1; j <= 10; j++)         for (int k = 0; k < 8; k++)           if (f[k][i][j] >= 5) return 1;     return 0;   }   int main() {     for (int i = 1; i <= 10; i++) scanf( %s , str[i] + 1);     for (int i = 1; i <= 10; i++)       for (int j = 1; j <= 10; j++) {         if (str[i][j] !=  . ) continue;         str[i][j] =  X ;         if (check()) {           puts( YES );           return 0;         }         str[i][j] =  . ;       }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, l, r, mid, a;   int main() {     cin >> n >> k;     a = 240 - k;     l = 0;     r = n + 1;     while (r - l > 1) {       mid = (r + l) / 2;       if (5 * (mid * (mid + 1) / 2) > a) {         r = mid;       } else {         l = mid;       }     }     cout << l << endl;     return 0;   }
//Saptak_Roy_Turja   #include<bits/stdc++.h>   #define ll long long int   using namespace std;   int main()   {       int t;       cin>>t;       while(t--){           ll n,a,b,c=1,i;           string s;           cin>>n>>a>>b>>s;           for(i=1;i<n;i++){               if(s[i]!=s[i-1]){                   c++;               }           }           if(b>=0){               cout<<n*(a+b)<<  n ;           }           else {               cout<<n*a+b*(c/2+1)<<  n ;           }       }   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, l, r, mid, ans;   long long a[200100];   bool check(long long x) {     long long p, q;     double sum = 0, s;     for (long long i = 1; i <= n; i++) {       if (a[i] == 0) continue;       s = a[i];       if (a[i] >= k) return 1;       p = x - 1;       q = n - i + x - 1;       p = min(p, q - p);       while (p) {         s = s * q / p;         p--;         q--;         if (s >= k) return 1;       }       sum += s;       if (sum >= k) return 1;     }     return 0;   }   int main() {     scanf( %I64d%I64d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);       if (a[i] >= k) {         puts( 0 );         return 0;       }     }     l = 1;     r = k;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const string yno[2] = { NO n ,  YES n };   int dem(vector<int> &a, int k) {     return upper_bound(a.begin(), a.end(), k) -            lower_bound(a.begin(), a.end(), k);   }   int dem(long long k) {     int ans = 0;     while (k) {       ans += k & 1;       k >>= 1;     }     return ans;   }   void process() {     int n, m;     cin >> n >> m;     vector<int> a(n), b(m);     for (int &i : a) cin >> i;     for (int &i : b) cin >> i;     vector<pair<long long, long long> > c;     map<int, pair<long long, long long> > M;     for (int i = 0; i <= n - 1; i++) {       for (int j = 0; j <= m - 1; j++) {         M[a[i] + b[j]].first |= (1ll << i);         M[a[i] + b[j]].second |= (1ll << j);       }     }     for (auto it = M.begin(); it != M.end(); it++) {       c.push_back(it->second);     }     int ans = 0;     for (int i = 0; i < c.size(); i++) {       for (int j = i; j < c.size(); j++) {         ans = max(ans, __builtin_popcountll(c[i].first | c[j].first) +                            __builtin_popcountll(c[i].second | c[j].second));       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     process();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 252;   int dis(int x1, int y1, int x2, int y2) { return abs(x1 - x2) + abs(y1 - y2); }   bool Gao(int x1, int y1, int x2, int y2) {     if (dis(0, 0, x1, y1) <= max(x2, y2)) return true;     for (int i = 1; i <= min(x2, y2); ++i) {       if (dis(x2 - i, y2 - i, x1, y1) <= i) return true;     }     return false;   }   int main() {     int x1, x2, y1, y2;     while (cin >> x1 >> y1 >> x2 >> y2) {       if (Gao(x1, y1, x2, y2))         cout <<  Polycarp  << endl;       else         cout <<  Vasiliy  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p[1005];   vector<int> T;   bool ok;   inline void enter() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];   }   void dfs(int u) {     while (T[u] != 1) {       T[u]++;       u = p[u];     }     cout << u <<    ;   }   inline void solve() {     for (int i = 1; i <= n; i++) {       T.assign(n + 4, 0);       dfs(i);     }   }   int main() {     enter();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t;   string s;   int puc(int k, int t) {     vector<int> v(n + 1, 0);     v[n - 1] = (s[n - 1] ==  H );     for (int i = n - 2; i >= 0; --i) v[i] = v[i + 1] + (s[i] ==  H );     int nh = 0, ns = 0;     for (int i = 0; i < int(n); ++i) {       if (s[i] ==  H )         ++nh;       else if (s[i] ==  S )         ++ns;     }     if (k + ns < nh) return 0;     int zk = k;     int ret = 0;     int qui = -1, q = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  S ) {         ++k;         --ns;       } else if (s[i] ==  H ) {         --nh;         if (k > 0)           --k;         else if (qui == -1) {           qui = i;           q = 1;         } else           ++q;       }       if (nh == 0 and k >= q) {         if (qui == -1 and ret < t) return true;         if (ret + (i - qui) < t) return true;         break;       }       ++ret;     }     k = zk;     int ult = -1;     int r = 0;     int ans = 0;     for (int i = 0; i < int(n); ++i) {       if (s[i] ==  S ) ++k;       if (k >= r and ult != -1) {         ans += i - ult;         if (v[i] > 0) ans += i - ult;         k -= r;         ult = -1;         r = 0;       }       if (s[i] ==  H ) {         if (k > 0)           --k;         else if (ult == -1) {           ult = i;           r = 1;         } else           ++r;       }       if (ult == -1 and v[i + 1] == 0) break;       ++ans;     }     return (ult == -1 and ans < t);   }   int main() {     cin >> n >> t;     cin >> s;     int lo = 0, hi = n, m;     while (hi - lo > 5) {       int m = (lo + hi) / 2;       if (puc(m, t))         hi = m;       else         lo = m;     }     bool trobat = 0;     if (puc(0, t)) {       cout << 0 << endl;       trobat = true;     }     for (int k = lo; !trobat and k <= hi; ++k) {       if (puc(k, t)) {         cout << k << endl;         trobat = true;       }     }     if (!trobat) cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const string YES =  Yes ;   const string NO =  No ;   string solve() {     int N;     cin >> N;     vector<int> p(N);     for (int i = 0; i < (N); ++i) {       cin >> p[i];     }     for (int i = 0; i < (N - 1); ++i) {       if (p[i] + 1 == p[i + 1]) {         continue;       }       if (p[i] > p[i + 1]) {         continue;       }       return NO;     }     return YES;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     for (int t = 0; t < (T); ++t) {       cout << solve() << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[6], i, sum = 0;     for (i = 0; i < 5; i++) {       scanf( %d , &arr[i]);       sum = sum + arr[i];     }     if (sum == 0) {       printf( -1 n );     } else if (sum % 5 == 0) {       printf( %d , sum / 5);     } else {       printf( -1 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b, c, ans, boby, apu;     cin >> n;     while (n--) {       cin >> a >> b >> c >> ans;       boby = b - a;       apu = c + ans;       if (boby % apu == 0) {         cout << boby / apu << endl;       } else         cout <<  -1  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9;   const int N = 5001;   const int maxxor = (1 << 13);   int f[2][maxxor];   vector<int> a[N];   int cnp(int l, int r, int pos, int id) {     if (l > r) return oo;     int mid = (l + r) / 2;     if (a[id][mid] > pos) return min(a[id][mid], cnp(l, mid - 1, pos, id));     return cnp(mid + 1, r, pos, id);   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a[x].push_back(i);     }     for (int i = 0; i <= 1; i++)       for (int j = 0; j < maxxor; j++) f[i][j] = oo;     f[0][0] = 0;     int id;     vector<int> res;     for (int i = 1; i < N; i++) {       int now = i & 1;       int back = now ^ 1;       for (int j = 0; j < maxxor; j++) {         f[now][j] = f[back][j];         if (a[i].size() == 0) {           if (i == N - 1 && f[now][j] != oo) res.push_back(j);           continue;         }         int pos = f[back][j ^ i];         id = cnp(0, a[i].size() - 1, pos, i);         if (id != oo) f[now][j] = min(f[now][j], id);         if (i == N - 1 && f[now][j] != oo) res.push_back(j);       }     }     cout << res.size() << endl;     for (int xnew : res) cout << xnew <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int add(int a, int b) {     return (a + b >= 1000000007) ? a + b - 1000000007 : a + b;   }   inline void inc(int &a, int b) { a = add(a, b); }   inline int sub(int a, int b) {     return (a - b < 0) ? a - b + 1000000007 : a - b;   }   inline void dec(int &a, int b) { a = sub(a, b); }   inline int mul(int a, int b) { return 1ll * a * b % 1000000007; }   inline void grow(int &a, int b) { a = mul(a, b); }   const int INV = 205555557;   int phi[1000005];   int pre[1000005];   int f[1000005];   int onepre[1000005];   int twopre[1000005];   void phiCalc() {     phi[0] = 0;     phi[1] = 1;     for (int i = 2; i <= 1000005 - 1; i++) phi[i] = i;     for (int i = 2; i <= 1000005 - 1; i++) {       if (phi[i] == i) {         for (int j = i; j <= 1000005 - 1; j += i) phi[j] -= phi[j] / i;       }     }   }   int func(int n, int m) {     int res = sub(0, INV);     grow(res, n);     grow(res, n + 1);     grow(res, n + 2);     int tres = 15;     inc(tres, mul(4, mul(n, mul(n, n))));     dec(tres, mul(12, mul(n, n)));     dec(tres, mul(7, n));     int ttres = mul(n, n);     dec(ttres, mul(3, n));     dec(ttres, 3);     grow(ttres, sub(0, 6));     grow(ttres, m);     return mul(res, add(tres, ttres));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     phiCalc();     for (int i = 1; i < 1000005; i++) {       for (int j = i; j < 1000005; j += i) inc(f[j], mul(i, phi[j / i]));     }     pre[0] = f[0];     onepre[0] = twopre[0] = 0;     for (int i = 1; i < 1000005; i++) {       pre[i] = add(pre[i - 1], f[i]);       onepre[i] = add(onepre[i - 1], mul(i, f[i]));       twopre[i] = add(twopre[i - 1], mul(mul(i, i), f[i]));     }     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       if (n > m) swap(n, m);       int ans = 0;       inc(ans, pre[n]);       inc(ans, twopre[n]);       dec(ans, mul(2, onepre[n]));       inc(ans, mul(m, mul(n, pre[n])));       dec(ans, mul(m, onepre[n]));       inc(ans, mul(m, pre[n]));       dec(ans, mul(n, onepre[n]));       inc(ans, mul(n, pre[n]));       grow(ans, 2);       inc(ans, func(n, m));       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int f = 1, x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     return x * f;   }   int len[300 + 5];   string str[300 + 5];   bool vis[300 + 5][300 + 5];   int main() {     int n = read(), Ans;     for (int i = 1; i <= n; i++) {       cin >> str[i];       len[i] = int(str[i].length()) + len[i - 1];     }     Ans = len[n] + n - 1;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         int tmp = 0;         if (vis[i][j]) continue;         vis[i][j] = 1;         for (int t = j + 1; t <= n - j + i; t++) {           bool flag = 0;           for (int s = 0; s <= j - i; s++)             if (str[i + s] != str[t + s]) {               flag++;               break;             }           if (!flag) tmp++, t += j - i, vis[t][t + j - i] = 1;         }         if (tmp != 0) {           int tot = len[n] - (tmp + 1) * (len[j] - len[i - 1]) + tmp + n;           Ans = min(Ans, tot);         }       }     }     printf( %d n , Ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18, MAXN = 1e5 + 128, MOD = 998244353;   long long binpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n & 1) res *= a;       a *= a;       n >>= 1;     }     return res;   }   long long NOD(long long NOD1, long long NOD2) {     while (NOD2) {       NOD1 %= NOD2;       swap(NOD1, NOD2);     }     return NOD1;   }   long long NOK(long long NOK1, long long NOK2) {     return NOK1 * NOK2 / NOD(NOK1, NOK2);   }   long long n, i1, i2;   string s;   char a, b;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> s;     a = s[0];     for (int i = 0; i < n; i++)       if (a == s[i])         i1 = i;       else         break;     b = s[n - 1];     for (int i = n - 1; i >= 0; i--)       if (b == s[i])         i2 = i;       else         break;     i2 = n - i2;     if (b == a)       cout << ((i1 + 2) * (i2 + 1)) % MOD;     else       cout << (i2 + i1 + 2) % MOD;   }
#include <bits/stdc++.h>   using namespace std;   const int maxint = 0x7fffffff;   const int minint = 0x80000000;   const double eps = 1e-6;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int max(int a, int b) { return a > b ? a : b; }   int main() {     int sum, d, n, a;     scanf( %d , &d);     scanf( %d , &n);     sum = 0;     while (--n) {       scanf( %d , &a);       sum += d - a;     }     scanf( %d , &a);     printf( %d n , sum);     return 0;   }