Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
H, W, A, B = map(int, input().split())
answer = 0
mod = 1000000007
factorial = [1]
for n in range(1, H+W):
    factorial.append(factorial[n-1]*n%mod)
def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y/2)**2%mod
    else:
        return power(x, y/2)**2*x%mod

inverseFactorial = [0] * (H+W)
inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2)
for n in range(H+W-2, -1, -1):
    inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod
def combi(n, m):
    return factorial[n] * inverseFactorial[m] *inverseFactorial[n-m]%mod

for i in range(B+1, W+1):
    answer = (answer + combi(H-A-2+i, i-1)*combi(A+W-i-1,W-i)) % mod
print(answer)

Fixed submission:
H, W, A, B = map(int, input().split())
answer = 0
mod = 1000000007
factorial = [1]
for n in range(1, H+W):
    factorial.append(factorial[n-1]*n%mod)
def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y//2) ** 2 % mod
    else:
        a = power(x, y//2) ** 2
        return a * x % mod
inverseFactorial = [0] * (H+W)
inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2)
for n in range(H+W-2, -1, -1):
    inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod
def combi(n, m):
    return factorial[n] * inverseFactorial[m] *inverseFactorial[n-m]%mod

for i in range(B+1, W+1):
    answer = (answer + combi(H-A-2+i, i-1)*combi(A+W-i-1,W-i)) % mod
print(answer)

Buggy python submission (verdict: Runtime Error):
mod = 1000000007
factorial = [1]
for n in range(1, H+W):
    factorial.append(factorial[n-1]*n%mod)
def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y/2)**2%mod
    else:
        return power(x, y/2)**2*x%mod

inverseFactorial = [0] * (H+W)
inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2)
for n in range(H+W-2, -1, -1):
    inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod
def combi(n, m):
    return factorial[n] * inverseFactorial[m] *inverseFactorial[n-m]%mod

H, W, A, B = map(int, input().split())
answer = 0
for i in range(B+1, W+1):
    answer = (answer + combi(H-A-2+i, i-1)*combi(A+W-i-1,W-i)) % mod
print(answer)

Fixed submission:
H, W, A, B = map(int, input().split())
answer = 0
mod = 1000000007
factorial = [1]
for n in range(1, H+W):
    factorial.append(factorial[n-1]*n%mod)
def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y//2) ** 2 % mod
    else:
        a = power(x, y//2) ** 2
        return a * x % mod
inverseFactorial = [0] * (H+W)
inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2)
for n in range(H+W-2, -1, -1):
    inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod
def combi(n, m):
    return factorial[n] * inverseFactorial[m] *inverseFactorial[n-m]%mod

for i in range(B+1, W+1):
    answer = (answer + combi(H-A-2+i, i-1)*combi(A+W-i-1,W-i)) % mod
print(answer)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

r = [0 for x in range(0, m)]

for _ in range(0, n):
    a = [x for x in map(int, input().split())]
    for i in a[1:]:
        r[i - 1] += 1

print(f'{len([x for x in r if x == n])}')


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

r = [0 for x in range(0, m)]

for _ in range(0, n):
    a = [x for x in map(int, input().split())]
    for i in a[1:]:
        r[i - 1] += 1

print('{}'.format(len([x for x in r if x == n])))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys
import pprint
from collections import deque


sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	h, w = map(int, sys.stdin.readline().split())
	ch, cw = map(int, sys.stdin.readline().split())
	dh, dw = map(int, sys.stdin.readline().split())
	s = [sys.stdin.readline().rstrip() for i in [0]*h]
	graph = [[[] for i in [0]*w] for j in [0]*h]
	
	def getMaze(x, y):
		if not (0 <= x < w and 0 <= y < h):
			return -1
		return s[y][x]

	for y in range(h):
		for x in range(w):
			if s[y][x] == "#":
				continue
			for i in range(-2, 2+1):
				for j in range(-2, 2+1):
					if (i, j) == (0, 0):
						continue
					if getMaze(x + i, y + j) == ".":
						if (i, j) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
							graph[y][x].append((x + i, y + j, 0))
						else:
							graph[y][x].append((x + i, y + j, 1))


	# log.print(graph)
	stack = deque([(cw-1, ch-1)])
	dist = [[float("inf")]*w for i in range(h)]
	while len(stack) != 0:
		x, y = stack.popleft()
		log.print(x, y, dist[y][x])
		if dist[y][x] == float("inf"):
			dist[y][x] = 0
		d = dist[y][x]
		nexts = graph[y][x]
		for next in nexts:
			nx, ny, cost = next
			if dist[ny][nx] > d + cost:
				dist[ny][nx] = d + cost
				if cost == 1:
					stack.append((nx, ny))
				else:
					stack.appendleft((nx, ny))
	log.print(dist)
	if dist[dh-1][dw-1] == float("inf"):
		print(-1)
	else:
		print(dist[dh-1][dw-1])
	
	


