Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s  = input()[::-1]
lsts = [0] * 2019
kai = 1
cou = 0
st = 0
lsts[0] = 1
for i in s:
  st =(st + int(i) * kai) % 2019
  cou += lsts[st]
  lsts[st] += 1  
  kai = kai * 10
 
print(cou)

Fixed submission:
from collections import deque
s  = input()[::-1]
lsts = [0] * 2019
kai = 1
cou = 0
st = 0
lsts[0] = 1
for i in s:
  st += int(i) * kai
  st %= 2019
  cou += lsts[st]
  lsts[st] += 1  
  kai = kai * 10 % 2019

print(cou)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = list(input())
lsts = deque()
kai = 0
cou = 0
for i in range(len(s)):
  s[i] = int(s[i])
s.reverse()
s = deque(s)
cou = 0
le = len(s)
st = 0

for i in s:
  st += i * (10 ** kai)
  amari = st % 2019
  if amari == 0:
    cou += 1
  else:
    lsts.append(amari)  
  kai += 1

while lsts:
  atai = lsts.pop()
  kosu = lsts.count(atai)
  if kosu != 0:
    cou += int(kosu * (kosu+1) / 2)
    for i in range(kosu):
      lsts.remove(atai)

print(cou)

Fixed submission:
from collections import deque
s  = input()[::-1]
lsts = [0] * 2019
kai = 1
cou = 0
st = 0
lsts[0] = 1
for i in s:
  st += int(i) * kai
  st %= 2019
  cou += lsts[st]
  lsts[st] += 1  
  kai = kai * 10 % 2019

print(cou)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = deque(input())
lsts = deque()

for i in range(len(s)):
  s[i] = int(s[i])
cou = 0

for i in range(100):
  lsts = deque(s)
  l = 2019*(i+1)
  llen = len(str(l))
  
  for j in range(len(s)-llen+1):
    st = 0
    
    for k in range(llen):
      st += lsts[-(1+k)] * (10**k)
      
    lsts.pop()
    if st == l:
      cou += 1

print(cou)

Fixed submission:
from collections import deque
s  = input()[::-1]
lsts = [0] * 2019
kai = 1
cou = 0
st = 0
lsts[0] = 1
for i in s:
  st += int(i) * kai
  st %= 2019
  cou += lsts[st]
  lsts[st] += 1  
  kai = kai * 10 % 2019

print(cou)
Buggy python submission (verdict: Runtime Error):
2
1 1
1 1

Fixed submission:
N=int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

xyp=[]
xym=[]
for i in range(N):
    xyp.append(x[i]+y[i])
    xym.append(x[i]-y[i])
    
print(max(max(xyp)-min(xyp),-min(xym)+max(xym),max(xym)-min(xym),-min(xym)+max(xym)))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

limit=10**9+7
for i in range(N):
    A[i]=A[i]%limit
ans=0
for i in range(N-1):
    ans+=(A[i]*(sum(A[i+1:])%limit))
    ans=ans%limit
print(ans)

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

limit=10**9+7
S=[0]
for i in range(N):
    A[i]=A[i]%limit
for i in range(1,N):
    S.append((S[i-1]+A[-i])%limit)
ans=0
for i in range(N-1):
    ans+=A[i]*S[-1-i]
    ans=ans%limit
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

limit=10**9+7

ans=0
for i in range(N-1):
    ans+=(A[i]*(sum(A[i+1:])%limit))
    ans=ans%limit
print(ans)

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

limit=10**9+7
S=[0]
for i in range(N):
    A[i]=A[i]%limit
for i in range(1,N):
    S.append((S[i-1]+A[-i])%limit)
ans=0
for i in range(N-1):
    ans+=A[i]*S[-1-i]
    ans=ans%limit
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

limit=10**9+7

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        ans+=A[i]*A[j]
        ans=ans%limit
print(ans)

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

limit=10**9+7
S=[0]
for i in range(N):
    A[i]=A[i]%limit
