Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03000 (python)

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

l = list(map(int,input().split()))

cnt = 1
dis = 0

for i in l:
    dis += i
    if dis > x:
        break
    cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
n,x = map(int,input().split())

l = list(map(int,input().split()))

dis = 0
i = 0

while True:
    dis += l[i]
    
    if dis > x:
        break
    i += 1

print(i+1)

Buggy submission (verdict: Runtime Error):
n,x = map(int,input().split())

l = list(map(int,input().split()))

dis = 0
i = 0

while dis <= x:
    dis += l[i]
    i += 1

print(i)
Problem p03109 (python)

Fixed submission:
S = list(map(int,input().split('/')))

if S[1] > 4 :
  print('TBD')
else:
  print('Heisei')

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

x = b // a

if x <= c:
	print(x)

else:
	print(c)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

x = b // a

if x <= c:
	print(x)

else:
	print(c)
Problem p03163 (python)

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

items = [list(map(int,input().split())) for i in range(n)]

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

for i in range(n):
    for j in range(w+1):
        if j >= items[i][0]:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-items[i][0]] + items[i][1])
            
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[n][w])

Buggy submission (verdict: Runtime Error):
import numpy as np

n, w = map(int, input().split())
l = [list(map(int,input().split())) for i in range(n)]


dp = np.zeros((n + 1, w + 1), dtype=np.int64)

for i in range(n):
    tmp = np.zeros(w + 1, dtype=int)
    tmp[l[i][0]:] = dp[i][:-l[i][0]] + l[i][1]
    dp[i + 1] = np.maximum(dp[i], tmp)
    
print(dp[n][w])
Problem p03262 (python)

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

cities = list(map(int,input().split()))

cities.append(K)

cities.sort()

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

dif = []

for i in range(N):
	dif.append(cities[i+1] - cities[i])
    

if len(dif) == 1:
	x = dif[0]

else:
    
	x = gcd(dif[0],dif[1])

	for i in range(2,N):
		x = gcd(x,dif[i])

print(x)

Buggy submission (verdict: Runtime Error):
import sympy

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

cities = list(map(int,input().split()))

cities.append(K)

cities.sort()

dif = []

for i in range(N):
	dif.append(cities[i+1] - cities[i])
    

if len(dif) == 1:
	x = dif[0]

else:
    
	x = sympy.gcd(dif[0],dif[1])

	for i in range(2,N):
		x = sympy.gcd(x,dif[i])

print(x)

Buggy submission (verdict: Runtime Error):
import sympy

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

cities = list(map(int,input().split()))

cities.append(K)

cities.sort()

dif = []

for i in range(N):
    dif.append(cities[i+1] - cities[i])
    

if len(dif) == 1:
    x = dif[0]

else:
    
    x = sympy.gcd(dif[0],dif[1])

    for i in range(2,N):
        x = sympy.gcd(x,dif[i])

print(x)
Problem p03264 (python)

Fixed submission:
k = int(input())

c=0

for i in range(1,k+1):
	for j in range(1,k+1):
		if i % 2 ==0:
			if j % 2 == 1:
				c += 1
print(c)

Buggy submission (verdict: Runtime Error):
k = int(input())

c=0

for i in range(1,k+1):
	for j in range(1,K+1)
		if i % 2 ==0:
			if j % 2 == 1:
				c += 1
print(c)
Problem p03282 (python)

Fixed submission:
S = int(input())
K = int(input())

lst = []
while S > 0:
    lst.append(S%10)
    S //= 10 
lst.reverse()

if len(lst) == lst.count(1):
	print(1)

elif K == lst[:K].count(1):
	print(1)
  
else:
	for i in range(K):
		if lst[i] != 1:
			print(lst[i])
			break

