Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import heapq

N, K = map(int, input().split())
dt = [list(map(int, input().split()))[::-1] for i in range(N)]
dt.sort(reverse=True)

ans = 0
t_set = set()
candidates = []
for d, t in dt[:K]:
  if t in t_set:
    heapq.heappush(candidates, [d, t])
    ans += d
  else:
    t_set.add(t)
    ans += d

x = len(t_set)
ans += x**2

ans = [ans]
for d, t in dt[K:]:
  if t in t_set:
    continue
  cand_d, cand_t = heapq.heappop(candidates)
  _ans = ans[-1] - cand_d + d + (2*x+1)
  x += 1
  ans.append(_ans)
  if len(candidates) == 0:
    break

print(max(ans))

Fixed submission:
import heapq

N, K = map(int, input().split())
dt = [list(map(int, input().split()))[::-1] for i in range(N)]
dt.sort(reverse=True)

ans = 0
t_set = set()
candidates = []
for d, t in dt[:K]:
  if t in t_set:
    heapq.heappush(candidates, [d, t])
    ans += d
  else:
    t_set.add(t)
    ans += d

x = len(t_set)
ans += x**2

if len(candidates) == 0:
  print(ans)
  quit()

ans = [ans]
for d, t in dt[K:]:
  if t in t_set:
    continue
  cand_d, cand_t = heapq.heappop(candidates)
  _ans = ans[-1] - cand_d + d + (2*x+1)
  x += 1
  ans.append(_ans)
  t_set.add(t)
  if len(candidates) == 0:
    break

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

N, K = map(int, input().split())
H = np.array(list(map(int, input().split())))

dp = np.ones([N]) * np.inf
dp[0] = 0

for i in range(1, N):
  left = max(0, i-K)
  dp[i] = np.min(dp[left:i] + abs(H[left:i]-H[i]))

print(int(dp[N-1]))

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

dp = [0] + [10**9]*(N-1)

for i in range(1, N):
  k = min(i, K)
  for j in range(1, k+1):
    cost = abs(H[i-j] - H[i])
    dp[i] = min(dp[i], dp[i-j]+cost)
    if cost == 0:
      break

print(dp[N-1])

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

dp = [0] + [10**9]*(N-1)

for i in range(1, N):
  k = min(i, K)
  for j in range(1, k+1):
    cost = abs(H[i-j] - H[i])
    dp[i] = min(dp[i], dp[i-j]+cost)
    if cost == 0:
      break

print(dp[N-1])

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

dp = [0] + [10**9]*(N-1)

for i in range(1, N):
  k = min(i, K)
  for j in range(1, k+1):
    cost = abs(H[i-j] - H[i])
    dp[i] = min(dp[i], dp[i-j]+cost)
    if cost == 0:
      break

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

graph = [[] for i in range(N)]
is_root = [True] * N
for i in range(M):
  x, y = map(int, input().split())
  graph[x-1].append(y-1)
  is_root[y-1] = False


depth = [0] * N
d = [i for i in range(N) if is_root[i]]
while d:
  node = d.pop()
  children = graph[node]
  _depth = depth[node] + 1
  for child in children:
    if depth[child] < _depth:
      depth[child] = _depth
      d.append(child)

print(max(depth))


Fixed submission:
from collections import deque

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

graph = [[] for i in range(N)]
to_this = [0] * N
for i in range(M):
  x, y = map(int, input().split())
  graph[x-1].append(y-1)
  to_this[y-1] += 1


depth = [0] * N
d = deque([i for i in range(N) if not to_this[i]])
while d:
  l = len(d)
  for i in range(l):
    node = d.popleft()
    children = graph[node]
    for child in children:
      to_this[child] -= 1
      if not to_this[child]:
        d.append(child)
        depth[child] = depth[node] + 1

print(max(depth))

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

graph = [[] for i in range(N)]
is_root = [True] * N
for i in range(M):
  x, y = map(int, input().split())
  graph[x-1].append(y-1)
  is_root[y-1] = False


depth = [0] * N
d = [i for i in range(N) if is_root[i]]
while d:
  node = d.pop()
  children = graph[node]
  _depth = depth[node] + 1
  for child in children:
    if depth[child] < _depth:
      depth[child] = _depth
      d.append(child)

print(max(depth))

Fixed submission:
from collections import deque

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

graph = [[] for i in range(N)]
to_this = [0] * N
for i in range(M):
  x, y = map(int, input().split())
  graph[x-1].append(y-1)
  to_this[y-1] += 1


