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:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)


n = inn()
a = inl()
b = inl()
c = inl()
sum = 0
for i in range(n):
    sum += b[a[i-1]-1]
    if i<n-1 and a[i+1]==a[i]+1:
        sum += c[a[i]-1]
print(sum)

Submission status: Accepted

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

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

a.insert(0, -1)
b.insert(0, -1)
c.insert(0, -1)

#print(a)
#print(b)
#print(c)

f = 0
for i in range(1,n+1):
    taste_a = a[i]
#    print("taste: "+str(taste_a))
    f += b[taste_a]
#    print("full: "+str(f))
    
    if a[i]-a[i-1] == 1:
#        print(str(i-1)+"番目の後に"+str(i)+"番目を食べました")
        f += c[taste_a-1]

print(f)

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

for i in range(n):
#    print("\n i: " + str(i))
    idx = a[i] - 1
#    print('idx: ' + str(idx))
    ans += b[idx]
#    print('ans: ' + str(ans))
    if i > 0 and idx == prev + 1:
        ans += c[prev]
    prev = idx
#    print('prev: ' + str(prev))

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


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

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_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

base = sum(b_list)

bouns = 0
pre = -10
for index, a in enumerate(a_list):
    if index > 0:
        if a - pre == 1:
            bouns += c_list[pre - 1]
    pre = a

print(base + bouns)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()] # input:"1 2 3 4 5"
B = [int(i) for i in input().split()] # input:"1 2 3 4 5"
C = [int(i) for i in input().split()] # input:"1 2 3 4 5"

ans=0
ans += B[A[0]-1]
tmp = A[0]

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

res = 0
for ai in range(len(A)):
    if ai == 0:
        res += B[A[ai] -1]
    else:
        res += B[A[ai] -1]
        if A[ai-1] +1 == A[ai]:
            res += C[A[ai-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()))

ans = 0
pre = None
for ai in a:
    ans += b[ai - 1]
    if pre is not None and pre + 1 == ai:
        ans += c[ai - 2]
    pre = ai

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

Submission status: Accepted

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    n = int(input())
    order = list(map(int, input().split()))
    points = list(map(int, input().split()))
    bonus = list(map(int, input().split()))
    last_one = -10
    ans = 0

    for x in order:
        if last_one + 1 == x - 1:
            ans += bonus[last_one]

        last_one = x - 1
        ans += points[x-1]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(lambda x: int(x) - 1, 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]]
    if i < N - 1 and A[i + 1] == A[i] + 1:
        ans += C[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()))
p = 0
l = -1
for a in A:
    p += B[a-1]
    if a-l == 1:
        p += C[l-1]
    l = a
print(p)

Submission status: Accepted

Solution code:
#coding utf-8
N=int(input())
A=list(map(int,input().split())) 
B=list(map(int,input().split())) 
C=list(map(int,input().split())) 
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:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

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

value = 0
tmp = A[0]
for i in A[1:]:
    if (tmp+1 == i):
        value += C[tmp-1]
    tmp = i
    

value += sum(B)
print(value)

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

def solve():
    m = A.pop(0)
    ans = B[m-1]
    for i, a in enumerate(A):
        ans += B[a-1]
        if a == m + 1:
            ans += C[m-1]
        m = a
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n = int(input())
li_a = list(map(int,input().split()))
li_b = list(map(int,input().split()))
li_c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if i==0:
    ans += li_b[li_a[0]-1]
    continue
  else:
    ans += li_b[li_a[i]-1]
    if li_a[i-1] + 1 == li_a[i]:
      ans += li_c[li_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 = -1
ans = 0
for i in range(n):
  manzoku = B[A[i]-1]
  if prev+1 == A[i]:
    manzoku += C[prev-1]
  prev = A[i]
  ans += manzoku
print(ans)

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

print(ans)

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
def calc(n, a, b, c):
    r = 0

    pre_x = -2
    for x in a:
        r += b[x-1]
        if pre_x + 1 == x:
            r += c[x-2]
        pre_x = x

    return r


n = int(input())  # 2-20
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

r = calc(n, a, b, c)
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()))

rslt = 0
before = -1
for i in a:
  if before == i - 1:
    rslt += b[i-1] + c[i-2]
  else:
    rslt += b[i-1]
  
  before = i

print(rslt)

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

Submission status: Accepted

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

ans = b[a[0]-1]

for i in range(1, n):
  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:
def main():
    N = int(input())
    A = [int(number) for number in input().split()]
    B = [int(number) for number in input().split()]
    C = [int(number) for number in input().split()]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
foods = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

satisfaction = 0
previous_food = -1

for food in foods:
    satisfaction += B[food-1]
    if food == previous_food+1:
        satisfaction += C[previous_food-1]
    previous_food = food

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

Submission status: Accepted

Solution code:
n = int(input())
sum = 0
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
for i in range(n):
    sum += b_list[a_list[i] - 1]
for i in range(n-1):
    if a_list[i+1] == a_list[i] + 1:
        sum += c_list[a_list[i]-1]
print(sum)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(a)-1 for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [int(c) for c in input().split()]

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    ABC = [list(map(int, input().split())) for _ in range(3)]
    A = ABC[0]
    B = ABC[1]
    C = ABC[2]

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

    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()))
m=sum(B)
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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

res = 0
tmp = n
for i in range(n):
    a_ = a[i]
    res += b[a_ - 1]
    if a_ == tmp + 1:
        res += c[tmp - 1]
    tmp = a_

print(res)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# import random
# import bisect
# import math
import numpy as np
# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def make_divisors(n):
    # divisors = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            # divisors.append(i)
            return i
            # if i != n // i:
            #     divisors.append(n//i)


