Harryxun/stf_run huggingface dataset:
import sys
import os
f = open('03_C - Forbidden List.txt', 'r')
sys.stdin = f

X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    diff, rst = -1, 0
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

### FIXED CODE ###

x, n = map(int, input().split(' '))
min_num = 100

ls = [0] * 201
for i in range(0, 201):
    ls[i] = i

ls_in = [0] * n
if n > 0:
    ls_in = list(map(int, input().split(' ')))
    for i in ls_in:
        ls.remove(i)
    ls.reverse()
    for i in ls:
        min_num = min(abs(x-i), min_num)
        if abs(x-i) == min_num:
            ans = i 
    print(ans)
else:
    print(x)
import fractions
N, M = map(int, input().split())

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


k = a[0]

for i in range(1, N):
    k = (a[i]*k) // fractions.gcd(a[i], k)
ans = 0
if k * 0.5 <= M:
    ans += 1
ans += M // k
print(ans)


### FIXED CODE ###

from fractions import gcd
N, M = map(int, input().split())
a = list(map(int, input().split()))
k = a[0]
for i in range(1, N):
    k = (a[i]*k) // gcd(a[i], k)
    if k > M*2:
        print(0)
        exit(0)
    k = int(k)
ans = (M - (k // 2)) // k

if M >= (k // 2):
    flag = True
    for i in range(N):
        if (k // a[i]) % 2 == 0:
            print(0)
            exit(0)
    if flag:
        ans += 1

print(int(ans))
import sys


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


INF = float('inf')


def calc_rle(s):
    tmp, count, ans = s[0], 1, ""
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            ans += tmp + str(count)
            tmp = s[i]
            count = 1
    ans += tmp + str(count)
    return ans


s = S()
rle = calc_rle(s)
if rle[0] == 'W':
    rle = rle[2:]
if rle[-2] == 'B':
    rle = rle[:-2]
# print(rle)
rle = [[rle[i], eval(rle[i+1])] for i in range(0, len(rle), 2)]
# print(rle)
ans = 0
for i in range(0, len(rle), 2):
    # print(rle[i], rle[i+1])
    ans += rle[i][1] * rle[i + 1][1]
    if i + 2 < len(rle):
        rle[i + 2][1] += rle[i][1]
    # print(f'{ans=}')
print(ans)


### FIXED CODE ###

import sys


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


INF = float('inf')


s = S()
ans = 0
w_cnt = 0
for i in range(len(s)):
    if s[i] == "W":
        ans += i - w_cnt  # その W の場所までにあった B の数
        w_cnt += 1

print(ans)
while 1:
  x,y = map( int , raw_input().split() )
  if x == 0 and y == 0
    break
  temp = x
  x = y
  y = temp
  print "%d %d" %(x,y) 

### FIXED CODE ###

while 1:
  x,y = map( int , raw_input().split() )
  if x == 0 and y == 0:
    break
  elif x <= y:
    print "%d %d" %(x,y) 
  elif y < x : 
    print "%d %d" %(y,x)
a,b == input().split()
print("H" if a == b else "D")

### FIXED CODE ###

a,b = input().split()
print('H' if a==b else 'D')
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    Ps = [int(i) for i in input().split()]
    coords = set(range(min(Ps), max(Ps)+1))
    for p in Ps:
        coords.remove(p)
    if X in coords:
        print(X)
    else:
        ret = [ (v, abs(X-v)) for v in coords ]
        minval = min(ret, key=lambda elm: elm[1])[0]
        print(
            min([ elm[0] for elm in ret if minval == elm[0] ])
        )

### FIXED CODE ###

X, N = [int(i) for i in input().split()]
if N == 0:
# if False:
    print(X)
else:
    Ps = set([int(i) for i in input().split()])
    # if not X in Ps:
    #     print(X)

    # print(f'{X} {sorted(Ps)}')
    diff = 0
    while True:
        a = X - diff
        if a not in Ps:
            print(a)
            break
        a = X + diff
        if a not in Ps:
            print(a)
            break
        diff += 1
N,K=map(int,(input().split()))
TO=list(map(int,input().split()))

visit_flag=[[0]*2 for i in [1]*N]
visit_count=0
first_visit=0
last_visit=0
next_town=1
visit_flag[0][0]=1
visit_flag[0][1]=0

for i in range(K):
    visit_count+=1
    next_town = TO[next_town-1]
    if visit_flag[next_town-1][0]==0:
        visit_flag[next_town-1][0]=1
        visit_flag[next_town-1][1]=visit_count
    else:
        first_visit=visit_flag[next_town-1][1]
        last_visit=visit_count
        break

roop=last_visit-first_visit

if K<=roop:
    next_town = 1
    for i in range(K):     
        next_town = TO[next_town-1]
    ans=next_town
else:
    for i in range((K-roop+1)%roop):
        next_town = TO[next_town-1]
    ans=next_town

print(ans)

### FIXED CODE ###

N,K=map(int,(input().split()))
TO=list(map(int,input().split()))

visit_flag=[[0]*2 for i in [1]*N]
visit_count=0
first_visit=0
last_visit=0
next_town=1
visit_flag[0][0]=1
visit_flag[0][1]=0

for i in range(K):
    visit_count+=1
    next_town = TO[next_town-1]
    if visit_flag[next_town-1][0]==0:
        visit_flag[next_town-1][0]=1
        visit_flag[next_town-1][1]=visit_count
    else:
        first_visit=visit_flag[next_town-1][1]
        last_visit=visit_count
        break

roop=last_visit-first_visit
span=visit_flag[next_town-1][1]

if K<=roop:
    next_town = 1
    for i in range(K):     
        next_town = TO[next_town-1]
    ans=next_town
else:
    if roop==0:
        ans=next_town
    else:
        for i in range((K-span)%roop):
            next_town = TO[next_town-1]
        ans=next_town

print(ans)
n = int(input())
s = input()

if(s[:n/2-1] == s[n/2:]):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

n = int(input())
s = input()

if n % 2 == 1:
  print("No")
elif s[:(int)(n/2)] == s[(int)(n/2):]:
  print("Yes")
else:
  print("No")
a, b, h, m = input().split()

a, b, h, m = int(a, b, h, m)

#長針は60分で一周、短針は720分で一周
#長針は1分で6、短針は1分で0.5 合わせて5.5度離れる

min = (60 * h) + m
ang0 = (min * 5.5) % 360

if ang0 <= 180:
    ang = ang0
else:
    ang = 360 - ang0

import math
cos_ang = math.cos(math.radians(ang))

x = math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * cos_ang))

print(x)


### FIXED CODE ###

a, b, h, m = input().split()

a = int(a)
b = int(b)
h = int(h)
m = int(m)

#長針は60分で一周、短針は720分で一周
#長針は1分で6、短針は1分で0.5 合わせて5.5度離れる

min = (60 * h) + m
ang0 = (min * 5.5) % 360

if ang0 <= 180:
    ang = ang0
else:
    ang = 360 - ang0

import math
cos_ang = math.cos(math.radians(ang))

x = math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * cos_ang))

