Harryxun/stf_run huggingface dataset:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
p=0
for i in range(n):
  p+=b[a[i]-1]
  
  if　i>=1 and a[i]-a[i-1]==1:
    p+=c[a[i-1]-1]
print(p)
  


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
p=0
for i in range(n):
  p+=b[a[i]-1]
  if i>=1 and a[i]-a[i-1]==1:
    p+=c[a[i-1]-1]
print(p)
import sys
def input(): return sys.stdin.readline().strip()
from collections import Counter
def resolve():
    n=int(input())
    l=[input() for i in range(n)]
    l.sort()
    setl = list(set(l))
    setl.sort()
    c=Counter(l)
    ll=[*c.values()]
    for i in range(len(setl)):
        if ll[i]==max(ll):
            print(setl[i])
resolve()

### FIXED CODE ###

from collections import Counter
def resolve():
    n=int(input())
    l=[input() for i in range(n)]
    c=Counter(l)
    maxl=[]
    cntmax=max(c.values())
    for name,kazu in c.items():
        if kazu==cntmax:
            maxl.append(name)
    maxl.sort()
    for i in maxl:
        print(i)
resolve()
X, N = map(int, input().split())
if N != 0:
    p = list(map(int, input().split()))
else:
    p = []

res = 10**9
MIN = res

for i in range(-100,X+1):
    if not i in p:
        x = i

for i in range(X,101):
    if not i in p:
        y = i
        break

if (X-x) == (y-X):
    print(x)
elif (X-x) > (y-X):
    print(y)
else:
    print(x)

### FIXED CODE ###

X, N = map(int, input().split())
if N > 0:
    p = list(map(int, input().split()))
elif N == 0:
    print(X)
    exit()
else :
    p = [int(input())]
if N == 100:
    if X <= 50:
        print(0)
    else:
        print(101)
    exit()

for i in range(X+1):
    if not i in p:
        x = i

for i in range(X,101):
    if not i in p:
        y = i
        break
    elif i == 100:
        y = 101

if (X-x) == (y-X):
    print(x)
elif (X-x) > (y-X):
    print(y)
else:
    print(x)
N, M = map(int, input().split())
xrd = [[] for i in range(N)]
x = [None]*N
visited = []


def check(s):
    global xrd, x, visited
    if s in visited:
        return
    visited.append(s)
    for t, d in xrd[s]:
        if t in visited:
            continue
        if x[t] is None:
            x[t] = x[s] + d
            check(t)
        else:
            if x[t] != x[s] + d:
                print("No")
                exit()


for i in range(M):
    L, R, D = map(int, input().split())
    xrd[L-1].append([R-1, D])
    xrd[R-1].append([L-1, -D])

for i in range(N):
    if x[i] is None:
        x[i] = 0
        check(i)


print("Yes")


### FIXED CODE ###

import sys
sys.setrecursionlimit(200002)

N, M = map(int, input().split())
G = [[] for _ in range(N)]
x = [None] * N

def fail():
    print("No")
    exit()

def dfs(s):
    global x, G
    for t, d in G[s]:
        if x[t] is None:
            x[t] = x[s] + d
            dfs(t)
        else:
            if x[t] != x[s] + d:
                fail()

for _ in range(M):
    L, R, D = map(int, input().split())
    G[L-1].append([R-1,  D])
    G[R-1].append([L-1, -D])

for i in range(N):
    if x[i] is None:
        x[i] = 0
        dfs(i)

print("Yes")
N,K=[int(s) for s in input().split()]
ls_p=[int(s) for s in input().split()]
ls_n=[]
X=0
for i in range(N):
  if ls_p[0]>=0 : break 
  else:
    X+=1
    ls_n.append(ls_p[0])
    ls_p.pop(0)
#ls_nにX個流れている
cand=[]
for i in range(min([X-1,K-2])):
  cand.append(-ls_n[-i-1]*2+ls_p[K-i-2])
  cand.append(-ls_n[-i-1]+ls_p[K-i-2]*2)