def n_to_10(X, n):
    if int(X / n):
        return n_to_10(int(X / n), n) + str(X % n)
    return str(X % n)


def main():
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = int(input())
    a = ip.IL()
    b = ip.IL()
    c = ip.IL()
    memo = a[0]
    ans = 0
    for i in range(1, n):
        if memo + 1 == a[i]:
            ans += c[memo-1]
        memo = a[i]
        # print(i, ans)
    print(sum(b) + 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()]
S=0
for x in range(0,N):
    S=S+B[A[x]-1]
    if x!=N-1:
        if A[x]==A[x+1]-1:
            S=S+C[A[x]-1]
print(S)

Submission status: Accepted

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

result = sum(B)

for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    result += C[A[i]-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 = 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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

manz = 0

for i, _ in enumerate(A):
    manz += B[A[i]-1]
    if i >= 1 and A[i] == A[i-1]+1:
        manz += C[A[i]-2]
        
print(manz)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = [val - 1 for val in A]
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] == 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()))
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:
#B
n = int(input())

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

ans = 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]

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()]
z=0
i_old = -100
for i in a:
    z += b[i-1]
    if i == (i_old + 1):
        z += c[i_old-1]
    i_old = i
print(z)

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

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

ans = 0
pred = -1
for a in A:
    ans += B[a-1]
    if (a-1) == pred:
        ans += C[pred-1]
    pred = 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()]
score=0
pre=0
pre_a=-100
for i,a in enumerate(A):
    score+=B[a-1]
    if pre_a+1==a:
        score+=C[pre_a-1]
    pre=i
    pre_a=a
print(score)

Submission status: Accepted

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

A = [i-1 for i in A]

for ind,i in enumerate(A):
  value += B[i]
  if ind != N-1:
    if A[ind+1] == i+1:
      value += C[i]
    
print(value)

Submission status: Accepted

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

M = 0
M += sum(B)
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 = 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()))
result = 0
for i in range(N-1):
    if A[i]+1 == A[i+1]:
        result += C[A[i]-1]
    else:
        None
print(sum(B)+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,j in zip(a,a[1:]):
    ans += b[i-1]
    if j == i + 1:
        ans += c[i-1]
print(ans + b[a[-1]-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=input().split()
b=input().split()
c=input().split()
for i in range(n):
    a[i]=int(a[i])
    b[i]=int(b[i])
for i in range(n-1):
    c[i]=int(c[i])
b1=sum(b)
for i in range(n):
    if i<n-1 and a[i+1]==a[i]+1:
        s=a[i]-1
        b1+=c[s]
print(b1)

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

Submission status: Accepted

Solution code:

n = int(input())

an = list(map(lambda x :int(x)-1, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))


ans = 0
before = n+1
for i in range(n):
    ans += bn[an[i]]

#    print( (before,an[i]))
    if before + 1 == an[i]:
#        print(cn[an[i]-1])
        ans += cn[ before ]

    before = an[i]
#    print((ans,before))

print(ans)

Submission status: Accepted

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

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

print(bonus+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 = 0
prev = -2
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:
n=int(input())
#L=list(map(int,input().split()))
#a,b=map(int,input().split())
#A=[[0 for i in range()] for j in range()]
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)
#data_list = [ list(map(int,input().split(" "))) for i in range(3)]

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
A = LI()
B = LI()
C = LI()

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())
order = list(map(int,input().split()))
satisfaction = list(map(int,input().split()))
add_satisfaction = list(map(int,input().split()))

total_satisfaction = 0
pre_num = -10

for i in order:
    total_satisfaction += satisfaction[i-1]
    if pre_num + 1 == i:
        total_satisfaction += add_satisfaction[pre_num-1]
    pre_num = i

print(total_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()))
point=B[A[0]-1]
for n in range(N-1):
    left=A[n]
    right=A[n+1]
    point+=B[right-1]
    if right==left+1:
        point+=C[left-1]
print(point)

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

Submission status: Accepted

Solution code:
n = int(input())

order = list(map(int, input().split()))
manzoku = list(map(int, input().split()))
add = list(map(int, input().split()))


ans = 0
before = order[0]

for i in range(n):
    if order[i] == before+1:
        ans += manzoku[order[i]-1] + add[before-1]
    else:
        ans += manzoku[order[i]-1]

    before = order[i]

print(ans)

Submission status: Accepted

Solution code:
def MAP(): return list(map(int,input().split()))

n = int(input())
a = MAP()
b = MAP()
c = MAP()

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ai = [int(i) for i in input().split()]
bi = [int(i) for i in input().split()]
ci = [int(i) for i in input().split()]

result = sum(bi)
prei = -1
for i in ai:
    if (prei+1) == i:
        result += ci[prei-1]
    prei = i

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

score = 0
prev_d = -1

for i in range(N):
    d = A[i] - 1
    score = score + B[d]

    if (prev_d >= 0) and (d - prev_d == 1):
        score = score + C[d-1]

    prev_d  = d

print(score)

Submission status: Accepted

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

ans = 0
for i in range(n):
	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
input = sys.stdin.readline


def main(n, a, b, c):
    total = sum(b)

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

    return total


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    print(main(n, a, b, c))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

point = 0
before = -2
for a in al:
    if a - before == 1:
        point += cl[before - 1]
    before = a
    point += bl[a - 1]
print(point)

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):
    result += B[A[i]-1]
    if i == 0:
        pass
    elif A[i] - 1 == A[i-1]:
        result += C[A[i-1]-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):
    ans+=b[a[i]-1]
    if i!=n-1:
        if a[i+1]==a[i]+1:
            ans+=c[a[i]-1]
print(ans)