#include<bits/stdc++.h>   #include<unordered_map>   #include<unordered_set>   #define f(i,a,b) for( int i=a;i<=b;++i)   #define ff(i,a,b) for( int i=a;i>=b;--i)   #define debug(x) cerr << #x <<   :   << x <<     << endl   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef long double ld;   typedef pair<int, int> pii;   typedef pair<string, string> pss;   const ll mod = 1e9 + 7;   const ll mod2 = 998244353;   const ll inf = 2e18;   const double tiaohe = 0.57721566490153286060651209;   ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }   ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }   ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }   void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }   ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }   bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }   inline ll in() { char ch = getchar();ll x = 0, f = 1;while (ch< 0  || ch> 9 ) { if (ch ==  - )f = -1;ch = getchar(); }while (ch >=  0 &&ch <=  9 ) { x = x * 10 + ch -  0 ;ch = getchar(); }return x * f; }   void print(double x) { printf( %.6lf n , x); }   //double a = log(n) +tiaohe + 1.0 / (2 * n);   double eqa = (1 + sqrt(5.0)) / 2.0;   double E = 2.7182818284;   const double eps = 1e-8;   double pi = acos(-1);   const int N = 5e5 + 100;   int n, m;   ll k;   int a[N], b[N],id;   ll M[2], LCM;   pair<ll,ll> st[N];//等价类起点   pair<ll,ll> linear( ll B[], ll M[], int n)   {    //求解 A[i]x = B[i] (mod M[i]), 总共 n 个线性 方程组, →     ll x = 0, m = 1;    for (int i = 0; i < n; i++)    {     ll a =  m, b = B[i] -  x, d = gcd(M[i], a);     if (b % d != 0) return pair<ll,ll>(0, -1);//答案不存在，返回-1      ll t = b / d * inv(a / d, M[i] / d) % (M[i] / d);     x = x + m * t;     m *= M[i] / d;    }    x = (x % m + m) % m;    return pair<ll, ll>{x,m};//返回的 x 就是答案，m 是最后的 lcm 值   }   ll pos[N][2];   bool check(ll mid) {    ll res = mid;//减去命中的    f(i, 1, id) {     if (st[i].second == -1) {      continue;     }     if (st[i].first > mid)continue;     ll num = (ll)ceil((mid-1-st[i].first)*1.0/LCM);     res -= num;    }    //cout << mid <<     << res << endl;    return res <= k;   }   void work(ll k) {    ll l = 0, r = 2e18,res=0;    while (l <= r) {     ll mid = l + r >> 1;     if (check(mid)) {      res = mid;      l = mid + 1;     }     else {      r = mid - 1;     }    }    cout << res << endl;   }   int main()   {   #ifndef ONLINE_JUDGE    freopen( in.txt ,  r , stdin);   #endif    cin >> n >> m >> k;    unordered_map<int, int> mp;    f(i, 1, n)a[i] = in(), mp[a[i]] = i-1;    f(i, 1, m)b[i] = in();    id = 0;    f(i, 1, m) {     if (mp.count(b[i])) {      pos[++id][0] = mp[b[i]];      pos[id][1] = i-1;     }    }    LCM= 1ll*n * m / gcd(n, m);    M[0] = n, M[1] = m;    f(i, 1, id) {     st[i] = linear(pos[i], M, 2);     //cout << st[i].first <<     << st[i].second << endl;    }    work(k);    return 0;   }