Harryxun/stf_run huggingface dataset:
n = int(input())
ai = [int(i) for i in input().split()]

is_odd = True

if n % 2 == 0:
    is_odd = False

if is_odd == True:
    dp = [[0 for i in range(3)] for j in range(n)]
else:
    dp = [[0 for i in range(2)] for j in range(n)]

if n == 3:
    print(max(ai[0],ai[2],ai[1]))
    print(ai[n+3])
    exit()
elif n == 2:
    print(max(ai[0],ai[1]))
    exit()
    

if is_odd == True:
    for i in range(n):
        dp[i][0] = dp[i-2][0]+ai[i]
        dp[i][1] = max(dp[i-2][1]+ai[i],dp[i-3][0]+ai[i])
        dp[i][2] = max(dp[i-4][0]+ai[i],dp[i-3][1]+ai[i],dp[i-2][2]+ai[i])
    print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))
else:
    for i in range(n):
        dp[i][0] = dp[i-2][0]+ai[i]
        dp[i][1] = max(dp[i-2][1]+ai[i],dp[i-3][0]+ai[i])
    print(max(dp[n-1][0],dp[n-1][1]))



### FIXED CODE ###

n = int(input())
ai = [int(i) for i in input().split()]

is_odd = True

if n % 2 == 0:
    is_odd = False

if is_odd == True:
    dp = [[0 for i in range(3)] for j in range(n)]
else:
    dp = [[0 for i in range(2)] for j in range(n)]

if n == 3:
    print(max(ai[0],ai[2],ai[1]))
    exit()
elif n == 2:
    print(max(ai[0],ai[1]))
    exit()
    

if is_odd == True:
    dp[0][0] = ai[0]
    dp[1][1] = ai[1]
    dp[2][0] = ai[0]+ai[2]
    dp[2][2] = ai[2]
    dp[3][1] = max(ai[0]+ai[3],ai[1]+ai[3])    
    for i in range(4,n):
        dp[i][0] = dp[i-2][0]+ai[i]
        dp[i][1] = max(dp[i-2][1]+ai[i],dp[i-3][0]+ai[i])
        dp[i][2] = max(dp[i-4][0]+ai[i],dp[i-3][1]+ai[i],dp[i-2][2]+ai[i])
    print(max(dp[n-3][0],dp[n-2][1],dp[n-1][2]))
else:
    dp[0][0] = ai[0]
    dp[1][1] = ai[1]
    dp[2][0] = ai[0]+ai[2]       
    for i in range(n):
        dp[i][0] = dp[i-2][0]+ai[i]
        dp[i][1] = max(dp[i-2][1]+ai[i],dp[i-3][0]+ai[i])
    print(max(dp[n-2][0],dp[n-1][1]))
import re
import math

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

n,m = map(int, input().split())
step = ['0']*(n+1)
for i in range(m):
    a = int(input())
    step[a] = '1'
steps = ''.join(step)

a = re.findall('000*', steps)
b = len(re.findall('11', steps))
# print(steps)
count = 1
for i in a:
    count *= fib(len(i)+1) % 1000000007

if b != 0:
    print(0)
else:
    print(count % 1000000007)


### FIXED CODE ###

import re
import math

def fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b

n,m = map(int, input().split())
step = ['0']*(n+1)
for i in range(m):
    a = int(input())
    step[a] = '1'
steps = ''.join(step)

a = re.findall('000*', steps)
b = len(re.findall('11', steps))
# print(steps)
count = 1
for i in a:
    count *= fib(len(i)+1) % 1000000007

if b != 0:
    print(0)
else:
    print(count % 1000000007)
n, m = map(int, input().split())
ls_ka = [[int(_) for _ in input().split()] for _ in range(n)]

ls_k = [0] * m
ls_a = [0] * m
st_ans = {_ for _ in range(1, m+1)} 

for i in range(n):
    ls_k[i] = ls_ka[i][0]
    ls_a[i] = ls_ka[i][1:]
    st_ans &= set(ls_a[i])