print(x)
i=R*6.28318530717958623200
print(i)

### FIXED CODE ###

R=int(input())
i=R*6.283184
print(i)
mod = 10**9+7
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]

def fib(n):
    if (n==1) or (n==2):
        return 1
    else:
        return fib(n-1)+fib(n-2)

start = 0
ans = 1

for k in a:
    tmp = k-start
    if tmp==0:
        print(0)
        exit(0)
    ans *= fib(tmp)
    ans%=mod
    start = k+1

ans*=fib(n-start+1)
ans%=mod

print(ans)

### FIXED CODE ###

import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
a = [INT() for _ in range(m)]

# 高速版
def fib(n):
    if n <= 1:
        return n
    result = [1, 0, 0, 1]
    matrix = [1, 1, 1, 0]
    while n > 0:
        if n % 2:
            result = mul(matrix, result)
        matrix = mul(matrix, matrix)
        n //= 2
    return result[2]

def mul(a, b):
    return [a[0]*b[0] + a[1]*b[2],
            a[0]*b[1] + a[1]*b[3],
            a[2]*b[0] + a[3]*b[2],
            a[2]*b[1] + a[3]*b[3]]

start = 0
ans = 1

for k in a:
    tmp = k-start
    if tmp==0:
        print(0)
        exit(0)
    ans *= fib(tmp)
    ans%=MOD
    start = k+1

