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: Accepted

Solution 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+=c[a[i]-1]

print(s)

Submission status: Accepted

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 and A[i+1]==A[i]+1:
        u=B[A[i+1]-1]
        q=C[A[i+1]-2]
        o=u+q
        P+=o
    else:
        u=B[A[i+1]-1]
        P+=u
    
print(int(P))

Submission status: Accepted

Solution code:
# a.py
# N = int(input()) #ここで標準入力
# # print (type(N),N) 

# print(N*N*N)
#### ##################
# b.py
man=0
N = int(input()) #ここで標準入力
A = [input().split() for i in range(3)]
# print(A)
# B全部たす
for i in range(N):
   man=man+int(A[1][i])
   # if (i!=N):

#例外処理
for i in range(N-1):
   # if(A[0][i]<=A[0][i+1]):    # 食べる順が i -> i+1 の時
   if(int(A[0][i+1]) == int(A[0][i])+1):
      # print(man)
      ryori_i=int(A[0][i])
      man_c=int(A[2][ryori_i-1])
      man=man+man_c
      # print (cn)

print(man)

Submission status: Accepted

Solution code:
# -*- coding:utf-8-*-
"""
1~Nの料理がある
{Ai}は実際に食べた順番である。
{Bi}はiを食べたときに得られる満足度である。
{Ci}はiを食べた直後にi+1を食べたときに得られる追加の満足度である。
"""
# 入力
N=int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

manzoku=0

pre_dish = None
for ai in A:
    ai_index = ai-1
    manzoku += B[ai_index]
    if pre_dish == ai-1: # 前に食べたものがai-1
        pre_dish_index=pre_dish-1
        manzoku += C[pre_dish_index]
        pre_dish = ai
    else:
        pre_dish = ai

print(manzoku)

Submission status: Accepted

Solution code:
n = int(input())
a_s = [int(v) for v in input().split()]
b_s = [int(v) for v in input().split()]
c_s = [int(v) for v in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

total = 0

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

print(total)

Submission status: Accepted

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(0,N-1):
    sum += B[A[i]-1]
    if A[i] == A[i+1] - 1:
        sum += C[A[i]-1]
sum += B[A[N-1]-1]
print(sum)

Submission status: Accepted

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


s = 0
before = -1

for i in a:
    s += b[i-1]
    if i == before + 1:
        s += c[before-1]
    before = i

print(s)

Submission status: Accepted

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(len(A)):
  sum += B[A[i]-1]
  if i != len(A)-1:
    if A[i+1]-A[i] == 1:
      #print(C[i])
      sum += C[A[i]-1]
      
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
eat_list = list(map(int,input().split()))
scores = list(map(int,input().split()))
c_list = list(map(int,input().split()))
"""
print(eat_list)
print(scores)
print(c_list)
"""

score = 0
for i_eat,eat in enumerate(eat_list):
    score += scores[eat-1]
    #print(i_eat,eat,score)
    if i_eat == 0:
        continue
    elif eat - 1 == eat_list[i_eat-1]:
        score += c_list[eat-2]
        #print("分岐",i_eat,eat,score)

print(score)

Submission status: Accepted

Solution code:
n = int(input())
a = [input().split() for l in range(3)]
mnpk = 0
fl = 0
for i in range(n):
  b = int(a[0][i]) - 1
  mnpk = mnpk + int(a[1][b])
  if fl == 1:
    if int(a[0][i-1]) == b:
      mnpk = mnpk + int(a[2][b-1])
  else:
    fl = 1

print(mnpk)

Submission status: Accepted

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

point = []
for i in range(len(A)):
    ryori = A[i]
    point.append(B[ryori - 1])
    if i >  0 :
        if ryori - A[i - 1] == 1:
            point.append(C[ryori - 2])
    

print(sum(point))

Submission status: Accepted

Solution code:
N = int(input())
order = list(map(int, input().split(' ')))
Bs = list(map(int, input().split(' ')))
Cs = list(map(int, input().split(' ')))
old = None
ans = 0
for i in order:
    index = i - 1
    if old != None and old + 1 == index:
        ans += Cs[old]
    ans += Bs[index]
    old = index
        
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
num = int(input())
A = input().split(" ")
B = input().split(" ")
C = input().split(" ")
result = 0
 
for i in range(num):
  result += int(B[int(A[i])-1])
  if i > 0 and (int(A[i]) - int(A[i-1]) == 1):
    result += int(C[int(A[i])-2])
 
print(result)

Submission status: Accepted

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()))
sum = 0
before_target = 0
for i in range(n):
    target = a_list[i]
    if i != 0 and before_target+1 == target :
        sum += b_list[target - 1] + c_list[target - 2]
    else:
        sum += b_list[target - 1]
    before_target = target

