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:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    res = 0
    prev = None
    for a in A:
        res += B[a-1]
        if prev == a-1:
            res += C[a-2]
        prev = a
    print(res)
    return


# Generated by 1.1.5 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:
def solve(a, b, c):
	ret = 0

	for i in range(len(a)):
		ret += b[a[i]-1]

		if i != 0:
			if a[i] == a[i-1] + 1:
				ret += c[a[i-1]-1]

	return ret

def main():
	n = int(input())

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

	print (solve(a,b,c))

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n = I()
    a = LI_()
    b = LI()
    c = LI()
    r = 0
    for i in range(n):
        r += b[a[i]]
        if i < n-1:
            if a[i] + 1 == a[i+1]:
                r += c[a[i]]

    return r


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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    a_list = LI()
    b_list = LI()
    c_list = LI()

    base = 0
    add = 0
    past = -10
    for i in range(N):
        a = a_list[i]
        base += b_list[a-1]
        if a == past + 1:
            add += c_list[past-1]
        past = a
    print(add+base)
solve()

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

temp = -1
score = 0

for i in a:
    score += b[i-1]
    if i == temp+1:
        score += c[temp-1]
    temp = i
    
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 = sum(B)
pa = -1
for a in A:
    if a - pa == 1:
        ans += C[pa-1]
    pa = 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()))
a = 0

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

print(a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s,p=0,-2
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
for i in a:
    s+=b[i-1]
    if p-i==-1:s+=c[i-2]
    p=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()))

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans = 0
    pre = -INF
    for a in A:
        ans += B[a-1]
        if pre == a-1:
            ans += C[pre-1]

        pre = a
    # 最後
    print(ans)

    return


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:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))
    prev = A[0]
    ans = B[A[0]-1]
    for i in range(1,N):
        if A[i]-1 == A[i-1]:
            ans += C[A[i-1]-1]
        ans += B[A[i]-1]
    print(ans)

if __name__ == "__main__":
    main()

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

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

mzoku=0
before=999

for al in alist:
    mzoku+=blist[al-1]
    if before==al-1:
        mzoku+=clist[before-1]
    before=al

print(mzoku)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    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()]

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

    print(s)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

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
p=-100
for i in A:
	ans+=B[i-1]
	if (p+1)==i:
		ans+=C[p-1]
	p=i

print(ans)

Submission status: Accepted

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

    ret = sum(B)
    for i, i1 in zip(A, A[1:]):
        if i1 == i + 1:
            ret += C[i - 1]
    print(ret)


main()

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(len(B)):
    ans+=B[i]

for i in range(len(A)-1):
    if A[i]+1==A[i+1]:
        p=A[i]-1
        ans+=C[p]

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans=0
    pre=-1
    for i,(a,b) in enumerate(zip(aa,bb)):
        ans+=b
        if a==pre+1:
            ans+=c[a-2]
        pre=a
    print(ans)

main()

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

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

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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

ans = 0
tmp = -2
for i in range(N):
    if A[i]-1 == tmp + 1:
        ans += B[A[i]-1] + C[A[i]-2]
    else:
        ans += B[A[i]-1]
    tmp = 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):
    ind = a[i] - 1
    ind_next = a[i+1] - 1
    if ind + 1 == ind_next:
        ans += c[ind]
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 = -100
for i in range(n):
    now = A[i] - 1
    ans += B[now]
    if (now - prev) == 1:
        ans += C[prev]
    
    prev = now

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, C):
    ans = 0
    pa = -2
    for a in A:
        ans += B[a-1]
        if pa == a-1:
            ans += C[a-2]
        pa = a
    return ans


def main():
    N = read_int()
    A = read_int_n()
    B = read_int_n()
    C = read_int_n()
    print(slv(N, A, B, C))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

ans = 0
for i in range(N):
    k = As[i]
    ans += Bs[k-1]
    if i < N-1 and As[i+1] == k+1:
        ans += Cs[k-1]

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

ans = 0
pre_order = -10
for aa in a:
    ind = aa - 1
    ans += b[ind]
    if ind - pre_order == 1:
        ans += c[pre_order]
    pre_order = ind
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] == 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
pre = -1
for a in A:
  ans += B[a-1]
  if a==pre+1:
    ans += C[pre-1]
  pre = a
  
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 = sum(B)
p = -1
for i,a in enumerate(A):
    if p+1==a:ans += C[p-1]
    p = a
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(el) for el in input().split(' ')]
B = [int(el) for el in input().split(' ')]
C = [int(el) for el in input().split(' ')]

