qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
A, B = map(int, input().split())

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

num = gcd(A, B)

isPrime = [True for i in range(num + 1)]
isPrime[2] = True
for i in range(2, num+1):
    if isPrime[i]:
        for j in range(2 * i, num+1, i):
            isPrime[j] = False

count = 1

cur = 2
while num != 1:
    if isPrime[cur] and num % cur == 0:
        while num % cur == 0:
            num //= cur
        count += 1
    cur += 1

print(count)


# Fixed code:
A, B = map(int, input().split())

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

num = gcd(A, B)

if num < 2:
    print(1)
    quit()

length = int(num ** 0.5) + 2
isPrime = [True for i in range(length)]
isPrime[2] = True
for i in range(2, length):
    if isPrime[i]:
        for j in range(2 * i, length, i):
            isPrime[j] = False

count = 1

cur = 2
while num != 1 and cur < length:
    if isPrime[cur] and num % cur == 0:
        while num % cur == 0:
            num //= cur
        count += 1
    cur += 1

print(count + (num != 1))
# Buggy code:
C,D = [int(e) for e in input().split()]

if C <= D:
    m = D
    n = C
else:
    m = C
    n = D

while  n != 0 :
    a = m%n
    m = n
    n = a

J = []
for i in range(1, int(m**0.5)+1):
    if m % i == 0:
        J.append(i)
        if i != m//i:
            J.append(m//i)


J.sort()

N = int(len(J))
print(J)
M = [1]
I = []

for i in range(1,N):
    for p in range(1,J[i]+1):
        if J[i]%p == 0:
            I.extend([J[i]])
    if int(len(I)) == 2:
        M.extend([J[i]])
    I = []


M = int(len(M))

print(M)

# Fixed code:
C,D = [int(e) for e in input().split()]

if C <= D:
    m = D
    n = C
else:
    m = C
    n = D

while  n != 0 :
    a = m%n
    m = n
    n = a

J = []

for i in range(1,int(m**0.5)+1):
    if m % i == 0:
        J.append(i)
        if i != m//i:
            J.append(m//i)


J.sort()

N = int(len(J))
M = [1]
I = []

for i in range(1,N):
    for p in range(1,int(J[i]**0.5)+1):
        if J[i]%p == 0:
            I.extend([J[i]])
            if int(len(I)) >=2:
                break
    if int(len(I)) == 1:
        M.extend([J[i]])
    I = []


M = int(len(M))

print(M)
# Buggy code:
#import sys

#input = sys.stdin.readline

#import heapq
import math
import fractions

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True

def main():
#    h,w,a,b = map(int, input().split())
    a,b=map(int,input().split())
    m=2
    k=1

    count=1
    if a>b:
        a,b=b,a
    sosu=set()
    #d = math.gcd(a,b)
#    print(d)
    c=math.sqrt(a)+1
 #   print(c)
    while m<c and m<=a:
        if a%m==0:
            sosu.add(m)
            if b%m==0:
                count+=1
            while a%m==0:
                a//=m

        m+=1
    if sosuhante(a):
        if b%a==0:
            count+=1

#    print(sosu)
#    for i in sosu:
 #       if b%i==0:
 #           count+=1



    print(count)
#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()

# Fixed code:
#import sys

#input = sys.stdin.readline

#import heapq
import math
#import fractions

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True

def main():
#    h,w,a,b = map(int, input().split())
    a,b=map(int,input().split())
    m=4
    k=1
    count=0

    if a>b:
        a,b=b,a
    sosu={1}
#    a = fractions.gcd(a,b)
    if a%2==0:
        sosu.add(2)
        while a%2==0:
            a//=2
    if a%3==0:
        sosu.add(3)
        while a%3==0:
            a//=3
#    print(d)
    c=math.sqrt(a)+1
 #   print(c)
    while m<=c and m!=1:
        if a%m==0:
            sosu.add(m)
            while a%m==0:
                a//=m

        m+=1
#    print(sosu)
    if a!=1:
        sosu.add(a)
#    print(sosu)

    for i in sosu:
        if b%i==0:
            count+=1
    print(count)
#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()
# Buggy code:
def gcd(x, y):
    if y == 0 :
        return x
    else:
        return gcd(y,x%y)
def prime(x):
    global  ans
    m = x ** (0.5)
    for i in range(2,int(m+1)):
        if x % i == 0 :
            while True:
                if x % i != 0 :
                    break
                else:
                    x = (x//i)
            ans +=1
    return ans
A,B = map(int,input().split())
t = gcd(A,B)
ans = 1
print(prime(t))


# Fixed code:
def gcd(x, y):
    if y == 0 :
        return x
    else:
        return gcd(y,x%y)
def prime(x):
    global  ans
    m = x ** (0.5)
    for i in range(2,int(m+1)):
        if x % i == 0 :
            while True:
                if x % i != 0 :
                    break
                else:
                    x = (x//i)
            ans +=1
    if x != 1 :
        ans += 1
    return ans
A,B = map(int,input().split())
t = gcd(A,B)
ans = 1
print(prime(t))
# Buggy code:
def gcd(a, b):
  if b==0:
    return a
  return gcd(b, a%b)

int main():
  a,b = map(int, input().split())
  g = gcd(a,b)
  N = int(g*0.5)
  ans = 1
  for i in range(2, N+1):
    flag = 0
    while(g%i==0):
      g /= i
      flag = 1
    ans += flag
  if g != 1:
    ans += 1
  print(ans)

main()

# Fixed code:
def gcd(a, b):
  if b==0:
    return a
  return gcd(b, a%b)

a,b = map(int, input().split())
g = gcd(a,b)
N = int(g**0.5)
ans = 1
for i in range(2, N+1):
  if g%i==0:
    ans += 1
  while(g%i==0):
    g /= i
if g != 1:
  ans += 1
print(ans)
# Buggy code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
  ans += b[i]
  if i <= n - 2:
    if a[i + 1] == a[i] + 1:
      ans += c[i - 1]
print(ans)

# Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  ans += b[i]
for i in range(n-1):
  if(a[i+1]-a[i] == 1):
    j = a[i]-1
    ans += c[j]

print(ans)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans=0
for i in range(N):
	ans+=B[A[i]]
	if A[i]==A[i-1]+1:
		ans+=C[A[i-1]]
print(ans)


# Fixed code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    ans = 0
    storage = -1
    for i in range(N):
        ans = ans + B[A[i] - 1]
        if storage + 1 == A[i]:
            ans = ans + C[storage - 1] 
        storage = A[i]
    print(ans)
main()
# Buggy code:
n = int(input())
a_lis = list(map(int,input().split()))
b_lis = list(map(int,input().split()))
c_lis = list(map(int,input().split()))

s = 0

for i in range(n):
  if a_lis[i+1] - a_lis[i] == 1:
    s += c_lis[a_lis[i]]
print(sum(b_lis)+s)

# Fixed code:
n = int(input())
a_lis = list(map(int,input().split()))
b_lis = list(map(int,input().split()))
c_lis = list(map(int,input().split()))
 
s = 0
 
for i in range(n-1):
  if a_lis[i+1] - a_lis[i] == 1:
    s += c_lis[a_lis[i]-1]
print(sum(b_lis)+s)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

Q = sum(B)
for i in range(N-1):
    if A[i+1] == A[i]+1:
        Q += C[A[i]]
        
print(Q)
        


# Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
s = sum(B)
for i in range(N-1):
    if (A[i] + 1) == A[i+1] :
        s = s + C[A[i]-1]
print(s)
# Buggy code:
N = int(input())
dishes = list(map(int, input().split()))
satisfaction = list(map(int, input().split()))
additional = list(map(int, input().split()))

res = 0

for i in range(N-1):
    res += satisfaction[i]

    if dishes[i] + 1 == dishes[i+1]:
        res += additional[dishes[i] - 1]
    
    print(res)

print(res + satisfaction[-1])




# Fixed code:
N = int(input())
dishes = list(map(int, input().split()))
satisfaction = list(map(int, input().split()))
additional = list(map(int, input().split()))

res = 0

for i in range(N-1):
    res += satisfaction[i]

    if dishes[i] + 1 == dishes[i+1]:
        res += additional[dishes[i] - 1]

print(res + satisfaction[-1])
# Buggy code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
num = -1
for i in range(n):
    ans += b[a[i] - 1]
    if num == a[i] - 2:
        ans += c[a[i] - 2]
    num = a[i] - 1
print(ans)


# Fixed code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
num = None
for i in range(n):
    ans += b[a[i] - 1]
    if num == a[i] - 2:
        ans += c[a[i] - 2]
    num = a[i] - 1
print(ans)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
bonus = 0
for i in  range(N):
  if A[i] + 1 == A[i+1]:
    bonus += C[A[i]-1]

    
print(sum(B)+bonus)

# Fixed code:
N = int(input())
A, B, C = [], [], []
A = list(map(int, input().split()))
B = list(map(int, input().split()))  
C = list(map(int, input().split()))

point = 0
point = sum(B)

for i in range(len(A)-1):
    if A[i+1] - A[i] == 1:
        point += C[A[i]-1]

print(point)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)

for i in range(N-1):
    if A[i] == A[i+1] - 1:
        print(str(A[i])+ " : " +str(A[i+1]))
        ans += C[A[i]-1]

print(ans)


# Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)

for i in range(N-1):
    if A[i]+1 == A[i+1]:
        #print(str(A[i])+ " : " +str(A[i+1]))
        ans += C[A[i]-1]

print(ans)
# Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=sum(b)
for i in range(len(a)-1):
  if a[i+1]-a[i]==1:
    x+=c[a[i]]
print(x)

# Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=sum(b)
for i in range(len(a)-1):
  if a[i+1]-a[i]==1:
    d=a[i]
    x+=c[d-1]
print(x)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
point = 0

for i in range(N):
  count+= B[A[i]]
  if i>0 and A[i] = A[i-1]:
    count += C[A[i-1]]
print(count)

# Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
point = 0

for i in range(N):
    point += B[A[i]-1]
    if i>0 and A[i]-1 == A[i-1]:
        point += C[A[i-1]-1]
print(point)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pt = 0
for i in range(N):
    pt += B[A[i]-1]
    if i > 1 and (A[i]-1) == A[i-1]:
        pt += C[i-2]
print(str(pt))

# Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pt = 0
for i in range(N):
    pt += B[A[i]-1]
    if i > 0 and (A[i]-1) == A[i-1]:
        pt += C[A[i-1]-1]
print(str(pt))
# Buggy code:
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))
B = list(map(lambda b: int(b), input().split(" ")))
C = list(map(lambda c: int(c), input().split(" ")))

satis = 0

for i in range(len(A)):
  satis += B[A[i]]
  if i >= 1 and A[i] - A[i-1] == 1:
    satis += C[i-1]

print(satis)

# Fixed code:
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))
B = list(map(lambda b: int(b), input().split(" ")))
C = list(map(lambda c: int(c), input().split(" ")))
 