for i in range(1,N):
    S.append((S[i-1]+A[-i])%limit)
ans=0
for i in range(N-1):
    ans+=A[i]*S[-1-i]
    ans=ans%limit
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break

if C[-1]=="R":
    for i in range(1,N):
        if C[-i]=="W":
            C=C[:-i+1]
            break    
    

print(min(C.count("R"),C.count("W")))

Fixed submission:
N=int(input())
C=input()

W=0
R=C.count("R")
ans=R
for i in range(N):
    
    if C[i]=="R":
        R-=1
    else:
        W+=1
    if  ans>max(W,R):
        ans=max(W,R)
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break

for i in range(1,N):
    if C[-i]=="W":
        C=C[:-i+1]
        break    
    

print(min(C.count("R"),C.count("W")))

Fixed submission:
N=int(input())
C=input()

W=0
R=C.count("R")
ans=R
for i in range(N):
    
    if C[i]=="R":
        R-=1
    else:
        W+=1
    if  ans>max(W,R):
        ans=max(W,R)
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break
for i in range(N):
    if C[-i]=="W":
        C=C[:-i+1]
        break    
    

print(min(C.count("R"),C.count("W")))

Fixed submission:
N=int(input())
C=input()

W=0
R=C.count("R")
ans=R
for i in range(N):
    
    if C[i]=="R":
        R-=1
    else:
        W+=1
    if  ans>max(W,R):
        ans=max(W,R)
