Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

reverse_flag = False

top = []
last = []
for i in range(q):
  q_list = list(input().split())
  
  if len(q_list) == 1:
    reverse_flag = not reverse_flag
    
  elif q_list[1] == '1' and (not reverse_flag):
    top.insert(0, q_list[2])
    
  elif q_list[1] == '2' and (not reverse_flag):
    last.append(q_list[2])
    
  elif q_list[1] == '1' and reverse_flag:
    last.append(q_list[2])
    
  elif q_list[1] == '2' and reverse_flag:
    top.insert(0, q_list[2])
    
if reverse_flag:
  print(''.join(reversed(last)) + ''.join(reversed(s)) + ''.join(reversed(top)))
else:
  print(''.join(top) + ''.join(s) + ''.join(last))

Fixed submission:
s = list(input())
q = int(input())

reverse_flag = False

top = []
last = []
for i in range(q):
  q_list = list(input().split())
  
  if len(q_list) == 1:
    reverse_flag = not reverse_flag
    
  elif q_list[1] == '1' and (not reverse_flag):
    top.append(q_list[2])
    
  elif q_list[1] == '2' and (not reverse_flag):
    last.append(q_list[2])
    
  elif q_list[1] == '1' and reverse_flag:
    last.append(q_list[2])
    
  elif q_list[1] == '2' and reverse_flag:
    top.append(q_list[2])
    
if reverse_flag:
  print(''.join(reversed(last)) + ''.join(reversed(s)) + ''.join(top))
else:
  print(''.join(reversed(top)) + ''.join(s) + ''.join(last))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

reverse_flag = False
for i in range(q):
  q_list = list(input().split())
  
  if len(q_list) == 1:
    reverse_flag = not reverse_flag
    
  elif q_list[1] == '1' and (not reverse_flag):
    s = q_list[2] + s
    
  elif q_list[1] == '2' and (not reverse_flag):
    s += q_list[2]
    
  elif q_list[1] == '1' and reverse_flag:
    s += q_list[2]
    
  elif q_list[1] == '2' and reverse_flag:
    s = q_list[2] + s
    
if reverse_flag:
  print(''.join(list(reversed(s))))
else:
  print(s)

Fixed submission:
s = list(input())
q = int(input())

reverse_flag = False

top = []
last = []
for i in range(q):
  q_list = list(input().split())
  
  if len(q_list) == 1:
    reverse_flag = not reverse_flag
    
  elif q_list[1] == '1' and (not reverse_flag):
    top.append(q_list[2])
    
  elif q_list[1] == '2' and (not reverse_flag):
    last.append(q_list[2])
    
  elif q_list[1] == '1' and reverse_flag:
    last.append(q_list[2])
    
  elif q_list[1] == '2' and reverse_flag:
    top.append(q_list[2])
    
if reverse_flag:
  print(''.join(reversed(last)) + ''.join(reversed(s)) + ''.join(top))
else:
  print(''.join(reversed(top)) + ''.join(s) + ''.join(last))
Buggy python submission (verdict: Runtime Error):
a

Fixed submission:
import math
n = int(input())

print(math.ceil(n/2))
Buggy python submission (verdict: Runtime Error):
def comb(n,k):
  if n == 0:
    return 0
  if n == k:
    return 1
  
  num = 1
  for i in range(n-k+1,n+1):
    num *= i
    
  for i in range(2,k+1):
    num //= i
    

  return num
    
def syou(n,k):
  if k == 0:
    return 1
  
  if len(n) < k:
    return 0
  
  if len(n) == 1:
    return int(n)
  
  if n[0] == '0':
    return syou(n[1:l], k-1)
  
  l = len(n)
  ans = comb(l-1, k) * (9**k)
  
  top = int(n[0])
  ans += comb(l-1, k-1) * (top-1) * (9**(k-1))
  
  ans += syou(n[1:l], k-1)
  print('tmp:', n,k,ans)
  return ans


n = input()
k = int(input())

print(syou(n, k))

Fixed submission:
def comb(n,k):
  if n == 0:
    return 0
  if n == k:
    return 1
  
  num = 1
  for i in range(n-k+1,n+1):
    num *= i
    
  for i in range(2,k+1):
    num //= i
    

  return num
    
def syou(n,k):
  if k == 0:
    return 1
  
  if len(n) < k:
    return 0
  
  if len(n) == 1:
    return int(n)
  
  l = len(n)
  if n[0] == '0':
    return syou(n[1:l], k)
  
  ans = comb(l-1, k) * (9**k)
  
  top = int(n[0])
  ans += comb(l-1, k-1) * (top-1) * (9**(k-1))
  
  ans += syou(n[1:l], k-1)
  return ans