Buggy submission (verdict: Runtime Error):
S = list(map(int,input().split()
print(S)
Problem p03324 (python)

Fixed submission:
d, n = map(int, input().split())
 
if d == 0:
    if n != 100:
        print(n)
    else:
        print(n + 1)
elif d == 1:
    if n != 100:
        print(n * 100)
    else:
        print(n * 100 + 100)
else:
    if n != 100:
        print(n * 10000)
    else:
        print(n * 10000 + 10000)

Buggy submission (verdict: Runtime Error):
d, n = map(int, input().split())
 
if d == 0:
    if n != 100:
        print(n)
    else:
        print(n + 1)
elif d == 1:
    if n != 100:
        print(n * 100)
    else:
        print(n * 100 + 100)
else:
    if n != 100:
        print(n * 10000)
    else:
        print(n * 10000 + 10000)
d, n = map(int, input().split())

if d == 0:
    if n != 100:
        print(n)
    else:
        print(n + 1)
elif d == 1:
    if n != 100:
        print(n * 100)
    else:
        print(n * 100 + 100)
else:
    if n != 100:
        print(n * 10000)
    else:
        print(n * 10000 + 10000)

Buggy submission (verdict: Runtime Error):
d, n = map(int, input().split())
 
if d == 0:
    if n != 100:
        print(n)
    else:
        print(n + 1)
elif d == 1:
    if n != 100:
        print(n * 100)
    else:
        print(n * 100 + 100)
else:
    if n != 100:
        print(n * 10000)
    else:
        print(n * 10000 + 10000)
d, n = map(int, input().split())

if d == 0:
    if n != 100:
        print(n)
    else:
        print(n + 1)
elif d == 1:
    if n != 100:
        print(n * 100)
    else:
        print(n * 100 + 100)
else:
    if n != 100:
        print(n * 10000)
    else:
        print(n * 10000 + 10000)
提出情報
Problem p03328 (python)

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


print(int((b-a)*(b-a+1)/2-b))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())

c = 0

def sigma(x):
	if x <= 0:
		return x
	return x + sigma(x-1)
  
for i in range(1,1000):
	c += 1
	if sigma(i) > a:
		break
        
print(sigma(c) - a)
Problem p03424 (python)

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


y_n = s.count('Y')

if y_n == 0:
	print('Three')  
else:
	print('Four')

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(map(str,input().split()))

print(s)


if y_n == 0:
	print('Three')  
else:
	print('Four')
Problem p03611 (python)

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

ans = [0 for i in range(2*10**5+2)]

for i in a:
    ans[i-1] += 1
    ans[i] += 1
    ans[i+1] += 1
    
print(max(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())

seq = list(map(int,input().split()))

unique = []

seq = sorted(seq)
c = 0
k = seq[0]

for i in seq:
    if not i in unique:
        unique.append(i)

unique_n = [0]*len(unique)

for i in seq:
    if i == k:
        unique_n[c] += 1
    
    else:
        c += 1
        unique_n[c] += 1





if n == 1:
    print(1)

elif n == 2:
    if max(seq) - min(seq) <= 2:
        print(2)
    
    else:
        print(1)

else:
    max_n = 0
    
    for i in range(1,len(unique)-2):
        cnt = 0
        cnt += unique_n[i-1]
        cnt += unique_n[i]
        cnt += unique_n[i+1]
    
        if cnt > max_n:
            max_n = cnt

    
    print(max_n)
Problem p03625 (python)

Fixed submission:
n = int(input())

length = list(map(int,input().split()))

length = sorted(length)
length.append(0)

temp = length[0]
c = 1

unique_n = []
square = []

for i in range(n):
    if temp == length[i+1]:
        c += 1
    
    else:
        if c >= 2 :
            unique_n.append(length[i-1])
        
        if c >= 4:
            square.append(length[i-1])
            
        
        c = 1
        temp = length[i+1]

if len(unique_n) <= 1:
    print(0)

else:
    if len(square) >= 1:
        print(max(unique_n[-1]*unique_n[-2],(square[-1])**2))
    
    else:
        print(unique_n[-1]*unique_n[-2])

Buggy submission (verdict: Runtime Error):
n = int(input())

length = list(map(int,input().split()))

length = sorted(length)
length.append(0)

temp = length[0]
c = 1

unique_n = []
square = []

for i in range(n):
    if temp == length[i+1]:
        c += 1
    
    else:
        if c >= 2 :
            unique_n.append(length[i-1])
        
        if c >= 4:
            square.append(length[i-1])
            
        
        c = 1
        temp = length[i+1]

if len(unique_n) <= 1:
    print(0)

else:
    print(max(unique_n[-1]*unique_n[-2],(square[-1])**2))
Problem p03659 (python)

Fixed submission:
n = int(input())

l = list(map(int,input().split()))

l.reverse()

x = 0

sum_x = []

for i in range(n-1):
    x += l[i]
    sum_x.append(x)

sum_y = [sum(l)]*(n-1)

for i in range(n-1):
    sum_y[i] -= sum_x[i]
    
abs_xy = []

for i in range(n-1):
    abs_xy.append(abs(sum_x[i]-sum_y[i]))

print(min(abs_xy))

Buggy submission (verdict: Runtime Error):
n = int(input())

l = list(map(int,input().split()))

l.reverse()

x = 0

sum_x = []

for i in range(n-1):
    x += l[i]
    sum_x.append(x)

sum_y = [sum(l)]*(n-1)

for i in range(n-1):
    sum_y[i] -= sum_x[i]
    
abs_xy = []

for i in range(n-1):
    abs_xy.append(abs(sum_x[i]-sum_y[i]))

print(min(abs_xy))
Problem p03695 (python)

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

color_n = [0 for i in range(9)]

for i in a:
    if 1 <= i <= 399:
        color_n[0] += 1
    
    elif 400 <= i <= 799:
        color_n[1] += 1
    
    elif 800 <= i <= 1199:
        color_n[2] += 1
    
    elif 1200 <= i <= 1599:
        color_n[3] += 1
    
    elif 1600 <= i <= 1999:
        color_n[4] += 1
    
    elif 2000 <= i <= 2399:
        color_n[5] += 1
    
    elif 2400 <= i <= 2799:
        color_n[6] += 1
    
    elif 2800 <= i <= 3199:
        color_n[7] += 1
    
    else:
        color_n[8] += 1

print(max(8-color_n[:-1].count(0), 1),8-color_n[:-1].count(0)+color_n[-1])

Buggy submission (verdict: Runtime Error):
n = int(input())

colors = list(map(int,input().split()))

col_n = [0]*9

for c in colors:
    if c >= 1 and c <= 399:
        col_n[0] += 1
    elif c >= 400 and c <= 799:
        col_n[1] += 1
    elif c >= 800 and c <= 1199:
        col_n[2] += 1
    elif c >= 1200 and c <= 1599:
        col_n[3] += 1
    elif c >= 1600 and c <= 1999:
        col_n[4] += 1
    elif c >= 2000 and c <= 2399:
        col_n[5] += 1
    elif c >= 2400 and c <= 2799:
        col_n[6] += 1
    elif c >= 2800 and c <= 3199:
        col_n[7] += 1
    else:
        col_n[8] += 1

if col_n[8] == 0:
    print(8-col_n[:8].count(0),8-col_n[:8].count(0))

else:
    if 8-col_n[:8].count(0) >= col_n[8]:
        print(8-col_n[:8].count(0),(8-col_n[:8].count(0)+col_n[8]))
    
    else:
        print(col[8],(8-col_n[:8].count(0))+col_n[8])
Problem p03828 (python)

Fixed submission:
import math

n = int(input())

prime_n = [2]

for i in range(3,n+1,2):
    if all( i % prime != 0 for prime in prime_n):
        prime_n.append(i)

multiply = []

for i in prime_n:
    k = 1
    temp = 0
    while i**k <= n:
        temp += math.floor(n/(i**k))
        k+=1
    
    multiply.append(temp)

ans = 1

for i in multiply:
    ans*=(i+1)
    ans%=((10**9)+7)

print(ans)

Buggy submission (verdict: Runtime Error):
for i in range(1, n+1):
    while i % 2 == 0:
        if not 2 in divisor_dic:
            divisor_dic[2] = 1
        else:
            divisor_dic[2] += 1
        i //= 2
    f = 3
    while f*f <= i:
        if i % f ==0:
            if not f in divisor_dic:
                divisor_dic[f] = 1
            else:
                divisor_dic[f] += 1
        
            i //= f
        
        else:
            f += 2
    
    if i != 1:
        if not i in divisor_dic:
            divisor_dic[i] = 1
        else:
            divisor_dic[i] += 1
                
c = 1          
for v in divisor_dic.values():
    c *= (v+1)
    c %= 10**9+7

print(c)
Problem p03951 (python)

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

for i in range(n):
   if s[i:] == t[:n-i]:
       print(n+i)
       exit()

print(2*n)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
s = input()
t = input()

for i in range(n):
   if s[i:] == t[:n-i]:
		print(n+i)
		exit()

print(2*n)
Problem p02630 (python)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
Q = int(input())
bc = [[int(i) for i in input().split()] for j in range(Q)]
 
counter = [0] * 1000000
for i in a:
    counter[i] += 1

ans = sum(a)
 
for _ in bc:
    ans = ans + counter[_[0]] * _[1] - counter[_[0]] * _[0]
    counter[_[1]] += counter[_[0]]
    counter[_[0]] = 0
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
Q = int(input())
bc = [[int(i) for i in input().split()] for j in range(Q)]

counter = [0] * 100000
for i in a:
    counter[i] += 1

ans = sum(a)

for _ in bc:
    ans = ans + counter[_[0]] * _[1] - counter[_[0]] * _[0]
    counter[_[1]] += counter[_[0]]
    counter[_[0]] = 0
    print(ans)
Problem p02780 (python)

Fixed submission:
N,K = map(int, input().split())
l = list(map(int,input().split()))
 
def E(n):
  return (1 + n) / 2
 
j = sum(l[0:0+K])
m = 0
if N == 1:
  l2 = list(map(E, l))
  print(sum(l2))
elif N == K:
  l2 = list(map(E, l))  
  print(sum(l2))
else:
  for i in range(1,len(l)-(K-1)):
      j = j - l[i-1] + l[i+K-1]
      if l[i] < l[i-1]:
          continue
      elif m < j:
          m = j
          t = l[i:i+K]

  l2 = list(map(E, t))
 
  print(sum(l2))

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())
l = list(map(int,input().split()))

def E(n):
  return sum(range(1,n+1)) / n

j = sum(l[0:0+K])
m = 0
if N == 1:
  l2 = list(map(E, l))
  print(sum(l2))
  
else:
  for i in range(1,len(l)-(K-1)):
      j = j - l[i-1] + l[i+K-1]
      if l[i] < l[i-1]:
          continue
      elif m < j:
          m = j
          t = l[i:i+K]

  l2 = list(map(E, t))

  print(sum(l2))

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())
l = list(map(int,input().split()))