satis = 0
 
for i in range(len(A)):
  satis += B[A[i] - 1]
  if i >= 1 and A[i] - A[i-1] == 1:
    satis += C[A[i - 1] - 1]
 
print(satis)
# Buggy code:
n = int(input())
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
cc = list(map(int,input().split()))
ans = 0
Cnum = 0
cur_a = 100
for a in aa:
    ans += bb[a-1]
    if a == cur_a+1:
        ans += cc[Cnum]
        Cnum += 1
    cur_a = a
print(ans)


# Fixed code:
n = int(input())
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
cc = list(map(int,input().split()))
ans = 0
Cnum = 0
cur_a = 100
for a in aa:
    ans += bb[a-1]
    if a == cur_a+1:
        ans += cc[cur_a-1]
        Cnum += 1
    cur_a = a
print(ans)
# Buggy code:
n = int(input())
a,b,c = list(map(int, input().split()))
ma=sum(b)
for i in range(0,n-1):
    if a[i+1]-a[i]==1:
        ma+=c[a[i]-1]
print(ma)

# Fixed code:
n = int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ma=sum(b)
for i in range(0,n-1):
    if a[i+1]-a[i]==1:
        ma+=c[a[i]-1]
print(ma)
# Buggy code:
n = int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
print(A[0])
ans=B[int(A[0])-1]

