malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, k;   string s;   int f[2222][2222][2];   const int mod = 1000000007;   int sum[2222][2222];   inline void add(int i, int j, int k, int val) {     f[i][j][k] += val;     if (f[i][j][k] >= mod) f[i][j][k] -= mod;   }   int solve() {     int ans = 0;     for (int pos = 0; pos < n; ++pos) {       int ls = s[pos] -  a ;       int mr = 25 - ls;       for (int cnt = 0; cnt <= k; ++cnt) {         add(pos, cnt, 0, ((long long)ls * (sum[cnt][pos - 1])) % mod);         if (!cnt) {           add(pos, cnt, 0, ls);         }         for (int prev = pos - 1; prev >= 0; --prev) {           int to_add = (pos - prev) * (n - pos);           if (to_add > cnt) break;           add(pos, cnt, 1, ((long long)mr * f[prev][cnt - to_add][0]) % mod);           add(pos, cnt, 1, ((long long)mr * f[prev][cnt - to_add][1]) % mod);         }         int to_add = (pos + 1) * (n - pos);         if (to_add == cnt) {           add(pos, cnt, 1, mr);         }         sum[cnt][pos] += f[pos][cnt][0];         if (sum[cnt][pos] >= mod) sum[cnt][pos] -= mod;         sum[cnt][pos] += f[pos][cnt][1];         if (sum[cnt][pos] >= mod) sum[cnt][pos] -= mod;         sum[cnt][pos] += sum[cnt][pos - 1];         if (sum[cnt][pos] >= mod) sum[cnt][pos] -= mod;       }       ans += f[pos][k][0];       if (ans >= mod) ans -= mod;       ans += f[pos][k][1];       if (ans >= mod) ans -= mod;     }     if (k == 0) {       ++ans;       if (ans == mod) ans = 0;     }     return ans;   }   int main() {     cin >> n >> k;     cin >> s;     cout << solve() << endl;   }
#include <bits/stdc++.h>   using namespace std;   int T, c, d;   int Abs(int x) { return x >= 0 ? x : -x; }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d%d , &c, &d);       if (c == d) {         if (c)           printf( 1 n );         else           printf( 0 n );       } else {         if (Abs(c - d) & 1)           printf( -1 n );         else           printf( 2 n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   char s[111111];   int m, l, r, n, pos[111111], nxt[111111][28], pre[111111][28], pr[111111][28],       nx[111111][28], cur[28], a[111111];   int prefix[111111];   int solve(int l, int r);   int getsuf(int pos, int k) {     if (~nx[pos][k]) return nx[pos][k];     return nx[pos][k] = solve(pos, nxt[pos][k] - 1);   }   int getpre(int pos, int k) {     if (~pr[pos][k]) return pr[pos][k];     return pr[pos][k] = solve(pre[pos][k] + 1, pos);   }   int solve(int l, int r) {     if (l > r) return 0;     if (l == r) return 1;     bool used[55];     memset(used, 0, sizeof(used));     int ans, res;     for (int i = 0; i < 26; i++) {       int s = nxt[l][i], e = pre[r][i];       if (s > e || !s || !e) continue;       ans = prefix[e] ^ prefix[pre[s][i]];       if (s != l) ans ^= getsuf(l, i);       if (e != r) ans ^= getpre(r, i);       used[ans] = 1;     }     res = 0;     while (used[res]) res++;     return res;   }   int main() {     scanf( %s , s);     n = strlen(s);     for (int i = 1; i <= n; i++) {       a[i] = s[i - 1] -  a ;     }     memset(nx, -1, sizeof(nx));     memset(pr, -1, sizeof(pr));     for (int i = n; i >= 1; i--) {       cur[a[i]] = i;       for (int j = 0; j < 26; j++) nxt[i][j] = cur[j];     }     memset(cur, 0, sizeof(cur));     for (int i = 1; i <= n; i++) {       cur[a[i]] = i;       for (int j = 0; j < 26; j++) pre[i][j] = cur[j];     }     for (int i = 1; i <= n; i++) {       if (!pre[i][a[i]]) continue;       prefix[i] = prefix[pre[i - 1][a[i]]] ^ solve(pre[i - 1][a[i]] + 1, i - 1);     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &l, &r);       if (!solve(l, r))         printf( Bob n );       else         printf( Alice n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000001;   const double EPS = 10e-9;   const int SIZE = 20;   char number[SIZE];   vector<int> dig[SIZE];   inline void mySwap(int i, int j) {     char tmp = number[j];     for (typeof(j) k = (j); k >= (i + 1); --k) number[k] = number[k - 1];     number[i] = tmp;   }   void fun(int n, int k) {     int bg = 0;     for (; bg < n; ++bg) {       for (typeof(9) i = (9); i >= (0); --i) {         if (i <= number[bg] -  0 ) break;         for (typeof(bg + 1) j = (bg + 1); j < (n); ++j) {           if (number[j] -  0  == i) {             if (k >= j - bg) {               k -= j - bg;               mySwap(bg, j);               ++bg;               if (!k) return;             }           }         }       }     }   }   void rob() {     int k;     scanf( %s %d , number, &k);     int n = strlen(number);     fun(n, k);     printf( %s n , number);   }   int main() {     int test = 1;     while (test--) rob();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   int arr[maxn];   map<int, int> mp;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     vector<int> v;     for (int i = n - 1; i >= 0; i--) {       if (mp[arr[i]] == 0) {         mp[arr[i]] = 1;         v.push_back(arr[i]);       }     }     reverse(v.begin(), v.end());     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;   }
#include <bits/stdc++.h>   int pow(int a) {     int o = 1;     for (int i = 0; i < a; i++) {       o = (o * 2) % 998244353;     }     return o;   }   int main(void) {     int n, m;     scanf( %d%d , &n, &m);     printf( %d , pow(n + m));   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   int n;   vector<int> vec[MAXN];   map<int, pair<int, int> > mp;   int main() {     cin >> n;     cin.tie(0);     for (int i = 0; i < n; i++) {       int t;       cin >> t;       vec[i].resize(t);       int sm = 0;       for (int j = 0; j < t; j++) cin >> vec[i][j], sm += vec[i][j];       for (int j = 0; j < t; j++)         if (mp.count(sm - vec[i][j])) {           int z = sm - vec[i][j];           if (mp[z].first == i) continue;           cout <<  YES n ;           cout << mp[z].first + 1 <<     << mp[z].second + 1 <<   n ;           cout << i + 1 <<     << j + 1 <<   n ;           return 0;         } else           mp[sm - vec[i][j]] = make_pair(i, j);     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const long long int N = 100005;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;       cin >> m >> n;       long long int a[n];       map<long long int, long long int> mp;       for (i = 0; i < n; i++) {         cin >> a[i];         mp[a[i]]++;         sum += a[i];       }       if (sum < m) {         cout << -1 <<   n ;       } else {         set<long long int> St;         for (i = 0; i < 62; i++) {           if (m >> i & 1ll) {             St.insert(1ll << i);           }         }         cnt = 1;         sum = 0;         for (auto x : St) {           while (cnt <= x) {             sum += mp[cnt] * cnt;             cnt *= 2;           }           if (sum >= x)             sum -= x;           else {             long long int nxt = cnt;             while (mp[nxt] == 0) {               nxt *= 2;             }             mp[nxt]--;             ans += log2(nxt / x);             while (nxt > x) {               nxt /= 2;               mp[nxt]++;             }           }         }         cout << ans <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     char dt[1002];     memset(dt, 0, sizeof(dt));     char gr[1002];     memset(gr, 0, sizeof(gr));     cin >> dt >> gr;     int n = strlen(dt);     int m = strlen(gr);     map<char, int> dtc;     map<char, int> gtc;     for (int i = 0; i < n; ++i) {       dtc[dt[i]]++;     }     for (int i = 0; i < m; ++i) {       gtc[gr[i]]++;     }     int res = 0;     map<char, int>::iterator it;     for (it = gtc.begin(); it != gtc.end(); ++it) {       char val = it->first;       if (dtc[val] == 0) {         cout << -1;         return 0;       }       if (dtc[val] >= gtc[val])         res += gtc[val];       else         res += dtc[val];     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>      #define ALL(x) x.begin(), x.end()   #define pb push_back   #define db1(x) cout << #x <<   =   << x << endl   #define db2(x, y) cout << #x <<   =   << x <<  ,   << #y <<   =   << y << endl   using namespace std;   void localFileInput() {   #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);   #endif   }   typedef long long ll;   typedef pair<int, int> pii;   const ll mod = 1e9+7;   const int N = 1e5+10;   int n, m, a[N];   struct Node   {       int r;       double p;       void input() {           scanf( %d%lf , &r, &p);       }   }b[N];   int r[N];   bool cmp(Node a , Node b) {       return a.r < b.r;   }   void sol() {       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; ++ i) scanf( %d , &a[i]);       for (int i = 1; i <= m; ++ i) b[i].input();       sort(b + 1, b + 1 + m, cmp);       for (int i = 1; i <= m; ++ i) r[i] = b[i].r;       int id = 0;       for (int i = n; i >= 1; -- i) if(a[i] != i) {           id = i;           break;       }       if(id == 0) {           puts( 1.000000 );           return ;       }       int st = lower_bound(r+1, r+1+m, id) - r;          double ans = 1.0;       for (int i = st; i <= m; ++ i)            ans = ans * (1 - b[i].p);       printf( %.6f n , 1-ans);   }   int main() {       localFileInput();       int _; scanf( %d , &_); while(_ --) sol();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, a, b, i = 0, cnt = 0, y;     cin >> n >> a >> b;     while (n >= 0) {       if (i == 0) {         n = n;       } else {         n = n - a;       }       if (n % b == 0 && n >= 0) {         y = n / b;         cnt++;         break;       }       i++;     }     if (cnt > 0) {       cout <<  YES  << endl;       cout << i <<     << y;     } else if (cnt == 0) {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 7;   long long n, q;   long long a[maxn];   long long m;   map<long long, long long> ma;   long long Mod(long long x, long long mod) {     if (x < mod) return x;     return x % mod + mod;   }   long long fp(long long a, long long b, long long mod) {     long long tmp = 1;     while (b) {       if (b & 1) tmp = Mod(tmp * a, mod);       b >>= 1, a = Mod(a * a, mod);     }     return tmp;   }   long long phi(long long k) {     long long s = k, kk = k;     if (ma.count(k)) return ma[k];     for (long long i = 2; i * i <= k; i++) {       if (k % i == 0) s = s / i * (i - 1);       while (k % i == 0) k /= i;     }     if (k > 1) s = s / k * (k - 1);     return ma[kk] = s;   }   long long solve(long long l, long long r, long long mod) {     if (l == r || mod == 1) return Mod(a[l], mod);     return fp(a[l], solve(l + 1, r, phi(mod)), mod);   }   int main() {     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     scanf( %d , &q);     while (q--) {       long long l, r;       scanf( %lld%lld , &l, &r);       printf( %lld n , solve(l, r, m) % m);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, N = 1e3 + 10;   int tp[maxn], x[maxn], y[maxn];   vector<int> edge;   char ch[2];   int rt[N], V, E, i, k;   int root(int u) {     if (rt[u] < 0)       return u;     else       return rt[u] = root(rt[u]);   }   void init(int _V) {     for (i = 1; i <= _V; i++) rt[i] = -1;   }   void merge(int u, int v) {     u = root(u);     v = root(v);     rt[v] = u;   }   void Read() {     scanf( %d%d , &V, &E);     for (i = 1; i <= E; i++) {       scanf( %d%d%s , x + i, y + i, ch);       tp[i] = (ch[0] ==  S ) ? 1 : 0;     }   }   void runs() {     if (V % 2 != 1) puts( -1 ), exit(0);     k = V >> 1;     init(V);     for (i = 1; i <= E; i++)       if (!tp[i] and root(x[i]) != root(y[i])) {         merge(x[i], y[i]);       }     for (i = 1; i <= E; i++)       if (tp[i] and root(x[i]) != root(y[i])) {         edge.push_back(i);         merge(x[i], y[i]);       }     if (((int)((edge).size())) > k) puts( -1 ), exit(0);     init(V);     for (i = 0; i < ((int)((edge).size())); i++) merge(x[edge[i]], y[edge[i]]);     for (i = 1; i <= E; i++)       if (((int)((edge).size())) < k and tp[i] and root(x[i]) != root(y[i])) {         edge.push_back(i);         merge(x[i], y[i]);       }     if (((int)((edge).size())) < k) puts( -1 ), exit(0);     for (i = 1; i <= E; i++)       if (!tp[i] and root(x[i]) != root(y[i])) {         edge.push_back(i);         merge(x[i], y[i]);       }     if (((int)((edge).size())) < 2 * k) puts( -1 ), exit(0);     printf( %d n , V - 1);     for (i = 0; i < ((int)((edge).size())); i++) printf( %d  , edge[i]);     puts(  );   }   int main() {     Read();     runs();   }
#include <bits/stdc++.h>   using namespace std;   int n, c;   int a[1 << 20], b[1 << 20];   char tp[1 << 20];   int hs[128][128];   int ne[128][128];   int li[128];   bool getDP(int l, int r) {     if (hs[l][r] != -1) return hs[l][r];     if (l >= r) {       return (hs[l][r] = 1);     }     hs[l][r] = 0;     for (int k = l; k <= r; ++k) {       bool ok = true;       for (int i = 0; i < c; ++i) {         if (a[i] == l) {           if (tp[i] ==  L  && b[i] > k) ok = false;           if (tp[i] ==  R  && b[i] <= k) ok = false;         }         if (a[i] > l && a[i] <= k) {           if (b[i] > k) ok = false;         }       }       if (ok) {         if (getDP(l + 1, k) && getDP(k + 1, r)) {           ne[l][r] = k;           hs[l][r] = 1;           break;         }       }     }     return hs[l][r];   }   int le[1 << 20], ri[1 << 20];   void cli(int l, int r) {     if (l >= r) return;     li[l] = ne[l][r];     if (li[l] > l) {       le[l] = l + 1;       cli(l + 1, li[l]);     }     if (li[l] < r) {       ri[l] = li[l] + 1;       cli(li[l] + 1, r);     }   }   vector<int> sl;   void sol(int v) {     if (le[v] != -1) sol(le[v]);     sl.push_back(v);     if (ri[v] != -1) sol(ri[v]);   }   int main() {     scanf( %d %d , &n, &c);     char buf[32];     for (int i = 0; i < c; i++) {       scanf( %d %d %s , &a[i], &b[i], buf);       tp[i] = buf[0];       if (a[i] >= b[i]) {         printf( IMPOSSIBLE n );         return 0;       }     }     memset(hs, -1, sizeof(hs));     bool ok = getDP(1, n);     if (!ok) {       printf( IMPOSSIBLE n );       return 0;     }     memset(li, -1, sizeof(li));     memset(le, -1, sizeof(le));     memset(ri, -1, sizeof(ri));     cli(1, n);     sol(1);     for (int i = 0; i + 1 < (int)sl.size(); i++) {       printf( %d  , sl[i]);     }     printf( %d n , sl.back());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void debug(int* a, int n, bool flag = false) {     if (!flag) printf( array  );     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     printf(  n );   }   void debug(vector<int>& E, bool flag = false) {     if (!flag) printf( vector  );     for (auto it : E) printf( %d  , it);     printf(  n );   }   const int maxn = 2e5 + 5;   int a[maxn];   set<pair<int, int> > s;   int n, m;   map<int, bool> Map;   vector<int> res;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       Map[a[i]] = true;       s.insert(make_pair(i, -1));       s.insert(make_pair(i, 1));     }     sort(a + 1, a + 1 + n);     long long ans = 0;     long long k = 1;     while (m) {       auto it = s.begin();       while (it != s.end()) {         long long val = a[it->first] + k * it->second;         if (!Map.count(val)) {           res.push_back(val);           ans += k;           it++;           m--;           Map[val] = true;           if (!m) break;         } else           s.erase(it++);       }       k++;     }     printf( %I64d n , ans);     debug(res, true);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct lr {     long long left, right;     lr() : left(-1), right(1e7) {}     lr(long long _l, long long _r) : left(_l), right(_r) {}   };   int main() {     long long n;     scanf( %lld , &n);     vector<long long> arr(n);     for (int i = 0; i < n; i++) scanf( %lld , &arr[i]);     vector<lr> mn(n, lr(0, n - 1));     vector<lr> mx(n, lr(0, n - 1));     stack<lr> mxs, mns;     for (int i = 0; i < n; i++) {       while (!mxs.empty()) {         if (mxs.top().left >= arr[i]) {           break;         } else {           lr it = mxs.top();           mxs.pop();           mx[it.right].right = i - 1;         }       }       mxs.push(lr(arr[i], i));       while (!mns.empty()) {         if (mns.top().left <= arr[i]) {           break;         } else {           lr it = mns.top();           mns.pop();           mn[it.right].right = i - 1;         }       }       mns.push(lr(arr[i], i));     }     while (!mxs.empty()) mxs.pop();     while (!mns.empty()) mns.pop();     for (int i = n - 1; i >= 0; i--) {       while (!mxs.empty()) {         if (mxs.top().left > arr[i]) {           break;         } else {           lr it = mxs.top();           mxs.pop();           mx[it.right].left = i + 1;         }       }       mxs.push(lr(arr[i], i));       while (!mns.empty()) {         if (mns.top().left < arr[i]) {           break;         } else {           lr it = mns.top();           mns.pop();           mn[it.right].left = i + 1;         }       }       mns.push(lr(arr[i], i));     }     long long res = 0;     for (int i = 0; i < n; i++) {       long long x1 = mx[i].right - i + 1, x2 = mn[i].right - i + 1,                 n1 = i - mx[i].left + 1, n2 = i - mn[i].left + 1;       long long a = x1 * n1;       long long b = x2 * n2;       res += a * arr[i];       res -= b * arr[i];     }     cout << res << endl;     return 0;   }
#include <iostream>     #include <bits/stdc++.h>    #include <stdio.h>   #include <cstdlib>   #include<algorithm>    #include<string.h>   #include<map>   #include<math.h>   using namespace std;    int main()   {   int t;   cin>>t;   while(t--)   {   int n,k;   cin>>n>>k;int count =0;   vector <int> v,a(n);int max=n;   if(k>(n-1)/2)    {   cout<< -1 <<endl;       continue;   }   for(int i=1;i<n;i+=2)   {       if(count==k)           break;       a[i]=max;       max--;           count++;      }   for(int i=0;i<n;i++)   {       if(a[i]!=0)           continue;       a[i]=max;       max--;   }   for(int i=0;i<n;i++)   {       cout<<a[i]<<   ;   }      cout<<endl;   }   }
#include <bits/stdc++.h>   using namespace std;   const long long maxM = 22, maxN = ((1LL << 20) + 1);   long long M, mod, T, N;   int bc[maxM][maxM];   int dp[maxN][2][maxM];   int arr[maxN], b[maxM], p2[maxM];   struct Matrix {     long long n, m;     long long val[maxM][maxM];     Matrix() {       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) val[i][j] = 0;     }   };   Matrix operator*(Matrix A, Matrix B) {     Matrix ret;     ret.n = 1, ret.m = M;     for (int k = 0; k <= M; k++) {       long long vl = 0;       for (int i = 0; i <= (M - k); i++) {         long long vl2 = 0;         for (int j = 0; j <= k; j++) {           vl2 = (vl2 +                  (((bc[k][j] * A.val[0][i + j]) % mod) * B.val[0][i + k - j])) %                 mod;         }         vl = (vl + (bc[M - k][i] * vl2)) % mod;       }       vl %= mod;       if (vl < 0) vl += mod;       ret.val[0][k] = vl;     }     return ret;   }   Matrix Pow(Matrix A, long long b) {     Matrix Temp;     Temp.n = 1;     Temp.m = M;     for (int i = 0; i <= M; i++) Temp.val[0][i] = (int(i == 0));     if (b == 0) return Temp;     Matrix res = A;     for (b--; b; b >>= 1, A = A * A)       if (b & 1) res = res * A;     return res;   }   int main() {     scanf( %lld%lld%lld , &M, &T, &mod);     N = (1LL << M);     for (int i = 0; i < N; i++) {       scanf( %lld , &arr[i]);       arr[i] %= mod;       dp[i][0][0] = arr[i];     }     bc[0][0] = 1;     p2[0] = 1;     for (int i = 1; i <= (M + 1); i++) {       p2[i] = 2 * p2[i - 1];       for (int j = 0; j <= i; j++) {         if (j == 0 || j == i)           bc[i][j] = 1;         else           bc[i][j] = (bc[i - 1][j - 1] + bc[i - 1][j]);       }     }     for (int i = 0; i <= M; i++) {       scanf( %lld , &b[i]);       b[i] %= mod;     }     long long J = 1;     for (int j = 1; j <= M; j++) {       for (int i = 0; i < N; i++) {         for (int k = 0; k <= M; k++) {           if (j == 0 && k == 0) {             dp[i][J][k] = arr[i];           } else if (j == 0)             dp[i][J][k] = 0;           else {             dp[i][J][k] = (dp[i][1 - J][k] + dp[i ^ (p2[j - 1])][1 - J][k - 1]);             if (dp[i][J][k] >= mod) dp[i][J][k] -= mod;           }         }       }       J = 1 - J;     }     Matrix B;     B.n = 1;     B.m = M;     for (int i = 0; i <= M; i++) B.val[0][i] = b[i];     Matrix c = Pow(B, T);     long long MD = M % 2, ans;     for (int i = 0; i < N; i++) {       ans = 0;       for (int j = 0; j <= M; j++)         ans = (ans + (c.val[0][j] * dp[i][MD][j])) % mod;       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double n, l, k, v1, v2;   int main() {     cout << fixed << setprecision(10);     cin >> n >> l >> v1 >> v2 >> k;     if (v2 <= v1) {       cout << l / (v1 * 1.0) << endl;       return 0;     }     if (n <= k) {       cout << l / (v2 * 1.0) << endl;       return 0;     }     int T = ceil(n / (k * 1.0));     long double K = ((T - 1) * (1 + (v2 - v1) / ((v2 + v1) * 1.0))) * v1;     K += v2;     K = l / K;     long double ans = K * (T + (T - 1) * (v2 - v1) / (v2 + v1));     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 7;   const long long INF = 1e18 + 7;   int n, a[MAXN], d[MAXN] = {}, k, l = 1, r = 0;   long long f[MAXN], g[MAXN], ans = 0;   void add(long long &a, const long long &b) {     a += b;     if (a > INF) a = INF;   }   long long sum(long long a, long long b) {     a += b;     if (a > INF) a = INF;     return a;   }   void cost(int newl, int newr) {     while (r < newr) ans += 1LL * (d[a[++r]]++);     while (r > newr) ans -= 1LL * (--d[a[r--]]);     while (l > newl) ans += 1LL * (d[a[--l]]++);     while (l < newl) ans -= 1LL * (--d[a[l++]]);   }   void calc(int l, int r, int mn, int mx) {     if (l > r) return;     int mid = (l + r) >> 1, opt = 0;     for (int i = min(mx, mid - 1); i >= mn; --i) {       cost(i + 1, mid);       if (g[i] + ans < f[mid]) f[mid] = g[i] + ans, opt = i;     }     calc(l, mid - 1, mn, opt);     calc(mid + 1, r, opt, mx);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];     g[0] = f[0] = 0;     for (int i = 1; i <= n; ++i) f[i] = g[i] = INF;     for (int i = 1; i <= k; ++i) {       calc(1, n, 0, n);       for (int j = 1; j <= n; ++j) g[j] = f[j], f[j] = INF;     }     cout << g[n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long mx = 2e6 + 10;   int posx[] = {1, -1, 0, 0};   int posy[] = {0, 0, 1, -1};   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1, n, k, m, a, b, c, d, h;     cin >> t;     while (t--) {       cin >> h >> c >> k;       if (h + c >= 2 * k) {         cout << 2 << endl;         continue;       }       long long x = (c - k) / (h + c - (2 * k));       long long y = x + 1;       long double xx = ((h * x) + (c * (x - 1))) / ((1.0) * 2 * x - 1);       long double yy = ((h * y) + (c * (y - 1))) / ((1.0) * 2 * y - 1);       if (abs(xx - k) <= abs(yy - k))         cout << 2 * x - 1 << endl;       else         cout << 2 * y - 1 << endl;     }     return 0;   }