Harryxun/stf_run huggingface dataset:
S = input()
#print(len(S))
dire = ['dream','dreamer','erase','eraser']
flag = 0
i=0
j=0
num=0
count = [0]*10000
while True:
    tmp = dire[count[num]]
    ind = i

    #if ind + len(dire[j]) <=len(S)+1:
        #print(j)
    for k in range(len(dire[count[num]])):
        if S[ind] != tmp[k]  or  i + len(dire[count[num]]) >=len(S)+1 :
            flag =0
            count[num]  += 1
            break
        else:
            ind = ind + 1
            if k==len(dire[count[num]])-1:
                i = i + len(dire[count[num]])
                num +=1
                flag = 1


    if   count[num] >= 4 and flag == 0:
        count[num] = 0
        num -= 1
        i = i - len(dire[count[num]])
        if count[num] != 3:
            count[num] += 1
        else:
            count[num] = 0
    if i >= len(S):
        print('YES')
        break
    elif count[0]==0 and flag == 0 and i <=0:
        print('NO')
        break


### FIXED CODE ###

S = input()
S_r = S[::-1]
dire = ['dream','dreamer','erase','eraser']
dire_r = [0]*4
for i in range(4):
    tmp = dire[i]
    dire_r[i] = tmp[::-1]
ind = 0

excep = 0

while ind  <len(S_r):
    if excep == 1:
        break
    flag2= 0
    for j in range(4):
        if flag2 ==0:
            case = 0
            for k in range(len(dire_r[j])):
                tmp = dire_r[j]

                if ind + k < len(S_r) and case == 0:
                #    print(j)
            #        print('S:'+S_r[ind+k])
            #        print('dire:'+tmp[k])
                    if S_r[ind+k] != tmp[k]:
                        flag = 0
                        case = 1
                        if j == 3:
                            excep = 1

                    elif k== len(dire_r[j])  -1:
                        ind = ind + len(dire_r[j])
                        flag = 1
                        case = 1
                        flag2 = 1


if flag == 1:
    print('YES')
else:
    print('NO')
A, B = map(int, input().split())
print("Yay!" if A <= 8 and B <= 8)


### FIXED CODE ###

A, B = map(int, input().split())
print("Yay!" if A <= 8 and B <= 8 else ":(")
N = int(input())
if N[0] == '7' or N[1] == '7' or N[2] == '7':
    print('Yes')
else:
    print('No')

### FIXED CODE ###

N = str(input())
if N[0] == '7' or N[1] == '7' or N[2] == '7':
    print('Yes')
else:
    print('No')
import java.io.*;
import java.util.*;

public class five {
	static class InputReader {
		BufferedReader reader;
		StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens())
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			return tokenizer.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public void close() throws IOException {
			reader.close();
		}
	}

	public static void main(String[] args) throws IOException {
		InputReader f = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);

		for (int i = 1; i <= 5; i++) {
			if (f.nextInt() == 0) {
				System.out.println(i);
				break;
			}
		}
		
		f.close();
		out.close();
	}
}

### FIXED CODE ###

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

for i in range(5):
    if A[i] == 0:
        print(i + 1)
        break
import math

N=int(input())

G=[[] for i in range(N)]
for _ in range(N-1):
	a,b=map(lambda x:int(x)-1,input().split())
	G[a].append(b)
	G[b].append(a)

depth=[[0]*N for i in range(2)]

def dfs(d, i, p, k=0):
	for t in G[i]:
		if t!=p:
			depth[k][t]=d
			dfs(d+1, t, i,k)
			


dfs(1,0,-1, 0)
dfs(1,N-1,-1, 1)

cnt=0
for i,j in zip(depth[0], depth[1]):
	if i<=j:
		cnt+=1

print('Fennec' if cnt*2>N else 'Snuke')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

import math

N=int(input())

G=[[] for i in range(N)]
for _ in range(N-1):
	a,b=map(lambda x:int(x)-1,input().split())
	G[a].append(b)
	G[b].append(a)

depth=[[0]*N for i in range(2)]