n = input()
k = int(input())

print(syou(n, k))
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))

one_count = [0] * 61
for v in a:
  count = 0
  while v != 0:
    if v % 2 == 1:
      one_count[count] += 1
      
    count += 1
    v //= 2
  

ans = 0
for i in range(len(one_count)):
  ans += (one_count[i] * (n - one_count[i]) * (2 ** i))
  ans %= MOD
  
print(ans)

Fixed submission:
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
 
one_count = [0] * 61
for v in a:
  count = 0
  while v != 0:
    if v % 2 == 1:
      one_count[count] += 1
      
    count += 1
    v //= 2
  
 
ans = 0
for i in range(len(one_count)):
  ans += (one_count[i] * (n - one_count[i]) * (2 ** i))
  ans %= MOD
  
print(ans)

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

count = 0
for i in range(n-1):
  for j in range(i+1,n):
    count += (a[i] ^ a[j])
    count %= 10 ** 9 + 7
  
print(count)

Fixed submission:
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
 
one_count = [0] * 61
for v in a:
  count = 0
  while v != 0:
    if v % 2 == 1:
      one_count[count] += 1
      
    count += 1
    v //= 2
  
 
ans = 0
for i in range(len(one_count)):
  ans += (one_count[i] * (n - one_count[i]) * (2 ** i))
  ans %= MOD
  
print(ans)
Buggy python submission (verdict: Runtime Error):
def func(iro,tree,num,max_color):
  if num not in tree:
    return
  
  my_color = iro[num]
  arr = tree[num]
  
  for i in arr:
    my_color += 1
    iro[i] = my_color % max_color
    func(iro,tree,i,max_color)
    

n = int(input())
tree = {}

b_arr = []
for i in range(n-1):
  a,b = map(int,input().split())
  
  b_arr.append(b)
  if a not in tree:
    tree[a] = []
    
  tree[a].append(b)

tree = sorted(tree.items())
  
color = len(tree[1])
for key in tree.keys():
  if key == 1:
    continue
    
  arr = tree[key]
  color = max(len(arr)+1, color)

print(color)

iro = [-1] * (n+1)

for key in tree.keys():
  my_color = iro[key]
  arr = tree[key]
  for i in arr:
    my_color += 1
    iro[i] = my_color % color

for i in b_arr:
  print(iro[i]+1)

Fixed submission:
def func(iro,tree,num,max_color):
  if num not in tree:
    return
  
  my_color = iro[num]
  arr = tree[num]
  
  for i in arr:
    my_color += 1
    iro[i] = my_color % max_color
    func(iro,tree,i,max_color)
    

n = int(input())
tree = {}

b_arr = []
for i in range(n-1):
  a,b = map(int,input().split())
  
  b_arr.append(b)
  if a not in tree:
    tree[a] = []
    
  tree[a].append(b)
  
color = len(tree[1])
for key,arr in sorted(tree.items()):
  if key == 1:
    continue
    
  color = max(len(arr)+1, color)

print(color)

iro = [-1] * (n+1)

for key,arr in sorted(tree.items()):
  my_color = iro[key]
  for i in arr:
    my_color += 1
    iro[i] = my_color % color

for i in b_arr:
  print(iro[i]+1)

Buggy python submission (verdict: Runtime Error):
def func(iro,tree,num,max_color):
  if num not in tree:
    return
  
  my_color = iro[num]
  arr = tree[num]
  
  for i in arr:
    my_color += 1
    iro[i] = my_color % max_color
    func(iro,tree,i,max_color)
    

n = int(input())
tree = {}

b_arr = []
for i in range(n-1):
  a,b = map(int,input().split())
  
  b_arr.append(b)
  if a not in tree:
    tree[a] = []
    
  tree[a].append(b)


color = len(tree[1])
for key in tree.keys():
  if key == 1:
    continue
    
  arr = tree[key]
  color = max(len(arr)+1, color)

print(color)

iro = [0] * (n+1)

func(iro,tree,1,color)

for i in b_arr:
  print(iro[i]+1)
  

Fixed submission:
def func(iro,tree,num,max_color):
  if num not in tree:
    return
  
  my_color = iro[num]
  arr = tree[num]
  
  for i in arr:
    my_color += 1
    iro[i] = my_color % max_color
    func(iro,tree,i,max_color)
    

n = int(input())
tree = {}

b_arr = []
for i in range(n-1):
  a,b = map(int,input().split())
  
  b_arr.append(b)
  if a not in tree:
    tree[a] = []
    
  tree[a].append(b)
  
