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



Sample input:
3
3 1 2
2 5 4
3 6


Sample output:
14

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
   
if N == 1:
    print(sum(B))
else:
    try:
        k = A[-1]
        print(sum(B)+sum(C)-C[k-1])
    except(IndexError):
        print(sum(B)+sum(C))

Submission status: Wrong Answer

Solution code:

N = [int(s) for s in raw_input().split(" ")][0]
A = [int(s) for s in raw_input().split(" ")]
B = [int(s) for s in raw_input().split(" ")]
C = [int(s) for s in raw_input().split(" ")]

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

Submission status: Wrong Answer

Solution code:
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(x)
 
 
for k in range(len(y)):
  t = t + C[k]
print(t)

Submission status: Wrong Answer

Solution 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()))
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 dif_list:
   if m == 1:
    result += c_list[m -1]
print(result)

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = int(input())
        ans = 0
        lsta = list(map(int, input().split()))
        lstb = list(map(int, input().split()))
        lstc = list(map(int, input().split()))
        last = lsta[0]
        for i in range(n):
            ans += lstb[lsta[i]-1]
            if last + 1 == i:
                ans += lstc[last-1]
            last = lsta[i]
        print(ans)
    except:
        break

Submission status: Wrong Answer

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

manzokudo = 0
for B in Blist:
    manzokudo += B
    
for i in range(0, N-1):
    if Alist[i] == Alist[i+1]:
        print(Clist[i])
        manzokudo += Clist[Alist[i]]

print(manzokudo)

Submission status: Wrong Answer

Solution code:
a = int(input())
List_a=list(map(int,input().split()))
List_b=list(map(int,input().split()))
List_c=list(map(int,input().split()))
B = 0
C = 0
count = 0
key = 0
for i in List_a:
  B += List_b[i-1]
  if count > 0 and key+1 ==i:
    C += List_c[i-2]
  key = i
  count += 1
  print(B+C)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
score = 0
order = -1
for i in range(n):
  score += b[i]
  _order = a[i]
  if order+1 == _order:
    score += c[order - 1]
    order = _orderprint(score)

Submission status: Wrong Answer

Solution 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))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
   
if N == 2:
    print(sum(B)+sum(C))
elif N == 1:
    print(sum(B))
else:
    try:
        k = A[-1]
        print(sum(B)+sum(C)-C[k-1])
    except(IndexError):
        print(sum(B)+sum(C))

Submission status: Wrong Answer

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

point = 0
count = 0
temp = n + 1

for i, num in enumerate(a):
    point += b[num - 1]
    if num == temp + 1:
        point += c[count]
        count += 1
    temp = num

print(point)

Submission status: Wrong Answer

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

d = 0
for i in b:
  d += i

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

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = int(input())
        ans = 0
        last = lsta[0]
        lsta = list(map(int, input().split()))
        lstb = list(map(int, input().split()))
        lstc = list(map(int, input().split()))
        for i in range(n):
            ans += lstb[lsta[i]-1]
            if last + 1 == i:
                ans += lstc[last-1]
            last = lsta[i]
        print(ans)
    except:
        break

Submission status: Wrong Answer

Solution code:
n = int(input())

list = []

for i in range(3):
    str = input()
    strList = str.split()
    miniList = []
    for x in strList:
        miniList.append(int(x))
    list.append(miniList)

list[2].append(0)

end = 1
sum = 0
for i in list[0]:
    i -= 1
    sum += list[1][i]
    if end == n:
        break
    else:
        sum += list[2][i]
    end += 1

print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=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[np.where(dC==1)[0]-1].sum()
print(sb, sC)
print(sb+sC)

Submission status: Wrong Answer

Solution 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))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
manzoku = 0
prev = 0
 
for a in A:
  manzoku += B[a-1]
  if prev != 0 and prev != N:
    manzoku += C[prev-1]
  prev = a
print(manzoku)

Submission status: Wrong Answer

Solution code:
N = int(input())
foods = [int(i) for i in input().split()]
eff = sum([int(i) for i in input().split()])
plus = [int(i) for i in input().split()]
tmp = 0
for i, f in enumerate(foods):
  if i == 0:
    tmp = f
  elif f - tmp == 1:
    eff += plus[f-2]
    tmp = f
print(eff)

Submission status: Wrong Answer

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

a_sub = input().split(" ")
a = [int(n0) for n0 in a_sub]
# print(a)

