Problem:
 Score : 200 points    Problem Statement Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1 , Dish 2 , \ldots , Dish N ) once.  The i -th dish (1 \leq i \leq N) he ate was Dish A_i .  When he eats Dish i  (1 \leq i \leq N) , he gains B_i satisfaction points.  Additionally, when he eats Dish i+1 just after eating Dish i  (1 \leq i \leq N - 1) , he gains C_i more satisfaction points.  Find the sum of the satisfaction points he gained.      Constraints  All values in input are integers.  2 \leq N \leq 20  1 \leq A_i \leq N  A_1, A_2, ..., A_N are all different.  1 \leq B_i \leq 50  1 \leq C_i \leq 50         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N  B_1  B_2  ...  B_N  C_1  C_2  ...  C_{N-1}       Output Print the sum of the satisfaction points Takahashi gained, as an integer.        Sample Input 1 3
3 1 2
2 5 4
3 6      Sample Output 1 14  Takahashi gained 14 satisfaction points in total, as follows:   First, he ate Dish 3 and gained 4 satisfaction points.  Next, he ate Dish 1 and gained 2 satisfaction points.  Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.        Sample Input 2 4
2 3 4 1
13 5 8 24
45 9 15      Sample Output 2 74       Sample Input 3 2
1 2
50 50
50      Sample Output 3 150

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
mae=-1
count = 0
for start in range(0,n):
  if mae>-1 and start<n and a[mae] + 1 == a[start]:
    count += b[a[start] - 1] + c[a[start] - 2]
  else:
    count+=b[a[start] - 1]
  mae+=1
print(count)

Solution (Python):
n=int(input())
a= list(map(int,input().split()))
a=[i-1 for i in a]
b= list(map(int,input().split()))
c= list(map(int,input().split()))

count=0
cook=-4
for i in a:
    if i==cook:
        count+=c[i-1]
    
    count+=b[i] 
    cook=i+1
    
print(count)

Solution (Python):
n = int(input())

A =        list( map(int, input().split()) )	
B =        list( map(int, input().split()) )	
C =        list( map(int, input().split()) )	

ans=0

x=-2
for a in A:
	a-=1
	ans+=B[a]
	if a==x+1:
		ans+=C[a-1]
	x=a

print(ans)

Solution (Python):
import sys


		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	cl = list(map(int, input().split()))
	
	ret=0
	pre=-10
	for i, v in enumerate(al):
		ret += bl[v-1]
		if pre == v -1:
			ret+=cl[v-2]
		pre=v
		
	print(ret)
	
	



if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):


N = int(input())

A = input().split()
B = input().split()
C = input().split()

score = 0
  
for a_str in A:
    a = int(a_str)
    score = score + int(B[a-1])

for i in range(len(A)-1):
    if int(A[i+1]) == int(A[i]) + 1:
        score = score + int(C[int(A[i])-1])
        continue
  
print(score)

Solution (Python):
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]-1]
      
  
      if i != 0:
        hantei = a[i-1] + 1
        if a[i] == hantei:
          ans += c[a[i]-2]
    
print(ans)

Solution (Python):

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

X = 0
for i in range(0,N):
    X += B[i]

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

print(X)

Solution (Python):
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
ans2 = 0

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split(' ')] 
B = [int(i) for i in input().split(' ')]
C = [int(i) for i in input().split(' ')]

s = 0
last = -2
for j in range(N):
    s += B[A[j]-1]
    if A[j] == last+1:
      s += C[last-1]
    last = A[j]
    
print(s)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

score=0
A.append([0])
C.append([0])

score = sum(B)

for i in range(N):

    if A[i]+1 == A[i+1]:

        score += C[A[i]-1]
    

    
print(score)

Solution (Python):
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 = point + b[i]

for i in range(1, N):
    if a[i] == a[i-1] + 1:
        point = point + c[ a[i-1]-1 ]

print(point)

Solution (Python):
n = int(input())

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

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

Solution (Python):
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))


prev = -1
satisfy = 0

for i in a:
    satisfy += b[i - 1]

    if i - prev == 1:
        satisfy += c[i - 2]

    prev = i