color = len(tree[1])
for key,arr in sorted(tree.items()):
  if key == 1:
    continue
    
  color = max(len(arr)+1, color)

print(color)

iro = [-1] * (n+1)

for key,arr in sorted(tree.items()):
  my_color = iro[key]
  for i in arr:
    my_color += 1
    iro[i] = my_color % color

for i in b_arr:
  print(iro[i]+1)
Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    index2 = dic.get(tmp, -1)
    
    if index2 == -1
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    index1 = dic.get(l[j], -1)
    if index1 == -1:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1     
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += max(d,0)
    
print(ans)

Fixed submission:
import bisect as bs
n = int(input())
l = sorted(list(map(int,input().split())))

count = 0
for i in range(n):
  for j in range(i+1,n):
    index = bs.bisect_left(l,l[i]+l[j])
    count += index - j - 1
    
print(count)

Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    index2 = dic.get(tmp, -1)
    
    if index2 == -1
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    index1 = dic.get(l[j], -1)
    if index == -1:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1     
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += max(d,0)
    
print(ans)

Fixed submission:
import bisect as bs
n = int(input())
l = sorted(list(map(int,input().split())))

count = 0
for i in range(n):
  for j in range(i+1,n):
    index = bs.bisect_left(l,l[i]+l[j])
    count += index - j - 1
    
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    if tmp in dic.keys():
      index2 = dic[tmp]
    else:
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    if l[j] in dic.keys():
      index1 = dic[l[j]]
    else:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1
      
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += max(d,0)
    
print(ans)

Fixed submission:
import bisect as bs
n = int(input())
l = sorted(list(map(int,input().split())))

count = 0
for i in range(n):
  for j in range(i+1,n):
    index = bs.bisect_left(l,l[i]+l[j])
    count += index - j - 1
    
print(count)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

count = 0
for i in range(s):
  if s[i] == t[i]:
    count += 1
    
print(count)

Fixed submission:
s = input()
t = input()

count = 0
for i in range(len(s)):
  if s[i] == t[i]:
    count += 1
    
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n,m = map(int,input().split())
dic = {}

for i in range(n):
  a,b = map(int,input().split())
  if a in dic:
    pass
  else:
    dic[a] = []
  
  dic[a].append(b)
  
dic = dict(sorted(dic.items(),key=lambda x: -x[0]))

count = 0

lst = []
for i in range(1,m+1):
  if i in dic.keys():
    lst.extend(dic[i])
    lst = sorted(lst, reverse=True)

  if len(lst) != 0:
    count += lst.pop(0)
  

print(count)

Fixed submission:
import heapq

n,m = map(int,input().split())
dic = {}

for i in range(n):
  a,b = map(int,input().split())
  if a in dic:
    pass
  else:
    dic[a] = []
  
  dic[a].append(-b)
  
dic = dict(sorted(dic.items(),key=lambda x: -x[0]))

count = 0

lst = []
for i in range(1,m+1):
  if i in dic.keys():
    for num in dic[i]:
      heapq.heappush(lst, num)
  if len(lst) != 0:
    tmp = heapq.heappop(lst)
    count -= tmp
  

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math
s = int(input())

root = math.floor(math.sqrt(s))

if s <= 10 ** 9:
  print(0,0,0,1,s,0)