j = sum(l[0:0+K])
m = 0
for i in range(1,len(l)-(K-1)):
    j = j - l[i-1] + l[i+K-1]
    if l[i] < l[i-1]:
        continue
    elif m < j:
        m = j
        t = l[i:i+K]
        
def E(n):
    return sum(range(1,n+1)) / n

l2 = list(map(E, t))

print(sum(l2))

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())
l = list(map(int,input().split()))

j = sum(l[0:0+K])
m = 0
for i in range(1,len(l)-(K-1)):
    j = j - l[i-1] + l[i+K-1]
    if l[i] =< l[i-1]:
        continue
    elif m < j:
        m = j
        t = l[i:i+K]
        
def E(n):
    return sum(range(1,n+1)) / n

l2 = list(map(E, t))

print(sum(l2))
Problem p02924 (python)

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

Buggy submission (verdict: Runtime Error):
N = int(input())
print(sum(list(range(0,N))))
Problem p02934 (python)

Fixed submission:
N = int(input())
l = list(map(int,input().split()))
 
total = 0
for i in l:
  total += 1/i

print(1/total)

Buggy submission (verdict: Runtime Error):
N = int(input())
l = map(int, raw_input().split())
l = [int(s) for s in l]

total = 0
for i in l:
  total += 1/i