print(ans)
Buggy python submission (verdict: Runtime Error):
A=list(map(int,input().split())
print(A[0]*A[1])

Fixed submission:
A=list(map(int,input().split()))
print(A[0]*A[1])

Buggy python submission (verdict: Runtime Error):
A=list(map(int,input().split)
print(A[0]*A[1])

Fixed submission:
A=list(map(int,input().split()))
print(A[0]*A[1])
Buggy python submission (verdict: Runtime Error):
A, B=map(int,input().split())
print(A*B)

Fixed submission:
A, B=(input().split())
A=int(A)
C=int(B[0])*100+int(B[2])*10+int(B[3])
print(int(A*C//100))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
def is_multiple_of_nine(x):
    if x < 10:
        if x == 0 or x == 9:
            return True
        else:
            return False
    else:
        running_sum = 0
        while x:
            running_sum += x % 10
            x = x // 10
        return is_multiple_of_nine(running_sum)
    
if is_multiple_of_nine(n):
    print("Yes")
else:
    print("No")

Fixed submission:
import math
n = str(input())
    
running_sum = 0
for i in n:
    if i != "0" and i != "9":
        running_sum += int(i)

if running_sum % 9 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import math
n, k = list(map(int,input().split()))
a = list(map(int,input().split()))

def lte_k(x, len_list):
    counter = 0
    for item in len_list:
        counter += math.ceil(item / x) - 1
    return counter <= k

def binary_search():
    low = 0
    high = max(a)

    while low < high-1:
        mid = (low + high) // 2
        guess = lte_k(mid, a)
        if guess:
            high = mid
        else:
            low = mid
    return high

print(binary_search())

Fixed submission:
x = int(input())
if x >= 30:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
answer = [0] * N
for i in range(N):
    tmp = a[:i] + a[i+1:]
    ans = tmp[0]
    for j in range(1, len(tmp)):
        ans = ans ^ tmp[j]
    answer[i] = ans
    
print(' '.join(map(str, answer)))

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
all_xor = a[0]
for j in range(1, len(a)):
    all_xor = all_xor ^ a[j]
answer = [0] * N
for i in range(N):
    answer[i] = all_xor ^ a[i]
    
print(' '.join(map(str, answer)))
Buggy python submission (verdict: Runtime Error):
A, B = int(input().split())
print(A, B)

Fixed submission:
A, B = list(map(int, input().split()))
print(A*B)

Buggy python submission (verdict: Runtime Error):
print(A * B)

Fixed submission:
A, B = list(map(int, input().split()))
print(A*B)
Buggy python submission (verdict: Runtime Error):
A, B = input().split()

A = int(A)
B = float(B)
B = (B*100).round()

print((A*B)//100)

Fixed submission:
A, B = input().split()
 
A = int(A)
B = float(B)
B = round((B*100))
 
print((A*B)//100)
Buggy python submission (verdict: Runtime Error):
S = str(input())
T = str(input())
 
if len(S) + 1 == len(T) and S = T[:-1]:
	print("Yes")
else:
	print("No")

Fixed submission:
S = str(input())
T = str(input())
 
if len(S) + 1 == len(T) and S == T[:-1]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
S = str(input())
T = str(input())

if len(S) + 1 == len(T) and S = T[:-1]:
  print("Yes")
else:
  print("No")

Fixed submission:
S = str(input())
T = str(input())
 
if len(S) + 1 == len(T) and S == T[:-1]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a, b, c, k = list(map(input().split()))
if k < a:
    return k
elif k < a+b:
    return a
else:
    return a - (k-a-b)

Fixed submission:
a, b, c, k = list(map(int, input().split()))
if k < a:
    print(k)
elif k < a+b:
    print(a)
else:
    print(a-(k-a-b))
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, M, X = list(map(int, input().split()))
a = np.zeros((N, M))
C = np.zeros(N)
for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] += tmp[0]
    a[i] += tmp[1:]

a = a.reshape(M, N)

answer_price = 2**10

for i in range(1 << N):
    tmp = np.zeros(M)
    cost = 0
    for j in range(N):
        if i % 2 == 1:
            tmp += a[j]
            cost += C[j]
        i = i >> 1
    if all(tmp >= X) and cost < answer_price:
        answer_price = cost
        
if answer_price == 2**10:
    print("-1")
else:
    print(int(answer_price))

Fixed submission:
import numpy as np

N, M, X = list(map(int, input().split()))
a = np.zeros((N, M))
C = np.zeros(N)
for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] += tmp[0]
    a[i] += tmp[1:]
    
answer_price = 10**10

for i in range(1 << N):
    tmp = np.zeros(M)
    cost = 0
    for j in range(N):
        if i % 2 == 1:
            tmp += a[j]
            cost += C[j]
        i = i >> 1

    if all(tmp >= X) and (cost < answer_price):
        answer_price = cost
        
if answer_price == 10**10:
    print("-1")
else:
    print(int(answer_price))

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, M, X = list(map(int, input().split()))
a = np.zeros((M, N))
C = np.zeros(N)
for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] += tmp[0]
    a[i] += tmp[1:]

a = a.reshape(M, N)

answer_price = 2**10

for i in range(1 << N):
    tmp = np.zeros(M)
    cost = 0
    for j in range(N):
        if i % 2 == 1:
            tmp += a[j]
            cost += C[j]
        i = i >> 1
    if all(tmp >= X) and cost < answer_price:
        answer_price = cost
        
if answer_price == 2**10:
    print("-1")
else:
    print(int(answer_price))

Fixed submission:
import numpy as np

N, M, X = list(map(int, input().split()))
a = np.zeros((N, M))
C = np.zeros(N)
for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] += tmp[0]
    a[i] += tmp[1:]
    
answer_price = 10**10

for i in range(1 << N):
    tmp = np.zeros(M)
    cost = 0
    for j in range(N):
        if i % 2 == 1:
            tmp += a[j]
            cost += C[j]
        i = i >> 1

    if all(tmp >= X) and (cost < answer_price):
        answer_price = cost
        
if answer_price == 10**10:
    print("-1")
else:
    print(int(answer_price))
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))

done_list = [1]
cur_place = 1
flag = True
for i in range(K):
    if a_list[cur_place-1] not in done_list:
        cur_place = a_list[cur_place-1]
        done_list.append(cur_place)
    else:
        period = len(done_list) - done_list.index(a_list[cur_place-1])
        print(done_list[done_list.index(a_list[cur_place-1]) + (K - i) % period + 1])
        flag = False
        break