ans*=fib(n-start+1)
ans%=MOD

print(ans)
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
# 文字列の入力
X = input()
one = 0
intX = 0
bitnow = 1
for i in reversed(range(len(X))):
    if X[i] == '1':
        one += 1
        intX += bitnow
    bitnow *= 2
hi = one + 1
lo = one - 1
hirembase = intX % hi
lorembase = intX % lo
# print(intX)
# print(hi)
# print(lo)
# print(hirembase)
# print(lorembase)
bo = []
for i in range(200010):
    num = 0
    while i != 0:
        bit = bin(i)
        bitnum = 0
        for j in range(len(bit)):
            if j == 0 or j == 1:
                continue
            if bit[j] == '1':
                bitnum += 1
        i = i % bitnum
        num += 1
    bo.append(num)
ans = []
hirem = 1
lorem = 1
for i in reversed(range(len(X))):
    if X[i] == '0':
        num = (hirembase + hirem + hi) % hi
        ans.append(bo[num] + 1)
    else:
        if one == 1:
            ans.append(0)
        else:
            num = (lorembase - lorem + lo) % lo
            ans.append(bo[num] + 1)
    hirem = (hirem * 2) % hi
    lorem = (lorem * 2) % lo
# print(ans)
# 出力
for i in reversed(range(len(ans))):
    print(ans[i])

### FIXED CODE ###

# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
# 文字列の入力
X = input()
one = 0
intX = 0
bitnow = 1
for i in reversed(range(len(X))):
    if X[i] == '1':
        one += 1
        intX += bitnow
    bitnow *= 2
hi = one + 1
lo = one - 1
hirembase = intX % hi
lorembase = 0
if lo != 0:
    lorembase = intX % lo
# print(intX)
# print(hi)
# print(lo)
# print(hirembase)
# print(lorembase)
bo = []
for i in range(200010):
    num = 0
    while i != 0:
        bit = bin(i)
        bitnum = 0
        for j in range(len(bit)):
            if j == 0 or j == 1:
                continue
            if bit[j] == '1':
                bitnum += 1
        i = i % bitnum
        num += 1
    bo.append(num)
ans = []
hirem = 1
lorem = 1
for i in reversed(range(len(X))):
    if X[i] == '0':
        num = (hirembase + hirem + hi) % hi
        ans.append(bo[num] + 1)
    else:
        if one == 1:
            ans.append(0)
        else:
            num = (lorembase - lorem + lo) % lo
            ans.append(bo[num] + 1)
    hirem = (hirem * 2) % hi
    if one != 1:
        lorem = (lorem * 2) % lo
# print(ans)
# 出力
for i in reversed(range(len(ans))):
    print(ans[i])
from math import gcd
def lcm(x,y):
    return (x*y)//gcd(x,y)
n=int(input())
t=int(input())
for i in range(n-1):
    t=lcm(t,int(input()))
print(t)

### FIXED CODE ###

def gcd(x,y):
    while y!=0:
        x,y=y,x%y
    return x
def lcm(x,y):
    return (x*y)//gcd(x,y)
n=int(input())
t=int(input())
for i in range(n-1):
    t=lcm(t,int(input()))