print(satisfy)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    res = B[A[0] - 1]
    for i, a in enumerate(A[1:]):
        res += B[a - 1]
        if A[i] + 1 == a:
            res += C[A[i] - 1]
    
    
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
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] - 1]
    
    
    if 0 < i and A[i] == A[i - 1] + 1:
        ans += C[A[i] - 2]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split(" ")))
B = list(map(int,input().split(" ")))
C = list(map(int,input().split(" ")))

def wei(N,A,B,C):
    r = 0
    c = 0
    C.insert(0,0)
    for i in A:
        r+=B[i-1]
        if i - c == 1:
            c = 1
            r+=C[i-1]
        c = i
    return r

print(wei(N,A,B,C))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

manzokudo = B[A[0] - 1]
for n in range(1, N):
  manzokudo += B[A[n] - 1]
  
  if A[n - 1] == A[n] - 1:
    manzokudo += C[A[n - 1] - 1]

print(manzokudo)

Solution (Python):
n = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
zs = list(map(int, input().split()))
b = None
r=0
for x in xs:
    if b==None:
        b=x
        continue
    if x == b+1:
        r+=zs[b-1]
    b=x
print(sum(ys) + r)

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
ans = 0
cnt = 0
for a in A:
    ans += B[a - 1]
    if cnt + 1 == a and cnt != 0:
        ans += C[a - 2]

    cnt = a

print(ans)

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

ans = 0
i_ = 20

for k in range(N):
    i = A[k] - 1
    ans += B[i - 1]
    if i == i_ + 1:
        ans += C[i_]
    
    i_ = i

print(ans)

Solution (Python):
n=int(input())
L=lambda:list(map(int,input().split()))
a,b,c=L(),L(),L()
s=b[a[0]-1]
for i in range(1,n):
  s+=b[a[i]-1]
  if a[i-1]+1==a[i]:s+=c[a[i]-2]
print(s)

Solution (Python):
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sum = 0
prev = b[0]
for i in range(0, len(a)):
	if i == 0:
		sum += b[a[i]-1]
		prev = a[i]
	else:
		if (a[i] == prev+1):
			sum += b[a[i]-1]
			sum += c[a[i]-2]
			prev = a[i]
		else:
			sum += b[a[i]-1]
			prev = a[i]

print(sum)

Solution (Python):
n = int(input())
a_i = input().split()
b_i = input().split()
c_i = input().split()
ans = 0
for i in range(n-1):
  ans += int(b_i[i])
  if int(a_i[i]) + 1 == int(a_i[i+1]):
    ans += int(c_i[int(a_i[i])-1])
ans += int(b_i[n-1])
print(ans)

Solution (Python):
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(0,n-1):
    
    if a[i+1] == (a[i] + 1):
        ans = ans + c[a[i]-1]
print(ans)

Solution (Python):
N = input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
old_a = 99

for i in range((len(A))):
  a = int(A[i])
  ans += B[a-1]
  if a - old_a == 1:
    ans += C[old_a-1]
  old_a = a
print(ans)

Solution (Python):
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(len(a)):
    ans +=b[a[i]-1]

    
    if(i != 0):

        if(a[i]-1 == a[i-1]):
            ans += c[a[i-1]-1]


print(ans)

Solution (Python):
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-1):
  if A[i+1]==A[i]+1:
    bonus+=C[A[i]-1]

print(sum(B)+bonus)

Solution (Python):
N = int(input())
  
A = list(map(int,input().split()))
A = [i-1 for i in A]
B = list(map(int,input().split()))
C = list(map(int,input().split()))

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

print(res)

Solution (Python):
n = int(input())
a = [ int(_) for _ in input().split() ]
b = [ int(_) for _ in input().split() ]
c = [ int(_) for _ in input().split() ]

a = [ _-1 for _ in a ]

ans = 0

for x in a:
	ans += b[x]
    
for j in range(len(a)-1):
	if a[j+1] == a[j] + 1:
		ans += c[a[j]]
        
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m = sum(b)
for i in range(0,n-1):
  if a[i]+1==a[i+1]:
    m += c[a[i]-1]
