Harryxun/stf_run huggingface dataset:
INF = float('inf')
MAX_N = 110
MAX_W = 10**5 + 1

N, W = map(int, input().split())
w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())

# dp table
# dp[i][j] := i-1番目までの品物から重さがjを超えないように選んだ時の、価値の最大値
dp = [[0]*MAX_N for _ in range(MAX_W)]

for i in range(1,N+1):
    for j in range(W+1):
        # i番目の品物を選ぶ
        if j-w[i-1]>=0:
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1])
        # i番目の品物を選ばない場合
        dp[i][j] = max(dp[i][j], dp[i-1][j])

print(dp[N][W])

### FIXED CODE ###

INF = float('inf')
MAX_N = 110
MAX_W = 10**5 + 100

N, W = map(int, input().split())
w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0]*MAX_W for _ in range(MAX_N)]

for i in range(1,N+1):
    for j in range(W+1):
        if j-w[i-1]>=0:
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1])

        dp[i][j] = max(dp[i][j], dp[i-1][j])

print(dp[N][W])
n = int(input())
p = 10**9 + 7

def fact(n, p):
    n_ = [1]
    for i in range(1, n+1):
         n_.append((n_[-1]*i) % p)
    return n

def invfact(n, f, p):
    m = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        m.append(m[-1] * i % p)
    return m

ans = 0
m = n - 1
f = fact(m, p)
rf = invfact(m, f, p)
rf.reverse()
perm = 0