print(len(st_ans))

### FIXED CODE ###

n, m = map(int, input().split())
ls_ka = [[int(_) for _ in input().split()] for _ in range(n)]

ls_k = [0] * n
ls_a = [0] * n
st_ans = {_ for _ in range(1, m+1)} 

for i in range(n):
    ls_k[i] = ls_ka[i][0]
    ls_a[i] = ls_ka[i][1:]
    st_ans &= set(ls_a[i])

print(len(st_ans))
def factorize(n):
    b,e = 2,0
    fct = []
    while b*b <= n:
        while n%b==0:
            n//=b
            e+=1
        if e>0:
            fct.append((b,e))
        b+=1
    if n!=1:
        fct.append((n,1))
    return fct
    
N,M = list(map(int,input().split()))

pl = factorize(M)

max_coef=max([p[1] for p in pl])



if max_coef==0:
    print(N)
else:

    comb_list = [1]
    c = 1
    mod = 10**9+7
    for i in range(max_coef):
        c *= N+i
        c *= pow(i+1,mod-2,mod)
        c %= mod
        comb_list.append(c)

    ans = 1

    for p in pl:
        ans*=comb_list[p[1]]
        ans %= mod

    print(ans)

### FIXED CODE ###

N,M = map(int,raw_input().split())

def factorize(n):
	fct = []  # prime factor
	b, e = 2, 0  # base, exponent
	while b * b <= n:
		while n % b == 0:
			n = n / b
			e = e + 1
		if e > 0:
			fct.append((b, e))
		b, e = b + 1, 0
	if n > 1:
		fct.append((n, 1))
	return fct

def comb(n,r):
	ans = 1
	for i in range(r):
		ans=ans*(n-i)
		ans=ans/(i+1)
	return ans%(10**9 + 7)

fct= factorize(M)

ans = 1

for f in fct:
	ans=(ans *comb(f[1]+N-1,f[1]))%(10**9+7)

print ans
#自分の回答
import math
def digit(b, n):
    if n < b:
        return n
    else:
        return digit(b, math.floor(n/b)) + n % b

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

if n == s:
    print(n+1)
    exit()

if n < s:
    print(-1)
    exit()

for i in range(2, int(math.sqrt(n)) + 2):
    if digit(i, n) == s:
        print(i)
        exit()
    else:
        continue

for p in range(1,int(math.sqrt(n)))[::-1]:
    b = (n-s)//p +1
    if digit(b, n) == s:
        print(b)
        exit()
print(-1)    

### FIXED CODE ###

import math
def digit(b, n):
    if n < b:
        return n
    else:
        return digit(b, math.floor(n/b)) + n % b

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

if n == s:
    print(n+1)
    exit()

if n < s:
    print(-1)
    exit()

for i in range(2, int(math.sqrt(n)) + 2):
    if digit(i, n) == s:
        print(i)
        exit()

for p in range(1,int(math.sqrt(n)))[::-1]:
    q = s - p
    b = (n-s)//p +1
    if 1 <= p < b and 0 <= q < b and (n - s)%p == 0:
        if digit(b, n) == s:
            print(b)
            exit()
print(-1)
num = 0
while true:
    x = input()
    num += 1
    if x == '0':
        break
    print("Case {}: {}".format(num, x))

### FIXED CODE ###

import sys
num = 0
while(True):
    x = int(sys.stdin.readline())
    num += 1
    if x == 0:
        break
    print("Case %d: %d" % (num, x))
K, S = int(input().split())
ans = 0
for o in range(2, K):
    for p in range(2, K-o):
        for q in range(2, K-o-p):
            if o + p + q == S:
                ans += 1
print(ans)


### FIXED CODE ###

K, S = map(int, input().split())
ans = 0
for o in range(0, K+1):
    for p in range(0, K+1):
            if 0 <= S-o-p <= K:
                ans += 1
print(ans)
import math
from functools import reduce