if N-X-1>=K-1:
  cand.append(ls_p[K-1])
if X>=K:
  cand.append(-ls_n[-K])
print(min(cand))
  


### FIXED CODE ###

N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
def length(i):
  if ls[i]>=0:
    return ls[K+i-1]
  elif ls[K+i-1]<=0:
    return -ls[i]
  else:
    return min([2*ls[K+i-1]-ls[i],ls[K+i-1]-2*ls[i]])
answer=[]
for i in range(N-K+1):
  answer.append(length(i))
  
print(min(answer))
s=input()
n=int(s)
c=0
for i in range(len(s)-3):
  for j in range(i,len(s)+1):
    m=int(int(n/(10**i))%(10**j))
    if m%2019==0 and :
      c+=1
print(c)

### FIXED CODE ###

S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
A = A[::-1]

MOD = 2019

p10 = [1] * N
for i in range(1, N):
	p10[i] = (p10[i - 1] * 10) % MOD

for i in range(N):
	A[i] = (A[i] * p10[i]) % MOD

cumsum = [A[0]] * N
for i in range(1, N):
	cumsum[i] = (cumsum[i - 1] + A[i]) % MOD

cnt = [0] * MOD
cnt[0] = 1
for i in range(N):
	cnt[cumsum[i]] += 1

ans = 0
for i in range(MOD):
	ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)
N = int(input())
i = 0
while(N >= 1):
    i += N % 10
    N = int(N/10)
if (i % 9 == 0):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N = input()
rank = len(N) - 1
i = 0
while(len(N) != 0):
    a = N[0]
    N = N[1:]
    a = int(a)
    i += a
if (i % 9 == 0):
    print("Yes")
else:
    print("No")
x,n = map(int,input().split())
p = list(map(int,input().split()))
absolute = list(map(lambda i:abs(i-x),p))
ab = set(absolute)

if n == 0 or 0 not in absolute:
    print(x)
else:
    i = 1
    while i < 100:
        if absolute.count(i) == 2:
            i += 1
        else:
            opt = set([x-i,x+i])
            ans = opt - ab
            break

print(min(ans))


### FIXED CODE ###

x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))
    absolute = list(map(lambda i:abs(i-x),p))
    if 0 not in absolute:
        print(x)
    else:
        ab = set(p)
        i = 1
        while i < 100:
            if absolute.count(i) == 2:
                i += 1
            else:
                opt = set([x-i,x+i])
                ans = opt - ab
                break

        print(min(ans))
a, b, c = map(int, input(input().split()))
print('YES' if b-a==c-b else 'NO')

### FIXED CODE ###

a, b, c = map(int, input().split())
print('YES' if b-a==c-b else 'NO')
def solve(H, W, h, w):
    if H == 1:
        if W <= 2:
            print('No')
        else:
            kari = (W - 2) // 2 + 1
            if kari >= w - 1:
                print('No')
            else:
                print('Yes')
                print(kari, *([-1] * (W - 2)), kari)
        return
    if W == 1:
        if H <= 2:
            print('No')
        else:
            kari = (H - 2) // 2 + 1
            if kari >= h - 1:
                print('No')
            else:
                print('Yes')
                print(kari)
                for _ in range(H - 2):
                    print(-1)
                print(kari)
        return
    kari = (H * W - 4) // 4 + 1
    if kari >= h * w - 1:
        print('No')
    else:
        print('Yes')
        print(kari, *([-1] * (W - 2)), kari)
        for _ in range(H - 2):
            print(*([-1] * W))
        print(kari, *([-1] * (W - 2)), kari)


H, W, h, w = map(int, input().split())
solve(H, W, h, w)


### FIXED CODE ###

def get_1d(H, h):
    ret = [0] * (H + 1)
    for s in range(h):
        for x, i in enumerate(range(s, H, h)):
            ret[i] = -x
    for x, i in enumerate(range(H, 0, -h)):
        ret[i] = x + 1
    return [x1 - x0 for x0, x1 in zip(ret, ret[1:])]