print(1/total)
Problem p02945 (python)

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

print(max([l[0]+l[1],l[0]-l[1],l[0]*l[1]]))

Buggy submission (verdict: Runtime Error):
import collections
import math
 
N = int(input())
words = [input() for i in range(N)] 
 
ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))
 
c = collections.Counter(L)
 
for i in c.values():    
    ans += factorial(i) / factorial(2) / factorial(i - 2)
 
print(int(ans))
import collections
from math import factorial

N = int(input())
words = [input() for i in range(N)] 

ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))

c = collections.Counter(L)

for i in c.values():    
    ans += math.factorial(i) / math.factorial(2) / math.factorial(i - 2)

print(int(ans))
提出情報
Problem p02947 (python)

Fixed submission:
N = int(input())
dic = {}

for i in range(N):
    spell = ''.join(sorted(input()))
    if spell in dic.keys():
        dic[spell] += 1
    else:
        dic[spell] = 1

count = 0
for num in dic.values():
    count += sum([i for i in range(num)])

print(count)

Buggy submission (verdict: Runtime Error):
import collections
import math
 
N = int(input())
words = [input() for i in range(N)] 
 
ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))
 
c = collections.Counter(L)
 
for i in c.values():    
    ans += math.factorial(i) / math.factorial(2) / math.factorial(i - 2)
 
