Kick

Find the shallowest and deepest depths at which the reality notes appear as an evenly spaced subsequence of the dream notes.

Easy3String matchingBrute forceInterviewNo attempts yetTime limit1sMemory limit256 MB

Problem

Inception is planting an idea in someone's unconscious while they dream, so that after waking they believe the idea was their own. It was thought impossible for a long time, because a target is very hard to convince that a dream is real.

The PurpleNoon team used to steal information out of a target's dreams. They decided that a dream inside a dream blurs the line between the dream and reality enough for inception to work. A dream inside a dream is very unstable, so the team has to use a sedative, and a sedated sleeper sometimes cannot wake up. That is why they also use a kick. A kick knocks the dreamer over so that the sensation of falling wakes them. It works by the same principle inside a dream and in reality, and it wakes a sleeping person.

The team plans a dream inside a dream, or a dream deeper still. Depending on the situation they can go into a deeper dream. Every level has to be kicked at the same moment, so the team plays music in reality as an advance signal and kicks right after the music ends, bringing everyone back to reality at once. Working out how many levels down they are is not easy. To be safe they compute, from the sound they hear right now, the shallowest and the deepest depth that is possible.

The tempo of the music tells them the depth. Every level down widens the interval between one note and the next by exactly 11, so the music sounds that much slower. Music heard as 1 2 3 in reality is heard as … 1 x 2 x 3 … one level down, and as … 1 x x 2 x x 3 … one more level down. Any note may sit in an x position, and two x positions may hold different notes. Other notes may also be audible before and after.

In other words, a depth of dd means that starting from some position among the notes heard in the dream and reading every (d+1)(d+1)-th note from there, the nn notes of reality come out in order. Reality itself is depth 00. Given the notes heard in reality and the notes heard in the dream right now, find the shallowest and the deepest possible depth.

Input

The first line contains nn, the number of notes heard in reality. The second line contains those nn notes, separated by spaces. The third line contains mm, the number of notes heard in the dream. The fourth line contains those mm notes, separated by spaces.

2nm10002 \le n \le m \le 1000, and every note is a natural number no greater than 10910^9. The notes heard in the dream may include notes that do not occur in reality.

Output

Print the shallowest and the deepest possible depth on one line, separated by a space. If no depth is possible, print -1 only.