for i in range(1,n):
    if A[i-1]+1==A[i]:
        ans += B[int(A[i])-1]+C[int(A[i-1])-1]
    else:
        ans += B[int(A[i]-1)]
       
print(ans)

# Fixed code:
n = int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans=B[int(A[0])-1]

for i in range(1,n):
    if A[i-1]+1==A[i]:
        ans += B[int(A[i])-1]+C[int(A[i-1])-1]
    else:
        ans += B[int(A[i])-1]
       
print(ans)
# Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=sum(b)

for i in range(n-1):
  k=a[i]
  if a[i+1]==k+1:
    ans+=c[i]
  else:
    ans+=0
print(ans)

# Fixed code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)

for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans += c[a[i]-1]
print(ans)
# Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=0
for i in range(0,n-1):
  if a[i]=a[i+1]:
    x+=c[a[i]-1]
y=sum(b)
print(x+y)

# Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=0
for i in range(0,n-1):
  if a[i]+1==a[i+1]:
    x+=c[a[i]-1]
y=sum(b)
print(x+y)
# Buggy code:
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

ans=0
j=0
for i in range(n):
    r=a[i]-1
    if i > 0 and r == prev+1:
        ans+=b[r]+c[j]
        j+=1
    else :
        ans+=b[r]
    prev=r

