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 = 0
t = 99
for i in a:
  if t+1 == i:
    s += c[t-1]
  s += b[i-1]
  t = 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()))
count=sum(B)
for i in range(N-1):
    if A[i]+1==A[i+1]:
        count=count+C[A[i]-1]
print(count)

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()))
satisfy = sum(B)

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

print(satisfy)

Submission status: Accepted

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

v = 0


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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans=sum(B)
    for i in range(N-1):
        if A[i+1]==A[i]+1: ans+=C[A[i]-1]
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, A, B, C)

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 = sum(B)
for i, j in zip(A, A[1:]):
    if j == i+1:
        ans += C[i-1]
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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()]

ans = B[A[0]-1]
for i in range(1,N) :
    ans += B[A[i]-1]
    if A[i] - A[i-1] == 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()))
ans=0
for i in range(n):
    a_i=a[i]
    b_i=b[i]
    ans+=b_i
    if i<n-1:
        if a[i+1]-a_i==1:
            ans+=c[a_i-1]
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(input())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
c = list(map(int, stdin.readline().split()))
ans = sum(b)
for i in range (n-1):
    if a[i]+1 == a[i+1]:
        t = a[i]-1
        ans +=c[t]
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(0,N-1):
    if A[i]+1 == A[i+1]:
        s = s+C[A[i]-1]
print (s)

Submission status: Accepted

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

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()))
print(sum(B)+sum(C[A[i]-1] for i in range(N-1) if A[i]==(A[i+1]-1)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

x = sum(B)
for a,b in zip(A,A[1:]):
    if b == a+1:
        x += C[a-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()))

add = 0

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

total = sum(b) + add

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()))
C.append(0)
m = sum(B)
for i in range(N-1):
  if A[i]+1 == A[i+1]:
    m = m+C[A[i]-1]
print(m)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  As = list(map(int, input().strip().split()))
  Bs = list(map(int, input().strip().split()))
  Cs = list(map(int, input().strip().split()))
  score = 0
  for i in range(len(As)):
    score += Bs[As[i]-1]
    if i > 0 and As[i-1] != n and As[i-1] + 1 == As[i]:
      score += Cs[As[i-1]-1]
  print(score)

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	ans = 0
	A = LI()
	B = LI()
	C = LI()
	pre = -1
	for a in A:
		if(pre+1 ==a):
			ans += B[a-1]+C[a-2]
		else:
			ans += B[a-1]
		pre = a

	print(ans)

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

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

print(scr)

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=0
for i in range(N):
  m+=B[A[i]-1]
for i in range(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()))

ans=B[A[0]-1]
buf=A[0]

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

print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline().rstrip())
a = [None] + [int(x) for x in sys.stdin.readline().split()]
b = [None] + [int(x) for x in sys.stdin.readline().split()]
c = [None] + [int(x) for x in sys.stdin.readline().split()]

def main():
    res = 0
    for i in range(1, n+1):
        j = a[i]
        res += b[j]
        if a[i-1] == j - 1:
            res += c[j-1]
    
    return res
    
if __name__ == '__main__':
    ans = main()
    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=sum(b)
for i in range(n-1):
  if a[i+1]==a[i]+1:
    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
b_n=-2
for i in range(n):
  num=a[i]-1
  ans+=b[num]
  if num==b_n+1:
    ans+=c[b_n]
  b_n=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()))
sum = 0

A.append(0)

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#python3

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = sum([int(i) for i in input().split()]) 
    c = [int(i) for i in input().split()]
    for i in range(len(a)-1):
        if a[i] + 1 == a[i+1]:
            ans += c[a[i]-1]  
    print(ans)
main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

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

s = b[a[0] - 1]

for i in range(1, n):
    s += b[a[i] - 1]
    if (a[i] - a[i - 1]) == 1:
        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()))

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 = [a - 1 for a in map(int, input().split())]
b = list(map(int, input().split()))
c = list(map(int, input().split()))

satisfy = 0
prev = 10000

for i in a:
    if prev + 1 == i:
        satisfy += b[i] + c[i-1]
    else:
        satisfy += b[i]
    prev = i

print(satisfy)

Submission status: Accepted

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

ans = 0
prev = 100000
for a in A:
    if prev + 1 == a:
        ans += B[a] + C[a - 1]
    else:
        ans += B[a]

    prev = 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()))
man=0
cnt=0
while cnt<N:
    man+=b[a[cnt]-1]
    if cnt<N-1:
        
        if a[cnt+1]-a[cnt]==1:
            man+=c[a[cnt]-1]
    cnt+=1
print(man)

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 a[i]-a[i-1] == 1 and i > 0:
        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()))
total=0
for i in range(N):
    total+=B[i]

for j in range(N-1):
    if (A[j])+1==A[j+1]:
        total+=C[A[j]-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()))

