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

Fixed submission:
import numpy as np

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

def calc(a):
    value = a[0]
    sign = value >= 0
    result = 0
    for i in a[1:]:
        value += i
        diff = 0
        if sign and value >= 0:
            diff = value + 1
        elif not sign and value < 0:
            diff = value - 1
        result += abs(diff)
        sign = not sign
        value -= diff
        if value == 0:
            diff += sign
            value += diff
            result += diff
    return result

if a[0] == 0:
    a[0] = 1
    r1 = calc(a[:])
    a[0] = -1
    r2 = calc(a[:])
    print(min(r1, r2) + 1)
else:
    r1 = calc(a[:])
    diff = -a[0] - a[0] // abs(a[0])
    a[0] += diff
    r2 = calc(a[:]) + abs(diff)
    print(min(r1, r2))

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

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

def calc(a):
    value = a[0]
    sign = value >= 0
    result = 0
    for i in a[1:]:
        value += i
        diff = 0
        if sign and value >= 0:
            diff = value + 1
        elif not sign and value < 0:
            diff = value - 1
        result += abs(diff)
        sign = not sign
        value -= diff
        if value == 0:
            diff += sign
            value += diff
            result += diff
    return result

r1 = calc(a[:])
diff = -a[0] - a[0] // abs(a[0])
a[0] += diff
r2 = calc(a[:]) + abs(diff)
print(min(r1, r2))
Problem p03759 (python)

Fixed submission:
a, b, c = map(int, input().split())
print("YES" if b - a == c - b else "NO")

Buggy submission (verdict: Runtime Error):

print("ABC" if int(input()) < 1000 else "ABD")
Problem p03826 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
print(max(a*b, c*d))

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input.split())
print(max(a*b, c*d))
Problem p03838 (python)

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

diff = abs(y) - abs(x)

if y == 0:
    if x <= 0:
        print(-x)
        exit()
    if x >= 0:
        print(x + 1)
        exit()

result = 0
if (x >= 0) == (y >= 0):
    if x < 0 and diff > 0:
        result = 2
    if x >= 0 and diff < 0:
        result = 2
else:
    result = 1
if diff < 0:
    diff *= -1
print(result + diff)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = np.array(a)

cs_plus = np.cumsum((a > 0) * a)
cs_plus = [0] + list(cs_plus)
plus = [v2 - v1 for v1, v2 in zip(cs_plus[:-k], cs_plus[k:])]

cs_minus = np.cumsum((a < 0) * a)
cs_minus = [0] + list(cs_minus)
minus = [v2 - v1 for v1, v2 in zip(cs_minus[:-k], cs_minus[k:])]

print(cs_plus[-1] - min(min(plus), -max(minus)))
Problem p03852 (python)

Fixed submission:
print(input() in "aiueo" and "vowel" or "consonant")

Buggy submission (verdict: Runtime Error):
print(ord(input()) in "aiueo" and "vowel" or "consonant")
Problem p03866 (python)

Fixed submission:
def dist(x1, y1, x2, y2):
    return ((x1 - x2)**2 + (y1 - y2)**2)**0.5


def dist_high(index1, index2):
    return max(dist(
            xyr[index1][0],
            xyr[index1][1],
            xyr[index2][0],
            xyr[index2][1]) - (xyr[index1][2] + xyr[index2][2]), 0)


def min_value_index(array):
    min_value = float("inf")
    min_index = -1
    for i, v in array:
        if min_value > v:
            min_value = v
            min_index = i
    return min_value, min_index

stx, sty, enx, eny = map(int, input().split())
n = int(input())
xyr = [[stx, sty, 0]] + [list(map(int, input().split())) for x in range(n)] + [[enx, eny, 0]]

nodes = {x: float("inf") for x in range(len(xyr))}
nodes[0] = 0
now = 0

