Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
g = [[] for _  in range(n)]
for _ in range(m):
  x, y = map(int, input().split())
  x, y = x -1, y-1
  g[x].append(y)  

# dp[v]: ノードvを起点にしたときの、Gの有効パスの長さの最大値
dp = [-1]*n
def rec(v):
  if dp[v] != -1:
    return dp[v]
  else:
    res = 0
    for u in g[v]:
      res = max(res, rec(u)+1)
    dp[v] = res
    return dp[v]
  
for i in range(n):
  rec(i)
print(max(dp))

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n, m = map(int, input().split())
g = [[] for _  in range(n)]
for _ in range(m):
  x, y = map(int, input().split())
  x, y = x -1, y-1
  g[x].append(y)  

# dp[v]: ノードvを起点にしたときの、Gの有効パスの長さの最大値
dp = [-1]*n
def rec(v):
  if dp[v] != -1:
    return dp[v]
  else:
    res = 0
    for u in g[v]:
      res = max(res, rec(u)+1)
    dp[v] = res
    return dp[v]
  
for i in range(n):
  rec(i)
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(float, input().split()))

dp = [[0]*(n+1) for _ in range(n+1)]
# dp[i][j]: 最初のi枚のコインを投げたとき、表がj枚になる確率
dp[0][0] = 1.0
for i in range(n):
  for j in range(i+1):
    dp[i+1][j+1] += dp[i][j] * l[i]
    dp[i+1][j] += dp[i][j] * (1-l[i])
    
ans_ = 0
for i in range(0, n//2+1):
  ans_ += dp[n][i]
print(1-ans_)

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

dp = [[0]*(n+1) for _ in range(n+1)]
# dp[i][j]: 最初のi枚のコインを投げたとき、表がj枚になる確率
dp[0][0] = 1.0
for i in range(n):
  for j in range(i+1):
    dp[i+1][j+1] += dp[i][j] * l[i]
    dp[i+1][j] += dp[i][j] * (1-l[i])
    
ans_ = 0
for i in range(0, n//2+1):
  ans_ += dp[n][i]
print(1-ans_)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [-1]*(k+1)
dp[0] = 0

for i in range(1, k+1):
  temp = 1
  for j in range(n):
    if i - l[j] >= 0:
      temp *= dp[i-l[j]]
  dp[i] = 1-temp
      
if dp[k] == 0:
  print('Second')
else:
  print('First')

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

dp = [-1]*(k+1)
dp[0] = 0

for i in range(1, k+1):
  temp = 1
  for j in range(n):
    if i - l[j] >= 0:
      temp *= dp[i-l[j]]
  dp[i] = 1-temp
      
if dp[k] == 0:
  print('Second')
else:
  print('First')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

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

for d in range(1, n+1):
    for i in range(n+1-d):
        j = i+d
        if (n-d)%2 == 0:
            dp[i][j] = max(dp[i+1][j]+A[i], dp[i][j-1]+A[j-1])
        else:
            dp[i][j] = min(dp[i+1][j]-A[i], dp[i][j-1]-A[j-1])
print(dp[0][n])

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

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

for d in range(1, n+1):
    for i in range(n+1-d):
        j = i+d
        if (n-d)%2 == 0:
            dp[i][j] = max(dp[i+1][j]+A[i], dp[i][j-1]+A[j-1])
        else:
            dp[i][j] = min(dp[i+1][j]-A[i], dp[i][j-1]-A[j-1])
print(dp[0][n])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 10**9+7

    dp = [[0]*(k+2) for i in range(n+1)]
    # dp[i][j]: i人目まで配ったときに残っているアメの個数がj個となる場合の数
    from itertools import accumulate
    dp[0][k] = 1
    for i in range(n):
        x = [0]*(k+2)
        for j in range(k+1):
            x[max(0, j-A[i])] += dp[i][j]%mod
            x[j+1] -= dp[i][j]%mod
        cum = list(accumulate(x))
        dp[i+1] = cum

    print(dp[n][0]%mod)

if __name__ == '__main__':
    main()

Fixed submission:
n, k = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(k+2) for i in range(n+1)]
# dp[i][j]: i人目まで配ったときに残っているアメの個数がj個となる場合の数
from itertools import accumulate
dp[0][k] = 1
for i in range(n):
    x = [0]*(k+2)
    for j in range(k+1):
        x[max(0, j-A[i])] += dp[i][j]%mod
        x[j+1] -= dp[i][j]%mod
    cum = list(accumulate(x))
    dp[i+1] = cum

print(dp[n][0]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

from itertools import accumulate
B = [0] + A
B = list(accumulate(B))

INF = 10**18
dp = [[INF]*(n+1) for i in range(n+1)]
# dp[i][j]: 区間[i, j)のスライムを取り除いたコストの最小値
for i in range(n):
    dp[i][i+1] = 0
# 区間の幅(d)が狭い方から更新していく(d: 2, 3, ...n+1)
# d = 0, 1については初期化で更新した
for d in range(2, n+1):
    for i in range(n+1-d):
        j = i + d
        for k in range(i+1, j):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]+B[j]-B[i])