print(ans)


# Fixed code:
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

ans=0
for i in range(n):
    r=a[i]-1
    if i > 0 and r == prev+1:
        ans+=b[r]+c[r-1]
    else :
        ans+=b[r]
    prev=r

print(ans)
# Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

m=0
for i in range(n):
  if a[i+1]==a[i]+1:
    m=m+c[i]

print(sum(b)+m)

# Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

m=0
for i in range(n-1):
  if a[i+1]==a[i]+1:
    m=m+c[a[i]-1]

print(sum(b)+m)
# Buggy code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

tmp = -1
sum = 0
for i in range(n):
    sum += b[i]
    if a[i] == tmp + 1:
        sum += c[i]
    tmp = a[i]
print(sum)

# Fixed code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

tmp = -1
sum = 0
for i in range(n):
    sum += b[i]
    if a[i] == tmp + 1:
        sum += c[tmp-1]
    tmp = a[i]
print(sum)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

manzoku = 0
for i in range(N):
    manzoku += B[A[i]-1]
    if i == N - 2 and A[i] + 1 == A[i + 1]:
        manzoku += C[A[i]-1]
print(manzoku)

# Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

manzoku = 0
for i in range(N):
    manzoku += B[A[i]-1]
    if i < N - 1 and A[i] + 1 == A[i + 1]:
        manzoku += C[A[i]-1]
print(manzoku)
# Buggy code:
n = int(input())
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
c = list(map(int,input().split(" ")))
m,j = [0,0]
for i in a:
    m += b[i-1]
    if i == j + 1:
        m += c[i-2]
    j = i
print(m)

# Fixed code:
n = int(input())
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
c = list(map(int,input().split(" ")))
m,j = [0,-1]
for i in a:
    m += b[i-1]
    if i == j + 1:
        m += c[j-1]
    j = i
print(m)
# Buggy code:
n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))

b_sum = sum(list_b)

satis = 0
for i in range(n-1):
  if list_a[i+1] == list_a[i] + 1:
    satis += list_c[i]

result = b_sum + satis
print(result)

# Fixed code:
n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))
 
b_sum = sum(list_b)
 
satis = 0
for i in range(n-1):
  if list_a[i+1] == list_a[i] + 1:
    satis += list_c[list_a[i]-1]
 
result = b_sum + satis

print(result)
# Buggy code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

answer = sum(B)
for i in range(len(B)):
  if B[i+1] = B[i]+1:
    answer += C[i]

print(answer)
  

# Fixed code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

answer = sum(B)
for i in range(len(A)-1):
  if A[i+1] == A[i]+1:
    answer += C[A[i]-1]

print(answer)
# Buggy code:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

def main(a_list, b_list, c_list):
    before_element = 999
    result = 0
    for element in a_list:
        result += b_list[element-1]
        print('b', result)
        if element == before_element + 1:
            result += c_list[before_element-1]
            print('c', result)
        before_element = element
    return result

print(main(a_list, b_list, c_list))

# Fixed code:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

def main(a_list, b_list, c_list):
    before_element = 999
    result = 0
    for element in a_list:
        result += b_list[element-1]
        if element == before_element + 1:
            result += c_list[before_element-1]
        before_element = element
    return result

print(main(a_list, b_list, c_list))
# Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=0
s += sum(b)
for i in range(n-1):
    if a[i]==a[i+1]+1:
        s += c[i-1]
print(s)

# Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
d = 0

b_sum = sum(b)
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        d = c[a[i]-1] + d

print(b_sum + d)
# Buggy code:
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=a[0]
for i in range(1,n):
  if a[i]==a[i-1]+1:
    s+=a[i]+c[i-1]
  else:
    s+=a[i]