while now != (len(xyr) - 1):
    for i in nodes.keys():
        if i == now:
            continue

        nodes[i] = min(nodes[i], nodes[now] + dist_high(now, i))
    del nodes[now]
    now = min_value_index(nodes.items())[1]
print(nodes[n + 1])

Buggy submission (verdict: Runtime Error):
def dist(x1, y1, x2, y2):
    return pow((x1 - x2)**2 + (y1 - y2)**2, 0.5)


def dist_high(i, now):
    if i == -1 and now == -1:
        return dist(stx, sty, enx, eny)
    if now == -1:
        result = dist(stx, sty, xyr[i][0], xyr[i][1])
        result -= xyr[i][2]
    elif i == -1:
        result = dist(xyr[now][0], xyr[now][1], enx, eny)
        result -= xyr[now][2]
    else:
        result = dist(xyr[now][0], xyr[now][1], xyr[i][0], xyr[i][1])
        result -= xyr[i][2] + xyr[now][2]
    return result if result > 0 else 0


debugs = []
def debug(**args):
    debugs.append(args)
    return args["ret"]
def d():
    for i in debugs:
        print(i)


stx, sty, enx, eny = map(int, input().split())
n = int(input())
xyr = [list(map(int, input().split())) for x in range(n)]
xyr = list(sorted(xyr, key=lambda x: dist(stx, sty, x[0], x[1])))

dp = [[False for y in range(1001)] for x in range(1001)]
def calc(i, now):
    if dp[i][now] != False:
        return dp[i][now]

    if i >= n:
        return dist_high(-1, now)
    dp[i][now] = min(
            calc(i + 1, i) + dist_high(i, now),
            calc(i + 1, now)
            )
    return dp[i][now]


print(calc(0, -1))
Problem p03951 (python)

Fixed submission:
N = int(input())
a, b = input(), input()

result = 0
for i in range(N):
    if b.startswith(a[i:]):
        break
    result += 1
print(result + N)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
m = 2 * N - 1