n = int(input())
a = [int(input()) for _ in range(n)]

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

def lcm(nums):
    #3つ目は初期値
    return reduce(lcm_base, nums, 1)

print(lcm(a))



### FIXED CODE ###

#import math
from functools import reduce

n = int(input())
a = [int(input()) for _ in range(n)]

def gcd(x, y):
    while y:
        x, y = y, x%y
    return x

def lcm_base(x, y):
    return (x*y)//gcd(x, y)

def lcm(nums):
    #3つ目は初期値
    return reduce(lcm_base, nums, 1)

print(lcm(a))
import sys
a,b=map(int,input().split())
f=True
for i in range(1,1010):#max_a=1
    if int(i*0.08)==a and int(i*0.1)==b:
        ans=i
        f=False
        break
if f:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

a=list(input())
if a[0]==a[1]==a[2]:
  print("No")
else:
  print("Yes")
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
A = [int(x) for x in input().split()]
AA = []
for i in A:
    if(not i in AA):
        AA+=[i]
AA.sort()
cand = -1
mingcd = gcd_list(AA)
if(N==2):
    print(max(AA))
else:
    for i in range(len(AA)-1):
        if(mingcd==gcd(AA[i],AA[i+1])):
            if(i<len(AA)-2):
                if(mingcd==gcd(AA[i],AA[i+2])):
                    cand = i
                else:
                    cand = i+1
                break
            else:
                cand = i+1
    if(cand==-1):
        cand = len(AA)-1
    print(gcd_list(AA[:cand]+AA[cand+1:]))


### FIXED CODE ###

import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
A = [int(x) for x in input().split()]
L = [0]*N
R = [0]*N
ans = 0
for i in range(N):
    if(i==0):
        L[i] = A[0]
        R[i] = A[-1]
    else:
        L[i] = gcd(A[i],L[i-1])
        R[i] = gcd(A[-i-1],R[i-1])

for i in range(N):
    if(i==0):
        ans = R[-2]
    elif(i==N-1):
        ans = max(ans,L[-2])
    else:    
        ans = max(ans,gcd(L[i-1],R[-i-2]))
print(ans)
a,b=input().split()
print(max(a+b,a-b,a*b))

### FIXED CODE ###

a,b=map(int,input().split())
print(max(a + b,a - b,a * b))
d, t, s = map(int, input())
t_d = t * d
if td >= d:
  print("yes")
else:
  print("no")

### FIXED CODE ###

d, t, s = map(int, input().split())
if d > t*s:
    print('No')
else:
    print('Yes')
n = int(input())
a = list(map(int, input().split()))

mod = 1000000007
ans = 1
rgb = [0, 0, 0]
for num in a:
    ans = (ans * rgb.count(num)) % mod
    index = rgb.index(num)
    rgb[index] += 1
print(ans)

### FIXED CODE ###

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

mod = 1000000007
ans = 1
rgb = [0, 0, 0]
for num in a:
    ans = (ans * rgb.count(num)) % mod
    if ans == 0:
        break
    index = rgb.index(num)
    rgb[index] += 1
print(ans)
W,H,x,y,r = list(map(int,input().split()))
    if (r<=x<=W-r)&(r<=y<=H-y):
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

W,H,x,y,r = list(map(int,input().split()))
if (r<=x<=W-r)&(r<=y<=H-r):
    print('Yes')
else:
    print('No')
n=input()
satis=[]

for i in range(n):
  satis += map(int,input().split())

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

### FIXED CODE ###

n=int(input())
satis=[]