b_sub = input().split(" ")
b = [int(n0) for n0 in b_sub]
# print(b)

c_sub = input().split(" ")
c = [int(n0) for n0 in c_sub]
# print(c)

score = 0
for xi in range(N):
    score = score + b[xi]

# print(score)

for xi in range(N-1):
    if a[xi+1]==a[xi]+1:
        score = score + c[a[xi]-1]
        print(xi, c[xi])
print(score)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

point = 0
count = 0

for i, num in enumerate(a):
    point += b[num - 1]
    temp = num
    if num == temp + 1:
        point += c[count]
        count += 1

print(point)

Submission status: Wrong Answer

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

manzokudo = 0
for B in Blist:
    manzokudo += B
    
for i in range(0, N-1):
    if Alist[i]+1 == Alist[i+1]:
        manzokudo += Clist[i-1]

print(manzokudo)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=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,0)

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

print(sb+sC)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
b = input().split()
c = input().split()

result = 0
j = 1
for i in a:
  m = int(i) - 1
  result += int(b[m])
  if not (m == 0) and (j + 1 == m):
      result += int(c[j])
  j = m
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
c = tuple(map(int,input().split()))
l = 30
ans = 0
for i in range(n):
    ans += b[a[i]-1]
    if l+1 == a[i]:
        ans += c[i-2]
    l = a[i]
print(ans)

Submission status: Wrong Answer

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

if A[N-1]!=len(A):
    print(np.sum(B)+np.sum(C)-C[A[N-1]-1])
else:
    print(np.sum(B)+np.sum(C))

Submission status: Wrong Answer

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

point = 0
count = 0

for i, num in enumerate(a):
    point += b[num - 1]
    if i == (len(a) - 1):
        point += c[count]
        count += 1

print(point)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
b = input().split()
c = input().split()

result = 0
j = 1
for i in a:
  m = int(i) - 1
  result += int(b[m])
  if not (m == 1) and (j + 1 == m):
      result += int(c[j])
  j = m
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))

A = [max(B)] * N

for n in range(N, 0, -1):
    if A[n-1] > B[n-2]:
        A[n-1] = B[n-2]
    if A[n-2] > B[n-2]:
        A[n-2] = B[n-2]
print(sum(A))

Submission status: Wrong Answer

Solution code:
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 A[i] - A[i-1] == 1:
        Sum += C[A[i] - 2]
print(Sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = 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>=1 and d[i]==(d[i-1]+1)):
        ans+=c[i-2]
print(ans)

Submission status: Wrong Answer

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

point = 0

for i, num in enumerate(a):
    point += b[num - 1]
    if i == (len(a) - 1):
        point += c[0]

print(point)

Submission status: Wrong Answer

Solution code:
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 = 1
cc = 0

for i in a:
    if tmp == i-1:
        cc = c[i-2]
    else:
        cc = 0
    sum += b[i-1]
    sum += cc
    tmp = i

print(sum)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
satisfy=0
b_i=0
for i in A:
    if i-b_i==1:
        satisfy=satisfy+B[i-1]+C[i-2]
    else:
        satisfy+=B[i-1]
    b_i=i
print(satisfy)

Submission status: Wrong Answer

Solution code:
a = int(input())
List_a=list(map(int,input().split()))
List_b=list(map(int,input().split()))
List_c=list(map(int,input().split()))
B = 0
C = 0
count = 0
key = 0
for i in List_a:
  B += List_b[i-1]
  if count > 0 and key + 1 ==i:
    C += List_c[i-1]
  key = i

Submission status: Wrong Answer

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

ans = 0
tmp = 0
for i in a:
	ans += b[i-1]
	print(ans)
	if i == tmp+1 and tmp != 0:
		ans += c[tmp-1]
	tmp = i

print(ans)

Submission status: Wrong Answer

Solution code:
#code
n=int(input())
a=input()
b=input()
c=input()
a=a.split()
b=b.split()
c=c.split()
a=list(map(int,a))
b=list(map(int,b))
c=list(map(int,c))
points=0
for i in range(len(a)):
    points+=b[a[i]-1]
    if( i!=0 and a[i-1]!=n):
        points+=c[a[i-1]-1]
    
print(points)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
P=0
P+=B[A[0]-1]
for i in range(N-1):
    if A[i]!=N:
        u=B[A[i+1]-1]
        q=C[A[i+1]-2]
        o=u+q
        P+=o
    elif A[i]==N:
        u=B[A[i+1]-1]
        P+=u
    