depth = [0] * N
d = deque([i for i in range(N) if not to_this[i]])
while d:
  l = len(d)
  for i in range(l):
    node = d.popleft()
    children = graph[node]
    for child in children:
      to_this[child] -= 1
      if not to_this[child]:
        d.append(child)
        depth[child] = depth[node] + 1

print(max(depth))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(float, input().split()))

dp = [[1] + [0]*N for i in range(N+1)]
for i in range(1, N+1):
  for j in range(1, i+1):
    dp[i][j] = dp[i-1][j-1]*(P[i-1]) + dp[i-1][j]*(1-P[i-1])

print(dp[-1][(N+1)//2])

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

dp = [[1] + [0]*N for i in range(N+1)]
for i in range(1, N+1):
  for j in range(1, i+1):
    dp[i][j] = dp[i-1][j-1]*(P[i-1]) + dp[i-1][j]*(1-P[i-1])

print(dp[-1][(N+1)//2])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

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

for i, a in enumerate(A):
  dp[i][i] = a

for i in range(1, N):
  for j in range(i-1, -1, -1):
    dp[i][j] = max(A[i]-dp[i-1][j], A[j]-dp[i][j+1])

print(dp[N-1][0])

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

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

for i, a in enumerate(A):
  dp[i][i] = a

for i in range(1, N):
  for j in range(i-1, -1, -1):
    dp[i][j] = max(A[i]-dp[i-1][j], A[j]-dp[i][j+1])

print(dp[N-1][0])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7

dp = [[0]*(K+1) for i in range(N)]
for i, a in enumerate(A):
  if i == 0:
    for j in range(a+1):
      dp[0][j] = 1
  
  else:
    dp[i][0] = 1
    for j in range(1, K+1):
      dp[i][j] = dp[i][j-1] + dp[i-1][j]
      if j > a:
        dp[i][j] -= dp[i-1][j-a-1]

      dp[i][j] %= MOD

print(dp[N-1][K])

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

dp = [[0]*(K+1) for i in range(N)]
for i, a in enumerate(A):
  if i == 0:
    for j in range(a+1):
      dp[0][j] = 1
  
  else:
    dp[i][0] = 1
    for j in range(1, K+1):
      dp[i][j] = dp[i][j-1] + dp[i-1][j]
      if j > a:
        dp[i][j] -= dp[i-1][j-a-1]

      dp[i][j] %= MOD

print(dp[N-1][K])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

cum = [[0]*(N) for i in range(N)]
for i in range(N):
  c = 0
  for j in range(i, N):
    c += A[j]
    cum[i][j] = c

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

for n in range(1, N+1):
  for i in range(N-n):
    j = i + n
    min_cost = 0
    for k in range(i, j):
      if min_cost == 0:
        min_cost = dp[i][k] + dp[k+1][j]
      else:
        min_cost = min(min_cost, dp[i][k]+dp[k+1][j])
    
    dp[i][j] = min_cost + cum[i][j]

print(dp[0][N-1])

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

cum = [[0]*(N) for i in range(N)]
for i in range(N):
  c = 0
  for j in range(i, N):
    c += A[j]
    cum[i][j] = c

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

def get_min_cost(i, j):
  global dp
  if dp[i][j] > 0:
    return dp[i][j]
  else:
    min_cost = 0
    for k in range(i, j):
      if min_cost == 0:
        min_cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
      else:
        cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
        min_cost = min(min_cost, cost)
    
    dp[i][j] = min_cost
    return dp[i][j]

print(get_min_cost(0, N-1))

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

cum = [[0]*(N) for i in range(N)]
for i in range(N):
  c = 0
  for j in range(i, N):
    c += A[j]
    cum[i][j] = c

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

def get_min_cost(i, j):
  global dp
  if dp[i][j] > 0:
    return dp[i][j]
  else:
    min_cost = 0
    for k in range(i, j):
      if min_cost == 0:
        min_cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
      else:
        cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
        min_cost = min(min_cost, cost)
    
    dp[i][j] = min_cost
    return dp[i][j]

print(get_min_cost(0, N-1))

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

cum = [[0]*(N) for i in range(N)]
for i in range(N):
  c = 0
  for j in range(i, N):
    c += A[j]
    cum[i][j] = c

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

def get_min_cost(i, j):
  global dp
  if dp[i][j] > 0:
    return dp[i][j]
  else:
    min_cost = 0
    for k in range(i, j):
      if min_cost == 0:
        min_cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
      else:
        cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
        min_cost = min(min_cost, cost)
    
    dp[i][j] = min_cost
    return dp[i][j]

print(get_min_cost(0, N-1))
Buggy python submission (verdict: Time Limit Exceeded):
# この方法だと、
# 参加している女性の数を数える部分 : c = bin(state).count('1')
# 一人減らして場合の数を足す部分 : for i in range(N): ...
# で、それぞれO(N)なので、
# 全体として 2 * N * 2**N 回の計算が必要
# 最大で N = 21 のときは間に合わない

N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
MOD = 10**9 + 7

dp = [0]*(2**N)
dp[0] = 1


for state in range(1, 2**N):
  c = bin(state).count('1')
  for i in range(N):
    if state & (1<<i):
      dp[state] += dp[state ^ (1<<i)]*A[c-1][i]
      dp[state] %= MOD

print(dp[2**N-1])

Fixed submission:
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
MOD = 10**9 + 7

dp = [-1]*(2**N)
dp[0] = 1

# stateを二進数で表したときに、1である桁番号の女性がマッチングに参加
# 男性側は前から固定で女性と同じ人数だけ参加
def solve(state, c):
  global dp
  if dp[state] >= 0:
    return dp[state]
  else:
    dp[state] = 0 # 一旦、値を0に戻しておく
    for i in range(N):
      if state & (1<<i) and A[c-1][i]: 
        # i番目の女性がマッチングに参加しており、なおかつ
        # 最後の男性との相性が良い場合は、その2人でペアを作った場合の組合せを足し合わせる
        dp[state] += solve(state ^ (1<<i), c-1)
        dp[state] %= MOD
    
    return dp[state]

print(solve(2**N-1, N))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
MOD = 10**9 + 7


def dot(M1, M2, mod=10**9+7):
  n = len(M1)
  res = [[0]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      for k in range(n):
        res[i][j] += M1[i][k] * M2[k][j] % MOD
  
  return res


def power(M, k, mod=10**9+7):
  if k == 1:
    return M
  elif k%2 == 0:
    return power(dot(M, M, mod), k//2)
  else:
    return dot(M, power(dot(M, M, mod), k//2), mod)


trans = power(A, K) 

ans = 0
for t in trans:
  ans += sum(t)%MOD
  ans %= MOD

print(ans)

Fixed submission:
N, K = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
MOD = 10**9 + 7


def dot(M1, M2, mod=10**9+7):
  n = len(M1)
  res = [[0]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      for k in range(n):
        res[i][j] += M1[i][k] * M2[k][j] % MOD
  
  return res


def power(M, k, mod=10**9+7):
  if k == 1:
    return M
  elif k%2 == 0:
    return power(dot(M, M, mod), k//2)
  else:
    return dot(M, power(dot(M, M, mod), k//2), mod)


trans = power(A, K) 

ans = 0
for t in trans:
  ans += sum(t)%MOD
  ans %= MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = input()
K_int = int(K)
digit = len(K)
D = int(input())
MOD = 10**9 + 7

# dp[d][r][i] : (d+1)桁目の数がiで、それまでの桁の数の和をDで割ったときの余りがrとなる組合せ
dp = [[[0]*10 for r in range(D)] for d in range(digit)]

for i in range(10):
  dp[0][i%D][i] += 1

for d in range(1, digit):
  for r in range(D):
    s = sum(dp[d-1][r])
    for i in range(10):
      dp[d][(r+i)%D][i] += s
      dp[d][(r+i)%D][i] %= MOD

ans = 0
r = 0
for _d, k in enumerate(K, 1):
  d = digit - _d
  k = int(k)
  if _d == 1:
    for i in range(1, k):
      ans += dp[d][0][i]
      ans %= MOD
  else:
    for i in range(1, 10):
      ans += dp[d][0][i]
      ans %= MOD
    
    for i in range(k):
      ans += dp[d][r][i]
      ans %= MOD
  
  r = (r-k)%D

e = 0
for i in K:
  e += int(i)
  e %= D

if e % D == 0:
  ans += 1
  ans %= MOD

print(ans)

Fixed submission:
K = input()
K_int = int(K)
digit = len(K)
D = int(input())
MOD = 10**9 + 7

# dp[d][r][i] : (d+1)桁目の数がiで、それまでの桁の数の和をDで割ったときの余りがrとなる組合せ
dp = [[[0]*10 for r in range(D)] for d in range(digit)]

for i in range(10):
  dp[0][i%D][i] += 1

for d in range(1, digit):
  for r in range(D):
    s = sum(dp[d-1][r])
    for i in range(10):
      dp[d][(r+i)%D][i] += s
      dp[d][(r+i)%D][i] %= MOD

ans = 0
r = 0
for _d, k in enumerate(K, 1):
  d = digit - _d
  k = int(k)
  if _d == 1:
    for i in range(1, k):
      ans += dp[d][0][i]
      ans %= MOD
  else:
    for i in range(1, 10):
      ans += dp[d][0][i]
      ans %= MOD
    
    for i in range(k):
      ans += dp[d][r][i]
      ans %= MOD
  
  r = (r-k)%D

e = 0
for i in K:
  e += int(i)
  e %= D

if e % D == 0:
  ans += 1
  ans %= MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
MOD = 10**9 + 7

# dp[j] (i番目のiteration時点): 
#   左から(i+1)番目まで並べ終えたときに、最も右の数が、
#   そのときに残っている(N-i)個の数の中で(j+1)番目に小さい数である場合の数
dp = [1] * N
cum = [[i for i in range(1, N+1)], [0]*N]

for i in range(1, N):
  idx = i%2
  if S[i-1] == '<':
    for j in range(N-i):
      dp[j] = cum[idx-1][j]
      if j == 0:
        cum[idx][0] = dp[j]
      else:
        cum[idx][j] = (cum[idx][j-1] + dp[j]) % MOD
  
  else:
    for j in range(N-i):
      dp[j] = (cum[idx-1][N-i] - cum[idx-1][j]) % MOD
      if j == 0:
        cum[idx][0] = dp[j]
      else:
        cum[idx][j] = (cum[idx][j-1] + dp[j]) % MOD

print(dp[0])

Fixed submission:
N = int(input())
S = input()
MOD = 10**9 + 7

# dp[j] (i番目のiteration時点): 
#   左から(i+1)番目まで並べ終えたときに、最も右の数が、
#   そのときに残っている(N-i)個の数の中で(j+1)番目に小さい数である場合の数
dp = [1] * N
cum = [[i for i in range(1, N+1)], [0]*N]

for i in range(1, N):
  idx = i%2
  if S[i-1] == '<':
    for j in range(N-i):
      dp[j] = cum[idx-1][j]
      if j == 0:
        cum[idx][0] = dp[j]
      else:
        cum[idx][j] = (cum[idx][j-1] + dp[j]) % MOD
  
  else:
    for j in range(N-i):
      dp[j] = (cum[idx-1][N-i] - cum[idx-1][j]) % MOD
      if j == 0:
        cum[idx][0] = dp[j]
      else:
        cum[idx][j] = (cum[idx][j-1] + dp[j]) % MOD

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

S = []
for l in range(0, N):
  temp = 0
  for r in range(l, N):
    temp += A[r]
    S.append(temp)

max_s = max(S)
n = max_s.bit_length()
S_temp = [S.copy(), []]
s_idx = 0
for i in range(n-1, -1, -1):
  c = 0
  for s in S_temp[s_idx]:
    if (s >> i) & 1:
      S_temp[s_idx-1].append(s)
      c += 1
  if c == K:
    ans = S_temp[s_idx-1][0]
    for _s in S_temp[s_idx-1]:
      ans &= _s
    print(ans)
    quit()
  if c > K:
    S_temp[s_idx] = []
    s_idx = not s_idx
  else:
    S_temp[s_idx-1] = []

ans = S_temp[s_idx][0]
for _s in S_temp[s_idx][:K]:
  ans &= _s

print(ans)

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

S = []
for l in range(0, N):
  temp = 0
  for r in range(l, N):
    temp += A[r]
    S.append(temp)

max_s = max(S)
n = max_s.bit_length()
S_temp = [S, []]
s_idx = 0
for i in range(n-1, -1, -1):
  c = 0
  for s in S_temp[s_idx]:
    if (s >> i) & 1:
      S_temp[s_idx-1].append(s)
      c += 1
  if c == K:
    ans = S_temp[s_idx-1][0]
    for _s in S_temp[s_idx-1]:
      ans &= _s
    print(ans)
    quit()
  if c > K:
    S_temp[s_idx] = []
    s_idx = not s_idx
  else:
    S_temp[s_idx-1] = []

ans = S_temp[s_idx][0]
for _s in S_temp[s_idx][:K]:
  ans &= _s

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
Q = int(input())
K = list(map(int, input().split()))

def count_DMC(k):
  num_d = [0] * (N+1)
  num_m = [0] * (N+1)
  num_dm = [0] * (N+1)
  res = 0
  for i, s in enumerate(S, 1):
    num_d[i] += num_d[i-1]
    num_m[i] += num_m[i-1]
    num_dm[i] += num_dm[i-1]
    if i - k - 1 >= 0 and S[i-k-1]=='D':
      num_dm[i] -= num_m[i]
    if s == 'D':
      num_d[i] += 1
      if i + k <= N:
        num_d[i+k] -= 1
    if s == 'M':
      num_m[i] += 1
      if i + k <= N:
        num_m[i+k] -= 1
      num_dm[i] += num_d[i]
    if s == 'C':
      res += num_dm[i]
  return res

for k in K:
  print(count_DMC(k))


Fixed submission:
import numpy as np

N = int(input())
S = np.array(list(input()))
Q = int(input())
K = list(map(int, input().split()))


D_idx = S == 'D'
M_idx = S == 'M'
C_idx = S == 'C'

num_d = D_idx.cumsum(dtype=int)
num_m = M_idx.cumsum(dtype=int)

def count_DMC(k):
  _num_d = num_d.copy()
  _num_d[k:] = _num_d[k:] - _num_d[:-k] # k個先になったらカウントを減らす
  _num_m = num_m.copy()
  _num_m[k:] = _num_m[k:] - _num_m[:-k] # 同上
  num_dm = _num_d * M_idx # 'M'の位置における'DM'の個数
  num_dm[k:] -= D_idx[:-k] * _num_m[k-1:-1]
  return (num_dm.cumsum(dtype=int) * C_idx).sum()


for k in K:
  print(count_DMC(k))

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

def count_DMC(k):
  num_d = [0] * (N+1)
  num_m = [0] * (N+1)
  num_dm = [0] * (N+1)
  res = 0
  for i, s in enumerate(S, 1):
    num_d[i] += num_d[i-1]
    num_m[i] += num_m[i-1]
    num_dm[i] += num_dm[i-1]
    if i - k - 1 >= 0 and S[i-k-1]=='D':
      num_dm[i] -= num_m[i]
    if s == 'D':
      num_d[i] += 1
      if i + k <= N:
        num_d[i+k] -= 1
    if s == 'M':
      num_m[i] += 1
      if i + k <= N:
        num_m[i+k] -= 1
      num_dm[i] += num_d[i]
    if s == 'C':
      res += num_dm[i]
  return res

for k in K:
  print(count_DMC(k))


Fixed submission:
import numpy as np

N = int(input())
S = np.array(list(input()))
Q = int(input())
K = list(map(int, input().split()))


D_idx = S == 'D'
M_idx = S == 'M'
C_idx = S == 'C'

num_d = D_idx.cumsum(dtype=int)
num_m = M_idx.cumsum(dtype=int)

def count_DMC(k):
  _num_d = num_d.copy()
  _num_d[k:] = _num_d[k:] - _num_d[:-k] # k個先になったらカウントを減らす
  _num_m = num_m.copy()
  _num_m[k:] = _num_m[k:] - _num_m[:-k] # 同上
  num_dm = _num_d * M_idx # 'M'の位置における'DM'の個数
  num_dm[k:] -= D_idx[:-k] * _num_m[k-1:-1]
  return (num_dm.cumsum(dtype=int) * C_idx).sum()


for k in K:
  print(count_DMC(k))
Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split())
ans = 'TLE'
cost = float('inf')

for i in range(N):
  c, t = map(int, input().split())
  if t <= T:
    ans = min(ans, c)

print(ans)

Fixed submission:
N, T = map(int, input().split())
ans = float('inf')
cost = float('inf')

for i in range(N):
  c, t = map(int, input().split())
  if t <= T:
    ans = min(ans, c)

if ans < float('inf'):
  print(ans)
else:
  print('TLE')
Buggy python submission (verdict: Runtime Error):
x1, y1, x2, y2 = map(int, input().split())
if x1 == x2:
  if y1 < y2:
    d = y2 - y1
    x3, y3 = x2-d, y2
    x4, y4 = x1-d, y1
  else:
    d = y1 - y2
    x3, y3 = x2+d, y2
    x4, y4 = x1+d, y1
else:
  if x1 < x2:
    d = x2 - x1
    x3, y3 = x2, y2+d
    x4, y4 = x1, y1+d
  else:
    x3, y3 = x2, y2-d
    x4, y4 = x1, y1-d

print(x3, y3, x4, y4)

Fixed submission:
x1, y1, x2, y2 = map(int, input().split())
v1 = [x2 - x1, y2 - y1]
v = [-v1[1], v1[0]]

x3, y3 = x2 + v[0], y2 + v[1]
x4, y4 = x1 + v[0], y1 + v[1]

print(x3, y3, x4, y4)
Buggy python submission (verdict: Runtime Error):
S = input()
if S[0] == '1':
  print(S[1])
else:
  print(S[0])

Fixed submission:
S = input()
K = int(input())
if S[0] != '1':
  print(S[0])
  quit()

for i, s in enumerate(S, 1):
  if s != '1':
    print(s)
    quit()
  elif i >= K:
    print(s)
    quit()
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())
Ls = [0] * N
Rs = [0] * N
for i in range(M):
  L, R = map(int, input().split())
  Ls[L-1] |= 1 << i
  Rs[R-1] |= 1 << i

for i in range(N-1):
  j = N - 1 - i
  Rs[i+1] |= Rs[i]
  Ls[j-1] |= Ls[j]

for i in range(Q):
  p, q = map(int, input().split())
  print(bin(Ls[p-1] & Rs[q-1]).count('1'))

Fixed submission:
N, M, Q = map(int, input().split())
MAP = [[0] * N for i in range(N)]
for i in range(M):
  L, R = map(int, input().split())
  MAP[L-1][R-1] += 1

for r in range(N):
  for l in range(N-1, 0, -1):
    MAP[l-1][r] += MAP[l][r]

for r in range(N-1):
  for l in range(N):
    MAP[l][r+1] += MAP[l][r]

for i in range(Q):
  p, q = map(int, input().split())
  print(MAP[p-1][q-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())
# LR = [list(map(int, input().split())) for i in range(M)]
Ls = [set() for i in range(N)]
Rs = [set() for i in range(N)]
for i in range(M):
  L, R = map(int, input().split())
  Ls[L-1].add(i)
  Rs[R-1].add(i)

for i in range(N-1):
  j = N - 1 - i
  Rs[i+1] |= Rs[i]
  Ls[j-1] |= Ls[j]

for i in range(Q):
  p, q = map(int, input().split())
  print(len(Ls[p-1] & Rs[q-1]))

Fixed submission:
N, M, Q = map(int, input().split())
MAP = [[0] * N for i in range(N)]
for i in range(M):
  L, R = map(int, input().split())
  MAP[L-1][R-1] += 1

for r in range(N):
  for l in range(N-1, 0, -1):
    MAP[l-1][r] += MAP[l][r]

for r in range(N-1):
  for l in range(N):
    MAP[l][r+1] += MAP[l][r]

for i in range(Q):
  p, q = map(int, input().split())
  print(MAP[p-1][q-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())
# LR = [list(map(int, input().split())) for i in range(M)]
Ls = [set() for i in range(N)]
Rs = [set() for i in range(N)]
for i in range(M):
  L, R = map(int, input().split())
  Ls[L-1].add(i)
  Rs[R-1].add(i)

for i in range(N-1):
  j = N - 1 - i
  Rs[i+1] |= Rs[i]
  Ls[j-1] |= Ls[j]

for i in range(Q):
  p, q = map(int, input().split())
  print(len(Ls[p-1] & Rs[q-1]))

Fixed submission:
N, M, Q = map(int, input().split())
MAP = [[0] * N for i in range(N)]
for i in range(M):
  L, R = map(int, input().split())
  MAP[L-1][R-1] += 1

for r in range(N):
  for l in range(N-1, 0, -1):
    MAP[l-1][r] += MAP[l][r]

for r in range(N-1):
  for l in range(N):
    MAP[l][r+1] += MAP[l][r]

for i in range(Q):
  p, q = map(int, input().split())
  print(MAP[p-1][q-1])
Buggy python submission (verdict: Runtime Error):
N = input()
S = 0
for n in N:
  S += int(n)

if S % N:
  print('No')
else:
  print('Yes')

Fixed submission:
N = input()
S = 0
for n in N:
  S += int(n)

if int(N) % S:
  print('No')
else:
  print('Yes')