for i in range(n):
  A=list(map(int,input().split()))
  satis.extend(A)

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))
a,b,c = map(int,input())
print(min(c-(a-b),0)

### FIXED CODE ###

a,b,c = map(int,input().split())
if c>a-b:
    print(c-a+b)
else:
    print(0)
n = int(input())
a = list(map(int, input().split()))

tmpma=n
ans=0
for val in a:
  if val<=tmpmin:
    ans+=1
    tmpmin=val
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
 
tmpmin=n
ans=0
for val in a:
  if val<=tmpmin:
    ans+=1
    tmpmin=val
print(ans)
K = int(input())
A, B = map(int, input().split())

l = 0
ret = 'NG"
while l <= B:
  if l >= A:
    ret = 'OK'
  l += K
  
print(ret)

### FIXED CODE ###

K = int(input())
A, B = map(int, input().split())
 
l = 0
ret = 'NG'
while l <= B:
  if l >= A:
    ret = 'OK'
  l += K
  
print(ret)
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]

roots = [(i,1) for i in range(N+1)] # root, num_islands_in_group

inconveniences = [0]*(M+1)
inconveniences[-1] = N*(N-1)//2 #すべての橋が崩落するとNC2

def find_root(a, roots=roots):
  if roots[a][0] == a:
    return roots[a]
  else:
    roots[a] = find_root(roots[a][0])
  return roots[a]

def reduce_inconvenience_with_unite(a, b, roots=roots):
  root_a, n_a = find_root(a)
  root_b, n_b = find_root(b)
  if root_a == root_b:
    return 0
  else:
    roots[root_a] = (b, None) # 二項目は何でも良い
    roots[root_b] = (root_b, n_a + n_b)
    return n_a * n_b

for i, ab in enumerate(AB[:0:-1]): #実は1個めの橋は全く関係ない
  a, b = ab
  inconveniences[M-1-i] = inconveniences[M-i] - reduce_inconvenience_with_unite(a,b)

for inc in inconveniences[1:]:
  print(inc)

### FIXED CODE ###

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

roots = [(i,1) for i in range(N+1)] # root, num_islands_in_group

inconveniences = [0]*(M+1)
inconveniences[-1] = N*(N-1)//2 #すべての橋が崩落するとNC2

def find_root(a, roots=roots):
  if roots[a][0] == a:
    return roots[a]
  else:
    roots[a] = find_root(roots[a][0])
  return roots[a]

def reduce_inconvenience_with_unite(a, b, roots=roots):
  root_a, n_a = find_root(a)
  root_b, n_b = find_root(b)
  if root_a == root_b:
    return 0
  else:
    if n_a > n_b:
      roots[root_a] = (root_a, n_a + n_b) # 二項目は何でも良い
      roots[root_b] = (root_a, n_a + n_b)
    else:
      roots[root_a] = (root_b, n_a + n_b) # 二項目は何でも良い
      roots[root_b] = (root_b, n_a + n_b)
    return n_a * n_b

for i, ab in enumerate(AB[:0:-1]): #実は1個めの橋は全く関係ない
  a, b = ab
  inconveniences[M-1-i] = inconveniences[M-i] - reduce_inconvenience_with_unite(a,b)

for inc in inconveniences[1:]:
  print(inc)
N = int(input())
A = list(map(int, input().spllit()))
print(max(A) - min(A))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
print(max(A) - min(A))
N, M =map(int, input().split())
ans = []
for i in range(M):
    a, b = map(int, input().split())
    ans.append(a)
    ans.append(b)

for i in range(1,N+1):
    print(ans.index(i))
    
    

### FIXED CODE ###

N, M =map(int, input().split())
ans = []
for i in range(M):
    a, b = map(int, input().split())
    ans.append(a)
    ans.append(b)

for i in range(1,N+1):
    print(ans.count(i))
a = int(input())
b = int(input())
c = int(input())
d = int(input())
ans = 0
if a > b:
  ans += a
else:
  ans += b
if c > d
  ans += c
else:
  ans += d
print(ans)
	

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
ans = 0
if a > b:
  ans += b
else:
  ans += a
if c > d:
  ans += d
else:
  ans += c
print(ans)
a=[]
w=[]
t=[]
r=[]
n = int(input())
s = list(input().split())

for i in range (n):
  if s[i] == "AC":
    a.append(s[i])
  elif s[i]== "WA":
    w.append(s[i])
  elif s[i]== "TLE":
    t.append(s[i])
  else:
    r.append(s[i])
  