print(int(ans))

Buggy submission (verdict: Runtime Error):
import collections
from math import factorial

N = int(input())
words = [input() for i in range(N)] 

ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))

c = collections.Counter(L)

for i in c.values():    
    ans += factorial(i) / factorial(2) / factorial(i - 2)

print(int(ans))

Buggy submission (verdict: Runtime Error):
import collections
from scipy.special import comb

N = int(input())
words = [input() for i in range(N)] 

ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))

c = collections.Counter(L)

for i in c.values():
    ans += comb(i, 2, exact=True)

print(ans)
Problem p03037 (python)

Fixed submission:
n,m=map(int,input().split())
low=1
high=n
for i in range(m):
	l,r=map(int,input().split())
	low = max(low,l)
	high=min(high,r)
ans=high-low+1
print(ans if ans>=0 else 0)

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for m in range(m)]

a = range(table[0][0],table[0][1]+1)
for i,t in enumerate(table[1:]):
    if i == 0:
    	b = range(t[0], t[1]+1)
    	ans = set(a) & set(b)
    else:
        b = range(t[0], t[1]+1)
        ans = ans & set(b)
print(len(ans))

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for m in range(m)]

a = range(table[0][0],table[0][1]+1)
for i,t in enumerate(table[1:]):
    if i == 0:
    	b = range(t[0], t[1]+1)
    	ans = set(a) & set(b)
    else:
        b = range(t[0], t[1]+1)
        ans = ans & set(b)
print(len(ans))
Problem p03262 (python)

Fixed submission:

N, X = map(int, input().split())
l = list(map(int, input().split()))

l.insert(0, X)
diff_list = [0] * (int(len(l)/2) + 1)

ans = abs(l[0] - l[1])
ix = 2

#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

for i in l[1:len(l)-1]:
    tmp = abs(i - l[ix])
    ans = gcd(ans, tmp)
    ix += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math 
N, X = map(int, input().split())
l = list(map(int, input().split()))

