Code 7
Code 7
There are many chandeliers that differs in color set or order of colors. And the person responsible for
the light made a critical mistake — they bought two different chandeliers.
Since chandeliers are different, some days they will have the same color, but some days — different.
Of course, it looks poor and only annoys Vasya. As a result, at the kk-th time when chandeliers will
light with different colors, Vasya will become very angry and, most probably, will fire the person who
bought chandeliers.
Your task is to calculate the day, when it happens (counting from the day chandeliers were
installed). You can think that Vasya works every day without weekends and days off.
Input
The first line contains three
integers nn, mm and kk (1≤n,m≤5000001≤n,m≤500000; 1≤k≤10121≤k≤1012) — the number of
colors in the first and the second chandeliers and how many times colors should differ to anger
Vasya.
The second line contains nn different integers aiai (1≤ai≤2⋅max(n,m)1≤ai≤2⋅max(n,m)) that
describe the first chandelier's sequence of colors.
The third line contains mm different integers bjbj (1≤bi≤2⋅max(n,m)1≤bi≤2⋅max(n,m)) that
describe the second chandelier's sequence of colors.
At the ii-th day, the first chandelier has a color axax, where x=((i−1)modn)+1)x=((i−1)modn)
+1) and the second one has a color byby, where y=((i−1)modm)+1)y=((i−1)modm)+1).
It's guaranteed that sequence aa differs from sequence bb, so there are will be days when colors of
chandeliers differs.
Output
Print the single integer — the index of day when Vasya will become angry.