for k in range((n+1)//2, n):
    perm_ = f[k-1] * rf[2*k-n] %p * f[k] % p
    ans += (perm_ - perm) %p * k % p
    ans %= p
    perm = perm_

print(ans)

### FIXED CODE ###

n = int(input())
p = 10**9 + 7

def fact(n):
    n_ = 1
    yield n_
    for i in range(1, n+1):
         n_ = (n_*i) % p
         yield n_

def invfact(n, f, p):
    m = pow(f[n], p-2, p)
    yield m
    for i in range(n, 0, -1):
        m = m * i % p
        yield m

ans = 0
m = n - 1
f = list(fact(m))
rf = list(invfact(m, f, p))
rf.reverse()
perm = 0

for k in range((n+1)//2, n):
    b = m - k
    a = (m - 1) - (2 * b)
    perm_ = f[a+b] * rf[a] %p * f[k] % p
    ans += (perm_ - perm) %p * k % p
    ans %= p
    perm = perm_

print(ans)
N = int(input())


def time_memo(n):
    memo = [0]*(n+1)

    def _time(n):
        if n <= 0:
            return 0
        elif n == 1:
            return 1
        elif memo[n] != 0:
            return memo[n]
        else:
            memo[n] = _time(n-1)*n
            return memo[n]
    return _time(n)


print(time_memo(N) % (10 ^ 9+7))


### FIXED CODE ###

N = int(input())

Ans = 1
for i in range(1, N+1):
    Ans *= i
    Ans %= (10**9+7)

print(Ans)
n=int(input())
A=sorted(list(map(int,input().split())))
print(sum(A[n//2:])-sum(A[:n//2]))

i=0
while len(A)>3:  
  a=min(A)
  b=max(A)
  if i%2==0:
    print("{} {}".format(b,a))
    A.append(b-a)
  else:
    print("{} {}".format(a,b))
    A.append(a-b)
  i+=1
  A.remove(a)
  A.remove(b)
  
  
A.sort()
print("{} {}".format(A[0],A[1]))
print("{} {}".format(A[2],A[0]-A[1]))

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))

if n==2:
    print(abs(A[0]-A[1]))
    print(*A)
    exit()
A.sort()
menos=[] ; plus=[]
for i in range(len(A)):
    if A[i]<0:
        menos.append(A[i])
    else:
        plus.append(A[i])
if menos==[]:
    print(sum(plus)-plus[0]*2)
    res=plus[0]
    for i in range(n-2):
        print(res, A[i+1])
        res=res-A[i+1]
    print(A[n-1], res);exit()
        
elif plus==[]:
    print(-sum(menos)+ menos[-1]*2)
    res=menos[-1]
    for i in range(n-1):
        print(res,menos[i])
        res=res-menos[i]
    exit()
    

print(sum(plus)-sum(menos))
m=len(menos); p=len(plus)
if p==1:
    res=plus[-1]
    for i in range(n-1):
        print(res,menos[i])
        res=res-menos[i]
    exit()
if m==1:
    res=menos[0]
    for i in range(n-2):
        print(res, plus[i])
        res=res-plus[i]
    print(plus[-1], res);exit()

Q= plus[1:]+ [menos[0]]
W= menos[1:]+[plus[0]] ;#print(Q,W)

res=W[-1]
for i in range(len(W)-1):
    print(res,W[i])
    res=res-W[i]
rec=Q[-1]
for i in range(len(Q)-1):
    print(rec, Q[i])
    rec=rec-Q[i]
print(res,rec)
x = input()

Pow = x*x*x

print ("Pow")

### FIXED CODE ###

# -*- coding: utf-8 -*-

x = int(input())

print(x*x*x)
n = int(input())
test_list = [[[int(i) for i in input().split()] for j in range(int(input()))] for k in range(n)]
    
man_list = [[int(j) for j in bin(i)[2:].zfill(n)] for i in range(2**n)]
    
ans = 0
bad = 0
    
for man in man_list:
    for j in range(n):
        if man[j] == 1:
            for k in test_list[j]:
            x = k[0] - 1
            y = k[1]
            if man[x] != y:
                bad = 1
                break
    if bad == 1:
        bad = 0
        break
    else:
        ans = max(ans, sum(man))
    
print(ans)

### FIXED CODE ###

n = int(input())

times = n
table = []
for _ in range(times):
    a = int(input())
    temp = []
    for _ in range(a):
        x , y = map(int,input().split())
        temp.append([x-1,y])
    table.append(temp)  


def check(i,n):
    flg = True
    for j in range(n):
        if i>>j & 1:
            for x,y in table[j]:
                if (i>>x)&1 != y:
                    flg = False
                    return flg
    return flg
ans = 0
for i in range(2**n):
    if check(i,n):
        ans = max(bin(i).count("1"),ans)

print(ans)
import math

a, b = map(int, input().split())
c = math.gcd(a, b)
print(a * b // c)

### FIXED CODE ###

import fractions

a, b = map(int, input().split())
c = fractions.gcd(a, b)
print(a * b // c)
n,x,t=map(int,input().split())
    print(ceil(n/x)*t)

### FIXED CODE ###

import os
import sys
from io import BytesIO, IOBase
from math import ceil
def main():
    n,x,t=map(int,input().split())
    print(ceil(n/x)*t)
# 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")


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

if __name__ == "__main__":
    main()
from collections import deque
n,m,q = map(int,input().split())
l = list(list(map(int,input().split())) for _ in range(q))
if m<7:
  num = ["1"*n]
  k = deque(["1"*n])
  while len(k)!=0:
    h = k.popleft()
    if int(h[-1])<m:
      num.append(str(int(h)+1))
      num.append(str(int(h)+11))
      num.append(str(int(h)+111))
      k.append(str(int(h)+1))
      k.append(str(int(h)+11))
      k.append(str(int(h)+111))
  num = list(set(num))
  ma = 0
  for i in num:
    s = 0
    for a,b,c,d in l:
      if int(i[b-1])-int(i[a-1])==c:
        s += d
        ma = max(ma,s)
  print(ma)
else:
  l1 = sorted(l,key=lambda x:x[3])[::-1]
  print(l1[0][-1])

### FIXED CODE ###

a,b,n = map(int,input().split())
if n<b:
  answer = (a*n//b)-a*(n//b)
else:
  answer = (a*(b-1)//b) - a*((b-1)//b)
print(answer)
n=int(input())
p=list(map(int,input().split()))
ans=1
m=s[0]
for i in range(1,n):
    if s[i]==1:
        ans=ans+1
    elif p[i]>m:
        continue
    else
        ans=ans+1
        m=s[i]
print(ans)

### FIXED CODE ###

n=int(input())
p=list(map(int,input().split()))
ans=1
m=p[0]
for i in range(1,len(p)):
    if p[i]==1:
        ans=ans+1
        break
    elif p[i]>m:
        continue
    else:
        ans=ans+1
        m=p[i]
print(ans)
N = int(input())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_c = list(map(int,input().split()))
all = sum(l_b)çß
for i in range (N-1):
    if l_a[i+1] - l_a[i] == 1:
        all +=l_c[l_a[i]-1]
print(all)


### FIXED CODE ###

N = int(input())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_c = list(map(int,input().split()))
all = sum(l_b)
for i in range (N-1):
    if l_a[i+1] - l_a[i] == 1:
        all +=l_c[l_a[i]-1]
print(all)
N = int(input())

list_aaa = [111,222,333,444,555,666,777,888,999]
cnt =0

for i in range(len(list_aaa)):
    if N >= list_aaa[i]:
        cnt +=1

if cnt ==0:
    print(111)
else:
    print(list_aaa[cnt])


### FIXED CODE ###

N = int(input())

list_aaa = [111,222,333,444,555,666,777,888,999]
cnt =0

for i in range(len(list_aaa)):
    if N > list_aaa[i]:
        cnt +=1

if cnt ==0:
    print(111)
else:
    print(list_aaa[cnt])
a, b, c, d = map(int, input().split())
print(min(a + c,
          a + d,
          b + c,
          b + d))


### FIXED CODE ###

a, b, c, d = [int(input()) for _ in range(4)]
print(min(a + c,
          a + d,
          b + c,
          b + d))
def main():
    n = int(input())
    h = list(map(int, input().split()))

    pre = 0
    flag = True
    for i in range(n):
        if h[i] - 1 >= pre:
            h[i] -= -1
        if h[i] < pre:
            flag = False
            break
        pre = h[i]
    
    if flag:
        print('Yes')
    else:
        print('No')
                

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    a, b, c = map(int, input().split())
    ans = c - (a - b)
    if ans > 0:
        print(ans)
    else:
        print(0)

if __name__ == '__main__':
    main()
n,m,l=map(int,input().split())
for i in range(n):
    a+=[list(map(int,input().split()))]

for i in range(m):
    b+=[list(map(int,input().split()))]
    
c=[[a[i][k]*b[k][i] for i in range(n)] for k in range(l)]
print(c)

### FIXED CODE ###

n,m,l=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a+=[list(map(int,input().split()))]

for i in range(m):
    b+=[list(map(int,input().split()))]
  
c=[]
c=[[sum(a[i][k]*b[k][j] for k in range(m))for j in range(l)] for i in range(n)]
[print(" ".join(list(map(str,c[i])))) for i in range(n)]
number = list(map(int,input().split()))
score = list(map(int,input().split()))
score.sort()
answer = 0
for i in range(number[1]):
    score[number[0]-1-i] = 0
for j in range(number[0]):
    answer += score[j]
print(answer)

### FIXED CODE ###

number = list(map(int,input().split()))
score = list(map(int,input().split()))
score.sort()
answer = 0
if number[1] > number [0]:
    number[1] = number[0]
for i in range(number[1]):
    score[number[0]-1-i] = 0
for j in range(number[0]):
    answer += score[j]
print(answer)
A, B = map(int, input().split())
S = input()
pos_hyphen = [i if S[i] == "-" for i in range(len(S))]
if len(pos_hyphen) == 1 and pos_hyphen[0] == A:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

A, B = map(int, input().split())
S = input()
pos_hyphen = [i for i in range(len(S)) if S[i] == "-"]
if len(pos_hyphen) == 1 and pos_hyphen[0] == A:
    print("Yes")
else:
    print("No")
N, M = map(int,input().split())
A = sorted([int(i) for i in input().split()])
BC = [list(map(int,input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1])[::-1]
ind = 0
for b, c in BC:
  for i in range(b):
    if A[ind] <= c:
      A[ind] = c
      ind += 1
    else:
      break  
print(sum(A))

### FIXED CODE ###

N, M = map(int,input().split())
A = sorted([int(i) for i in input().split()])
BC = [list(map(int,input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1])[::-1]
ind = 0
for b, c in BC:
  for i in range(b):
    if A[ind] < c:
      A[ind] = c
      ind += 1
      if ind == N:
        print(sum(A))
        exit()
    else:
      break
print(sum(A))
def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a
def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)

n = int(input())

ans = 1
for i in range(n):
    ti = int(input())
    ans = int(lcm(ti, ans))
print(ans)


### FIXED CODE ###

import fractions
def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b // fractions.gcd(a, b)

n = int(input())

ans = 1
for i in range(n):
    ti = int(input())
    ans = int(lcm(ti, ans))
print(ans)
s = input()
for i in range(3):
    if s[i] == '1':
        s[i] = '9'
    elif s[i] == '9':
        s[i] = '1'
print(s)

### FIXED CODE ###

n = int(input())
if n ==111:
    print(999)
elif n ==119:
    print(991)
elif n == 191:
    print(919)
elif n == 199:
    print(911)
elif n== 911:
    print(199)
elif n == 919:
    print(191)
elif n== 991:
    print(119)
else:
    print(111)
import numpy as np
N,M=map(int,input().split())
S=np.zeros((N,N))
H=list(map(int,input().split()))

for j in range(M):
  a,b=map(int,input().split())
  
  if H[a-1]<H[b-1]:
    S[a-1,b-1]=-1
    S[b-1,a-1]=1
  elif H[a-1]>H[b-1]:
    S[a-1,b-1]=1
    S[b-1,a-1]=-1
  else:
    S[a-1,b-1]=-1
    S[b-1,a-1]=-1

s=np.zeros(N)
for k in range(N):
  s[k]=np.any(S[k,:]<0)

print(len([i for i,x in enumerate(s) if x==0]))
print(S)

### FIXED CODE ###

import numpy as np
N,M=map(int,input().split())
S=np.ones(N)
H=list(map(int,input().split()))

for j in range(M):
  a,b=map(int,input().split())
  
  if H[a-1]<H[b-1]:
    S[a-1]=0

  elif H[a-1]>H[b-1]:
    S[b-1]=0

  else:
    S[a-1]=0
    S[b-1]=0

print(int(np.sum(S)))
import sys

# 再帰上限の変更(デフォルトは1000)
sys.setrecursionlimit(10 ** 20)

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

# XがわかればYがわかるので、あるAiがわかったときどこまでわかるか?をグラフにしてDFSで探索

graph = [[]for i in range(N + 1)]

seen = [0] * (N + 1)

for X, Y, Z in XYZ:
    graph[X].append(Y)
    graph[Y].append(X)


def dfs(a):
    if seen[a] == 1:
        return
    else:
        seen[a] = 1
        for i in graph[a]:
            dfs(i)


ans = 0

for i in range(1, N + 1):
    if seen[i] == 1:
        continue
    else:
        dfs(i)
        ans += 1

print(ans)


### FIXED CODE ###

import sys

# 再帰上限の変更(デフォルトは1000)
# 大きくしすぎるとREするらしい
sys.setrecursionlimit(10 ** 9)

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

# XがわかればYがわかるので、あるAiがわかったときどこまでわかるか?をグラフにしてDFSで探索

graph = [[]for i in range(N + 1)]

seen = [0] * (N + 1)

for X, Y, Z in XYZ:
    graph[X].append(Y)
    graph[Y].append(X)


def dfs(a):
    if seen[a] == 1:
        return
    else:
        seen[a] = 1
        for i in graph[a]:
            dfs(i)


ans = 0

for i in range(1, N + 1):
    if seen[i] == 1:
        continue
    else:
        dfs(i)
        ans += 1

print(ans)
s = list(map(int, input().split()))

sunuke = []
ans = 0
for n in range(s[0]):
  sunuke.append(0)
for n in range(len(s)):
  d = input()
  a = list(map(int, input().split()))
  for n2 in a:
    sunuke[n2-1] += 1
for n in sunuke:
  if n == 0:
    ans += 1
print(ans)

### FIXED CODE ###

s = list(map(int, input().split()))

sunuke = []
ans = 0
for n in range(s[0]):
  sunuke.append(0)
for n in range(s[1]):
  d = input()
  a = list(map(int, input().split()))
  for n2 in a:
    sunuke[n2-1] += 1
for n in sunuke:
  if n == 0:
    ans += 1
print(ans)
x = int(input())

500yen = x//500*1000
5yen = (x - x//500)//5*5

print(500yen + 5yen)


### FIXED CODE ###

s = input()

if(s[2] == s[3] and s[4] == s[5]):
  print("Yes")
 
else:
  print("No")
import math

n = int(input())

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

ct = 1
for _ in range(n):
	t = int(input())
	ct = lcm(ct,t)
	
print(ct)


### FIXED CODE ###

import math

n = int(input())

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
    
def lcm(x,y):
	return (x * y) // gcd(x, y)

ct = 1
for _ in range(n):
	t = int(input())
	ct = lcm(ct,t)
	
print(ct)
import sys
input = sys.stdin.readline
S = input()

def ctoi(c):
    return ord(c) - ord('a')

cums = [0]
for c in S:
    cums.append(cums[-1] ^ (1<<ctoi(c)))
if cums[-1] == 0:
    print(1)
    exit()

dp = {0:0}
for i,b in enumerate(cums):
    for k in range(26):
        msk = b^(1<<k)
        if msk in dp:
            if b in dp:
                dp[b] = min(dp[b], dp[msk]+1)
            else:
                dp[b] = dp[msk]+1
print(dp[cums[-1]])

### FIXED CODE ###

def ctoi(c):
    return ord(c) - ord('a')

def solve(s):
    masks = [1<<k for k in range(26)]
    cums = [0]
    for c in s:
        cums.append(cums[-1] ^ masks[ctoi(c)])
    if cums[-1] == 0:
        print(1)
        exit()

    dp = {0:0}
    for b in cums:
        for m in masks:
            msk = b^m
            if msk in dp:
                if b in dp:
                    dp[b] = min(dp[b], dp[msk]+1)
                else:
                    dp[b] = dp[msk]+1
    return dp[cums[-1]]

print(solve(input()))
z = list(map(int, input().split()))
x = z[0]
if z[1] == 0:
  print(z[0])
else:
  p = list(map(int, input().split()))
  count = 0
  l = []
  for i in range(1, 101):
    l.append(i)
  for i in p:
    l.remove(i)
  print(l)
  t = 200
  for i in l:
    e = abs(x-i)
    if e >= t:
      break
    t = e
    ans = i
  print(ans)

### FIXED CODE ###

z = list(map(int, input().split()))
x = z[0]
if z[1] == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  l = []
  for i in range(-1, 102):
    l.append(i)
  for i in p:
    l.remove(i)
  t = 200
  for i in l:
    e = abs(x-i)
    if e >= t:
      break
    t = e
    ans = i
  print(ans)
input()
foods=list(map(int,input().split()))
ans = 0
sum = 0
for i in foods:
    for j in foods:
        i<j
        ans= foods[i]*foods[j]
        sum += ans
print(sum)

### FIXED CODE ###

n=int(input())
foods=list(map(int,input().split()))
ans = 0
sum_ans = 0
for i in range(0,n-1):
    for j in range(1,n):
        if i<j:
            ans = foods[i]*foods[j]
            sum_ans += ans
print(sum_ans)
N = int(input())
c = False
s = 0
for i in range(N):
    ai,bi = map(int,input().split())
    s += ai
    if ai > bi:
        if not C:
            c = bi
        if bi < c:
            c = bi
if not c:
    print(0)
else:
    print(s-c)

### FIXED CODE ###

N = int(input())
c = -1
s = 0
for i in range(N):
    ai,bi = map(int,input().split())
    s += ai
    if ai > bi:
        if c == -1:
            c = bi
        if bi < c:
            c = bi
if c == -1:
    print(0)
else:
    print(s-c)
A, B = map(int, input().split())
S = input()
print ('Yes' if re.search(r'\A\d{{{}}}-\d{{{}}}\Z'.format(A, B), S) else 'No') 

### FIXED CODE ###

import re

A, B = map(int, input().split())
S = input()
print ('Yes' if re.search(r'\A\d{{{}}}-\d{{{}}}\Z'.format(A, B), S) else 'No')
N = int(input())
S = list(map(int,input().split()))

S.sort()

if S[-1] == "Y":
  print("Four")
else:
  print("Three")
         
         

### FIXED CODE ###

N = int(input())
S = input().split()
 
S.sort()
 
if S[-1] == "Y":
  print("Four")
else:
  print("Three")
import numpy as np
a,b=map(int,input().split())
print((a*b)//np.gcd(a,b))

### FIXED CODE ###

from fractions import gcd
a,b=map(int,input().split())
print((a*b)//gcd(a,b))
import bisect

MAX_VALUE = 10**100
S = input()
lenS = len(S)
T = input()
Si = {}
for i,s in enumerate(S):
  if s not in Si:
    Si[s] = []
  Si[s].append(i)

ans = 0
for t in T:
  if t not in Si:
    print(-1)
    exit()
  else:
    idx = -1
    if ans<=max(Si[t]):
      idx = Si[t][bisect.bisect(Si[t],ans)]
    else:
      factor = (ans-min(Si[t]))//lenS + 1
      idx = Si[t][max(min(bisect.bisect(Si[t],ans%lenS),len(Si[t])-1),0)] + factor*lenS
    ans = idx
    if MAX_VALUE<ans:
      print(-1)
      exit()
print(ans+1)

### FIXED CODE ###

import bisect

REPEAT_NUM = 10 ** 100

S = input()
T = input()
lenS = len(S)
lenT = len(T)

idxes_S = {}
for idx, s in enumerate(S):
    if s not in idxes_S:
        idxes_S[s] = []
    idxes_S[s].append(idx)

idx_s = -1
idx_t = 0
while idx_t < lenT and idx_s < lenS * REPEAT_NUM:
    if T[idx_t] not in idxes_S:
        print(-1)
        exit()
    else:
        tmp_idx = bisect.bisect(idxes_S[T[idx_t]], idx_s % lenS)
        if len(idxes_S[T[idx_t]]) == tmp_idx:
            idx_s += lenS - idx_s % lenS + idxes_S[T[idx_t]][0]
        else:
            idx_s += idxes_S[T[idx_t]][tmp_idx] - idx_s % lenS
        idx_t += 1

if idx_t == lenT:
    print(idx_s + 1)
else:
    print(-1)
class Dice(object):
    def __init__(self):
        self.upside = 1
	self.frontside = 2
	self.rightside = 3
	self.backside = 4
	self.leftside = 5
	self.downside = 6
		
    def throwDice(self,dir):
	up = self.upside
	front = self.frontside
	left = self.leftside
	if dir == "S":
	    self.frontside = up
	    self.backside = 7-up
	    self.downside = front
            self.upside = 7-front
			
	elif dir == "N":
	    self.frontside = 7-up
	    self.backside = up
	    self.downside = 7-front
	    self.upside = front
			
	elif dir == "E":
	    self.rightside = up
	    self.leftside = 7-up
	    self.upside = left
	    self.downside = 7-left
		
	elif dir == "W":
	    self.rightside = 7-up
	    self.leftside = up
	    self.upside = 7-left
	    self.downside = left
	
	def getUpside(self):
	    return self.upside
		
n = list(map(int,input().split()))
com = list(input())

dice = Dice()
for i in range(len(com)):
	dice.throwDice(com[i])

print(n[dice.getUpside()-1])

	
	
	

### FIXED CODE ###

def move(up,bottom,right,left,front,back,direction):
    if direction == "N":
        return (front,back,right,left,bottom,up)
    elif direction == "S":
        return (back,front,right,left,up,bottom)
    elif direction == "E":
        return (left,right,up,bottom,front,back)
    elif direction == "W":
        return (right,left,bottom,up,front,back)
    
up,front,right,left,back,bottom = input().split()
direction = list(input())

for i in range(len(direction)):
    up,bottom,right,left,front,back = move(up,bottom,right,left,front,back,direction[i])
    
print(up)
w = list(map(int, input().split(" ")))
if s >= w:
  print("unsafe")
else:
  print("safe")

### FIXED CODE ###

s, w = list(map(int, input().split(" ")))
if s <= w:
  print("unsafe")
else:
  print("safe")
n,m=map(int,input().split())
lovelist=[]
for _ in range(n):
    a=set(sorted(list(map(int,input().split()))))
    lovelist.append(a)
for i in range(n-1):
    lovelist[i+1]=lovelist[i]&lovelist[i+1]
print(len(lovelist[2]))

### FIXED CODE ###

n,m=map(int,input().split())
l=[]
for _ in range(n):
    a=list(map(int,input().split()))
    a=set(a[1:])
    l.append(a)
for i in range(n-1):
    l[i+1]=l[i]&l[i+1]
print(len(l[-1]))