print(m)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.append(0)
C.append(0)

D = sum(B)

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

print(D)

Solution (Python):
N = int(input())
A = input().split(' ')
B = input().split(' ')
C = input().split(' ')

total = sum(int(b) for b in B)
pre_ai = -1
for i in range(1, N + 1):
    ai = int(A[i - 1])
    if ai == pre_ai + 1:
        total += int(C[pre_ai - 1])
    pre_ai = ai

print(total)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
score = sum(b)
for i in range(len(a)-1):
    if a[i]+1 == a[i+1]:
        score += c[a[i]-1]
print(score)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

m = 20
sum=0


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


print(sum)

Solution (Python):
N=int(input())
A=[int(s) for s in input().split()]
B=[int(s) for s in input().split()]
C=[int(s) for s in input().split()]


count=0
a=999
b=0
for i in range(0,N):
    b=A[i]-1
    count=count+B[b]
    if A[i]==a+1:
        count+=C[b-1]
    a=A[i]

print(count)

Solution (Python):






if __name__ == '__main__':
    tmp = 0
    a = 0
    counter = 0
    li = []
    a = int(input())
    li_1 = list(map(int, input().split()))
    li_2 = list(map(int, input().split()))
    li_3 = list(map(int, input().split()))

    for x in range(0, len(li_1) - 1):
        if li_1[x + 1] - li_1[x] == 1:
            li.append(li_1[x] - 1)

    tmp = 0
    for y in li_2:
        tmp += y

    for z in li:
        tmp += li_3[z]

    print(tmp)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
H = 0
H += B[A[0] - 1]
for i in range(1, N):
  H += B[A[i] - 1]
  if A[i] == A[i - 1] + 1:
    H += C[A[i - 1] - 1]
print(H)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
C.insert(0, 0)
ans = 0
pre = N

for _ in range(N):
  buf = A[_] - 1
  ans += B[buf]
  if buf == pre + 1:
    ans += C[buf]
  pre = buf

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

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

Solution (Python):
N = int(input())
lstA = list(map(int,input().split()))
lstB = list(map(int,input().split()))
lstC = list(map(int,input().split()))

plusC = 0
for i in range(len(lstA)-1):
    if (lstA[i] == N ):
        continue
    elif ( lstA[i] + 1 == lstA[i+1]):
        plusC += lstC[lstA[i]-1]
        

print (sum(lstB) + plusC )

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
csum=0
for i in range(n-1):
  if a[i]+1 == a[i+1]:
    csum = csum + c[a[i]-1]
  else:
    csum = csum

print(sum(b)+csum)

Solution (Python):
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(len(a)-1):
    if a[i+1] - a[i] == 1:
        ans += c[a[i]-1]
print(ans)

Solution (Python):


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):
    e = a[i] - 1
    m += b[e]
    if i > 0 and a[i - 1] == a[i] - 1:
        m += c[a[i - 1] - 1]

print(m)

Solution (Python):
n = int(input())
a = list(map(int,(input().split())))
b = list(map(int,(input().split())))
c = list(map(int,(input().split())))

score = 0
for i in range(n):
  score += b[a[i]-1]
  
  if (i != 0) and a[i] == a[i-1] + 1:
    score += c[a[i]-2]

  
print(score)

Solution (Python):
kind = int(input())
atLIST=[list(map(int,input().split())) for i in range(3)]

happy = 0
tmp = atLIST[0][0]
c=0
for i in range(kind):
		happy = happy + atLIST[1][i-1]
		if tmp == atLIST[0][i]-1:
				happy = happy + atLIST[2][tmp-1]
				c = c + 1
		tmp = atLIST[0][i]
print(happy)

Solution (Python):
n = int(input())
a_array = [int(x) for x in input().split()]
b_array = [int(x) for x in input().split()]
c_array = [int(x) for x in input().split()]

res = b_array[a_array[0] - 1]
now_a = a_array[0]
for i in range(1, n):
    res += b_array[a_array[i] - 1]
    if now_a + 1 == a_array[i]:
        res += c_array[a_array[i - 1]-1]
    now_a = a_array[i]