print("AC x ",sum(a))
print("WA x ",sum(w))
print("TLE x ",sum(t))
print("RE x ",sum(r))
  

### FIXED CODE ###

n = int(input())
s = list(input() for i in range(n))
  
print("AC x ",s.count("AC"))
print("WA x ",s.count("WA"))
print("TLE x ",s.count("TLE"))
print("RE x ",s.count("RE"))
a=input().split()
N=int(a[0])
M=int(a[1])
X=int(a[2])
list1=[]
for i in range(N) :
  k=input().split()
  k=[int(j) for j in k]
  list1.append(k)
flag1=True
def count(item,i) :
  count=0
  for a in item :
    count+=a[i]
  return count

import itertools
import numpy as np
for i in range(1,N+1) :
  c=list(itertools.combinations(list1,i))

  value_list=[]
  for item in c :
    item1=list(item)


    if count(item,1)>=X and count(item,2)>=X and count(item,3)>=X :
      value_list.append(count(item,0))
  if value_list!=[] :
    print(min(value_list))
    flag1=False

    break
if flag1 :
  print('-1')


### FIXED CODE ###

a=input().split()
N=int(a[0])
M=int(a[1])
X=int(a[2])
list1=[]
for i in range(N) :
  k=input().split()
  k=[int(j) for j in k]
  list1.append(k)

flag1=True
def count(item,i) :
  count1=0
  for a in item :
    count1+=a[i]
  return count1

def algo(item,i) :

  for j in range(1,i+1) :
    if count(item,j)<X :
      return False
  return True


import itertools
value_list=[]
for i in range(1,N+1) :
  c=list(itertools.combinations(list1,i))


  for item in c :
    item1=list(item)


    if algo(item1,M) :
      value_list.append(count(item1,0))

if value_list!=[] :
  print(min(value_list))
else :
  print('-1')
a = str(input())
b = str(input())
 
rev_a = a[::-1]
 
if rev_a == b:
    print('YES)
else:
    print('NO')

### FIXED CODE ###

a = str(input())
b = str(input())
 
rev_a = a[::-1]
 
if rev_a == b:
  print('YES')
else:
  print('NO')
n = int(input())

a = []
for i in range(n):
  arr = list(map(int, input().split()))
  a.append(arr)

for i in range(0, n):
  for j in range(0, 3):
    for k in range(3):
      if (j == k): continue
      dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])

print(max(dp[-1]))

### FIXED CODE ###

n = int(input())

a = []
for i in range(n):
  arr = list(map(int, input().split()))
  a.append(arr)

INF = -10 ** 18

dp = [ [INF] * 3 for i in range(0, n+1)]
dp[0] = [0] * 3

for i in range(0, n):
  for j in range(0, 3):
    for k in range(3):
      if (j == k): continue
      dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])

print(max(dp[-1]))
N=int(input())
S=input()
edge=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

parent=[0]*N
depth=[0]*N
def dfs(v,pv):
    for nv in edge[v]:
        if nv!=pv:
            depth[nv]=depth[v]+1
            parent[nv]=v
            dfs(nv,v)

def dfs2(v,pv):
    res=depth[v]*(S[v]=="1")
    for nv in edge[v]:
        if nv!=pv:
            res+=dfs2(nv,v)
    return res

ans=10**18

