malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   double prec = 0.00000001;   void calcHistory(vector<double>& history, int hp2, double p1, int l1, int h1) {     double h[201];     double newh[201];     memset(h, 0, sizeof(h));     memset(newh, 0, sizeof(newh));     h[hp2] = 1.;     for (int i = 0; i < history.size(); ++i) {       for (int j = 1; j <= hp2; ++j)         if (h[j] > 0) {           double pHit = (1. - p1) / (h1 - l1 + 1.);           for (int idx = l1; idx <= h1; ++idx) {             int nIdx = j - idx > 0 ? j - idx : 0;             newh[nIdx] += pHit * h[j];           }           newh[j] += p1 * h[j];         }       history[i] = newh[0];       newh[0] = 0;       for (int idx = 0; idx <= 200; ++idx)         if (newh[idx] > prec)           h[idx] = newh[idx];         else           h[idx] = 0.;       memset(newh, 0, sizeof(newh));     }   }   int main(int argc, char* argv[]) {     stringstream strStr;     int hp1;     int dt1;     int l1;     int h1;     int pp1;     double p1;     int hp2;     int dt2;     int l2;     int h2;     int pp2;     double p2;     cin >> hp1;     cin >> dt1;     cin >> l1;     cin >> h1;     cin >> pp1;     cin >> hp2;     cin >> dt2;     cin >> l2;     cin >> h2;     cin >> pp2;     strStr >> hp1;     strStr >> dt1;     strStr >> l1;     strStr >> h1;     strStr >> pp1;     strStr >> hp2;     strStr >> dt2;     strStr >> l2;     strStr >> h2;     strStr >> pp2;     p1 = double(pp1) / 100.;     p2 = double(pp2) / 100.;     vector<double> history(5000, 0.);     calcHistory(history, hp2, p1, l1, h1);     double res = 0;     double h[201];     double newh[201];     memset(h, 0, sizeof(h));     memset(newh, 0, sizeof(newh));     h[hp1] = 1.;     int k = 0;     double p = 0.;     double pp = 0.;     for (int i = 0; i < history.size(); ++i) {       double histP1 = history[i];       while (dt2 * k < dt1 * i) {         ++k;         for (int j = 1; j <= hp1; ++j)           if (h[j] > 0) {             double pHit = (1. - p2) / (h2 - l2 + 1.);             for (int idx = l2; idx <= h2; ++idx) {               int nIdx = j - idx > 0 ? j - idx : 0;               newh[nIdx] += pHit * h[j];             }             newh[j] += p2 * h[j];           }         pp += newh[0];         for (int idx = 0; idx <= 200; ++idx)           if (newh[idx] > prec)             h[idx] = newh[idx];           else             h[idx] = 0.;         memset(newh, 0, sizeof(newh));       }       res += histP1 * (1. - pp);       p += histP1;     }     cout << showpoint << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long l[200020], r[200020];   struct node {     long long x, y, p;   } a[200020];   long long ans[200020];   struct bridge {     long long p, v;   };   struct Compare {     bool operator()(const bridge& a, const bridge& b) const {       if (a.v < b.v || (a.v == b.v && a.p < b.p))         return true;       else         return false;     }   };   set<bridge, Compare> b;   bool cmp(node a, node b) {     if (a.x > b.x) return true;     if (a.x < b.x) return false;     if (a.y > b.y) return true;     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lld%lld , &l[i], &r[i]);     long long j;     for (int i = 1; i <= m; i++) {       bridge tmp;       scanf( %lld , &j);       tmp.v = j;       tmp.p = i;       b.insert(tmp);     }     if (m < n - 1) {       printf( No n );       return 0;     }     for (int i = 1; i < n; i++) {       a[i].x = l[i + 1] - r[i];       a[i].y = r[i + 1] - l[i];       a[i].p = i;     }     sort(a + 1, a + n, cmp);     bool ok = true;     set<bridge, Compare>::iterator iter;     bridge tmp;     for (int i = 1; i < n; i++) {       tmp.v = a[i].y + 1;       tmp.p = -1;       iter = b.lower_bound(tmp);       if (iter == b.begin()) {         ok = false;         break;       }       iter--;       if (iter == b.end() || iter->v < a[i].x) {         ok = false;         break;       } else {         ans[a[i].p] = iter->p;         b.erase(iter);       }     }     if (ok) {       printf( Yes n );       for (int i = 1; i < n; i++) printf( %lld  , ans[i]);     } else       printf( No n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[111];   int main() {     int mx = 1000000000;     int cnt, n;     scanf( %d , &n);     int sum = 0;     cnt = 0;     int k = 0;     for (int i = 1; i < n * 2; ++i) {       scanf( %d , &a[i]);       sum += abs(a[i]);       mx = ((mx) < (abs(a[i])) ? (mx) : (abs(a[i])));       if (a[i] < 0) {         cnt++;       }       if (a[i] == 0) k++;     }     if (cnt % 2 == 0 || n % 2 == 1 || k != 0)       printf( %d n , sum);     else {       printf( %d n , sum - mx - mx);     }   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   char a[1010], b[1010];   int h = 0;   int main() {     scanf( %s , a);     int l = strlen(a);     int j = 0;     for (int i = 0; i < l; i++) {       b[j++] = a[i];       if (a[i] ==  > ) {         b[j] = 0;         if (b[1] ==  / ) h--;         for (int k = 0; k < 2 * h; k++) putchar(   );         if (b[1] !=  / ) h++;         puts(b);         j = 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   default_random_engine generator;   uniform_int_distribution<int> distribution(1, INT_MAX);   long long my_rand(long long a = 0, long long b = INT_MAX) {     return a + distribution(generator) % b;   }   inline int mul(int a, int b) { return int(a * 1ll * b % 998244353); }   inline int norm(int a) {     if (a >= 998244353) a -= 998244353;     if (a < 0) a += 998244353;     return a;   }   inline int binPow(int a, int k) {     int ans = 1;     while (k > 0) {       if (k & 1) ans = mul(ans, a);       a = mul(a, a);       k >>= 1;     }     return ans;   }   inline int subtract(int a, int b) { return norm(a - b); }   inline int sum(int a, int b) { return int((a + b) % 998244353); }   inline int inv(int a) { return binPow(a, 998244353 - 2); }   long long ceil_int(long long a, long long b) { return a / b + (a % b != 0); }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   int main() {     generator.seed(chrono::system_clock::now().time_since_epoch().count());     cin.sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     int sum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     int res = sum;     sort(a.begin(), a.end());     for (int i = 1; i <= 100; i++) {       int cur = sum;       for (int j = n - 1; j > 0; j--) {         if (a[j] % i == 0) {           cur += ((a[j] / i) - a[j]);           cur += (a[0] * i - a[0]);         }         res = min(res, cur);         cur = sum;       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   struct node {     int x, id;   } a[N], ans[N];   int anss;   bool cmp(node x, node y) {     if (x.x != y.x) return x.x > y.x;     return x.id < y.id;   }   void solve() {     int k = a[2].x / a[3].x;     while (k) {       if (k & 1) {         a[2].x -= a[3].x;         a[3].x <<= 1;         ans[++anss].x = a[3].id;         ans[anss].id = a[2].id;       } else {         a[1].x -= a[3].x;         a[3].x <<= 1;         ans[++anss].x = a[3].id;         ans[anss].id = a[1].id;       }       k >>= 1;     }   }   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) a[i].id = i, scanf( %d , &a[i].x);     sort(a + 1, a + n + 1, cmp);     if (!a[2].x) {       puts( -1 );       return 0;     }     while (a[3].x) {       solve();       sort(a + 1, a + n + 1, cmp);     }     printf( %d n , anss);     for (int i = 1; i <= anss; ++i) printf( %d %d n , ans[i].x, ans[i].id);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 59;   const long long mod = 998244353;   int add[maxn];   long long w[maxn];   long long dp[52][52][52];   long long val[52][52][52];   bool vis[52][52][52];   long long Pow(long long a, long long b) {     long long res = 1;     a %= mod;     while (b) {       if (b & 1) res = res * a % mod;       b >>= 1;       a = a * a % mod;     }     return res;   }   inline long long inv(long long a) { return Pow(a, mod - 2); }   int flag;   long long dfs(int step, long long p, int i, int j, int k, long long x,                 long long y, long long z) {     if (step == 0) return p * x % mod;     if (vis[i][j][k]) {       return val[i][j][k] * inv(dp[i][j][k]) % mod * p % mod;     }     dp[i][j][k] = p;     val[i][j][k] += dfs(step - 1, p * x % mod * inv(x + y + z) % mod, i + 1, j, k,                         max(0ll, x + flag), y, z);     val[i][j][k] += dfs(step - 1, p * y % mod * inv(x + y + z) % mod, i, j + 1, k,                         x, y + 1, z);     val[i][j][k] += dfs(step - 1, p * z % mod * inv(x + y + z) % mod, i, j, k + 1,                         x, y, max(0ll, z - 1));     val[i][j][k] %= mod;     vis[i][j][k] = 1;     return val[i][j][k];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     long long ori, s0 = 0, s1 = 0;     for (int i = 1; i <= n; i++) scanf( %d , add + i);     for (int i = 1; i <= n; i++) {       scanf( %lld , w + i);       if (add[i])         s1 += w[i];       else         s0 += w[i];     }     ori = s0 + s1;     int x, y, z, step;     for (int i = 1; i <= n; i++) {       memset(dp, 0, sizeof dp);       memset(val, 0, sizeof val);       memset(vis, 0, sizeof vis);       if (add[i])         flag = 1, val[0][0][0] = dfs(m, 1, 0, 0, 0, w[i], s1 - w[i], s0);       else         flag = -1, val[0][0][0] = dfs(m, 1, 0, 0, 0, w[i], s1, s0 - w[i]);       printf( %lld n , val[0][0][0]);     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     scanf( %d , &n);     if (n % 2 == 0) {       printf( -1 );       return 0;     }     for (int i = 0; i < n; i++) printf( %d  , i);     printf(  n );     for (int i = 0; i < n; i++) printf( %d  , i);     printf(  n );     for (int i = 0; i < n; i++) printf( %d  , (i * 2) % n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long int;   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  , ;     return os <<  ] ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.st <<  ,  << P.nd <<  ) ;   }   const int MAXN = 3003;   string t, s;   int n, m;   LL dp[MAXN][MAXN];   LL mod = 998244353;   bool vis[MAXN][MAXN];   LL dfs(int i, int j) {     (i, j);     if (j == i - 1) {       return 1;     }     if (vis[i][j]) {       return dp[i][j];     }     vis[i][j] = true;     char last = s[(j - i) + 1];     LL actRes = 0;     if (i > m || last == t[i]) {       actRes += dfs(i + 1, j);       actRes %= mod;     }     if (j > m || last == t[j]) {       actRes += dfs(i, j - 1);       actRes %= mod;     }     dp[i][j] = actRes;     return dp[i][j];   }   int main() {     cin >> s >> t;     n = s.size();     m = t.size();     s =  #  + s;     t =  #  + t;     LL res = dfs(1, n);     res = 0;     for (int i = m; i <= n; ++i) {       res += dp[1][i];       res %= mod;     }     cout << res << endl;   }
#include <bits/stdc++.h>   int main() {     std::ios::sync_with_stdio(false);     int n;     long long m, k;     long long tmp;     std::cin >> n >> m >> k;     std::vector<long long> a;     for (int i = 0; i < n; i++) {       std::cin >> tmp;       a.push_back(tmp);     }     std::sort(a.begin(), a.end());     std::cout << (m / (k + 1)) * (*(a.end() - 2)) +                      (m - (m / (k + 1))) * (*(a.end() - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long oo = 1000000000000000000;   long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;   vector<int> v[100001];   long long int a[100001], mxx[100001];   map<int, int> mp[100001];   void unin(int x, int y) {     if (mp[x].size() < mp[y].size()) {       mp[x].swap(mp[y]);       mxx[x] = mxx[y];       a[x] = a[y];     }     for (map<int, int>::iterator it = mp[y].begin(); it != mp[y].end(); it++) {       mp[x][(it)->first] += (it)->second;       if (mp[x][it->first] == mxx[x]) {         a[x] += it->first;       } else if (mp[x][it->first] > mxx[x]) {         mxx[x] = mp[x][it->first];         a[x] = it->first;       }     }   }   void dfs(int u, int pr = -1) {     for (int i = 0; i < v[u].size(); i++) {       int to = v[u][i];       if (to == pr) continue;       dfs(to, u);       unin(u, to);     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> num;       mp[i][num]++;       mxx[i] = 1;       a[i] = num;     }     int x, y;     for (int i = 1; i < n; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1);     for (int i = 1; i <= n; i++) {       num = 0;       cout << a[i] <<    ;       sum = 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> a(6);     int s = 0;     for (int i = 0; i < 6; i++) {       cin >> a[i];       s += a[i];     }     if (s % 2 != 0) {       cout <<  NO ;       return 0;     }     for (int i = 0; i < 6; i++)       for (int j = i + 1; j < 6; j++)         for (int k = j + 1; k < 6; k++)           if (s / 2 == a[i] + a[j] + a[k]) {             cout <<  YES ;             return 0;           }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long ans = 0;     int n, m, k = 0;     scanf( %d %d , &n, &m);     vector<int> v(1e7);     for (int i = 0; i < n; i++) {       scanf(  %d , &k);       ans += v[(k ^ m)];       v[k]++;     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char s[101];     int n;     cin >> n;     cin >> s;     if (n == 1 && s[0] ==  0 ) {       cout << 0;       return 0;     }     cout << 1;     for (int i = 0; i < n; i++)       if (s[i] ==  0 ) cout << 0;     return 0;   }
#include <bits/stdc++.h>   int main() {     int m, s, c, i;     std::cin >> m >> s;     c = s;     if (m == 1 && c == 0)       std::cout << 0 <<     << 0;     else {       if (c == 0 || c > (9 * m)) {         std::cout << -1 <<     << -1;       } else {         for (i = m; i > 0; i--) {           if (c <= 9 * (i - 1)) {             if (i == m) {               std::cout << 1;               c--;             } else               std::cout << 0;           } else {             std::cout << (c - 9 * (i - 1));             c = 9 * (i - 1);           }         }         std::cout <<    ;         c = s;         for (i = m - 1; i >= 0; i--) {           if (c <= 9) {             std::cout << c;             c = 0;           } else {             std::cout << 9;             c = c - 9;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <size_t N, size_t M>   struct Suffix_Automata {     int maxlen[N], trans[N][M], link[N], Size, Last, isclone[N];     Suffix_Automata() { Size = Last = 1; }     void Extend(int id) {       int cur = (++Size), p;       maxlen[cur] = maxlen[Last] + 1;       for (p = Last; p && !trans[p][id]; p = link[p]) trans[p][id] = cur;       if (!p)         link[cur] = 1;       else {         int q = trans[p][id];         if (maxlen[q] == maxlen[p] + 1)           link[cur] = q;         else {           int clone = (++Size);           maxlen[clone] = maxlen[p] + 1;           memcpy(trans[clone], trans[q], sizeof(trans[q]));           link[clone] = link[q];           for (; p && trans[p][id] == q; p = link[p]) trans[p][id] = clone;           link[cur] = link[q] = clone;           isclone[clone] = true;         }       }       isclone[cur] = false;       Last = cur;     }     int cnt[N], in[N];     vector<int> G[N];     long long calc() {       long long res = 0;       for (int i = 1; i <= Size; i++) cnt[i] = !isclone[i];       for (int i = 1; i <= Size; i++) {         G[i].clear();         G[i].push_back(link[i]);         ++in[link[i]];       }       queue<int> Q;       for (int i = 1; i <= Size; i++) {         if (!in[i]) {           Q.push(i);         }       }       while (!Q.empty()) {         int u = Q.front();         Q.pop();         for (int v : G[u]) {           cnt[v] += cnt[u];           if (!(--in[v])) {             Q.push(v);           }         }       }       for (int i = 1; i <= Size; i++) {         res += 1LL * cnt[i] * cnt[i] * (maxlen[i] - maxlen[link[i]]);       }       return res;     }   };   Suffix_Automata<300000, 26> SAM;   char s[300000];   int main() {     int T;     scanf( %d , &T);     for (int _ = 0; _ < T; _++) {       memset(SAM.trans, 0, sizeof(SAM.trans));       SAM.Last = SAM.Size = 1;       scanf( %s , s + 1);       int n = strlen(s + 1);       for (int i = 1; i <= n; i++) {         SAM.Extend(s[i] -  a );       }       printf( %lld n , SAM.calc());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s, t, a;   void dfs(int i, int c4, int c7, bool d) {     if (c4 + n - i < n / 2 || c7 + n - i < n / 2) return;     if (i == n) {       a = t;       return;     }     if (d) {       t[i] =  4 ;       dfs(i + 1, c4 + 1, c7, 1);       if (a !=   ) return;       t[i] =  7 ;       dfs(i + 1, c4, c7 + 1, 1);     } else {       if (s[i] <=  4 ) {         t[i] =  4 ;         dfs(i + 1, c4 + 1, c7, s[i] <  4 );         if (a !=   ) return;       }       if (s[i] <=  7 ) {         t[i] =  7 ;         dfs(i + 1, c4, c7 + 1, s[i] <  7 );       }     }   }   int main() {     cin >> s;   restart:     if (s.size() % 2) s =  0  + s;     n = s.size();     t = string(n,  0 );     dfs(0, 0, 0, 0);     if (a ==   ) {       s =  00  + s;       goto restart;     } else {       cout << a << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   void read(int &k) {     k = 0;     char x = getchar();     while (x <  0  || x >  9 ) x = getchar();     while (x >=  0  && x <=  9 ) {       k = k * 10 - 48 + x;       x = getchar();     }   }   int n, a[55], K;   long double dp[55][55][55], ans, fac[55];   int main() {     scanf( %d , &n);     int sum = 0;     for (int i = 0; i < n; i++) scanf( %d , &a[i]), sum += a[i];     scanf( %d , &K);     if (sum <= K) {       printf( %.9lf n , double(n));       return 0;     }     for (int i = 0; i < n; i++) fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i;     for (int pos = 0; pos < n; pos++) {       memset(dp, 0, sizeof dp);       dp[0][0][0] = 1;       for (int i = 0; i < n; i++) {         if (i == pos) {           memcpy(dp[i + 1], dp[i], sizeof dp[i]);           continue;         }         for (int j = 0; j <= i; j++)           for (int k = 0; k <= K; k++) {             if (k + a[i] <= K) dp[i + 1][j + 1][k + a[i]] += dp[i][j][k];             dp[i + 1][j][k] += dp[i][j][k];           }       }       for (int i = 1; i <= n; i++)         for (int j = max(K - a[pos] + 1, 1); j <= K; j++)           ans += ((long double)dp[n][i][j]) * fac[i] * fac[n - i - 1] * i;     }     ans /= fac[n];     printf( %.9lf n , double(ans));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ok[101010];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> ct(n);     int tl = 0;     int nn = 0;     int odd = 0;     for (int i = 0; i < n; i++) {       cin >> ct[i];       tl += ct[i];       if (ct[i] % 2 == 1) odd++;       if (ct[i] > 0) {         nn++;         for (int j = 1; j <= ct[i]; j++) {           if (ct[i] % j == 0) {             ok[j]++;           }         }       }     }     if (nn < 2) {       cout << tl << endl;       for (int i = 0; i < n; i++) {         for (int j = 0; j < ct[i]; j++) {           cout << (char)( a  + i);         }       }       cout << endl;     } else if (odd > 1) {       cout << 0 << endl;       for (int i = 0; i < n; i++) {         for (int j = 0; j < ct[i]; j++) {           cout << (char)( a  + i);         }       }       cout << endl;     } else {       int bv = 1;       for (int i = 1; i <= tl; i++) {         if (ok[i] == nn) {           int x = i;           int o = 0;           for (int ii = 0; ii < n; ii++) {             ct[ii] /= x;             if (ct[ii] % 2 == 1) o++;           }           if (o < 2 || (i % 2 == 0)) {             bv = max(bv, i);           }           for (int ii = 0; ii < n; ii++) {             ct[ii] *= x;           }         }       }       cout << bv << endl;       tl /= bv;       string r(tl,    );       int of = 0;       for (int ii = 0; ii < n; ii++) {         ct[ii] /= bv;         if (ct[ii] % 2 == 1) of = 1;       }       if (bv % 2 == 0) {         int i2 = 0;         for (int i = 0; i < (int)ct.size(); i++) {           for (int j = 0; j < ct[i]; j++) {             r[i2++] = (char)( a  + i);           }         }       } else {         int i2 = 0;         if (of) {           for (int i = 0; i < (int)ct.size(); i++) {             if (ct[i] % 2 == 1) {               for (int j = 0; j < ct[i]; j += 2) {                 r[tl / 2 - i2] = (char)( a  + i);                 r[tl / 2 + i2] = (char)( a  + i);                 i2++;               }             }           }           for (int i = 0; i < (int)ct.size(); i++) {             if (ct[i] % 2 == 0) {               for (int j = 0; j < ct[i]; j += 2) {                 r[tl / 2 - i2] = (char)( a  + i);                 r[tl / 2 + i2] = (char)( a  + i);                 i2++;               }             }           }         } else {           for (int i = 0; i < (int)ct.size(); i++) {             if (ct[i] % 2 == 0) {               for (int j = 0; j < ct[i]; j += 2) {                 r[tl / 2 - i2 - 1] = (char)( a  + i);                 r[tl / 2 + i2] = (char)( a  + i);                 i2++;               }             }           }         }       }       string v =   ;       for (int i = 0; i < bv; i++) {         v = v + r;         reverse(r.begin(), r.end());       }       cout << v << endl;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize ( Ofast ,  unroll-loops )   using namespace std;   #define ll long long   //#define int ll   #define FOR(i,a,b) for (int i = (a); i<(b); i++)   #define REP(i,n) FOR(i,0,n)   #define REP1(i,n) FOR(i,1,n+1)   #define RREP(i,n) for (int i=(n)-1; i>=0; i--)   #define f first   #define s second   #define pb push_back   #define ALL(x) x.begin(),x.end()   #define SZ(x) (int)(x.size())   #define SQ(x) (x)*(x)   #define pii pair<int, int>   #define pdd pair<double ,double>   #define pcc pair<char, char>    #define endl   n    //#define TOAD   #ifdef TOAD   #define bug(x) cerr<<__LINE__<< :  <<#x<<  is  <<x<<endl   #define IOS()   #else   #define bug(...)   #define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)   #endif   const ll inf = 1ll<<60;   const int iinf=2147483647;   const ll mod = 1e9+7;   const ll maxn=1e7+5;   const double PI=acos(-1);   ll pw(ll x, ll p){       ll ret=1;       while (p>0){           if (p&1){               ret*=x;               ret%=mod;           }           x*=x;           x%=mod;           p>>=1;       }       return ret;   }      ll inv(ll a){       return pw(a,mod-2);       }      signed main(){       IOS();       int t; cin>>t;       while(t--){           int n; cin>>n;           vector<pii> vc(n);           vector<int> t(n);           REP(i,n) cin>>vc[i].f>>vc[i].s;           REP(i,n) cin>>t[i];           int cur=vc[0].f, ans=0;           REP(i,n){               cur+=t[i];               if (i==n-1) break;               int ex=(vc[i].s-vc[i].f)/2+((vc[i].s-vc[i].f)%2>0);               cur+=ex;               cur=max(cur, vc[i].s);               cur+=vc[i+1].f-vc[i].s;              }           cout<<cur<<endl;       }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long long x, y, z;       cin >> x >> y >> z;       long long sum = x + y + z;       cout << (sum / 2) << endl;     }     return 0;   }