total = 0
last = 100
for a in A:
    total += B[a-1]
    if last == a - 1:
        total += C[last-1]
    last = a
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 += B[A[i]-1]
    if i > 0 and A[i] == A[i-1] + 1:
        ans += C[A[i]-2]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
ans=sum(lb)
for i in range(1,n):
    if la[i]==la[i-1]+1:
        ans+=lc[la[i-1]-1]
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):
  x = a[i]
  x = x-1
  ans += b[x]
  if i<N-1:
    if a[i]+1 == a[i+1]:
      ans += c[x]
print(ans)

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()))
ret = b_list[a_list[0] - 1]
for i in range(1, n):
    if(a_list[i] == a_list[i-1] + 1):
        ret += c_list[a_list[i] - 2]
    ret += b_list[a_list[i] - 1]
print(ret)

Submission status: Accepted

Solution code:
N = int(input())
As = [0] + list(map(int, input().split()))
Bs = [0] + list(map(int, input().split()))
Cs = [0, 0] + list(map(int, input().split()))
ans = Bs[As[1]]
for i in range(2, N+1):
  ans += Bs[As[i]]
  if As[i] == As[i-1] + 1:
    ans += Cs[As[i]]
print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
b_list=list(map(int,input().split()))
c_list=list(map(int,input().split()))
pre=100
ans=0
for x in a_list:
    if x==pre+1:
        ans+=c_list[x-2]
    ans+=b_list[x-1]
    pre=x
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a)-1 for a in input().split()]
ans = sum([int(a) for a in input().split()])
C = [int(a) for a in input().split()]
for i in range(1, N):
    if 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()))
tmp = -1000
ans = 0
for i in range(n):
    j = a[i] - 1
    if tmp + 1 == j:
        ans += b[j] + c[tmp]
    else:
        ans += b[j]
    tmp = j
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC140 B

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))
r = sum(Bs)
for i in range(1, N):
  if As[i] == As[i-1]+1:
    r += Cs[As[i-1]-1]
print(r)

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

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
pa = -100
for a in A:
    s += B[a-1]
    if a == pa + 1:
        s += C[pa-1]
    pa = a
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=0
buf=-2
for i in range(n):
    x=a[i]-1
    s+=b[x]
    if x==buf+1:
        s+=c[buf]
    buf=x
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
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:

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


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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    ans = sum(B)
    prev = -1
    for a in A:
        if a == prev + 1:
            ans += C[a - 2]
        prev = 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()))

res = 0
pre = -10
for a in A:
    a -= 1
    res += B[a]
    if pre == a - 1:
        res += C[pre]
    pre = a

print(res)

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


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

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

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Accepted

Solution code:
import sys
import collections
import copy
import math
def input(): return sys.stdin.readline().strip()
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 = 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):
    cur = a[i]
    ans += b[a[i]-1]
    if i < n-1 and a[i+1] == cur+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):
    if i == 0:
        ans += b[a[0]-1]
    else:
        if a[i-1] + 1 == a[i]:
            ans += b[a[i]-1] + c[a[i]-2]
        else:
            ans += b[a[i]-1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
food = list(map(int, input().split(" ")))
one = list(map(int, input().split(" ")))
sec = list(map(int, input().split(" ")))
cnt = 0
for i in range(N-1):
  cnt += one[food[i]-1]
  if food[i+1] == food[i]+1:
    cnt += sec[food[i]-1]
cnt += one[food[N-1]-1]
print(cnt)

Submission status: Accepted

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

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

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

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=[[int(i) for i in input().split()] for j in range(3)]
manzoku=0
prev=0
for n,a in enumerate(A):
  b=a-1
  if n!=0:
    if b==prev+1:
      manzoku+=C[b-1]
  manzoku+=B[b]
  prev=b
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(' ')))

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

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

Submission status: Accepted

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

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

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 >= 1:
        if a[i] - a[i - 1] == 1:
            score += c[a[i - 1] - 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 = B[A[0] - 1]

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

print(ans)

Submission status: Accepted

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

total = 0
prev = -2
for a in A:
    total += B[a]
    if prev + 1  == a:
        total += C[a-1]
    prev = a
print(total)