Thanos VS Power Stone

jisan047 BSMRSTU Home Quarantine C...
Limits 1s, 512 MB

Who doesn't know about thanos the genius mad titan, who waste his life acquiring the infinity stones. He is close enough to discover the architectural value of power stone.

He found that the architectural value of power stone is X such that X % M1 = A 1, X % M2 = A 2, . . . ,X % Mn = A n and X is minimum possible. He has the set of A, M but he can't find out X himself. Can you help him find X?

As the X can be very big find X Modulo LCM(M1, M2, . . ., Mn)

Input

Input starts with N representing the size of set A, M
Next two lines contain N Integers each. Representing set A and M respectively.

Constraints:

1 ≤ N ≤ 105

1 ≤ Mi ≤ 40

N.B: Every constraints will be valid

Output

Print X Modulo LCM(M1, M2, . . ., Mn) denoting the Architectural value of power stone, If such X is not possible print "Infinity Stones are just a myth"

Sample

InputOutput
3
1 2 4
2 3 5
29

Submit

Login to submit.

Statistics

76% Solution Ratio
Riaz_BSMRSTUEarliest, May '20
Deshi_TouristFastest, 0.0s
TurinhstuLightest, 1.7 MB
steinumShortest, 556B
Toph uses cookies. By continuing you agree to our Cookie Policy.