def dfs(d, i, p, k=0):
	for t in G[i]:
		if t!=p:
			depth[k][t]=d
			dfs(d+1, t, i,k)


dfs(1,0,-1, 0)
dfs(1,N-1,-1, 1)

cnt=0
for i,j in zip(depth[0], depth[1]):
	if i<=j:
		cnt+=1

print('Fennec' if cnt*2>N else 'Snuke')
import numpy as np

# not solved by myself
N = input()
A = list(map(int, input().split()))

Sum = sum(A)
s = []
multi = np.lcm.reduce(A)
for a in A:
    s.append(int(multi / a))


print(int(multi / sum(s)))



### FIXED CODE ###

N = input()
A = list(map(float, input().split()))

print(1 / sum(1 / x for x in A))
'''input
100000 5
'''
from math import ceil, log2
N, K = [int(x) for x in input().split()]

ats = 0.0

for i in range(1, N+1):
	if i >= K:
		ats += 1/N
		continue

	ats += 1/N/(2.0**(float(ceil(log2(K/i)))))

print(ats)

### FIXED CODE ###

'''input
100000 5
'''
from math import ceil, log2
N, K = [int(x) for x in input().split()]

ats = 0.0

for i in range(1, N+1):
	if i >= K:
		ats += 1/N
		continue

	ats += 1/N/(2.0**(float(ceil(log2(K/i)))))

print(ats)
import numpy as np

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

h = np.array(h)

for i in range(len(h)-1):
   if h[i] < h[i+1]:
       h[i+1] -= 1
np.diff(h-1, n=1)

minus = [i for i in np.diff(h-1, n=1) if i < 0]

if len(minus) > 0:
    print('No')
else:
    print('Yes')


### FIXED CODE ###

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

c1 = b
c2 = c
cap = a - b

c1 = c1 + cap
c2 = c2 - cap

if c2 < 0:
    c2 = 0
print(c2)
x = input()
y = pow(x, 3)
print(y)

### FIXED CODE ###

x = int(input())
print(x ** 3)
import sys
read=sys.stdin.read
readline=sys.stdin.readline

a,b,c,d,e,f=map(int,readline().split())