#print(dp)
print(dp[0][n])

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

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

memo = [[float('inf')]*410 for _ in range(410)]
visit = [[False]*410 for _ in range(410)]

from itertools import accumulate
B = [0]+A
B = list(accumulate(B))

def dp(l, r):
  if l == r:
    return 0
  if visit[l][r]:
    return memo[l][r]
  visit[l][r] = True
  res = float('inf')
  for c in range(l, r):
    res = min(res, dp(l, c)+dp(c+1, r)+B[r+1]-B[l])
  memo[l][r] = res
  return res

print(dp(0, n-1))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

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

memo = [[float('inf')]*410 for _ in range(410)]
visit = [[False]*410 for _ in range(410)]

from itertools import accumulate
B = [0]+A
B = list(accumulate(B))

def dp(l, r):
  if l == r:
    return 0
  if visit[l][r]:
    return memo[l][r]
  visit[l][r] = True
  res = float('inf')
  for c in range(l, r):
    res = min(res, dp(l, c)+dp(c+1, r)+B[r+1]-B[l])
  memo[l][r] = res
  return res

print(dp(0, n-1))

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

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

memo = [[float('inf')]*410 for _ in range(410)]
visit = [[False]*410 for _ in range(410)]

from itertools import accumulate
B = [0]+A
B = list(accumulate(B))

def dp(l, r):
  if l == r:
    return 0
  if visit[l][r]:
    return memo[l][r]
  visit[l][r] = True
  res = float('inf')
  for c in range(l, r):
    res = min(res, dp(l, c)+dp(c+1, r)+B[r+1]-B[l])
  memo[l][r] = res
  return res

print(dp(0, n-1))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    H = list(map(int, input().split()))
    A = list(map(int, input().split()))

    def segfunc(x, y):
        if x >= y:
            return x
        else:
            return y

    def init(init_val):
        # set_val
        for i in range(n+1):
            seg[i+num-1] = init_val[i]
        # built
        for i in range(num-2, -1, -1):
            seg[i] = segfunc(seg[2*i+1], seg[2*i+2])

    def update(k, x):
        k += num - 1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = segfunc(seg[2*k+1], seg[2*k+2])

    def query(p, q):
        if q <= p:
            return ide_ele
        p += num - 1
        q += num - 2
        res = ide_ele
        while p < q:
            if p&1 == 0: #左のnode: == 1, 右のnode: == 0
                res = segfunc(res, seg[p])
            if q&1 == 1: #左のnode: == 1, 右のnode: == 0
                res = segfunc(res, seg[q])
                q -= 1 # 隣に移動
            p = p//2 # 隣のnodeの親にアクセス
            q = (q-1)//2 #親のnodeにアクセス
        if p == q:
            res = segfunc(res, seg[p])
        else:
            res = segfunc(segfunc(res, seg[p]), seg[q])
        return res

    # identity element
    ide_ele = 0

    # num: n以上の最小の2のべき乗
    num = 2**n.bit_length()
    seg = [ide_ele]*2*num

    X = [0]*(n+1)
    for i in range(n):
        update(H[i], query(0, H[i]+1)+A[i])
    print(query(0, n+2))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    H = list(map(int, input().split()))
    A = list(map(int, input().split()))

    def segfunc(x, y):
        if x >= y:
            return x
        else:
            return y

    def init(init_val):
        # set_val
        for i in range(n+1):
            seg[i+num-1] = init_val[i]
        # built
        for i in range(num-2, -1, -1):
            seg[i] = segfunc(seg[2*i+1], seg[2*i+2])

    def update(k, x):
        k += num - 1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = segfunc(seg[2*k+1], seg[2*k+2])

    def query(p, q):
        if q <= p:
            return ide_ele
        p += num - 1
        q += num - 2
        res = ide_ele
        while p < q:
            if p&1 == 0: #左のnode: == 1, 右のnode: == 0
                res = segfunc(res, seg[p])
            if q&1 == 1: #左のnode: == 1, 右のnode: == 0
                res = segfunc(res, seg[q])
                q -= 1 # 隣に移動
            p = p//2 # 隣のnodeの親にアクセス
            q = (q-1)//2 #親のnodeにアクセス
        if p == q:
            res = segfunc(res, seg[p])
        else:
            res = segfunc(segfunc(res, seg[p]), seg[q])
        return res

    # identity element
    ide_ele = 0

    # num: n以上の最小の2のべき乗
    num = 2**n.bit_length()
    seg = [ide_ele]*2*num

    X = [0]*(n+1)
    for i in range(n):
        update(H[i], query(0, H[i]+1)+A[i])
    print(query(0, n+2))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