def solve(H, W, h, w):
    if H % h == 0 and W % w == 0:
        return False
    ans = []
    if H % h > 0:
        col = get_1d(H, h)
        ans.extend([x] * W for x in col)
    else:
        row = get_1d(W, w)
        ans.extend([row] * H)
    return ans


H, W, h, w = map(int, input().split())
ans = solve(H, W, h, w)
if ans == False:
    print('No')
else:
    print('Yes')
    for row in ans:
        print(*row)
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N,K=map(int,input().split())
    V=list(map(int,input().split()))
    ans=0
    for l in range(K+1):
        for r in range(K-l+1):
            if l+r>K: continue
            now=[]
            for i in range(l):
                now.append(V[i])
            for j in range(r):
                now.append(V[-j-1])
            

            now.sort()
            m=K-l-r
            if m==0:
                ans=max(ans,sum(now))
            if range(min(l+r,m)):
                for i in range(min(l+r,m)):
                    if now[i]>=0:
                        temp=i
                        break
                    else: temp=i+1
                ans=max(ans,sum(now[temp:]))

    print(ans)



    
resolve()

### FIXED CODE ###

# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K+1):
        for r in range(K-l+1):
            if l+r > N:
                continue
            now = []
            val = 0
            for i in range(l):
                now.append(V[i])
                val += V[i]
            for j in range(r):
                now.append(V[-j-1])
                val += V[-j-1]

            d = K-l-r
            now.sort()
            for i in range(d):
                if i >= len(now):
                    break
                if now[i] > 0:
                    break
                val -= now[i]
            ans=max(ans,val)

    print(ans)

