malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   int main() {     int n;     cin >> n;     long long int a;     cin >> a;     while (1) {       if (a % 2 == 0)         a /= 2;       else if (a % 3 == 0)         a /= 3;       else         break;     }     bool f = 1;     for (int i = 0; i < n; i++) {       long long int b;       cin >> b;       while (1) {         if (b % 2 == 0)           b /= 2;         else if (b % 3 == 0)           b /= 3;         else           break;       }       if (a != b) f = 0;       a = b;     }     if (f)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int nums[n];     for (int i = 0; i < n; i++) {       cin >> nums[i];     }     int ans = 0;     int maxi = 0;     int mini = 1e9;     for (int i = 0; i < n; i++) {       maxi = max(maxi, nums[i]);       mini = min(mini, nums[i]);     }     int f = -1, l = -1;     for (int i = 0; i < n; i++) {       if (nums[i] == maxi) {         f = i;         break;       }     }     for (int i = n - 1; i >= 0; i--) {       if (nums[i] == mini) {         l = i;         break;       }     }     ans += f + n - 1 - l;     if (l < f) ans--;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int ar[n];       for (int i = 0; i < n; i++) {         cin >> ar[i];         --ar[i];       }       for (int i = 0; i < n; i++) {         int pos = i, j = i, cnt = 1, kaku = ar[i];         while (kaku != pos) {           j = ar[j];           kaku = ar[j];           cnt++;         }         cout << cnt <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     string Fillipino =  po ;     string Japanese1 =  desu ;     string Japanese2 =  masu ;     string Korean =  mnida ;     string s;     cin >> s;     long long n = s.size();     if (s.substr(n - 2, 2) == Fillipino) {       cout <<  FILIPINO  << endl;       return;     }     if (s.substr(n - 4, 4) == Japanese1) {       cout <<  JAPANESE  << endl;       return;     }     if (s.substr(n - 4, 4) == Japanese2) {       cout <<  JAPANESE  << endl;       return;     }     if (s.substr(n - 5, 5) == Korean) {       cout <<  KOREAN  << endl;       return;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> st;   int main() {     ios::sync_with_stdio(0);     int n, x;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (st.empty())         st.push_back(x);       else {         st.push_back(x);         while (st.size() > 1) {           if (st[int(st.size()) - 1] != st[int(st.size()) - 2]) break;           st.pop_back();           st[int(st.size()) - 1]++;         }       }     }     cout << int(st.size()) <<   n ;     for (auto v : st) cout << v <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int xx = 0, ff = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       xx = xx * 10 + ch -  0 ;       ch = getchar();     }     return xx * ff;   }   long long READ() {     long long xx = 0, ff = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       xx = xx * 10 + ch -  0 ;       ch = getchar();     }     return xx * ff;   }   char one() {     char ch = getchar();     while (ch ==     || ch ==   n ) ch = getchar();     return ch;   }   const int maxn = 110;   int N, R, cnt;   struct proj {     int a, b;     bool friend operator<(const proj& A, const proj& B) {       return A.a + A.b > B.a + B.b;     }   } P[maxn], obj[maxn];   bool vis[maxn];   int f[maxn][maxn];   int main() {     N = read(), R = read();     for (int i = 1; i <= N; i++) P[i].a = read(), P[i].b = read();     int ans = 0;     while (1) {       bool flag = 0;       for (int i = 1; i <= N; i++)         if (!vis[i] && R >= P[i].a && P[i].b >= 0) {           flag = 1;           vis[i] = 1;           R += P[i].b;           ans++;         }       if (!flag) break;     }     for (int i = 1; i <= N; i++)       if (P[i].b < 0) obj[++cnt] = P[i];     memset(f, -1, sizeof(f));     sort(obj + 1, obj + 1 + cnt);     f[0][0] = R;     for (int i = 1; i <= cnt; i++) {       for (int j = 0; j <= i; j++) {         f[i][j] = f[i - 1][j];         if (j && f[i - 1][j - 1] >= obj[i].a)           f[i][j] = max(f[i][j], f[i - 1][j - 1] + obj[i].b);       }     }     int mx = 0;     for (int i = 1; i <= cnt; i++)       for (int j = 0; j <= cnt; j++)         if (f[i][j] != -1) mx = max(mx, j);     printf( %d n , mx + ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1000000007;   long long int store[2002][2002] = {0};   long long int ncrModp(long long int n, long long int r, long long int p) {     long long int value[9999] = {0};     value[0] = 1;     for (long long int e = 1; e <= n; e++) {       store[e][0] = 1;       for (long long int f = e; f > 0; f--) {         value[f] = (value[f] + value[f - 1]) % p;         store[e][f] = value[f];       }     }     return (value[r]);   }   int bin(long long int n) {     long long int r = n;     long long int one = 0;     while (r != 0) {       one += r % 2;       r = r / 2;     }     return (one);   }   int main() {     long long int dp[1111] = {0};     dp[1] = 0;     dp[2] = 1;     for (int e = 3; e <= 1001; e++) {       long long int k = bin(e);       dp[e] = 1 + dp[k];     }     string s;     long long int n;     cin >> s;     cin >> n;     ncrModp(s.length() + 1, s.length() + 1, mod);     long long int ones = 0;     for (int u = 0; u < s.length(); u++) {       if (s[u] ==  1 ) ++ones;     }     int q = s.length() - 1;     long long int qar[1111] = {0};     for (int u = 1; u <= q; u++) {       qar[u] = store[q][u];     }     long long int u = 0, ct = 0;     long long int h = 0;     long long int t = 0;     qar[ones] += 1;     for (int w = q; w > 0; w--) {       if (s[w] ==  1 ) {         ++t;         long long int u = ones - t;         if (w != q)           for (int h = 0; h <= ct; h++) {             qar[h + ones - t] += store[ct][h];           }         else {           qar[ones - t] += 1;         }       }       ++ct;     }     long long int ans = 0;     for (int p = 1; p < s.length(); p++)       if (dp[p] == n - 1) ans += qar[p] % mod;     if (n == 1 && s !=  1 ) ans -= 1;     if (n != 0)       cout << ans % mod;     else       cout <<  1 ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void show(T a, int n) {     for (int i = 0; i < n; ++i) cout << a[i] <<    ;     cout << endl;   }   template <class T>   void show(T a, int r, int l) {     for (int i = 0; i < r; ++i) show(a[i], l);     cout << endl;   }   const int N = 20;   const int M = 5000;   const int oo = 10000 * 10000 * 10;   int n;   char s[N + N];   long long h[N];   long long dp[N][N];   char tag[N][N];   void print(int i, int j) {     if (!i && !j) return;     if (tag[i][j] ==  H )       print(i - 1, j);     else       print(i, j - 1);     putchar(tag[i][j]);   }   void solve() {     int i, j, k;     h[n] = 1;     for (i = n - 1; i >= 1; --i) h[i] = h[i + 1] * 10;     for (i = 1; i <= n; ++i) {       int g = s[i] -  0 ;       dp[i][0] = dp[i - 1][0] + g * h[i];       tag[i][0] =  H ;       dp[0][i] = dp[0][i - 1] + g * h[i];       tag[0][i] =  M ;     }     for (i = 1; i <= n; ++i) {       for (j = 1; j <= n; ++j) {         int d = i + j;         int g = s[d] -  0 ;         dp[i][j] = (dp[i - 1][j] + g * h[i] > dp[i][j - 1] + g * h[j]                         ? dp[i - 1][j] + g * h[i]                         : dp[i][j - 1] + g * h[j]);         if (dp[i - 1][j] + g * h[i] > dp[i][j - 1] + g * h[j])           tag[i][j] =  H ;         else           tag[i][j] =  M ;       }     }     print(n, n);     putchar(10);   }   int main() {     int i, j, cas = 0;     scanf( %d , &n);     while (getchar() != 10)       ;     scanf( %s , s + 1);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int n1, long long int n2) {     if (n2 != 0)       return gcd(n2, n1 % n2);     else       return n1;   }   long long int power(long long int a, long long int b) {     if (b == 0) return 1;     if (b == 1) return a;     long long int x = power(a, b / 2);     if (b & 1) {       return a * x * x;     }     return x * x;   }   int tree[4 * (1000005)], lazy[4 * (1000005)];   void push(int ind, int l, int r) {     if (lazy[ind] == 0) return;     tree[ind] += lazy[ind];     if (l != r) {       lazy[2 * ind] += lazy[ind];       lazy[2 * ind + 1] += lazy[ind];     }     lazy[ind] = 0;   }   void upd(int ind, int l, int r, int left, int right, int val) {     push(ind, l, r);     if (left > r || l > right) return;     if (left <= l && r <= right) {       lazy[ind] += val;       push(ind, l, r);       return;     }     int mid = (l + r) / 2;     upd(ind * 2, l, mid, left, right, val);     upd(ind * 2 + 1, mid + 1, r, left, right, val);     tree[ind] = min(tree[2 * ind], tree[2 * ind + 1]);   }   int que(int ind, int l, int r) {     push(ind, l, r);     if (tree[ind] >= 0) return -1;     if (l == r) return l;     int mid = (l + r) / 2;     int res = que(2 * ind + 1, mid + 1, r);     if (res != -1) return res;     que(2 * ind, l, mid);   }   int main() {     int n, m;     cin >> n >> m;     int a[300005], b[300005];     memset(tree, 0, sizeof(tree));     memset(lazy, 0, sizeof(lazy));     for (__typeof((n)) i = (1); i <= (n); i++) {       cin >> a[i];       upd(1, 1, (1000000 + 5) - 1, 1, a[i], -1);     }     for (__typeof((m)) i = (1); i <= (m); i++) {       cin >> b[i];       upd(1, 1, (1000000 + 5) - 1, 1, b[i], 1);     }     int t;     cin >> t;     while (t--) {       int i, j, k;       cin >> i >> j >> k;       if (i == 1) {         upd(1, 1, (1000000 + 5) - 1, 1, a[j], 1);         a[j] = k;         upd(1, 1, (1000000 + 5) - 1, 1, a[j], -1);       } else {         upd(1, 1, (1000000 + 5) - 1, 1, b[j], -1);         b[j] = k;         upd(1, 1, (1000000 + 5) - 1, 1, b[j], 1);       }       cout << que(1, 1, (1000000 + 5) - 1) <<   n ;     }   }
#include <iostream>   #include <string>   #include <string.h>   #include <cstring>   #include <math.h>   #include <iomanip>   #include <vector>   #include <cmath>   #include <algorithm>   #include <numeric>   #include <cctype>   #include <utility>   #include <set>   #include <map>   #include <sstream>   #include <iterator>   #include <limits>   #include <map>   #include <deque>   #include <stack>   #include <queue>   #include <climits>   #include <tuple>   using namespace std;   #define pb push_back   #define ff(i, a, b) for (int i = a; i < b; ++i)   #define ffr(i, b, a) for (int i = b; i >= a; --i)   #define fflr(i, b, a) for (long long i = b; i >= a; --i)   #define ffl(i, a, b) for (long long i = a; i < b; ++i)   #define all(v) v.begin(), v.end()   #define endl   n    #define Yes cout <<  Yes  << endl   #define No cout <<  No  << endl   #define YES cout <<  YES  << endl   #define NO cout <<  NO  << endl   #define trav(a, x) for (auto &a : x)   #define lb lower_bound   #define ub upper_bound   #define ins insert   #define collect(v, n)                 for (ll i = 0; i < n; i++)        {                                     cin >> v[i];                  }   #define X first   #define epsilon -0.0000001f   #define Y second   #define mp make_pair   #define mt make_tuple   typedef long long ll;   typedef long double ld;   typedef std::pair<int, int> pii;   typedef pair<ll, ll> pll;   typedef std::vector<int> vec;   typedef vector<pii> vii;   typedef vector<pll> vll;   typedef std::vector<long long> vecl;   typedef map<int, int> mii;   typedef map<ll, ll> mll;      void FAST()   { // FAST Input Output, DONT use both scnaf,printf / cin,cout , Use any ONE system       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);   }      const ll md = 1000000007;   #define pi 3.141592653589793238462643383279   const ll inf = 1e18L + 5; // max 1000*inf   const char nl =   n ;   const int N = 200005;      // ll sod(ll x)   // {   //     ll sum = 0;   //     while (x > 0)   //     {   //         sum += x % 10;   //         x = x / 10;   //     }   //     return sum;   // }   // float round1(float var)   // {      //     char str[40];   //     sprintf(str,  %.2f , var);   //     sscanf(str,  %f , &var);      //     return var;   // }   // bool palindrome(string s)   // {   //     int count = 0;   //     int i = 0;   //     int l = s.length();   //     ff(i, 0, l / 2)   //     {   //         if (s[i] != s[l - i - 1])   //             return 0;   //     }   //     return 1;   // }      int main()   {       //     FAST();       //     int tt{}, T{};       //     tt = 1;       //     cin >> tt;       //     T = tt;       //     while (tt--)       //     {      ll n;      cin>>n;      n=n%9;      if(n==0)n=9;     cout<<n;          return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     float x, y, avg = 0, result = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       avg += y;     }     avg = avg / n + 5;     printf( %3f , avg);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int k, u, v, a[N], n;   long long ans, dp[N];   vector<int> G[N];   void dfs(int u, int v, int flag) {     dp[u] = a[u];     for (int i : G[u]) {       if (i != v) {         dfs(i, u, flag);         dp[u] += max(dp[i], 0ll);       }     }     if (flag)       ans = max(ans, dp[u]);     else if (dp[u] == ans)       dp[u] = 0, k++;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i < n; i++) {       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     ans = -1e9;     dfs(1, 0, 1);     dfs(1, 0, 0);     cout << ans * k <<     << k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a[36] = {         1,          2,          4,          8,          16,          32,         64,         128,        256,        512,        1024,        2048,         4096,       8092,       16184,      32368,      64736,       129472,         258944,     517888,     1035776,    2071552,    4143104,     8286208,         16572416,   33144832,   66289664,   132579328,  265158656,   530317312,         1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968};     int n;     cin >> n;     cout << a[n];   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1024;   double p[MAXN][MAXN];   int a[MAXN];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       for (int j = 0; j < i; ++j) p[i][j] = a[i] > a[j], p[j][i] = 1 - p[i][j];     }     for (int x, y; m--;) {       scanf( %d%d , &x, &y), --x, --y;       for (int i = 0; i < n; ++i)         if (i != x && i != y) {           p[i][x] = p[i][y] = (p[i][x] + p[i][y]) / 2;           p[x][i] = p[y][i] = 1 - p[i][x];         }       p[x][y] = (p[x][y] + p[y][x]) / 2, p[y][x] = 1 - p[x][y];     }     double e = 0;     for (int i = 0; i < n; ++i)       for (int j = i + 1; j < n; ++j) e += p[i][j];     printf( %.16lf n , e);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long N;   string S;   long long sol;   long long dim;   long long e;   long long last() {     long long d = 1ll;     long long n = 0ll;     long long sz = (long long)(S.size());     int zero = 0;     for (long long i = sz - 1; i >= sz - dim && i >= 0 && n < N; i--) {       if (d * (long long)(S[i] -  0 ) + n < N) {         if (S[i] ==  0 )           zero++;         else           zero = 0;         n += d * (long long)(S[i] -  0 ), d *= 10ll, S.pop_back();       }     }     if (n == 0) zero--;     while (zero > 0) S.push_back( 0 ), zero--;     return n;   }   int main() {     cin >> N >> S;     long long c = N;     while (c) c /= 10, dim++;     e = 1ll;     while (!S.empty()) {       sol += e * last();       e *= N;     }     cout << sol;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   long long dp[2005][2005];   int main() {     long long n, k, sum = 0;     cin >> n >> k;     for (long long i = 1; i <= n; i++) dp[1][i] = 1;     for (int i = 2; i <= k; i++) {       for (long long j = 1; j <= n; j++) {         for (int a = j; a <= n; a += j) {           dp[i][a] = (dp[i][a] + dp[i - 1][j]) % MOD;         }       }     }     for (long long i = 1; i <= n; i++) sum = (sum + dp[k][i]) % MOD;     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 1005;   int n, m, k, now;   char s[max_n], a[max_n][max_n], b[max_n][max_n];   int ans[max_n][max_n];   inline int gcd(int a, int b) {     if (!b)       return a;     else       return gcd(b, a % b);   }   int main() {     scanf( %d%d%d n , &n, &m, &k);     for (int i = 1; i <= 2 * n - 1; ++i) {       gets(s);       if (i % 2 != 0) {         now = i / 2 + 1;         for (int j = 1; j < m; ++j) a[now][j] = s[j - 1];       } else {         now = i / 2;         for (int j = 1; j <= m; ++j) b[now][j] = s[j - 1];       }     }     if (k == 1) {       int cnt = 0;       for (int i = 1; i <= n; ++i)         for (int j = 1; j < m; ++j)           if (a[i][j] ==  E ) cnt++;       for (int i = 1; i < n; ++i)         for (int j = 1; j <= m; ++j)           if (b[i][j] ==  E ) cnt++;       int t1 = 4;       int t2 = n * (m - 1) + m * (n - 1);       int t = gcd(t1, t2);       int tt = t1 * t2 / t;       int tmp1 = 3 * (tt / t1);       int tmp2 = cnt * (tt / t2);       if (tmp1 > tmp2)         printf( NO n );       else {         printf( YES n );         for (int i = 1; i <= n; ++i)           for (int j = 1; j <= m; ++j) printf( %d%c , 1,    n [j == m]);       }       return 0;     }     if (n > m) {       for (int i = 1; i <= m; ++i) {         ans[1][i] = 0;         for (int j = 1; j < n; ++j)           if (b[j][i] ==  E )             ans[j + 1][i] = ans[j][i];           else             ans[j + 1][i] = ans[j][i] ^ 1;       }       for (int i = 1; i < m; ++i) {         int cnt = 0;         for (int j = 1; j <= n; ++j)           if (a[j][i] ==  E ) {             if (ans[j][i] != ans[j][i + 1]) cnt++;           } else {             if (ans[j][i] == ans[j][i + 1]) cnt++;           }         if (cnt > n / 2)           for (int j = 1; j <= n; ++j) ans[j][i + 1] ^= 1;       }     } else {       for (int i = 1; i <= n; ++i) {         ans[i][1] = 0;         for (int j = 1; j < m; ++j)           if (a[i][j] ==  E )             ans[i][j + 1] = ans[i][j];           else             ans[i][j + 1] = ans[i][j] ^ 1;       }       for (int i = 1; i < n; ++i) {         int cnt = 0;         for (int j = 1; j <= m; ++j)           if (b[i][j] ==  E ) {             if (ans[i][j] != ans[i + 1][j]) cnt++;           } else {             if (ans[i][j] == ans[i + 1][j]) cnt++;           }         if (cnt > m / 2)           for (int j = 1; j <= m; ++j) ans[i + 1][j] ^= 1;       }     }     printf( YES n );     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) printf( %d%c , ans[i][j] + 1,    n [j == m]);   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   stringstream output;   inline void eOP();   inline void solve() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     bool* letters = new bool[26]();     for (int i = 0; i < n; ++i) {       letters[s[i] -  a ] = true;     }     vector<char> decode;     for (int i = 0; i < 26; ++i) {       if (letters[i]) {         decode.push_back(i +  a );       }     }     unordered_map<char, int> encode;     for (int i = 0; i < decode.size(); ++i) {       encode[decode[i]] = i;     }     vector<int> t;     t.reserve(k);     const size_t L = min(n, k);     for (int i = 0; i < L; ++i) {       t.push_back(encode[s[i]]);     }     t.resize(k);     if (k <= n) {       int i = k - 1;       ++t[i];       while (t[i] == decode.size()) {         t[i] = 0;         --i;         ++t[i];       }     }     for (int code : t) {       output << decode[code];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     size_t t = 1;     for (int i = 0; i < t; ++i) {       solve();     }     eOP();   }   inline void eOP() {     cout << output.str();     output.str(string());     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9 + 9;   const int MAX = 1e5 + 9;   int n, m, freq[MAX], dp[2][MAX];   vector<int> adj[MAX];   vector<pair<int, int> > a;   bool vis[MAX];   template <typename T>   void Minimize(T& a, T b) {     a = min(a, b);   }   void Add(int cnt, int x) {     int p = 1, sum = 0;     while (sum < cnt) {       if (sum + p <= cnt) {         a.push_back({p * x, p});       } else {         int more = cnt - sum;         a.push_back({more * x, more});         break;       }       sum += p;       p *= 2;     }   }   bool Lucky(int x) {     while (x) {       if (x % 10 != 4 && x % 10 != 7) {         return 0;       }       x /= 10;     }     return 1;   }   int Dfs(int cur) {     vis[cur] = 1;     int cnt = 1;     for (int i = 0; i < adj[cur].size(); ++i) {       int child = adj[cur][i];       if (!vis[child]) {         cnt += Dfs(child);       }     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         ++freq[Dfs(i)];       }     }     for (int i = 1; i <= n; ++i) {       if (freq[i]) {         Add(freq[i], i);       }     }     const int sz = a.size();     for (int j = 0; j <= n; ++j) {       dp[0][j] = OO;     }     bool cur = 0;     dp[0][0] = 0;     for (int i = 0; i < sz; ++i) {       for (int j = 0; j <= n; ++j) {         dp[cur ^ 1][j] = OO;       }       for (int j = 0; j <= n; ++j) {         if (dp[cur][j] == OO) {           continue;         }         int subsetSize = j + a[i].first, cost = dp[cur][j] + a[i].second;         Minimize(dp[cur ^ 1][subsetSize], cost);         Minimize(dp[cur ^ 1][j], dp[cur][j]);       }       cur ^= 1;     }     int mn = OO;     for (int i = 1; i <= n; ++i) {       if (dp[cur][i] == OO || !Lucky(i)) {         continue;       }       mn = min(mn, dp[cur][i]);     }     cout << (mn == OO ? -1 : mn - 1);     return 0;   }
#include <iostream>   using namespace std;   #define ll long long   ll t,n,m,k,x,y,ans;   int main(){       cin>>t;       while(t--){           cin>>n>>m>>k;           x=(k-1)/n+1,y=(k-1)%n+1;           ans=x+(y-1)*m;           cout<<ans<<endl;       }       return 0;   }