mod = 10**9+7
A = [list(map(int, input().split())) for _ in range(n)]

# A*B
def mul(a, b):
    c = [[0]*len(b[0]) for i in range(len(a))]
    for i in range(len(a)):
        for k in range(len(b)):
            for j in range(len(b[0])):
                c[i][j] = (c[i][j] + a[i][k]*b[k][j])%mod

    return c

#A**n
def pow(a, n):
    b = [[0]*len(a) for i in range(len(a))]
    for i in range(len(a)):
        b[i][i] = 1
    while n > 0:
        if n & 1 == 1:
            b = mul(a, b)
        a = mul(a, a)
        n = n>>1
    return b

B = pow(A, k)
#print(B)
ans = 0
for i in range(n):
    ans += sum(B[i])
    ans %= mod
print(ans)

Fixed submission:
n, k = map(int, input().split())
mod = 10**9+7
A = [list(map(int, input().split())) for _ in range(n)]

# A*B
def mul(a, b):
    c = [[0]*len(b[0]) for i in range(len(a))]
    for i in range(len(a)):
        for k in range(len(b)):
            for j in range(len(b[0])):
                c[i][j] = (c[i][j] + a[i][k]*b[k][j])%mod

    return c

#A**n
def pow(a, n):
    b = [[0]*len(a) for i in range(len(a))]
    for i in range(len(a)):
        b[i][i] = 1
    while n > 0:
        if n & 1 == 1:
            b = mul(a, b)
        a = mul(a, a)
        n = n>>1
    return b

B = pow(A, k)
#print(B)
ans = 0
for i in range(n):
    ans += sum(B[i])
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
D = int(input())
n = len(str(K))

mod = 10**9+7

s = str(K)