resolve()
print(int((int(input())+int(input())/2))

### FIXED CODE ###

a, b = map(int, input().split())
print((a + b + 1) // 2)
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

sub = np.bincount(A, weights=None, minlength=N+1)
sub1 = sub.reshape(N+1, 1)

print(sub1[1:])

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 13:36:36 2020

@author: hiroki
"""

import math

a = input()
print(int(a)*2*math.pi)
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

count = 0
for i in range(0, n):
    a = list(map(int, input().split()))
    s = 0
    for j in range(0, m):
        s += a[j] * b[j]
    if s + c > 0:
        count += 1
print(count)


### FIXED CODE ###

H, W = map(int, input().split())
h, w = map(int, input().split())
print((H - h) * (W - w))
import bisect

N, M = map(int, input().split(" "))
As = list(map(int, input().split(" ")))
As = sorted(As)
cnt = 0
j = 0
for _ in range(M):
  if j >= As[-1-cnt]:
    i = j>>1
  else:
    i = As[-1-cnt]>>1
    
  j = i
  
  if i < As[-1-cnt-1]:
    cnt += 1
    bisect.insort_left(As,i)

if j > As[-1-cnt-1]:
  bisect.insort_left(As,j)

print(sum(As[:-cnt]))

### FIXED CODE ###

import heapq
 
N, M = map(int, input().split(" "))
As = [-i for i in map(int, input().split(" "))]
As.sort()
heapq.heapify(As)

for _ in range(M):
  i = - heapq.heappop(As)
  i = i >> 1
  heapq.heappush(As,-i)

print(-sum(As))
import sys
list=[]
for i in sys.stdin.readlines():
    if float(i) != 0:
        list.append(float(i))
    else:
        print int(list.pop())

### FIXED CODE ###

import sys
list=[]
for i in sys.stdin:
    if i.strip() != '0':
        list.append(i.strip())
    else:
        print list.pop()
n = int(input())
a = list(map(int, input().split()))
q = int(input())
query = [list(map(int,input().split())) for _ in range(q)]

all_sum  = sum(a)

cnt = {}
for i in a:
    if i not in cnt:
        cnt[a] = 0
    cnt[a] += 1

for (b, c) in query:
    if b in cnt:
        all_sum -= b*cnt[b]
        all_sum += c * cnt[b]
        if c not in cnt:
            cnt[c]=0 
    print(all_sum)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
query = [list(map(int,input().split())) for _ in range(q)]

all_sum  = sum(a)

cnt = {}
for i in a:
    if i not in cnt:
        cnt[i] = 0
    cnt[i] += 1

for (b, c) in query:
    if b in cnt:
        all_sum -= b * cnt[b]
        all_sum += c * cnt[b]
        if c not in cnt:
            cnt[c]=0 
        cnt[c] += cnt[b]
        cnt[b] = 0
    print(all_sum)
import bisect
 
n = int(input())
d = sorted(list(map(int,input().split())))
m = int(input())
t = list(map(int,input().split()))
d.append(d[-1]+1)

flg = True
for i in range(m):
  index = bisect.bisect_left(d,t[i])
  if t[i] == d[index]:
    del d[index]
  else:
    flg = False
    break
 
print('YES' if flg else 'NO')

### FIXED CODE ###

import collections
 
n = int(input())
d = sorted(list(map(int,input().split())))
m = int(input())
t = list(map(int,input().split()))

cd = collections.Counter(d)
ct = collections.Counter(t)

flg = True
for k in ct.items():
  if k[1] > cd[k[0]]:
    flg = False

print('YES' if flg else 'NO')
N = int(input())
p = 10**9 + 7

fac = [0] * (N + 33)
inv = [0] * (N + 33)
finv = [0] * (N + 33)

fac[0] = fac[1] = 1
inv[1] = 1
finv[0] = finv[1] = 1

for i in range(2, N+34):
  fac[i] = fac[i-1] * i % p
  inv[i] = p - inv[p%i] * (p // i) % p
  finv[i] = finv[i-1] * inv[i] % p

primes = {}
i = 2
n = N
while(n > 1):
  if(n % i == 0):
    primes[i] = primes.get(i, 0) + 1
    n //= i
  else:
    i += 2 - (n + 1) % 2

r = 1
for v in primes.value():
  r = r * fac[N+v-1] * finv[N-1] * finv[v] % p
print(r)

### FIXED CODE ###

N, M = map(int, input().split())
p = 10**9 + 7

fac = [0] * (N + 33)
inv = [0] * (N + 33)
finv = [0] * (N + 33)

fac[0] = fac[1] = 1
inv[1] = 1
finv[0] = finv[1] = 1

for i in range(2, N+33):
  fac[i] = fac[i-1] * i % p
  inv[i] = p - inv[p%i] * (p // i) % p
  finv[i] = finv[i-1] * inv[i] % p

primes = {}
i = 2
while(M > 1):
  if(M % i == 0):
    primes[i] = primes.get(i, 0) + 1
    M //= i
  else:
    i += 2 - (i + 1) % 2
r = 1
for v in primes.values():
  r = r * fac[N+v-1] * finv[N-1] * finv[v] % p
print(r)
H,W = map(int, input().split())
h,w = map(int, input().split())
print(HW-hW-Hw+hw)

### FIXED CODE ###

H,W = map(int, input().split())
h,w = map(int, input().split())
print(H*W-h*W-H*w+h*w)
a, b = map(int, input().split())
s = input()
l = list(range(10))
for i in range(len(s)):
    if i == 3:
        if s[i] != "-":
            print("No")
            exit()
    else:
        if int(s[i]) not in l:
            print("No")
            exit()
print("Yes")


### FIXED CODE ###

a, b = map(int, input().split())
s = input()

for i in range(len(s)):
    if i == a:
        if s[a] != "-":
            print("No")
            exit()
    else:
        if not "0" <= s[i] <= "9":
            print("No")
            exit()
print("Yes")
S = input()
S.split()

N = len(S)

for i in range(N//2):
    if (S[i*2] == 'R' or S[i*2] == 'U' or S[i*2] == 'D') and \
            (S[i*2 + 1] == 'L' or S[i*2 + 1] == 'U' or S[i*2 + 1] == 'D'):
        continue
    else:
        print('No')
        exit(1)
if N%2 != 0:
    if S[N-1] == 'R' or S[N-1] == 'U' or S[N-1] == 'D':
        print('Yes')
    else:
        print('No')
        exit(1)
else:
    print('Yes')


### FIXED CODE ###

S = input()
S.split()

N = len(S)

for i in range(N//2):
    if (S[i*2] == 'R' or S[i*2] == 'U' or S[i*2] == 'D') and \
            (S[i*2 + 1] == 'L' or S[i*2 + 1] == 'U' or S[i*2 + 1] == 'D'):
        continue
    else:
        print('No')
        exit(0)
if N%2 != 0:
    if S[N-1] == 'R' or S[N-1] == 'U' or S[N-1] == 'D':
        print('Yes')
    else:
        print('No')
        exit(0)
else:
    print('Yes')
In = input().split(" ")
T = int(In[0])
A = int(In[1])
K = int(In[2])
 
if K>=T+A:
  print("0 0")
else:
	if (K > T):
  		print("0 {0}".format(A-(K-T)))
	elif (T > K):
  		print("{0} {1}".format(T-K, A))
	else:
  		for i in range(K):
    		if T >= 1:
     			 T -= 1
    		else:
    			if A >= 1:
      				A -= 1
    			else:
      				break
  		print("{0} {1}".format(T, A))

### FIXED CODE ###

In = input().split(" ")
T = int(In[0])
A = int(In[1])
K = int(In[2])
 
if K <= T:
  print("{0} {1}".format(T-K,A))
elif K <= T+A:
  print("0 {0}".format(A-(K-T)))
else:
  print("0 0")
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
        
def lcm(a,b):
    return int(a*b/gcd(a,b))

n = int(input())
t = []
for i in range(n):
    t.append(int(input()))

res=1
for i in range(n):
    res = lcm(res,t[i])
    
print(res)

### FIXED CODE ###

n = int(raw_input())

def gcd(a,b):
    if a > b:
        a,b = b,a
    # a <= b
    while a > 0:
        a,b = b%a, a
    return b

def lcm(a,b):
    g = gcd(a,b)
    return a/g * b

x = 1
for i in range(n):
    ti = int(raw_input())
    x = lcm(x, ti)

print x
i=list(map(int,input().split()))
a=i[0]*i[1]
if a%%2==0:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

i=list(map(int,input().split()))
a=i[0]*i[1]
if a%2==0:
  print("Even")
else:
  print("Odd")
k, x = map(int, input().split())
print range(x-k+1,x+k-1)

### FIXED CODE ###

k, x = map(int, input().split())
for i in range(x-k+1,x+k):
	print (i)
l=input()
if(int(l[:2])>0 and int(l[2:])>0 and int(l[:2])<=12 and int(l[2:])<=12):
    print('AMBIGUOUS')
elif(int(l[:2])>0 and int(l[2:])>0 and int(l[2:])<=12 and int(l[:2])>=13):
    print("YYMM")
elif(int(l[:2])>0 and int(l[2:])>0 and int(l[2:]>=13) and int(l[:2])<=12):
    print("MMYY")
else:
    print('NA')

### FIXED CODE ###

s = input()
first = int(s[0:2])
second = int(s[2:4])
if 1 <= first <= 12 and 1 <= second <= 12:
    print('AMBIGUOUS')
elif 1 <= first <= 12:
    print('MMYY')
elif 1 <= second <= 12:
    print('YYMM')
else:
    print('NA')
#include <iostream>
#include <vector>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
 
int main() {
  int n,m;
  int cnt=0;
  cin >> n >> m;
  
  vector<int> v,x;
 
  int a,b;
  for(int i = 0; i < n; ++i) {
    cin >> a;
    v.push_back(a);
  }
  x = v;
  
  for(int i = 0; i < m; ++i) {
    cin >> a >> b;
    a--;
    b--;
    if(v[a] < v[b]) {
      x[a] = -1;
    }
    else if(v[a] == v[b]) {
      x[a] = -1;
      x[b] = -1;
    }else if(x[b] < x[a]) {
      x[b] = -1;
    }
  }
 
  cout << v.size() - count(x.begin(), x.end(), -1) << "\n";
  return 0;
}

### FIXED CODE ###

N, M =map(int, input().split())
H_tree = [0] + [int(n) for n in input().split()]
GOOD_Tree = [0] + [1 for n in range(N)]
 
for i in range(M):
  A, B = map(int, input().split())
  if H_tree[A]<=H_tree[B]:GOOD_Tree[A] = 0
  if H_tree[A]>=H_tree[B]:GOOD_Tree[B] = 0
print(sum(GOOD_Tree))
c=input()
if c="a" or c="i" or c="u" or c="e" or c="o":
    print("vowel")
else:
    print("consonant")

### FIXED CODE ###

c=input()
if c=="a" or c=="i" or c=="u" or c=="e" or c=="o":
    print("vowel")
else:
    print("consonant")
H,W=map(int, input().split())
c=[list(input()) for i in range(W)]
a=[0]*W
ans=''
   
for i in range(2*H):
    ans=''
    for j in range(W):
        #print((i)//2)
        a[j]=c[int((i)//2)][j]
        ans+=a[j]
    print(ans)

### FIXED CODE ###

h, w = map(int, input().split())  
for i in range(h):
    s = input()
    print(s)
    print(s)
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    flag = 0
    for k in range(K):
        imos = [0]*(N + 1)
        if flag == N:
            print([N]*(N))
            return
        for i in range(N):
            imos[max(0,i  - A[i])] += 1
            imos[min(N + 1,i + 1 + A[i])] -= 1
        for j in range(N):
            imos[j+1] += imos[j]
        A = imos[:N].copy()
    print(*A,sep=" ")
    return 

if __name__ == "__main__":
    main()

### FIXED CODE ###

from math import log2

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    if K > log2(N)+ 50:
        return print(*[N]*N,sep = " ")
    for _ in range(K):
        imos = [0]*(N + 1)
        for i in range(N):
            imos[max(0,i  - A[i])] += 1
            imos[min(N,i + 1 + A[i])] -= 1
        for j in range(N):
            imos[j+1] += imos[j]
        A = imos[:N].copy()
    print(*A,sep=" ")
    return

if __name__ == "__main__":
    main()
S = int(input())
mod = 10**9 + 7
d = [[0 for i in range(S + 1)] for j in range(S + 1)]
d[3][1] = 1
for j in range(S - 3):
  for i in range(S):
    d[j+4][i+1] = (d[j+3][i+1] + d[j+1][i]) %mod
print(sum(d[S])%mod)

### FIXED CODE ###

import sys
S = int(input())
mod = 10**9 + 7
if S <= 2:
  print(0)
  sys.exit()
d = [[0 for i in range(S + 1)] for j in range(S + 1)]
d[3][1] = 1
for j in range(S - 3):
  for i in range(S):
    d[j+4][i+1] = (d[j+3][i+1] + d[j+1][i]) %mod
print(sum(d[S])%mod)
a,b=map(int,input().split())
k=[]
o=[]
p=[]
for i in range(1,101):
    if i==A//1.08:
        k.append(i)
for j in range(1,101):
    if j==b//1.1:
        o.append(j)
for t in range(len(k)):
    for u in range(len(o)):
        if k[t]==o[u]:
            p.append(k[t])
if p==[]:
    print(-1)
else:
    print(min(p))

### FIXED CODE ###

a,b=map(int,input().split())
k=[]
o=[]
p=[]
for i in range(1,5000):
    if int(i*0.08)==a:
        k.append(i)
for j in range(1,5000):
    if int(j*0.1)==b:
        o.append(j)
for t in range(len(k)):
    for u in range(len(o)):
        if k[t]==o[u]:
            p.append(k[t])
if p==[]:
    print(-1)
else:
    print(min(p))
i = int(input())
s= input()
if len(s) > k:
  s=s[:k] + "..."
print(s)

### FIXED CODE ###

i = int(input())
s= input()
if len(s) > i:
	s=s[:i] + "..."
print(s)
N,D=map(int,input().split())
for i in range(N):
  X[i]=list(map(int,input().split()))
count=0
for i in range(N):
  for j in range(i,N):
    dis=0
    for k in range(D):
      dis += pow(X[i][k],2) + pow(X[j][k],2) 
    dis = sqrt(dis)
    if dis==int(dis):
      count+=1
print(count)

### FIXED CODE ###

import math
N,D=map(int,input().split())
X=[0]*N
for i in range(N):
  X[i]=list(map(int,input().split()))
count=0
for i in range(N):
  for j in range(i,N):
    dis=0
    for k in range(D):
      dis += pow(X[i][k]-X[j][k],2) 
    dis = math.sqrt(dis)

    if dis==int(dis) and dis!=0:
      count+=1
print(count)
import sys

def echo(A):
    for i, a in enumerate(A):
        if i < len(A) - 1:
            sys.stdout('%d ' % a)
        else:
            sys.stdout('%d\n' % a)

def insertionSort(A, N):
    echo(A)
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        echo(A)


n = raw_input()
a = raw_input()
insertionSort(a, n)

### FIXED CODE ###

import sys, re

def echo(A):
    for i, a in enumerate(A):
        if i < len(A) - 1:
            sys.stdout.write('%d ' % a)
        else:
            sys.stdout.write('%d\n' % a)

def insertionSort(A, N):
    echo(A)
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        echo(A)


n = int(raw_input())
a_text = raw_input()
splits = re.split(' ', a_text)
a = []
for i, s in enumerate(splits): 
    if s:
        a.append(int(s))

insertionSort(a, n)
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]

x0, y0, h0 = P[0]
for cy in range(101):
    for cx in range(101):
        h = h0 + abs(cx - x0) + abs(cy - y0)
        for x, y, h1 in P[1:]:
            if h != h1 + abs(cx - x) + abs(cy - y):
                break
        else:
            print(cx, cy, h)
            exit(0)
exit(1)


### FIXED CODE ###

N = int(input())
P = [list(map(int, input().split())) for i in range(N)]

i = 0
while 1:
    if P[i][2] > 0:
        break
    i += 1
x0, y0, h0 = P[i]
for cy in range(101):
    for cx in range(101):
        h = h0 + abs(cx - x0) + abs(cy - y0)
        for x, y, h1 in P:
            if h1 != max(h - abs(cx - x) - abs(cy - y), 0):
                break
        else:
            print(cx, cy, h)
            exit(0)
exit(1)
while(1):
  count = int(raw_input())
  if count == 0: break
  previous_cube = [1, 2, 3, 4, 5, 6]
  operation{'North':[2, 6, 3, 4, 1, 5], 'East':[4, 2, 1, 6, 5, 3], 'West': [3, 2, 6, 1, 5, 4], 'South':[5, 1, 3, 4, 6, 2], 'Right':[1, 3, 5, 2, 4, 6], 'Left'[1, 4, 2, 5, 3, 6]}
  sum = 1
  for i in xrange(count):
    new_cube = []
    for i in xrange(6):
      new_cube.append(previous_cube[operation[raw_input()][i]])
    sum += new_cube[0]
    previous_cube = new_cube
  print sum

### FIXED CODE ###

while 1:
  n = input()
  if n == 0:  break
  d = range(1, 7)
  ans = 1
  for i in range(n):
    c = raw_input()[0]
    if c == 'N': S = [1,5,2,3,0,4]
    elif c == "S": S = [4,0,2,3,5,1]
    elif c == "E": S = [3,1,0,5,4,2]
    elif c == "W": S = [2,1,5,0,4,3]
    elif c == "R": S = [0,2,4,1,3,5]
    elif c == "L": S = [0,3,1,4,2,5]
    d = [d[s] for s in S]
    ans += d[0]
  print ans