print(P)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
        
i = A[N-1]
if i != N:
  C.pop(i-1)

print(sum(B) + sum(C))

Submission status: Wrong Answer

Solution code:
a = int(input())

s = [input().split() for i in range(3)]

count =  0

num = s[0]
point = s[1]
bonus = s[2]


for p in range(int(len((num)))):
    count += int(point[int(num[p])-1])

for q in range(int(len(num))-1):
    if int(num[q+1]) - int(num[q]) == 1:
        count += int(bonus[q-1])
    
print(count)

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

print(m)

Submission status: Wrong Answer

Solution 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)+sum(C)
if A[-1] == N:
    pass
else:
    ans = ans - C[A[-1]-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
c = tuple(map(int,input().split()))
l = 30
ans = 0
for i in range(n):
    ans += b[a[i]-1]
    if l+1 == a[i]:
        ans += c[i-2]
    l = a[i]
    print(ans)

Submission status: Wrong Answer

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

ans = 0
tmp = -100
for i in a:
	ans += b[i-1]
	print(ans)
	if i == tmp+1:
		ans += c[tmp-1]
	tmp = i

print(ans)

Submission status: Wrong Answer

Solution code:
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 > 1 & A[i] - A[i-1] == 1:
        Sum += C[A[i] - 2]
print(Sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
count = 0
ins = 0
for i in A:
  count += B[i-1]
  if ins == i-1 and C[i-2]:
    count += C[i-2]
  ins = i
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

sati = 0
for (index, a) in enumerate(A):
    print("eat {}, sati: {}".format(a, B[a-1]))
    sati += B[a-1]

    if(index+1 < N and A[index]+1 == A[index+1]):
        sati += C[A[index]-1]

print(sati)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution 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)

Submission status: Wrong Answer

Solution 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)

Submission status: Wrong Answer

Solution code:
#B

n = int(input())

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

a.insert(0,0)
b.insert(0,0)
c.insert(0,0)
ans = 0

if a[n] == n:
    ans = sum(b) + sum(c)
else:
    ans = sum(b) + sum(c) - c[a[n]]
print(ans)

Submission status: Wrong Answer

Solution 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):
  if i==0:
    s+=b[0]
  elif a[i]==a[i-1]+1:
    s=s+b[i]+c[i-1]
  else:
    s=s+b[i]
print(s)

Submission status: Wrong Answer

Solution code:
import copy

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

bef = 0
ans = 0
for i in A:
    ans += B[i-1]
    if(bef + 1 == i):
        ans += C[i-2]
    bef = i
print(ans)

Submission status: Wrong Answer

Solution code:
print(int(input())**3)

Submission status: Wrong Answer

Solution code:
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:
        ans += C[pa]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = 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[d[i]-1];
    if(i>=1 and d[i]==(d[i-1]+1)):
        ans+=c[i-2]
print(ans)

Submission status: Wrong Answer

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

ans = 0
tmp = 0
for i in a:
	ans += b[i-1]
	if i == tmp+1:
		ans += c[tmp-1]
	tmp = i

print(ans)

Submission status: Wrong Answer

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

D = sum(B)

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

print(D)

Submission status: Wrong Answer

Solution code:
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]
    print(cnt)
    if (a[i]-1 == a[i-1])&(i!=0):
        cnt += c[a[i - 1]-1]
        print(cnt)
print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
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
    cost += B[index]
    if i != 0 and abs(A[i] - A[i-1]) == 1:
        cost += C[index - 1]

print(cost)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
foods = [int(i) for i in input().split()]
eff = sum([int(i) for i in input().split()])
plus = [int(i) for i in input().split()]
if foods[-1]-2 in plus:
  print(eff + plus[foods[-1]-2])
else:
  print(eff)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = sum(B)

for i in range(N-1):
  if A[i] < A[i+1]:
    s = A[i]-1
    cnt = cnt + C[s]
  
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=input().split()
A=[int(n) for n in A]
B=input().split()
B=[int(n) for n in B]
C=input().split()
C=[int(n) for n in C]
ans=0
ans+=sum(B)
ans+=sum(C)
if A[-1]-1!=len(C):
    ans-=C[A[-1]-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split())) # taberu order
b = list(map(int, input().split())) # get
c = list(map(int, input().split())) # renzoku
 