print(res)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = [i-1 for i in a]
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
now = 999
for i in a:
    if now+1 == i:
        ans += b[i] + c[i-1]
    else:
        ans += b[i]
    now = i
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
r = 0
for i, j in enumerate(a):
    r += b[j - 1]
    if a[i - 1] == a[i] - 1 and i > 0:
        r += c[j - 2]
print(r)

Solution (Python):
n = int(input())

a = list(map(int, input().split()))
b = input().split()
c = input().split()

sat = 0

ant = -10
for j in a:
    if ant+1 == j:
        sat += int(c[ant-1])
    
    sat += int(b[j-1])
    ant = j

print(sat)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
r = 0
for i, j in enumerate(a):
    r += b[j - 1]
    if a[i - 1] == a[i] - 1 and i > 0:
        r += c[j - 2]
print(r)

Solution (Python):
num = int(input())
order = list(map(int, input().split()))
content = list(map(int, input().split()))
add_content = list(map(int, input().split()))
base = sum(content)
add = 0
for i in range(len(order) - 1):
    if order[i] + 1 == order[i+1]:
        add += add_content[order[i] - 1]
print(add + base)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = B[A[0] - 1]
for i in range(1, N):
    a = A[i] - 1
    pa = A[i - 1] - 1
    ans += B[a]
    if 0 <= pa < N - 1 and a == pa + 1:
        ans += C[pa]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
AAA = list(map(int, input().split()))
BBB = list(map(int, input().split()))
CCC = list(map(int, input().split()))

n_satisfy = 0
for i, A in enumerate(AAA):
    B = BBB[A - 1]
    if i == 0:
        n_satisfy += B
    elif AAA[i - 1] + 1 != A:
        n_satisfy += B
    else:
        n_satisfy += B + CCC[A - 1 - 1]

print(n_satisfy)

Solution (Python):
N =int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.insert(0,-100)
ans = sum(B)
for i in range(N):
    if A[i+1]-1 == A[i]:
        ans += C[A[i]-1]

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

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

Solution (Python):
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(1,n+1):
    ans += b[a[i-1]-1]
    if i < n:
        if a[i] ==  a[i-1]+1 :
            ans += c[a[i]-2]
print(ans)

Solution (Python):
n=int(input())
a=input().split()
b=input().split()
c=input().split()
ans=0
ans+=int(b[int(a[0])-1])

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
result = 0
result += sum(B)
for i in range(N - 1):
    if A[i] < A[i + 1] and A[i+1] == A[i] + 1:
        aim = A[i] - 1 
        result +=C[aim]
        
print(result)

Solution (Python):
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

Solution (Python):


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
sum = 0

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

Solution (Python):
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))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
s = 0
for i in a:
  s += b[i-1] 
  if i -1 == a[a.index(i)-1] and a.index(i)>0:
    s+= c[i-2]
print(s)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ba = -1
ans = 0
for a in A:
	if ba + 1 == a:
		ans += C[ba-1]
	ba = a
print(sum(B)+ans)

Solution (Python):
N=int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

print(total)

Solution (Python):
N = int(input())
A = ([int(x) for x in input().split()])
B = ([int(x) for x in input().split()])
C = ([int(x) for x in input().split()])

Sat = 0
j = 0
for i in A:
    Sat += B[i-1]
    if (i - j == 1) & (j != 0):
        Sat += C[j-1]
    j = i

print(Sat)

Solution (Python):
num = int(input())
dish=[] 
while True:
    try:
        dish.append(list(map(int,input().split())))

    except:
        break;
        
cnt=0


for i in range(num):
    cnt= cnt+dish[1][i]
    

for i in range(0,num-1):
    if dish[0][i+1]-dish[0][i]==1:
        cnt = cnt+ dish[2][int(dish[0][i])-1]
       
     
    else:
        pass
print(cnt)

Solution (Python):
N = int(input())
A = ([int(x) for x in input().split()])
B = ([int(x) for x in input().split()])
C = ([int(x) for x in input().split()])

