Two urgent cake orders came to Byteasar's confectionery.
As we all know, cakes have layers.
The confectionery offers different kinds of layers
and each cake contains exactly one layer of each kind.
A cake order specifies a sequence in which the layers are to be placed.
Byteasar hires confectioners; the -th confectioner
(for ) can prepare only a layer of the -th kind.
Each confectioner places his layer in a single minute
(during that time he or she can work on a single cake only).
Layers of a cake are to be placed one by one,
however two cakes can be processed in parallel.
How much time will it take to fulfill the two given cake orders,
assuming that the cakes are produced in an optimal manner?
Input
The first line of input contains a single integer ().
Two lines follow containing a description of the first and the second
cake order respectively.
Each cake order is a sequence of pairwise distinct integers
of value between and ,
describing the subsequent layers of the ordered cake
starting from the topmost layer.
Output
The first and only line of output should contain
a single integer: the number of minutes needed
to produce the two ordered cakes.
Example
For the input data:
3
1 2 3
3 2 1
the correct result is:
4
Task author: Anna Zych.
Kontakt
W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem szkopul@fri.edu.pl.
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, odwiedź nasze serwery na Discordzie. Są one moderowane przez społeczność, ale członkowie zespołu wsparcia również aktywnie się tam udzielają.