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()))
before = 10**3
ans = 0
for i in A:
    if i - before == 1:
        ans += C[before-1]
    before = i
ans += sum(B)
print(ans)

Submission status: Accepted

Solution code:
# yorikatu_58_a.py
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
for i in range(n):
    ans += b[a[i]-1]
    if i < n-1 and 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
for i in range(n-1):
    ans += b[a[i]-1]
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]
ans += b[a[-1]-1]

print(ans)

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
b = readints()
c = readints()
ans = 0
for i in range(n):
    ans += b[a[i]-1]
# print(ans)
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        # print(a[i])
        #print('c', c[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()))

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

print(ans)

Submission status: Accepted

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

  ans = 0
  prev = -2
  for x in a:
    x -= 1
    ans += b[x]
    if prev + 1 == x:
      ans += c[prev]
    prev = x
  print(ans)
  return

if __name__ == "__main__":
  resolve()

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = 0
    pre = -1
    for i in range(n):
        res += B[A[i] - 1]
        if pre + 1 == A[i]:
            res += C[pre - 1]
        pre = A[i]
    print(res)


if __name__ == '__main__':
    resolve()

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
for i in range(n):
    ans += b[i]
    if i == 0:continue
    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 = sum(b)
pre_idx = -1
pre_val = -1
for idx, val in enumerate(a):
    if pre_idx == -1:
        pre_idx = idx
        pre_val = val
    else:              # pre_idx != -1:
        if pre_val == val  - 1:
            ans = ans + c[pre_val - 1]
            pre_idx = idx
            pre_val = val
        else:
            pre_idx = idx
            pre_val = val   
        
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()))
ab = 21
m = 0
for i in a:
    m += b[i-1]
    if i == ab + 1:
        m += c[i-2]
    ab = i
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()))
sum = 0

for i in range(len(a)):
  num = a[i]-1
  sum += b[num]
  if i >= 1 and a[i]-a[i-1] == 1:
    tmp = a[i]-2
    sum += c[tmp]
else:
  print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(n):
    ans += B[A[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()))
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,B,C=[list(map(int,input().split())) for i in range(3)]
satisfaction=0
for i in range(N):
    satisfaction+=B[A[i]-1]
    if i!=0 and A[i]==A[i-1]+1:
        satisfaction+=C[A[i-1]-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()))
sum, hoge = 0, 100
for i in range(n):
    sum += b[a[i]-1]
    if hoge + 1 == a[i]:
        sum += c[hoge-1]
    hoge = a[i]
print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
U=list(map(int,input().split()))

goukei=0

before=1000
for i in range(N):
    goukei+=T[S[i]-1]
    if before+1==S[i]:
        goukei+=U[S[i]-2]
    
    before=S[i]
    
print(goukei)

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 actual(n, A, B, C):
    bonus_point = 0

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

    return sum(B) + bonus_point

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


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

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
a = LI()
a = list(map(lambda x: x - 1, a))
b = LI()
c = LI()

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

t = 1000000000
lis = list()
for i in A:
    lis.append(B[i-1])
    #print(i,t)
    if i == t + 1:
        lis.append(C[i-2])
    t = i

print(sum(lis))

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

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

print(sum(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()))
 
ans = sum(b)
for i in range(1,n):
    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()))

ans = sum(b)
for i in range(1,n):
    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()))
sum_satisfaction = sum(b)

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    eat = list(map(int, input().split()))
    heal = list(map(int, input().split()))
    plus = list(map(int, input().split()))
    ans = 0
    for i in range(N-1):
        if eat[i+1] - eat[i] == 1:
           ans += plus[eat[i]-1]
    print(sum(heal) + ans)
resolve()

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()))
sts = 0
for i in range(n):
    sts += B[A[i] - 1]
    if 0 < i and A[i] - A[i-1] == 1:
        sts += C[A[i] - 2]
print(sts)

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

Submission status: Accepted

Solution code:
def linp():return list(map(int,input().split()))
n=int(input())
a=linp()
b=linp()
c=linp()
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-1]-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()))

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:
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = [0] + list(map(int, input().split()))
    B = [0] + list(map(int, input().split()))
    C = [0] + list(map(int, input().split()))

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

    print(ans)


if __name__ == '__main__':
    solve()

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

print(score)

Submission status: Accepted

Solution code:
import sys
import decimal # 10進法に変換，正確な計算

def input():
    return sys.stdin.readline().strip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    keep = n
    sum = 0
    for i in a:
        sum += b[i-1]
        if i == keep + 1:
            sum += c[i-2]
        keep = i
    print(sum)

    
    
main()

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
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):
    # 食べた料理
    k = A[i] - 1
    # 得た満足度
    ans += B[k]
    # 追加満足度の判定
    if i < N-1 and A[i] == A[i+1]-1:
        ans += C[k]

print(ans)

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    a=map(int,input().split())
    b=list(map(int,input().split()))
    c=list(map(int,input().split()))
    m = 0
    prev = -100
    for i in (x-1 for x in a):
        m += b[i]
        if prev + 1 == i:
            m += c[prev]
        prev = i
    return m

if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    a=map(int,input().split())
    b=list(map(int,input().split()))
    c=list(map(int,input().split()))
    m = 0
    prev = -100
    for i in (x-1 for x in a):
        m += b[i]
        if prev + 1 == i:
            m += c[prev]
        prev = i
    return m

if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

ans = 0
for i in range(N):
    ans+= int(B[i])

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

Submission status: Accepted

Solution code:
N,  *_ABC,  = map(int, open(0).read().split())

A = _ABC[:N]
B = _ABC[N: 2*N]
C = _ABC[2*N:]

ans = 0