Sat = 0
j = 0
for i in A:
    Sat += B[i-1]
    if (i - j == 1) & (j != 0):
        Sat += C[j-1]
    j = i

print(Sat)

Solution (Python):
n = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
ans = 0

for i in range(1, n + 1):
    if i == n:
        break
    if As[i-1] + 1 == As[i]:
        ans += Cs[As[i-1] - 1]
ans += sum(Bs)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
score = 0
for i in range(n):
    score += b[ a[i]-1 ]
bonus = 0
for j in range(1,n):
    if a[j-1]+1 == a[j]:
        bonus += c[ a[j] -2 ]
print(score+bonus)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

cnt = 0
for i in range(N):
    cnt += b[a[i]-1]

for i in range(N-1):
    if a[i]+1 == a[i+1]:
        cnt += c[a[i]-1]

print(cnt)

Solution (Python):
c=0
n=int(input())
A_list=list(map(int,input().split()))
B_list=list(map(int,input().split()))
C_list=list(map(int,input().split()))
for i in range(0,n):
  c+=B_list[A_list[i]-1]
  if i==n-1:
    break
  if A_list[i]==(A_list[i+1]-1):
    c+=C_list[A_list[i]-1]
print(c)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

p = 0
prev = -1
for i in A:
    p += B[i-1]
    if i - prev == 1:
        p += C[prev-1]
    prev = i
print(p)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

p = 0
for i in range (n):
  
  
  p += b[a[i]-1]
  if i >= 1 and a[i]-1 == a[i-1]:
    
    ci = a[i-1]
    
    
    p += c[ci-1]
    
print(p)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
value = 0
for i in range(N):
  value += B[A[i]-1]
  if i > 0 and A[i] == A[i-1]+1:
    value += C[A[i-1]-1]
print(value)

Solution (Python):
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Clist = list(map(int, input().split()))

Alist.insert(0,0)
Blist.insert(0,0)
Clist.insert(0,0)

ans = 0

for i in range(1,N+1):
    ans = ans + Blist[Alist[i]]
    if i+1 < N+1:
        if Alist[i] +1  == Alist[i+1]:
            ans = ans + Clist[Alist[i]]

print(ans)

Solution (Python):
n = int(input())

grid = []
for i in range(3):
    array = list(map(int, input().strip().split()))
    grid.append(array)

k = sum(grid[1])
for i in range(n-1):
    if grid[0][i]+1 == grid[0][i+1]:
        k += grid[2][grid[0][i]-1]
        
print(k)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
value=0
last=100

for dish in A:
  value+=B[dish-1]
  if dish==last+1:
    value+=C[last-1]
  
  last=dish
  
print(value)

Solution (Python):
n = int(input(''))
a = [int(x) for x in str(input('')).split(' ')]
b = [int(x) for x in str(input('')).split(' ')]
c = [int(x) for x in str(input('')).split(' ')]

sat = sum(b)

for i in range (0, len(a)-1):
    if a[i]+1 == a[i+1]:
        sat += c[a[i]-1]
        
print(sat)

Solution (Python):
n=int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

addc = []
for i in range(n-1):
    if a[i+1] == a[i]+1:
        addc.append(c[a[i]-1])
ans = sum(b)+sum(addc)
print(str(ans))

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
 
t = 0
for i in B:
  t = t + i
  
y = []
for x in range(len(A)-1):
  if A[x] + 1 == A[x+1]:
    y.append(A[x]-1)
  else:
    pass
for k in y:
  t = t + C[k]
print(t)

Solution (Python):
n = 0
a = []
b = []
c = []

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sum = 0
tmp = 0
cc = 0

for m in range(n):
    i = a[m]
    if i-1 <=0:
        cc = 0
    elif tmp == i-1:
        cc = c[i-2]
    else:
        cc = 0
    sum += b[i-1]
    sum += cc
    tmp = i

print(sum)

Solution (Python):
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
result = sum(b_list)
dif_list = []
for i in range(n -1):
  if a_list[i + 1] == a_list[i] + 1:
    dif_list.append(1)
  else:
    dif_list.append(0)
