0% found this document useful (0 votes)
18 views

Code 7

Uploaded by

Md.Amdad Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Code 7

Uploaded by

Md.Amdad Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Vasya is a CEO of a big construction company.

And as any other big boss he has a spacious, richly


furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his
office to change every day. That's why he ordered both chandeliers that can change its color
cyclically. For example: red – brown – yellow – red – brown – yellow and so on.

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.

You might also like