Harryxun/stf_run huggingface dataset:
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7


def solve(N, K, A):
    ans = 1
    if N == K:
        for i in range(K):
            ans *= A[i]
            ans %= MOD
    elif max(A) < 0 and K % 2 == 1:
        A.sort(reverse=True)
        for i in range(K):
            ans *= A[i]
            ans %= MOD
    else:
        A_nonneg = [a for a in A if a >= 0]
        A_neg = [a for a in A if a < 0]
        A_nonneg.sort()
        A_neg.sort(reverse=True)
        count = 0
        while count < K:
            if count == K - 1 or len(A_neg) < 2 or A_nonneg[-1] > A_neg[-1] * A_neg[-2]:
                count += 1
                ans *= A_nonneg.pop()
            else:
                count += 2
                ans *= A_neg.pop()
                ans *= A_neg.pop()
            ans %= MOD
    return ans


print(solve(N, K, A))

### FIXED CODE ###

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


def solve(N, K, A):
    ans = 1
    # K = N の場合は明らか
    if K == N:
        for i in range(K):
            ans *= A[i]
            ans %= MOD
    # Ai の全ての数が負かつ K が奇数のとき、
    elif max(A) < 0 and K % 2 == 1:
        A.sort(reverse=True)
        # 絶対値が小さい方から K 個の積
        for i in range(K):
            ans *= A[i]
            ans %= MOD
    # それ以外の場合、積は必ず非負
    else:
        # {Ai} を絶対値の降順にソート
        A.sort(key=abs, reverse=True)
        # 最初の K 個の積
        sign = 1
        for i in range(K):
            ans *= A[i]
            ans %= MOD
            if A[i] < 0:
                sign *= -1
            elif A[i] == 0:
                sign *= 0
        # P が負の場合
        if sign < 0:
            small_nonneg = [a for a in A[K:] if a >= 0]
            small_neg = [a for a in A[K:] if a < 0]
            large_nonneg = [a for a in A[:K] if a >= 0]
            large_neg = [a for a in A[:K] if a < 0]
            if not small_neg or not large_nonneg:
                ans *= max(small_nonneg)
                ans %= MOD
                ans *= pow(max(large_neg), MOD - 2, MOD)
                ans %= MOD
            elif not small_nonneg or not large_neg:
                ans *= min(small_neg)
                ans %= MOD
                ans *= pow(min(large_nonneg), MOD - 2, MOD)
                ans %= MOD
            else:
                if min(small_neg) * max(large_neg) > max(small_nonneg) * min(
                    large_nonneg
                ):
                    # (2) 正の数を 1 つ取り除き、負の数を 1 つ加える
                    ans *= min(small_neg)
                    ans %= MOD
                    ans *= pow(min(large_nonneg), MOD - 2, MOD)
                    ans %= MOD
                else:
                    # (1) 負の数を 1 つ取り除き、非負の数を 1 つ加える
                    ans *= max(small_nonneg)
                    ans %= MOD
                    ans *= pow(max(large_neg), MOD - 2, MOD)
                    ans %= MOD
    return ans


print(solve(N, K, A))
N,X = [int(x) for x in input().split()]
mi = 110000000
for i in range(N):
  x = int(input())
  ans +=x 
  mi = min(x,mi)
