Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0.

There are also n cards, each card has 2 attributes: length l_{i} and cost c_{i}. If she pays c_{i} dollars then she can apply i-th card. After applying i-th card she becomes able to make jumps of length l_{i}, i. e. from cell x to cell (x - l_{i}) or cell (x + l_{i}).

She wants to be able to jump to any cell on the tape (possibly, visiting some intermediate cells). For achieving this goal, she wants to buy some cards, paying as little money as possible. 

If this is possible, calculate the minimal cost.


-----Input-----

The first line contains an integer n (1 ≤ n ≤ 300), number of cards.

The second line contains n numbers l_{i} (1 ≤ l_{i} ≤ 10^9), the jump lengths of cards.

The third line contains n numbers c_{i} (1 ≤ c_{i} ≤ 10^5), the costs of cards.


-----Output-----

If it is impossible to buy some cards and become able to jump to any cell, output -1. Otherwise output the minimal cost of buying such set of cards.


-----Examples-----
Input
3
100 99 9900
1 1 1

Output
2

Input
5
10 20 30 40 50
1 1 1 1 1

Output
-1

Input
7
15015 10010 6006 4290 2730 2310 1
1 1 1 1 1 1 10

Output
6

Input
8
4264 4921 6321 6984 2316 8432 6120 1026
4264 4921 6321 6984 2316 8432 6120 1026

Output
7237



-----Note-----

In first sample test, buying one card is not enough: for example, if you buy a card with length 100, you can't jump to any cell whose index is not a multiple of 100. The best way is to buy first and second card, that will make you be able to jump to any cell.

In the second sample test, even if you buy all cards, you can't jump to any cell whose index is not a multiple of 10, so you should output -1.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
l = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

gcds = {0: 0}

for i in range(n):
    adds = {}
    for g in list(gcds.keys()):
        x = gcd(g, l[i])
        y = gcds.get(x)
        u = gcds[g]
        if y is not None:
            if u + c[i] < y:
                t = adds.get(x)
                if t and t > u + c[i] or t is None:
                    adds[x] = u + c[i]
        else:
            t = adds.get(x)
            if t and t > u + c[i]or t is None:
                adds[x] = u + c[i]
    gcds.update(adds)

if gcds.get(1):
    print(gcds[1])
else:
    print(-1)



def main():
    input()
    acc = {0: 0}
    for p, c in zip(list(map(int, input().split())),
                    list(map(int, input().split()))):
        adds = []
        for b, u in acc.items():
            a = p
            while b:
                a, b = b, a % b
            adds.append((a, u + c))
        for a, u in adds:
            acc[a] = min(u, acc.get(a, 1000000000))
    print(acc.get(1, -1))


def __starting_point():
    main()
__starting_point()

#D
input()
ok = {0:0}
for p, c in zip(list(map(int, input().split())),
                list(map(int, input().split()))):
    ad = []
    for b, u in list(ok.items()):
        a = p
        while b:
            a,b  = b, a % b
        ad.append((a, u + c))
    for a, u in ad:
        ok[a] = min(u, ok.get(a, 1000000000))
print(ok.get(1, -1))


import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
mod = int(1e9) + 7
INF=float('inf')

n=int(data())
l=mdata()
c=mdata()
d=dict()
for i in range(n):
    if d.get(l[i]):
        d[l[i]]=min(d[l[i]],c[i])
    else:
        d[l[i]]=c[i]
for i in l:
    lis=list(d.keys())
    for j in lis:
        g = math.gcd(i, j)
        if d.get(g):
            d[g]=min(d[g],d[i]+d[j])
        else:
            d[g] = d[i] + d[j]
if 1 in d:
    out(d[1])
else:
    out(-1)