malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int inf = 1e9 + 9;   const long long int MOD = 1e9 + 696969;   const long long INF = 4LL * 1000000LL * 1000000LL * 1000000LL;   template <class T>   int size(T &&x) {     return int(x.size());   }   template <class A, class B>   ostream &operator<<(ostream &out, const pair<A, B> &p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {     out <<  { ;     for (auto it = x.begin(); it != x.end(); ++it)       out << *it << (it == prev(x.end()) ?    :  ,  );     return out <<  } ;   }   void dump() {}   template <class T, class... Args>   void dump(T &&x, Args... args) {     cerr << x <<  ;   ;     dump(args...);   }   mt19937_64 rng(0);   int random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }   inline void addmod(int &x, int val) {     x += val;     while (x >= mod) x -= mod;   }   const int maxn = 300100;   int dr[maxn];   int n, m, tab[maxn];   int N;   int temp[maxn];   inline void add(int p, int val) {     for (; p <= n; p += p & (-p)) dr[p] += val;   }   inline int get(int p) {     if (p == 0) return 0;     int res = 0;     for (; p > 0; p -= p & (-p)) res += dr[p];     return res;   }   map<long long, long long> M;   vector<pair<int, int> > skal;   int cnt = 0;   long long inversions(int base) {     if (M.find(base) != M.end()) return M[base];     skal.resize(n);     ++cnt;     for (int i = (1); i <= (n); ++i) skal[i - 1] = make_pair(tab[i] ^ base, i);     sort(skal.begin(), skal.end());     for (int i = 0; i < n; ++i) temp[skal[i].second] = i + 1;     long long res = 0;     fill(dr, dr + n + 1, 0);     for (int i = n; i > 0; --i) {       res += get(temp[i]);       add(temp[i], 1);     }     M[base] = res;     return res;   }   void solveone() {     cin >> n;     for (int i = (1); i <= (n); ++i) {       cin >> tab[i];     }     int b = 0;     for (int bit = 29; bit >= 0; --bit) {       if (inversions(b) > inversions(b + (1 << bit))) b += (1 << bit);     }     cout << inversions(b) <<     << b <<   n ;   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     };     int tests;     tests = 1;     for (int _ = (1); _ <= (tests); ++_) solveone();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, mp;     cin >> n >> m >> k;     mp = n / 2 + 1;     if (n % 2 == 0 || mp > m) {       cout << 0;       return 0;     }     int ans = 0, i, a[10005];     for (i = 0; i < n; i++) cin >> a[i];     int min = a[0];     for (i = 0; i < n; i++)       if (i % 2 == 0)         if (a[i] < min) min = a[i];     for (i = 0; i < k; i++) {       int num = m / mp;       if (min == 0) break;       if (num <= min) {         min -= num;         ans += num;       } else {         ans += min;         min = 0;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool is_Palindrome(string s) {     long long int n = s.size();     for (long long int i = 0; i < n / 2; i++) {       if (s[i] != s[n - i - 1]) {         return 0;       }     }     return 1;   }   void solve() {     string a;     cin >> a;     long long int n = a.size();     if (is_Palindrome(a)) {       cout << 0 << endl;       return;     }     cout << 3 << endl;     cout <<  L           <<     << 2 << endl          <<  R           <<     << 2 << endl          <<  R           <<     << (2 * n - 1);   }   void testcase() {     int t;     cin >> t;     while (t--) {       solve();     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int a, b;     cin >> a >> b;     long long int c = 0;     if (a % b == 0) cout << 0 << endl;     if (a % b != 0) {       long long int ans = b - (a % b);       cout << ans << endl;     }   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1000000007;   void solve() {     string s;     cin >> s;     long long ans = INT_MAX;     for (long long i = 0; i <= 9; i++) {       long long count = 0;       for (long long j = 0; j < (long long)s.size(); j++) {         if (s[j] == (char)( 0  + i)) count++;       }       ans = min(ans, (long long)s.size() - count);     }     if (ans == 0) {       cout << 0 << endl;       return;     }     for (long long i = 0; i <= 9; i++) {       for (long long j = 0; j <= 9; j++) {         string temp;         if (i == j) continue;         temp += (char)( 0  + i);         temp += (char)( 0  + j);         long long count = 0;         long long n = (long long)s.size();         long long curr = 0;         for (long long k = 0; k < n; k++) {           if (s[k] == temp[curr]) {             if (curr == 1) {               count++;             }             curr = (curr + 1) % 2;           }         }         ans = min(ans, (long long)s.size() - 2 * count);       }     }     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX_N = (1e3) + 3;   int a[MX_N][MX_N];   int main() {     int n;     scanf( %d , &n);     if (n == 4)       puts( -1 );     else {       for (int i = 0; i < n; ++i) {         for (int j = i - 2; j >= 0; j -= 2) a[i][j] = 1;         for (int j = i + 1; j < n; j += 2) a[i][j] = 1;       }       if (!(n & 1)) {         a[0][n - 1] = 0;         a[n - 1][0] = 1;         a[0][2] = 1;         a[2][0] = 0;       }       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           if (j) printf(   );           printf( %d , a[i][j]);         }         printf(  n );       }     }     return 0;   }
#include <iostream>   #include <string>   #include <vector>   #include <algorithm>   #include <queue>   #include <deque>   #include <bitset>   #include <iterator>   #include <list>   #include <stack>   #include <map>   #include <set>   #include <math.h>   #include <stdio.h>   #include <string.h>   #include <stdlib.h>   #include <climits>   #include <iterator>   using namespace std;       typedef long long ll;   const ll mod=1e9+7;   const ll N=2e5+1;   const ll INF=1e10;       vector<vector<int>> adj(N);   vector<bool> visited(N);   vector<int> parent(N),root(N);   pair<int,int> backedge;      void dfs(int cur){    visited[cur]=true;    for(int next:adj[cur]){     if(!visited[next]){      parent[next]=cur;      dfs(next);     }     else if(parent[cur]!=next) backedge={cur,next};    }   }      void solve(){    map<int,int> subtree;    int n;    cin>>n;    for(int i=0;i<n;i++){     int u,v;     cin>>u>>v;     adj[u].push_back(v);     adj[v].push_back(u);    }    dfs(1);    //cout<<backedge.first<<   <<backedge.second<<  n ;/*    for(int i=0;i<adj[backedge.first].size();i++){     if(adj[backedge.first][i]==backedge.second){      adj[backedge.first][i]=adj[backedge.first].back();      adj[backedge.first].pop_back();      //cout<< done ;      break;     }    }    for(int i=0;i<adj[backedge.second].size();i++){     if(adj[backedge.second][i]==backedge.first){      adj[backedge.second][i]=adj[backedge.second].back();      adj[backedge.second].pop_back();      //cout<< done ;      break;     }    }    //cout<< done ;/*    for(int i=1;i<=n;i++) parent[i]=-1,visited[i]=false;    parent[backedge.first]=0;    dfs(backedge.first);    for(int i=1;i<=n;i++) visited[i]=false;    queue<int> q;    q.push(backedge.second);    root[backedge.second]=backedge.second;    visited[q.back()]=true;    while(parent[q.back()]){     //cout<<q.back()<<   ;     visited[parent[q.back()]]=true;     q.push(parent[q.back()]);     root[q.back()]=q.back();    }    visited[backedge.first]=true;    root[backedge.first]=backedge.first;    ll c=q.size();    while(!q.empty()){     int t=q.front();     q.pop();     for(int i:adj[t]){      if(!visited[i]){       root[i]=root[t];       subtree[root[i]]++;       visited[i]=true;       q.push(i);      }     }    }    //for(auto i:subtree) cout<<i.first<<   <<i.second<<  n ;    ll ans1=0,ans2=0,sum=0;    for(auto i:subtree){     ans1+=(ll)i.second*(i.second+1)/2;     ans2+=i.second*sum;     sum+=i.second;    }    ans1+=2*ans2+2*(c-1)*(n-c)+c*(c-1);    cout<<ans1<<  n ;    for(int i=1;i<=n;i++){     adj[i].clear();     visited[i]=false;     parent[i]=0;    }   }      int main(){    ios_base::sync_with_stdio(0);    cin.tie(NULL);    int t;    cin>>t;    while(t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, ans = 0;     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int a, b;         cin >> a >> b;         ;         if (a == 1 || b == 1) ans++;       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, l, r, cnt;   long long ans;   char s[101][10005];   int dfs(int x, int y, int d) {     if (x == n - 1) return 1;     if (s[x + 1][y] ==  . ) {       l = y;       r = y;       ans++;       cnt = 0;       return dfs(x + 1, y, d);     }     if (s[x][y + d] ==  . ) {       ans++;       r = max(r, y + d);       l = min(l, y + d);       return dfs(x, y + d, d);     } else if (s[x][y + d] ==  # ) {       if (cnt > 2 * m) return 0;       ans += 1;       cnt++;       if (d == 1) {         ans += y - l;         r = y;         return dfs(x, l, -1);       } else {         ans += r - y;         l = y;         return dfs(x, r, 1);       }     } else {       s[x][y + d] =  . ;       ans++;       if (d == 1) {         ans += y - l;         r = y + 1;         return dfs(x, l, -1);       } else {         ans += r - y;         l = y - 1;         return dfs(x, r, 1);       }     }   }   int main() {     int i, j, k, t;     while (~scanf( %d%d , &n, &m)) {       m++;       for (i = 0; i < n; i++) scanf( %s , s[i] + 1), s[i][0] = s[i][m] =  # ;       l = r = 1;       ans = 0;       j = dfs(0, 1, 1);       if (j)         printf( %I64d n , ans);       else         puts( Never );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int arr[3];     cin >> arr[0] >> arr[1] >> arr[2];     sort(arr, arr + 3);     int d = arr[1] - arr[0];     d += arr[2] - arr[1];     cout << d;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int in() {     int res = 0;     char c;     int f = 1;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) f = -1;     while (c >=  0  && c <=  9 ) res = res * 10 + c -  0 , c = getchar();     return res * f;   }   const int N = 100010;   long long num[N], rd[N];   long long ans;   pair<int, int> a[N << 1];   int main() {     int n = in(), m = in();     for (int i = 1; i <= n; i++) {       num[i] = 1;     }     for (int i = 0; i < m; i++) {       a[i].first = in();       a[i].second = in();     }     sort(a, a + m);     for (int i = 0; i < m; i++) {       int x = a[i].first, y = a[i].second;       if (x > y) {         num[x] = max(num[x], num[y] + 1);       } else {         num[y] = max(num[y], num[x] + 1);       }       rd[x]++;       rd[y]++;     }     for (int i = 1; i <= n; i++) {       ans = max(ans, 1LL * num[i] * rd[i]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long Cross(int x1, int y1, int x2, int y2) {     return 1ll * x1 * y2 - 1ll * x2 * y1;   }   int main() {     int xa, xb, xc, ya, yb, yc;     scanf( %d%d%d%d%d%d , &xa, &ya, &xb, &yb, &xc, &yc);     long long cross = Cross(xb - xa, yb - ya, xc - xa, yc - ya);     if (cross == 0)       printf( TOWARDS n );     else if (cross > 0)       printf( LEFT n );     else       printf( RIGHT n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool SR(int &_x) { return scanf( %d , &_x) == 1; }   bool SR(long long &_x) { return scanf( %lld , &_x) == 1; }   bool SR(double &_x) { return scanf( %lf , &_x) == 1; }   bool SR(char *_s) { return scanf( %s , _s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &_x, T &..._tail) {     return SR(_x) && RI(_tail...);   }   void SP(const int _x) { printf( %d , _x); }   void SP(const long long _x) { printf( %lld , _x); }   void SP(const double _x) { printf( %.16lf , _x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I _x, const T... _tail) {     SP(_x);     if (sizeof...(_tail)) putchar(   );     PL(_tail...);   }   const int maxn = 5e5 + 5;   int n, x[maxn], y[maxn];   void read() {     RI(n);     for (int i = (1); i <= int(n); i++) {       int a, b;       RI(x[i], y[i], a, b);     }   }   int c[maxn];   void build() {     for (int i = (1); i <= int(n); i++) {       c[i] = 1 + (x[i] & 1) * 2 + (y[i] & 1);     }   }   void sol() {     PL( YES );     for (int i = (1); i <= int(n); i++) PL(c[i]);   }   int main() {     read();     build();     sol();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> V;   vector<int> E[200005];   int d[200005];   int p[200005];   int find(int x) {     while (p[x] != x) p[x] = p[p[x]], x = p[x];     return x;   }   int rnk[200005];   void meld(int x, int y) {     x = find(x), y = find(y);     if (rnk[x] > rnk[y]) swap(x, y);     p[x] = y;     rnk[y] = rnk[x] == rnk[y] ? rnk[y] + 1 : rnk[y];   }   int s, t;   void build() {     fill(begin(d), end(d), 1e9);     queue<int> Q;     for (auto x : V) Q.emplace(x), d[x] = 0;     while (!Q.empty()) {       auto x = Q.front();       Q.pop();       for (auto y : E[x]) {         if (d[y] == 1e9) d[y] = d[x] + 1, Q.emplace(y);       }     }   }   int n, m, k;   bool test(int mid) {     iota(begin(p), end(p), 0);     fill(begin(rnk), end(rnk), 0);     for (int x = 1; x <= n; ++x) {       if (d[x] + 1 > mid) continue;       for (auto y : E[x])         if (d[x] + d[y] + 1 <= mid) meld(x, y);     }     return find(s) == find(t);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= k; ++i) {       int x;       cin >> x;       V.push_back(x);     }     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       E[u].push_back(v);       E[v].push_back(u);     }     cin >> s >> t;     if (find(begin(V), end(V), t) == end(V)) V.push_back(t);     build();     int l = 1, r = n;     while (l < r) {       int mid = (l + r) / 2;       if (test(mid))         r = mid;       else         l = mid + 1;     }     if (test(l))       cout << l << endl;     else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void R(int &x) {     char ch = getchar();     x = 0;     for (; ch <  0 ; ch = getchar())       ;     for (; ch >=  0 ; ch = getchar()) x = x * 10 + ch -  0 ;   }   const int N = 100005;   double x, y, ans;   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lf%lf , &x, &y);       ans += y;     }     printf( %.3lf n , ans / n + 5);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     vector<long long> a(k);     for (int h = 0; h < a.size(); h++) {       cin >> a[h];     };     int gg = max_element(a.begin(), a.end()) - a.begin();     for (int i = k - 1; i > gg; i--) {       if (a[i] > a[i - 1]) {         cout <<  no ;         return 0;       }     }     for (int i = 0; i < gg; i++) {       if (a[i] > a[i + 1]) {         cout <<  no ;         return 0;       }     }     cout <<  YES ;   }
#include <bits/stdc++.h>   int main() {     int n, k, i;     double t, z, a, b, d = 0;     scanf( %d %d , &n, &k);     int x[n], y[n];     for (i = 0; i < n; i++) {       scanf( %d %d , &x[i], &y[i]);     }     for (i = 1; i < n; i++) {       a = x[i - 1] - x[i];       b = y[i - 1] - y[i];       a = pow(a, 2);       b = pow(b, 2);       z = a + b;       z = sqrt(z);       d = d + z;     }     t = (d / 50) * k;     printf( %.9lf , t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     srand(time(0));     cout << fixed << setprecision(7);     cerr << fixed << setprecision(7);     int n, q;     scanf( %d%d , &n, &q);     static long long s[1 << 23];     for (int i = 1; i <= n; ++i)       scanf( %I64d , &s[i]), s[i + n] = s[i + n + n] = s[i];     for (int i = 2; i <= n + n + n; ++i) s[i] += s[i - 1];     static int nxt[1 << 23];     for (int i = 1; i <= n; ++i) nxt[i] = i;     for (int i = n + 1; i <= n + n + n; ++i) nxt[i] = nxt[i - n];     while (q--) {       int v;       scanf( %d , &v);       if (s[n] <= v) {         cout <<  1 n ;         continue;       }       static int a[1 << 22];       int cnt = 0;       for (int i = 1; i <= n + n; ++i) {         while (s[cnt] - s[i - 1] <= v) ++cnt;         a[i] = cnt;       }       int ans = 0;       cnt = 1;       for (int i = 1; i <= n; ++i) cnt = nxt[a[cnt]];       const int lim = cnt + n;       while (cnt < lim) ++ans, cnt = a[cnt];       cout << ans <<   n ;     }     cerr <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms           <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, h;   double p;   double memexpected[2001][2001][2][2];   int calculado[2001][2001][2][2];   int ri[2001], le[2001];   int v[2001];   double expected(int i1, int i2, int l1, int l2) {     if (i1 > i2) return 0;     double &mem = memexpected[i1][i2][l1][l2];     if (calculado[i1][i2][l1][l2]) return mem;     calculado[i1][i2][l1][l2] = 1;     mem = 0;     int distle = h;     if (i1 > 0)       distle =           (l1 == 0) ? min(v[i1] - v[i1 - 1], h) : min(v[i1] - (v[i1 - 1] + h), h);     int distri = h;     if (i2 < n - 1)       distri =           (l2 == 1) ? min(v[i2 + 1] - v[i2], h) : min(v[i2 + 1] - h - v[i2], h);     int RI = min(ri[i1], i2);     int lenri = min(v[RI] + h - v[i1], v[i2] - v[i1] + distri);     int LE = max(le[i2], i1);     int lenle = min(v[i2] - v[LE] + h, v[i2] - v[i1] + distle);     double mem1 = 0.5 * (p * (distle + expected(i1 + 1, i2, 0, l2)) +                          (1 - p) * (lenri + expected(RI + 1, i2, 1, l2)));     double mem2 = 0.5 * ((1 - p) * (distri + expected(i1, i2 - 1, l1, 1)) +                          p * (lenle + expected(i1, LE - 1, l1, 0)));     mem = mem1 + mem2;     return mem;   }   int main() {     cout.setf(ios::fixed);     cout.precision(10);     cin >> n >> h >> p;     for (int i = 0; i < n; i++) cin >> v[i];     sort(v, v + n);     le[0] = 0;     for (int i = 1; i < n; i++) le[i] = (v[i] - v[i - 1] < h) ? le[i - 1] : i;     ri[n - 1] = n - 1;     for (int i = n - 2; i >= 0; i--)       ri[i] = (v[i + 1] - v[i] < h) ? ri[i + 1] : i;     cout << expected(0, n - 1, 0, 1) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const int inf = 1e9;   const int N = 2e5;   void solve() {     long long int d, m;     cin >> d >> m;     long long int mx;     for (long long int i = 32; i >= 0; i--) {       if ((1LL << i) & d) {         mx = i;         break;       }     }     long long int dp[mx + 1];     dp[mx] = (d - (1LL << mx) + 1);     long long int res = dp[mx];     res %= m;     for (long long int i = mx - 1; i >= 0; i--) {       dp[i] = (1LL << i) * (1 + res);       res += dp[i];       res %= m;     }     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> m;   pair<bool, char> check(int a, string s) {     int flag = 0;     char x = s[a], e;     for (long long int i = 1 + (x -  a ); i < 26; i++) {       if (m.count(i)) {         return {true, char(i +  a )};       }     }     return {false,  f };   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);     int a, b;     cin >> a >> b;     string s;     cin >> s;     for (long long int i = 0; i < s.size(); i++) {       m[s[i] -  a ]++;     }     if (a < b) {       cout << s;       sort(s.begin(), s.end());       for (long long int i = 0; i < b - a; i++) cout << s[0];     } else {       int k = 0;       char e;       for (long long int i = b - 1; i >= 0; i--) {         pair<bool, char> p = check(i, s);         if (p.first) {           e = p.second;           k = i;           break;         }       }       for (long long int i = 0; i < k; i++) cout << s[i];       cout << e;       sort(s.begin(), s.end());       if (b - k - 1 > 0) {         for (long long int i = 0; i < b - k - 1; i++) cout << s[0];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int c1 = 0;     int c2 = 0;     int a[1000];     for (int i = 1;; i++) {       if (i % 2 == 0) {         a[i] = (i * i) / 2;       } else {         a[i] = (i / 2) * (i / 2) + ceil(i / 2.0) * ceil(i / 2.0);       }       if (a[i] > 200) break;     }     for (int i = 0; i < n; i++) {       string s1, s2;       cin >> s1 >> s2;       if (s2 ==  soft )         c1++;       else         c2++;     }     if (c1 == c2 && c1 == 1)       cout << 2;     else if (c1 == 1 && c2 == 0)       cout << 1;     else if (c2 == 1 && c1 == 0)       cout << 1;     else {       int x = max(c1, c2);       for (int i = 1;; i++) {         if (a[i] < x && x <= a[i + 1]) {           cout << i + 1;           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n, L, a;   int t[N], l[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     srand(time(NULL));     cin >> n >> L >> a;     int res = 0;     for (int i = 1; i <= n; i++) {       cin >> t[i] >> l[i];       int len = t[i] - (t[i - 1] + l[i - 1]);       res += len / a;     }     res += (L - (t[n] + l[n])) / a;     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int kMaxN = 100010;   const int kMaxA = 1000000010;   int a[kMaxN];   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     long long ans = 0;     for (long long x = 1; (1LL << x) < 2 * kMaxA; x++) {       long long val = (1 << x);       for (long long i = 0; i < n; i++) {         long long num = upper_bound(a + i + 1, a + n, val - a[i]) -                         lower_bound(a + i + 1, a + n, val - a[i]);         ans += num;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 50;   const int INF = 0x3f3f3f3f;   void bf(int A, int B) {     for (long long a = 1; a <= A; a++)       for (long long b = 1; b <= B; b++) {         if ((a * b + a + b) == stol(to_string(a) + to_string(b)))           cout << a <<     << b << endl;       }   }   int main() {     int cs;     while (cin >> cs) {       while (cs--) {         int a, b;         cin >> a >> b;         long long ret = to_string(b + 1).size() - 1;         cout << a * ret << endl;       }     }     return 0;   }