for i in range(N):
    depth[i]=0
    parent[i]=0
    dfs(i,-1)
    test=dfs2(i,-1)
    if test%2==0:
        for nv in edge[i]:
            check=dfs2(nv,i)
            if check>test//2:
                break
        else:
            ans=min(ans,test//2)

if ans==10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

import sys

sys.setrecursionlimit(10**4)

N=int(input())
S=input()
edge=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

depth=[0]*N
num=[0]*N
sd=[0]*N
def dfs(v,pv):
    res=depth[v]*(S[v]=="1")
    n=int(S[v])
    for nv in edge[v]:
        if nv!=pv:
            depth[nv]=depth[v]+1
            dfs(nv,v)
            res+=sd[nv]
            n+=num[nv]
    sd[v]=res
    num[v]=n

def dfs2(v,pv):
    hosei=depth[v]
    S=sd[v]-num[v]*hosei
    if S%2==0:
        check=0
        node=-1
        for nv in edge[v]:
            if nv!=pv:
                if sd[nv]-num[nv]*hosei>S//2:
                    check=sd[nv]-num[nv]*hosei
                    node=nv
        if not check:
            return S//2
        else:
            minus=dfs2(node,v)
            if check-2*minus<=S-check:
                return S//2
            else:
                return S-check+minus
    else:
        check=0
        node=-1
        k=S//2
        for nv in edge[v]:
            if nv!=pv:
                if sd[nv]-num[nv]*hosei>k+1:
                    check=sd[nv]-num[nv]*hosei
                    node=nv
        if not check:
            return k
        else:
            minus=dfs2(node,v)
            if check-2*minus<=S-check:
                return k
            else:
                return S-check+minus


ans=10**18

for i in range(N):
    depth[i]=0
    dfs(i,-1)
    #print(i,depth)
    test=dfs2(i,-1)
    if test*2==sd[i]:
        ans=min(ans,test)

if ans==10**18:
    print(-1)
else:
    print(ans)
n = int(input())
suuretu = [int(x) for x in input().split()]
answer = 0
 
for i in suuretu:
    answer += calculate(i)
 
def calculate(i):
    a = 0
    while i % 2 == 0:
        i = i / 2
        a += 1
    return a

print(answer)

### FIXED CODE ###

import math
n = int(input())
a = list(map(int,input().split()))
maxlog = int(math.log2(max(a)))
answer = 0
for _ in range(maxlog):
  a = [aa/2 for aa in a if aa%2==0]
  answer+= len(a)
  if not a:
    break
print(answer)
M = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
#print(B)
#print(B[])
num = 1

while num <= M:
    print(B[num])
    num += 1

### FIXED CODE ###

import collections
M = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
num = 1

while num <= M:
    print(B[num])
    num += 1
s=input()
c=0
for i in range(s):
    if i=='1':
        c+=1
print(c)

### FIXED CODE ###

s=input()
c=0
for i in s:
    if i=='1':
        c+=1
print(c)
def dfs(x, y, gx, gy, s, f):
    if len(s) == 0:
        if (x, y) == (gx, gy):
            return True
        return False
    ans = False
    if s[0] == 'T':
        if f:
            ans = ans or dfs(x, y, gx, gy, s[1:], not f)
        else:
            ans = ans or dfs(x, y, gx, gy, s[1:], not f)
    else:
        if f:
            for xx, yy in [(x + 1, y), (x - 1, y)]:
                ans = ans or dfs(xx, yy, gx, gy, s[1:], f)
        else:
            for xx, yy in [(x, y + 1), (x, y - 1)]:
                ans = ans or dfs(xx, yy, gx, gy, s[1:], f)
    return ans


def main():
    s = input()
    x, y = map(int, input().split())
    if dfs(0, 0, x, y, s, True):
        print('Yes')
    else:
        print('No')


main()


### FIXED CODE ###

def main():
    s = input()
    x, y = map(int, input().split())
    sl = s.split('T')
    dx = list(map(len, sl[::2]))
    dy = list(map(len, sl[1::2]))
    nx = dx.pop(0)
    ny = 0
    dx.sort(reverse=True)
    dy.sort(reverse=True)
    for xx in dx:
        if x >= nx:
            nx += xx
        else:
            nx -= xx
    for yy in dy:
        if y >= ny:
            ny += yy
        else:
            ny -= yy
    print('YNeos'[nx != x or ny != y::2])


main()
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]

