Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())
smap = []
for _ in range(h):
  smap.append(input().strip())

L = [[0 for _ in range(w)] for _ in range(h)]
R = [[0 for _ in range(w)] for _ in range(h)]
U = [[0 for _ in range(w)] for _ in range(h)]
D = [[0 for _ in range(w)] for _ in range(h)]

for y in range(h):
  for x in range(w):
    if smap[y][x] == '#':
      L[y][x] = 0
      D[y][x] = 0
    else:
      if 0 < x <= w-1:
        L[y][x] = L[y][x-1] + 1
      else:
        L[y][x] = 1
      if 0 < y <= h-1:
        D[y][x] = D[y-1][x] + 1
      else:
        D[y][x] = 1

for y in range(h-1, -1, -1):
  for x in range(w-1, -1, -1):
    if smap[y][x] == '#':
      R[y][x] = 0
      U[y][x] = 0
    else:
      if 0 <= x < w-1:
        R[y][x] = R[y][x+1] + 1
      else:
        R[y][x] = 1
      if 0 <= y < h-1:
        U[y][x] = U[y+1][x] + 1
      else:
        U[y][x] = 1

ans = 0
for y in range(h):
  for x in range(w):
    tmp = L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3
    if ans < tmp:
      ans = tmp

print(ans)


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

L = [[0 for _ in range(w)] for _ in range(h)]
R = [[0 for _ in range(w)] for _ in range(h)]
U = [[0 for _ in range(w)] for _ in range(h)]
D = [[0 for _ in range(w)] for _ in range(h)]

for y in range(h):
  for x in range(w):
    if smap[y][x] == '#':
      L[y][x] = 0
      D[y][x] = 0
    else:
      if 0 < x <= w-1:
        L[y][x] = L[y][x-1] + 1
      else:
        L[y][x] = 1
      if 0 < y <= h-1:
        D[y][x] = D[y-1][x] + 1
      else:
        D[y][x] = 1

for y in range(h-1, -1, -1):
  for x in range(w-1, -1, -1):
    if smap[y][x] == '#':
      R[y][x] = 0
      U[y][x] = 0
    else:
      if 0 <= x < w-1:
        R[y][x] = R[y][x+1] + 1
      else:
        R[y][x] = 1
      if 0 <= y < h-1:
        U[y][x] = U[y+1][x] + 1
      else:
        U[y][x] = 1

ans = 0
for y in range(h):
  for x in range(w):
    tmp = L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3
    if ans < tmp:
      ans = tmp

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

n, m = map(int, input().split())
alist = list(sorted(map(int, input().split())))

for _ in range(m):
  b, c = map(int, input().split())
  i = bisect_left(alist, c)
  if i + 1 > b:
    alist = alist[b:] + [c]*b
  else:
    alist = alist[i:] + [c]*i
  alist.sort()

print(sum(alist))



Fixed submission:
n, m = map(int, input().split())
alist = list(sorted(map(int, input().split())))
bc = []
total = 0
for _ in range(m):
  bc.append(tuple(map(int, input().split())))

lim = n-1
total = 0
ans = 0
for b, c in sorted(bc, key=lambda x: -x[1]):
  while lim >= 0 and alist[lim] >= c:
    ans += alist[lim]
    lim -= 1
    total += 1
  ans += c * min(b, n-total)
  total += min(b, n-total)
  if total == n:
    break
if total == n:
  print(ans)
else:
  print(ans + sum(alist[total:]))

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappushpop

n, m = map(int, input().split())
alist = list(map(int, input().split()))
heapify(alist)

for _ in range(m):
  b, c = map(int, input().split())
  for _ in range(b):
    if alist[0] >= c:
      break
    else:
      heappushpop(alist, c)

print(sum(alist))


Fixed submission:
n, m = map(int, input().split())
alist = list(sorted(map(int, input().split())))
bc = []
total = 0
for _ in range(m):
  bc.append(tuple(map(int, input().split())))

lim = n-1
total = 0
ans = 0
for b, c in sorted(bc, key=lambda x: -x[1]):
  while lim >= 0 and alist[lim] >= c:
    ans += alist[lim]
    lim -= 1
    total += 1
  ans += c * min(b, n-total)
  total += min(b, n-total)
  if total == n:
    break
if total == n:
  print(ans)