dp = [[[0, 0] for _ in range(D)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(n):
    for j in range(D):
        for k in range(2):
            nd = int(s[i])
            for d in range(10):
                ni = i+1
                nj = (j+d)%D
                nk = k
                if k == 0:
                    if d > nd:
                        continue
                    elif d < nd:
                        nk = 1
                    else:
                        pass
                dp[ni][nj][nk] += dp[i][j][k]%mod
print((dp[n][0][0]+dp[n][0][1]-1)%mod)

Fixed submission:
K = int(input())
D = int(input())
n = len(str(K))

mod = 10**9+7

s = str(K)

dp = [[[0, 0] for _ in range(D)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(n):
    for j in range(D):
        for k in range(2):
            nd = int(s[i])
            for d in range(10):
                ni = i+1
                nj = (j+d)%D
                nk = k
                if k == 0:
                    if d > nd:
                        continue
                    elif d < nd:
                        nk = 1
                    else:
                        pass
                dp[ni][nj][nk] += dp[i][j][k]%mod
print((dp[n][0][0]+dp[n][0][1]-1)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n  = int(input())

if n < 357:
  print(0)
  exit()

max_m = len(str(n))

ans = 0

for m in range(3,max_m+1):
  for i in range(1, m):
    for j in range(1, m-i):
      k = m-i-j
      ls = ['7']*i+['5']*j+['3']*k
      for l in set(itertools.permutations(ls)):
        s = ''.join(l)
        s = int(s)
        if s <= n:
          ans += 1
          #print(s)
print(ans)

Fixed submission:
n = int(input())

def dfs(s):
  ret = 0
  if int(s) > n:
    return 0
  if all(s.count(c) > 0 for c in '753'):
    ret = 1
  for c in '753':
    ret += dfs(s+c)
  return ret

print(dfs('0'))

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

n  = int(input())

max_m = len(str(n))

ans = 0

for m in range(1,max_m+1):
  for i in range(1, m):
    for j in range(1, m-i):
      k = m-i-j
      ls = ['7']*i+['5']*j+['3']*k
      for l in set(itertools.permutations(ls)):
        s = ''.join(l)
        s = int(s)
        if s <= n:
          ans += 1
          #print(s)
print(ans)

Fixed submission:
n = int(input())

def dfs(s):
  ret = 0
  if int(s) > n:
    return 0
  if all(s.count(c) > 0 for c in '753'):
    ret = 1
  for c in '753':
    ret += dfs(s+c)
  return ret

print(dfs('0'))

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

n  = int(input())

max_m = len(str(n))

ans = 0

for m in range(1,max_m+1):
  for i in range(1, m):
    for j in range(1, m-i):
      k = m-i-j
      ls = ['7']*i+['5']*j+['3']*k
      ss = set()
      for l in itertools.permutations(ls):
        s = ''.join(l)
        s = int(s)
        if s in ss:
          continue
        elif s <= n:
          ans += 1
          # print(s)
          ss.add(s)
        else:
          ss.add(s)
print(ans)

Fixed submission:
n = int(input())

def dfs(s):
  ret = 0
  if int(s) > n:
    return 0
  if all(s.count(c) > 0 for c in '753'):
    ret = 1
  for c in '753':
    ret += dfs(s+c)
  return ret

print(dfs('0'))
Buggy python submission (verdict: Runtime Error):
n = int(input())

if k == 3:
    print('Yes')
    print(k)
    print(2, 1, 2)
    print(2, 3, 1)
    print(2, 2, 3)

else:
    print('No')

Fixed submission:
n = int(input())

k = 0
for i in range(1, 2*n+1):
    if i*(i-1) == 2*n:
        k = i

#print(k)
if not k:
    print('No')
    exit()

S = [[] for _ in range(k)]
import itertools
C = list(itertools.combinations(range(k),2))
for i in range(n):
    j = i+1
    c1, c2 = C[i]
    S[c1].append(j)
    S[c2].append(j)

print('Yes')
print(k)
for i in range(k):
    print(len(S[i]), *S[i])
Buggy python submission (verdict: Runtime Error):
N = input()
if N == 2:
	A = int(input())
  	B = int(input())
    print(A+B)
else:
  	print('Hello World')

Fixed submission:
N = int(input())
if N == 2:
  A = int(input())
  B = int(input())
  print(A + B)
elif N == 1:
  print('Hello World')

Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 2:
	A = int(input())
  	B = int(input())
    print(A+B)
else:
  	print('Hello World')

Fixed submission:
N = int(input())
if N == 2:
  A = int(input())
  B = int(input())
  print(A + B)
elif N == 1:
  print('Hello World')
Buggy python submission (verdict: Runtime Error):
n = int(input())

L = [[0, 0, 0] for _ in range(n)]
for i in range(n):
    x, y, h = map(int, input().split())
    L[i][0] = x
    L[i][1] = y
    L[i][2] = h

L.sort(key=lambda x: x[2], reverse=True)

for i in range(0, 101):
    for j in range(0, 101):
        for k in range(n):
            x = L[k][0]
            y = L[k][1]
            h = L[k][2]
            if k == 0:
                H = abs(i-x)+abs(j-y)+h
            else:
                if H != abs(i-x)+abs(j-y)+h:
                    break
        else:
            ans = [i, j, H]
print(*ans)


Fixed submission:
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

l.sort(key=lambda x: x[2], reverse=True)
#print(l)

for cx in range(0, 101):
  for cy in range(0, 101):
    x = l[0][0]
    y = l[0][1]
    h = l[0][2]
    H = h+abs(x-cx)+abs(y-cy)
    #print(cx, cy, H)
    for i in range(1, n):
      x = l[i][0]
      y = l[i][1]
      h = l[i][2]
      if h != max(H-abs(x-cx)-abs(y-cy), 0):
        break
    else:
      print(cx, cy, H)
      exit()
Buggy python submission (verdict: Time Limit Exceeded):
import math
 
def div(m):
  d = {}
  temp = int(math.sqrt(m))+1
  for i in range(2, temp):
    while m%i== 0:
      m //= i
      if i in d:
        d[i] += 1
      else:
        d[i] = 1
  if d == {}:
    d[m] = 1
  else:
    if m in d:
      d[m] += 1
    elif m != 1:
      d[m] =1
  return d

n, m = map(int, input().split())
if m == 1:
  print(1)
  exit()
#print(div(m))
from math import factorial
d = div(m)
#print(d)
ans = 1
for i in d.values():
  ans *= int(factorial(i+n-1)) // int(factorial(n-1)) // int(factorial(i))
  ans %= 10**9+7
print(ans)

Fixed submission:
import math
 
def div(m):
  d = {}
  temp = int(math.sqrt(m))+1
  for i in range(2, temp):
    while m%i== 0:
      m //= i
      if i in d:
        d[i] += 1
      else:
        d[i] = 1
  if d == {}:
    d[m] = 1
  else:
    if m in d:
      d[m] += 1
    elif m != 1:
      d[m] =1
  return d

n, m = map(int, input().split())
if m == 1:
  print(1)
  exit()
#print(div(m))
from math import factorial
d = div(m)
#print(d)
ans = 1
for i in d.values():
  ans *= int(factorial(i+n-1)) // int(factorial(n-1)) // int(factorial(i))
  ans %= 10**9+7
print(ans)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]

cnt = 0
ans = []
for i in range(h):
    for j in range(w):
        a = A[i][j]
        if a%2 == 1:
            for dy, dx in (-1, 0), (0, -1), (0, 1), (1, 0):
                ni = i+dy
                nj = j+dx
                if 0 <= ni < h and 0 <= nj < w:
                    ni_ = ni
                    nj_ = nj
                    if A[ni][nj]%2 == 1:
                        A[ni][nj] += 1
                        A[i][j] -= 1
                        cnt += 1
                        ans.append([i+1, j+1, ni+1, nj+1])
                        break
            else:
                A[ni_][nj_] += 1
                A[i][j] -= 1
                cnt += 1
                ans.append([i+1, j+1, ni_+1, nj_+1])

print(cnt)
for i in range(cnt):
    print(*ans[i])


Fixed submission:
h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]

if h == 1 and w == 1:
    print(0)
    exit()

cnt = 0
ans = []
for i in range(h):
    for j in range(w):
        a = A[i][j]
        if a%2 == 1:
            for dy, dx in (-1, 0), (0, -1), (0, 1), (1, 0):
                ni = i+dy
                nj = j+dx
                if 0 <= ni < h and 0 <= nj < w:
                    ni_ = ni
                    nj_ = nj
                    if A[ni][nj]%2 == 1:
                        A[ni][nj] += 1
                        A[i][j] -= 1
                        cnt += 1
                        ans.append([i+1, j+1, ni+1, nj+1])
                        break
            else:
                A[ni_][nj_] += 1
                A[i][j] -= 1
                cnt += 1
                ans.append([i+1, j+1, ni_+1, nj_+1])

print(cnt)
for i in range(cnt):
    print(*ans[i])
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
xs= list(map(int, input().split()))

l = []
r = []
for i in range(n):
  x = xs[i]
  if x < 0:
    l.append(x)
  else:
    r.append(x)
    
if n == k:
  print(min(r[-1], -l[0])*2+max(r[-1], -l[0]))
  exit()

if l == []:
  print(r[k-1])
  exit()
elif r == []:
  print(-l[-k])
  exit()
  
ts = []
for i in range(max(k-len(l), 0), min(len(r), k+1)):
  print(i)
  if i == 0:
    t = -l[-k]
  elif i == k:
    t = r[k-1]
  else:
    t = min(r[i-1], -l[-(k-i)])*2+max(r[i-1], -l[-(k-i)])
  ts.append(t)
print(ts)
print(min(ts))

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

l = []
r = []
for i in range(n):
  x = xs[i]
  if x < 0:
    l.append(x)
  else:
    r.append(x)
    
if l == []:
  print(r[k-1])
  exit()
elif r == []:
  print(-l[-k])
  exit()
  
if n == k:
  print(min(r[-1], -l[0])*2+max(r[-1], -l[0]))
  exit()
  
ts = []
for i in range(max(k-len(l), 0), min(len(r), k+1)):
  if i == 0:
    t = -l[-k]
  elif i == k:
    t = r[k-1]
  else:
    t = min(r[i-1], -l[-(k-i)])*2+max(r[i-1], -l[-(k-i)])
  ts.append(t)
#print(ts)
print(min(ts))

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
xs= list(map(int, input().split()))

l = []
r = []
for i in range(n):
  x = xs[i]
  if x < 0:
    l.append(x)
  else:
    r.append(x)

if l == []:
  print(r[k-1])
  exit()
elif r == []:
  print(-l[-k])
  exit()
  
ts = []
for i in range(max(k-len(l), 0), min(len(r), k+1)):
  if i == 0:
    t = -l[-k]
  elif i == k:
    t = r[k-1]
  else:
    t = min(r[i-1], -l[-(k-i)])*2+max(r[i-1], -l[-(k-i)])
  ts.append(t)
#print(ts)
print(min(ts))

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

l = []
r = []
for i in range(n):
  x = xs[i]
  if x < 0:
    l.append(x)
  else:
    r.append(x)
    
if l == []:
  print(r[k-1])
  exit()
elif r == []:
  print(-l[-k])
  exit()
  
if n == k:
  print(min(r[-1], -l[0])*2+max(r[-1], -l[0]))
  exit()
  
ts = []
for i in range(max(k-len(l), 0), min(len(r), k+1)):
  if i == 0:
    t = -l[-k]
  elif i == k:
    t = r[k-1]
  else:
    t = min(r[i-1], -l[-(k-i)])*2+max(r[i-1], -l[-(k-i)])
  ts.append(t)
#print(ts)
print(min(ts))
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
print(max([A+B, A-B, A*B])

Fixed submission:
A, B = map(int, input().split())
print(max([A+B, A-B, A*B]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

ans = 0
t = 0
S = [0]*30

def func(cur, S):
    cur_bi = list(format(cur, 'b'))
    cur_bi = list(reversed(cur_bi))
    flag = True
    for i in range(len(cur_bi)):
        if cur_bi[i] == '1' and S[i] == 1:
            flag = False
            break
    return flag

for s in range(n):
    while t < n and func(A[t], S):
        cur = A[t]
        cur_bi = list(format(cur, 'b'))
        cur_bi = list(reversed(cur_bi))
        for i in range(len(cur_bi)):
            if cur_bi[i] == '1':
                S[i] = 1
        t += 1
    ans += t-s
    if s == t:
        t += 1
    else:
        cur = A[s]
        cur_bi = list(format(cur, 'b'))
        cur_bi = list(reversed(cur_bi))
        for i in range(len(cur_bi)):
            if cur_bi[i] == '1':
                S[i] = 0

print(ans)

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

ans = 0
t = 0
S = [0]*30

def func(cur, S):
    cur_bi = list(format(cur, 'b'))
    cur_bi = list(reversed(cur_bi))
    flag = True
    for i in range(len(cur_bi)):
        if cur_bi[i] == '1' and S[i] == 1:
            flag = False
            break
    return flag

for s in range(n):
    while t < n and func(A[t], S):
        cur = A[t]
        cur_bi = list(format(cur, 'b'))
        cur_bi = list(reversed(cur_bi))
        for i in range(len(cur_bi)):
            if cur_bi[i] == '1':
                S[i] = 1
        t += 1
    ans += t-s
    if s == t:
        t += 1
    else:
        cur = A[s]
        cur_bi = list(format(cur, 'b'))
        cur_bi = list(reversed(cur_bi))
        for i in range(len(cur_bi)):
            if cur_bi[i] == '1':
                S[i] = 0

print(ans)