l.insert(0, X)
diff_list = [0] * (int(len(l)/2) + 1)

ans = abs(l[0] - l[1])
ix = 2
for i in l[1:len(l)-1]:
    tmp = abs(i - l[ix])
    ans = math.gcd(ans, tmp)
    ix += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

N, X = map(int, input().split())
l = list(map(int, input().split()))

l.insert(0, X)
diff_list = [0] * (int(len(l)/2) + 1)

for ix,i in enumerate(l[1:]):
    diff_list.append(abs(l[ix] - i))

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(diff_list))
Problem p03325 (python)

Fixed submission:
import math
n = int(input())
a = list(map(int,input().split()))

ans = 0
for i in a:
  if i%2==0:
    while(i%2==0):
      i = i//2
      ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
g_c = sum([1 for i in a if i%2==0]) 
ans = 0
for i in a:
  if i%2==0:
    while(i%2==0):
      i = i//2
      ans += 1
print(c)
Problem p03361 (python)

Fixed submission:
N, M = map(int,input().split()) 
p = [input() for i in range(N)]

ans = "Yes"
for n in range(1,N-1):
    for m in range(1,M-1):
        if p[n][m] == '#':
            if p[n-1][m] != "#" and p[n][m-1] != "#" and p[n+1][m] != "#" and p[n][m+1]!= "#":
                ans = "No"
                break
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split()) 
P = [input().split() for i in range(M)]

ans = "Yes"
for n in range(N):
    for m in range(M):
        if p[n][m] == '#':
            if p[n-1][m] == "." and p[n][m-1] == "." and p[n+1][m] == "." and p[n][m+1] == ".":
                ans = "No"
                break
print(ans)
Problem p03387 (python)

Fixed submission:
x = sorted(list(map(int, input().split())))
ans = 0
if x[0]%2==x[1]%2:
    ans += (x[1] - x[0])//2
    ans += (x[2] - x[1])
else:
    ans += 1
    ans += (x[1] - x[0] + 1)//2
    ans += (x[2] - x[1])
print(ans)

Buggy submission (verdict: Runtime Error):
x = sort(list(map(int, input().split())))
ans = 0
if x[0]%2==x[1]%2:
    ans += (x[1] - x[0])//2
    ans += (x[2] - x[1])
else:
    ans += 1
    ans += (x[1] - x[0] + 1)//2
    ans += (x[2] - x[1])
print(ans)
Problem p03681 (python)

Fixed submission:
import math

n,m = map(int,input().split())

rev = 10**9+7

if n-m==0:
    ans = 2 * math.factorial(n) * math.factorial(m)
elif (abs(n-m)==1):
    ans = 1 * math.factorial(n) * math.factorial(m)
else:
    ans = 0
print(ans%rev)

Buggy submission (verdict: Runtime Error):
import math

n,m = map(int,input().split())

rev = 10**9+7

if n-m==0:
    ans = 2 * math.factorial(n) * math.factorial(m)
elif (abs(n-m)==1):
    ans = 1 * math.factorial(n) : math.factorial(m)
else:
    ans = 0
print(ans%rev)
Problem p02995 (python)

Fixed submission:
import fractions

a, b, c, d = list(map(int, input().split()))


def lcm(a, b):
    return (a * b) // fractions.gcd(a, b)


def ans(x):
    can_div_c_count = x // c
    can_div_d_count = x // d
    can_div_lcm_count = x // lcm(c, d)
    return x - (can_div_c_count + can_div_d_count - can_div_lcm_count)


print(ans(b)-ans(a-1))

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = list(map(int, input().split()))


def lcm(a, b):
    return (a * b) // math.gcd(a, b)


def ans(x):
    can_div_c_count = x // c
    can_div_d_count = x // d
    can_div_lcm_count = x // lcm(c, d)
    return x - (can_div_c_count + can_div_d_count - can_div_lcm_count)


print(ans(b)-ans(a))