def searints(m,n,l):#m<=n
  mask=(1<<l+1)-1
  s=sum([1<<n*i for i in range(1,l//n+1)])&mask
  for i in range(1,l//m+1):
    s=(s+1<<m*i|s) &mask
  return [x for x in range(0,l+1) if ((s+1)>>x)&1==1]

w=searints(100*a,100*b,f)
s=searints(c,d,f)
candidates=[(100*y/(x+y),x+y,y) for x in w for y in s if e*x>=100*y and x*y>0 and x+y<=f]
print(*max(candidates)[1:])

### FIXED CODE ###

import sys
read=sys.stdin.read
readline=sys.stdin.readline

a,b,c,d,e,f=map(int,readline().split())

def searints(m,n,l):#m<=n
  mask=(1<<l+1)-1
  s=sum([1<<n*i for i in range(1,l//n+1)])&mask
  for i in range(1,l//m+1):
    s=(s+1<<m*i|s) &mask
  return [x for x in range(0,l+1) if ((s+1)>>x)&1==1]

w=searints(100*a,100*b,f)
s=searints(c,d,f)
candidates=[(100*y/(x+y),x+y,y) for x in w for y in s if e*x>=100*y and x*y>0 and x+y<=f]
if candidates:
  print(*max(candidates)[1:])
else:
  print(100*a,0)
*Pos, K = [int(input()) for _ in range(6)]
print('Yay!' if Pos[4] - pos[0] <= K else ':(')

### FIXED CODE ###

*Pos, K = [int(input()) for _ in range(6)]
for s in range(5):
  for t in range(s + 1, 5):
    if Pos[t] - Pos[s] > K:
      print(':(')
      exit()
print('Yay!')
n=int(input())
a,b,c=map(int,input().split())
dp=[[a,b,c] for i in range(n)]
for i in range(1,n):
  a,b,c=map(int,input().split()¥
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print(max(dp[n-1]))

### FIXED CODE ###

n=int(input())
a,b,c=map(int,input().split())
dp=[[a,b,c] for i in range(n)]
for i in range(1,n):
  a,b,c=map(int,input().split())
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print(max(dp[n-1]))
N,K=map(int,input().split())
wa=0
for i in range(N+1-k+1):
    n=i+K
    min=(n)*(0+n-1)/2
    max=(n)*(N-n+1+N)/2

    wa=max-min+wa
    
print(wa)


### FIXED CODE ###

N,K=map(int,input().split())
wa=0
for i in range(N+1-K):
    n=i+K
    min=(n)*(0+n-1)/2
    max=(n)*(N-n+1+N)/2

    wa=max-min+wa+1


wa=wa+1
wa=wa%(10**9+7)
print(int(wa))
a b = input()

print a*b 2*(a+b) 

### FIXED CODE ###

a,b=map(int,raw_input().split()) #korenazo
print a*b , 2*(a+b)
a, b = [int(i) for i in input().split()]

if a<b:
    print("a<b")


elif a > b:
     print("a>b")


else:
  print("a==b")

### FIXED CODE ###

a, b = [int(i) for i in input().split()]

if a < b:
   print("a < b")


elif a > b:
     print("a > b")


else:
  print("a == b")
import sys
input = sys.stdin.readline
 
h, n = map(int, input().split())
A = []
B = []
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
  
dp=[float("inf")]*h
dp[0]=0
answer = float("inf")

for i in range(h+1):
    for j in range(n):
      if i + A[j] < h:
        dp[i+A[j]]=min(dp[i+A[j]],dp[i]+B[j])
      else:
        answer = min(answer, dp[i]+B[j])
print(answer)

### FIXED CODE ###

h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
 
dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
 
ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)
from math import ceil
N = int(input())
T,A = 1,1
for i in range(N):
    Ti,Ai = map(int,input().split())
    r = max(ceil(T/Ti),ceil(A/Ai))
    T,A = Ti*r,Ai*r
print(T+A)


### FIXED CODE ###

from collections import Counter
A,B,C = map(int,input().split())
print(len(Counter([A,B,C]).most_common()))
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    P = list(map(int, input().split()))

P.sort()
P.append(101)

excluded = P.pop(0)

ans, absolute = None, 101

for i in range(1, 101):
    if i == excluded:
        excluded = P.pop(0)
    else:
        if abs(i - x) < absolute:
            ans = i
            absolute = abs(i - x)
    
print(ans)

### FIXED CODE ###

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

for d in range(x + 1):
    for s in [-1, +1]:
        a = x + s * d
        if P.count(a) == 0:
            print(a)
            exit(0)
N = input()
A = list(map(int, input().split()))
import numpy as np
X = np.prod(A)
if X <= 10**18 :
    print(X)
else :
    print('-1')


### FIXED CODE ###

a , b = input() . split()
c = int(a) *int(b)
print(c)
from heapq import heappush, heappop

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

for _ in range(N) :
    a, b = map(int, input().split())
    if a <= M :
        AB[M-a].append(b)
    
q = []
for a in range(M+1) :
    for b in AB[a] :
        if len(q) < a + 1 :
            heappush(q, b)
        else :
            heappop(q)
            heappush(q, b)
            
print(sum(q))

### FIXED CODE ###

from heapq import heappush, heappop

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

for _ in range(N) :
    a, b = map(int, input().split())
    if a <= M :
        AB[M-a].append(b)
    
q = []
for a in range(M+1) :
    for b in AB[a] :
        heappush(q, b)
        if len(q) > a + 1 :
            heappop(q)
            
print(sum(q))
st = input().strip().split()

a = int(st[0])
b = 0

for x in st[1]:
  if x == '.':
  else: b = b*10 + x

print(a*b//100)

### FIXED CODE ###

print(eval(input().strip().replace(' ','*')))
N = int(input())
H = list(map(int, input().split()))
max_count = 0
for i in range(N-1):
  tmp_count = 0
  for j in range(i, N-2):
  	if H[j] >= H[j+1]:
      print(j)

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
tmp = 0
s = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    tmp += 1
    s = max(s, tmp)
  else:
    tmp = 0
    
print(s)
# coding: utf-8

import math

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

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

print(lcm(a, b))

### FIXED CODE ###

# coding: utf-8

import fractions

a,b = map(int,input().split())
print((a * b) // fractions.gcd(a, b))
# -*- coding: utf-8 -*-

f_line = input().split()
N = int(f_line[0])
L = int(f_line[1])
S = []
s = ""
for i in range(N):
    S.append(input())
S.sort()
for i in range(N):
    s = s + S[i]
print("%s"%(s))

### FIXED CODE ###

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

f_count = 2
s_count = 1
haikuflag = False
input_stuck = input().split()
num = [int(input_stuck[0]),int(input_stuck[1]),int(input_stuck[2])]
for i in num:
    if i == 5:
        f_count-=1
    elif i == 7:
        s_count-=1
if f_count == 0 and s_count == 0:
    print('YES')
else:
    print('NO')
n,m,d = [int(i) for i in input().split()]

ans = 2(n-d)*(m-1)/(n*n)

print(ans)


### FIXED CODE ###

n,m,d = [int(i) for i in input().split()]
if d == 0:
    ans = (n-d)*(m-1)/(n*n)
else:
    ans = 2*(n-d)*(m-1)/(n*n)

print(ans)
a = input()
b = input()
if a*b //2 == 0 :
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

numbers = input().split(" ")
a= int(numbers[0])
b= int(numbers[1])
c=a*b
if c%2==0:
  print("Even")
else:
  print("Odd")
x, y = input().split()
 
x = int(x)
y = float(y)
 
print(int(x * y, '10'))

### FIXED CODE ###

import math
x, y = list(map(float, input().split()))

x = int(x)
y = int(y * 100 + 0.5)
 
print(x * y // 100)
from itertools import combinations
N, M, Q = map(int,input().split())
P = [list(map(int,input().split())) for i in range(Q)]

A = list(itertools.combinations_with_replacement(range(1,M+1), N))
number = len(A)

amount = 0
max_amount = 0
for i in range(number): #A
    
    for j in range(Q): # P
        bi = P[j][1]
        ai = P[j][0]
        if(A[i][bi-1] - A[i][ai-1] == P[j][2]):
            amount += P[j][3]
        
   # print(amount)
    
   # print(amount)
    if(amount >= max_amount):
        max_amount = amount
    
    amount = 0
    
print(max_amount)

### FIXED CODE ###

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

A = list(itertools.combinations_with_replacement(range(1,M+1), N))
number = len(A)

amount = 0
max_amount = 0
for i in range(number): #A
    
    for j in range(Q): # P
        bi = P[j][1]
        ai = P[j][0]
        if(A[i][bi-1] - A[i][ai-1] == P[j][2]):
            amount += P[j][3]
        
   # print(amount)
    
   # print(amount)
    if(amount >= max_amount):
        max_amount = amount
    
    amount = 0
    
print(max_amount)
#!/usr/bin/env python3

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

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

query = []
for _ in range(Q):
    p, x = map(int, input().split())
    query.append([p, x])

counter = [0 for _ in range(N)]
for p, x in query:
    counter[p - 1] += x


def dfs(v, parent):
    for v_next in edges[v]:
        if v_next != parent:
            counter[v_next] += counter[v]
            dfs(v_next, v)


root = 0
dfs(root, None)

print(*counter)


### FIXED CODE ###

#!/usr/bin/env python3

import sys

input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 6)

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

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

query = []
for _ in range(Q):
    p, x = map(int, input().split())
    query.append([p, x])

counter = [0 for _ in range(N)]
for p, x in query:
    counter[p - 1] += x


def dfs(v, parent):
    for v_next in edges[v]:
        if v_next != parent:
            counter[v_next] += counter[v]
            dfs(v_next, v)


root = 0
dfs(root, None)

print(*counter)
import math

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

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

print(lcm(a,b))

### FIXED CODE ###

a,b = map(int,input().split())
 
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a


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

print(lcm(a,b))
from math import factorial

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

X_max = 0
X_min = 0

nCr = {}

def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n, r) in nCr: return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


for i in range(N-K+1):
    n = cmb(N-1-i, K-1)
    X_max += n*A[-(i+1)]
    X_min += n*A[i]

print((X_max - X_min) % 1000000007)

### FIXED CODE ###

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

p = 1000000007
X_max = 0
X_min = 0


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


for i in range(N-K+1):
    n = cmb(N-1-i, K-1, p)
    X_max += n*A[-(i+1)]
    X_max %= p
    X_min += n*A[i]
    X_min %= p

print(int((X_max - X_min) % p))
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
LR = list(zip(m,m))

if N==2:
    L1,R1 = LR[0]
    L2,R2 = LR[1]
    answer = (R1-L1+1) + (R2-L2+1)
    print(answer)
    exit()

# 片方に集める場合
max_width = max(R-L+1 for L,R in LR)

LR.sort()

INF=10**18
# Rが最小のもの
i = -1
opt_R = INF
for n,(L,R) in enumerate(LR):
    if opt_R>=R:
        opt_R=R
        i=n
j = -1
opt_L = -INF
for n,(L,R) in enumerate(LR):
    if opt_L<=L:
        opt_L=L
        j=n

if i==j:
    L,R = LR[i]
    answer = max_width + (R-L+1)
    print(answer)
    raise Exception
    exit()

L1,R1 = LR[i]; L2,R2 = LR[j]

LR = [(L,R) for n,(L,R) in enumerate(LR) if n != i and n != j]

LR.sort()

n = len(LR)
dpl = [(-INF,INF)]*(n+1)
dpr = [(-INF,INF)]*(n+1)

for i in range(n):
    a,b = dpl[i]
    L,R = LR[i]
    dpl[i+1] = (max(a,L),min(b,R))
for i in range(n,0,-1):
    a,b = dpr[i]
    L,R = LR[i-1]
    dpr[i-1] = (max(a,L),min(b,R))

answer = 0
for (a,b),(c,d) in zip(dpl,dpr):
    l1 = max(L1,a); r1 = min(R1,b)
    l2 = max(L2,c); r2 = min(R2,d)
    x = max(0,r1-l1+1) + max(0,r2-l2+1)
    if answer < x:
        answer = x

if answer < max_width:
    answer = max_width

print(answer)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
LR = list(zip(m,m))

if N==2:
    L1,R1 = LR[0]
    L2,R2 = LR[1]
    answer = (R1-L1+1) + (R2-L2+1)
    print(answer)
    exit()

# 片方に集める場合
max_width = max(R-L+1 for L,R in LR)

LR.sort()

INF=10**18
# Rが最小のもの
i = -1
opt_R = INF
for n,(L,R) in enumerate(LR):
    if opt_R>=R:
        opt_R=R
        i=n
j = -1
opt_L = -INF
for n,(L,R) in enumerate(LR):
    if opt_L<=L:
        opt_L=L
        j=n

if i==j:
    L,R = LR[i]
    answer = max_width + (R-L+1)
    print(answer)
    exit()

L1,R1 = LR[i]; L2,R2 = LR[j]

LR = [(L,R) for n,(L,R) in enumerate(LR) if n != i and n != j]

LR.sort(key = lambda x: (x[0],-x[1]))

n = len(LR)
dpl = [(-INF,INF)]*(n+1)
dpr = [(-INF,INF)]*(n+1)

for i in range(n):
    a,b = dpl[i]
    L,R = LR[i]
    dpl[i+1] = (max(a,L),min(b,R))
for i in range(n,0,-1):
    a,b = dpr[i]
    L,R = LR[i-1]
    dpr[i-1] = (max(a,L),min(b,R))

answer = 0
for (a,b),(c,d) in zip(dpl,dpr):
    l1 = max(L1,a); r1 = min(R1,b)
    l2 = max(L2,c); r2 = min(R2,d)
    x = max(0,r1-l1+1) + max(0,r2-l2+1)
    if answer < x:
        answer = x

x = max_width + max(0,min(R1,R2)-max(L1,L2)+1)
if answer < x:
    answer = x

print(answer)
N = int(input())
if N == 0:
    print(0)
else:
    li = []
    ind = 0
    while N != 0:
        if N % 2**(ind + 1) == 0:
            li.insert(0,0)
            ind += 1
        else:
            li.insert(0,1)
            N -= (-2)**(ind)
            ind += 1            
x = ''.join([str(li[i]) for i in range(len(li))])
print(x)

### FIXED CODE ###

N = int(input())
if N == 0:
    print(0)
else:
    li = []
    ind = 0
    while N != 0:
        if N % 2**(ind + 1) == 0:
            li.insert(0,0)
            ind += 1
        else:
            li.insert(0,1)
            N -= (-2)**(ind)
            ind += 1            
    x = ''.join([str(li[i]) for i in range(len(li))])
    print(x)
N, K = map(int, input().split(" "))
S = input()

alp = S[K-1]
if alp == "A":
  S[K-1] = "a"
elif alp == "B":
  S[K-1] = "b"
else:
  S[K-1] = "c"
  
print(S)

### FIXED CODE ###

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

alp = S[K-1]
if alp == "A":
  print(S[:K-1] + "a" + S[K:])
elif alp == "B":
  print(S[:K-1] + "b" + S[K:])
else:
  print(S[:K-1] + "c" + S[K:])
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
N = li()
A = list(li())

def gcd(A, B):
    if A * B <= 0:
        # at least one is positive
        return max(A, B)
    # fast return
    if B == 1 or A == 1:
        return 1

    # normal gcd logic
    if A != B:
        return gcd(min(A, B), abs(A - B))
    else:
        return A

A.sort()
res = A[0]
for a in A:
    if a <= 0:
        continue
    res = gcd(a, res)
    if res == 1:
        break

print(max(res, 0))


### FIXED CODE ###

import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
N = li()
A = list(li())

def gcd(A, B):

    # normal gcd logic
    while B not in (1, 0):
        A, B = (A, B) if A > B else (B, A)
        _, mod = divmod(A, B)
        A, B = B, mod
    if B == 0:
        return A
    elif B == 1:
        return 1

A = list(filter(lambda x:x>0, A))
A.sort()
if len(A) == 0:
    print(0)
else:
    res = A[0]
    for a in A:
        res = gcd(a, res)
        if res == 1:
            break

    print(res)
a = n
print(a + a ** 2 + a ** 3)

### FIXED CODE ###

a = int(input())
print (a + a **2 + a **3)
N,L = map(int, input().split())

apple = [L+i for i in range(N)]
min = 500
for k in range(len(apple)):
    if abs(apple[k])<min:
        min = abs(apple[k])

apple.remove(min)
print(sum(apple))

### FIXED CODE ###

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

apple = [L+i for i in range(N)]
min = 500
for k in range(len(apple)):
    if abs(apple[k])<abs(min):
        min = apple[k]

apple.remove(min)
print(sum(apple))
from heapq import heappush, heappop
X, Y, Z, K, *L = map(int, open('0').read().split())
A = L[:X]
B = L[X:X+Y]
C = L[X+Y:]
ab = []
for i in range(X):
  for j in range(Y):
    ab += [A[i]+B[j]]
ab.sort(reverse=True)
ls = []
for i in range(Z):
  heappush(ls,(-ab[0]-C[i],j,0))
for i in range(K):
  m, j, cnt = heappop(ls)
  print(-m)
  if cnt<X*Y:
    heappush(ls,(-ab[cnt+1]-C[j],j,cnt+1))

### FIXED CODE ###

inf = input().split()
X = int(inf[0])
Y = int(inf[1])
Z = int(inf[2])
K = int(inf[3])

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ab = []
for a in A:
  for b in B:
    ab +=[a+b]
ab.sort(reverse=True)
C.sort(reverse=True)
state = [[ab[0]+C[i],0,i] for i in range(len(C))]
count  = 0
while count<K:
  s = max(state)
  print(s[0])
  count +=1
  x = s[1]
  i = s[2]
  if x<X*Y-1:
    state[i][0] = C[i]+ab[x+1]
    state[i][1] = x+1
  else:
    state[i][0] = -1