for i, a in enumerate(A):
    ans += B[a-1]

    if i != len(A)-1 and A[i+1] == a + 1:
        ans += C[a-1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a, b, c = [list(map(int, input().split())) for i in[0]*3]
ans = b[a[0]-1]
prev = a[0]
for i in range(1, n):
    ans += b[a[i]-1]
    if prev+1==a[i]:
        ans += c[prev-1]
    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=0
for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
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()) )

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

print( sum(b)+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()))

total = 0
p = -1

for i in a:
    total += b[i-1]
    
    if p + 1 == i:
        total += c[i-2]
        
    p = i
    
print(total)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
total = sum(b)
for i in range(n-1):
    if a[i] + 1 == a[i+1]:
        total += c[a[i] - 1]
print(total)

Submission status: Accepted

Solution code:
import collections
n = int(raw_input())
ais = map(int, raw_input().split(' '))
bis = map(int, raw_input().split(' '))
cis = map(int, raw_input().split(' '))


c = 0
q = collections.deque([])
for a in ais:
	c += bis[a - 1]
	if q:
		p = q.popleft()
		if p + 1== a - 1:
			c += cis[p]
	q.append(a - 1)

print c

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    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] == a[i - 1] + 1:
            ans += c[a[i - 1] - 1]

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    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 in range(1, n):
    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()))

A = [0] + A
B = [0] + B
C = [0] + C

ans = 0
for i, a in enumerate(A[1:-1]):
    i = i+1 
#    print(i, A[i], A[i+1])
#    print(B[a])
    ans += B[a]
    if A[i+1] - A[i] == 1:
#        print('C', C[a])
        ans += C[a]
ans += B[A[-1]]
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
readline = sys.stdin.readline
A = [int(i)-1 for i in readline().split()]
B = [int(i) for i in readline().split()]
C = [int(i) for i in readline().split()]

ans = 0
a_prev = -100
for a in A:
    ans += B[a]
    if a == a_prev+1:
        ans += C[a-1]
    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()))
count = 0
bonus = 0
for i in a:
    count += b[i-1]
    if i == bonus:
        count += c[i-2]
    bonus = i+1
print(count)

Submission status: Accepted

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()
B = rl()
C = rl()

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

Submission status: Accepted

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

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

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()]
ans = sum(b)
for i, j in zip(a, a[1:]):
    if i+1 == j:
        ans += c[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()))
count = sum(B)

for x in range(len(A)):
    if x != len(A) - 1:
        if A[x] + 1 == A[x + 1]:
            count += C[A[x]-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()))

ans = 0
a.append(0)

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

print(ans)

Submission status: Accepted

Solution code:
# ABC 140

N = int(input())
A = [int(a)-1 for a in input().split()]
B = [int(a) for a in input().split()]
C = [int(a) for a in input().split()]
m =0
l = N + 10
for a in A:
    m+=B[a]
    if l+1 == a:
        m+=C[l]
    l=a
print(m)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0
tmp = -1

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

Submission status: Accepted

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

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

ans = 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:
pre=-1
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=[0]+list(map(int,input().split()))
ans=0
prec=0
for  a,b in zip(al,bl):
    ans+=b
    if pre+1==a:ans+=cl[pre]
    pre=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()]
r=0
for i in range(1,len(a)):
    if a[i]-a[i-1] == 1:
        r+=c[a[i-1]-1]
print(sum(b)+r)

Submission status: Accepted

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    _ = int(readline())
    As = list(map(int, readline().split()))
    Bs = list(map(int, readline().split()))
    Cs = list(map(int, readline().split()))

    ans = 0
    for a, a_next in zip(As, As[1:]):
        ans += Bs[a-1]
        if a_next - a == 1:
            ans += Cs[a-1]
    ans += Bs[As[-1]-1]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

S = 0

for i in range(N):
    S += B[i]
    try:
        if A[i+1] == A[i]+1:
            S += C[A[i]-1]
    except IndexError as e:
        continue

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=0

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

#print(sum(b))
print(sum(b)+ 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()))
count = 0
back = 0
for i in range(0, n):
  count += b[a[i]-1]
  if back+1 == a[i] and back != 0:
    count += c[a[i]-2]
  back = a[i]
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()))

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
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:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
memo = -100
for i in range(N):
  dish = A[i]
  base = B[dish - 1]
  ans += base
  if dish - memo == 1:
    ans += C[dish - 2]
  memo = dish
  
    
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(" ")))

buffer = 0
sati = 0

for i in A:
  sati += B[i - 1]
  if buffer == 0:
    buffer = i
    continue
  elif buffer == i - 1:
    sati += C[buffer -1]
  buffer = i
print(sati)

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

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

s = sum(B)
s += sum([C[a1 - 1] for a1, a2 in zip(A, A[1:]) if a2 - a1 == 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()))
takashi=b[a[0]-1]
for i in range(1,n):
    takashi+=b[a[i]-1]
    if a[i]-a[i-1]==1:
        takashi+=c[a[i-1]-1]

print(takashi)

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    B = il()
    C = il()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
n=n0()
a=[0]
a.extend(n1())

b=[0]
b.extend(n1())
c=[0]
c.extend(n1())

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

Submission status: Accepted

Solution code:
def buffet(n, ali, bli, cli):

    ans = 0
    count = 10**5

    for i in range(n):
        ans += bli[ali[i]-1]

        if ali[i] == count+1:
            ans += cli[count-1]
        count = ali[i]
    return ans

def main():
    n = int(input())
    ali = list(map(int, input().split()))
    bli = list(map(int, input().split()))
    cli = list(map(int, input().split()))
    print(buffet(n, ali, bli, cli))

if __name__ == '__main__':
    main()

Submission status: Accepted

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