malteklaes/cpp-code-code_search_net-style huggingface dataset:
//Jai Shree Ram   #include<bits/stdc++.h>   using namespace std;   #define   f(a,b,n)        for(ll a=b;a<n;a++)   #define   readarr(arr,n)  f(i,0,n) cin>>arr[i];   #define   ll              long long   #define   pb              push_back   #define   fastio            ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)   #define   all(x)          x.begin(), x.end()   #define   mod             1000000007    #define   w(t)            int t; cin>>t; while(t--)    #define   fi              first   #define   sd              second                                                                                                                                                                                                                              #define   sp(x,y)         fixed<<setprecision(y)<<x                 #define   trace(x)     cout<<#x<< :  <<x<<endl;    #define   trav(a, x)      for(auto& a : x)    #define   setbits(x)      __builtin_popcountll(x)     #define   zrobits(x)      __builtin_ctzll(x)     #define   pqmax           priority_queue<ll>   #define   pqmin           priority_queue<ll,vi,greater<ll>>                            #define   vi              vector<ll>   #define   mpi              map<ll,ll>    #define   pi              pair<ll,ll>     #define   N               1e5      #define   inf             1e18    #define   nline             n    void c_a_c()   {    #ifndef ONLINE_JUDGE    freopen( input.txt , r ,stdin);    freopen( output.txt , w ,stdout);    #endif   }   int main()   {    c_a_c();    ll t;    cin>>t;    while(t--)    {     ll n;     cin>>n;        vector<long long> v[n+1];        long long array[n];        for(long long i = 0; i < n; i++) {         cin >> array[i];        }        long long x;        for(long long i = 0; i < n; i++) {         cin >> x;         v[array[i]].push_back(x);        }        for(long long i = 1; i <= n; i++) {         sort(all(v[i]));         reverse(all(v[i]));        }        long long ans[n+1];        for(long long i = 1; i <= n; i++) {         ans[i] = 0;        }        for(long long i  = 1; i <= n; i++) {         for(long long j  = 1; j < v[i].size(); j++) {          v[i][j] += v[i][j-1];         }         for(long long j = 1; j <= v[i].size(); j++) {          long long temp = v[i].size() % j;          ans[j] += v[i][v[i].size() - temp-1];         }        }        for(long long i = 1; i <= n; i++) {         cout << ans[i] <<    ;        }        cout <<   n ;       }   }
#include <bits/stdc++.h>   using namespace std;   bool flag = 0, flag1 = 0, flag2 = 0;   string t =  abacaba ;   int check(string s) {     long long int x = 0;     for (long long int i = 0; i < s.size(); i++) {       if (s.substr(i, 7) == t) {         x++;       }     }     return x;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int tt = 1;     cin >> tt;     while (tt--) {       long long int n;       cin >> n;       string s;       cin >> s;       long long int ans = 0;       ans = check(s);       if (ans == 0) {         for (long long int i = 0; i < n - 6; i++) {           if (s[i] == t[0] || s[i] ==  ? ) {             flag = 0;             for (long long int j = 0; j < 7; j++) {               if (s[j + i] != t[j] && s[i + j] !=  ? ) {                 flag = 1;                 break;               }             }             if (flag == 0) {               string temp = s;               for (long long int j = 0; j < 7; j++) temp[i + j] = t[j];               if (check(temp) == 1) {                 ans++;                 s = temp;                 break;               }             }           }         }       }       if (ans == 1) {         cout <<  Yes n ;         for (long long int i = 0; i < s.size(); i++) {           if (s[i] ==  ? )             cout <<  d ;           else             cout << s[i];         }         cout <<   n ;       } else         cout <<  No n ;     }   }
#include <bits/stdc++.h>   using namespace std;   struct rua {     long double x, y;   } m;   set<pair<long double, long double> > p;   vector<pair<long double, long double> > del;   vector<long double> d;   set<long double> mm;   int n, ans;   long double x, y;   bool tt;   bool check(rua T) {     d.clear();     rua M = {(T.x + x) / 2, (T.y + y) / 2};     rua mM = {M.x - m.x, M.y - m.y};     rua r0 = {mM.y, -mM.x};     if (!r0.x)       if (tt)         return false;       else         tt = true;     long double k = r0.y / r0.x;     if (mm.count(k))       return false;     else       mm.insert(k);     long double R = pow(r0.x * r0.x + r0.y * r0.y, 0.5);     for (auto i = p.begin(); i != p.end(); i++) {       rua mP = {(*i).first - m.x, (*i).second - m.y};       long double t = r0.x * mP.x + r0.y * mP.y;       t /= r0.x * r0.x + r0.y * r0.y;       if (t) d.push_back(t);     }     long double _ = (r0.x * mM.x + r0.y * mM.y) / R;     int l = 0, r = d.size() - 1;     sort(d.begin(), d.end());     while (l <= r && d[l] + d[r] == 0) l++, r--;     return l > r;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       cin >> x >> y;       p.insert(make_pair(x, y));       m.x += x, m.y += y;     }     m.x = m.x * 1.0 / n, m.y = m.y * 1.0 / n;     for (auto i = p.begin(); i != p.end(); i++) {       x = (*i).first, y = (*i).second;       if (p.count(make_pair(2 * m.x - x, 2 * m.y - y)))         del.push_back(make_pair(2 * m.x - x, 2 * m.y - y)), del.push_back(*i);     }     for (int i = 0; i < del.size(); i++)       if (p.count(del[i])) p.erase(del[i]);     if (!p.size()) return printf( -1 n ), 0;     x = (*p.begin()).first, y = (*p.begin()).second;     for (auto i = p.begin(); i != p.end(); i++)       if (check({(*i).first, (*i).second})) ans++;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     long long n;     cin >> n;     long long num = 1e5 + 3;     long long pos[num];     for (int i = 0; i < n; ++i) {       long long a;       cin >> a;       pos[a] = i + 1;     }     long long m;     cin >> m;     long long counta = 0, countb = 0;     for (int j = 0; j < m; ++j) {       long long b;       cin >> b;       counta += pos[b];       countb += n - pos[b] + 1;     }     cout << counta <<     << countb;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const long long inf = 1e9 + 7;   long long mod = 998244353;   vector<int> a;   int solve(vector<int> &b, int bit) {     vector<int> l, r;     if (b.size() == 0 || bit < 0) return 0;     for (int i = 0; i < b.size(); i++) {       if ((b[i] >> bit) & 1 == 1)         l.push_back(b[i]);       else         r.push_back(b[i]);     }     if (l.size() == 0) return solve(r, bit - 1);     if (r.size() == 0) return solve(l, bit - 1);     return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit);   }   int main(void) {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       a.push_back(x);     }     int ans = solve(a, 30);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n, m, u, v, w, answer, capital, intree, l, dis[N];   vector<pair<int, int> > nei[N];   vector<pair<int, pair<int, int> > > edge;   bool done[N];   priority_queue<pair<int, int> > pq;   int main() {     cin >> n >> m >> capital;     capital--;     for (int i = 0; i < m; i++) {       cin >> u >> v >> w;       u--, v--;       nei[v].push_back(make_pair(u, w));       nei[u].push_back(make_pair(v, w));       edge.push_back(make_pair(w, make_pair(u, v)));     }     cin >> l;     done[capital] = true;     for (int i = 0; i < nei[capital].size(); i++) {       pq.push(make_pair(-nei[capital][i].second, nei[capital][i].first));     }     while (intree < n - 1) {       while (done[(pq.top()).second]) pq.pop();       pair<int, int> p = pq.top();       v = p.second;       dis[v] = -p.first;       done[v] = true;       for (int i = 0; i < nei[v].size(); i++) {         if (!done[nei[v][i].first])           pq.push(make_pair(-dis[v] - nei[v][i].second, nei[v][i].first));       }       intree++;     }     for (int i = 0; i < n; i++) {       answer += (dis[i] == l);     }     for (int i = 0; i < m; i++) {       pair<int, pair<int, int> > pa = edge[i];       for (int j = 1; j < pa.first; j++) {         if (min(dis[pa.second.first] + j, dis[pa.second.second] + pa.first - j) ==             l) {           answer++;         }       }     }     cout << answer;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> v(n + 1);     long long xr = 0;     for (long long i = 1; i <= n; i++) {       cin >> v[i];       xr ^= v[i];     }     if (xr == 0) {       cout <<  DRAW             <<   n ;       return;     }     long long msb;     for (long long i = 32; ~i; i--) {       if (xr & (1ll << i)) {         msb = i;         break;       }     }     long long count = 0;     for (long long i = 1; i <= n; i++) {       count += ((v[i] & (1ll << msb)) > 0);     }     bool win = (count % 4 == 1 or ((n - count) & 1));     cout << (win ?  WIN  :  LOSE ) <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ul = unsigned long long;   using ld = long double;   const int N = 101;   int a[N][N];   vector<vector<int>> ans;   void q(int ax, int ay, int bx, int by, int cx, int cy) {     a[ax][ay] ^= 1;     a[bx][by] ^= 1;     a[cx][cy] ^= 1;     ans.push_back({ax, ay, bx, by, cx, cy});   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t, n, m;     cin >> t;     for (int z = 0; z < (t); z++) {       cin >> n >> m;       string s;       for (int i = 0; i < (n); i++) {         cin >> s;         for (int j = 0; j < (m); j++) a[i][j] = s[j] -  0 ;       }       ans.clear();       for (int i = 0; i < (n - 2); i++)         for (int j = 0; j < (m); j++) {           if (a[i][j]) q(i, j, i + 1, j, i + 1, j + (j == 0 ? 1 : -1));         }       for (int i = 0; i < (m - 2); i++) {         if (a[n - 2][i] && a[n - 1][i])           q(n - 2, i, n - 1, i, n - 2, i + 1);         else if (a[n - 2][i])           q(n - 2, i, n - 2, i + 1, n - 1, i + 1);         else if (a[n - 1][i])           q(n - 1, i, n - 1, i + 1, n - 2, i + 1);       }       int ss = 0;       for (int i = 0; i < (2); i++)         for (int j = 0; j < (2); j++) ss ^= a[n - 2 + i][m - 2 + j];       for (int i = 0; i < (2); i++) {         for (int j = 0; j < (2); j++) {           if (a[n - 2 + i][m - 2 + j] == ss) continue;           vector<int> cv;           for (int i1 = 0; i1 < (2); i1++)             for (int j1 = 0; j1 < (2); j1++)               if (i1 != i || j1 != j) {                 cv.push_back(n - 2 + i1);                 cv.push_back(m - 2 + j1);               }           ans.push_back(cv);         }       }       cout << ans.size() <<   n ;       for (auto &pp : ans) {         for (int i : pp) cout << i + 1 <<    ;         cout <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(char ch) {     string s;     s += ch;     return s;   }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   long long expmod(long long x, long long n, long long mod) {     if (n == 0)       return 1;     else if (n % 2 == 0) {       long long temp = expmod(x, n / 2, mod);       return (temp * temp) % mod;     } else {       return (expmod(x, n - 1, mod) * x) % mod;     }   }   long long modinv(long long x, long long mod) { return expmod(x, mod - 2, mod); }   void solve() {     int n;     cin >> n;     long long mod = 1e9 + 7;     long long p = 0, q = 0;     int even = 0;     long long power = 2;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       even |= (x % 2 == 0);       power = expmod(power, x, mod);     }     42;     power = power * modinv(2, mod) % mod;     p = power + (even ? 1 : -1);     p = (p + mod) % mod;     p = p * modinv(3, mod) % mod;     q = power;     42;     cout << p <<  /  << q <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int tc = 1; tc <= t; tc++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int Read() {     char c;     while (c = getchar(), (c !=  - ) && (c <  0  || c >  9 ))       ;     bool neg = (c ==  - );     int ret = (neg ? 0 : c - 48);     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + c - 48;     return neg ? -ret : ret;   }   const int MAXN = 1005;   int N, n, a[MAXN];   pair<int, int> ans[MAXN * MAXN];   void init() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) a[i] = Read(), n += (a[i] > 0);   }   void work() {     if (n < 2) {       puts( -1 );       return;     } else       n = 0;     int B = 1, C = 2;     for (int i = 3; i <= N; i++)       for (int A = i;;) {         if (a[B] < a[A]) swap(A, B);         if (a[C] < a[B]) swap(C, B);         if (a[B] < a[A]) swap(A, B);         if (!a[A]) break;         for (int j = a[B] / a[A]; j; j >>= 1)           if (j & 1)             ans[++n] = make_pair(A, B), a[B] -= a[A], a[A] <<= 1;           else             ans[++n] = make_pair(A, C), a[C] -= a[A], a[A] <<= 1;       }     printf( %d n , n);     for (int i = 1; i <= n; i++) printf( %d %d n , ans[i].first, ans[i].second);   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long int cvp = 3;   int main() {     scanf( %d , &n);     for (int i = 3; i <= n; i++) {       cvp = cvp * 3;       if (i % 2 == 1)         cvp -= 3;       else         cvp += 3;       cvp = cvp % (long long int)1000000007;     }     if (n == 1) {       printf( 0 n );       return 0;     }     printf( %lld n , cvp);   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long ret = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) ret = ret * 10 + ch -  0 , ch = getchar();     return ret * f;   }   const long long maxn = 100005;   long long n, A, cj, cm, m;   pair<long long, long long> a[maxn];   long long sum[maxn];   long long ans = 0, ansx = -1, ansy = -1;   inline bool cmp_value(pair<long long, long long> aa,                         pair<long long, long long> bb) {     return aa.first < bb.first;   }   inline bool cmp_id(pair<long long, long long> aa,                      pair<long long, long long> bb) {     return aa.second < bb.second;   }   inline long long get_all_sum(long long x, long long up) {     long long L = 1, R = up;     long long ret = 0;     while (L <= R) {       long long mid = ((R - L) >> 1) + L;       if (a[mid].first > x)         R = mid - 1;       else         ret = x * mid - sum[mid], L = mid + 1;     }     return ret;   }   signed main() {     n = read();     A = read();     cj = read();     cm = read();     m = read();     for (long long i = 1; i <= n; i++) a[i].first = read(), a[i].second = i;     sort(a + 1, a + 1 + n, cmp_value);     for (long long i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i].first;     long long need = 0;     for (long long i = n + 1; i >= 1; i--) {       if (i <= n) need += A - a[i].first;       if (need > m) break;       long long L = 0, R = A;       while (L <= R) {         long long mid = ((R - L) >> 1) + L;         long long all_sum = get_all_sum(mid, i - 1);         if (all_sum > m - need)           R = mid - 1;         else {           if ((n - i + 1) * cj + mid * cm > ans) {             ans = (n - i + 1) * cj + mid * cm;             ansx = mid;             ansy = i;           }           L = mid + 1;         }       }     }     printf( %lld n , ans);     if (ansx != -1 && ansy != -1) {       for (long long i = 1; i < ansy; i++) a[i].first = max(ansx, a[i].first);       for (long long i = ansy; i <= n; i++) a[i].first = A;     }     sort(a + 1, a + 1 + n, cmp_id);     for (long long i = 1; i <= n; i++) printf( %lld  , a[i].first);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     char c;     int flag = 1;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flag *= -1;     x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= flag;     return;   }   inline void read(long long &x) {     char c;     int flag = 1;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flag *= -1;     x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= flag;     return;   }   int dp[5005][5005];   int arr[5005];   int main() {     int n;     read(n);     for (int i = 1; i <= n; ++i) {       read(arr[i]);       dp[i][1] = arr[i];     }     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         dp[j][i] = dp[j + 1][i - 1] ^ dp[j][i - 1];       }     }     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         dp[j][i] = max(dp[j][i], max(dp[j + 1][i - 1], dp[j][i - 1]));       }     }     int q;     cin >> q;     while (q--) {       int l, r;       read(l);       read(r);       printf( %d n , dp[l][r - l + 1]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int add(int a, int b) { return (a + b) % MOD; }   int sub(int a, int b) { return add(a, MOD - b); }   int mul(int a, int b) { return ((long long)a * b) % MOD; }   int inv(int a) {     int b = 1;     for (int i = 0; (1 << i) <= MOD - 2; i++) {       if ((1 << i) & (MOD - 2)) b = mul(b, a);       a = mul(a, a);     }     return b;   }   const int MAXN = 1e5 + 10;   vector<int> e[MAXN];   int val[MAXN], sz[MAXN], parent[MAXN];   map<int, int> dist[MAXN];   int A[MAXN], B[MAXN], total;   bool active[MAXN];   vector<int> in[MAXN], out[MAXN];   int calc_sz(int i, int p) {     sz[i] = 1;     for (int j : e[i]) {       if (!active[j] || j == p) continue;       sz[i] += calc_sz(j, i);     }     return sz[i];   }   int find_centroid(int i, int p, int n) {     for (int j : e[i]) {       if (!active[j] || j == p) continue;       if (sz[j] > n / 2) return find_centroid(j, i, n);     }     return i;   }   void calc_dist(int i, int p, int r, int d) {     dist[i][r] = d;     for (int j : e[i]) {       if (!active[j] || j == p) continue;       calc_dist(j, i, r, d + 1);     }   }   int build_centroid(int i) {     i = find_centroid(i, -1, calc_sz(i, -1));     calc_dist(i, -1, i, 0);     active[i] = false;     for (int j : e[i]) {       if (!active[j]) continue;       parent[build_centroid(j)] = i;     }     return i;   }   void update(int i, int k) {     int v = mul(val[i], MOD + k);     for (int p = i; p != -1; p = parent[p]) {       total = sub(total, mul(A[p], B[p]));       A[p] = add(A[p], mul(v, dist[i][p]));       if (parent[p] != -1) A[p] = sub(A[p], mul(v, dist[i][parent[p]]));       B[p] = add(B[p], v);       total = add(total, mul(A[p], B[p]));     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int t = 1;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       in[l].push_back(i);       out[r].push_back(i);       val[i] = inv(r - l + 1);       t = mul(t, r - l + 1);       active[i] = true;     }     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       e[x].push_back(y);       e[y].push_back(x);     }     parent[build_centroid(0)] = -1;     int sol = 0;     for (int color = 0; color < MAXN; color++) {       for (int i : in[color]) update(i, 1);       sol = add(sol, total);       for (int i : out[color]) update(i, -1);     }     cout << mul(sol, t);     return 0;   }
#include <bits/stdc++.h>   #pragma hdrstop   using namespace std;   void solve();   int main() {     int t = 1;     while (t--) solve();     return 0;   }   long long n, k;   long long dp[5000][5000];   vector<pair<long long, long long> > a;   long long b[5000];   void solve() {     cin >> n >> k;     a.push_back(make_pair(1, 0));     b[0] = 1;     for (long long i = 0; i < n; i++) {       long long q, w;       cin >> q >> w;       a.push_back(make_pair(q, w));       b[i + 1] = q;     }     a.push_back(make_pair(86401, 0));     b[n + 1] = 86401;     long long border = 0;     for (long long i = 0; i <= n + 5; i++)       for (long long j = 0; j <= i; j++) dp[i][j] = (1LL << 50);     dp[0][0] = 1;     for (long long i = 0; i <= n; i++)       for (long long j = 0; j <= i; j++) {         pair<long long, long long> cur = a[i + 1];         dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);         long long now = max(b[i + 1], dp[i][j]) + cur.second;         dp[i + 1][j] = min(dp[i + 1][j], now);       }     long long ans = 0;     for (long long i = 1; i <= n + 1; i++) {       for (long long j = 0; j <= k; j++) {         long long cur = dp[i - 1][j];         long long now = b[i];         ans = max(ans, now - cur);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[500005];   map<long long, int> mm;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &arr[i]);     for (int i = 1; i <= n - 1; i++) arr[i] += arr[i - 1];     for (int i = 0; i < n; i++) mm[arr[i]]++;     int mx = -1;     map<long long, int>::iterator it;     for (it = mm.begin(); it != mm.end(); it++) {       mx = max(mx, it->second);     }     printf( %d n , n - mx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100007;   long long i, j, k, n, m, t, x, y, ans;   long long pw2[32];   long long a[MAXN];   void calPowerTwo() {     long long i, j, k;     pw2[0] = 1;     for (i = 1; i < 32; i++) {       pw2[i] = pw2[i - 1] * 2;     }   }   int main() {     calPowerTwo();     while (cin >> n) {       for (i = 0; i < n; i++) {         cin >> a[i];       }       ans = 0;       for (i = 0; i < n - 1; i++) {         ans += a[i];         k = 0;         while (i + pw2[k] < n) {           k++;         }         k--;         a[i + pw2[k]] += a[i];         a[i] = 0;         cout << ans << endl;       }     }     return 0;   }