else:
  print(ans + sum(alist[total:]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(pow(10, 6))

n = int(input())
nodes = [[] for _ in range(n)]
visited = [False for _ in range(n)]

def dfs(i, d):
  global nodes
  child_d = [(i, d)]
  for cn, c in nodes[i]:
    if not visited[cn]:
      visited[cn] = True
      child_d += dfs(cn, d+c)
  return child_d

for _ in range(n-1):
  u, v, w = map(int, input().split())
  nodes[u-1].append((v-1, w))
  nodes[v-1].append((u-1, w))

visited[0] = True
ans = dfs(0, 0)

for _, c in sorted(ans, key=lambda x: x[0]):
  if c % 2 == 0:
    print(0)
  else:
    print(1)


Fixed submission:
import sys
sys.setrecursionlimit(pow(10, 6))

n = int(input())
nodes = [[] for _ in range(n)]
visited = [False for _ in range(n)]
dist = [0 for _ in range(n)]

def dfs(i, d):
  dist[i] = d
  for cn, c in nodes[i]:
    if not visited[cn]:
      visited[cn] = True
      dfs(cn, d+c)

for _ in range(n-1):
  u, v, w = map(int, input().split())
  nodes[u-1].append((v-1, w))
  nodes[v-1].append((u-1, w))

visited[0] = True
dfs(0, 0)

for c in dist:
  if c % 2 == 0:
    print(0)
  else:
    print(1)
Buggy python submission (verdict: Runtime Error):
n = int(input())

divl = [n]
i = 2
while i * i <= n:
  if n % i == 0:
    divl.append(i)
    divl.append(n // i)
  i += 1

ans = 0
for d in divl:
  if n == d * (n // (d - 1)):
    ans += d - 1
print(ans)


Fixed submission:
n = int(input())

if n == 1:
  print(0)
else:
  divl = [n]
  i = 2
  while i * i <= n:
    if n % i == 0:
      divl.append(i)
      divl.append(n // i)
    i += 1

  ans = 0
  for d in divl:
    if n == d * (n // (d - 1)):
      ans += d - 1
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h, w = map(int,input().split())
alist = [input().strip() for i in range(h)]
dxy = [(0,1),(1,0),(0,-1),(-1,0)]

INF = 99999
dp = [[INF]*w for i in range(h)]
q = deque()
for y, row in enumerate(alist):
  for x, c in enumerate(row):
    if c=='#':
      dp[y][x] = 0
      q.append((x,y))

while q:
  x, y = q.popleft()
  d = dp[y][x]
  for dx, dy in dxy:
    nx, ny = x+dx, y+dy
    if not 0 <= nx < w:
      continue
    if not 0 <= ny < h:
      continue
    if dp[ny][nx] <= d+1:
      continue
    dp[ny][nx] = d+1
    q.append((nx,ny))

print(max(max(row) for row in dp))


Fixed submission:
from collections import deque

h, w = map(int,input().split())
alist = [input().strip() for i in range(h)]
dxy = [(0,1),(1,0),(0,-1),(-1,0)]

INF = 99999
dp = [[INF]*w for i in range(h)]
q = deque()
for y, row in enumerate(alist):
  for x, c in enumerate(row):
    if c=='#':
      dp[y][x] = 0
      q.append((x,y))

while q:
  x, y = q.popleft()
  d = dp[y][x]
  for dx, dy in dxy:
    nx, ny = x+dx, y+dy
    if not 0 <= nx < w:
      continue
    if not 0 <= ny < h:
      continue
    if dp[ny][nx] <= d+1:
      continue
    dp[ny][nx] = d+1
    q.append((nx,ny))

print(max(max(row) for row in dp))
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input().strip()
td = [tuple(input().strip().split()) for _ in range(q)]

def is_fall_l(i):
  now = i
  for t, d in td:
    if s[now] == t:
      if d == 'L':
        now -= 1
      else:
        now += 1
    if now == -1:
      return True
  return False

def is_fall_r(i):
  now = i
  for t, d in td:
    if s[now] == t:
      if d == 'L':
        now -= 1
      else:
        now += 1
    if now == n:
      return True
  return False

ll, lr = 0, n-1
while ll != lr:
  mid = (ll + lr) // 2
  if is_fall_l(mid):
    ll = mid + 1
  else:
    lr = mid

rl, rr = 0, n-1
while rl != rr:
  mid = (rl + rr) // 2
  if is_fall_r(mid):
    rr = mid
  else:
    rl = mid + 1

if rl == n-1:
  rl += 1
if lr == 0:
  lr -= 1

print(rl - lr)


Fixed submission:
n, q = map(int, input().split())
s = '*' + input().strip() + '*'
td = [tuple(input().strip().split()) for _ in range(q)]

def fall_d(i):
  now = i
  for t, d in td:
    if s[now] == t:
      if d == 'L':
        now -= 1
      else:
        now += 1
    if now == 0:
      return 'Left'
    elif now == n + 1:
      return 'Right'
  return 'Remain'

ll, lr = 0, n + 1
while ll != lr:
  mid = (ll + lr) // 2
  if fall_d(mid) == 'Left':
    ll = mid + 1
  else:
    lr = mid

rl, rr = 0, n + 1
while rl != rr:
  mid = (rl + rr) // 2
  if fall_d(mid) == 'Right':
    rr = mid
  else:
    rl = mid + 1

print(rr - ll)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

base = 2
ans = ''
while base // 2 <= b:
  nb = (b // base) * (base // 2)
  na = (a // base) * (base // 2)
  if b % base != 0:
    nb += max(0, b % base - (base // 2) + 1)
  if a % base != 0:
    na += max(0, (a - 1) % base - (base // 2) + 1)
  if (nb - na) % 2 == 1:
    ans += '1'
  else:
    ans += '0'
  base *= 2
print(int(ans[::-1], 2))

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

base = 2
ans = ''
if a == 0 and b == 0:
  print(0)
else:
  while base // 2 <= b:
    nb = (b // base) * (base // 2)
    na = (a // base) * (base // 2)
    if b % base != 0:
      nb += max(0, b % base - (base // 2) + 1)
    if a % base != 0:
      na += max(0, (a - 1) % base - (base // 2) + 1)
    if (nb - na) % 2 == 1:
      ans += '1'
    else:
      ans += '0'
    base *= 2
  print(int(ans[::-1], 2))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
  l = int(input())
  dp = [[float('inf') for _ in range(l+1)] for _ in range(5)]
  dp[0][0] = 0
  for i in range(l):
    a = int(input())
    for j in range(5):
      for k in range(j, 5):
        cost = a
        if k == 1 or k == 3:
          if a % 2 == 0 and a > 0:
            cost = 0
          elif a > 0:
            cost = 1
          else:
            cost = 2
        elif k == 2:
          if a % 2 == 1:
            cost = 0
          else:
            cost = 1
        if dp[k][i+1] > dp[j][i] + cost:
          dp[k][i+1] = dp[j][i] + cost
  print(min([dpp[-1] for dpp in dp]))


if __name__ == '__main__':
  main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
  l = int(input())
  dp = [[float('inf') for _ in range(l+1)] for _ in range(5)]
  dp[0][0] = 0
  for i in range(l):
    a = int(input())
    for j in range(5):
      for k in range(j, 5):
        cost = a
        if k == 1 or k == 3:
          if a % 2 == 0 and a > 0:
            cost = 0
          elif a > 0:
            cost = 1
          else:
            cost = 2
        elif k == 2:
          if a % 2 == 1:
            cost = 0
          else:
            cost = 1
        if dp[k][i+1] > dp[j][i] + cost:
          dp[k][i+1] = dp[j][i] + cost
  print(min([dpp[-1] for dpp in dp]))


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
ll = list(sorted(map(int, input().split())))

if sum(ll[:-1]) > sum[-1]:
  print('Yes')
else:
  print('No')

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

if sum(ll[:-1]) > ll[-1]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().strip().split())
S = [input().strip() for _ in range(H)]
visited = [[False for _ in range(W)] for _ in range(H)]

def dfs(_i, _j, _S, _visited, _fs):
  if _i<H-1 and not _visited[_i+1][_j] and S[_i][_j]!=S[_i+1][_j]:
    if S[_i+1][_j] == '.':
      _fs.add((_i+1, _j))
    _visited[_i+1][_j] = True
    _fs |= dfs(_i+1, _j, _S, _visited, _fs)
    _visited[_i+1][_j] = False
  if _i>0 and not _visited[_i-1][_j] and S[_i][_j]!=S[_i-1][_j]:
    if S[_i-1][_j] == '.':
      _fs.add((_i-1, _j))
    _visited[_i-1][_j] = True
    _fs |= dfs(_i-1, _j, _S, _visited, _fs)
    _visited[_i-1][_j] = False
  if _j<W-1 and not _visited[_i][_j+1] and S[_i][_j]!=S[_i][_j+1]:
    if S[_i][_j+1] == '.':
      _fs.add((_i, _j+1))
    _visited[_i][_j+1] = True
    _fs |= dfs(_i, _j+1, _S, _visited, _fs)
    _visited[_i][_j+1] = False
  if _j>-0 and not _visited[_i][_j-1] and S[_i][_j]!=S[_i][_j-1]:
    if S[_i][_j-1] == '.':
      _fs.add((_i, _j-1))
    _visited[_i][_j-1] = True
    _fs |= dfs(_i, _j-1, _S, _visited, _fs)
    _visited[_i][_j-1] = False
  return _fs

ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      fs = set()
      visited[i][j] = True
      fs = dfs(i, j, S, visited, fs);
      ans += len(fs)
      for k in range(H):
        for l in range(W):
          visited[k][l] = False
          
print(ans)

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

visited = [[False for _ in range(w)] for _ in range(h)]

ans = 0
for i in range(h):
  for j in range(w):
    if visited[i][j]:
      continue
    bc = 0
    wc = 0
    visited[i][j] = True
    node = [(i, j)]
    while node:
      ci, cj = node[0]
      node = node[1:]
      if s[ci][cj] == '#':
        bc += 1
      else:
        wc += 1
      if ci - 1 >= 0 and s[ci][cj] != s[ci-1][cj]:
        if not visited[ci-1][cj]:
          visited[ci-1][cj] = True
          node.append((ci-1, cj))
      if ci + 1 <= h-1 and s[ci][cj] != s[ci+1][cj]:
        if not visited[ci+1][cj]:
          visited[ci+1][cj] = True
          node.append((ci+1, cj))
      if cj - 1 >= 0 and s[ci][cj] != s[ci][cj-1]:
        if not visited[ci][cj-1]:
          visited[ci][cj-1] = True
          node.append((ci, cj-1))
      if cj + 1 <= w-1 and s[ci][cj] != s[ci][cj+1]:
        if not visited[ci][cj+1]:
          visited[ci][cj+1] = True
          node.append((ci, cj+1))
    ans += bc * wc

print(ans)
Buggy python submission (verdict: Runtime Error):
N, H, W = map(int, input.strip().split())
A, B = [], []
for _ in range(N):
  a, b = map(int, input().strip().split())
  A.append(a)
  B.append(b)

i = 0
for a, b in zip(A, B):
  if a >= H and b >= W:
    i += 1
print(i)

Fixed submission:
N, H, W = map(int, input().strip().split())
A, B = [], []
for _ in range(N):
  a, b = map(int, input().strip().split())
  A.append(a)
  B.append(b)

i = 0
for a, b in zip(A, B):
  if a >= H and b >= W:
    i += 1
print(i)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().strip().split())

b = 'P'
for _ in range(N):
  b = 'B'+b+'P'+b+'B'

print(b[:X].count('P'))

Fixed submission:
N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)

def f(N, X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))
Buggy python submission (verdict: Runtime Error):
S=int(input().strip())

m =None
for i in range(len(S)-2):
  e=int(S[i:i+3])
  if m is None:
    m=abs(753-e)
  elif abs(753-e) <m:
    m=abs(753-e)
print(m)

Fixed submission:
S=input().strip()

m =None
for i in range(len(S)-2):
  e=int(S[i:i+3])
  if m is None:
    m=abs(753-e)
  elif abs(753-e) <m:
    m=abs(753-e)
print(m)
Buggy python submission (verdict: Runtime Error):
N = int(input().strip())

xyh = []
for _ in range(N):
  x, y, h = map(int, input().strip().split())
  if h != 0:
    xyh.append((x, y, h))

for k in range(N):
  for i in range(101):
    for j in range(101):
      H = xyh[k][2] + abs(i-xyh[k][0]) + abs(j-xyh[k][1])
      is_h = True
      for _xyh in xyh:
        if H != _xyh[2] + abs(i-_xyh[0]) + abs(j-_xyh[1]):
          is_h = False
          break
      if is_h:
        mx, my, mh = i, j, H

print(mx, my, mh)


Fixed submission:
N = int(input().strip())
xyh = []
for _ in range(N):
  x, y, h = map(int, input().strip().split())
  xyh.append((x, y, h))

for i in range(101):
  for j in range(101):
    for k in range(N):
      if xyh[k][2] != 0:
        H = xyh[k][2] + abs(i-xyh[k][0]) + abs(j-xyh[k][1])
        break
    is_h = True
    for k in range(N):
      if max(0, H-abs(i-xyh[k][0])-abs(j-xyh[k][1])) != xyh[k][2]:
        is_h = False
        break
    if is_h:
      print(i, j, H)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().strip().split())

i=1
while i*i < M and i <= M//N:
  if M % i == 0:
    maxg = i
  i += 1

print(maxg)

Fixed submission:
N, M = map(int, input().strip().split())

i=1
while i <= M//N: 
  if M % i == 0:
    maxg = i
    if M//i <= M//N:
      maxg = M // i
      break
  i += 1

print(maxg)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().strip().split())

i=1
while i*i < M:
  if M % i == 0:
    maxg = M // N
  i += 1

print(maxg)

Fixed submission:
N, M = map(int, input().strip().split())

i=1
while i <= M//N: 
  if M % i == 0:
    maxg = i
    if M//i <= M//N:
      maxg = M // i
      break
  i += 1

print(maxg)

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

maxg = 1
if N == 1:
  maxg = M
else:
  for i in range(2, M//N+1):
    if (M - N*i) % i == 0:
      maxg = i

print(maxg)


Fixed submission:
N, M = map(int, input().strip().split())

i=1
while i <= M//N: 
  if M % i == 0:
    maxg = i
    if M//i <= M//N:
      maxg = M // i
      break
  i += 1

print(maxg)

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

maxg = 1
for i in range(2, M//N+1):
  if (M - N*i) % i == 0:
    maxg = i

print(maxg)

Fixed submission:
N, M = map(int, input().strip().split())

i=1
while i <= M//N: 
  if M % i == 0:
    maxg = i
    if M//i <= M//N:
      maxg = M // i
      break
  i += 1

print(maxg)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input().strip())
vs = list(map(int, input().strip().split()))
oddv = [v for i, v in enumerate(vs) if i % 2 == 0]
evenv = [v for i, v in enumerate(vs) if i % 2 == 1]

oddc = Counter(oddv)
evenc = Counter(evenv)
if oddc.most_common(1)[0][0] != evenc.most_common(1)[0][0]:
  print(len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(1)[0][1])
else:
  if len(oddc.most_common()) == 1 and len(evenc.most_common()) == 1:
    print(len(oddv))
  elif len(oddc.most_common()) == 1:
    print(len(evenv) - evenc.most_common(2)[1][1])
  else len(evenc.most_common()) == 1:
    print(len(oddv) - oddc.most_common(2)[1][1])
  else:
    print(min(len(oddv) - oddc.most_common(2)[1][1] + len(evenv) - evenc.most_common(1)[0][1], len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(2)[0][1]))

Fixed submission:
from collections import Counter

n = int(input().strip())
vs = list(map(int, input().strip().split()))
oddv = [v for i, v in enumerate(vs) if i % 2 == 0]
evenv = [v for i, v in enumerate(vs) if i % 2 == 1]

oddc = Counter(oddv)
evenc = Counter(evenv)
if oddc.most_common(1)[0][0] != evenc.most_common(1)[0][0]:
  print(len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(1)[0][1])
else:
  if len(oddc.most_common()) == 1 and len(evenc.most_common()) == 1:
    print(len(oddv))
  elif len(oddc.most_common()) == 1:
    print(len(evenv) - evenc.most_common(2)[1][1])
  elif len(evenc.most_common()) == 1:
    print(len(oddv) - oddc.most_common(2)[1][1])
  else:
    print(min(len(oddv) - oddc.most_common(2)[1][1] + len(evenv) - evenc.most_common(1)[0][1], len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(2)[1][1]))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

yd = {}
i = 2
while m != 1:
  while m % i == 0:
    if i in yd:
      yd[i] += 1
    else:
      yd[i] = 1
    m //= i
  i += 1

ans = 1
for v in yd.values():
  start = v + n - 1
  c = 1
  for _ in range(v):
    c *= start
    start -= 1
  d = 1
  for _v in range(v):
    d *= (_v + 1)
  ans *= (c // d)
print(ans % 1000000007)


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

yd = {}
i = 2
while m != 1:
  while m % i == 0:
    if i in yd:
      yd[i] += 1
    else:
      yd[i] = 1
    m //= i
  i += 1

ans = 1
for v in yd.values():
  start = v + n - 1
  c = 1
  for _ in range(v):
    c *= start
    start -= 1
  d = 1
  for _v in range(v):
    d *= (_v + 1)
  ans *= (c // d)
print(ans % 1000000007)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().strip().split())
xs = list(map(int, input().strip().split()))

for i in range(len(xs)):
  xs[i] = abs(xs[i] - X)

isis = False
if N == 1:
  print(xs[0] - X)
  isis = True

max_dis = max(abs(xs[i] - xs[i+1]) for i in range(len(xs) - 1))
min_dis = min(abs(xs[i] - xs[i+1]) for i in range(len(xs) - 1))
a, b = max_dis, min_dis
while isis:
  if b == 0:
    print(a)
    break
  c = a % b
  if c == 0:
    print(b)
    break
  a = b
  b = c

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

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

mx = abs(xlist[0] - x)
for _x in xlist[1:]:
  mx = gcd(max(abs(_x-x), mx), min(abs(_x-x), mx))
print(mx)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int, input().split())
trnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
cnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
  l, r = map(int, input().split())
  trnum[l][r] += 1

for i in range(n+1):
  for j in range(n+1):
    cnum[i][j] = cnum[i][j-1] + trnum[i][j]

for _ in range(q):
  qp, qq = map(int, input().split())
  s = 0
  for j in range(qp, qq+1):
    s += cnum[j][qq] - cnum[j][qp-1]
  print(s)


Fixed submission:
n, m, q = map(int, input().split())
trnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
cnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
  l, r = map(int, input().split())
  trnum[l][r] += 1

for i in range(1, n+1):
  for j in range(1, n+1):
    trnum[i][j] += trnum[i][j-1]

for i in range(1, n+1):
  for j in range(1, n+1):
    trnum[i][j] += trnum[i-1][j]


for _ in range(q):
  l, r = map(int, input().split())
  print(trnum[r][r] + trnum[l-1][l-1] - trnum[l-1][r] - trnum[r][l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().strip().split())
train_starts = {}
for n in range(1, N + 1):
  train_starts[n] = []

for _ in range(M):
  L, R = map(int, input().strip().split())
  train_starts[L].append(R)

for _ in range(Q):
  p, q = map(int, input().strip().split())
  num_trains = 0
  for _p in range(p, N + 1):
    if _p not in train_starts or _p > q:
      continue
    else:
      num_trains += len([_q for _q in train_starts[_p] if _q <=q])
  print(num_trains)

Fixed submission:
n, m, q = map(int, input().split())
trnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
cnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
  l, r = map(int, input().split())
  trnum[l][r] += 1

for i in range(1, n+1):
  for j in range(1, n+1):
    trnum[i][j] += trnum[i][j-1]

for i in range(1, n+1):
  for j in range(1, n+1):
    trnum[i][j] += trnum[i-1][j]


for _ in range(q):
  l, r = map(int, input().split())
  print(trnum[r][r] + trnum[l-1][l-1] - trnum[l-1][r] - trnum[r][l-1])
Buggy python submission (verdict: Runtime Error):
N = int(input().strip())
A = map(int, input().strip().split())
max_abs_sum = 0
for i in range(len(A) - 1):
  for j in (i+1, range(A)):
    if max_abs_sum < abs(A[i] - A[j]):
      max_abs_sum = abs(A[i] - A[j])
print(max_abs_sum)

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

print(A[-1] - A[0])
Buggy python submission (verdict: Runtime Error):
N = input().strip()

SN = sum(int(c) for c in N)

if N % SN == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
N = input().strip()

SN = sum(int(c) for c in N)

if int(N) % SN == 0:
    print('Yes')
else:
    print('No')