malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool umax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   long long POW(long long a, long long p, long long M) {     if (!p) return 1LL;     long long T = POW(a, p / 2, M);     T = T * T % M;     if (p & 1) T = T * (a % M) % M;     return T;   }   long long SQRT(long long a) {     long long b = (long long)sqrtl(((double)a) + 0.5);     while (b * b < a) ++b;     while (b * b > a) --b;     return (b * b == a) ? b : -1;   }   const long long MOD = 1e9 + 7;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     long long n, m;     cin >> n >> m;     if (n == 1) {       cout << 0 << endl;       return 0;     }     vector<vector<long long>> guess(n + 1);     long long f = 0;     long long N = 2e5;     long long fq[4 * N];     memset(fq, 0, sizeof(fq));     for (long long i = 1; i <= n; i++) fq[N + i] = 1;     for (long long i = 1; i <= n; i++) {       long long mx = min(n, i + m + 1);       f += 2 * (mx - i + 1) - 1;     }     long long st;     for (long long i = 1; i <= m; i++) {       long long a;       cin >> a;       guess[a].push_back(i);     }     for (long long i = 1; i <= n; i++) {       if (guess[i].empty()) continue;       long long ss = guess[i][0];       for (long long j = 1; j <= guess[i].size(); ++j) {         if (j < guess[i].size() && guess[i][j] == guess[i][j - 1] + 1)           continue;         else {           long long ct = 0;           for (long long k = i - ss; k >= i - guess[i][j - 1]; --k) {             long long org = min(n, k + m + 1);             long long wt = min(n, k + m - (guess[i][j - 1] + (k - i) + 1) + 1);             f -= fq[N + k] * (org - wt);             ct += fq[N + k];             fq[N + k] = 0;           }           fq[N + i - guess[i][j - 1] - 1] += ct;           if (j < guess[i].size()) ss = guess[i][j];         }       }     }     memset(fq, 0, sizeof(fq));     for (long long i = 1; i <= n; i++) fq[i] = 1;     for (long long i = n; i >= 1; i--) {       if (guess[i].empty()) continue;       long long ss = guess[i][0];       for (long long j = 1; j <= guess[i].size(); ++j) {         if (j < guess[i].size() && guess[i][j] == guess[i][j - 1] + 1)           continue;         else {           long long ct = 0;           for (long long k = i + ss; k <= i + guess[i][j - 1]; ++k) {             long long org = max(1LL, k - m - 1);             long long wt = max(1LL, k - m + (guess[i][j - 1] - (k - i) + 1) - 1);             f -= fq[k] * (wt - org);             ct += fq[k];             fq[k] = 0;           }           fq[i + guess[i][j - 1] + 1] += ct;           if (j < guess[i].size()) ss = guess[i][j];         }       }     }     cout << f << endl;     cerr <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   inline bool check2(long long x, long long y3) {     return (x * x + y3 * y3 * 3 <= n * n);   }   inline bool check(long long x, long long y3) {     return check2(x - 2, y3) & check2(x - 1, y3 - 1) & check2(x + 1, y3 - 1) &            check2(x + 2, y3) & check2(x + 1, y3 + 1) & check2(x - 1, y3 + 1);   }   long long calc(long long x, long long d) {     long long l = 0, r = 3e6;     while (l < r) {       long long mid = (l + r + 1) / 2;       long long y3 = d + mid * 2;       if (check(x, y3))         l = mid;       else         r = mid - 1;     }     long long ret = r * 2;     if (d == 0 && check(x, 0)) ret += 1;     if (d == 1 && check(x, d)) ret += 2;     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     n *= 2;     long long s = 0;     int x = 3, d = 1;     while (true) {       long long t = calc(x, d);       if (t == 0) break;       s += t;       x += 3, d ^= 1;     }     s *= 2;     s += calc(0, 0);     cout << s << endl;   }
#include <bits/stdc++.h>   inline int getint() {     register char ch;     while (!isdigit(ch = getchar()))       ;     register int x = ch ^  0 ;     while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^  0 );     return x;   }   const long long mod = 1e9 + 7;   const int N = 150001, M = 150002, K = 100001;   void exgcd(const long long &a, const long long &b, long long &x, long long &y) {     if (!b) {       x = 1;       y = 0;       return;     }     exgcd(b, a % b, y, x);     y -= a / b * x;   }   inline long long inv(const long long &x) {     long long tmp, ret;     exgcd(x, mod, ret, tmp);     return (ret + mod) % mod;   }   long long f[2][M];   long long p[M], q[M];   long long fact[K], tcaf[K];   int k;   inline long long calc(const int &x) {     return fact[k] * tcaf[k - x] % mod * tcaf[x] % mod * p[x] % mod * q[k - x] %            mod;   }   signed main() {     int n = getint(), m = getint();     long long a = getint(), b = getint();     k = getint();     fact[0] = 1;     for (register int i = 1; i <= k; i++) {       fact[i] = fact[i - 1] * i % mod;     }     tcaf[k] = inv(fact[k]);     for (register int i = k - 1; ~i; i--) {       tcaf[i] = tcaf[i + 1] * (i + 1) % mod;     }     p[0] = q[0] = 1;     p[1] = a * inv(b) % mod;     q[1] = (b - a) * inv(b) % mod;     for (register int i = 2; i <= k; i++) {       p[i] = p[i - 1] * p[1] % mod;       q[i] = q[i - 1] * q[1] % mod;     }     f[0][m] = 1;     for (register int i = 1; i <= n; i++) {       long long s1 = 0, s2 = 0;       for (register int j = 0; j <= m; j++) {         f[i & 1][j] = (s1 * (f[!(i & 1)][m] - f[!(i & 1)][m - j]) - s2) % mod *                       calc(m - j) % mod;         s1 = (s1 + calc(j)) % mod;         s2 = (s2 + f[!(i & 1)][j] * calc(j)) % mod;       }       for (register int j = 1; j <= m; j++) {         f[i & 1][j] = (f[i & 1][j] + f[i & 1][j - 1]) % mod;       }     }     printf( %I64d n , (f[n & 1][m] + mod) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[5005][5005], bad[30][5005], pre[5005];   const long long MOD = 1e9 + 7;   long long fact[5005];   long long qikpow(long long a, long long b) {     if (!b) {       return 1;     }     long long ret = qikpow(a, b / 2);     ret *= ret;     ret %= MOD;     if (b & 1) {       ret *= a;       ret %= MOD;     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int N;     cin >> N;     fact[0] = 1;     dp[0][0] = 1;     pre[0] = 1;     for (int i = 1; i <= N; i++) {       char c;       cin >> c;       fact[i] = (fact[i - 1] * i) % MOD;       for (int k = 1; k <= i; k++) {         dp[i][k] = pre[k - 1];         dp[i][k] = (dp[i][k] - bad[c -  a ][k - 1] + MOD) % MOD;         dp[i][k] = (dp[i][k] - bad[c -  a ][k] + MOD) % MOD;       }       for (int k = 1; k <= i; k++) {         bad[c -  a ][k] = (bad[c -  a ][k] + dp[i][k]) % MOD;         pre[k] = (pre[k] + dp[i][k]) % MOD;       }     }     long long ans = 0;     for (int i = 1; i <= N; i++) {       ans += pre[i] * fact[N - 1] % MOD *              qikpow(fact[i - 1] * fact[N - i] % MOD, MOD - 2) % MOD;       ans %= MOD;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int n, s[3000 + 5], c[3000 + 5], f[3000 + 5][5];   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   int main() {     n = read();     memset(f, inf, sizeof(f));     for (int i = 1; i <= n; i++) s[i] = read();     for (int i = 1; i <= n; i++) c[i] = read();     for (int i = 1; i <= n; i++) {       f[i][1] = c[i];       for (int j = 1; j < i; j++)         if (s[j] < s[i]) f[i][2] = min(f[j][1] + c[i], f[i][2]);       for (int j = 1; j < i; j++)         if (s[j] < s[i]) f[i][3] = min(f[j][2] + c[i], f[i][3]);     }     int ans = inf;     for (int i = 1; i <= n; i++)       if (f[i][3]) ans = min(ans, f[i][3]);     if (ans == inf)       cout << -1;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   int main() {     long long a, sum, l, i, b;     char ch[10];     while (scanf( %I64d , &a) != EOF) {       getchar();       scanf( %s , ch);       l = strlen(ch);       b = 0;       for (i = l - 1; i > 0; i--) b = (ch[i] -  0  + b) * 10;       b = ch[0] -  0  + b;       sum = a + b;       printf( %I64d n , sum);     }   }
#include <bits/stdc++.h>   int x[5], j = 1, b, d, ans, t, i, u = 0;   void GCD(int a, int b) {     if (a == b) {       x[j] = a;       j++;     } else if (a < b)       GCD(b - a, a);     else       GCD(a - b, b);   }   int main() {     scanf( %d , &b);     scanf( %d , &d);     GCD(b - 1, d);     GCD(b, d);     GCD(b + 1, d);     GCD(x[1], x[3]);     t = (x[1] * x[2] * x[3] / x[4]) % d;     for (i = 1; i <= 8; i++) {       if (t == 0) {         u = i;         break;       } else         t = (t * x[2]) % d;     }     if (u == 0)       ans = 7;     else {       if (x[1] == 1 && x[3] == 1)         ans = 2;       else if (x[2] == 1 && x[3] == 1)         ans = 3;       else if (x[1] == 1 && x[2] == 1)         ans = 11;       else if (x[1] == 1 || x[3] == 1)         ans = 6;       else if (x[2] > 1)         ans = 6;       else if (x[3] == 2)         ans = 3;       else if (x[1] == 2 && x[3] > 2)         ans = 11;       else         ans = 6;     }     printf( %d-type , ans);     if (ans == 2) printf(  n%d , u);   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 50;   long long dp[N];   void solve() {     long long n;     cin >> n;     long long count = 0;     while (n > 0) {       long long quotient = n / 3;       long long rem = n % 3;       n = n / 3;       dp[count] = rem;       count++;     }     for (long long i = 0; i < N; i++) {       if (dp[i] == 0 || dp[i] == 1)         continue;       else {         dp[i] = -1;         dp[i + 1] += 1;       }     }     long long finalAns = 0;     for (long long i = N - 1; i >= 0; i--) {       if (dp[i] == 0) continue;       if (dp[i] == -1)         break;       else {         long long coeff = dp[i];         finalAns += pow(3, i);       }     }     cout << finalAns << endl;     for (long long i = 0; i < N; i++) dp[i] = 0;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = int(1e9 + 7), MAXN = int(1e3 + 50);   int n, s[MAXN], br, raz, z[MAXN];   vector<int> v[MAXN];   vector<pair<pair<int, int>, int>> rez;   void dfs(int i, int ot) {     s[i] = 1;     for (auto j : v[i])       if (j != ot) {         dfs(j, i);         s[i] += s[j];       }   }   int centroid() {     dfs(1, -1);     int c = 1, ot = -1;     while (1) {       int br = 1;       for (auto j : v[c])         if (j != ot && 2 * s[j] >= n) {           br = 0;           ot = c;           c = j;           break;         }       if (br) break;     }     return c;   }   void dfs2(int i, int ot) {     br += raz;     z[i] = br;     rez.push_back({{i, ot}, z[i] - z[ot]});     for (auto j : v[i])       if (j != ot) dfs2(j, i);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int p, q;       cin >> p >> q;       v[p].push_back(q);       v[q].push_back(p);     }     if (n == 1) {       exit(0);     }     if (n == 2) {       printf( 1 2 1 n );       exit(0);     }     int c = centroid();     dfs(c, -1);     vector<pair<int, int>> v2, g1, g2;     multiset<pair<int, vector<int>>> sv;     for (auto i : v[c]) {       vector<int> vv{i};       sv.insert({s[i], vv});     }     while (sv.size() > 2) {       auto pom1 = *sv.begin();       sv.erase(sv.begin());       auto pom2 = *sv.begin();       sv.erase(sv.begin());       vector<int> vu;       for (auto i : pom1.second) vu.push_back(i);       for (auto i : pom2.second) vu.push_back(i);       sv.insert({pom1.first + pom2.first, vu});     }     auto a = *sv.begin();     sv.erase(sv.begin());     auto b = *sv.begin();     sv.erase(sv.begin());     z[c] = 0;     br = 0;     raz = 1;     for (auto i : a.second) dfs2(i, c);     br = 0;     raz = a.first + 1;     for (auto i : b.second) dfs2(i, c);     for (auto i : rez)       printf( %d %d %d n , i.first.first, i.first.second, i.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const uint64_t seed =       std::chrono::system_clock::now().time_since_epoch().count();   mt19937_64 rnd(seed);   const int MOD = 998244353;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     set<pair<long long, long long>> ss;     int cnt = 0;     long long x = 1, y = 0;     auto has = [&](int v) {       long long d = (v - y) / x;       auto it = ss.upper_bound({d, LLONG_MAX});       if (it != ss.begin()) {         it = prev(it);         return it->first <= d && it->second >= d;       }       return false;     };     for (int p : a) {       if (p % 2 == 0 && has(p / 2)) {         ss.clear();         ss.insert({p / 2, p / 2});         x = 1, y = 0;         continue;       };       x = -x;       y = p - y;       cnt++;       if (p % 2 == 0) {         long long d = (p / 2 - y) / x;         ss.insert({d, d});       }       long long r1 = (1 - y) / x;       long long r2 = (p - 1 - y) / x;       if (r1 > r2) swap(r1, r2);       for (auto it = ss.begin(); it != ss.end();) {         long long aa, bb;         tie(aa, bb) = *it;         aa = max(aa, r1);         bb = min(bb, r2);         if (aa > bb)           it = ss.erase(it);         else {           ss.erase(it);           ss.insert({aa, bb});           break;         }       }       for (auto it = ss.rbegin(); it != ss.rend();) {         long long aa, bb;         tie(aa, bb) = *it;         aa = max(aa, r1);         bb = min(bb, r2);         it = decltype(it){ss.erase(next(it).base())};         if (aa <= bb) {           ss.insert({aa, bb});           break;         }       }       if (ss.empty()) {         cnt++;         ss.insert({r1, r2});       }     }     cout << cnt <<   n ;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(10);     int T = 1;     cin >> T;     for (int i = 1; i <= T; i++) {       solve();     }     cout.flush();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200005;   long long n, m, u, v, k;   long long flag;   long long a[N];   long long x, y, z;   long long aa, bb, cc, dd;   long long ans[100005];   long long sum;   void init() {}   long long gcd(long long x, long long y) {     if (!y) return x;     return gcd(y, x % y);   }   struct node {     long long x, id;     bool operator<(const node t) const { return x < t.x; }   };   long long getn(long long x, long long y, long long z) {     long long n;     cout <<  ?   << x <<     << y <<     << z << endl;     cin >> n;     return n;   }   void solve() {     init();     cin >> n;     sum = 0;     for (long long i = 1; i <= n; i++) {       a[i] = 0;     }     for (long long i = 0; i < n / 3; i++) {       ans[i] = getn(i * 3 + 1, i * 3 + 2, i * 3 + 3);       if (!ans[i]) {         u = i;       } else {         v = i;       }     }     aa = getn(u * 3 + 1, u * 3 + 2, v * 3 + 1);     bb = getn(u * 3 + 1, u * 3 + 2, v * 3 + 2);     cc = getn(v * 3 + 1, v * 3 + 2, u * 3 + 1);     dd = getn(v * 3 + 1, v * 3 + 2, u * 3 + 2);     if (aa + bb == 0) {       x = u * 3 + 1;     } else {       x = u * 3 + 3;     }     a[x] = 0;     if (cc + dd == 2) {       y = v * 3 + 1;     } else {       y = v * 3 + 3;     }     a[y] = 1;     for (long long i = 0; i < n / 3; i++) {       if (ans[i]) {         aa = getn(i * 3 + 1, i * 3 + 2, x);         bb = getn(i * 3 + 2, i * 3 + 3, x);         if (aa + bb == 0) {           a[i * 3 + 1] = 1;           a[i * 3 + 2] = 0;           a[i * 3 + 3] = 1;         } else if (aa + bb == 2) {           a[i * 3 + 1] = 1;           a[i * 3 + 2] = 1;           a[i * 3 + 3] = 1;         } else if (aa == 1) {           a[i * 3 + 1] = 1;           a[i * 3 + 2] = 1;           a[i * 3 + 3] = 0;         } else {           a[i * 3 + 1] = 0;           a[i * 3 + 2] = 1;           a[i * 3 + 3] = 1;         }       } else {         aa = getn(i * 3 + 1, i * 3 + 2, y);         bb = getn(i * 3 + 2, i * 3 + 3, y);         if (aa + bb == 0) {           a[i * 3 + 1] = 0;           a[i * 3 + 2] = 0;           a[i * 3 + 3] = 0;         } else if (aa + bb == 2) {           a[i * 3 + 1] = 0;           a[i * 3 + 2] = 1;           a[i * 3 + 3] = 0;         } else if (aa == 1) {           a[i * 3 + 1] = 1;           a[i * 3 + 2] = 0;           a[i * 3 + 3] = 0;         } else {           a[i * 3 + 1] = 0;           a[i * 3 + 2] = 0;           a[i * 3 + 3] = 1;         }       }     }     for (long long i = 1; i <= n; i++) {       if (a[i] == 0) sum++;     }     cout <<  !   << sum <<    ;     for (long long i = 1; i <= n; i++) {       if (a[i] == 0) cout << i <<    ;     }     cout << endl;   }   signed main() {     long long t = 1;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   bool compare(const int a, const int b) {     if (a <= b) {       return false;     }     return true;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       string s;       cin >> s;       int last_count = 0;       vector<int> arr;       for (int j = 0; j < s.length(); j++) {         if (j == 0) {           if (s[0] ==  1 ) {             last_count++;           }         } else {           if (s[j] ==  0 ) {             if (last_count != 0) {               arr.push_back(last_count);             }             last_count = 0;           } else {             last_count++;           }         }       }       if (last_count != 0) {         arr.push_back(last_count);       }       if (arr.size() == 0) {         cout << 0 << endl;       } else {         sort(arr.begin(), arr.end(), compare);         int alice_Count = 0;         for (int j = 0; j < arr.size(); j++) {           if (j % 2 == 0) {             alice_Count += arr[j];           }         }         cout << alice_Count << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   const double PI = acos(-1.0);   const int MAX = 150005;   int n, len, h;   pair<int, int> a[MAX];   int b[MAX];   pair<int, int> T[MAX * 8];   int lazy[MAX * 8];   bool pzdc[MAX];   void push(int v) {     T[v].first += lazy[v];     lazy[v * 2] += lazy[v];     lazy[v * 2 + 1] += lazy[v];     lazy[v] = 0;   }   void upd(int v, int tl, int tr, int l, int r, int delta) {     push(v);     if (l > r) return;     if (tl == l && tr == r) {       lazy[v] += delta;       push(v);       return;     }     int tm = (tl + tr) / 2;     upd(v * 2, tl, tm, l, min(r, tm), delta);     upd(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, delta);     T[v] = min(T[v * 2], T[v * 2 + 1]);   }   void build(int v, int tl, int tr) {     if (tl == tr) {       T[v].second = tl;       return;     }     int tm = (tl + tr) / 2;     build(v * 2, tl, tm);     build(v * 2 + 1, tm + 1, tr);     T[v] = min(T[v * 2], T[v * 2 + 1]);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> len >> h;     build(1, 0, n - len);     for (int i = 0; i < len; i++) cin >> b[i];     sort(b, b + len);     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a, a + n);     int ptr = n - 1;     for (int i = 0; i < len; i++) {       while (ptr >= 0 && a[ptr].first + b[i] >= h) {         upd(1, 0, n - len, max(0, a[ptr].second - len + 1),             min(n - len, a[ptr].second), 1);         ptr--;       }       while (T[1].first <= i) {         pzdc[T[1].second] = 1;         upd(1, 0, n - len, T[1].second, T[1].second, INF);       }     }     int ans = 0;     for (int i = 0; i < n - len + 1; i++) ans += !pzdc[i];     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a;   int main(int argc, char *argv[]) {     int n;     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     if (n == 2) {       cout << 1 <<     << 2;       return 0;     }     if (n == 3) {       cout << 1 <<     << 1 <<     << 3;       return 0;     }     int so = 1, ts = 2, ss = n, luu = 1;     while (ss > 2) {       int m = n / ts;       m = ss - m;       for (int i = 1; i <= m; i++) cout << luu <<    ;       ss = ss - m;       if (ss == 1) {         cout << ts;         return 0;       }       if (ss == 2) {         cout << ts <<     << ts * 2;         return 0;       }       if (ss == 3) {         cout << ts <<     << ts <<     << ts * 3;         return 0;       }       luu = ts;       ts = ts * 2;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > T;   vector<vector<int> > T2;   set<int> att;   bool keep[123456 + 5];   bool hasa(int from, int v) {     keep[v] = false;     if (att.find(v) != att.end()) keep[v] = 1;     for (int i = 0; i < T[v].size(); ++i) {       if (T[v][i] != from) keep[v] |= hasa(v, T[v][i]);     }     return keep[v];   }   map<pair<int, int>, long long> dp[2];   long long get(bool back, int from, int v) {     pair<int, int> state(from, v);     if (dp[back].find(state) == dp[back].end()) {       long long ans = 0;       for (int i = 0; i < T2[v].size(); ++i) {         int u = T2[v][i];         if (u == from) continue;         ans += 2 + get(true, v, u);       }       long long a2 = ans;       if (!back) {         for (int k = 0; k < T2[v].size(); ++k) {           int u = T2[v][k];           if (u == from) continue;           a2 = min(a2, ans - 2 - get(true, v, u) + 1 + get(false, v, u));         }       }       dp[back][state] = a2;     }     return dp[back][state];   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i <= n; ++i) {       T.push_back(vector<int>());       T2.push_back(vector<int>());     }     for (int i = 1; i < n; ++i) {       int a, b;       cin >> a >> b;       T[a].push_back(b);       T[b].push_back(a);     }     for (int i = 0; i < m; ++i) {       int a;       cin >> a;       att.insert(a);     }     fill(keep, keep + n, false);     hasa(-1, *att.begin());     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < T[i].size(); ++j) {         int u = T[i][j];         if (keep[i] && keep[u]) T2[i].push_back(u);       }     }     long long vert = -1, mn = 0x7fffffffffffffff;     for (int i = 1; i <= n; ++i) {       if (keep[i]) {         long long score = get(false, -1, i);         if (score < mn) {           vert = i;           mn = score;         }       }     }     cout << vert <<   n  << mn <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   const long long inf = 0x3f3f3f3f3f;   long long a[1010][1010];   long long n, k;   int main() {     cin >> n >> k;     long long cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = n; j >= k; j--) {         a[i][j] = n * n - cnt;         cnt++;       }     }     long long fcnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j < k; j++) {         fcnt++;         a[i][j] = fcnt;       }     }     long long sum = 0;     for (int i = 1; i <= n; i++) sum += a[i][k];     cout << sum << endl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cout << a[i][j] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     string s;     cin >> s;     long long n = s.size();     long long an = 0;     for (long long i = 0; i < n; i++) {       long long r = INT_MAX;       for (long long j = i; j <= min((long long)(i + 9), n - 1); j++) {         for (long long k = 1; k <= 8; k++) {           if (j + 2 * k < n) {             if (s[j] == s[j + k] and s[j] == s[j + 2 * k]) {               r = min(r, j + 2 * k);             }           }         }       }       if (r != INT_MAX) an = an + n - r;     }     cout << an << endl;   }