if flag:        
    print(cur_place)
    

Fixed submission:
N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))

before = 1
start = 0
end = 0

if K <= N:
    for i in range(K):
        before = a[before]
    print(before)

# 周期がどこからどこまでかっていうのを求めると逆に時間がかかってしまうので、N回移動したあとの街っていうのをマークしたほうがはやい
    
else:
    market_town = 0
    for i in range(N):
        before = a[before]
    marked_town = before
    K -= N
    counter = 1
    while marked_town != a[before]:
        before = a[before]
        counter += 1
    K = K % counter
    for i in range(K+1):
        before = a[before]
    print(before)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.special import comb

N, M, K = list(map(int, input().split()))
mod = 998244353

c = comb(N-1, K, exact=True)
exp = ((M-1) ** (N-1-K)) % mod

answer = (M * c * exp) % mod

for t in range(1, K+1):
    c = ((c * (K - t + 1)) // (N-1-K+t))
    exp = (exp*(M-1)) % mod
    answer += (M * c * exp) % mod
    answer = answer % mod

print(answer)

Fixed submission:
N, M, K = list(map(int, input().split()))
mod = 998244353

c = 1
answer = 0

for i in range(K+1):
    answer += (M * c  * pow(M-1, N - i - 1, mod)) % mod
    answer %= mod
    c = (c * (N-i-1) * pow(i+1, mod-2, mod)) % mod
    
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, M, K = list(map(int, input().split()))
mod = 998244353
d = np.zeros(K+2)
d[1] = M
for _ in range(N-1):
    d[1:] = (d[:-1] + d[1:] * (M-1)) % mod
print(int(sum(d) % mod))

Fixed submission:
N, M, K = list(map(int, input().split()))
mod = 998244353

c = 1
answer = 0

for i in range(K+1):
    answer += (M * c  * pow(M-1, N - i - 1, mod)) % mod
    answer %= mod
    c = (c * (N-i-1) * pow(i+1, mod-2, mod)) % mod
    
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

mod = 998244353

d = np.zeros(K+1)
d[0] = M

for _ in range(N-1):
    d[1:] = (d[:-1] + d[1:] * (M-1)) % mod
    d[0] = (d[0] * (M-1))  % mod

print(int(sum(d) % mod))

Fixed submission:
N, M, K = list(map(int, input().split()))
mod = 998244353

c = 1
answer = 0

for i in range(K+1):
    answer += (M * c  * pow(M-1, N - i - 1, mod)) % mod
    answer %= mod
    c = (c * (N-i-1) * pow(i+1, mod-2, mod)) % mod
    
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split(" ")]

from itertools import combinations

mod = 1000000007  # 丁度いい大きさの素数だけで意味は特にない。
s = 0
for c in combinations(A, 2):
    s += c[0] * c[1]

print(s % mod)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split(" ")]

from itertools import combinations

mod = 1000000007  # 丁度いい大きさの素数だけで意味は特にない。

s = 0
ans = 0
for n in A:
    s += n
    s %= mod

for i in range(N):
    s -= A[i]
    ans += A[i] * s
    ans %= mod

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input)
A = [int(x) for x in input().split(" ")]

from itertools import combinations

mod = 1000000007  # 丁度いい大きさの素数だけで意味は特にない。
s = 0
for c in combinations(A, 2):
    s += c[0] * c[1]

print(s % mod)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split(" ")]

from itertools import combinations

mod = 1000000007  # 丁度いい大きさの素数だけで意味は特にない。

s = 0
ans = 0
for n in A:
    s += n
    s %= mod

for i in range(N):
    s -= A[i]
    ans += A[i] * s
    ans %= mod

print(ans)
Buggy python submission (verdict: Runtime Error):

strN = input()
s = 0
for c in strN:
  s += int(c)

  if s % 9 == 0:
    print("Yes")
    else:
      print("No")