print(s)

# Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=b[a[0]-1]
for i in range(1,n):
  if a[i]==a[i-1]+1:
    s+=b[a[i]-1]+c[a[i-1]-1]
  else:
    s+=b[a[i]-1]
print(s)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
res = 0
for i in range(N - 1):
    res += B[i]
    if A[i] + 1 == A[i + 1]:
		res += C[A[i] - 1]
print(res)


# Fixed code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
res = 0
for i in range(n - 1):
    res += B[i]
    if A[i] + 1 == A[i + 1]:
        res += C[A[i] - 1]
print(res + B[-1])
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

total = sum(B)

for i in range(N - 1):
    if A[i + 1] - A[i] == 1:
        total += C[i]

print(total)

# Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

total = sum(B)

for i in range(N - 1):
    if A[i + 1] - A[i] == 1:
        total += C[A[i] - 1]

print(total)
# Buggy code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
s=0
for i in range(N):
  s+=B[A[i]-1]
  if i>=1 and A[i]==A[i-1}+1:
    s+=C[i]
print(s)

# Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

satisfy = 0
for i in range(N):
    if A[i] == A[i - 1] + 1 and i >= 1:
        satisfy += C[A[i - 1] - 1]
    satisfy += B[A[i] - 1]
print(satisfy)
# Buggy code:
import math
a,b=map(int,input().split())
b=b-1
if a>b:
    c=0
else:
    c=math.ceil(b/a)
print(c)

# Fixed code:
import math
a,b=map(int,input().split())
if b==1:
    print(0)
else:
    if a>=b:
        c=1
    else:
        c=math.ceil((b-1)/(a-1))
    print(c)
# Buggy code:
s=list(map(int,input().split()))
a=0
if s[1]<=1:
  print(a)
else:
  while s[1]>0:
    a=a+1
    s[1]=s[1]-s[0]
    print(a)

# Fixed code:
s=list(map(int,input().split()))
a=0
b=s[0]-1
if s[1]==1:
  print(a)
else:
  a=a+1
  while s[1]>s[0]:
    a=a+1
    s[0]=s[0]+b
  print(a)
# Buggy code:
a,b=map(int,input().split())

result=a
count=1
while result =< b:
    result += a-1
    count += 1

print(count)

# Fixed code:
a,b=map(int,input().split())

result=1
count=0
while result < b:
    result += a-1
    count += 1

print(count)
# Buggy code:
A, B = [int(i) for i in input().split()]
result = 1
require_socket = B - A

if B == 1:
    print(0)
else:
    result += require_socket // A - 1
    if (require_socket / A - 1).is_integer() is False:
        result += 1

print(result)

# Fixed code:
A, B = [int(i) for i in input().split()]
result = 1
require_socket = B - A

result += require_socket // (A - 1)
if (require_socket / (A - 1)).is_integer() is False:
    result += 1

print(result)
# Buggy code:
A, B = map(int, input().split(" "))
if (B - 1) % A == 0:
    print((B - 1) // A)
else:
    print(((B - 1) // A) + 1)


# Fixed code:
A, B = map(int, input().split(" "))
if (B - 1) % (A - 1) == 0:
    print((B - 1) // (A - 1))
else:
    print(((B - 1) // (A - 1)) + 1)
# Buggy code:
x = input().split()
A, B = x[0], x[1]
n = 1
t = 0
while n <= B:
  n += A - 1
  t += 1
print(t)

# Fixed code:
x = input().split()
A, B = int(x[0]), int(x[1])
n = 1
t = 0
while n < B:
  n += A - 1
  t += 1
print(t)
# Buggy code:
A, B = map(int,input().split())
puragu = 1
if A >= B:
  print(1)
  exit()

result = 0

while puragu <= B:
  puragu += A-1
  result += 1

print(result)


# Fixed code:
A, B = map(int,input().split())
puragu = 1
if B == 1:
  print(0)
  exit()
if A >= B:
  print(1)
  exit()

result = 0

while puragu < B:
  puragu += A-1
  result += 1

print(result)
# Buggy code:
import math
A, B = map(int, input().split())
print(math.ceil((B - 1)//(A - 1)))


# Fixed code:
import math
A, B = map(int, input().split())

print(math.ceil((B -1) / (A - 1)))