print(t)
x=int(input())
ans=0
for i in range(1000):
   if i*100<=x<=105*i:
       ans=1
print(ans)

### FIXED CODE ###

M1,D1=map(int,input().split())
M2,D2=map(int,input().split())
if D2==1:
    print(1)
else:
    print(0)
a,b = map(int,input().split())
c_li = []
array = []
for i in range(1,max(a,b)):
    if a%i==0 and b%i == 0:
        c_li.append(i)
for i in range(2, max(c_li)):
    sosu = True
    for n in range(2, i):
        if i % n == 0:
            sosu = False
            break
            # 割り切れる場合（素数ではない場合）
            # 一回でも何かの数値で割り切れたら素数ではない
    if sosu:
        array.append(i)
array.insert(0,1)
s_array = set(array)
s_cli = set(c_li)
s_intersection = s_array & s_cli
print(len(s_intersection))



### FIXED CODE ###

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def fact(n):
    b = 2
    li = []
    li.insert(0,1)
    while b*b<=n:
        while n%b == 0:
            n = n//b
            li.append(b)
        b+=1
    if n>1:
        li.append(n)

    return li
a,b = map(int,input().split())
c = gcd(a,b)
ans = set(fact(c))
print(len(ans))
from operator import mul
from functools import reduce

def nCr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    # reduceは第一引数で与えた関数を第二引数のiterbleのそれぞれで実行した結果をもどす
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under



MOD = 10**9+7
N,K = map(int, input().split())

for i in range(1, K+1):
    blue = nCr(K-1, i-1)
    red = nCr(N-K+1, i)
    print(blue*red%MOD)

### FIXED CODE ###

N, K = map(int, input().split())

def nCr(n,r):
  if n < 0 or r < 0 or n < r: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  
  # 分子のn*(n-1)*...がr個分続くやつ
  numerator = [n-r+k+1 for k in range(r)]
  # 分母：r!=r*(r-1)*...*3*2の要素
  denominator = [k+1 for k in range(r)]
  
  # 分母の要素で割れる部分を割っていく部分
  for p in range(2, r+1):
    # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か
    pivot = denominator[p-1]
    if pivot > 1:
      # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか
      offset = (n-r) % p
      for k in range(p-1, r, p):
        # 約分できる要素について割る
        numerator[k - offset]  /= pivot
        denominator[k] /= pivot
        
  ret = 1
  for k in range(r):
    if numerator[k] > 1: ret *= int(numerator[k])
      
  return ret

def nPr(n,r):
    tmp = 1
    for i in range(n,n-r,-1):
        tmp *= i
    return tmp

for i in range(1, K+1):
    sukima = nCr(N-K+1, i)
    p = nPr(K-1, i-1) // nPr(i-1, i-1)
    print(sukima*p%(10**9+7))
import sys

for line in sys.stdin:
    x1, y1, x2, y2 = line.strip('\n')
    x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
    print ((x1-x2)**2+(y1-y2)**2)**0.5

### FIXED CODE ###

x1, y1, x2, y2 = map(float, raw_input().split())
print ((x1-x2)**2 + (y1-y2)**2)**0.5
N, M = map(int,input().split())
P=[]
Y=[]
cities=[]
for i in range(M):
    try:
        s = input()
        p,y = s.split()
        city=(p,y)
        cities.append(city) 
        P.append(p)
        Y.append(y)

    except:
        break
sort_city=sorted(cities,key=lambda x:(x[0],x[1]))
prefs = sorted(set(P))

address=[]
res=[]
for i in range(len(sort_city)): 
    address=str(sort_city[i][0]).rjust(6,'0')+str(i+1).rjust(6,'0')
    res.append((sort_city[i],address))

print(res[1][0])
for i in range(len(cities)):
    for j in range(len(res)):
        if cities[i] == res[j][0]:
            print(res[j][1])


### FIXED CODE ###

n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
s=[]
for i in enumerate(l):
    s.append(i)