Fixed submission:

strN = input()
s = 0
for c in strN:
  s += int(c)

if s % 9 == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
def check_h(a):
    for row in a:
        if row == [0, 0, 0]:
            return True


def check_v(a):
    for col in range(3):
        if [row[col] for row in a] == [0, 0, 0]:
            return True


def check_c(a):
    if [a[i][i] for i in range(3)] == [0, 0, 0] or [a[i][2 - i] for i in range(3)] == [0, 0, 0]:
        return True


def resolve():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    for _ in range(N):
        B = int(input())
        mark(A, B)
    if check_h(A) or check_v(A) or check_c(A):
        print("Yes")
    else:
        print("No")
resolve()

Fixed submission:
def mark(a, b):
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = 0


def check_h(a):
    for row in a:
        if row == [0, 0, 0]:
            return True


def check_v(a):
    for col in range(3):
        if [row[col] for row in a] == [0, 0, 0]:
            return True


def check_c(a):
    if [a[i][i] for i in range(3)] == [0, 0, 0] or [a[i][2 - i] for i in range(3)] == [0, 0, 0]:
        return True


def resolve():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    for _ in range(N):
        B = int(input())
        mark(A, B)
    if check_h(A) or check_v(A) or check_c(A):
        print("Yes")
    else:
        print("No")
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    A = [int(input()) - 1 for _ in range(N)]

    pressed = []
    i = 0
    t = 0
    while i != 1:
        i = A[i]
        if i in pressed:
            t = -1
            break
        pressed.append(i)
        t += 1

    print(t)
    
resolve()

Fixed submission:
def resolve():
    N = int(input())
    A = [int(input()) - 1 for _ in range(N)]

    pressed = 0
    i = 0
    t = 0
    while i != 1:
        i = A[i]
        if pressed > N:
            t = -1
            break
        pressed += 1
        t += 1

    print(t)
    
resolve()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
kane = 1000
kabu = 0
for i in range(0, n - 1):
    if a[i] > a[i + 1]:
        kane += a[i] * kabu
        kabu = 0
    if a[i] < a[i + 1]:
        kabu = kane // a[i]
        kane %= a[i]
kane += a[n - 1] * kabu
print(kane)

Fixed submission:
x = int(input())
print(8 - ((x - 400) // 200))
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
p = []

for i in range(N):
    x = int(input())
    p.append(x)

p.sort()

y = 0

for i in range(K):
    y += p[i]

print(y)


Fixed submission:
K = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
y = 0
for i in range(K[1]):
    y += p[i]
print(y)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
m = max(a)
count = 0
nishin = []

while True:
    m, r = divmod(m, 2)
    count += 1
    if m == 0:
        break

for i in range(0, N):
    for j in range(0, count):
        a[i], r = divmod(a[i], 2)
        nishin.append(str(r))
    a[i] = ''.join(reversed(nishin))
    nishin.clear()

for k in range(0, N):
    q = ''
    for j in range(0, count):
        p = 0
        for i in range(0, N):
            if i == k:
                pass
            else:
                p += int(a[i][j])
        p %= 2
        q += str(p)
    nishin.append(q)

jusshin = [int(i, 2) for i in nishin]

ans = ''

for i in range(0, N-1):
    ans += (str(jusshin[i]) + ' ')

ans += str(jusshin[N-1])
print(ans)


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
x = 0
for i in range(0, N):
    x ^= a[i]
ans = []
for i in range(0, N):
    ans.append(str(x ^ a[i]))

print(' '.join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
def fun(n):
    return (n*(n+1))//2
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(len(a)):
    d[a[i]] = 0
for i in range(len(a)):
    d[a[i]] += 1
for i in range(len(a)):
    ans = 0
    d[a[i]] -= 1
    for j in d:
        ans += fun(d[j]-1)
    print(ans)
    d[a[i]] += 1

Fixed submission:
def fun(n):
    return (n*(n+1))//2
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(len(a)):
    d[a[i]] = 0
for i in range(len(a)):
    d[a[i]] += 1
total = 0
for i in d:
    total += fun(d[i]-1)
for i in d:
    d[i] = total - (d[i] -1)
for i in range(len(a)):
    print(d[a[i]])
Buggy python submission (verdict: Runtime Error):
inp = list(map(int,input().split()))
if (inp[0]*inp[1])%2==1:
  print((inp[0]*inp[1])//2+1)
else:
  print((inp[0]*inp[1])//2)

Fixed submission:
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())-1])

Buggy python submission (verdict: Runtime Error):
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())])

