malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   void test_case() {     int n, l, r;     cin >> n >> l >> r;     vector<int> mn(n + 1);     int rem = l - 1;     for (int i = rem + 1; i <= n; ++i) {       mn[i] = 1;     }     for (int i = rem, nxt = 2; i >= 1; --i, nxt *= 2) {       mn[i] = nxt;     }     vector<int> mx(n + 1);     for (int i = 1, unq = 0, nxt = 1; i <= n; ++i) {       mx[i] = nxt;       ++unq;       if (unq < r) {         nxt *= 2;       }     }     cout << accumulate(mn.begin(), mn.end(), 0) <<              << accumulate(mx.begin(), mx.end(), 0) <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     test_case();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   using ll = long long;   int n, m, p, a[N];   struct TNode {     int l, r;     vector<ll> f;     ll sum;   } t[N << 2];   inline int lc(int pos) { return pos << 1; }   inline int rc(int pos) { return pos << 1 | 1; }   void pushup(int pos) {     t[pos].sum = t[lc(pos)].sum + t[rc(pos)].sum;     int ptr = 0;     for (int i = 1; i <= t[pos].r - t[pos].l + 1; i++)       t[pos].f[i] = (LLONG_MAX >> 2);     for (int i = 0; i <= t[lc(pos)].r - t[lc(pos)].l + 1; i++) {       if (ptr > t[rc(pos)].r - t[rc(pos)].l + 1) --ptr;       while (ptr <= t[rc(pos)].r - t[rc(pos)].l + 1) {         ll ret = t[rc(pos)].f[ptr] - (t[lc(pos)].sum - i * 1ll * p);         ll val = t[lc(pos)].f[i + 1] - 1 + (t[lc(pos)].sum - i * 1ll * p);         if (val < t[rc(pos)].f[ptr]) {           if (ptr > 0) --ptr;           break;         }         t[pos].f[i + ptr] = min(t[pos].f[i + ptr], max(t[lc(pos)].f[i], ret));         ++ptr;       }     }   }   void build(int pos, int l, int r) {     t[pos].l = l;     t[pos].r = r;     t[pos].f.resize(r - l + 1 + 1);     t[pos].f[0] = LLONG_MIN >> 2;     t[pos].f.push_back(LLONG_MAX >> 2);     if (l == r) {       t[pos].sum = a[l];       t[pos].f[1] = p - a[l];       return;     }     int mid = (l + r) >> 1;     build(lc(pos), l, mid);     build(rc(pos), mid + 1, r);     pushup(pos);   }   ll query(int pos, int l, int r, ll cur = 0) {     if (t[pos].l == l && t[pos].r == r) {       assert(cur < LLONG_MAX / 4);       ll pp = upper_bound(t[pos].f.begin(), t[pos].f.end(), cur) -               t[pos].f.begin() - 1;       return cur + t[pos].sum - p * pp;     }     int mid = (t[pos].l + t[pos].r) >> 1;     if (r <= mid)       return query(lc(pos), l, r, cur);     else if (l > mid)       return query(rc(pos), l, r, cur);     else       return query(rc(pos), mid + 1, r, query(lc(pos), l, mid, cur));   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> p;     for (int i = 1; i <= n; i++) cin >> a[i];     build(1, 1, n);     while (m--) {       int l, r;       cin >> l >> r;       cout << query(1, l, r) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long wph;   long long mul(long long a, long long b) {     long long c = (a * b - (long long)((long double)a / wph * b) * wph);     return c < 0 ? c + wph : c;   }   void fwt(long long *a, int n, int f) {     for (int k = 2, mid = 1; k <= n; k <<= 1, mid <<= 1)       for (int i = 0; i < n; i += k)         for (int j = 0; j < mid; j++) {           long long x = a[i + j], y = a[i + mid + j];           a[i + j] = (x + y) % wph, a[i + mid + j] = (x - y + wph) % wph;         }     if (f)       for (int i = 0; i < n; i++) a[i] /= n;   }   long long c[2000010], b[2000010], f[2000010];   long long ksm(long long bs, long long mi) {     long long ans = 1;     while (mi) {       if (mi & 1) ans = mul(ans, bs);       bs = mul(bs, bs);       mi >>= 1;     }     return ans;   }   long long count(long long x) {     long long cnt = 0;     while (x) x &= (x - 1), cnt++;     return cnt;   }   int main() {     long long t;     int m, n;     scanf( %d%I64d%I64d , &m, &t, &wph);     n = 1 << m;     wph *= n;     for (int i = 0; i < n; i++) scanf( %I64d , &f[i]);     for (int i = 0; i <= m; i++) scanf( %I64d , &b[i]);     for (int i = 0; i < n; i++) c[i] = b[count(i)];     fwt(c, n, 0);     fwt(f, n, 0);     for (int i = 0; i < n; i++) c[i] = ksm(c[i], t);     for (int i = 0; i < n; i++) c[i] = mul(c[i], f[i]);     fwt(c, n, 1);     wph /= n;     for (int i = 0; i < n; i++) printf( %I64d n , c[i] % wph);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y;   };   struct Line {     double A, B, C;   };   Line Build(Point A, Point B) {     Line res;     res.A = A.y - B.y;     res.B = B.x - A.x;     res.C = A.x * B.y - B.x * A.y;     return res;   }   Line Per(Line l, Point A) {     Line res;     res.A = -l.B;     res.B = l.A;     res.C = -(res.A * A.x + res.B * A.y);     return res;   }   Line Par(Line l, Point A) {     Line res;     res.A = l.A;     res.B = l.B;     res.C = -(l.A * A.x + l.B * A.y);     return res;   }   Point Inter(Line a, Line b) {     Point res;     res.x = (a.B * b.C - b.B * a.C) / (a.A * b.B - b.A * a.B);     res.y = (a.A * b.C - b.A * a.C) / (b.A * a.B - b.B * a.A);     return res;   }   Point Middle(Point A, Point B) {     Point res;     res.x = (A.x + B.x) / 2.0;     res.y = (A.y + B.y) / 2.0;     return res;   }   double Dist(Point A, Point B) {     double res = sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));     return res;   }   double Dist2(Point A, Point B) {     double res = (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);     return res;   }   Point Mir(Point A, Point B) {     Point res;     res.x = B.x * 2 - A.x;     res.y = B.y * 2 - A.y;     return res;   }   double Cp2(Point A, Point B) {     double res = A.x * B.y - A.y * B.x;     return res;   }   double Cp3(Point O, Point A, Point B) {     double res = (A.x - O.x) * (B.y - O.y) - (B.x - O.x) * (A.y - O.y);     return res;   }   bool Zero(double x) { return (fabs(x) < 1e-9 ? true : false); }   Line Midper(Point A, Point B) {     Line res = Per(Build(A, B), Middle(A, B));     return res;   }   bool Check(Point ans[]) {     double tmp;     for (int i = 0; i < 4; i++) {       if (Zero(Cp3(ans[i], ans[(i + 1) % 4], ans[(i + 2) % 4]))) return false;       if (i == 0)         tmp = Cp3(ans[i], ans[(i + 1) % 4], ans[(i + 2) % 4]);       else if (tmp * Cp3(ans[i], ans[(i + 1) % 4], ans[(i + 2) % 4]) < 0)         return false;     }     return true;   }   bool Mak(Point A, Point B, Point C) {     if (Cp3(A, B, C) > 1e-9) swap(B, C);     Line l1 = Midper(B, A);     Line l2 = Midper(B, C);     Point E = Inter(l1, l2);     Point F = Mir(E, B);     Point ans[4];     ans[0] = Inter(Par(l2, F), l1);     ans[1] = Mir(ans[0], B);     ans[2] = Mir(ans[1], C);     ans[3] = Mir(ans[0], A);     if (Check(ans) == false) return false;     puts( YES );     for (int i = 3; i < 7; i++) {       printf( %.9f %.9f , ans[i & 3].x, ans[i & 3].y);       putchar(i < 6 ? 32 : 10);     }     return true;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       Point a, b, c;       scanf( %lf%lf%lf%lf%lf%lf , &a.x, &a.y, &b.x, &b.y, &c.x, &c.y);       if (!Zero(Cp3(a, b, c)) && (Mak(a, b, c) || Mak(b, c, a) || Mak(c, a, b)))         continue;       puts( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m;   pair<long long int, bool> All[120];   long long int ans = 0, na;   void GetAll() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> All[i].first;       All[i].second = false;     }     int buf;     for (int i = 0; i < m; i++) {       cin >> buf;       All[buf - 1].second = true;     }   }   void Run() {     sort(All, All + n);     for (int i = 0; i < n; i++) {       if (!All[i].second) {         na += All[i].first;       }     }     for (int i = n - 1; i >= 0; i--) {       if (!All[i].second) {         continue;       }       if (All[i].first > na) {         na += All[i].first;       } else {         na += na;       }     }     cout << na;   }   int main() {     GetAll();     Run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool prime(long long int n) {     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   long long binexpm(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long binexp(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long int n, p;   vector<long long int> adj[10001];   map<pair<long long int, long long int>, long long int> mp;   bool vis[10001] = {false};   map<pair<long long int, long long int>, long long int> res;   long long int x, y = -1;   long long int dm = INT_MAX;   bool xx = true;   long long int in[10001] = {0};   long long int out[10001] = {0};   bool dfs(long long int node) {     if (vis[node]) xx = false;     vis[node] = true;     for (auto child : adj[node]) {       dm = min(dm, mp[{node, child}]);       if (adj[child].size() == 0) y = child;       xx &= dfs(child);     }     return xx;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> p;     for (long long int i = 0; i < p; i++) {       long long int a, b, d;       cin >> a >> b >> d;       out[a]++;       in[b]++;       adj[a].push_back(b);       mp[make_pair(a, b)] = d;     }     long long int ans = 0;     for (long long int i = 1; i <= n; i++) {       bool flag;       dm = INT_MAX;       if (out[i] == 1 && in[i] == 0) {         x = i;         flag = dfs(i);         if (flag && y != -1) {           ans++;           res[make_pair(x, y)] = dm;         }       }     }     cout << ans <<   n ;     if (ans != 0) {       for (auto it : res) {         cout << it.first.first <<     << it.first.second <<     << it.second              <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int h, i, j, x, l, r, pa[200200], pb[200200];   bool ans;   int main() {     scanf( %d , &h);     for (j = 0; j <= h; j++) {       scanf( %d , &x);       for (i = 1; i <= x; i++) {         pa[r + i] = l;         pb[r + i] = min(l + i - 1, r);         if (pa[r + i] != pb[r + i]) ans = true;       }       l = r + 1;       r = r + x;     }     if (ans) {       puts( ambiguous );       for (i = 1; i <= r; i++) printf( %d  , pa[i]);       puts(  );       for (i = 1; i <= r; i++) printf( %d  , pb[i]);       puts(  );     } else       puts( perfect );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int matrix[100][100];   int ans[10000];   void fill() {     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         matrix[i][j] = i * m + j;       }     }   }   void solve_1(int i) {     int temp;     temp = matrix[i][m - 1];     matrix[i][m - 1] = matrix[i][0];     for (int j = m - 2; j >= 0; --j) {       int new_temp = matrix[i][j];       matrix[i][j] = temp;       temp = new_temp;     }   }   void solve_2(int j) {     int temp;     temp = matrix[n - 1][j];     matrix[n - 1][j] = matrix[0][j];     for (int i = n - 2; i >= 0; --i) {       int new_temp = matrix[i][j];       matrix[i][j] = temp;       temp = new_temp;     }   }   int main(int argc, char *argv[]) {     memset(ans, 0, sizeof(ans));     scanf( %d%d%d , &n, &m, &q);     fill();     while (q--) {       int t;       scanf( %d , &t);       if (t == 1) {         int n_i;         scanf( %d , &n_i);         n_i--;         solve_1(n_i);       } else if (t == 2) {         int m_i;         scanf( %d , &m_i);         m_i--;         solve_2(m_i);       } else {         int r, c, x;         scanf( %d%d%d , &r, &c, &x);         r--;         c--;         ans[matrix[r][c]] = x;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         printf( %d  , ans[i * m + j]);       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d, s;   int E[2510050][10];   int Get(int x, int y) { return x * d + y; }   int dis[2710500];   char ok[2700050] = {};   vector<int> ans;   int ST, EN;   int dfs(int x) {     if (x == EN) return 1;     ok[x] = 1;     for (int u = 0; u < 10; u++)       if (x != 0 || u != 0) {         int v = E[x][u];         if (dis[v] == dis[x] + 1 && ok[v] == 0) {           ans.push_back(u);           if (dfs(v)) return 1;           ans.pop_back();         }       }     return 0;   }   int main() {     scanf( %d%d , &d, &s);     for (int i = 0; i <= s; i++)       for (int j = 0; j < d; j++) {         int x = Get(i, j);         for (int e = 0; e < 10; e++) {           if (i == 0 && j == 0 && e == 0) continue;           int ni = i + e;           int nj = (10 * j + e) % d;           if (ni <= s) {             int xx = Get(ni, nj);             E[x][e] = xx;           }         }       }     ST = Get(0, 0), EN = Get(s, 0);     vector<int> v;     v.push_back(ST);     memset(dis, -1, sizeof dis);     dis[ST] = 0;     for (int i = 0; i < (int)v.size(); i++) {       int t = v[i];       for (int u = 0; u < 10; u++)         if (t != 0 || u != 0) {           int w = E[t][u];           if (dis[w] == -1) {             dis[w] = dis[t] + 1;             v.push_back(w);           }         }     }     if (dis[EN] == -1)       puts( -1 );     else {       dfs(ST);       for (int e : ans) printf( %d , e);       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   int n, i, tmp, res, a[10000];   bool kt;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     kt = true;     for (i = 3; i <= n; i++)       if (a[i] - a[i - 1] != a[i - 1] - a[i - 2]) kt = false;     if (kt == false) {       printf( %d , a[n]);       return 0;     }     tmp = a[1] - a[2];     res = a[n] - tmp;     printf( %d , res);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool Up(T &a, const T &b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool Down(T &a, const T &b) {     if (a > b) {       a = b;       return true;     }     return false;   }   const int MAXN = 100023;   int N, M, color[MAXN], ans[MAXN];   vector<int> fir[MAXN], side[2];   int tot = 2;   void BFS() {     static int Q[MAXN];     int head = 0, tail = 0;     memset(color, -1, sizeof(color));     for (int S = (1); S <= (N); ++S)       if (color[S] == -1)         for (color[S] = 0, Q[++tail] = S; head < tail;) {           int x = Q[++head], y;           side[color[x]].push_back(x);           for (vector<int>::iterator itr(fir[x].begin()); itr != fir[x].end();                ++itr)             if (color[y = *itr] == -1) {               Q[++tail] = y;               color[y] = color[x] ^ 1;             }         }   }   void Print() {     for (int c = (0); c <= (1); ++c)       for (vector<int>::iterator itr(side[c].begin()); itr != side[c].end();            ++itr) {         int x = *itr;         if (!ans[x]) ans[x] = ++tot;       }     puts( YES );     for (int i = (1); i <= (N); ++i)       printf( %d%c , ans[i] / 3, i == N ?   n  :    );   }   void Paint(int x) {     static int forbid[MAXN];     memset(forbid, 0, sizeof(forbid));     for (vector<int>::iterator itr(fir[x].begin()); itr != fir[x].end(); ++itr)       forbid[*itr] = 1;     int cnt = 0;     ans[x] = ++tot;     for (vector<int>::iterator itr(side[color[x] ^ 1].begin());          itr != side[color[x] ^ 1].end(); ++itr) {       int y = *itr;       if (!ans[y] && !forbid[y]) {         ans[y] = ++tot;         if (++cnt == 2) break;       }     }   }   int main() {     memset(ans, 0, sizeof(ans));     scanf( %d %d , &N, &M);     for (int i = (1); i <= (M); ++i) {       int a, b;       scanf( %d %d , &a, &b);       fir[a].push_back(b);       fir[b].push_back(a);     }     BFS();     if (side[0].size() % 3 == 0) {       Print();       return 0;     }     if (side[0].size() % 3 == 2) {       side[0].swap(side[1]);       for (int i = (1); i <= (N); ++i) color[i] ^= 1;     }     for (vector<int>::iterator itr(side[0].begin()); itr != side[0].end();          ++itr) {       int x = *itr;       if (fir[x].size() + 2 <= side[1].size()) {         Paint(x);         Print();         return 0;       }     }     int cnt = 0;     for (vector<int>::iterator itr(side[1].begin()); itr != side[1].end();          ++itr) {       int x = *itr;       if (fir[x].size() + 2 <= side[0].size()) {         Paint(x);         if (++cnt == 2) {           Print();           return 0;         }       }     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int> > a;   set<pair<int, int> > d;   void solve(int l, int r) {     if (r - l <= 1) return;     int m = (l + r) / 2;     solve(l, m);     solve(m, r);     for (int i = l; i < r; ++i) {       d.insert({a[m].first, a[i].second});     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     a.resize(n);     for (int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;       d.insert(a[i]);     }     sort(a.begin(), a.end());     solve(0, n);     cout << d.size() <<   n ;     for (auto i : d) {       cout << i.first <<     << i.second <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[300011];   long long ans[300011];   struct P {     long long dis = -1, val = 0;   } temp;   vector<P> m[300011];   map<long long, long long> bit;   void add(long long i, long long val) {     i = 1000000000000000 - i;     for (; i < 1000000000000000; i += (i & (-i))) bit[i] += val;   }   long long get(long long i) {     long long ret = 0;     i = 1000000000000000 - i;     for (; i > 0; i -= (i & (-i))) ret += bit[i];     return ret;   }   void dfs(int u, int par = 0, long long lev = 1) {     for (auto i : m[u]) add(lev + i.dis, i.val);     ans[u] = get(lev);     for (auto v : g[u]) {       if (v != par) dfs(v, u, lev + 1);     }     for (auto i : m[u]) add(lev + i.dis, -i.val);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x, y, v, d;     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     int q;     cin >> q;     while (q--) {       cin >> v >> d >> x;       temp.dis = d;       temp.val = x;       m[v].push_back(temp);     }     dfs(1);     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void print(int a) { cout << a <<    ; }   void print(long long a) { cout << a <<    ; }   void print(double a) { cout << a <<    ; }   void print(string a) { cout << a <<    ; }   template <typename T1, typename T2>   void print(pair<T1, T2> a) {     print(a.first);     cout <<   :::  ;     print(a.second);   }   template <typename Container>   void print(const Container& c) {     for (auto it = c.begin(); it != c.end(); it++) {       print(*it);     }     cout << endl;   }   vector<long long> tot_comb(51, 0);   vector<long long> fac(51, 1);   int CALC_MAX = 0;   long long INF = 2e18;   long long get_fac(int x) {     if (x <= 0) return 1;     return fac[x];   }   long long mul(long long x, long long y) {     if (x >= INF || y >= INF || x * y >= INF || x * y < 0) return INF;     return x * y;   }   long long add(long long x, long long y) {     if (x >= INF || y >= INF || x + y >= INF) return INF;     return x + y;   }   void fill_fac() {     fac[0] = 1;     fac[1] = 1;     for (int i = 2; i <= 50; i++) {       fac[i] = mul(fac[i - 1], i);     }   }   void fill_tot_comb() {     tot_comb[0] = 1;     tot_comb[1] = 1;     tot_comb[2] = 2;     tot_comb[3] = 4;     for (int i = 4; i <= 50; i++) {       tot_comb[i] = 0;       for (int j = 1; j <= i; j++) {         tot_comb[i] = add(tot_comb[i], mul(get_fac(j - 2), tot_comb[i - j]));       }     }   }   void KthPermhelp(int k, long long n, int st) {     vector<int> perm(k + 1, 0);     vector<int> pos(k + 1, 0);     perm[1] = k;     pos[k] = 1;     long long cnt = n;     vector<bool> taken(k + 1, false);     taken[k] = true;     for (int i = 2; i <= k; i++) {       for (int j = 1; j < k; j++) {         if (!taken[j]) {           int jk = i;           while (taken[jk]) jk = pos[jk];           if (j == jk && i != k) continue;           long long tot_with_j_i = get_fac(k - 1 - i);           if (cnt > tot_with_j_i) {             cnt -= tot_with_j_i;           } else {             perm[i] = j;             taken[j] = true;             pos[j] = i;             break;           }         }       }     }     if (k == 2) {       perm[1] = 2;       perm[2] = 1;     }     for (int i = 1; i <= k; i++) cout << perm[i] + st <<    ;   }   void KthPerm(int n, long long k, int st) {     if (n == 0) return;     if (tot_comb[n] < k) {       cout << -1;       return;     }     for (int i = 1; i <= n; i++) {       if (mul(get_fac(i - 2), tot_comb[n - i]) >= k) {         KthPermhelp(i, (k / tot_comb[n - i]) + (k % tot_comb[n - i] > 0), st);         KthPerm(n - i,                 (k % tot_comb[n - i]) +                     ((k % tot_comb[n - i] == 0) ? tot_comb[n - i] : 0),                 st + i);         break;       }       k -= mul(get_fac(i - 2), tot_comb[n - i]);     }   }   int main() {     fill_fac();     fill_tot_comb();     int t;     cin >> t;     while (t--) {       int n;       long long int k;       cin >> n >> k;       KthPerm(n, k, 0);       cout << endl;     }   }
#include <bits/stdc++.h>      #define pb push_back   #define int long long    #define debug(n) cerr << #n <<   =   << n <<   n ;      using namespace std;      const int MaxN = 1e6 + 10;   const int Mod = 1e9 + 7;   const int inf = 1e18;   int cnt[100] , a[MaxN];      void solve() {    int n;    cin >> n;    for(int i = 0; i < n; i++) {     cin >> a[i];     for(int j = 0; j <= 60; j++)       if(a[i] & (1LL << j)) cnt[j]++;    }    int ans = 0;    for(int i = 0; i < n; i++) {     int x = 0 , y = 0;     for(int j = 0; j <= 60; j++) {      int p = (1LL << j) % Mod;      if(a[i] & (1LL << j)) {       x = (x + p * cnt[j]) % Mod;       y = (y + p * n) % Mod;      } else y = (y + p * cnt[j]) % Mod;     }     ans = (ans + x * y) % Mod;    }    cout << ans <<   n ;    fill(cnt , cnt + 100 , 0);   }      int32_t main() {    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);    int t = 1;    cin >> t;    while(t--)      solve();    return 0;   }