s=sorted(s,key=lambda x:(x[1][0],x[1][1]))
a=0
for i in range(m):
    if s[i][1][0]==0:
       a=1     
    elif s[i][1][0]==s[i-1][1][0]:
        a+=1
    elif s[i][1][0]!=s[i-1][1][0]:
        a=1
    s[i][1][1]=a
s = sorted(s,key=lambda x:x[0])
for i in s:
    print('%06d'%i[1][0]+'%06d'%i[1][1])
N, K = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
visited = [-1] * N
visited[0] = 0
next = A[0]
for i in range(1, K+1):
    present = next
    visited[present - 1] = i

    next = A[present - 1]
    if visited[next - 1] != -1:
        loopLength = visited[present - 1] - visited[next - 1] + 1
        cnt = i
        rest = (K - cnt) % loopLength
        present = visited.index(visited[next - 1] + rest - 1)
        break

print(present)


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [-1] * N
visited[0] = 0
next = A[0]
for i in range(1, K+1):
    present = next
    visited[present - 1] = i

    next = A[present - 1]
    if visited[next - 1] != -1:
        loopLength = visited[present - 1] - visited[next - 1] + 1
        rest = (K - i) % loopLength
        if rest > 0:
            present = visited.index(visited[next - 1] + rest - 1) + 1
        break

print(present)
class gv:
    input:str = None;
    
def build():
    gv.str = input()

def solve():
    slen = len(gv.str)
    if (slen&1) == 1:
        print("No")
        return
    
    for i in range(0,slen,2):
        if (gv.str[i:i+2] == "hi") :
            pass
        else :
            print("No")
            return
    
    print("Yes")
    
    

if __name__ == '__main__':
    build()
    solve()


### FIXED CODE ###

class gv:
    input = None;
    
def build():
    gv.str = input()

def solve():
    slen = len(gv.str)
    if (slen&1) == 1:
        print("No")
        return
    
    for i in range(0,slen,2):
        if (gv.str[i:i+2] == "hi") :
            pass
        else :
            print("No")
            return
    
    print("Yes")
    
    

build()
solve()
def wa(h, w, f):
    if not (0 <= h <= H-1 and 0 <= w <= W-1):
        return
    elif mapp[h][w] != f:
        return
    else:
        mapp[h][w] = '$'
        wa(h, w+1, f)
        wa(h-1, w, f)
        wa(h, w-1, f)
        wa(h+1, w, f)