main()

Fixed submission:
#!/usr/bin/env python3

import sys
import pprint
from collections import deque


sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	h, w = map(int, sys.stdin.readline().split())
	ch, cw = map(int, sys.stdin.readline().split())
	dh, dw = map(int, sys.stdin.readline().split())
	s = [sys.stdin.readline().rstrip() for i in [0]*h]
	graph = [[[] for i in [0]*w] for j in [0]*h]
	
	def getMaze(x, y):
		if not (0 <= x < w and 0 <= y < h):
			return -1
		return s[y][x]

	for y in range(h):
		for x in range(w):
			if s[y][x] == "#":
				continue
			


	# log.print(graph)
	stack = deque([(cw-1, ch-1)])
	dist = [[float("inf")]*w for i in range(h)]
	while len(stack) != 0:
		x, y = stack.popleft()
		log.print(x, y, dist[y][x])
		if dist[y][x] == float("inf"):
			dist[y][x] = 0
		d = dist[y][x]
		nexts = []
		for i in range(-2, 2+1):
			for j in range(-2, 2+1):
				if (i, j) == (0, 0):
					continue
				if getMaze(x + i, y + j) == ".":
					if (i, j) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
						nexts.append((x + i, y + j, 0))
					else:
						nexts.append((x + i, y + j, 1))
		for next in nexts:
			nx, ny, cost = next
			if dist[ny][nx] > d + cost:
				dist[ny][nx] = d + cost
				if cost == 1:
					stack.append((nx, ny))
				else:
					stack.appendleft((nx, ny))
	log.print(dist)
	if dist[dh-1][dw-1] == float("inf"):
		print(-1)
	else:
		print(dist[dh-1][dw-1])
	
	


main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	a = [0]*100
	if n == 0:
		print(x)
		exit()
	for i in range(n):
		a[p[i]-1] = 1
	i = x - 1
	log.print(p, i)
	lower = 0
	while i >= -1:
		log.print(i, a[i])
		if a[i] == 0:
			lower = i + 1
			break
		i -= 1
	i = x - 1
	upper = 0
	while i <= 101:
		log.print(i, a[i])
		if a[i] == 0:
			upper = i + 1
			break
		i += 1
	if abs(x - lower) == abs(x - upper):
		print(lower)
		exit()
	if abs(x - lower) < abs(x - upper):
		print(lower)
	else:
		print(upper)

main()

Fixed submission:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	i = x - 1
	lower = 0
	while i >= 0:
		if not i+1 in p:
			lower = i+1
			break
		i -= 1
	i = x - 1
	upper = 101
	while i <= 101:
		if not i+1 in p:
			upper = i+1
			break
		i += 1
	if abs(x - lower) == abs(x - upper):
		print(lower)
	elif abs(x - lower) < abs(x - upper):
		print(lower)
	else:
		print(upper)

main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import pprint
import itertools

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n, m, x = map(int, sys.stdin.readline().split())
	c = []
	a = []
	for i in range(n):
		ci, *ai = map(int, sys.stdin.readline().split())
		c.append(ci)
		a.append(ai)
	ans = 10**9
	for i in range(2**n):
		cost = 0
		rikai = [0]*n
		case = []
		for j in range(n):
			case.append(i>>j & 1)
		for j in range(n):
			if not case[j]:
				continue
			cost += c[j]
			for k in range(m):
				rikai[k] += a[j][k]
		log.print(case, rikai, len(list(filter(lambda z:z>=x, rikai))))
		if len(list(filter(lambda z:z>=x, rikai))) == m:
			ans = min(cost, ans)
	if ans == 10**9:
		print(-1)
		exit()
	print(ans)





main()

Fixed submission:

#!/usr/bin/env python3

import sys
import pprint
import itertools

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n, m, x = map(int, sys.stdin.readline().split())
	c = []
	a = []
	for i in range(n):
		ci, *ai = map(int, sys.stdin.readline().split())
		c.append(ci)
		a.append(ai)
	ans = 10**9
	log.print(a)
	for i in range(2**n):
		cost = 0
		rikai = [0]*m
		case = []
		for j in range(n):
			case.append(i>>j & 1)
		for j in range(n):
			if not case[j]:
				continue
			cost += c[j]
			for k in range(m):
				rikai[k] += a[j][k]
		# log.print(case, rikai, len(list(filter(lambda z:z>=x, rikai))))
		if len(list(filter(lambda z:z>=x, rikai))) == m:
			ans = min(cost, ans)
	if ans == 10**9:
		print(-1)
		exit()
	print(ans)





