#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define _roverload(_a1, _a2, _a3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _roverload(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); --i)
#define rrep(...) _roverload(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << '\n'; }
template <class T>
void print(const vector<T> &v) {
    bool f = false;
    for (const auto &e : v) {
        if (f) cout << ' ';
        cout << e;
        f = true;
    }
    cout << '\n';
}
template <class... T>
void print(const T &...args) {
    bool f = false;
    for (const auto &e : {args...}) {
        if (f) cout << ' ';
        cout << e;
        f = true;
    }
    cout << '\n';
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main() {
    int n, m;
    ll k;
    cin >> n >> m >> k;
    int MX = 2 * max(n, m) + 10;
    vi a(n);
    rep(i, n) cin >> a[i];
    vi b(m);
    rep(i, m) cin >> b[i];
    if (n < m) {
        swap(n, m);
        swap(a, b);
    }
    assert(a.size() >= b.size());
    vi idxs(MX, -1);
    rep(i, n) {
        idxs[a[i]] = i;
    }
    vi diff(n, m);
    rep(i, m) {
        if (idxs[b[i]] == -1) continue;
        diff[(idxs[b[i]] - i + n) % n]--;
    }
    int now = 0;
    ll ans = 0;
    ll loopday = 0, loopdiff = 0;
    do {
        if (loopdiff + diff[now] < k) {
            loopday += m;
            loopdiff += diff[now];
        } else {
            ans += loopday;
            rep(i, m) {
                if (a[(now + i) % n] != b[i]) {
                    loopdiff++;
                }
                ans++;
                if (loopdiff == k) {
                    print(ans);
                    return 0;
                }
            }
        }
        now += m;
        now %= n;
    } while (now != 0);
    ans += loopday * (k / loopdiff - 1);
    k %= loopdiff;
    k += loopdiff;
    if (k == 0) {
        print(ans);
        return 0;
    }
    loopday = 0, loopdiff = 0;
    while (true) {
        if (loopdiff + diff[now] < k) {
            loopday += m;
            loopdiff += diff[now];
        } else {
            ans += loopday;
            rep(i, m) {
                if (a[(now + i) % n] != b[i]) {
                    loopdiff++;
                }
                ans++;
                if (loopdiff == k) {
                    print(ans);
                    return 0;
                }
            }
        }
        now += m;
        now %= n;
    }
}