h = sorted(h)
Lh = len(h)
while Lh > K:
    print(h)
    head = h[1] - h[0]
    tail = h[Lh-1]-h[Lh-2]
    if head > tail:
        h = h[1:]
    else:
        h = h[:Lh-1]
    Lh = len(h)
        
print(h[Lh-1]-h[0])


### FIXED CODE ###

N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]

h = sorted(h)
hK = h[0:K]
ans = hK[K-1]-h[0]
for i in range(N-K+1):
    ans = min(ans,h[i+K-1]-h[i])

print(ans)
def fib(n):
  if n <= 1:
    return 1
  return fib(n-1)*n

n,k = map(int, input().split())
print(int(fib(k)/fib(k-n)))

### FIXED CODE ###

n,k = map(int, input().split())
p=k
for i in range(n-1):
  p *= k-1
print(p)
a,b=list(map(int,input().splilt()))
if a==b:
  print('Yes')
else :
  print('No')


### FIXED CODE ###

a,b=list(map(int,input().split()))
if a==b:
  print('Yes')
else :
  print('No')
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a.sort()
b = []
for i in range(0,n-1,2):
  if a[i] != a[i+1]:
    b.append(a[i])
    b.append(a[i+1])
  else:
    continue
if n%2 == 1:
  b.append(a[-1])
#print(b)
ans = []
if b != []:
  ans.append(b[0])
  for j in range(1,len(b)-1,2):
    if b[j] != b[j+1]:
      ans.append(b[i])
      ans.append(b[i+1])
#print(ans)
if ans == []:
  print(0)
else:
  print(len(ans))

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a.sort()
b = []
for i in range(0,n-1,2):
  if a[i] != a[i+1]:
    b.append(a[i])
    b.append(a[i+1])
  else:
    continue
if n%2 == 1:
  b.append(a[-1])
#print(b)
ans = []
if b != []:
  ans.append(b[0])
  for j in range(1,len(b)-1,2):
    if b[j] != b[j+1]:
      ans.append(b[j])
      ans.append(b[j+1])
  if len(b)%2 == 0:
    ans.append(b[-1])
#print(ans)
if ans == []:
  print(0)
else:
  print(len(ans))
a = input()
b = input()
print((int(a) * int(b),(int(a) * 2) + (int(b) * 2)))

### FIXED CODE ###

a ,b = input().split(' ')
print(int(a) * int(b),(int(a) * 2) + (int(b) * 2))
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

res=0
back=0

for a in A:
	res=res+B[a-1]					#listは０スタート
	if back==a-1 and a!=len(A):		#A内の今考えている変数が前のと同じなら
		res=res+C[back-1]			#listは０スタート
	back=a
    
print(res)

### FIXED CODE ###

n=int(input())
print(n**3)
n=int(input())
t,a=list(map(int,input().split()))
h=list(map(int,input().split()))
imin=100000
suf=0
for i in range(n):
  h[i]=t- h[i]＊0.006
  if imin > abs(a- h[i]):
    imin=abs(a- h[i])
    suf=i
print(i)
  
    

### FIXED CODE ###

n=int(input())
t,a=list(map(int,input().split()))
h=list(map(int,input().split()))
imin=100000
suf=0
for i in range(n):
  h[i]=t- h[i]*0.006
  if a>=h[i]:
    if imin>a-h[i]:
      #print("!!",a-h[i],h[i],i)
      imin=abs(a- h[i])
      suf=i
  else:
    if imin>h[i]-a:
      #print("!!",a-h[i],h[i],i)
      imin=abs( h[i]-a)
      suf=i 
print(suf+1)
n=int(input())
happy=0
def covid(num):
  if num==0:
    return 0
  else:
    fund=num//500
    num-=fund*500
    happy+=fund*1000
    happy+=num//5*5
    return happy
print(covid(n))

### FIXED CODE ###

n=int(input())
def covid(num):
  if num==0:
    return 0
  else:
    happy=0
    fund=num//500
    num-=fund*500
    happy+=fund*1000
    happy+=num//5*5
    return happy
print(covid(n))