main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import pprint
import math

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	a, b, n = map(int, sys.stdin.readline().split())
	if n < b:
		print(int((n/b - int(n/b))*a))
	else:
		print(int(((b-1)/b - int((b-1)/b))*a))

	


main()

def main():
	log = Logger(1)
	a, b, n = map(int, sys.stdin.readline().split())
	if n < b:
		print(int((n/b - int(n/b))*a))
	else:
		print(int(((b-1)/b - int((b-1)/b))*a))

	


main()

Fixed submission:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	a, b, n = map(int, sys.stdin.readline().split())
	if n < b:
		print(int((n/b - int(n/b))*a))
	else:
		print(int(((b-1)/b - int((b-1)/b))*a))

	


main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	s = input()
	sumc = []
	sumr = 0
	sumg = 0
	sumb = 0
	for i in range(n):
		if s[i] == "R":
			sumr += 1
		if s[i] == "G":
			sumg += 1
		if s[i] == "B":
			sumb += 1
		sumc.append({
			"R" : sumr,
			"G": sumg,
			"B": sumb
			})
	a = {"R": 0, "G": 1, "B": 2}
	case = 0
	log.print(sumc)
	for i in range(n):
		for j in range(i+1, n-1):
			l = j - i
			if s[i] == s[j]:
				continue
			rgb = list("RGB")
			rgb.pop(rgb.index(s[i]))
			rgb.pop(rgb.index(s[j]))
			case += sumc[n-1][rgb[0]] - sumc[j][rgb[0]]
			if j + l < n and s[j+l] == rgb[0]:
				case -= 1
			log.print(i, j, rgb, case)
	print(case)




	


main()

Fixed submission:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	s = input()
	sumc = []
	sumr = 0
	sumg = 0
	sumb = 0
	for i in range(n):
		if s[i] == "R":
			sumr += 1
		if s[i] == "G":
			sumg += 1
		if s[i] == "B":
			sumb += 1
		sumc.append({
			"R" : sumr,
			"G": sumg,
			"B": sumb
			})
	a = {"R": 0, "G": 1, "B": 2}
	case = 0
	log.print(sumc)
	for i in range(n):
		for j in range(i+1, n-1):
			l = j - i
			if s[i] == s[j]:
				continue
			rgb = list("RGB")
			rgb.pop(rgb.index(s[i]))
			rgb.pop(rgb.index(s[j]))
			case += sumc[n-1][rgb[0]] - sumc[j][rgb[0]]
			if j + l < n and s[j+l] == rgb[0]:
				case -= 1
			log.print(i, j, rgb, case)
	print(case)




	


main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env pypy3

import sys
import pprint
from collections import deque

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	n = int(sys.stdin.readline())
	cnt = 0
	stack = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
	already = deque([])
	while len(stack) != 0:
		now = stack.popleft()
		already.append(now)
		cnt += 1
		if cnt == n:
			print(now)
			exit()
		if now % 10 == 0:
			nexts = [now * 10 + now % 10, now * 10 + now  % 10+ 1]
		elif now % 10 == 9:
			nexts = [now * 10 + now % 10 - 1, now * 10 + now % 10]
		else:
			nexts = [now * 10  + now % 10 - 1, now * 10 + now % 10, now * 10 + now % 10 + 1]
		for next in nexts:
			if next in already or next in stack:
				continue
			stack.append(next)


main()

Fixed submission:
K = int(input())
a = []
dp = [[[] for i in range(10)] for j in range(100)]
for i in range(10):
  dp[0][i] = [i]
  if i != 0:
    a.append(i)
for i in range(1, 10):
  for j in range(10):
    if j != 0:
      for k in dp[i-1][j-1]:
        dp[i][j].append(k + 10 ** i * j)
        a.append(k + 10 ** i * j)
    for k in dp[i-1][j]:
      dp[i][j].append(k + 10 ** i * j)
      if j != 0:
        a.append(k + 10 ** i * j)
    if j != 9:
      for k in dp[i-1][j+1]:
        dp[i][j].append(k + 10 ** i * j)
        if j != 0:
          a.append(k + 10 ** i * j)
print(a[K-1])
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
s = "b" * a + "r" * b
if a == 0 and b == 0:
    print(0)
if s[n % (a + b)] == "b":
    bcnt = n % (a+b)
else:
    bcnt = a