print(N+(X-ans)//mi)

### FIXED CODE ###

N,X = [int(x) for x in input().split()]
mi = 110000000
ans = 0
for i in range(N):
  x = int(input())
  ans +=x 
  mi = min(x,mi)
print(N+(X-ans)//mi)
int = input().split()

N = int[0]
R = int[1]

if N >=10 :
  print(R)
else:
  print(100*(10-N))
  
  

### FIXED CODE ###

input_data = input().split()
 
N = int(input_data[0])
R = int(input_data[1])
 
if N >= 10 :
  print(R)
else:
  print(R+100*(10-N))
s = input()
if "a" in s ans "b" in s and "c" in s:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = input()
if "a" in s and "b" in s and "c" in s:
  print("Yes")
else:
  print("No")
from fractions import gcd

class SegmentTree():
    _data = []
    _offset = 0
    
    def __init__(self, size):
        t = 1
        while t <= size:
            t *= 2
        self._offset = t - 1
        self._data = [0] * (t * 2 - 1)
    
    def update_all(self, iterable):
        for i, v in enumerate(iterable):
            self._data[i + self._offset] = v
        for i in range(self._offset - 1, -1, -1):
            self._data[i] = gcd(self._data[i * 2 + 1], self._data[i * 2 + 2])
    
    def update(self, index, value):
        i = self._offset + index
        self._data[i] = value
        while i >= 1:
            i = (i - 1) // 2
            self._data[i] = gcd(self._data[i * 2 + 1], self._data[i * 2 + 2])
    
    def _query(self, start, stop, index, left, right):
        if right <= start or stop <= left:
            return 0
        if start <= left and right <= stop:
            return self._data[index]
        a = self._query(start, stop, index * 2 + 1, left, (left + right) // 2)
        b = self._query(start, stop, index * 2 + 2, (left + right) // 2, right)
        return gcd(a, b)
    
    def query(self, start, stop):
        return self._query(start, stop, 0, 0, self._offset + 1)

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

st = SegmentTree(N)
st.update_all(A)

result = st.query(1, N)
for i in range(1, N - 1):
    result = max(result, gcd(st.query(0, i), st.query(i + 1, N)))
result = max(result, gcd(st.query(0, i), st.query(0, N - 1)))
print(result)

### FIXED CODE ###

from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
c1 = [0] * (n + 1)
c2 = [0] * (n + 1)
# c1[1] = a[0]
# c2[n - 1] = a[n - 1]
for i in range(1, n + 1):
  c1[i] = gcd(c1[i - 1], a[i - 1])
  c2[n - i] = gcd(c2[n - i + 1], a[n - i])
print(max(gcd(c1[i], c2[i + 1]) for i in range(n)))
(a,b,c,d,e,f)  =  map(int,input().split())
  g = (a * e)  - (b * d)
  ans1= "{0:.3f}".format((( e * c) + ( -b * f)) / g)
  ans2= "{0:.3f}".format(((-d * c) + (  a * f)) / g)
  print (ans1,ans2)


### FIXED CODE ###

while True:
    try:
        (a,b,c,d,e,f)  =  map(int,input().split())
    except:
        break
    g = (a * e)  - (b * d)
    ans1= "{0:.3f}".format((( e * c) + ( -b * f)) / g + 0)
    ans2= "{0:.3f}".format(((-d * c) + (  a * f)) / g + 0)
    print (ans1,ans2)
N, K = map(int, input().split())
H = sorted([int(input()) for _ in range(N)])

print(min(H[i+K-1] - H[i] for i in range(N-2)))

### FIXED CODE ###

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

m = []
for i in range(N-K+1):
    m.append(h[i+K-1] - h[i])
print(min(m))
N, A, B, C = list(map(str, input().split()))
l = [0]*N
for i in range(N):
    l[i] = int(input())


def dfs(A_list, B_list, C_list, i):
    if i == N:
        return A - sum(A_list) + B - sum(B_list) + C - sum(C_list)

    dfs_not_used = dfs(A_list, B_list, C_list, i+1)
    dfs_A = dfs(A_list.append(l[i]), B_list, C_list, i+1) + 10
    dfs_B = dfs(A_list, B_list.append(l[i]), C_list, i+1) + 10
    dfs_C = dfs(A_list, B_list, C_list.append(l[i]), i+1) + 10

    return min(dfs_not_used, dfs_A, dfs_B, dfs_C)


ans = dfs([0], [0], [0], 0)
print(ans)


### FIXED CODE ###

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

N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for i in range(N)]


def dfs(idx, a, b, c):

    if idx == N:
        if a == 0 or b == 0 or c == 0:
            return 1e9

        return abs(A - a) + abs(B - b) + abs(C - c)

    x = dfs(idx + 1, a, b, c)
    y = dfs(idx + 1, a + L[idx], b, c) + 10*(a != 0)
    z = dfs(idx + 1, a, b + L[idx], c) + 10*(b != 0)
    w = dfs(idx + 1, a, b, c + L[idx]) + 10*(c != 0)
    return min(x, y, z, w)


ans = dfs(0, 0, 0, 0)
print(ans)
#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=input().split()
for i in range(N):
    A[i]=int(A[i])
sorted(A)#Aを昇順にソート
for i in (reversed(beki)):
    inverseA=[]
    for j in range(len(A)):
        inverseA.append(i-A[j])#inverseA
    for j in range(len(A)):
        if inverseA[j] in A:
            A.remove(inverseA[j])
print((N-len(A))//2)

### FIXED CODE ###

#AGC029 A - Irreversible operation
def countB(data):#dataのBの個数kosuとiの総和sumを返す
    sum=0
    kosu=0
    for i in range(len(data)):
        if data[i]=="B":
            kosu=kosu+1
            sum=sum+i
    return[sum,kosu]

text=input()
S=[]
N=len(text)
for i in range(N):
    S.append(text[i])
result=countB(S)
x=result[1]
Ans=int((2*N-x-1)*x/2-result[0])
print(Ans)
n, m = map(int, input().split())
e = [[] for _ in range(n)]

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

c = [0] * n
ans = []
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            print(-99999)
            exit()
        else:
            search_path(x, temp + [x])

t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(i, [i])

print(-1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

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

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

c = [0] * n
ans = []
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            print(-99999)
            exit()
        else:
            search_path(x, temp + [x])


t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(i, [i])

print(-1)
import math

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

bandc = b // c 
bandd = b // d
bandcd = b // ((c*d) // math.gcd(c,d))

aandc = a // c 
aandd = a // d
aandcd = a // ((c*d) // math.gcd(c,d))

totalb = b - bandc - bandd + bandcd
totala = a - aandc - aandd + aandcd
#print(totalb)
#print(totala)
print(totalb-totala)

### FIXED CODE ###

#最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

#最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

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

bandc = b // c 
bandd = b // d
bandcd = b // lcm(c,d)

aandc = a // c 
aandd = a // d
aandcd = a // lcm(c,d)

totalb = b - bandc - bandd + bandcd
totala = a - aandc - aandd + aandcd
#print(totalb)
#print(totala)
if (a % c != 0) and (a % d != 0):
    ans = totalb - totala + 1
else:
    ans = totalb - totala

print(ans)
import collections
N = int(input())
x = [0 for i in range(N)]
for i in range(N):
    x[i] = list(map(int, input().split()))
x.sort(key=lambda x: (x[0],x[1]))
salist = []
for i in range(1,N):
    lb, mb = x[i-1]
    l, m = x[i]
    salist.append((l-lb,m-mb))
#print(salist)
c = collections.Counter(salist)
print( N - c.most_common()[0][1])

### FIXED CODE ###

import collections
N = int(input())
x = [0 for i in range(N)]
for i in range(N):
    x[i] = list(map(int, input().split()))
x.sort(key=lambda x: (x[0],x[1]))
salist = []
if N >= 2:
    for i in range(1,N):
        for k in range(1,N):
            if i >= k:
                lb, mb = x[i-k]
                l, m = x[i]
                salist.append((l-lb,m-mb))
    #print(salist)
    c = collections.Counter(salist)
    print( N - c.most_common()[0][1])
else:
    print(1)
for letter in listofentries[1]:
    letters.append(letters)
letters1= letters[:len(letters)//2]
letters2= letters[len(letters)//2:]
  
if letters1==letters2:
	return print(Yes)
else:
  	return print(No)

### FIXED CODE ###

n=int(raw_input())
ch=raw_input()
if ch[:n//2]==ch[n//2:]:
        print('Yes')
else:
        print('No')
N = int(input())
names = []
for i in range(N):
    names.append(input())

M,A,R,C,H = 0,0,0,0,0

for i in range(N):
    if names[i][0]=='M':
        M += 1
    elif names[i][0]=='A':
        A += 1
    elif names[i][0]=='R':
        R += 1
    elif names[i][0]=='C':
        C += 1
    elif names[i][0]=='H':
        H += 1

ALL = M + A + R + C + H

def kaijo(a):
    if a==0:
        return 1
    return a*kaijo(a-1)

def permitation(a,b):
    return kaijo(a)//kaijo(a-b)

def combination(a,b):
    if a==0 or b==0:
        return 0
    elif a<b:
        return 0
    else:
        return permitation(a,b)//kaijo(b)

m2 = combination(M,2)*(ALL-M)
a2 = combination(A,2)*(ALL-A)
r2 = combination(R,2)*(ALL-R)
c2 = combination(C,2)*(ALL-C)
h2 = combination(H,2)*(ALL-H)

mC3 = combination(M,3)
aC3 = combination(A,3)
rC3 = combination(R,3)
cC3 = combination(C,3)
hC3 = combination(H,3)

ALLC3 = combination(ALL,3)

print(ALLC3-m2-a2-r2-c2-h2-mC3-aC3-rC3-cC3-hC3)

### FIXED CODE ###

N = int(input())
names = []
for i in range(N):
    names.append(input())

M,A,R,C,H= 0,0,0,0,0

for i in range(N):
    if names[i][0]=='M':
        M+=1
    elif names[i][0]=='A':
        A+=1
    elif names[i][0]=='R':
        R+=1
    elif names[i][0]=='C':
        C+=1
    elif names[i][0]=='H':
        H+=1

print(M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H)
x = x***
print(x)

### FIXED CODE ###

x = int(input())
print(x**3)
##======================================python3
import sys
import collections
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

class Run:
    def build(gv):
        gv.s = input()
    
    def string_reverse_chk(gv, s:str):
        rev_s = ''.join(reversed(s))
        if s == rev_s:
            return True
        return False
    
    def solve(gv):
        
        ans:_ = "No"
        
        while True:
            reversed_s = "".join(reversed(gv.s))
            slen = len(gv.s)
            
            if gv.string_reverse_chk(gv.s) is False : break
        
            if gv.string_reverse_chk(gv.s[0:int((slen -1)/2)]) is False : break
            if gv.string_reverse_chk(reversed_s[0:int((slen -1)/2)]) is False : break
        
            if gv.string_reverse_chk(gv.s[int((slen +3)/2 -1):slen]) is False : break
            if gv.string_reverse_chk(reversed_s[int((slen +3)/2 -1):slen]) is False : break
            
            
            ans = "Yes"
            break
        
        print(ans)
        
if __name__ == '__main__':
    run = Run()
    run.build()
    run.solve()


### FIXED CODE ###

##======================================python3
import sys
import collections
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

class Run:
    def build(gv):
        gv.s = input().strip()
    
    def string_reverse_chk(gv, s:str):
        rev_s = "".join(list(reversed(s))[0:len(s)])
        if s == rev_s:
            return True
        return False
    
    def solve(gv):
        
        ans = "No"
        
        while True:
            slen = len(gv.s)
            reversed_s = "".join(list(reversed(gv.s))[0:slen])
            
            if gv.string_reverse_chk(gv.s) is False : break
            if gv.string_reverse_chk(gv.s[0:int((slen -1)/2)]) is False : break
            if gv.string_reverse_chk(reversed_s[0:int((slen -1)/2)]) is False : break
            
            if gv.string_reverse_chk(gv.s[int((slen +3)/2 -1):slen]) is False : break
            if gv.string_reverse_chk(reversed_s[int((slen +3)/2 -1):slen]) is False : break
            
            
            ans = "Yes"
            break
        
        print(ans)
        
if __name__ == '__main__':
    run = Run()
    run.build()
    run.solve()
input1 = input()
kbai= int(input1)
 
input2=input().split(" ")
maxs= int(input2[0])
mins= int(input2[1])
flg=0
ans=0
 
while ans < maxs:
  ans=ans+kbai
  if ans >= mins and ans <= maxs:
    flg=1
 
if flg ==1:
  print("OK")
else:
  print("NG")


### FIXED CODE ###

#
#at coder beginner contest165 1%
#
import math

input1 = input()
Ns = int(input1)

wallet=100
i=0

while wallet < Ns:
    wallet=math.floor(wallet*1.01)
    i=i+1

print(i)
x,y=map(int,input().split())
mod=10**9+7

a=(2*x-y)//3
b=(2*y-x)//3



if a!=(2*x-y)/3 or b!=(2*y-x)/3:
    print(0)
else:
    max=a+b+10
    fac=[0]*max
    finv=[0]*max
    inv=[0]*max

    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i]=fac[i-1]*i%mod
        inv[i]=mod-inv[mod%i]*(mod//i)%mod
        finv[i]=finv[i-1]*inv[i]%mod

    ans=fac[a+b]*(finv[a]*finv[b]%mod)%mod
    print(ans)

### FIXED CODE ###

x,y=map(int,input().split())
mod=10**9+7

a=(2*x-y)//3
b=(2*y-x)//3



if a!=(2*x-y)/3 or b!=(2*y-x)/3:
    print(0)
elif a<0 or b<0:
    print(0)
else:
    max=a+b+10
    fac=[0]*max
    finv=[0]*max
    inv=[0]*max

    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i]=fac[i-1]*i%mod
        inv[i]=mod-inv[mod%i]*(mod//i)%mod
        finv[i]=finv[i-1]*inv[i]%mod

    ans=fac[a+b]*(finv[a]*finv[b]%mod)%mod
    print(ans)
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
a=0
for co,i in enumerate(A):
    if co==0 :
        a+=B[i-1]
    if co>=1 :
        if A[co-1]!=N:
            a+=B[i-1]
            a+=C[A[co-1]-1]
        else:
            a+=B[i-1]
print(a)


### FIXED CODE ###

N=int(input())
print(N**3)
#!/usr/bin/env python

nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]

student = list()
point = list()

for i in range(n):
    student.append([int(i) for i in input().split()])

for j in range(m):
    point.append([int(i) for i in input().split()])


mat = [[0 for j in range(m)] for i in range(m)]

for j in range(m):
    for i in range(n):
        mat[i][j] = abs(student[i][0]-point[j][0]) + abs(student[i][1]-point[j][1])

for i in range(n):
    print(mat[i].index(min(mat[i]))+1)

### FIXED CODE ###

#!/usr/bin/env python

nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]

a = list()
b = list()
c = list()
d = list()

for i in range(n):
    ab = [int(tmp) for tmp in input().split()]
    a.append(ab[0])
    b.append(ab[1])

for j in range(m):
    cd = [int(tmp) for tmp in input().split()]
    c.append(cd[0])
    d.append(cd[1])

for i in range(n):
    min_dist = abs(a[i]-c[0]) + abs(b[i]-d[0])
    checkpoint = 1
    for j in range(m):
        cur_dist = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if min_dist > cur_dist:
            min_dist = cur_dist
            checkpoint = j + 1
    print(checkpoint)
#-------------
s = input()
#-------------
N = len(s)//2
q = 0
if N%2 == 1:
  q=1
Odd = []
for i in range(N+q):
  Odd.append(s[2*i])
Odd = "".join(Odd)
print(Odd)

### FIXED CODE ###

#-------------
s = input()
#-------------
if len(s) <= 2:
  print(s[0])

else:
  N = len(s)//2
  q = 0
  if N%2 == 1:
    q=1
  Odd = []
  for i in range(N+q):
    Odd.append(s[2*i])
  Odd = "".join(Odd)
  print(Odd)
# -*- coding: utf-8 -*-
import sys
n, m = map(int, input().split())
demands = [
    tuple(map(int,
              line.strip().split())) for line in sys.stdin.readlines()
]

compressed = []
while demands:
    a, b = demands.pop()

    flag = False
    for i, (ai, bi) in enumerate(compressed):
        if b <= ai or bi <= a:
            continue

        else:
            compressed = [max(a, ai), min(b, bi)]
            break

    else:
        compressed.append([a, b])

print(len(compressed))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
n, m = map(int, input().split())
# demands = [tuple(map(int, input().split())) for i in range(m)]
demands = [
    tuple(map(int,
              line.strip().split())) for line in sys.stdin.readlines()
]
demands.sort(key=lambda x: x[1])

compressed = []
while demands:
    a, b = demands.pop()

    for i, (ai, bi) in enumerate(compressed):
        if b <= ai or bi <= a:
            continue

        else:
            compressed[i] = [max(a, ai), min(b, bi)]
            break

    else:
        compressed.append([a, b])

print(len(compressed))
from collections import defaultdict
s = defaultdict()
m = 0
for _ in range(int(input())):
  t = input()
  s[t] += 1
  m = max(m, s[t])
ans = []
for el in s:
  if s[el] == m:
    ans.append(el)
ans.sort()
for a in ans:
  print(a)

### FIXED CODE ###

s = {}
m = 0
for _ in range(int(input())):
  t = input()
  if t in s:
    s[t] += 1
  else:
    s[t] = 1
  m = max(m, s[t])
ans = []
for el in s:
  if s[el] == m:
    ans.append(el)
ans.sort()
for a in ans:
  print(a)
be=list(map(str,input().split()))
af=list(map(str,input().split()))
ans=0
for i in range 2:
  	if be[i]==af[i]:
    	ans+=1
print(ans)


### FIXED CODE ###

be=input()
af=input()
ans=0
for i in range (3):
    if be[i]==af[i]:
        ans+=1
print(ans)
from heapq import heappush,heappop
import numpy as np
n,m,s,t=map(int,input().split())
a=[[]for i in range (n+1)]
b=[[]for i in range(n+1)]
for i in range(m):
    p,q,r,g=map(int,input().split())
    a[p].append((q,r))
    a[q].append((p,r))
    b[p].append((q,g))
    b[q].append((p,g))
def f(x,r):
    p=[float("INF")for i in range(n+1)]
    p[x],q=0,[[0,x]]
    while q:
        y,z=heappop(q)
        for i,j in r[z]:
            if p[i]>y+j:
                p[i]=y+j
                heappush(q,[p[i],i])
    return p[1:]
s1,t1=f(s,a),f(t,b)
p=[]
for i in range(n):
    p.append((s1[i]+t1[i],i))
p,e=sorted(p),0
for i in range(n):
    while p[e][1]<=i: e+=1
    print(10**15-p[e][0])

### FIXED CODE ###

from heapq import heappush,heappop
n,m,s,t=map(int,input().split())
a,b=[[]for i in range (n+1)],[[]for i in range(n+1)]
for i in range(m):
    p,q,r,g=(int(i) for i in input().split())
    a[p].append((q,r))
    a[q].append((p,r))
    b[p].append((q,g))
    b[q].append((p,g))
def f(x,r):
    p=[float("inf")for i in range(n+1)]
    p[x],q=0,[[0,x]]
    while q:
        y,z=heappop(q)
        for i,j in r[z]:
            if p[i]>y+j:
                p[i]=y+j
                heappush(q,[p[i],i])
    return p
s1,t1,p=f(s,a),f(t,b),[]
for i in range(1,n+1):
    p.append((s1[i]+t1[i],i))
p,e=sorted(p),0
for i in range(n):
    while p[e][1]<=i: e+=1
    print(10**15-p[e][0])
n,x=map(int,input().split())
a=list(int(input()) for _ range(n))
print(n+((x-sum(a))//min(a)))

### FIXED CODE ###

n,x=map(int,input().split())
a=list(int(input()) for _ in range(n))
print(n+((x-sum(a))//min(a)))
a=input()
a=int(a)
if a%2==0:
  print(int((a/2)**2))
else:
  print(int(a/2)*2(int(int(a/2)+1)))


### FIXED CODE ###

a=input()
a=int(a)
if a%2==0:
  print(int((a/2)**2))
else:
  print(int(a/2)*(int(int(a/2)+1)))
import numpy as np
N = int(input())
a= list(map(int,input().split()))
score=np.array(a)
b=np.sort(score)
c=b[-1::-1]
#print(c)
x=np.argsort(a)
y=x[-1::-1]
#print(y)

#c:score、y:index
cand=list(range(N))

count=0
for i in range(N):
    if (y[i]-cand[0])>(cand[-1]-y[i]):
        count+=c[i]*abs(y[i]-cand[0])
        cand.pop(0)
    elif (y[i]-cand[0])<(cand[-1]-y[i]):
        count+=c[i]*abs(cand[-1]-y[i])
        cand.pop(-1)
    else:
        if y[i+1]>y[i]:
            count+=c[i]*abs(y[i]-cand[0])
            cand.pop(0)
        else:
            count+=c[i]*abs(cand[-1]-y[i])
            cand.pop(-1) 

print(count)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
N = int(input())
A = list(map(int, input().split()))
acts = [(x, i) for i, x in enumerate(A)]
acts.sort()
dp = [[-1]*N for _ in range(N)]
 
def solve(l, r):
    if r < l:
        return 0
    if dp[l][r] >= 0:
        return dp[l][r]
    k = r - l
    act, init_pos = acts[k]
    gain_l = act * abs(l - init_pos)
    gain_r = act * abs(r - init_pos)
    res = dp[l][r] = max(gain_l + solve(l+1, r), gain_r + solve(l, r-1))
    return res
 
print(solve(0, N-1))
S = list(input())
Q = int(input())
l_list = []
r_list = []
flag = True
for i in range(Q):
    A = list(map(str, input().split()))
    if len(A)==1:
        flag = not flag
    else:
        if flag1:
            if A[1]=="1":
                l_list.appendleft(A[2])
            else:
                r_list.append(A[2])
        else:
            if A[1]=="1":
                r_list.append(A[2])
            else:
                l_list.appendleft(A[2])
if flag:
    print("".join(l_list)+"".join(S)+"".join(r_list))
else:
    print("".join(r_list[::-1])+"".join(S[::-1])+"".join(l_list[::-1]))

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
flag = True
for i in range(Q):
    A = list(map(str, input().split()))
    if len(A)==1:
        flag = not flag
    else:
        if flag:
            if A[1]=="1":
                S.appendleft(A[2])
            else:
                S.append(A[2])
        else:
            if A[1]=="1":
                S.append(A[2])
            else:
                S.appendleft(A[2])
S = "".join(S)
if flag:
    print(S)
else:
    print(S[::-1])