malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:268435456 )   using namespace std;   template <typename T>   T sqr(const T &x) {     return x * x;   }   template <typename T>   T my_abs(const T &x) {     return x < 0 ? -x : x;   }   const int INF = (int)1e9;   const long long LINF = (long long)6e18;   const long long INF64 = LINF;   const long long INFLL = LINF;   const long double EPS = 1e-15;   const long double PI = 3.1415926535897932384626433832795;   const long double ME = 1e-5;   const long long MOD2 = (int)1e9 + 21;   const int SQN = 320;   const int LOGN = 17;   const int dx[] = {0, 1, 0, -1};   const int dy[] = {-1, 0, 1, 0};   const int N = (int)5e3 + 10;   const int M = (int)2e6 + 10;   const long long MOD = (int)1e9 + 7;   int z[N][N];   int psum[N][N];   int prv[26][N];   int a[N];   void solve() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < int(n); ++i) {       a[i] = s[i] -  a ;     }     memset(prv, -1, sizeof(prv));     for (int i = 0; i < int(26); ++i) {       for (int j = 1; j < int(n); ++j) {         if (a[j - 1] == i) {           prv[i][j] = j - 1;         } else {           prv[i][j] = prv[i][j - 1];         }       }     }     z[0][0] = 1;     for (int j = 1; j < int(n + 1); ++j) {       psum[0][j] = 1;     }     for (int i = 1; i < int(n + 1); ++i) {       for (int j = 0; j < int(n); ++j) {         z[i][j] = (z[i][j] + z[i - 1][j]) % MOD;         z[i][j] =             (z[i][j] + psum[i - 1][j] - psum[i - 1][prv[a[j]][j] + 1] + MOD) %             MOD;         psum[i][j + 1] = (psum[i][j] + z[i][j]) % MOD;       }     }     int ans = 0;     for (int j = 0; j < int(n); ++j) {       ans = (ans + z[n][j]) % MOD;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     srand((unsigned int)time(NULL));     cout << setprecision(15) << fixed;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const double pi = acos(-1.0);   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt;     tt = 1;     while (tt--) {       long long n, m;       cin >> n >> m;       long long cost[n + 2];       for (long long i = 0; i < n; i += 1) cin >> cost[i + 1];       long long ans = 0;       for (long long i = 0; i < m; i += 1) {         long long p, q;         cin >> p >> q;         ans += min(cost[p], cost[q]);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<long long> a;       for (int i = 0; i < n; i++) {         long long x;         cin >> x;         a.push_back(x);       }       long long m = 0;       for (int i = 0; i < (n - 1); i++) {         long long x = a[i] * a[i + 1];         if (x > m) m = x;       }       cout << m << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef long long int lli;   const int mod=1e9+7;   int main()   {           ll t;       cin>>t;       while(t--)       {           ll n;           cin>>n;           if(n<=32)           {               ll m=n-3;               m+=5;               cout<<m<<endl;               for(ll i=3; i<n; i++)               {                   cout<<i<<   <<n<<endl;               }               for(ll i=0; i<5; i++)               {                   cout<<n<<   <<2<<endl;               }           }           else           {               ll m = n-4;               m+=9;               cout<<m<<endl;               for(ll i=3; i<n; i++)               {                   if(i==16)                       continue;                   cout<<i<<   <<n<<endl;               }                   for(ll i=0; i<5; i++)               {                   cout<<n<<   <<16<<endl;               }                   for(ll i=0; i<4; i++)               {                   cout<<16<<   <<2<<endl;               }               //cout<<m<<nn;           }       }   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int a = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) {       a = a * 10 + c - 48;       c = getchar();     }     return a;   }   const int _ = 3e5 + 7, __ = _ * 19;   vector<int> nxt[_];   int N, M, dep[_];   void qdep(int x, int p) {     dep[x] = dep[p] + 1;     for (auto &t : nxt[x])       if (t != p) qdep(t, x);   }   long long mrk[__], mn[__];   int ch[__][2], cnode;   void mark(int x, long long v) {     if (x) {       mrk[x] = min(mrk[x] + v, mn[0]);       mn[x] = min(mn[x] + v, mn[0]);     }   }   void down(int x) {     if (x && mrk[x]) {       mark((ch[x][0]), mrk[x]);       mark((ch[x][1]), mrk[x]);       mrk[x] = 0;     }   }   void mdf(int &x, int l, int r, int t, long long v, bool type) {     if (!type && !x) {       x = ++cnode;     }     if (l == r) {       mn[x] = type ? v : min(mn[x], v);       return;     }     down(x);     ((l + r) >> 1) >= t ? mdf((ch[x][0]), l, ((l + r) >> 1), t, v, type)                         : mdf((ch[x][1]), ((l + r) >> 1) + 1, r, t, v, type);     mn[x] = min(mn[(ch[x][0])], mn[(ch[x][1])]);   }   int merge(int p, int q) {     if (!p || !q) {       return p + q;     }     mn[p] = min(mn[p], mn[q]);     down(p);     down(q);     ch[p][0] = merge(ch[p][0], ch[q][0]);     ch[p][1] = merge(ch[p][1], ch[q][1]);     return p;   }   vector<pair<int, int> > route[_];   int dfs(int x, int p) {     long long vlsum = 0;     int rt = 0;     for (auto t : nxt[x])       if (t != p) {         int R = dfs(t, x);         mdf(R, 1, N, dep[x] + 1, mn[0], 1);         long long v = mn[R];         mark(rt, v);         mark(R, vlsum);         vlsum = min(mn[0], vlsum + v);         rt = merge(rt, R);       }     for (auto t : route[x]) mdf(rt, 1, N, t.first, vlsum + t.second, 0);     if (x == 1) cout << (vlsum <= 1e16 ? vlsum : -1);     return rt;   }   int main() {     N = read();     M = read();     for (int i = 1; i < N; ++i) {       int x = read(), y = read();       nxt[x].push_back(y);       nxt[y].push_back(x);     }     qdep(1, 0);     for (int i = 1; i <= M; ++i) {       int x = read(), y = read(), w = read();       route[x].push_back(pair<int, int>(dep[y], w));     }     memset(mn, 0x3f, sizeof(mn));     dfs(1, 0);     return 0;   }
#include <bits/stdc++.h>   int main() {     int x, y, s;     scanf( %d %d %d , &x, &y, &s);     if (s >= 0) {       y = y + s;       if (y % x)         printf( %d , y % x);       else         printf( %d , x);     } else if (s < 0) {       double p = abs(s);       p = ceil(p / x);       y = y + s + (p * x);       if (y % x)         printf( %d , y % x);       else         printf( %d , x);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long q = 1, w, a[3], s[3], d[3] = {1000000000, 0, 0};     for (w = 0; w < 18; w++) q *= 10;     bool c = 0;     for (w = 0; w < 3; w++) {       cin >> a[w] >> s[w];       if ((w == 2) && (d[2] > 0)) c = 1;       if (a[w] == 0) {         if (s[w] > 0) d[(w + 1) % 3] = q;       } else {         if (s[w] > 0)           if (d[w] == q)             d[(w + 1) % 3] = q;           else {             d[(w + 1) % 3] = (d[w] / a[w]) * s[w];             d[w] %= a[w];           }       }     }     if ((((d[0] > 1000000000) && (c)) || ((d[0] == 1000000000) && (d[2] > 0))) ||         (d[2] == q))       cout <<  Ron ;     else       cout <<  Hermione ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, a, b;     cin >> n >> a >> b;     set<long long> s;     while (a--) {       long long j;       cin >> j;       s.insert(j);     }     for (long long i = 1; i <= n; i++)       if (s.count(i))         cout <<  1  ;       else         cout <<  2  ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9, MAXN = 4010;   int n;   inline int pack(int l, int r, int k) { return (l << 19) + (r << 7) + k; }   unordered_map<int, int> dp(MAXN* MAXN * 2);   vector<int> a, pref;   int calc(int l, int r, int k, int p) {     if (p) {       if (dp.count(pack(l, r, k))) return dp[pack(l, r, k)];       if (r - l + 1 < k) return dp[pack(l, r, k)] = 0;       if (r - l + 1 == k)         return dp[pack(l, r, k)] =                    (calc(l + k, r, k, p ^ 1) + (pref[l + k - 1] - pref[l - 1]));       return dp[pack(l, r, k)] = max(                  calc(l + k, r, k, p ^ 1) + (pref[l + k - 1] - pref[l - 1]),                  calc(l + k + 1, r, k + 1, p ^ 1) + (pref[l + k] - pref[l - 1]));     }     if (r - l + 1 < k) return 0;     if (r - l + 1 == k) return calc(l, r - k, k, p ^ 1) - (pref[r] - pref[r - k]);     return min(calc(l, r - k, k, p ^ 1) - (pref[r] - pref[r - k]),                calc(l, r - k - 1, k + 1, p ^ 1) - (pref[r] - pref[r - k - 1]));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     a.resize(n);     pref.resize(n + 1);     for (int i = 0; i < n; i++) {       cin >> a[i];       pref[i + 1] = pref[i] + a[i];     }     cout << calc(1, n, 1, 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = numeric_limits<int>::max();   int n;   vector<int> d, a;   int get_longest(int l) {     vector<int> d;     while (l > a.size())       for (int i = 0; i < n; ++i) a.push_back(a[i]);     d.assign(l + 10, INF);     d[0] = -INF;     for (int i = 0; i < l; ++i) {       int j = int(upper_bound(d.begin(), d.end(), a[i]) - d.begin());       if (d[j - 1] <= a[i] && a[i] < d[j]) d[j] = a[i];     }     for (int i = 1; i <= l; ++i)       if (d[i] == INF) return i - 1;     return l;   }   int main() {     int t;     int longest_same = 1;     vector<int> b;     scanf( %d %d , &n, &t);     a.assign(n, 0);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     b.assign(a.begin(), a.end());     sort(b.begin(), b.end());     map<int, int> new_val;     int longest = 1;     for (int i = 0; i < n; ++i) {       if (i > 0 && b[i] == b[i - 1])         ++longest;       else {         if (longest > longest_same) longest_same = longest;         longest = 1;       }       if (i == 0 || b[i] != b[i - 1]) new_val[b[i]] = i;     }     if (longest > longest_same) longest_same = longest;     for (int i = 0; i < n; ++i) {     }     longest = get_longest(n);     int next_longest, prev_longest;     int d = INF;     int k = 1;     while (d > longest_same && k < t) {       ++k;       next_longest = get_longest(k * n);       d = next_longest - longest;       prev_longest = longest;       longest = next_longest;     }     if (d <= longest_same) {       longest = prev_longest + (t - k + 1) * longest_same;     }     printf( %d n , longest);     return 0;   }
/******************************************************************************                                    Online C++ Compiler.                  Code, Compile, Run and Debug C++ program online.   Write your code in this editor and press  Run  button to compile and execute it.      *******************************************************************************/      #include <bits/stdc++.h>   using namespace std;      #define ll long long      int main()   {       int t; cin >> t;              while (t--){           int n; cin >> n;           vector<int> a(n);           for (int i = 0; i < n; i++) cin >> a[i];           int check = 1;           for (int i = 0; i < n - 1; i++) if (a[i] > a[i + 1]) check = 0;           if (check) cout << 0 << endl;           else if (a[0] == 1 || a[n - 1] == n) cout << 1 << endl;           else if (a[0] == n && a[n - 1] == 1) cout << 3 << endl;           else cout << 2 << endl;       }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, x1, y, y1;     char a, b;     cin >> a >> y >> b >> y1;     x1 = a - 96;     x = b - 96;     int counter = 0;     string s[100000];     while (true) {       if (x == x1 && y == y1) {         break;       }       if (x > x1) {         x1++;         s[counter] +=  R ;       }       if (x < x1) {         x1--;         s[counter] +=  L ;       }       if (y > y1) {         y1++;         s[counter] +=  D ;       }       if (y < y1) {         y1--;         s[counter] +=  U ;       }       counter++;     }     cout << counter << endl;     for (int i = 0; i < counter; i++) {       cout << s[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int INF = 1e8 + 7;   int n;   int Min[N][20], Max[N][20];   struct Node {     int x, y;     bool operator<(const Node& p) const { return x < p.x; }   } nod[N];   long long sqr(long long x) { return x * x; }   void rmq() {     for (int i = 0; i < n; ++i) {       Min[i][0] = nod[i].y;       Max[i][0] = nod[i].y;     }     for (int j = 1; (1 << j) <= n; ++j)       for (int i = 0; i + (1 << j) - 1 < n; ++i) {         Min[i][j] = min(Min[i][j - 1], Min[i + (1 << (j - 1))][j - 1]);         Max[i][j] = max(Max[i][j - 1], Max[i + (1 << (j - 1))][j - 1]);       }   }   int query(int t, int l, int r) {     if (l > r) return (1 - (t << 1)) * INF;     int k = (int)log2(r - l + 1.0);     switch (t) {       case 0:         return min(Min[l][k], Min[r - (1 << k) + 1][k]);       case 1:         return max(Max[l][k], Max[r - (1 << k) + 1][k]);     }     return 0;   }   bool isok(long long D, long long x, long long ymin, long long ymax) {     if (x > D) return false;     if (ymin != -INF && x + sqr(ymin) > D) return false;     if (ymax != INF && x + sqr(ymax) > D) return false;     if (ymin != -INF && ymax != INF && sqr(ymax - ymin) > D) return false;     return true;   }   bool check(long long D) {     if (sqr(nod[n - 1].x - nod[0].x) <= D) return true;     if (sqr(query(1, 0, n - 1) - query(0, 0, n - 1)) <= D) return true;     int l = 0, r = n - 1, ymin, ymax;     r = 0;     for (int i = 0; i < n; ++i) {       if (r < i) r = i;       while (r + 1 < n && abs(nod[r + 1].x) <= abs(nod[i].x) &&              sqr(nod[r + 1].x - nod[i].x) <= D)         ++r;       while (abs(nod[r].x) > abs(nod[i].x)) --r;       l = i;       ymin = min(query(0, 0, l - 1), query(0, r + 1, n - 1));       ymax = max(query(1, 0, l - 1), query(1, r + 1, n - 1));       long long x = sqr(nod[l].x);       if (isok(D, x, ymin, ymax)) return true;     }     l = 0, r = n - 1;     l = n - 1;     for (int i = n - 1; i >= 0; --i) {       if (l > i) l = i;       while (l - 1 >= 0 && abs(nod[l - 1].x) <= abs(nod[i].x) &&              sqr(nod[l - 1].x - nod[i].x) <= D)         --l;       while (abs(nod[l].x) > abs(nod[i].x)) ++l;       r = i;       ymin = min(query(0, 0, l - 1), query(0, r + 1, n - 1));       ymax = max(query(1, 0, l - 1), query(1, r + 1, n - 1));       long long x = max(sqr(nod[l].x), sqr(nod[r].x)),                 y = max(sqr(ymin), sqr(ymax));       if (isok(D, x, ymin, ymax)) return true;     }     return false;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &nod[i].x, &nod[i].y);     }     sort(nod, nod + n);     rmq();     long long L = 0, R = sqr(nod[n - 1].x - nod[0].x);     while (L + 1 < R) {       long long M = (L + R) >> 1;       check(M) ? R = M : L = M;     }     long long ans = check(L) ? L : R;     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   int m, n, h;   int t[maxn];   int first[maxn * 2], nxt[maxn * 2], des[maxn * 2], tot;   int dfn[maxn], low[maxn], dft;   bool d[maxn];   int flag[maxn], cnt[maxn], scc;   stack<int> stk;   inline void add(int x, int y) {     tot++;     des[tot] = y;     nxt[tot] = first[x];     first[x] = tot;   }   void tar(int node) {     dfn[node] = low[node] = ++dft;     stk.push(node);     for (int t = first[node]; t; t = nxt[t]) {       int v = des[t];       if (!dfn[v]) tar(v);       low[node] = min(low[node], low[v]);     }     if (dfn[node] == low[node]) {       scc++;       while (true) {         int temp = stk.top();         flag[temp] = scc;         cnt[scc]++;         stk.pop();         if (temp == node) break;       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &h);     for (int i = 1; i <= n; i++) {       scanf( %d , t + i);     }     for (int i = 0; i < m; i++) {       int u1, u2;       scanf( %d%d , &u1, &u2);       if (t[u1] == (t[u2] + 1) % h) add(u2, u1);       if (t[u2] == (t[u1] + 1) % h) add(u1, u2);     }     for (int i = 1; i <= n; i++) {       if (!dfn[i]) tar(i);     }     for (int i = 1; i <= n; i++) {       for (int t = first[i]; t; t = nxt[t]) {         if (flag[i] == flag[des[t]])           continue;         else {           d[flag[i]]++;         }       }     }     cnt[0] = n + 1;     int ans = 0;     for (int i = 1; i <= scc; i++) {       if (d[i] == 0 && cnt[i] < cnt[ans]) {         ans = i;       }     }     cout << cnt[ans] << endl;     for (int i = 1; i <= n; i++) {       if (flag[i] == ans) {         cout << i <<    ;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, j, a[2002];   double p[5005], sp[5005], m, res;   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     for (i = 0; i < n; i++)       for (j = 0; j < i; j++) p[a[i] - a[j]]++;     m = (n - 1) * n / 2;     for (i = 5000; i >= 0; i--) {       p[i] = p[i] / m;       sp[i] = sp[i + 1] + p[i];     }     for (i = 1; i < 5000; i++)       for (j = 1; i + j < 5000; j++) res += p[i] * p[j] * sp[i + j + 1];     printf( %.6lf n , res);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long T, n, i, l, r, mid, res;     scanf( %lld , &T);     while (T--) {       scanf( %lld , &n);       l = 2;       r = n - 1;       res = n - 1;       while (l <= r) {         mid = (l + r) >> 1;         if (mid * (mid - 1) / 2 + (n - mid) <= 2 * (n - mid))           l = mid + 1;         else           r = mid - 1;       }       res = max(res, min(l * (l - 1) / 2 + (n - l), 2 * (n - l)));       res = max(res, min((l - 1) * (l - 2) / 2 + (n - l + 1), 2 * (n - l + 1)));       printf( %lld n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<  ,  ;     err(++it, args...);   }   void solve() {     int n, m;     cin >> n >> m;     vector<int> l(m), r(m);     for (int i = 0; i < m; ++i) {       cin >> l[i] >> r[i];     }     for (int i = 0; i < n; ++i) cout << (i & 1);     cout << endl;   }   int main(int argc, char* argv[]) {     ios::sync_with_stdio(false);     cin.tie(nullptr);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k[5] = {3, 4, 5, 4, 3};   int st[5] = {0, 0, 0, 1, 2};   int dx[] = {0, -1, -1, 0, 1, 1};   int dy[] = {-1, -1, 0, 1, 1, 0};   int x[32], y[32];   int id[32][32];   char a[32][32];   char f[1 << 20];   int prep() {     memset(id, 0xff, sizeof(id));     int n = 0;     for (int i = 0; i < (5); ++i)       for (int j = 0; j < (k[i]); ++j)         x[n] = i, y[n] = st[i] + j, id[i][st[i] + j] = n++;     int res = 0;     for (int i = 0; i < (5); ++i)       for (int j = 0; j < (k[i]); ++j)         if (a[i][st[i] + j] ==  O ) res |= 1 << id[i][st[i] + j];     return res;   }   int main() {     for (int i = 0; i < (5); ++i) {       gets(a[i]);       for (int j = 0; j < (k[i]); ++j) a[i][st[i] + j] = a[i][2 * j + 5 - k[i]];       a[i][st[i] + k[i]] = 0;     }     int need = prep();     for (int m = 0; m < ((1 << 19)); ++m) {       for (int i = 0; i < (19); ++i)         if (m & (1 << i)) {           for (int q = 0; q < (6); ++q) {             int xx = x[i], yy = y[i], d = 1 << i;             for (;;) {               f[m] |= 1 - f[m ^ d];               if (f[m]) goto end;               xx += dx[q], yy += dy[q];               if (xx < 0 || xx >= 5 || yy - st[xx] < 0 || yy - st[xx] >= k[xx] ||                   (~m & (1 << id[xx][yy])))                 break;               d |= 1 << id[xx][yy];             }           }         }     end:;     }     if (f[need])       puts( Karlsson );     else       puts( Lillebror );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     char c = getchar();     if (c <  0  && c >  9  && c !=  - ) c = getchar();     long long f = 1, cnt = 0;     if (c ==  - ) f = -1, c = getchar();     while (c >=  0  && c <=  9 ) {       cnt = cnt * 10 + int(c -  0 );       c = getchar();     }     return cnt * f;   }   const int MOD = 1e9 + 9;   struct Loc {     Loc(int a, int b) {       x = a;       y = b;     }     int x;     int y;     bool operator<(const Loc &a) const {       if (y == a.y) {         return x < a.x;       }       return y < a.y;     }   };   map<Loc, int> table;   bool vis[100005];   priority_queue<int> q1;   priority_queue<int, vector<int>, greater<int> > q2;   long long result = 0;   void add(int a, int m) { result = (result * m + a) % MOD; }   int xPos[100005];   int yPos[100005];   bool judge(int x, int y) {     if (table.find(Loc(x, y + 1)) != table.end()) {       if (table.find(Loc(x - 1, y)) == table.end() &&           table.find(Loc(x + 1, y)) == table.end()) {         return false;       }     }     if (table.find(Loc(x - 1, y + 1)) != table.end()) {       if (table.find(Loc(x - 1, y)) == table.end() &&           table.find(Loc(x - 2, y)) == table.end()) {         return false;       }     }     if (table.find(Loc(x + 1, y + 1)) != table.end()) {       if (table.find(Loc(x + 1, y)) == table.end() &&           table.find(Loc(x + 2, y)) == table.end()) {         return false;       }     }     return true;   }   int main() {     int m;     int x, y;     m = read();     for (int i = 0; i < m; i++) {       cin >> x >> y;       xPos[i] = x;       yPos[i] = y;       table[Loc(x, y)] = i;     }     for (int i = 0; i < m; i++) {       if (judge(xPos[i], yPos[i])) {         q1.push(i);         q2.push(i);       }     }     memset(vis, false, sizeof(vis));     int top = 0;     int count = 0;     while (count < m) {       if ((count & 1) == 0) {         top = q1.top();       } else {         top = q2.top();       }       x = xPos[top];       y = yPos[top];       bool found = false;       if (!vis[top] && judge(x, y)) {         add(top, m);         table.erase(Loc(x, y));         vis[top] = true;         found = true;       }       if ((count & 1) == 0) {         q1.pop();       } else {         q2.pop();       }       if (found) {         count++;         if (table.find(Loc(x, y - 1)) != table.end() && judge(x, y - 1)) {           q1.push(table[Loc(x, y - 1)]);           q2.push(table[Loc(x, y - 1)]);         }         if (table.find(Loc(x - 1, y - 1)) != table.end() && judge(x - 1, y - 1)) {           q1.push(table[Loc(x - 1, y - 1)]);           q2.push(table[Loc(x - 1, y - 1)]);         }         if (table.find(Loc(x + 1, y - 1)) != table.end() && judge(x + 1, y - 1)) {           q1.push(table[Loc(x + 1, y - 1)]);           q2.push(table[Loc(x + 1, y - 1)]);         }       }     }     printf( %d , result);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long q;     cin >> q;     while (q--) {       long long n, m;       cin >> n;       cin >> m;       if (m > n || m % 10 == 0) {         cout << 0 <<   n ;         continue;       }       long long p = (n / m) / 10;       long long q = (n / m) % 10;       long long sum = 0;       if (m % 2 == 0)         sum = p * (40LL);       else if (m % 5 == 0)         sum = p * (25LL);       else         sum = p * (45LL);       long long num = 0;       for (long long i = 1; i <= q; i++) {         num += m;         sum += (num % 10);       }       cout << sum <<   n ;     }     return 0;   }