for m in range(len(dif_list)):
   if dif_list[m] == 1:
    result += c_list[a_list[m] -1]
print(result)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

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

Solution (Python):
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=list(map(int,input().split()))
C=np.array(list(map(int,input().split())))

sb=sum(B)
dC=np.diff(A)

sC=C[A[np.where(dC==1)[0]]-1].sum()

print(sb+sC)

Solution (Python):
from itertools import tee


def pairwise(iterable):
    x, y = tee(iterable)
    next(y, None)
    return zip(x, y)


n = int(input())
a = tuple(map(int, input().split(" ")))
b = tuple(map(int, input().split(" ")))
c = tuple(map(int, input().split(" ")))

point = sum(b)
for i, j in pairwise(a):
    if j == i + 1:
        point += c[i - 1]

print(point)

Solution (Python):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
import math
import time
ts=time.time()
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n=I()
a=LI()
b=LI()
c=LI()
ans=sum(b)

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

Solution (Python):
n=int(input())
a=input().split()
b=input().split()
c=input().split()
ans=0

for x in range(len(b)):
  ans+=int(b[x])
  if x+1<len(b):
    if int(a[x])+1==int(a[x+1]):
      ans+=int(c[int(a[x])-1])
print(ans)

Solution (Python):
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
b=[0]+list(map(int,input().split()))
c=[0]+list(map(int,input().split()))
ans=0
for i in range(1,n+1):
    ans+=b[a[i]]
    if a[i]+1==a[i+1]:
        ans+=c[a[i]]
print(ans)

Solution (Python):
N = int(input())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_c = list(map(int,input().split()))
all = sum(l_b)
for i in range (N-1):
    if l_a[i+1] - l_a[i] == 1:
        all +=l_c[l_a[i]-1]
print(all)

Solution (Python):
N = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")


satisfaction = 0

for i in range(0, N):
  satisfaction += int(B[int(A[i])-1])
  if i == 0:
    continue
  if int(A[i]) - int(A[i-1]) == 1:
    satisfaction += int(C[int(A[i-1])-1])
    
print(satisfaction)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
an=0
before=0

for i in a:
    an+=b[i-1]

for j in range(n-1):
    if a[j]==(a[j+1]-1):
        an+=c[a[j]-1]

print(an)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

su = b[a[0] - 1]
for i in range(1, len(a)):
    su += b[a[i] - 1]
    if (a[i] == a[i - 1] + 1):
        su += c[a[i - 1] - 1]

print(su)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
tmp = 1000000000000
for i in range(N):
  ans += b[a[i]-1]
  if tmp - a[i] == -1:
    ans += c[a[i-1]-1]
  tmp = a[i]

print(ans)

Solution (Python):
N = int(input())
A = map(int, input().split())
B = list(map(int, input().split()))
C = list(map(int, input().split()))

satisf = 0
former = 20

for a in A:
    satisf += B[a-1]
    if a - 1 == former:
        satisf += C[a-2]
    former = a

print(satisf)

Solution (Python):
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):
    num = a[i] -1
    point += b[num]
    
    j = i -1
    
    if a[i] == a[j]+1 and a[i] > a[j] and j >=0:
        
        k = a[i] - 1 - 1 
        point += c[k]
    
print(point)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
cost = 0

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

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
man=0
prev=100
for i in range(n):
    man+=b[a[i]-1]
    if a[i]==(prev+1):
        man+=c[prev-1]
    prev=a[i]
print(man)

Solution (Python):
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):
    if i > 0:
        if (a[i] - a[i-1]) == 1:
            ans += c[a[i]-2]

print(ans)

Solution (Python):
import sys
import re

N = sys.stdin.readline() 
A = (sys.stdin.readline()).split()
B = (sys.stdin.readline()).split()
C = (sys.stdin.readline()).split()

j=0
result = 0

for i in A:
  i = int(i)
  result += int(B[i-1])
  
  if j != 0 and j+1 is i:
    result += int(C[j-1])
  j = i
  

print (result)

Solution (Python):
N = int(input())
a = [int(i) - 1 for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

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

print(ans)