else:
  for i in reversed(range(root+1)):
    if s % i == 0:
      print(0,0,0,i,s//i,0)
      break
  

Fixed submission:
import math
s = int(input())

root = math.ceil(math.sqrt(s))

if s <= 10 ** 9:
  print(0,0,0,1,s,0)
else:
  tmp = root**2 - s
  print(0,0,tmp,root,root,1)

Buggy python submission (verdict: Runtime Error):
s = int(input())

root = math.floor(math.sqrt(s))

if s <= 10 ** 9:
  print(0,0,0,1,s,0)
else:
  for i in reversed(range(root)):
    if s % i == 0:
      print(0,0,0,i,s//i,0)
      break
  

Fixed submission:
import math
s = int(input())

root = math.ceil(math.sqrt(s))

if s <= 10 ** 9:
  print(0,0,0,1,s,0)
else:
  tmp = root**2 - s
  print(0,0,tmp,root,root,1)
Buggy python submission (verdict: Runtime Error):


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

list_sum = sum(list)

ans = 1000000
s1 = 0
s2 = list_sum
for i in range(n):
  s1 += w[i]
  s2 -= w[i]
  ans = min(ans,max(s1-s2,s2-s1))

print(ans)

Fixed submission:


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

list_sum = sum(w)

ans = 1000000
s1 = 0
s2 = list_sum
for i in range(n):
  s1 += w[i]
  s2 -= w[i]
  ans = min(ans,max(s1-s2,s2-s1))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
list1 = []
list2 = []

for i in range(w):
  list2.append([])

for i in range(h):
  s = input()
  list1.append(s)
  for j in range(w):
    list2[j].append(s[j])

list3 = []
for i in range(h):
  list3.append([])
  
list4 = []
for i in range(w):
  list4.append([])

for i in range(h):
  tmp_list = list1[i].split('#')
  for tmp in tmp_list:
    leng = len(tmp)
    list3[i].extend([leng]*leng)
    list3[i].append(0)
    
for i in range(w):
  tmp_list = (''.join(list2[i])).split('#')
  for tmp in tmp_list:
    leng = len(tmp)
    list4[i].extend([leng]*leng)
    list4[i].append(0)
    
max_num = -1
for i in range(w):
  for j in range(h):
    list3[j][i] += list4[i][j]-1
    max_num = max(max_num, list3[j][i])
    
print(max_num)

Fixed submission:
h,w = map(int,input().split())
list1 = []
list2 = []
 
for i in range(w):
  list2.append([])
 
for i in range(h):
  s = input()
  list1.append(s)
  for j in range(w):
    list2[j].append(s[j])
 
list3 = []
for i in range(h):
  list3.append([])
  
list4 = []
for i in range(w):
  list4.append([])
 
for i in range(h):
  tmp_list = list1[i].split('#')
  for tmp in tmp_list:
    leng = len(tmp)
    list3[i].extend([leng]*leng)
    list3[i].append(0)
    
for i in range(w):
  tmp_list = (''.join(list2[i])).split('#')
  for tmp in tmp_list:
    leng = len(tmp)
    list4[i].extend([leng]*leng)
    list4[i].append(0)
    
max_num = -1
for i in range(w):
  for j in range(h):
    list3[j][i] += list4[i][j]-1
    max_num = max(max_num, list3[j][i])
    
print(max_num)
Buggy python submission (verdict: Runtime Error):
import math

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

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(math.gcd(right[i-1], a[i]))
    left.append(math.gcd(left[i-1], a[len(a)-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, math.gcd(right[0], left[len(left)-2-i]))
    
  print(ans)
  
main()

Fixed submission:
import fractions

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

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(fractions.gcd(right[i-1], a[i]))
    left.append(fractions.gcd(left[i-1], a[-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, fractions.gcd(right[i], left[-i-2]))
    
  print(ans)
  
main()

Buggy python submission (verdict: Runtime Error):
import math

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

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(math.gcd(right[i-1], a[i]))
    left.append(math.gcd(left[i-1], a[-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, math.gcd(right[0], left[-2-i]))
    
  print(ans)
  
main()

Fixed submission:
import fractions

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

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(fractions.gcd(right[i-1], a[i]))
    left.append(fractions.gcd(left[i-1], a[-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, fractions.gcd(right[i], left[-i-2]))
    
  print(ans)
  
main()

Buggy python submission (verdict: Runtime Error):
import math

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

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(math.gcd(right[i-1], a[i]))
    left.append(math.gcd(left[i-1], a[len(a)-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, math.gcd(right[0], left[-2-i]))
    
  print(ans)
  
main()

Fixed submission:
import fractions

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

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(fractions.gcd(right[i-1], a[i]))
    left.append(fractions.gcd(left[i-1], a[-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, fractions.gcd(right[i], left[-i-2]))
    
  print(ans)
  
main()
Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque

n = int(input())

ans = 0
array = ['7','5','3']

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_used = copy.deepcopy(used)
    cp_s.append(c)
    cp_used.add(c)
    d.append((cp_s,cp_used))
  
print(count)


Fixed submission:
import copy
from collections import deque

n = int(input())

ans = 0
array = ['7','5','3']

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1  
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_s.append(c)    
    if len(used) == 3:
      d.append((cp_s,used))
    
    else:
      cp_used = copy.deepcopy(used)
      cp_used.add(c)
      d.append((cp_s,cp_used))
  
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque

n = int(input())

ans = 0
array = ['7','5','3']

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_used = copy.deepcopy(used)
    cp_s.append(c)
    cp_used.add(c)
    d.append((cp_s,cp_used))
  
print(count)

Fixed submission:
import copy
from collections import deque

n = int(input())

ans = 0
array = ['7','5','3']

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1  
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_s.append(c)    
    if len(used) == 3:
      d.append((cp_s,used))
    
    else:
      cp_used = copy.deepcopy(used)
      cp_used.add(c)
      d.append((cp_s,cp_used))
  
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

def saiki(s,used,n):
  if int(s) > n:
    return 0

  count = 0
  arr = ['7','5','3']
  if len(used) == 3:
    count += 1
  
  for c in arr:
    cp_used = copy.deepcopy(used)
    cp_used.add(c)
    count += saiki(s+c,cp_used,n)
    
  return count
  

n = int(input())

ans = 0
array = []

used = set()
ans = saiki('7',set('7'),n) + saiki('5',set('5'),n) + saiki('3',set('3'),n)
print(ans)

Fixed submission:
import copy
from collections import deque

n = int(input())

ans = 0
array = ['7','5','3']

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1  
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_s.append(c)    
    if len(used) == 3:
      d.append((cp_s,used))
    
    else:
      cp_used = copy.deepcopy(used)
      cp_used.add(c)
      d.append((cp_s,cp_used))
  
print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(input())

if n % k == 0 :
    print(0)
else:
    print(1)



Fixed submission:
nums = [int(i) for i in input().split()]

if nums[0] % nums[1] == 0 :
    print(0)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input()) -1

array = set()
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    array.add(s[i:j])
    
array = sorted(array)

print(array[k])

Fixed submission:
s = input()
k = int(input())

s_sorted = sorted(s)
array = set()

n = len(s)
for i in range(n):
  for j in range(n):
    if s_sorted[i] == s[j]:
      for l in range(k):
        if l+j >= n:
          break
        
        array.add(s[j:l+j+1])
      
  if len(array) >= k:
    break
    
array = sorted(array)
print(array[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input()) -1

array = set()
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    array.add(s[i:j])
    
array = sorted(array)

print(array[k])

Fixed submission:
s = input()
k = int(input())

s_sorted = sorted(s)
array = set()

n = len(s)
for i in range(n):
  for j in range(n):
    if s_sorted[i] == s[j]:
      for l in range(k):
        if l+j >= n:
          break
        
        array.add(s[j:l+j+1])
      
  if len(array) >= k:
    break
    
array = sorted(array)
print(array[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,c = map(int,input().split())

x = []
v = []
array1 = []
array2 = []

for i in range(n):
  a,b = map(int, input().split())
  x.append(a)
  v.append(b)
  
rx = []
rv = []
for i in reversed(range(len(x))):
  rx.append(c-x[i])
  rv.append(v[i])
  
count = x[0]
array1.append(v[0] - x[0])
for i in range(1,n):
  array1.append(v[i]-x[i]+array1[i-1]+count)
  count = x[i]
  
count = rx[0]
array2.append(rv[0] - rx[0])
for i in range(1,n):
  array2.append(rv[i]-rx[i]+array2[i-1]+count)
  count = rx[i]
  
ans = 0
for i in range(n):
  if i != n-1:
    tmp = max(array1[i], array1[i]-x[i]+max(array2[:n-i-1]))
    ans = max(ans, tmp)
  else:
    ans = max(ans, array1[i])
  
for i in range(n):
  if i != n-1:
    tmp = max(array2[i], array2[i]-rx[i]+max(array1[:n-i-1]))
    ans = max(ans, tmp)
  else:
    ans = max(ans, array2[i])
    

  
print(ans)

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

x = []
v = []
array1 = []
array2 = []

for i in range(n):
  a,b = map(int, input().split())
  x.append(a)
  v.append(b)
  
rx = []
rv = []
for i in reversed(range(len(x))):
  rx.append(c-x[i])
  rv.append(v[i])
  
count = x[0]
array1.append(v[0] - x[0])
for i in range(1,n):
  array1.append(v[i]-x[i]+array1[i-1]+count)
  count = x[i]
  
count = rx[0]
array2.append(rv[0] - rx[0])
for i in range(1,n):
  array2.append(rv[i]-rx[i]+array2[i-1]+count)
  count = rx[i]

num = 0
max_array = []
for i in range(len(array1)-1):
  num = max(num, array1[i])
  max_array.append(num)

max_array = list(reversed(max_array))

num = 0
rmax_array = []
for i in range(len(array2)-1):
  num = max(num, array2[i])
  rmax_array.append(num)
  
rmax_array = list(reversed(rmax_array))
  
  
ans = 0
for i in range(n):
  if i != n-1:
    tmp = max(array1[i], array1[i]-x[i]+rmax_array[i])
    ans = max(ans, tmp)
  else:
    ans = max(ans, array1[i])
  
for i in range(n):
  if i != n-1:
    tmp = max(array2[i], array2[i]-rx[i]+max_array[i])
    ans = max(ans, tmp)
  else:
    ans = max(ans, array2[i])
    
print(ans)