malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int tc = 0;   long long a, b, c, d;   inline long long sum(long long i) {     return -a * i + b * (d - 1) * i + i * (i - 1) / 2 * b * d;   }   inline long long calc(long long i) {     if (i < 0) return 0;     long long ans = 0;     if (i < (c + 1) / d) {       ans = min(ans, sum(i) - a + i * b);     } else {       i = (c + 1) / d;       ans = min(ans, sum(i) - a + (i - 1) * b + (c + 1 % d > 0) * b);       ans = min(ans, sum(i));       ans = min(ans, -a);     }     return ans;   }   inline void solve() {     ++tc;     scanf( %lld%lld%lld%lld , &a, &b, &c, &d);     if (c < d) {       if (b * c >= a)         printf( %lld n , a);       else         puts( -1 );     } else {       long long i = floor(-(-a + b * (d - 1) + b - 1.0 * b * d / 2) / (b * d));       i = max(i, 0ll);       long long dmg =           (-a + b * (d - 1) + b * d * ((c + 1) / d - 1) + ((c + 1) % d) * b);       long long ans = 0;       if (dmg < 0) {         puts( -1 );       } else {         ans = min(ans, calc(i - 1));         ans = min(ans, calc(i));         ans = min(ans, calc(i + 1));         ans = min(ans, calc(i + 2));         printf( %lld n , -ans);       }     }     return;   }   int main() {     int T;     for (scanf( %d , &T); T--; solve())       ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n;   int a[110][110], b[110][110];   template <typename T>   inline void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   inline void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   inline void read(T &x) {     T f = 1;     x = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= f;   }   int main() {     read(m);     read(n);     memset(a, 255, sizeof(a));     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         read(b[i][j]);         if (b[i][j] == 0) {           for (int k = 1; k <= n; k++) a[i][k] = 0;           for (int k = 1; k <= m; k++) a[k][j] = 0;         }       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         if (a[i][j] == -1) a[i][j] = 1;       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         int res = 0;         for (int k = 1; k <= n; k++) res |= a[i][k];         for (int k = 1; k <= m; k++) res |= a[k][j];         if (res != b[i][j]) {           printf( NO n );           return 0;         }       }     }     printf( YES n );     for (int i = 1; i <= m; i++) {       for (int j = 1; j < n; j++) {         printf( %d  , a[i][j]);       }       printf( %d n , a[i][n]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct DT {     int l, r, x;   };   DT qr[300005];   int n, m, ans[300005], tree[4 * 300005];   void update(int nd, int b, int e, int l, int r, int v) {     if (r < l || l < 1 || r > n) return;     if (b > r || e < l) return;     if (tree[nd] != 0 && b != e) {       tree[2 * nd] = tree[nd];       tree[2 * nd + 1] = tree[nd];       tree[nd] = 0;     }     if (b >= l && e <= r) {       tree[nd] = v;       return;     }     int md = (b + e) / 2;     update(2 * nd, b, md, l, r, v);     update(2 * nd + 1, md + 1, e, l, r, v);   }   int query(int nd, int b, int e, int x, int v) {     if (b == e) {       if (v == 0)         return tree[nd];       else         return v;     }     int md = (b + e) / 2;     if (v == 0) v = tree[nd];     if (x <= md)       return query(2 * nd, b, md, x, v);     else       return query(2 * nd + 1, md + 1, e, x, v);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> qr[i].l >> qr[i].r >> qr[i].x;     }     for (int i = m; i >= 1; i--) {       int l, r, x;       l = qr[i].l;       r = qr[i].r;       x = qr[i].x;       if (x >= l && x <= r) {         update(1, 1, n, l, x - 1, x);         update(1, 1, n, x + 1, r, x);       } else {         update(1, 1, n, l, r, x);       }     }     for (int i = 1; i <= n; i++) {       ans[i] = query(1, 1, n, i, 0);     }     for (int i = 1; i <= n; i++) {       if (i < n)         cout << ans[i] <<    ;       else         cout << ans[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt = 0;   int main() {     ios::sync_with_stdio(false);     cin >> n;     if (n <= 3) {       cout <<  NO ;       return 0;     }     cout <<  YES  <<   n ;     if (n % 2) {       cout <<  5 - 3 = 2  <<   n ;       cout <<  2 + 1 = 3  <<   n ;       cout <<  3 * 4 = 12  <<   n ;       cout <<  12 * 2 = 24  <<   n ;       while (n > 5) {         cout << n <<   -   << n - 1 <<   =   << 1 <<   n ;         cnt++;         n -= 2;       }       cnt--;       while (cnt > 0) {         cout <<  1 * 1 = 1  <<   n ;         cnt--;       }       if (cnt == 0) cout <<  1 * 24 = 24  <<   n ;     } else {       cout <<  1 * 2 = 2  <<   n ;       cout <<  2 * 3 = 6  <<   n ;       cout <<  6 * 4 = 24  <<   n ;       while (n > 4) {         cout << n <<   -   << n - 1 <<   =   << 1 <<   n ;         n -= 2;         cnt++;       }       cnt--;       while (cnt > 0) {         cout <<  1 * 1 = 1  <<   n ;         cnt--;       }       if (cnt == 0) cout <<  1 * 24 = 24  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const int INF = 1000000009;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int a, b;     cin >> a >> b;     if ((a || b) && max(a, b) - min(a, b) < 2) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<pair<int, int>, int> > v;   int a[(int)(1e5 + 50)];   string s;   void solve() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       s += (char)(x +  0 );     }     for (int i = 0; i < s.size();) {       int st = i, len = 0;       char c = s[i];       while (i < s.size() && c == s[i]) {         len++;         i++;       }       v.push_back(make_pair(make_pair(st, len), (int)(c -  0 )));     }     int len = v.size();     if (v[len - 1].second == 1 ||         (v[len - 1].first.second == 2 && v[len - 1].second == 0 && len < 3)) {       printf( NO );       return;     }     printf( YES n );     string ans;     if (v[len - 1].first.second == 2) {       for (int i = 0; i < len - 3; i++) {         char toAdd = (char)(v[i].second +  0 );         for (int j = 0; j < v[i].first.second; j++) {           ans += toAdd;           ans +=  -> ;         }       }       for (int j = 0; j < v[len - 3].first.second - 1; j++) {         ans +=  0 ;         ans +=  -> ;       }       ans +=  (0->( ;       for (int i = 0; i < v[len - 2].first.second; i++) {         ans +=  1 ;         ans +=  -> ;       }       ans +=  0))->0 ;       cout << ans;       return;     }     if (v[len - 1].first.second % 2 == 0) {       ans +=  ( ;       for (int i = 0; i < v[len - 1].first.second - 3; i++) {         ans +=  0-> ;       }       ans +=  (0->0) ;       ans +=  ->0 ;       ans +=  ) ;     } else {       ans +=  ( ;       for (int i = 0; i < v[len - 1].first.second - 1; i++) {         ans +=  0-> ;       }       ans +=  0 ;       ans +=  ) ;     }     if (len - 1 == 0) {       cout << ans;       return;     }     reverse(ans.begin(), ans.end());     ans +=  >- ;     ans +=  )1 ;     for (int i = 0; i < v[len - 2].first.second - 1; i++) {       ans +=  >-1 ;     }     ans +=  ( ;     for (int i = len - 3; i >= 0; i--) {       ans +=  >- ;       char toAdd = (char)(v[i].second +  0 );       int curlen = v[i].first.second;       for (int j = 0; j < curlen - 1; j++) {         ans += toAdd;         ans +=  >- ;       }       ans += toAdd;     }     reverse(ans.begin(), ans.end());     cout << ans;   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 755;   const long long INF = 1LL << 62;   long long dp[NMAX][NMAX];   int main() {     cin.sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j <= n - i; j++) {         if (j) {           dp[i][j] = dp[i + 1][j - 1];         } else {           dp[i][j] = INF;         }         if (v[i] >= 0) {           dp[i][j] = min(dp[i][j], max(0LL, dp[i + 1][j] - v[i]));         } else {           dp[i][j] = min(dp[i][j], dp[i + 1][j] - v[i]);         }       }     }     for (; m; m--) {       long long x;       cin >> x;       int l = 0;       int r = n;       int ans = n;       while (l <= r) {         int mi = (l + r) / 2;         if (dp[0][mi] <= x) {           ans = mi;           r = mi - 1;         } else {           l = mi + 1;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     long long int k;     cin >> k;     vector<long long int> arr(n, 0);     long long int cnt = 0;     for (int i = 0; i < n; ++i) {       cin >> arr[i];       long long int var = 0;       while (arr[i] > 0) {         long long int rem = arr[i] % 10;         if (rem == 4 || rem == 7) {           var++;         }         arr[i] /= 10;       }       if (var > k) {         cnt++;       }     }     cout << n - cnt <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   bool Max(T1& a, T2 b) {     return a < b ? a = b, 1 : 0;   }   template <typename T1, typename T2>   bool Min(T1& a, T2 b) {     return a > b ? a = b, 1 : 0;   }   const int N = 1000001;   bool prime[N];   vector<long long> pri;   vector<pair<long long, long long> > nv, sv;   long long n, m, s;   long long ans;   void rec(long long i, long long prod) {     if (i == sv.size()) {       ans++;       return;     }     auto cur = sv[i];     for (int j = 0; j < (cur.second + 1); ++j) {       rec(i + 1, prod);       if ((prod *= cur.first) > n) break;     }   }   long long pow(long long a, long long p) {     long long ret = 1;     while (p) {       if (p & 1) ret *= a;       a *= a;       p >>= 1;     }     return ret;   }   void solve() {     long long v;     n = 1;     for (int i = 0; i < (3); ++i) {       cin >> v;       n *= v;     }     m = 1;     for (int i = 0; i < (3); ++i) {       cin >> v;       m *= v;     }     s = 2;     for (int i = 0; i < (3); ++i) {       cin >> v;       s *= v;     }     long long ts = s, tn = n;     nv.clear();     sv.clear();     for (auto& e : pri) {       if (e * e > ts) break;       long long cnt = 0;       while (ts % e == 0) {         cnt++;         ts /= e;       }       if (cnt) sv.emplace_back(e, cnt);     }     if (ts > 1) sv.emplace_back(ts, 1);     for (auto& e : pri) {       if (e * e > tn) break;       long long cnt = 0;       while (tn % e == 0) {         cnt++;         tn /= e;       }       if (cnt) nv.emplace_back(e, cnt);     }     if (tn > 1) nv.emplace_back(tn, 1);     ans = 0;     rec(0, 1);     sv.emplace_back(N, 1);     vector<long long> tmp;     long long i = 0;     for (auto& e : nv) {       while (sv[i].first < e.first) i++;       if (sv[i].first > e.first) {         tmp.emplace_back(e.first);       } else {         if (sv[i].second < e.second)           tmp.emplace_back(pow(e.first, sv[i].second + 1));         i++;       }     }     long long sz = tmp.size();     for (int sub = 0; sub < (1 << sz); ++sub) {       long long t = 1;       bool add = 1;       for (int i = 0; i < (sz); ++i)         if ((sub >> i) & 1) {           t *= tmp[i];           add ^= 1;         }       if (add)         ans += m / t;       else         ans -= m / t;     }     cout << ans <<   n ;   }   void init() {     for (int i = 2; i <= (N - 1); ++i)       if (!prime[i]) {         pri.emplace_back(i);         for (long long j = (long long)i * i; j < N; j += i) prime[j] = 1;       }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     init();     int TC = 1;     cin >> TC;     for (int TI = 1; TI <= (TC); ++TI) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void test_case() {     int n;     long long k;     cin >> n >> k;     int l, r[2] = {-1, -1};     long long curr[2] = {k, k}, ans[2] = {0, 0}, monsters;     for (int i = 0; i < n; i++) {       int old_r[2] = {r[0], r[1]}, tmp_r;       long long old_curr[2] = {curr[0], curr[1]}, old_ans[2] = {ans[0], ans[1]};       cin >> l >> tmp_r >> monsters;       ans[0] = -1;       for (int j = 0; j < 2; j++) {         if (old_ans[j] == -1) continue;         if (old_curr[j] + (tmp_r - l) * k < monsters) continue;         if (ans[0] != -1 && ans[0] < old_ans[j] + monsters) continue;         ans[0] = old_ans[j] + monsters;         if (old_curr[j] >= monsters) {           r[0] = l;           curr[0] = old_curr[j] - monsters;         } else {           int turns = (monsters - old_curr[j] + k - 1) / k;           r[0] = l + turns;           curr[0] = k * turns + old_curr[j] - monsters;         }       }       ans[1] = -1;       for (int j = 0; j < 2; j++) {         if (old_ans[j] == -1) continue;         if ((tmp_r - l + 1) * k < monsters) continue;         if (old_r[j] == l) continue;         if (ans[1] != -1 && ans[1] <= old_ans[j] + old_curr[j] + monsters)           continue;         ans[1] = old_ans[j] + old_curr[j] + monsters;         int turns = (monsters + k - 1) / k;         r[1] = l + turns - 1;         curr[1] = k * turns - monsters;       }     }     if (ans[0] == -1)       cout << ans[1] <<   n ;     else if (ans[1] == -1)       cout << ans[0] <<   n ;     else       cout << min(ans[0], ans[1]) <<   n ;   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     int Case = 1;     for (int i = 0; i < Case; i++) {       test_case();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int vis[maxn];   vector<int> e[maxn];   vector<int> w[maxn];   int a[maxn];   int ans;   void add_edge(int u, int v, int ww) {     e[u].push_back(v);     e[v].push_back(u);     w[u].push_back(ww);     w[v].push_back(ww);   }   void dfs(int num, int l, int c) {     if (l > a[num] && c != 1) {       c = 1;     }     if (c == 1) {       ans++;     }     vis[num] = 1;     int cc = e[num].size();     for (int i = 0; i < cc; i++) {       if (!vis[e[num][i]]) {         if (l < 0) l = 0;         vis[e[num][i]] = 1;         dfs(e[num][i], l + w[num][i], c);       }     }   }   int main() {     memset(vis, 0, sizeof(vis));     int n;     scanf( %d , &n);     ans = 0;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 2; i <= n; i++) {       int u = i, v, ww;       scanf( %d%d , &v, &ww);       add_edge(u, v, ww);     }     ans = 0;     dfs(1, 0, 0);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;      #define ll int   #define vl vector<long long>   #define fr(i,a,n) for(ll i=a; i<n; i++)   #define all(x) x.begin(), x.end()      int32_t main(){    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    ll t; cin>>t;    while(t--){     ll n, x=0, z[4];     cin>>n;     for(ll i=0; i<4; i++) cin>>z[i];     for(ll i=0; i<=15; i++){      ll a=0, b=0, c=0, d=0;      if(i&1) a++;      if(i&2) b++;      if(i&4) c++;      if(i&8) d++;      if(z[0]-a-b<=n-2 && z[0]>=a+b) x++;      if(z[1]-c-b<=n-2 && z[1]>=c+b) x++;      if(z[2]-c-d<=n-2 && z[2]>=c+d) x++;      if(z[3]-a-d<=n-2 && z[3]>=a+d) x++;      if(x==4) break;      else x=0;     }     if(x==4) cout<< Yes n ;     else cout<< No n ;    }    }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   bool et[N];   int n;   int mob[N];   vector<int> d[N];   int cnt[N];   bool get(int x) {     int coprime = 0;     for (auto p : d[x]) coprime += cnt[p] * mob[p];     return coprime > 0;   }   void update(int x, int val) {     for (auto p : d[x]) cnt[p] += val;   }   int main() {     for (int i = 1; i < N; i++) {       for (int j = i; j < N; j += i) d[j].push_back(i);       if (i == 1)         mob[i] = 1;       else if ((i / d[i][1]) % d[i][1] == 0)         mob[i] = 0;       else         mob[i] = -mob[i / d[i][1]];     }     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       et[x] = 1;     }     for (int i = 1; i < N; i++) {       for (auto x : d[i])         if (i != x) et[x] |= et[i];     }     long long ans = 0;     stack<int> s;     for (int i = N - 1; i >= 1; i--) {       if (et[i] == 0) continue;       while (get(i) > 0) {         ans = max(ans, 1LL * i * s.top());         update(s.top(), -1);         s.pop();       }       update(i, 1);       s.push(i);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int i, j, count_star, diff, res = 0, n;     cin >> s;     n = s.size();     for (i = 0; i < n; i++) {       diff = count_star = 0;       for (j = i; j < n; j++) {         if (s[j] ==  ( )           diff++;         else if (s[j] ==  ) )           diff--;         else {           count_star++;           diff--;         }         if (diff < 0) {           count_star--;           if (count_star < 0)             break;           else             diff += 2;         }         if (diff == 0 && (j - i + 1) % 2 == 0) res++;       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int P;   int g1() {     double p = rand() / 32767.0, s = 0, g = 1;     for (int k = 0;; k++) {       if (k) g *= k;       double c = pow(P, k) * exp(-P) / g;       s += c;       if (p <= s) return k;     }   }   int g2() {     double p = rand() / 32767.0, s = 0;     for (int k = 0; k <= P + P; k++) {       s += 1.0 / (2 * P + 1);       if (p <= s) return k;     }     return P + P;   }   int main() {     int v;     scanf( %d , &v);     while (v--) {       vector<int> vs;       for (int i = 0; i < 250; i++) {         int x;         scanf( %d , &x);         vs.push_back(x);       }       double avr = 0, ss = 0;       for (int i = 0; i < 250; i++) avr += (double)vs[i];       avr /= 250;       int mx = 0;       for (int i = 0; i < 250; i++)         ss += (vs[i] - avr) * (vs[i] - avr), mx = max(mx, vs[i]);       ss /= avr;       if (ss < 500)         printf( %d n , int(avr + 0.5));       else         printf( %d n , int(mx / 2.0 + 0.5));     }   }
#include <bits/stdc++.h>   using namespace std;   unsigned gcd(unsigned a, unsigned b) {     unsigned r;     do {       r = a % b;       a = b;       b = r;     } while (r > 0);     return a;   }   unsigned arr[705];   bool dp[705][705][2];   bool en[705][705][2];   unsigned g[705][705];   bool f(int l, int r, int rm) {     if (en[l][r][rm]) return dp[l][r][rm];     en[l][r][rm] = true;     if (l == r)       dp[l][r][rm] = g[l][l - 1 + 2 * rm] > 1;     else {       dp[l][r][rm] |= (g[l - 1 + rm * (r - l + 2)][l] > 1) && f(l + 1, r, 0);       dp[l][r][rm] |= (g[l - 1 + rm * (r - l + 2)][r] > 1) && f(l, r - 1, 1);       for (int curs = 1; curs < r - l; curs++)         dp[l][r][rm] |= (g[l - 1 + rm * (r - l + 2)][l + curs] > 1) &&                         f(l, l + curs - 1, 1) && f(l + curs + 1, r, 0);     }     return dp[l][r][rm];   }   void init(int n) {     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) g[i][j] = gcd(arr[i], arr[j]);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     init(n);     if (f(1, n - 1, 0)) {       printf( Yes n );       return 0;     }     if (f(0, n - 2, 1)) {       printf( Yes n );       return 0;     }     for (int i = 1; i < n - 1; i++) {       if (f(0, i - 1, 1) && f(i + 1, n - 1, 0)) {         printf( Yes n );         return 0;       } else         continue;     }     printf( No n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void __dbg() { cout << endl; }   template <typename Arg, typename... Args>   void __dbg(Arg A, Args... B) {     cout <<     << A;     __dbg(B...);   }   const int inf = INT_MAX;   const int ninf = INT_MIN;   const int mod = 1e9 + 7;   const int maxN = 1e6 + 2;   int main() {     int n;     scanf( %d , &n);     map<pair<int, int>, int> ma;     vector<int> x(n), y(n);     for (int i = 0; i < n; i++) {       scanf( %d , &x[i]);       scanf( %d , &y[i]);     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int cx = x[i] + x[j];         int cy = y[i] + y[j];         ma[{cx, cy}]++;       }     }     long long ans = 0;     for (auto it : ma) {       ans += it.second * 1LL * (it.second - 1) / 2;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[111];   int main() {     int n, a = 0, b = 0, c = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i];       if (i < 3 && i == 1 || i % 3 == 1) {         a = a + p[i];       } else if (i < 3 && i == 2 || i % 3 == 2) {         b = b + p[i];       } else if (i % 3 == 0) {         c = c + p[i];       }     }     if (max(a, max(b, c)) == a) {       cout <<  chest ;     } else if (max(a, max(b, c)) == b) {       cout <<  biceps ;     } else if (max(a, max(b, c)) == c) {       cout <<  back ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, m, v[100][100], x, y, cnt, ans = 0, dcnt = 1;     vector<int> del;     memset(v, 0, sizeof(v));     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> x >> y;       v[x - 1][y - 1] = 1;       v[y - 1][x - 1] = 1;     }     while (dcnt != 0) {       dcnt = 0;       for (int i = 0; i < n; i++) {         cnt = 0;         for (int j = 0; j < n; j++) cnt += v[i][j];         if (cnt == 1) {           dcnt++;           del.push_back(i);           for (int j = 0; j < n; j++) v[i][j] = 0;         }       }       for (int i = 0; i < n; i++) {         for (unsigned int j = 0; j < del.size(); j++) v[i][del[j]] = 0;       }       if (dcnt > 0) ans++;       del.clear();     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   long long dp[2 * 100000 + 10][2], arr[2 * 100000 + 10];   long long Solve(int, bool);   int main() {     scanf( %d , &N);     dp[0][0] = dp[0][1] = dp[1][0] = dp[1][1] = -2;     for (int i = 2; i <= N; i++) {       scanf( %I64d , &arr[i]);       dp[i][0] = dp[i][1] = -2;     }     for (int i = 2; i <= N; i++) Solve(i, 0), Solve(i, 1);     for (int i = 1; i < N; i++)       dp[1 + i][0] != -1 ? printf( %I64d n , dp[1 + i][0] + i) : printf( -1 n );     return 0;   }   long long Solve(int ind, bool f) {     if (ind <= 0 || ind > N) return 0;     if (dp[ind][f] == -3) return -1;     if (dp[ind][f] != -2) return dp[ind][f];     dp[ind][f] = -3;     long long ret, a;     if (f)       a = Solve(ind + arr[ind], 0);     else       a = Solve(ind - arr[ind], 1);     if (a == -1)       ret = -1;     else       ret = a + (long long)arr[ind];     return dp[ind][f] = ret;   }