print(sum)

Submission status: Accepted

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 = sum(B)
for i in xrange(N):
    # res += B[A[i]-1]
    if i > 0 and A[i] == A[i-1]+1:
        # print(A[i], C[A[i-1]-1])
        res += C[A[i-1]-1]
print(res)

Submission status: Accepted

Solution code:
n=int(input())
alist=list(map(int, input().split()))
blist=list(map(int, input().split()))
clist=list(map(int, input().split()))
manzoku=sum(blist)
for i in range(n-1):
    if alist[i+1]==alist[i]+1:
        manzoku+=clist[alist[i]-1]
print(manzoku)

Submission status: Accepted

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

#print(N,A,B,C)

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

  
print(sum(B)+k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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)

diff = [a[i+1] - a[i] == 1 for i in range(n-1)]
diff.append(False)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...
B =        list( map(int, input().split()) )	# 1 2 3 4 5 ...
C =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

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)

Submission status: Accepted

Solution code:
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
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

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):
      #print(i)
      ans += b[a[i]-1]
      #print("ans",ans)
  #print("aaa",a[i])
      if i != 0:
        hantei = a[i-1] + 1
        if a[i] == hantei:
          ans += c[a[i]-2]
    
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

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

Submission status: Accepted

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(' ')]

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]
    # a = sum([B[i - 1] for i in A])
    # c = sum([C[i - 1] for i, j in zip(A[:-1], A[1:]) if i == j - 1])
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる
b = list(map(int, input().split()))
c = list(map(int, input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(B)+bonus)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# if __name__ == '__main__':
#     a = int(input())
#     if a == 1:
#         print(1)
#     else:
#         print(pow(a, 3))
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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
for i in range(n):#012
    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)

Submission status: Accepted

Solution code:
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]
        #minusC = lstC[lstA[N-1]-1]

print (sum(lstB) + plusC )

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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
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 ('DEBUG ' + str(score) + ' : ' + str(c[i-1]) + ' : ' + str(i))
  
print(score)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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(len(A)):
    sum += B[i]
    if i > 0 and A[i-1] + 1 == A[i]:
        sum += C[A[i-1]-1]
print(sum)

Submission status: Accepted

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 and a == pa + 1:
        ans += C[pa]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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)
memo = A[0]
for i in range(1,N):
	if memo == A[i]-1:
		ans += C[memo-1]
		
	memo = A[i]
print(ans)

Submission status: Accepted

Solution code:
#Buffet

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)

Submission status: Accepted

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 > 0 and (A[i]-1) == A[i-1]:
        pt += C[A[i-1]-1]
print(str(pt))

Submission status: Accepted

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

Submission status: Accepted

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()]
ba = -1
ans = 0
for a in A:
	if ba + 1 == a:
		ans += C[ba-1]
	ba = a
print(sum(B)+ans)

Submission status: Accepted

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

Submission status: Accepted

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

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)

Submission status: Accepted

Solution code:
num = int(input())
dish=[] #appendのために宣言が必要
while True:
    try:
        dish.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。
cnt=0
#print(dish)
#print(dish[1][0])
for i in range(num):
    cnt= cnt+dish[1][i]
    
#print(cnt)
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]
       # print(dish[2][i-1])
     
    else:
        pass
print(cnt)