ans=0
beforeN=-1
for i in range(N):
  ans += B[A[i]-1]
  #print(ans)
  #print(A[i]-beforeN)
  if A[i]-beforeN==1:
    ans += C[A[i]-2]
  beforeN=A[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()))
sum = 0

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc140/tasks/abc140_b

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()]
e = 0
last = -1
for ax in a:
    e += b[ax - 1]
    if ax == last + 1:
        e += c[last - 1]
    last = ax
print(e)

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=0
for i in a:
    m+=b[i-1]
for i in range(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()))
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())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))

ans=0
dish=al[0]
ans+=bl[dish-1]
bef_dish=dish
for i in range(1,n):
    dish=al[i]
    ans+=bl[dish-1]
    if dish== bef_dish+1:
        ans+=cl[bef_dish-1]
    bef_dish=dish
print(ans)

Submission status: Accepted

Solution code:
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    result = sum(B)

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


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()))
s=sum(b)
for x in range(len(a)-1):
    if a[x+1]-a[x]==1:
        s+=c[a[x]-1]
print(s)

Submission status: Accepted

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

score=b[a[0]-1]

for i in range(1,n):
    if a[i]==a[i-1]+1:
        score+=b[a[i]-1]+c[a[i]-2]
    else:
        score+=b[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()))
ans = 0
x = -1
for i in a:
    ans += b[i-1]
    if i == x + 1:
        ans += c[i-2]
    x = 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()))
ans=0
for i in range(0, N):
    ans+=B[A[i]-1]
    if i>0 and A[i]-A[i-1]==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()))

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

for j in range(N):
  total = total + B[j]

for i in range(N):
  if i > 0 and A[i] == A[i-1] + 1:
    total = total +C[A[i-1]-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()))
ans=0
for i in range(N):
  ans = ans + B[A[i] - 1]
  if i > 0 and A[i] == A[i-1] + 1:
    ans = ans + C[A[i-1] - 1]
print(str(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 = sum(b)

for i, j in zip(a[1:], a[:-1]):
    if i - j == 1:
        ans += c[i-2]
        
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()
C = LIST()

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

print(sum(B) + su)

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

Submission status: Accepted

Solution code:
import sys

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

for i in range(number):
    answer += b[a[i]-1]
    
    if i != 0:
        if a[i-1] == a[i]-1:
            answer += c[a[i-1]-1]

print(answer)

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()))
glad=0

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

for i in range(N):
    glad+=B[i]

print(glad)

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

sem_result = sum(b_list)
for i in range(n-1):
    if a_list[i+1] - a_list[i] == 1:
        sem_result += c_list[a_list[i] - 1]

print(sem_result)

Submission status: Accepted

Solution code:
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

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

Submission status: Accepted

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()]
#ここまで入力
manzoku = 0
for i in range(n):
    manzoku += b[a[i]]
    if i ==0:
        continue
    if a[i] == a[i-1]+1:
        manzoku += c[a[i]-1]
print(manzoku)

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 = b[a[0]-1]
for i in range(1, n):
    point += b[a[i]-1]
    if a[i] - a[i-1] == 1:
        point += c[a[i-1]-1]

print(point)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
score = list(map(int,input().split()))
add = list(map(int,input().split()))
sum = sum(score)

for i in range(n-1):
  if l[i+1] - 1 == l[i]:
    sum += add[l[i]-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 = 0
for i in range(N):
    ans = B[i] + ans
for i in range(N-1):
    if A[i+1] == A[i]+1:
        ans = C[A[i]-1] + ans
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a, b, c = [list(map(int, input().split()))for i in range(3)]

ans = 0
prev = -1
for i in range(n):
    ans += b[i]
    if(prev+1==a[i]): ans += c[a[i]-2]
    prev = a[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()))
ans=int(0)
for i in range(N):
  ans+=B[A[i]-1]
  if i>=1 and A[i-1]+1==A[i]:
    ans+=C[A[i-1]-1]
  else:
    continue
print(ans)

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

ans = 0

for i in range(n):

	ans += b[a[i]-1]

	if i > 0 and a[i] == a[i-1] + 1:
		ans += c[a[i-1]-1]
print(ans)

Submission status: Accepted

Solution code:
import sys

[N] = [int(x) for x in sys.stdin.readline().split(" ")]

As = [int(x) - 1 for x in sys.stdin.readline().split(" ")]
Bs = [int(x) for x in sys.stdin.readline().split(" ")]
Cs = [int(x) for x in sys.stdin.readline().split(" ")]

prev = -999
result = 0
for i in range(N):
    a = As[i]
    result += Bs[a]
    if a == prev+1:
        result += Cs[prev]
    prev = a

print(result)

Submission status: Accepted

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

d = {}
for i in A:
    d[i] = B[i-1]

