malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, t;     cin >> n;     while (n--) {       cin >> t;       if (t <= 2) {         cout << 0 << endl;         continue;       }       if (t % 2 != 0) {         cout << t / 2 << endl;       } else {         cout << t / 2 - 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 1000 * 100 + 1000;   const int INF = (1u << 31) - 1;   int l1[MN];   int l2[MN];   int b[MN];   int p[MN];   int n, m, _;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> _ >> _;     for (int i = 0; i < n; i++) cin >> l1[i];     for (int i = 0; i < m; i++) cin >> l2[i];     sort(l1, l1 + n);     sort(l2, l2 + m);     for (int i = 0; i < m; i++) b[i] = INF;     int now = 0;     for (int i = 0; i < n; i++) {       while (now + 1 < m && abs(l2[now + 1] - l1[i]) < abs(l2[now] - l1[i]))         now++;       if (now + 1 < m && abs(l2[now + 1] - l1[i]) == abs(l2[now] - l1[i]) &&           b[now] != abs(l2[now] - l1[i]) && b[now] != INF)         now++;       p[i] = now;       b[now] = min(b[now], abs(l2[now] - l1[i]));     }     int hung = 0;     for (int i = 0; i < n; i++)       if (b[p[i]] != abs(l2[p[i]] - l1[i])) hung++;     cout << hung << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp1[100010];   int dp2[100010];   int a[100010];   int main(int argc, char const *argv[]) {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       std::cin >> a[i];     }     dp1[0] = 0;     int sum = 0;     for (int i = 1; i <= n; i++) {       sum += a[i];       dp1[i] = dp1[i - 1] + a[i];       if (dp1[i] < -sum) {         dp1[i] = -sum;       }     }     dp2[n + 1] = 0;     sum = 0;     for (int i = n; i >= 1; --i) {       sum += a[i];       dp2[i] = dp2[i + 1] + a[i];       if (dp2[i] < -sum) {         dp2[i] = -sum;       }     }     int ans = 0;     for (int i = 1; i <= n + 1; i++) {       ans = max(ans, dp1[i - 1] + dp2[i]);     }     std::cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   const double PI = acos(-1.0);   const int EPS = (1e-10);   const int N = 1e5 * 2 + 10;   const int inf = 1e9 * 2 + 10;   const ll INF = 1e18 * 2 + 10;   const int MOD = 1e9 + 7;   int nxt() {     int x;     cin >> x;     return x;   }   int fcmp(double a, double b) {     return (fabs(a - b) < EPS ? 0 : a > b ? 1 : -1);   }   bool prime[N];   vector<int> adj[N];   int sz[N], link[N];   void sieve() {     fill(&prime[0], &prime[0] + N, 1);     prime[0] = 0;     prime[1] = 1;     for (int i = 2; i * i <= N; ++i)       if (prime[i]) {         for (int j = i * i; j < N; j += i) prime[j] = 0;       }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     sieve();     string s;     cin >> s;     map<char, int> mp;     for (int i = (0); i <= ((int)(s).size() - 1); ++i) mp[s[i]]++;     s =  0  + s;     char k = 0;     for (int i = (0); i <= (256); ++i)       if (mp[k] < mp[i]) k = i;     prime[1] = 1;     for (int i = 2; i + i <= (int)(s).size() - 1; ++i) prime[i] = 0;     for (int i = (1); i <= ((int)(s).size() - 1); ++i)       if (!prime[i]) {         if (mp[k] == 0) {           cout <<  NO n ;           return 0;         }         mp[s[i] = k]--;       }     for (int i = (1); i <= ((int)(s).size() - 1); ++i)       if (prime[i]) {         bool ok = false;         for (int j = (0); j <= (256); ++j)           if (mp[j] > 0) {             mp[s[i] = j]--;             ok = true;             break;           }         if (ok)           continue;         else {           cout <<  NO n ;           return 0;         }       }     s.erase(0, 1);     cout <<  YES n  << s;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   #define ll long long int   const ll mod = 1e9+7;         void solve(){     int a;     cin>>a;     float arr[a];     float sum=0;       for(int i=0;i<a;i++){           cin>>arr[i];           sum+=arr[i];       }   float avg = sum/(float)a;   sort(arr,arr+a);   int ans=0;    for(int i=0;i<a;i++){          if(arr[i]>arr[0])          ans++;       }   cout<<ans<<endl;      }         int main(){    int t;    cin>>t;    while(t--){      solve();    }   }
#include<iostream>   #include <math.h>   using namespace std;    bool issquare(long int num)    {        long int sqrtnum=sqrt(num);        if(num==(sqrtnum*sqrtnum))        {            return true;        }        else{            return false;        }    }    int main()   {   int t;   cin>>t;      for(int i=0;i<t;i++)   {       int flag=0;       long int n;   cin>>n;   if(n%2==0)   {       long int k=n/2;       if(issquare(k))           flag=1;   }   if(flag==0)   {       if(n%4==0)       {           long int l=n/4;           if(issquare(l))           flag=1;       }   }   if(flag==1)   cout<< YES <<endl;   else   cout<< NO <<endl;   }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   const long long oo = 1LL << 60;   const long long kNumMoves = 4;   const long long kMoves[kNumMoves][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};   long long GetMinMoves(long long x, long long y, long long m) {     if (max(x, y) >= m) return 0;     if ((x + y) <= min(x, y)) return -1;     if (x < y) swap(x, y);     long long cnt = 0;     if (y < 0) {       cnt = (-y / x);       y += cnt * x;     }     if (x < y) swap(x, y);     while (max(x, y) < m) {       long long sum = x + y;       long long mx = max(x, y);       x = (sum < mx) ? mx : sum;       y = (x == sum) ? mx : sum;       ++cnt;     }     return cnt;   }   int main() {     long long x, y, m;     cin >> x >> y >> m;     cout << GetMinMoves(x, y, m) << endl;     int i;     cin >> i;     return 0;   }
#include <bits/stdc++.h>   int main() {     char a[21];     char b[21];     int s1[21];     int s2[21];     int lena;     int lenb;     while (scanf( %s%s , &a, &b) != EOF) {       lena = strlen(a);       for (int i = 0; i < lena; i += 2) {         if (a[i] ==  [  && a[i + 1] ==  ] )           s1[i / 2] = 2;         else if (a[i] ==  (  && a[i + 1] ==  ) )           s1[i / 2] = 1;         else if (a[i] ==  8  && a[i + 1] ==  < )           s1[i / 2] = 0;         if (b[i] ==  [  && b[i + 1] ==  ] )           s2[i / 2] = 2;         else if (b[i] ==  (  && b[i + 1] ==  ) )           s2[i / 2] = 1;         else if (b[i] ==  8  && b[i + 1] ==  < )           s2[i / 2] = 0;       }       int sum = 0;       for (int i = 0; i < lena / 2; i++) {         if (s1[i] - s2[i] == 1 || (s1[i] - s2[i] == -2))           sum += 1;         else if ((s1[i] - s2[i] == -1) || (s1[i] - s2[i] == 2))           sum -= 1;       }       if (sum > 0)         printf( TEAM 1 WINS n );       else if (sum < 0)         printf( TEAM 2 WINS n );       else         printf( TIE n );     }     return 0;   }
#include <bits/stdc++.h>   const int maxn = 2 * 100000;   const int inf = 99999999;   class array {    public:     int num;     int left;     int right;     array() { left = right = inf; }   } a[maxn + 1];   int queue[maxn + 1];   int head = 1, tail = 1;   int main() {     int n;     scanf( %d , &n);     int nowzero = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].num);       if (!a[i].num) {         nowzero = i;         a[i].left = a[i].right = 0;         for (int j = head; j < tail; j++) {           a[queue[j]].right = nowzero - queue[j];         }         tail = head;       } else {         if (nowzero) a[i].left = i - nowzero;         queue[tail++] = i;       }     }     for (int i = 1; i <= n; i++)       printf( %d%c , a[i].left > a[i].right ? a[i].right : a[i].left,              i == n ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string q1, q2, ans;     cin >> q1 >> q2;     int n, k = 0, c(0), p;     n = q1.length();     for (int i = 0; i < n; i++) {       if (q1[i] != q2[i]) {         c++;         if (c % 2 == 1) {           ans += q1[i];         } else {           ans += q2[i];         }       } else {         ans += q1[i];       }     }     if (c % 2 == 1) {       cout <<  impossible ;     } else {       cout << ans;     }   }
#include <bits/stdc++.h>   int main() {     int a[4], i, test, flag = 1, flag2 = 1;     double test2, testn;     for (i = 0; i < 4; i++) scanf( %d , &a[i]);     test = a[1] - a[0];     if (a[2] - a[1] == test && a[3] - a[2] == test) {       printf( %d , a[3] + test);       flag = 0;       flag2 = 0;     }     if (flag) {       test2 = (double)a[1] / a[0];       if (fabs((double)a[2] / a[1] - test2) < 0.001 &&           fabs((double)a[3] / a[2] - test2) < 0.001) {         testn = a[3] * test2;         if (fabs(testn - (int)testn) < 0.001) {           printf( %.0f , testn);           flag2 = 0;         }       }     }     if (flag2) printf( 42 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   const ll MOD = 998244353;   const ll INF = 1e15 + 373;   template <typename T>   using vector2 = vector<vector<T>>;   template <typename T>   vector2<T> init_vector2(size_t n0, size_t n1, T e = T()) {     return vector2<T>(n0, vector<T>(n1, e));   }   template <typename T>   using vector3 = vector<vector<vector<T>>>;   template <typename T>   vector3<T> init_vector3(size_t n0, size_t n1, size_t n2, T e = T()) {     return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  [ ;     for (T e : v) {       os << e <<  ,  ;     }     os <<  ] ;     return os;   }   class Point {    public:     ll y, x;     Point() : y(0), x(0) {}     Point(ll y, ll x) : y(y), x(x) {}     bool operator==(const Point& p) { return this->y == p.y && this->x == p.x; }     ll distance(const Point& p) {       return abs(this->y - p.y) + abs(this->x - p.x);     }     friend ostream& operator<<(ostream& os, const Point& p) {       os <<  (  << p.x <<  ,   << p.y <<  ) ;       return os;     }   };   signed main() {     ll n;     cin >> n;     vector<Point> ps(n + 1);     for (ll i = 0; i < (ll)(n); ++i) {       ll x, y;       cin >> x >> y;       ps[i] = Point(y, x);     }     ps[n] = Point(0, 0);     vector<ll> levels(n + 1);     for (ll i = 0; i < (ll)(n + 1); ++i) {       levels[i] = max(ps[i].y, ps[i].x);     }     sort(levels.begin(), levels.end());     levels.erase(unique(levels.begin(), levels.end()), levels.end());     map<ll, ll> levelmap;     for (ll i = 0; i < (ll)(levels.size()); ++i) {       levelmap[levels[i]] = i;     }     vector<Point> minX(levels.size(), Point(0, 0));     vector<Point> minY(levels.size(), Point(0, 0));     for (ll i = 0; i < (ll)(n); ++i) {       ll lev = levelmap[max(ps[i].y, ps[i].x)];       if (minX[lev] == Point(0, 0) || ps[i].x < minX[lev].x ||           (ps[i].x == minX[lev].x && ps[i].y >= minX[lev].y)) {         minX[lev] = ps[i];       }       if (minY[lev] == Point(0, 0) || ps[i].y < minY[lev].y ||           (ps[i].y == minY[lev].y && ps[i].x >= minY[lev].x)) {         minY[lev] = ps[i];       }     }     vector<vector<ll>> dp(levels.size(), vector<ll>(2));     dp[levels.size() - 1][0] =         minX[levels.size() - 1].distance(minY[levels.size() - 1]);     dp[levels.size() - 1][1] =         minY[levels.size() - 1].distance(minX[levels.size() - 1]);     for (ll i = levels.size() - 2; i >= 0; i--) {       dp[i][0] = min(minX[i].distance(minY[i]) + minY[i].distance(minX[i + 1]) +                          dp[i + 1][0],                      minX[i].distance(minY[i]) + minY[i].distance(minY[i + 1]) +                          dp[i + 1][1]);       dp[i][1] = min(minY[i].distance(minX[i]) + minX[i].distance(minX[i + 1]) +                          dp[i + 1][0],                      minY[i].distance(minX[i]) + minX[i].distance(minY[i + 1]) +                          dp[i + 1][1]);     }     cout << dp[0][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 500;   int n;   long long a[maxn], ans;   long long dfs(int l, int r, int now) {     if (l == r) {       return 1;     }     long long fenge = r + 1;     for (int i = l; i <= r; i++) {       if (a[i] & (1 << now)) {         fenge = i;         break;       }     }     long long ans = 0;     if (fenge == l || fenge == r + 1) {       ans = dfs(l, r, now - 1);     } else {       ans = max(dfs(l, fenge - 1, now - 1), dfs(fenge, r, now - 1)) + 1;     }     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     ans = dfs(1, n, 30);     cout << n - ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int test;     cin >> test;     while (test--) {       int n, m;       cin >> n >> m;       int array[n];       for (int i = 0; i < n; i++) cin >> array[i];       int sum = 0;       for (int i = 0; i < n; i++) {         sum += array[i];       }       double average = sum / double(n);       double value = m / double(n);       if (value <= average)         cout << m << endl;       else         cout << average * n << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     int r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   int GCD(int a, int b) {     if (a == 0)       return b;     else       return GCD(b % a, a);   }   long long int power(long long int a, long long int b) {     long long int r = 1;     while (b) {       if (b & 1) {         r = r * a;         b--;       }       a = a * a;       b >>= 1;     }     return r;   }   int palindrome(char *s, int len) {     int i, j, k, count = 0, c = 0;     for (i = 0, j = len - 1; i < len, j >= 0; i++, j--) {       if (s[i] == s[j]) count++;     }     if (count == len)       return 1;     else       return 0;   }   long long int binary(char *s, long long int len) {     long long int i, j, k, r = 0, p = 0, num;     for (i = len - 1; i >= 0; i--) {       num = s[i] -  0 ;       r += (num * power(2, p));       p++;     }     return r;   }   int binary_search(int *ara, int size, int n) {     int high, mid, low;     low = 0;     high = size - 1;     while (low <= high) {       mid = (low + high) / 2;       if (ara[mid] == n) {         return 1;       } else if (n > ara[mid])         low = mid + 1;       else if (n < ara[mid])         high = mid - 1;     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int i, j, k, n, T, q, a, b, num;     string s1, s2;     cin >> a >> b;     int ara[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};     long long sum = 0;     for (i = a; i <= b; i++) {       num = i;       while (num) {         int mod = num % 10;         sum = sum + (ara[mod]);         num /= 10;       }     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     ;     cin >> t;     while (t--) {       int s;       vector<int> v;       cin >> s;       for (int i = 0; i < s; i++) {         int x;         cin >> x;         v.push_back(x);       }       int f = 0;       for (int i = 0; i < s - 1; i++) {         if (v[i] != v[i + 1]) f = 1;       }       if (f == 1)         cout <<  1  << endl;       else         cout << s << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 200000;   const int MAX_L = MAX_N * 2;   vector<int> nbrs[MAX_N];   int ps[MAX_N], cis[MAX_N], vs[MAX_L];   bool used[MAX_N];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       u--, v--;       nbrs[u].push_back(v);       nbrs[v].push_back(u);     }     ps[0] = -1;     int l = 0;     for (int u = 0; u >= 0;) {       vector<int> &nbru = nbrs[u];       if (cis[u] == 0) {         vs[l++] = u;         used[u] = true;       }       while (cis[u] < nbru.size() && used[nbru[cis[u]]]) cis[u]++;       if (cis[u] < nbru.size()) {         int v = nbru[cis[u]++];         ps[v] = u;         u = v;       } else {         int v = ps[u];         if (v >= 0) vs[l++] = v;         u = v;       }     }     int q = l / k, r = l % k;     for (int i = 0, j = 0; i < k; i++) {       int ci = q + ((i < r) ? 1 : 0);       printf( %d , ci);       while (ci--) printf(  %d , vs[j++] + 1);       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   const int INF = (int)1e9;   const int long minINF = (int)-1e9;   const int mod = (int)1e9 + 7;   const int MAXN = (int)2e6 + 5;   using namespace std;   long long arr[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int N;     cin >> N;     for (int i = 0; i < N; i++) cin >> arr[i];     long long f, x;     cin >> x >> f;     long long ans = 0;     for (int i = 0; i < N; i++) {       ans += arr[i] / (f + x) * f;       if (arr[i] % (f + x) > x) {         ans += f;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, tmpsum = 0;     cin >> n;     int v[2][n];     for (int i = 0; i < n; i++) cin >> v[0][i] >> v[1][i];     for (int i = 0; i < n; i++) {       sum += v[1][i];       sum -= v[0][i];       if (sum >= tmpsum) tmpsum = sum;     }     cout << tmpsum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int an = 0;   int ht;   char a[20][20][20];   int h[20][20][20];   int fill(int x, int y, int k) {     if (k <= 0 || k > ht || a[k][x][y] ==  #  || h[k][x][y]) return 1;     an++;     h[k][x][y] = 1;     fill(x - 1, y, k);     fill(x, y - 1, k);     fill(x, y + 1, k);     fill(x + 1, y, k);     fill(x, y, k - 1);     fill(x, y, k + 1);     return 1;   }   int main() {     char s[100];     int x, y, i, j, k, n, m, u;     memset(h, 0, sizeof(h));     scanf( %d%d%d , &k, &n, &m);     ht = k;     for (i = k; i > 0; i--) {       for (j = 1; j < n + 1; j++) {         scanf( %s , &a[i][j][1]);       }     }     for (i = 1; i < k + 1; i++) {       for (j = 0; j < m + 2; j++) {         a[i][0][j] =  # ;         a[i][n + 1][j] =  # ;       }       for (j = 0; j < n + 2; j++) {         a[i][j][0] =  # ;         a[i][j][m + 1] =  # ;       }     }     scanf( %d%d , &x, &y);     fill(x, y, k);     printf( %d n , an);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, c;   vector<int> l;   vector<int> r;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> c;     while (l.size() + r.size() < n) {       int val;       cin >> val;       if (val <= c / 2) {         bool temp = 0;         for (int i = 0; i < (int)l.size(); i++) {           if (l[i] > val) {             l[i] = val;             temp = 1;             cout << i + 1 << endl;             break;           }         }         if (!temp) {           l.push_back(val);           cout << l.size() << endl;         }       } else {         bool temp = 0;         for (int i = 0; i < (int)r.size(); i++) {           if (r[i] < val) {             r[i] = val;             cout << n - i << endl;             temp = 1;             break;           }         }         if (!temp) {           r.push_back(val);           cout << n - r.size() + 1 << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 102;   char a[N][N][N];   int main() {     int n, m, p;     int i, j, k, l;     scanf( %d%d%d , &n, &m, &p);     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) scanf(  n%s , &a[i][j][0]);       for (j = 0; j < m; j++)         for (k = 0; k < p; k++)           if (a[i][j][k] ==  0 ) a[i][j][k] = 0;       if (i != n - 1) scanf(  n );     }     int s = 0;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         for (k = 0; k < p; k++)           if (a[i][j][k]) {             if (k - 1 >= 0 && k + 1 < p && a[i][j][k - 1] && a[i][j][k + 1])               s++;             else if (j - 1 >= 0 && j + 1 < m && a[i][j - 1][k] && a[i][j + 1][k])               s++;             else if (i - 1 >= 0 && i + 1 < n && a[i - 1][j][k] && a[i + 1][j][k])               s++;             else if (i - 1 >= 0 && j + 1 < m && a[i - 1][j][k] &&                      a[i][j + 1][k] && !a[i - 1][j + 1][k])               s++;             else if (i - 1 >= 0 && k + 1 < p && a[i - 1][j][k] &&                      a[i][j][k + 1] && !a[i - 1][j][k + 1])               s++;             else if (j - 1 >= 0 && i + 1 < n && a[i][j - 1][k] &&                      a[i + 1][j][k] && !a[i + 1][j - 1][k])               s++;             else if (j - 1 >= 0 && k + 1 < p && a[i][j - 1][k] &&                      a[i][j][k + 1] && !a[i][j - 1][k + 1])               s++;             else if (k - 1 >= 0 && i + 1 < n && a[i][j][k - 1] &&                      a[i + 1][j][k] && !a[i + 1][j][k - 1])               s++;             else if (k - 1 >= 0 && j + 1 < m && a[i][j][k - 1] &&                      a[i][j + 1][k] && !a[i][j + 1][k - 1])               s++;             {}           }     printf( %d , s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1E-9;   const double Exp = 2.718281828459045;   const double Pi = 3.1415926535897932;   const int Max_Bit = 63;   const int INF = 2000000000;   const long long LINF = 1000000000000000007ll;   const int MOD = 1000000007;   const int NMAX = 100005;   const int MMAX = 505;   const int KMAX = 6;   const string CODE =  CODEFORCES ;   const int go[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};   int n, a[NMAX], l[NMAX], r[NMAX];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int q, u, v;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i + 1]);     }     for (int i = 0; i < n - 1; ++i) {       a[i + 1] = abs(a[i + 2] - a[i + 1]);     }     a[0] = INF;     a[n] = INF;     for (int i = 1; i < n; ++i) {       l[i] = i - 1;       while (a[i] >= a[l[i]]) {         l[i] = l[l[i]];       }     }     for (int i = n - 1; i > 0; i--) {       r[i] = i + 1;       while (a[i] > a[r[i]]) {         r[i] = r[r[i]];       }     }     for (int i = 0; i < q; ++i) {       long long ans = 0;       scanf( %d%d , &u, &v);       for (int j = u; j < v; ++j) {         ans += (j - max(l[j], u - 1)) * 1ll * (min(r[j], v) - j) * 1ll * a[j];       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long dp[500005] = {0};       dp[3] = 8;       long long fac = 2;       for (long long i = 5; i <= 500000; i += 2) {         dp[i] = dp[i - 2] + fac * (i + i + i - 2 + i - 2);         ++fac;       }       cout << dp[n] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   string str;   long long int n, k;   int main() {     string temp;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int a, b, i, j, cnt = 0;     cin >> str;     n = str.size();     cin >> k;     for (i = 0; i < k; i++) {       cin >> temp;       for (j = 0; j < n; j++) {         a = 0, b = 0;         while (j < n && (str[j] == temp[0] || str[j] == temp[1])) {           if (str[j] == temp[0])             a++;           else             b++;           j++;         }         cnt += min(a, b);       }     }     cout << cnt <<   n ;     return 0;   }