ans = 0
for i in range(n):
  po = a[i]
  ans += b[po-1]
 
for i in range(n-1):
  if(a[i] + 1 == a[i+1] ):
    ans += c[i]
    
print(ans)

Submission status: Wrong Answer

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

satisfaction = 0

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

print(satisfaction)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
eat = 0
mae = n
for i in a:
    eat += b[i-1]
    if mae < n:
        eat +=c[mae-1]
    mae = i
print(eat)

Submission status: Wrong Answer

Solution code:
N = int(input())

food_array = []
for i in range(3):
    food_array.append(list(map(int, input().split())))
#print(food_array)

A = food_array[0]
B = food_array[1]
C = food_array[2]

index = -1
count = 0
for i in A:
    count += B[i - 1]
    print(index, i)
    if index + 1 == i:
        count += C[index - 1]
    index = i
print(count)

Submission status: Wrong Answer

Solution 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, a in enumerate(A):
    ans += B[a-1]
    if a - A[i-1] == 1 and i-1 > 0:
        ans += C[i-2]
print(ans)

Submission status: Wrong Answer

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

ans = 0
bonus = 0
for a in A:
	ans += B[a-1]
	if bonus:
		ans += bonus
		bonus = 0
	if a != n:
		bonus = C[a-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
c = tuple(map(int,input().split()))
l = 30
ans = 0
for i in range(n):
    ans += b[i]
    if l+1 == a[i]:
        ans += c[i-1]
    l = a[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
foods = [int(i) for i in input().split()]
eff = sum([int(i) for i in input().split()])
plus = [int(i) for i in input().split()]
print(eff + plus[foods[-1]-2])

Submission status: Wrong Answer

Solution code:
while True:
    try:
        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 in range(1, len(A)):
            res += B[A[i]-1]
            if A[i-1] <= N - 1:
                res += C[A[i-1]-1]
        print(res)
    except:
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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()]
score=0
pre=0
pre_a=0

for i,a in enumerate(A):
    score+=B[a-1]
    if pre_a+1==a:
        score+=C[pre_a-1]
    pre=i
    pre_a=a
print(score)

Submission status: Wrong Answer

Solution 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[i]

Submission status: Wrong Answer

Solution code:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        A, B, C = [list(map(int, input().split())) for _ in range(3)]

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


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Wrong Answer

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

A_1 = A_list[0]-1
ans = B_list[A_1]
for i in range(1, N):
    A = A_list[i]-1
    ans += B_list[A]
    if A_1 < N-1:
        ans += C_list[A_1]
    A_1 = A
print(ans)

Submission status: Wrong Answer

Solution code:
while True:
    try:
        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 in range(1, len(A)):
            res += B[A[i]-1]
            if A[i-1]-1 < len(C):
                res += C[A[i-1]-1]
        print(res)
    except:
        break

Submission status: Wrong Answer

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

befo = -1
sat = 0
for i in range(N):
    index = A[i] - 1
    sat += B[index]
    if befo + 1 == index:
        sat += C[befo]
    befo = index

print(sat)

Submission status: Wrong Answer

Solution code:
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
adds = list(map(int, input().split()))

if dishes[-1] == n:
  print(sum(points) + sum(adds))
else:
  print(sum(points) + sum(adds) - adds[dishes[-1]-1])

Submission status: Wrong Answer

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

sat = 0
prev_ryouri = 0

for i in range(n):
  ryouri = A[i] - 1
  sat += B[ryouri]
  if prev_ryouri+1 == ryouri:
    sat += C[prev_ryouri]
    
  prev_ryouri = ryouri


print(sat)

Submission status: Wrong Answer

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

c.append(0)

ans = 0
ans += sum(b) + sum(c)
ans -= c[a[n-1]-1]
print(ans)

Submission status: Wrong Answer

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

satisfaction = 0

for i in range(N):
  satisfaction += B[i]
  if i != (N-1):
    satisfaction += C[i]

if A[N-1] != N:
  satisfaction -= C[A[N-1]-1]

print(satisfaction)

Submission status: Wrong Answer

Solution 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[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]+list(map(int, input().split()))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


lastEatIdx = -1
ans = 0
for eatIdx in A:
    ans += B[eatIdx]
    if eatIdx == lastEatIdx + 1:
        ans += C[lastEatIdx]
    lastEatIdx = eatIdx

print(ans)