print(n // (a + b) * a + bcnt)



Fixed submission:
n, a, b = map(int, input().split())
if a == 0 and b == 0:
    print(0)
    exit()
if n % (a + b) < a:
    bcnt = n % (a+b)
else:
    bcnt = a
print(n // (a + b) * a + bcnt)
Buggy python submission (verdict: Runtime Error):
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
lists = list(itertools.permutations(list(range(1, n+1)), n))
print(abs(lists.index(p) - lists.index()))

Fixed submission:
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
lists = list(itertools.permutations(list(range(1, n+1)), n))
print(abs(lists.index(p) - lists.index(q)))
Buggy python submission (verdict: Runtime Error):
if n % 2 == 1:
    print(0)
else:
    cnt = 0
    a = n // 2 // 5
    b = 0
    while a >= 5 ** b:
        cnt += a // 5**b
        b += 1
    print(cnt)

Fixed submission:
n = int(input())
if n % 2 == 1:
    print(0)
else:
    cnt = 0
    a = n // 2 // 5
    b = 0
    while a >= 5 ** b:
        cnt += a // 5**b
        b += 1
    print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(range(1, n+1))
print(sum(list(range(1, n))))

Fixed submission:
n = int(input())
print(n * (n-1) // 2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(range(1, n+1))
p = list(range(2, n+1)) + [1]
m = 0
for i in range(n):
  m += a[i] % p[i]
print(m)

Fixed submission:
n = int(input())
print(n * (n-1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int, input().split()))
if h == sorted(h):
    print("Yes")
    exit()
for i in range(len(h)):
    copyh = h
    copyh[i] -= 1
    if copyh == sorted(copyh):
        print("Yes")
        exit()
print("No")

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
down = 0
for i in range(1, n):
    if h[i-1] > h[i]:
        down += h[i-1] - h[i]
    if h[i-1] < h[i]:
        down = 0
    if down >= 2:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
c = []
ci = ""
nowR = True
nowL = False
for i in range(n-1):
  if s[i] != s[i+1]:
    ci += s[i]
    c.append(ci)
    ci = ""
  else:
    ci += s[i]
ci += "L"
c.append(ci)
cnt = [0]*n
j = -1
for i in range(len(c)):
  if i % 2 == 0:
    # R
    cil = len(c[i])
    j += cil
    cnt[j] += cil - cil//2
    cnt[j+1] += cil//2
  else:
    # L
    cil = len(c[i])
    cnt[j] += cil//2
    cnt[j+1] += cil - cil//2
    j += cil
print(*cnt)
    

Fixed submission:
s = input()
n = len(s)
c = []
ci = ""
nowR = True
nowL = False
for i in range(n-1):
  if s[i] != s[i+1]:
    ci += s[i]
    c.append(ci)
    ci = ""
  else:
    ci += s[i]
ci += "L"
c.append(ci)
cnt = [0]*n
j = -1
for i in range(len(c)):
  if i % 2 == 0:
    # R
    cil = len(c[i])
    j += cil
    cnt[j] += cil - cil//2
    cnt[j+1] += cil//2
  else:
    # L
    cil = len(c[i])
    cnt[j] += cil//2
    cnt[j+1] += cil - cil//2
    j += cil
print(*cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(len(a) + 1)]
for i in range(len(a)):
    ri = len(a) - i
    if sum(b[::ri]) % 2 != a[ri - 1]:
        b[ri] = a[ri - 1]
b = b[1:]
print(len(str(b).split("1"))-1)
for i in range(len(b)):
    if b[i]:
        print(i + 1, end="")
        print(" ", end="")

Fixed submission:
print(3 * (int(input()) ** 2))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
escape = min(a) - 1
for i in range(len(a)):
    compare = list(a)
    compare[i] = escape
    print(max(compare))

Fixed submission:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
firstMax = max(a)
minVal = min(a)
secondMax = max(map(lambda x:x if x != firstMax else minVal, a)) if len(str(a).split(str(firstMax))) == 2 else firstMax
for i in range(len(a)):
    if a[i] < firstMax:
        print(firstMax)
    else:
        print(secondMax)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
bon = []
for i in range(n):
  ri = n - i - 1
  if sum(b[ri::ri+1]) % 2 != a[ri]:
    b[ri] = 1
    bon.append(ri+1)
for i in range(n):
  if sum(b[ri::ri+1]) % 2 != a[ri]:
    print(-1)
    exit()
print(len(bon))
print(*bon)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
bon = []
for i in range(n):
  ri = n - i - 1
  if sum(b[ri::ri+1]) % 2 != a[ri]:
    b[ri] = 1
    bon.append(ri+1)
print(len(bon))
print(*bon)
Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split())
if r - l >= 2019:
    print(0)
    exit()
minn = 2*(10**9)*2
for i in range(l, r+1):
    for j in range(i+1, r+1):
        if minn > i * j % 2019:
        minn = min(minn, i * j % 2019)
print(minn)

Fixed submission:
l, r = map(int, input().split())
if r - l >= 2019:
    print(0)
    exit()
minn = 2*(10**9)*2
for i in range(l, r+1):
    for j in range(i+1, r+1):
        minn = min(minn, i * j % 2019)
print(minn)
Buggy python submission (verdict: Runtime Error):
from franctions import gcd
a, b, c, d = map(int, input().split())
if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)
    exit()
cd_lcm = c * d // gcd(c, d)
print(b - a + 1 - (b // c - a // c) - (b // d - a // d) + (b // cd_lcm - a // cd_lcm))

Fixed submission:
from fractions import gcd
a, b, c, d = map(int, input().split())
if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)
    exit()
cd_lcm = c * d // gcd(c, d)
print(b - a + 1 - (b // c - (a-1) // c) - (b // d - (a-1) // d) + (b // cd_lcm - (a-1) // cd_lcm))

Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)
    exit()
cd_lcm = c * d // math.gcd(c, d)
print(b - a + 1 - (b // c - a // c) - (b // d - a // d) + (b // cd_lcm - a // cd_lcm))

Fixed submission:
from fractions import gcd
a, b, c, d = map(int, input().split())
if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)
    exit()
cd_lcm = c * d // gcd(c, d)
print(b - a + 1 - (b // c - (a-1) // c) - (b // d - (a-1) // d) + (b // cd_lcm - (a-1) // cd_lcm))

Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
cd_lcm = c * d // math.gcd(c, d)
l = b - a
print(l - (l // c + l // d - l // cd_lcm))

Fixed submission:
from fractions import gcd
a, b, c, d = map(int, input().split())
if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)
    exit()
cd_lcm = c * d // gcd(c, d)
print(b - a + 1 - (b // c - (a-1) // c) - (b // d - (a-1) // d) + (b // cd_lcm - (a-1) // cd_lcm))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = []
for i in range(m):
  a.append(int(input()))
# 0: 1, 1: 1, 2: 2(1+1, 2), 3: 3(1+1+1, 1+2, 2+1)
# dp[i] = dp[i-1] + dp[i-2]
dp = [0]*(n+1)
dp[0] = 1
for i in range(n):
  if i not in a:
    dp[i+1] += dp[i]
    dp[i+1] %= 10**9+7
    if i+2 != n+1:
      dp[i+2] += dp[i]
      dp[i+2] %= 10**9+7
print(dp[n])

Fixed submission:
n, m = map(int, input().split())
a = []
for i in range(m):
  a.append(int(input()))
# 0: 1, 1: 1, 2: 2(1+1, 2), 3: 3(1+1+1, 1+2, 2+1)
# dp[i] = dp[i-1] + dp[i-2]
dp = [0]*(n+1)
dp[0] = 1
for i in range(m):
  dp[a[i]] = -1
for i in range(n):
  if dp[i] == -1:
    continue
  if dp[i+1] != -1:
    dp[i+1] += dp[i]
    dp[i+1] %= 10**9+7
  if i+2 != n+1:
    if dp[i+2] != -1:
      dp[i+2] += dp[i]
      dp[i+2] %= 10**9+7
print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, n = map(int, input().split())
cnt = 0
for r in range(n//R+1):
  for g in range((n-r*R)//G+1):
    b = (n-r*R-g*G)//B
    if r * R + g*G + b*B == n:
      cnt += 1
print(cnt)

Fixed submission:
R, G, B, n = map(int, input().split())
cnt = 0
for r in range(n//R+1):
  for g in range((n-r*R)//G+1):
    b = (n-r*R-g*G)//B
    if r * R + g*G + b*B == n:
      cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, n = map(int, input().split())
cnt = 0
for r in range(n//R+1):
  for g in range((n-r*R)//G+1):
    b = (n - r * R - g * G) // B
    if r * R + g * G + b * B == n:
      cnt += 1
print(cnt)

Fixed submission:
R, G, B, n = map(int, input().split())
cnt = 0
for r in range(n//R+1):
  for g in range((n-r*R)//G+1):
    b = (n-r*R-g*G)//B
    if r * R + g*G + b*B == n:
      cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        m = n//i - 1
        if n // m == n % m:
            ans += n//i - 1
print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        m = n//i - 1
        if m != 0 and n // m == n % m:
            ans += n//i - 1
print(ans)