while True:
    H, W = map(int, raw_input().split(' '))
    if H == 0: break
    mapp = [list(raw_input()) for i in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if mapp[h][w] == '@':
                wa(h, w, '@')
            elif mapp[h][w] == '#':
                wa(h, w, '#')
            elif mapp[h][w] == '*':
                wa(h, w, '*')
            else:
                continue
            count += 1
    else:
        print count

### FIXED CODE ###

import sys
sys.setrecursionlimit(20000)
def wa(h, w, f):
    if not (0 <= h < H and 0 <= w < W):
        return
    elif mapp[h][w] != f:
        return
    else:
        mapp[h][w] = '$'
        wa(h, w+1, f)
        wa(h-1, w, f)
        wa(h, w-1, f)
        wa(h+1, w, f)

while True:
    H, W = map(int, raw_input().split())
    if H == 0 and W == 0: break
    mapp = [list(raw_input()) for i in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if mapp[h][w] == '@':
                count += 1
                wa(h, w, '@')
            elif mapp[h][w] == '#':
                count += 1
                wa(h, w, '#')
            elif mapp[h][w] == '*':
                count += 1
                wa(h, w, '*')
    else:
        print count
a_list=list(int,input().split())
ans=abs(a[0]-a[1])+abs(a[0]-a[2])
ans=min(ans,abs(a[1]-a[0])+abs(a[1]-a[2]))
ans=min(ans,abs(a[2]-a[1])+abs(a[0]-a[2]))
print(ans)

### FIXED CODE ###

a=list(map(int,input().split()))
ans=abs(a[0]-a[1])+abs(a[0]-a[2])
ans=min(ans,abs(a[1]-a[0])+abs(a[1]-a[2]))
ans=min(ans,abs(a[2]-a[1])+abs(a[0]-a[2]))
print(ans)
a,b,c = map(int, input().split())
print i for i in range(a,b+1):
    if c % i == 0

### FIXED CODE ###

a,b,c = map(int,input().split())
count = 0
for i in range(a,b+1):
    d = c % i
    if d == 0:
        count += 1
print (count)
k, s = map(int, input().split())
count = 0

for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i + j + l == s:
                count += 1

print(count)

### FIXED CODE ###

n, a, b = map(int, input().split())
total = 0


def calc(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n = n // 10
    return sum

for i in range(n+1):
    if a <= calc(i) & calc(i) <= b:
        total += i

print(total)
import math
n = int(input())
lcmn = 1
def lcm(a, b):
    return a*b//math.gcd(a, b)
for _ in range(n):
    t = int(input())
    lcmn = lcm(lcmn, t)
print(lcmn)

### FIXED CODE ###

n = int(input())
lcmn = 1
def gcd(a, b):
    while b!=0:
        a, b = b, a%b
    return a
def lcm(a, b):
    return a*b//gcd(a, b)
for _ in range(n):
    t = int(input())
    lcmn = lcm(lcmn, t)
print(lcmn)
n, a, b = map(int, input().split())

ans = []
for i in range(1,n+1):
    # i = 12
    num = 0
    while i != 0:
        num +=i%10
        i = i//10
    if a <= num <= b:
        ans.append(i)
print(ans.sum())

### FIXED CODE ###

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

ans = []
for i in range(1,n+1):
    num = 0
    for j in str(i):
        num += int(j)
    if a <= num <= b:
        ans.append(i)
print(sum(ans))
from bisect import bisect_right

n = int(input())
x = list(map(int, input().split()))
l = int(input())

depth = [-1]*n
depth[-1] = 0

m = 18
par = [[-1]*n for i in range(m)]

def dfs(i):
    if depth[i] >= 0:
        return depth[i]
    j = bisect_right(x, x[i]+l)-1
    if j >= n:
        j = n-1
    par[0][i] = j
    depth[i] = dfs(j) + 1
    return depth[i]

for i in range(n):
    dfs(i)

for i in range(17):
    for j in range(n):
        par[i+1][j]=par[i][par[i][j]]

def hoge(x, y):
# xからk個上の頂点がy以上になる最小のkを求める
    k = 0
    for i in range(18)[::-1]:
        if 0 <= par[i][x] <= y:
            k += 1<<i
            x = par[i][x]
    return k

q = int(input())
ans = []
for i in range(q):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    if a > b:
        a,b = b,a
    ans.append(hoge(a, b))

print(*ans, sep="\n")

### FIXED CODE ###

import sys
input = sys.stdin.readline

from bisect import bisect

n = int(input())
x = list(map(int, input().split()))
l = int(input())

m = 20
par = [[-1]*n for i in range(m)]

for i in range(n):
    j = bisect(x, x[i]+l)-1
    par[0][i] = j

for i in range(m-1):
    for j in range(n):
        par[i+1][j]=par[i][par[i][j]]

def hoge(x, y):
    k = 0
    for i in range(m)[::-1]:
        if par[i][x] < y:
            k += 1<<i
            x = par[i][x]
    return k+1

q = int(input())
ans = []
for i in range(q):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    if a > b:
        a,b = b,a
    print(hoge(a,b))
def __init__ (self,data):
        self.data = data

class Dice:
    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[4],elf.data[5],self.data[1],self.data[0]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
    print(dice.getTop())

### FIXED CODE ###

class Dice:
    def __init__ (self,data):
        self.data = data

    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())