Harryxun/stf_run huggingface dataset:
n = input()
A = map(int, raw_input().split())

Q = input()
m = map(int, raw_input().split())

f = []
f[1] = 1

for i in range(n):
  for j in range(2000):
    if(j + A < 2000 && f[j] == 1):
      f[j + A] == 1
    
for i in range(Q):
    if(f[m - 1] == 1):
      print "yes"
    else:
      print "no"

### FIXED CODE ###

n = int(raw_input())
A = map(int,raw_input().split())
Q = int(raw_input())
m = map(int,raw_input().split())

def s(i, m):
  if m == 0:
    return True
  if i >= n or m > sum(A):
    return False
  r = s(i + 1, m) or s(i + 1, m - A[i])
  return r

for j in range(Q):
  if s(0, m[j]):
    print "yes"
  else:
    print "no"
a, b =(int, input().split())
if 13 <= a:
  print(b)
elif 6 <= a <= 12:
  print(b//2)
else:
  print(0)

### FIXED CODE ###

a,b=map(int, input().split())
if a <= 5:
    print(0)
elif 6 <= a <= 12:
    print(b//2)
else:
    print(b)
if __name__ == '__main__':
    # We have a string S of length N consisting of uppercase English letters.
    temp = input().split('\n')
    n = temp[0]
    s = temp[1]
    num = 0
    if 'ABC' in s:
        num += 1
        s = s.replace('ABC', '')
    print(num)

### FIXED CODE ###

if __name__ == '__main__':
    # We have a string S of length N consisting of uppercase English letters.
    n = input()
    s = input()
    num = 0
    for i in range(len(s)):
        if 'ABC' in s:
            num += 1
            s = s.replace('ABC', '', 1)
    print(num)
a,b,c,d=map(int,input().split())
x=float(a/d)
y=float(c/b)

if x>=y:
  print("yes")
else:
  print("no")

### FIXED CODE ###

s,w=map(int,input().split())
if s <= w:
    print("unsafe")
else:
    print("safe")
import math
jishin, hunshin, hour, minute = map(float, input().split())

x_ji = jishin * math.cos(math.radian(hour * 360 / 12))
y_ji = jishin * math.sin(math.radian(hour * 360 / 12))
x_hun = hunshin  * math.cos(math.radian(minute * 360 / 60))
y_hun = hunshin  * math.sin(math.radian(minute * 360 / 60))

kyori = math.sqrt((x_ji - x_hun) ** 2 + (y_ji - y_hun) ** 2)
print(kyori)


### FIXED CODE ###

import math
jishin, hunshin, hour, minute = map(float, input().split())

x_ji = jishin * math.cos(math.radians((hour + minute / 60) * 360 / 12))
y_ji = jishin * math.sin(math.radians((hour + minute / 60) * 360 / 12))
x_hun = hunshin  * math.cos(math.radians(minute * 360 / 60))
y_hun = hunshin  * math.sin(math.radians(minute * 360 / 60))

kyori = math.sqrt((x_ji - x_hun) ** 2 + (y_ji - y_hun) ** 2)
print(kyori)
N, Y = map(int, input().split())
# x:10000円, y;5000円, z:1000円
for x in range(N+1):
    for y in range(N-x+1):# 5000円の枚数をN-(10000円の枚数)までに制限
        for z in range(N-x-y-1):
            if 10000*x + 5000*y + 1000*z == Y:
                print(x, y, z)
                exit(0)
print(-1, -1, -1)

### FIXED CODE ###

S = input()
print("2018"+S[4::])
n,m=list(map(int,input().split()))

H=list(map(int, input().split()))
A = [input().split() for l in range(n-1)]

li = []

for a,b in A:
    if H[int(a)-1]<H[int(b)-1]:
        li.append((a,0))
    elif H[int(a)-1]>H[int(b)-1]:
        li.append((b,0))
    else:
        li.append((a,0))
        li.append((b,0))

di=dict(li)
print(n-len(di))
        

### FIXED CODE ###

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

H=list(map(int, input().split()))
A = [input().split() for l in range(m)]

li = []

for a,b in A:
    if H[int(a)-1]<H[int(b)-1]:
        li.append((a,0))
    elif H[int(a)-1]>H[int(b)-1]:
        li.append((b,0))
    else:
        li.append((a,0))
        li.append((b,0))


di=dict(li)
print(n-len(di))
i = 0
while(True):
    print("Case %d: %s" % (i+1, input()))
    i+=1


### FIXED CODE ###

i = 0
while(True):
    s = input()
    if(s == '0'):
        break
    print("Case %d: %s" % (i+1, s))
    i+=1
from collections import defaultdict
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]
dict = defaultdict(int)
for a in A:
    dict[a] += 1

mod = 10 ** 9 + 7
dp = [0 for _ in range(N+1)]
dp[0] = 1
dp[1] = 1 if dict[1] == 0 else dp[1] = 0
for i in range(1, N):
    if dict[i] == 0 and dict[i-1] == 0:
        dp[i+1] += ((dp[i-1] + dp[i]) % mod)
    elif dict[i] == 0:
        dp[i+1] += (dp[i] % mod)
    elif dict[i-1] == 0:
        dp[i+1] += (dp[i-1] % mod)

print(dp[-1])

### FIXED CODE ###

from collections import defaultdict
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]
dict = defaultdict(int)
for a in A:
    dict[a] += 1