Fixed submission:
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())-1])
Buggy python submission (verdict: Time Limit Exceeded):
str = input()
a = str.split(" ")
n = (int)(a[0])
k = (int)(a[1])
str = input();
for ii in range(k-1):
  s = str + str[::-1]
  s1 = s[0:n]
  for i in range(1,n+1):
    s2 = s[i:n+i]
    if(s1>s2):
      s1 = s2
  str = s1[::-1]

s = str + str[::-1]
s1 = s[0:n]
for i in range(1,n+1):
  s2 = s[i:n+i]
  if(s1>s2):
    s1 = s2
print(s1)

Fixed submission:
str = input()
a = str.split(" ")
n = (int)(a[0])
k = (int)(a[1])
str = input()
before = ""
for ii in range(k-1):
  s = str + str[::-1]
  s1 = s[0:n]
  for i in range(1,n+1):
    s2 = s[i:n+i]
    if(s1>s2):
      s1 = s2
  str = s1[::-1]
  if(before==str):
    break
  before = str

s = str + str[::-1]
s1 = s[0:n]
for i in range(1,n+1):
  s2 = s[i:n+i]
  if(s1>s2):
    s1 = s2
print(s1)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

ok = a[-1]
ng = 0
while abs(ok - ng)>1:
    X = (ok + ng)//2
    
    cnt = 0
    for i in range(n):
        temp = a[-(i + 1)]
        if temp <= X:break
        temp_cnt = (temp + X - 1)//X - 1
        cnt += temp_cnt
    
    if cnt <= k:ok = X
    else:ng = X
    
print(ok)

Fixed submission:
n, k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

ok = a[-1]
ng = 0
while abs(ok - ng)>1:
    X = (ok + ng)//2
    
    cnt = 0
    for i in range(n):
        temp = a[-(i + 1)]
        if temp <= X:break
        temp_cnt = (temp + X - 1)//X - 1
        cnt += temp_cnt
    
    if cnt <= k:ok = X
    else:ng = X
    
print(ok)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
res = a[0]
a.pop(0)
cnt = n - 2
while cnt > 0:
    if cnt >= 2:
        res += a.pop(0) * 2
        cnt -= 2
    
    elif cnt == 1:
        res += a.pop(0)
        cnt -= 1
    
print(res)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
res = a[0]
a.pop(0)

num = (n - 2) // 2
num1 = (n - 2) % 2
res += sum(a[:num]) * 2 + a[num] * num1
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

rec = [0] * n

def check(k):
    off = []
    on = []
    flag = 0
    for i in range(n):
        if (a[i]>>k)&1:
            flag += 1
            on.append(i)
        else:
            off.append(i)

    if flag%2 == 0:
        for i in on:
            rec[i] += pow(2, k)
    else:
        for i in off:
            rec[i] += pow(2, k)

for i in range(31):
    check(i)
print(*rec)



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

rec = [0] * n

def check(k):
    off = []
    on = []
    flag = 0
    for i in range(n):
        if (a[i]>>k)&1:
            flag += 1
            on.append(i)
        else:
            off.append(i)

    if flag%2 == 0:
        for i in on:
            rec[i] += pow(2, k)
    else:
        for i in off:
            rec[i] += pow(2, k)

for i in range(31):
    check(i)
print(*rec)