malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-20;   int main() {     int n, a, d;     cin >> n >> a >> d;     int *t = new int[n];     int *v = new int[n];     double ans = -1.0;     for (int i = 0; i < n; i++) cin >> t[i] >> v[i];     for (int i = 0; i < n; i++) {       double t1 = (v[i] + 0.0) / (a + 0.0);       double t2 = (d - a * t1 * t1 * 0.5) / (v[i] + 0.0);       if (a * t1 * t1 * 0.5 >= d) {         t1 = sqrt(2.0 * d / (a + 0.0));         t2 = 0;       }       double tt = t1 + t2 + t[i];       if (tt > ans) {         printf( %.6f n , tt);         ans = tt;       } else         printf( %.6f n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 110;   const int M = 1010;   double f[N][M * N], sum[N * M];   int a[N], n, m, s;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       s += a[i];     }     f[0][0] = 1;     sum[0] = 1.0;     for (int j = 1; j < s; j++) sum[j] = sum[j - 1] + f[0][j];     for (int i = 1; i <= n; i++) {       for (int j = i; j < s; j++) {         int l = min(m, j - i + 1);         int r = max(-1, j - l - 1);         double tmp = sum[j - 1] - ((r == -1) ? 0 : sum[r]);         if (l < a[i])           f[i][j] = tmp / (m - 1);         else           f[i][j] = (tmp - f[i - 1][j - a[i]]) / (m - 1);       }       sum[0] = 0;       for (int j = 1; j < s; j++) {         sum[j] = sum[j - 1] + f[i][j];       }     }     double ans = 0;     for (int i = n; i < s; i++) {       ans += f[n][i];     }     printf( %.10f n , 1 + ans * (m - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[111], x[111], saven;   long double f[2][100111], sum[2][100111];   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout << (fixed) << setprecision(12);     while (cin >> n >> m) {       int sumA = 0;       for (int i = (1), _b = (n); i <= _b; ++i) {         int x;         cin >> x;         --x;         a[i] = x;         sumA += x;       }       if (m == 1) {         cout << 1.0 << endl;         continue;       }       for (int i = (1), _b = (n); i <= _b; ++i) {         int cur = i % 2;         memset(f[cur], 0, sizeof f[cur]);         if (i == 1) {           for (int val = 0, _a = (m * i); val < _a; ++val)             if (val < m && val != a[i]) f[cur][val] = 1;         } else {           for (int val = 0, _a = (m * i); val < _a; ++val) {             f[cur][val] = sum[1 - cur][val];             if (val >= m) f[cur][val] -= sum[1 - cur][val - m];             f[cur][val] -= f[1 - cur][val - a[i]];           }         }         for (int val = 0, _a = (m * (i + 1)); val < _a; ++val) {           sum[cur][val] = f[cur][val];           if (val > 0) sum[cur][val] += sum[cur][val - 1];         }       }       long double t = sum[n % 2][sumA - 1];       for (int turn = 0, _a = (n); turn < _a; ++turn) t /= (m - 1);       cout << t * (m - 1.0) + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;      int n, k;      void solve(){       cin >> n >> k;          int cnt = 1;          int query = 0;          for(int i = 0; i < n; i++){           if(i) query = i ^ (i - 1);           cout << query << endl;           int r;           cin >> r;           if(r == 1) return;       }   }      int main(){       // freopen( inp.txt ,  r , stdin);       // freopen( out.txt ,  w , stdout);       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);          int t;       cin >> t;       while(t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, x, y, k, a, q, h, l, r, j, p, s[400];   vector<int> ve[51][51];   bool ok1, ok2, Find, ok[51][51];   void get(int x, int y, int z) {     q = 105;     h = 104;     for (int i = 1; i < ve[x][y].size(); i++) {       s[++h] = ve[x][y][i];       if (i == z) l = h, r = h + 1;     }     while (q != l && h - q + 1 <= 2 * n) {       if (ve[s[l - 1]][s[l]].size() == 0) return;       for (int i = ve[s[l - 1]][s[l]].size() - 1; i; i--)         s[--q] = ve[s[l - 1]][s[l]][i];       l--;     }     if (h - q + 1 > 2 * n) return;     while (h != r && h - q + 1 <= 2 * n) {       if (ve[s[r]][s[r + 1]].size() == 0) return;       for (int i = 1; i < ve[s[r]][s[r + 1]].size(); i++)         s[++h] = ve[s[r]][s[r + 1]][i];       r++;     }     if (h - q + 1 > 2 * n) return;     Find = true;   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d%d , &x, &y, &k);       ok1 = false;       ok2 = false;       ve[x][y].push_back(0);       a = 0;       while (k--) {         if (a != x)           ok1 = false;         else           ok1 = true;         scanf( %d , &a);         if (a == y && ok1) ok2 = true;         ve[x][y].push_back(a);       }       if (ok2) ok[x][y] = true;     }     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         if (ok[i][j])           for (p = 1; p < ve[i][j].size() - 1; p++)             if (ve[i][j][p] == i && ve[i][j][p + 1] == j) {               get(i, j, p);               if (Find) {                 printf( %d n , h - q + 1);                 for (i = q; i <= h; i++) printf( %d  , s[i]);                 printf(  n );                 return 0;               }             }     printf( 0 n );   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793238462643383;   int w;   int visit[37] = {0};   int Ceil(int a, int b) {     if (a % b == 0)       return a / b;     else       return (a / b) + 1;   }   struct TrieNode {     struct TrieNode *children[37];     bool isEndofWord;     int cnt[37];     int snum[37];     int visit[37];   };   TrieNode *getNode() {     TrieNode *x = new TrieNode;     x->isEndofWord = false;     for (int i = 0; i < (37); ++i) x->children[i] = NULL;     for (int i = 0; i < (37); ++i) x->cnt[i] = 0;     for (int i = 0; i < (37); ++i) x->snum[i] = -1;     for (int i = 0; i < (37); ++i) x->visit[i] = -1;     return x;   }   int find(char c) {     if (c ==  . ) {       return 26;     }     if (c >=  a  && c <=  z ) {       return c -  a ;     }     return 27 + c -  0 ;   }   void insert(TrieNode *root, string s, int num) {     TrieNode *p = root;     for (int i = 0; i < (s.size()); ++i) {       int index;       index = find(s[i]);       if (!p->children[index]) {         p->children[index] = getNode();       }       if (p->visit[index] != num) p->cnt[index]++;       p->snum[index] = num;       p->visit[index] = num;       p = p->children[index];     }     p->isEndofWord = true;   }   int search(TrieNode *root, string s) {     TrieNode *p = root;     int ans;     for (int i = 0; i < (s.size()); ++i) {       int index;       index = find(s[i]);       if (!p->children[index]) {         return 0;       }       ans = p->cnt[index];       w = p->snum[index];       p = p->children[index];     }     return ans;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     int n;     cin >> n;     string a[n];     TrieNode *root = getNode();     int e = 0;     while (n--) {       string s;       cin >> s;       a[e] = s;       e++;       int y = s.size() - 1;       for (int i = 0; i < (s.size()); ++i) {         string str;         int x = s.size() - i;         str.resize(x);         int q = 0;         for (int j = i; j <= (y); ++j) {           str[q] = s[j];           q++;         }         insert(root, str, e);       }     }     int q;     cin >> q;     while (q--) {       string s;       cin >> s;       int y = search(root, s);       if (y == 0) {         cout <<  0 -  <<   n ;       } else {         cout << y <<     << a[w - 1] <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> v;     long long mx = -1, mn = -1;     for (long long i = 1; i * i <= n; i++)       if (n % i == 0) {         v.push_back(i);         v.push_back(n / i);       }     sort((v).begin(), (v).end());     for (int i = 0; i < (int)(v).size(); i++) {       long long rest = n / v[i];       for (int j = 0; j < (int)(v).size(); j++)         if (rest % v[j] == 0) {           long long a = v[i] + 1;           long long b = v[j] + 2;           long long c = rest / v[j] + 2;           mx = max(mx, a * b * c - (a - 1) * (b - 2) * (c - 2));           if (mn == -1) mn = a * b * c - (a - 1) * (b - 2) * (c - 2);           mn = min(mn, a * b * c - (a - 1) * (b - 2) * (c - 2));         }     }     cout << mn <<     << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10, inf = 1e9 + 10, P = 53, MOD = 1e9 + 7;   int n, a, b, k, q, seg1[4 * maxn], seg2[4 * maxn];   inline void update(int ind) {     seg1[ind] = seg1[((ind) * (2))] + seg1[(((ind) * (2)) + 1)];     seg2[ind] = seg2[((ind) * (2))] + seg2[(((ind) * (2)) + 1)];   }   void add(int s, int e, int ind, int l, int r, int x) {     if (s >= r || e <= l) return;     if (s >= l && e <= r) {       seg1[ind] += x;       seg2[ind] += x;       seg1[ind] = min(seg1[ind], b);       seg2[ind] = min(seg2[ind], a);       return;     }     int mid = (s + e) / 2;     add(s, mid, ((ind) * (2)), l, r, x);     add(mid, e, (((ind) * (2)) + 1), l, r, x);     update(ind);   }   int query(int type, int s, int e, int ind, int l, int r) {     if (s >= r || e <= l) return 0;     if (s >= l && e <= r) {       if (type == 1)         return seg1[ind];       else         return seg2[ind];     }     int mid = (s + e) / 2;     return query(type, s, mid, ((ind) * (2)), l, r) +            query(type, mid, e, (((ind) * (2)) + 1), l, r);   }   int main() {     scanf( %d%d%d%d%d , &n, &k, &a, &b, &q);     while (q--) {       int type, l, x;       scanf( %d , &type);       if (type == 1) {         scanf( %d%d , &l, &x);         add(0, n, 1, l - 1, l, x);       } else {         scanf( %d , &x);         x--;         printf( %d n , query(1, 0, n, 1, 0, x) + query(2, 0, n, 1, x + k, n));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   struct node {     int x, y;   } point[maxn];   bool check(node a, node b, node c, node d) {     if (a.x - b.x == c.x - d.x && a.y - b.y == c.y - d.y) return true;     return false;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> point[i].x >> point[i].y;     if (n & 1) {       cout <<  nO  << endl;     } else {       bool flag = true;       for (int i = 0; i < n; ++i) {         if (!check(point[(i + 1) % n], point[i], point[(i + n / 2) % n],                    point[(i + n / 2 + 1) % n]))           flag = false;       }       if (flag)         cout <<  YES  << endl;       else         cout <<  nO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 10;   const long long M = 1e9 + 7;   long long Max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long Min(long long a, long long b) {     if (a > b) return b;     return a;   }   long long big_mul(long long a, long long b, long long m) {     long long x = 0, y = a % m;     while (b > 0) {       if (b & 1) x = (x + y) % m;       y = (2 * y) % m;       b >>= 1;     }     return x % m;   }   long long big_mod(long long a, long long b, long long m) {     long long x = 1, y = a % m;     while (b > 0) {       if (b & 1) x = (x * y) % m;       y = (y * y) % m;       b >>= 1;     }     return x % m;   }   long long Big_mod(long long a, long long b, long long m) {     long long x = 1, y = a % m;     while (b > 0) {       if (b & 1) x = big_mul(x, y, m);       y = big_mul(y, y, m);       b >>= 1;     }     return x % m;   }   long long mod_inverse(long long a, long long m) { return big_mod(a, m - 2, m); }   unordered_map<string, bool> Map;   int a, b, c, d, e, f, g, h;   vector<pair<int, int> > vec;   vector<pair<pair<int, int>, int> > save;   void fnct(int x1, int y1, int x2, int y2) {     if (x1 < x2 && y1 > y2) {       a = x1;       b = y2;       c = x1;       d = y1;       e = x2;       f = y1;       g = x2;       h = y2;     } else if (x1 > x2 && y1 < y2) {       a = x2;       b = y1;       c = x2;       d = y2;       e = x1;       f = y2;       g = x1;       h = y1;     } else if (x1 < x2 && y1 < y2) {       a = x1;       b = y1;       c = x1;       d = y2;       e = x2;       f = y2;       g = x2;       h = y1;     } else {       a = x2;       b = y2;       c = x2;       d = y1;       e = x1;       f = y1;       g = x1;       h = y2;     }   }   double dis(double w, double z, double p, double q) {     double n = w - p;     double m = z - q;     return sqrt(n * n + m * m);   }   bool check(double p, double q) {     for (int i = 0; i < save.size(); i++) {       double w = (double)(save[i].first.first);       double z = (double)(save[i].first.second);       double r = (double)(save[i].second);       if (dis(w, z, p, q) <= r) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     fnct(x1, y1, x2, y2);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int w, z, r;       cin >> w >> z >> r;       if (Map[to_string(w) + to_string(z) + to_string(r)] == false)         save.push_back(make_pair(make_pair(w, z), r));       Map[to_string(w) + to_string(z) + to_string(r)] = true;     }     for (int i = c; i <= e; i++) vec.push_back(make_pair(i, d));     for (int i = a; i <= g; i++) vec.push_back(make_pair(i, b));     for (int i = d - 1; i > b; i--) vec.push_back(make_pair(a, i));     for (int i = f - 1; i > h; i--) vec.push_back(make_pair(e, i));     int ans = 0;     for (int i = 0; i < vec.size(); i++) {       double p = (double)(vec[i].first);       double q = (double)(vec[i].second);       if (check(p, q) == false) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100010];   bool b[100010];   long long gcd(long long a, long long b) { return a % b ? gcd(b, a % b) : b; }   int main() {     long long n, t;     scanf( %lld , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       b[i] = a[i] % 2;     }     long long ans = gcd(abs(a[1]), abs(a[2]));     for (int i = 3; i <= n; i++) ans = gcd(ans, abs(a[i]));     if (ans > 1)       printf( YES n0 n );     else {       int num = 0;       for (int i = 1; i < n; i++)         while (b[i] == 1) {           if (b[i + 1] == 1) {             b[i] = 0;             b[i + 1] = 0;           } else {             b[i + 1] = 1;           }           ++num;         }       if (b[n] == 1) num += 2;       printf( YES n%d n , num);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const long long INF = 1000000007;   const long long INF2 = 1000000007LL * 1000000007LL;   const long double EPS = 1e-9;   const int SIZE = 1001000;   int n, a, b;   string fn[SIZE];   int val[SIZE], ans[SIZE];   int z[SIZE];   vector<int> g[SIZE];   void setVal(int v) {     if (fn[v][0] ==  I ) {       return;     }     for (auto& i : g[v]) setVal(i);     if (fn[v][0] ==  A ) {       val[v] = val[g[v][0]] && val[g[v][1]];       return;     }     if (fn[v][0] ==  O ) {       val[v] = val[g[v][0]] || val[g[v][1]];       return;     }     if (fn[v][0] ==  X ) {       val[v] = (val[g[v][0]] + val[g[v][1]]) % 2;       return;     }     val[v] = !val[g[v][0]];   }   void dfs(int v, int zn) {     if (fn[v][0] ==  I ) {       z[v] = zn;       return;     }     if (zn == 0) {       for (auto& i : g[v]) dfs(i, 0);       return;     }     if (fn[v][0] ==  A ) {       if (val[v] == 1) {         for (auto& i : g[v]) dfs(i, 1);       } else {         if (!val[g[v][0]] && val[g[v][1]]) {           dfs(g[v][0], 1);           dfs(g[v][1], 0);         } else if (val[g[v][0]] && !val[g[v][1]]) {           dfs(g[v][0], 0);           dfs(g[v][1], 1);         } else {           for (auto& i : g[v]) dfs(i, 0);         }       }       return;     }     if (fn[v][0] ==  O ) {       if (val[v] == 0) {         for (auto& i : g[v]) dfs(i, 1);       } else {         if (val[g[v][0]] && val[g[v][1]]) {           dfs(g[v][0], 0);           dfs(g[v][1], 0);         } else if (!val[g[v][0]] && val[g[v][1]]) {           dfs(g[v][0], 0);           dfs(g[v][1], 1);         } else if (val[g[v][0]] && !val[g[v][1]]) {           dfs(g[v][0], 1);           dfs(g[v][1], 0);         }       }       return;     }     for (auto& i : g[v]) dfs(i, zn);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> fn[i];       if (fn[i] ==  IN ) {         cin >> val[i];       } else if (fn[i] ==  NOT ) {         cin >> a;         --a;         g[i].push_back(a);       } else {         cin >> a;         --a;         g[i].push_back(a);         cin >> a;         --a;         g[i].push_back(a);       }     }     setVal(0);     dfs(0, 1);     for (int i = 0; i < n; ++i) {       if (fn[i][0] ==  I ) {         if (z[i])           cout << !val[0];         else           cout << val[0];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 202;   const int MAXM = 50005;   struct edge {     int a, b;     long long int g, s;     edge(int a_ = 0, int b_ = 0, long long int g_ = 0LL, long long int s_ = 0LL) {       a = a_, b = b_, g = g_, s = s_;     }   };   int N, M, cnt;   int dad[MAXN];   long long int G, S, res = 1LL << 62;   edge g[MAXM];   edge way[MAXM];   inline bool compare(const edge &a, const edge &b) { return a.g < b.g; }   inline int find(int a) {     if (a == dad[a]) return a;     return dad[a] = find(dad[a]);   }   int main() {     scanf(  %d %d %I64d %I64d , &N, &M, &G, &S);     for (int i = 1; i <= M; i++) {       scanf(  %d %d %I64d %I64d , &way[i].a, &way[i].b, &way[i].g, &way[i].s);       way[i].g *= G;       way[i].s *= S;     }     sort(way + 1, way + M + 1, compare);     for (int i = 1; i <= M; i++) {       g[++cnt] = way[i];       for (int j = cnt; j > 1; j--) {         if (g[j].s < g[j - 1].s)           swap(g[j], g[j - 1]);         else           break;       }       if (i >= N - 1) {         long long int ss;         for (int j = 1; j <= N; j++) dad[j] = j;         int c = 0;         int ncnt = 0;         for (int j = 1; j <= cnt; j++)           if (find(g[j].a) != find(g[j].b)) {             c++;             g[++ncnt] = g[j];             ss = g[j].s;             dad[find(g[j].a)] = g[j].b;           }         cnt = ncnt;         if (c == N - 1) res = min(res, way[i].g + ss);       }     }     if (res == 1LL << 62)       printf( -1 n );     else       printf( %I64d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, id, nxt[100005], num[100005], mark[100005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &nxt[i]);       if (nxt[i] == i) {         puts( YES );         for (int j = 1; j <= n; j++)           if (j != i) printf( %d %d n , i, j);         return 0;       }     }     for (int i = 1; i <= n; i++) {       if (num[i]) continue;       int j = nxt[i], t = 1;       while (j != i) j = nxt[j], t++;       while (!num[j]) num[j] = t, j = nxt[j];       if (t & 1) {         puts( NO );         return 0;       }       if (t == 2) id = i;     }     if (!id) {       puts( NO );       return 0;     }     puts( YES );     printf( %d %d n , id, nxt[id]);     for (int i = 1; i <= n; i++) {       if (i == id || i == nxt[id] || mark[i]) continue;       int a = id, b = i;       while (num[i]--) {         printf( %d %d n , a, b);         mark[b] = 1;         a = nxt[a];         b = nxt[b];       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int ara[n];     int temp, j;     int i = 0;     while (i < n) {       scanf( %d , &ara[i]);       i++;     }     i = 0;     while (i < (n - 1)) {       j = 0;       while (j < (n - 1)) {         if (ara[j] > ara[j + 1]) {           temp = ara[j];           ara[j] = ara[j + 1];           ara[j + 1] = temp;         }         j++;       }       i++;     }     i = 0;     while (i < n) {       printf( %d  , ara[i]);       i++;     }     return 0;   }
#include <bits/stdc++.h>   #define MP make_pair   using namespace std;      #define rep(i, n) for (int i = 0; i < (int)(n); ++ i)   #define rep1(i, n) for (int i = 1; i <= (int)(n); ++ i)   #define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++ itr)      typedef long long LL;   typedef pair<int, int> pii;      const int MAXN = 2e5 + 5;      int N;   string str[MAXN];   map<string, vector<string> > grps;   LL ans;      int solve_pair(const string& s1, const string& s2)   {       int prefix = 0, suffix = 0, n = s1.size();          while (s1[prefix] == s2[prefix]) prefix ++;       while (s1[n - suffix - 1] == s2[n - suffix - 1]) suffix ++;          return is_sorted(s1.begin() + prefix, s1.end() - suffix) || is_sorted(s2.begin() + prefix, s2.end() - suffix) ? 1ll : 2ll;   }   void solve(vector<string>& grp)   {       int n = grp.size(), len = grp[0].size();       ans -= 1ll * (n - 1) * n / 2 * 1337;          if (n <= 200 * len) {           rep(i, n) for (int j = i + 1; j < n; ++ j) {               ans += solve_pair(grp[i], grp[j]);           }       } else {           sort(grp.begin(), grp.end());           ans += 1ll * (n - 1) * n / 2 * 2;              for (auto& s : grp) {               rep(i, len) for (int j = i + 2; j <= len; ++ j) {                   string sorted = s;                   sort(sorted.begin() + i, sorted.begin() + j);                   ans -= (sorted[i] != s[i] && sorted[j - 1] != s[j - 1] && binary_search(grp.begin(), grp.end(), sorted));               }           }       }   };      int main()   {       scanf( %d , &N);       rep(i, N) {           cin >> str[i];           string sorted = str[i];           sort(sorted.begin(), sorted.end());           grps[sorted].push_back(str[i]);       }          ans = 1ll * (N - 1) * N / 2 * 1337;          for (auto& grp : grps) solve(grp.second);          printf( %lld n , ans);              return 0;   }
#include <iostream>   #include <cmath>   #include <map>   #include <string>   #include <vector>   #include <algorithm>   #define int long long   using namespace std;   string s;   int a, b, c;   int n, m, k;   vector<int>vec, vec2;   int arr[4000000], mark[4000000];   signed main() {    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    cin >> n >> m >> k;    for (int i = 0; i < n; i++) {     cin >> a;     vec.push_back(a);    }    for (int i = 0; i < m; i++) {     cin >> a;     vec2.push_back(a);    }    if (n < m) {     swap(n, m);     swap(vec, vec2);    }    int iter = 0;    for (auto i : vec) {     mark[iter] = m;     iter++;     arr[i] = iter;    }    iter = 0;    int pos;    for (auto i : vec2) {     iter++;     if (arr[i] != 0) {      pos = (arr[i] - iter + n) % n;      mark[pos]--;     }    }    pos = 0;    int sum = 0;    int len = 0;    while (true) {     sum += mark[pos];     pos += m;     len += m;     pos %= n;     if (pos == 0) {      break;     }    }    k -= 2;    int ans = (k / sum);    ans *= len;    k %= sum;    k += 2;    pos = 0;    while (k > mark[pos]) {     k -= mark[pos];     pos += m;     ans += m;     pos %= n;    }    int pos2 = 0;    while (k > 0) {     ans++;     if (vec[(pos + pos2) % n] != vec2[pos2 % m]) {      k--;     }     pos2++;    }    cout << ans;    return 0;   }