mod = 10 ** 9 + 7
dp = [0 for _ in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(1, N):
    if dict[i] == 0 and dict[i-1] == 0:
        dp[i+1] += ((dp[i-1] + dp[i]) % mod)
    elif dict[i] == 0:
        dp[i+1] += (dp[i] % mod)
    elif dict[i-1] == 0:
        dp[i+1] += (dp[i-1] % mod)

print(dp[-1])
import sys
sys.setrecursionlimit(1000000)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
n = I()

def primes(n):
    cnt = defaultdict(int)
    for i in range(2,int(n**0.5)+1): # range(3)だと、0,1,2が出てくる。
        while n % i == 0:
            cnt[i] += 1 # 同じ素数で何回割れるか辞書型で登録しておく
            n //= i # iで割り切った商で更新しておく
    if n > 1: # nの平方根より大きい値があった場合、追加
        cnt[n] += 1
    return cnt

prs = primes(n) #　素数の辞書
l = 0
ans = 0
for key in prs.keys(): #辞書から素数を抽出して、その素数の指数値をvとして格納する。
    v = prs[key]
    for i in range(100):
        if (i * (i+1)) // 2 <= v:
            ans += (i)
print(ans)


### FIXED CODE ###

a,b = map(int, input().split())
c = a * b
print(c)
h, w = map(int, input().split())
s = list(input() for _ in range(h))

yoko = [[0]*w for _ in range(h)]
tate = [[0]*w for _ in range(h)]


def yoko_check(y, x, cnt):
    global yoko, s
    if x == w-1:
        yoko[y][x] = cnt
        return cnt
    else:
        if s[y][x+1] == "#":
            yoko[y][x] = cnt
            return cnt
        else:
            yoko[y][x] = yoko_check(y, x+1, cnt+1)
            return yoko[y][x]


def tate_check(y, x, cnt):
    global tate, s
    if y == h-1:
        tate[y][x] = cnt
        return cnt
    else:
        if s[y+1][x] == "#":
            tate[y][x] = cnt
            return cnt
        else:
            tate[y][x] = tate_check(y+1, x, cnt+1)
            return tate[y][x]


for y in range(h):
    for x in range(w):
        if yoko[y][x] == 0 and s[y][x] == ".":
            yoko_check(y, x, 1)
        if tate[y][x] == 0 and s[y][x] == ".":
            tate_check(y, x, 1)

# print(tate)

result = 0
for y in range(h):
    for x in range(w):
        if s[y][x] == ".":
            result = max(result, tate[y][x]+yoko[y][x]-1)

print(result)


### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
 
h,w=map(int,input().split())
s=list(input() for _ in range(h))
 
yoko=[[0]*w for _ in range(h)]
tate=[[0]*w for _ in range(h)]
 
def yoko_check(y,x,cnt):
    global yoko,s
    if x==w-1:
        yoko[y][x]=cnt
        return cnt
    else:
        if s[y][x+1]=="#":
            yoko[y][x]=cnt
            return cnt
        else:
            yoko[y][x]=yoko_check(y,x+1,cnt+1)
            return yoko[y][x]
 
 
def tate_check(y,x,cnt):
    global tate,s
    if y==h-1:
        tate[y][x]=cnt
        return cnt
    else:
        if s[y+1][x]=="#":
            tate[y][x]=cnt
            return cnt
        else:
            tate[y][x]=tate_check(y+1,x,cnt+1)
            return tate[y][x]
 
 
for y in range(h):
    for x in range(w):
        if yoko[y][x]==0 and s[y][x]==".":
            yoko_check(y,x,1)
        if tate[y][x]==0 and s[y][x]==".":
            tate_check(y,x,1)
 
#print(tate)
 
result=0
for y in range(h):
    for x in range(w):
        if s[y][x]==".":
            result=max(result,tate[y][x]+yoko[y][x]-1)  
 
print(result)
def is_palindrome(str):
  i, j = 0, len(str)-1
  while i != j:
    if str[i] != str[j]:
      return False
    i += 1
    j -= 1

  return True

s = input()
n = len(s)
if is_palindrome(s) and is_palindrome(s[0:((n-1)//2)]) and is_palindrome(s[(n+3)//2-1:n]):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

def is_palindrome(str):
  i, j = 0, len(str)-1
  while i <= j:
    if str[i] != str[j]:
      return False
    i += 1
    j -= 1

  return True

s = input()
n = len(s)
if is_palindrome(s) and is_palindrome(s[0:((n-1)//2)]) and is_palindrome(s[(n+3)//2-1:]):
  print("Yes")
else:
  print("No")
MOD = 998244353
FACT_MAX = 2 * 10 ** 5
fact = [(f := 1 if not i else (f := f * i % MOD)) for i in range(FACT_MAX)]
def comb(n, r):
    return fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD) % MOD
N, M, K = map(int, input().split())
total = 0
for k in range(K + 1):
    total = (total + comb(N - 1, k) * M * pow(M - 1, N - k - 1, MOD)) % MOD
print(total)

### FIXED CODE ###

MOD = 998244353
FACT_MAX = 2 * 10 ** 5
fact = [1] * FACT_MAX
for i in range(1, FACT_MAX):
    fact[i] = fact[i - 1] * i % MOD
def comb(n, r):
    return fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD) % MOD
N, M, K = map(int, input().split())
total = 0
for k in range(K + 1):
    total = (total + comb(N - 1, k) * M * pow(M - 1, N - k - 1, MOD)) % MOD
print(total)
children = list(map(int,input().split())) 
children.sort()
count=0
c = 0
if x < children[0]:
  print(0)
  exit()
for i in range(n):
  count += children[i]
  c += 1
  if count == x:
    print(c)
    exit()
  elif count > x:
    print(c-1)
    exit()

print(n-1)

### FIXED CODE ###

n, x = map(int,input().split())
children = list(map(int,input().split())) 
children.sort()
count=0
c = 0
if x < children[0]:
  print(0)
  exit()
for i in range(n):
  count += children[i]
  c += 1
  if count == x:
    print(c)
    exit()
  elif count > x:
    print(c-1)
    exit()

print(n-1)
import sys
raw_input = sys.stdin.readline
N,K = map(int,raw_input().split())
nums = list(map(int,raw_input().split()))
dp = [10000000000 for x in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(K):
        if i+j+1 < N:
            dp[i+j+1] = min(dp[i]+abs(nums[i]-nums[i+j+1]),dp[i+j+1])
print dp[N-1]

### FIXED CODE ###

N = int(raw_input())
nums = list(map(int,raw_input().split()))
dp = [10000000000 for x in range(N)]
dp[0] = 0
for i in range(N):
    if i<N-1:
        dp[i+1] = min(dp[i+1],dp[i]+abs(nums[i+1]-nums[i]))
    if i<N-2:
        dp[i+2] = min(dp[i+2],dp[i]+abs(nums[i+2]-nums[i]))
print dp[N-1]
#abc106c
import sys

s=raw_input()
k=int(raw_input())
while True:
 if s:
  if s[0]=='1':
   s=s[1:]
  print s[0]
  sys.exit()
 else:
  print '1'
  sys.exit()


### FIXED CODE ###

#abc106c
import sys

s=raw_input()
k=int(raw_input())
if s.count('1')==len(s):
 print '1'
 sys.exit()
for i in xrange(k):
 if s[i]!='1':
  print s[i]
  sys.exit()
print '1'
import itertools
import heapq
from heapq import heappush, heappop
global G

def input_graph(N, xy):
  comb_list = list(itertools.combinations(xy, 2))
  for i in range(N*(N-1)//2):
    a, b = comb_list[i]
    an, ax, ay = a 
    bn, bx, by = b 
    cost = min(abs(ax-bx), abs(ay-by))
    G[an] += [(cost, bn)]
    G[bn] += [(cost, an)]

def prim(V):
  global G, used 
  edgelist = []
  for e in G[0]:
    heappush(edgelist, e)
  used[0] = True
  res = 0
  while edgelist:
    minedge = heappop(edgelist)
    if used[minedge[1]]:
      continue 
    v = minedge[1]
    used[v] = True 
    for e in G[v]:
      if not used[e[1]]:
        heappush(edgelist, e)
    res += minedge[0]
  return res

def main():
  global G, used
  N = int(input())
  xy = []
  for i in range(N):
    xy += [[i, *list(map(int, input().split()))]]
  G = [[] for _ in range(N)]
  used = [False for _ in range(N)]
  input_graph(N, xy)
  print(prim(N))

if __name__ == "__main__":
  main()

### FIXED CODE ###

import itertools
import heapq
from heapq import heappush, heappop
global G, inp_x, inp_y

def input_graph(N):
  global G, inp_x, inp_y
  inp_x = []
  inp_y = []
  for i in range(N):
    x, y = map(int, input().split())
    inp_x.append((x, i))
    inp_y.append((y, i))
  inp_x.sort()
  inp_y.sort()
  for i in range(N-1):
    xa = inp_x[i][1]
    xb = inp_x[i+1][1]
    ya = inp_y[i][1]
    yb = inp_y[i+1][1]
    cost_x = abs(inp_x[i][0]-inp_x[i+1][0])
    cost_y = abs(inp_y[i][0]-inp_y[i+1][0])
    G[xa] += [(cost_x, xb)]
    G[xb] += [(cost_x, xa)]
    G[ya] += [(cost_y, yb)]
    G[yb] += [(cost_y, ya)]

  
def prim(V):
  global G, used
  edgelist = []
  for e in G[0]:
    heappush(edgelist, e)
  used[0] = True
  res = 0
  while edgelist:
    minedge = heappop(edgelist)
    if used[minedge[1]]:
      continue 
    v = minedge[1]
    used[v] = True 
    for e in G[v]:
      if not used[e[1]]:
        heappush(edgelist, e)
    res += minedge[0]
  return res

def main():
  global G, used
  N = int(input())
  G = [[] for _ in range(N)]
  used = [False for _ in range(N)]
  input_graph(N)
  print(prim(N))

if __name__ == "__main__":
  main()
A=int(input())
B=int(input())
C=int(input())
if  A==B and A!=C:
  print('Yes')
if  A==C and A!=B: 
  print('Yes')
if  B==C and B!=A: 
  print('Yes')
else: 
  print('No')

### FIXED CODE ###

A,B,C = input().split()
if A==B and A!=C or B==C and B!=A or C==A and C!=B:
    print("Yes")
else:
    print("No")
H,W = map(int,raw_input().split())

s = []
for i in range(H):
  s.append(raw_input())

flag=True
for i in range(H):
  for j in range(W):

    if s[i][j]=='#':
    	local_flag=False
		if i+1<H:
          if s[i+1][j]=='#':
            local_flag=True
        if j+1<W:
          if s[i][j+1]=='#':
            local_flag=True
        if i-1>=0:
          if s[i-1][j]=='#':
            local_flag=True
        if j-1>=0:
          if s[i][j-1]=='#':
            local_flag=True
        if local_flag=False:
          flag=False
if flag:
  print 'Yes'
else:
  print 'No'

### FIXED CODE ###

H,W = map(int,raw_input().split())
 
s = []
for i in range(H):
	s.append(raw_input())
 
flag=True
for i in range(H):
	for j in range(W):
		if s[i][j]=='#':
			local_flag=False
			if i+1<H:
				if s[i+1][j]=='#':
					local_flag=True
			if j+1<W:
				if s[i][j+1]=='#':
					local_flag=True
			if i-1>=0:
				if s[i-1][j]=='#':
					local_flag=True
			if j-1>=0:
				if s[i][j-1]=='#':
					local_flag=True
			if local_flag==False:
				flag=False
if flag:
	print 'Yes'
else:
	print 'No'
MOD = 10 ** 9 +7

n, m =map(int,input().split())

div = []

for i in range(1,int(m ** (1/2)) + 1):
    if m % i == 0:
        div.append(i)
        div.append(m//i)

memo = [{} for _ in range(m+1)]
def count(k,n):
    if n == 1:
        return 1
    if n in memo[k]:
        return memo[k][n]
    ret = 0
    for x in div:
        if k % x == 0:
            ret = (ret + count(k//x,n-1)) % MOD
    memo[k][n] = ret
    return ret

print(count(m,n))



### FIXED CODE ###

n,m = map(int,input().split())
mod = 10 ** 9 + 7

def combo(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    else:
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod



N = n + 100
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#print(combo(2,1))

#print(m)
fac = {}
mm = m
#print(mm)
count = 0
while mm % 2 == 0:
    count += 1
    mm //= 2
if count > 0:
    fac[2] = count
f = 3
count = 0
while f ** 2 <= mm:
    while mm % f == 0:
        count += 1
        mm //= f
        #print(f,count)
    if count > 0:
        fac[f] = count
        count = 0
    f += 2
    #print(fac)
if mm != 1:
    if mm in fac:
        fac[mm] += 1
    else:
        fac[mm] = 1
#print(fac)

count = 1

for i in fac:
    if fac[i] >= 1:
        count = (count * combo(fac[i]+n-1,fac[i],mod)) % mod
    #print(count)
    
print(count)
n, m = input().split()
N = int(n)
K = int(m)

S = input()

string = list(S)

string[K+1] = string[K+1].lower()

print(''.join(string))


### FIXED CODE ###

n, m = input().split()
N = int(n)
K = int(m)

S = input()

string = list(S)

string[K-1] = string[K-1].lower()

print(''.join(string))
import sys
import bisect
n = int(sys.stdin.readline().strip())
s = list(sys.stdin.readline().strip())
alpha = "abcdefghijklmnopqrstuvwxyz"
dict = {i:[] for i in alpha}
for i, _s in enumerate(s):
    dict[_s].append(i)
q = int(sys.stdin.readline().strip())
for i in range(q):
    type, first, last = [i for i in sys.stdin.readline().split()]
    if type == "2":
        first = int(first)
        last = int(last)
        first -= 1
        last -= 1
        cnt = 0
        for ls in dict.values():
            if bisect.bisect_left(ls, first) != bisect.bisect_right(ls, last):
                cnt += 1
        print(cnt)
    else:
        _s = s[first]
        first = int(first)
        first -= 1
        dict[_s].pop(bisect.bisect_left(dict[_s], first))
        s[first] = last
        bisect.insort_left(dict[last], first)

### FIXED CODE ###

import sys
import bisect
n = int(sys.stdin.readline().strip())
s = list(sys.stdin.readline().strip())
alpha = "abcdefghijklmnopqrstuvwxyz"
dict = {i:[] for i in alpha}
for i, _s in enumerate(s):
    dict[_s].append(i)
q = int(sys.stdin.readline().strip())
for i in range(q):
    type, first, last = [i for i in sys.stdin.readline().split()]
    if type == "2":
        first = int(first)
        last = int(last)
        first -= 1
        last -= 1
        cnt = 0
        for ls in dict.values():
            if bisect.bisect_left(ls, first) != bisect.bisect_right(ls, last):
                cnt += 1
        print(cnt)
    else:
        first = int(first)
        first -= 1
        _s = s[first]
        if _s == last:
            continue
        del dict[_s][(bisect.bisect_left(dict[_s], first))]
        s[first] = last
        bisect.insort_left(dict[last], first)
import math
k=input()
s=0
for x in range(1,k+1):
  for y in range(1,k+1):
    for z in range(1,k+1):
      s+=math.gcd(x,gcd(y,z))
print(s)

### FIXED CODE ###

import math
k=int(input())
l=[]
s=0
for x in range(1,k+1):
  for y in range(1,k+1):
    l.append(math.gcd(x,y))

for x in range(len(l)):
  for y in range(1,k+1):
    s+=math.gcd(l[x],y)
print(s)
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, M = read_ints()
S = read()[:-1]
S = S[::-1]
ans = []
cur_i = 0
while True:
    dice = M
    cur_i += dice
    if cur_i > N + 1:
        ans.append(N - (cur_i - M))
        break
    if cur_i = N = 1:
        break
    while S[cur_i] == '1':
        cur_i -= 1
        dice -= 1
        if dice == 0:
            print(-1)
            exit()
    ans.append(dice)
print(*ans[::-1])


### FIXED CODE ###

# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, M = read_ints()
S = read()[:-1]
S = S[::-1]
ans = []
cur_i = 0
while True:
    dice = M
    cur_i += dice
    if cur_i > N:
        if N - (cur_i - M) == 0:
            pass
        else:
            ans.append(N - (cur_i - M))
        break
    # if cur_i == N + 1:
    #     ans.append(cur_i - N)
    #     break
    while S[cur_i] == '1':
        cur_i -= 1
        dice -= 1
        if dice == 0:
            print(-1)
            exit()
    ans.append(dice)
print(*ans[::-1])
A=input()
B=input()
C=input()
t=[0,0,0]
flag="a"
while True:
  if flag=="a":
    if len(A)==t[0]+1:
      print("A")
      break
    else:
      flag=A[t[0]]
      t[0]+=1
  elif flag=="b":
    if len(B)==t[1]+1:
      print("B")
      break
    else:
      flag=B[t[1]]
      t[1]+=1
  elif flag=="c":
    if len(C)==0:
      print("C")
      break
    else:
      flag=C[t[2]]
      t[2]+=1


### FIXED CODE ###

A=input()
B=input()
C=input()
t=[0,0,0]
flag="a"
while True:
  if flag=="a":
    if len(A)==t[0]:
      print("A")
      break
    else:
      flag=A[t[0]]
      t[0]+=1
  elif flag=="b":
    if len(B)==t[1]:
      print("B")
      break
    else:
      flag=B[t[1]]
      t[1]+=1
  elif flag=="c":
    if len(C)==t[2]:
      print("C")
      break
    else:
      flag=C[t[2]]
      t[2]+=1
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1


l1 = []
l2 = []
for key,value in D.items():
    if value > 1:
        l1.append(key)
    if value > 3:
        l2.append(key)
if len(l1) < 2:
    print(0)
    exit()
l1.sort()
l2.sort()
print(max(l1[-1]*l1[-2],l2[-1]*l2[-1]))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
l1 = []
l2 = []
for key,value in D.items():
    if value > 1:
        l1.append(key)
    if value > 3:
        l2.append(key)
if len(l1) < 2:
    print(0)
    exit()
l1.sort()
l2.sort()
if len(l2) > 0:
    print(max(l1[-1]*l1[-2],l2[-1]*l2[-1]))
else:
    print(l1[-1]*l1[-2])
# 2019-11-21 01:26:03(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r, insort_left as in_l
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 

def is_palindrome_in(s):
    s = s.replace('x', '')
    if s == ''.join(reversed(s)):
        return True
    else:
        return False

def main():
    s = sys.stdin.readline().rstrip()
    
    if not is_palindrome_in(s):
        print(-1)
        exit()

    s = collections.deque(s)
    print(s)
    count = 0
    i, j = 0, 0
    while i < len(s) - 1 - j:
        if s[i] == 'x':
            if s[-1-j] == 'x':
                pass
            else:
                s.insert(len(s)-j, 'x')
                count += 1
        else:
            if s[-1-j] == 'x':
                s.insert(i, 'x')
                count += 1
        
        i += 1
        j += 1

    print(count)


if __name__ == "__main__":
    main()


### FIXED CODE ###

# 2019-11-21 01:26:03(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r, insort_left as in_l
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 

def is_palindrome_in(s):
    s = s.replace('x', '')
    if list(s) == list(reversed(s)):
        return True
    return False

def main():
    s = sys.stdin.readline().rstrip()
    
    if not is_palindrome_in(s):
        print(-1)
        sys.exit()
    
    s = collections.deque(s)
    
    count = 0
    while len(s) > 1:
        if s[0] == 'x':
            if s[-1] == 'x':
                s.popleft(); s.pop()
            else:
                s.popleft()
                count += 1
        else:
            if s[-1] != 'x':
                s.popleft(); s.pop()
            else:
                s.pop()
                count += 1

    print(count)

if __name__ == "__main__":
    main()