before = -1
ans = 0
for i in A:
    ans+=d[i]
    if i-before==1:
        ans += C[i-2]
    before = i

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
U1 = list(map(int,input().split()))
U2 = list(map(int,input().split()))
Ut = 0
for j in A:
    Ut += U1[j-1]
i = 0
while i < N-1:
    x = A[i:i+1]+A[i+1:i+2]
    if (x[1] - x[0]) == 1:
        Ut += U2[x[0]-1]
    i += 1
print(Ut)

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, pp, np = 0, -1, 0
for i in range(n):
    np = a[i]
    p += b[np - 1]
    if np == pp + 1:
        p += c[pp - 1]
    pp = np
print(p)

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += bl[al[i]-1]
    if 1 <= i and al[i] == al[i-1]+1:
        ans += cl[al[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()))

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

print(Satisfaction)

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

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

Submission status: Accepted

Solution code:
n = int(input())
a_array, b_array, c_array = [list(map(int, input().split())) for _ in range(3)]
c_array.append(0)

sum = 0

for m in a_array:
    sum += b_array[m-1]

for i in range(n-1):
    if (a_array[i] + 1 == a_array[i+1]):
        sum += c_array[a_array[i]-1]

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
A, B, C = [input().split() for i in range(3)]
A = [int(num) for num in A]
B = [int(num) for num in B]
C = [int(num) for num in C]
A.insert(0,0)
B.insert(0,0)
C.insert(0,0)
p = 0
for i in range(1,N+1):
  p += B[A[i]]
  if A[i-1] == A[i] - 1:
    p += C[A[i-1]]
print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans=0
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.append(0)
for i in A:
    ans+=B[i-1]
for i in range(N-1):
    if A[i]+1==A[i+1]:
        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()))
s,f=0,-1
for x in a:
  s+=b[x-1]
  if x-f==1:
    s+=c[f-1]
  f=x
print(s)

Submission status: Accepted

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

ans = 0
p = -99999
for ind, i in enumerate(a):
  ans += b[i]
  if ind != 0:
    if i-1 == p:
      ans += c[i-1]
  p = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    r=sum(B)
    for i in range(N-1):
        if A[i+1]-A[i]==1:
            r+=C[A[i]-1]
    return r


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    print(solve(N, A, B, C))

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()))
ttl = sum(b)
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ttl += c[a[i]-1]
print(ttl)

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 = 0
for num in b:
    s += num

for i in range(len(a)-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()))

ans = 0
before = -9

for i in a:
  ans += b[i - 1]
  if before + 1 == i:
    ans += c[before - 1]
  before = 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()))

s = 0
o = a[0]
for i in a:
	s += b[i-1]
	if i-o == 1:
		s += c[o-1]
	o = 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()))
x = 0
for i in range(n):
    x += b[a[i]-1]
    if i!=0 and a[i-1]==a[i]-1:
        x += c[a[i]-2]
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()))
b_dic = {}
for i in range(1, N + 1):
  b_dic[i] = B[i - 1]
c_dic = {}
for i in range(1, N):
  c_dic[i] = C[i - 1]
count=0
br = -1
for a in A:
  count += b_dic[a]
  if br == a - 1:
    count += c_dic[br]
  br = a
print(count)

Submission status: Accepted

Solution code:
_ = input()
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
C = tuple(map(int, input().split()))
AA = tuple(zip(A, A[1:]))
CC = {(i,i+1):c for i, c in enumerate(C, 1)}
print(sum(B) + sum(CC.get(aa, 0) for aa in AA))

Submission status: Accepted

Solution code:
N = input()
A = [int(t)-1 for t in raw_input().split()]
B = map(int, raw_input().split())
C = map(int, raw_input().split())

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

result=0

for i in range(n):
    if i > 0:
        j=A[i]
        result+=B[j-1]
        if A[i] == A[i-1]+1:
            result += C[j-2]
    else:
        j=A[i]
        result+=B[j-1]

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

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

c_count=0

ans=0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input().rstrip())
Idxs = [int(x) for x in input().rstrip().split()]
Bs = [int(x) for x in input().rstrip().split()]
Cs = [int(x) for x in input().rstrip().split()]

ret = 0
prev = -100
for idx in Idxs:
    ret += Bs[idx-1]
    if idx-1 == prev:
        ret += Cs[prev-1]
    prev = idx
print(ret)

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

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

print(answer)

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()))
happiness = 0
memory = 100
for i in range(N):
  happiness += B[A[i]-1]
  if memory + 1 == A[i]:
    happiness += C[A[i]-2]
  memory = A[i]
print(happiness)

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()))
d=0
ab=0
for i in range(N):
  d+=b[a[i]-1]
  
  if i != 0:
    if ab+1==a[i]:
      d+=c[ab-1]
   
  ab=a[i]
    
print(d)