if 2 <= K < m:
    mid = list((3, 2, 1) if K == 2 else (K - 1, K, K + 1, K - 2))
    a = list(set(range(1, m + 1)) - set(mid))
    print("Yes\n" + "\n".join(map(str, a[:m//2 - 1] + mid + a[m//2 - 1:])))
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
print("No" if K < N else "Yes\n" + "\n".join(map(str, range(1, K * 2))))
Problem p03952 (python)

Fixed submission:
N, K = map(int, input().split())
m = 2 * N - 1

if 2 <= K < m:
    mid = list((3, 2, 1) if K == 2 else (K - 1, K, K + 1, K - 2))
    a = list(set(range(1, m + 1)) - set(mid))
    print("Yes\n" + "\n".join(map(str, a[:m//2 - 1] + mid + a[m//2 - 1:])))
else:
    print("No")

Buggy submission (verdict: Runtime Error):
print("No" if K < N else "Yes\n" + "\n".join(map(str, range(1, K * 2))))
Problem p03962 (python)

Fixed submission:
print(len(set(input().split())))

Buggy submission (verdict: Runtime Error):
print len(set(input().split()))
Problem p02642 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
M = max(a)
cands = [0]*M

ans = 0
for num in a:
    if cands[num-1] >= 2:
        continue
    for i in range(num, M+1, num):
        cands[i-1] += 1
        
for num in a:
    if cands[num-1]==1:
        ans+=1
print(ans)

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

if a[0]==1:
    if a[1]==1:
        print(0)
    else:
        print(1)
else:
    ans = 0
    for num in a:
        if a.count(num) >= 2:
            continue
        else:
            cands = [i for i in a if i<=num*(1/2)]
            for cand in cands:
                if num % cand == 0:
                    break
            else:
                ans+=1
    print(ans)

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

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

if a[0]==1:
    if a[1]==1:
        print(0)
    else:
        print(1)
else:
    ans = 0
    for num in a:
        if a.count(num) >= 2:
            continue
        else:
            cands = set([i for i in a if i!=num])
            divs = set(make_divisors(num))
            if not cands&divs:
                ans+=1
            
    print(ans)

Buggy submission (verdict: Runtime Error):
import sympy

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

if a[0]==1:
    if a[1]==1:
        print(0)
    else:
        print(1)
else:
    ans = 0
    for num in a:
        if a.count(num) >= 2:
            continue
        else:
            cands = set([i for i in a if i!=num])
            divs = set(sympy.divisors(num))
            if not cands&divs:
                ans+=1
            
    print(ans)

Buggy submission (verdict: Runtime Error):
import sympy

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

if a[0]==1:
    if a[1]==1:
        print(0)
    else:
        print(1)
else:
    ans = 0
    for num in a:
        if a.count(num) >= 2:
            continue
        else:
            cands = set([i for i in a if i!=num])
            divs = set(sympy.divisors(num))
            if not cands&divs:
                ans+=1
            
    print(ans)
Problem p02801 (python)

Fixed submission:
import string

key = input()
alphabet = string.ascii_lowercase
print(alphabet[alphabet.index(key) + 1])

Buggy submission (verdict: Runtime Error):
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

def combinations_count(n, r, factorials, invs):
    return (factorials[n] * invs[n-r] * invs[r]) % (10 ** 9 + 7)
 
f = open("151_E_max01", "r")
n, k = map(int, f.readline().split())
a = sorted(list(map(int, f.readline().split())))

factorials, invs = prepare(n, 10 ** 9 + 7)

ans = 0
for i in range(n):
    if i <= n - k:
        ans -= a[i] * combinations_count(n-i-1, k-1, factorials, invs)
    
    if i >= k - 1:
        ans += a[i] * combinations_count(i, k-1, factorials, invs)
    
    ans = ans % (10 ** 9 + 7)
 
print(ans)
Problem p02804 (python)

Fixed submission:
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

def combinations_count(n, r, factorials, invs):
    return (factorials[n] * invs[n-r] * invs[r]) % (10 ** 9 + 7)
 
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))

factorials, invs = prepare(n, 10 ** 9 + 7)

ans = 0
for i in range(n):
    if i <= n - k:
        ans -= a[i] * combinations_count(n-i-1, k-1, factorials, invs)
    
    if i >= k - 1:
        ans += a[i] * combinations_count(i, k-1, factorials, invs)
    
    ans = ans % (10 ** 9 + 7)
 
print(ans)

Buggy submission (verdict: Runtime Error):
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

def combinations_count(n, r, factorials, invs):
    return (factorials[n] * invs[n-r] * invs[r]) % (10 ** 9 + 7)
 
f = open("151_E_max01", "r")
n, k = map(int, f.readline().split())
a = sorted(list(map(int, f.readline().split())))

factorials, invs = prepare(n, 10 ** 9 + 7)

ans = 0
for i in range(n):
    if i <= n - k:
        ans -= a[i] * combinations_count(n-i-1, k-1, factorials, invs)
    
    if i >= k - 1:
        ans += a[i] * combinations_count(i, k-1, factorials, invs)
    
    ans = ans % (10 ** 9 + 7)
 
print(ans)
Problem p02814 (python)

Fixed submission:
# coding: utf-8
# Your code here!
 
import fractions
 
n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))
 
for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = fractions.gcd(gcd, numbers[i])
        lcm = (lcm * numbers[i]) // fractions.gcd(lcm, numbers[i])
 
if (lcm//gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm // 2
    print((m - init_num) // lcm + 1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import fractions

n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))

for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = fractions.gcd(gcd, numbers[i])
        lcm = int(lcm * numbers[i] / fractions.gcd(lcm, numbers[i]))

if int(lcm/gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm / 2
    print(int(m - init_num) // lcm + 1)

Buggy submission (verdict: Runtime Error):
import math

n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))

for i in range(len(numbers)):
    if i == 0:
        gcd = numbers[i]
        lcm = numbers[i]
    else:
        gcd = math.gcd(gcd, numbers[i])
        lcm = int(lcm * numbers[i] / math.gcd(lcm, numbers[i]))

if int(lcm/gcd) % 2 == 0:
    print(0)
else:
    init_num = lcm / 2
    print(int(m - init_num) // lcm + 1)

Buggy submission (verdict: Runtime Error):
import fractions

n, m = map(int, input().split(" "))
numbers = list(set(map(int, input().split(" "))))

for i in range(len(numbers)):
    if i == 0:
        a = numbers[i]
    else:
        a = fractions.gcd(a, numbers[i])

lcm = a
for i in range(len(numbers)):
    lcm *= int(numbers[i] / a)

if int(lcm/a) % 2 == 0:
    print(0)
else:
    init_num = lcm / 2
    print(int((m - init_num) // lcm) + 1)
Problem p02911 (python)

Fixed submission:
n, k, q = map(int, input().split())
points = [k-q]*n

for i in range(q):
    points[int(input())-1] += 1

for i in range(n):
    if points[i] > 0:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
n, k, q = map(int, input().split())
points = [k-q]*n

for i in range(q):
    points[int(input())-1] += 1

for i in range(q):
    if points[i] > 0:
        print("Yes")
    else:
        print("No")
Problem p02600 (python)

Fixed submission:
n = int(input())
if n <= 599:
    print(8)
    exit()

if n <= 799:
    print(7)
    exit()

if n <= 999:
    print(6)
    exit()

if n <= 1199:
    print(5)
    exit()

if n <= 1399:
    print(4)
    exit()

if n <= 1599:
    print(3)
    exit()

if n <= 1799:
    print(2)
    exit()

if n <= 1999:
    print(1)
    exit()

Buggy submission (verdict: Runtime Error):
n = int(input()):
if n <= 599:
    print(8)
    exit()

if n <= 799:
    print(7)
    exit()

if n <= 999:
    print(6)
    exit()

if n <= 1199:
    print(5)
    exit()

if n <= 1399:
    print(4)
    exit()

if n <= 1599:
    print(3)
    exit()

if n <= 1799:
    print(2)
    exit()

if n <= 1999:
    print(1)
    exit()
Problem p02641 (python)

Fixed submission:
x,n = map(int,input().split())
l = list(map(int,input().split()))
s = set(l)
o = []
d = {}
for i in range(-1000,1000):
    if i not in s:
        g = abs(i-x)
        o.append(g)
        if g in d:
            h = d[g]
            h.append(i)
            d[g] = h

        else:
            d[g] = [i]

o.sort()
k = o[0]
n = d[k]
n.sort()
print(n[0])

Buggy submission (verdict: Runtime Error):
x,n = map(int,input().split())
l = list(map(int,input().split()))
s = set(l)
o = []
d = {}
for i in range(1,101):
    if i not in s:
        g = abs(i-x)
        o.append(g)
        if g in d:
            h = d[g]
            h.append(i)
            d[g] = h

        else:
            d[g] = [i]

o.sort()
k = o[0]
n = d[k]
n.sort()
print(n[0])
Problem p03163 (python)

Fixed submission:
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0]*(w+1) for _ in range(n+1)]
for i in range(n):
    w_, v_ = wv[i]
    for j in range(w+1):
        if j < w_:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j-w_]+v_, dp[i][j])
print(dp[n][w])

Buggy submission (verdict: Runtime Error):
n,w = map(int,input().split())
d = {}
p = []
for i in range(n):
    k,v = map(int,input().split())
    d[k] = v
    p.append(k)

dp = []
for i in range(n+1):
    o = []
    for j in range(w+1):
        o.append(0)

    dp.append(o)


for i in range(n):
    for j in range(w+1):
        if p[i] > j:
            dp[i+1][j] = dp[i][j]

        else:
            dp[i+1][j] = max(d[p[i]] + dp[i][j - p[i]], dp[i][j])

print(dp[n][w])n,w = map(int,input().split())
d = {}
p = []
for i in range(n):
    k,v = map(int,input().split())
    d[k] = v
    p.append(k)

dp = []
for i in range(n+1):
    o = []
    for j in range(w+1):
        o.append(0)

    dp.append(o)


for i in range(n):
    for j in range(w+1):
        if p[i] > j:
            dp[i+1][j] = dp[i][j]

        else:
            dp[i+1][j] = max(d[p[i]] + dp[i][j - p[i]], dp[i][j])

print(dp[n][w])
Problem p02719 (python)

Fixed submission:
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

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

## Logic

print(min(N%K,abs(K-N%K)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

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

## Logic

print(min(N%K,abs(K-N%K))
Problem p02732 (python)

Fixed submission:
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]


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

C = [0]*(2*10**5+1)

for i in A:
    C[i] += 1

ans = sum(i*(i-1)//2 for i in C)

for i in A:
    print(ans-C[i]+1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

# 0 0
# 1 0
# 2 1
# 3 3
# 4 6

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

C = [0]*(2*10**5+1)

for i in A:
    l[i] += 1

ans = sum(i*(i-1)//2 for i in l)

for i in A:
    print(ans-l[i]+1)
Problem p02993 (python)

Fixed submission:
# -*- coding: utf-8 -*-

S=input()

ans = 'Good'

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3] :
    ans = 'Bad'

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

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

ans = 0
for i in range(N):
    ans = ans + L + i

if L > 0:
    ans = ans - L
if (L + N - 1) < 0:
    ans = ans - (L + N - 1)

print(ans)
Problem p02994 (python)

Fixed submission:
# -*- coding: utf-8 -*-

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

ans = 0
for i in range(N):
    ans = ans + L + i

if L > 0:
    ans = ans - L
if (L + N - 1) < 0:
    ans = ans - (L + N - 1)

print(ans)

Buggy submission (verdict: Runtime Error):
(L + N - 1)
Problem p02995 (python)

Fixed submission:
# -*- coding: utf-8 -*-

from fractions import gcd
from math import ceil,floor

A,B,C,D=map(int, input().split())

Cans = B//C - (A-1)//C
Dans = B//D - (A-1)//D

CD = C * D // gcd(C,D)
CDans = B//CD - (A-1)//CD

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import fractions

A,B,C,D=map(int, input().split())

ans = 0

Cans = fractions.floor(B/C) - fractions.ceil(A/C) + 1
Dans = fractions.floor(B/D) - fractions.ceil(A/D) + 1

CD = C * D / fractions.gcd(C,D)
CDans = fractions.floor(B/CD) - fractions.ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

A,B,C,D=map(int, input().split())

ans = 0

Cans = math.floor(B/C) - math.ceil(A/C) + 1
Dans = math.floor(B/D) - math.ceil(A/D) + 1

CD = C * D / math.gcd(C,D)
CDans = math.floor(B/CD) - math.ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

A,B,C,D=map(int, input().split())

ans = 0

Cans = math.floor(B/C) - math.ceil(A/C) + 1
Dans = math.floor(B/D) - math.ceil(A/D) + 1

CD = C * D / math.gcd(C,D)
CDans = math.floor(B/CD) - math.ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)
Problem p03419 (python)

Fixed submission:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
N,M=map(int, input().split())

if N==1 and M==1:
    print(1)
    sys.exit()

if N==1:
    print(M-2)
    sys.exit()

if M==1:
    print(N-2)
    sys.exit()

print((N-2)*(M-2))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
N,M=map(int, input().split())

if N==1 and M==1:
    print(0)
    sys.exit()

if N==1 and M==2:
    print(2)
    sys.exit()

if N==2 and M==1:
    print(2)
    sys.exit()

if N==1:
    print(M-2)
    sys.exit()

if M==1:
    print(N-2)
    sys.exit()

print((N-2)*(M-2))

oo