Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    r, g, b, n = map(int, input().split())

    count = 0
    for i in range((n+(r-1))//r+1):
        for j in range((n+(g-1))//g+1):
            for k in range((n+(b-1))//b+1):
                if (i*r)+(j*g)+(k*b) == n:
                    count += 1
    print(count)
          
 

if __name__=='__main__':
    main()

Fixed submission:
def main():
    r, g, b, n = map(int, input().split())

    count = 0

    for i in range(3001):
        for j in range(3001):
            v = (i*r) + (j*g) 
            if n >= v and (n-v)%b == 0: 
                count += 1



    print(count)
                

if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    S = input()

    count = 0
    max_ = 0

    for i in range(N):
        x = set(S[:i])
        y = set(S[i:])

        max_ = max(len(x&y), max_)

    print(max_)


if __name__=='__main__':
    main()

Fixed submission:
def main():
    a, b = map(int, input().split())
    print(max(a+b, max(a-b,a*b)))

if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()

day = int(a)-1
if b >= a:
	day += 1
print(day)


Fixed submission:
if __name__=='__main__':
    a, b = map(int, input().split())

    day = int(a)-1
    if b >= a:
        day += 1
    print(day)

Buggy python submission (verdict: Runtime Error):
if __name__=='__main__':
    a = input()
    b = input()

    day = int(a)-1
    if b >= a:
        day += 1
    print(day)

Fixed submission:
if __name__=='__main__':
    a, b = map(int, input().split())

    day = int(a)-1
    if b >= a:
        day += 1
    print(day)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
for i in range(n):
    y = x[:]
    y[i] = 0
    y = list(sorted(y))
    s = n // 2
    print(y[-s])

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
y = sorted(x[:])
for i in x:
    s = n // 2
    ss= y[-s]
    if i >= ss:
        print(y[-(s+1)])
    else:
        print(y[-s])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
for i in range(n):
    y = x[:]
    y.pop(i)
    y = list(sorted(y))
    s = n // 2
    print(y[-s])

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
y = sorted(x[:])
for i in x:
    s = n // 2
    ss= y[-s]
    if i >= ss:
        print(y[-(s+1)])
    else:
        print(y[-s])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
 
for y in range(1, N+1):
    hold = A[y]
    A.pop(y)
    price = 0
    
    for x in range(len(A)-1):
        price += abs(A[x+1] - A[x])
    price += abs(A[-1])
    print(price)
    A.insert(y, hold)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
A.append(0)
price = 0
for x in range(n+1):
    price += abs(A[x+1]-A[x])
for x in range(1, n+1):
    s = price
    s = s + abs(A[x-1]-A[x+1]) - (abs(A[x-1]-A[x])+abs(A[x]-A[x+1]))
    print(s)

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

def list_set(a,y):
    B = list(a)
    B.pop(y)
    B.insert(0, 0)
    return B
 
 
for y in range(N):
    a = list_set(A,y)
    price = 0
    
    for x in range(len(a)-1):
        price += abs(a[x+1] - a[x])
    price += abs(a[-1])
    print(price)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
A.append(0)
price = 0
for x in range(n+1):
    price += abs(A[x+1]-A[x])
for x in range(1, n+1):
    s = price
    s = s + abs(A[x-1]-A[x+1]) - (abs(A[x-1]-A[x])+abs(A[x]-A[x+1]))
    print(s)

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

for y in range(N):
    price = 0
    a.pop(y)
    a.insert(0,0)
    hold_max = a[0]
    hold_min = a[0]
    for x in range(len(a)):
        if a[x] > 0 and a[x] > hold_max:
            price += a[x] - hold_max
            hold_min = 0
            hold_max = a[x]
        elif a[x] < 0 and a[x] < hold_min:
            price += abs(a[x]) - abs(hold_min)
            hold_max = 0
            hold_min = a[x]
        else:
            continue
    print(price*2)
    a = list(A)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
A.append(0)
price = 0
for x in range(n+1):
    price += abs(A[x+1]-A[x])
for x in range(1, n+1):
    s = price
    s = s + abs(A[x-1]-A[x+1]) - (abs(A[x-1]-A[x])+abs(A[x]-A[x+1]))
    print(s)

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



for y in range(N):
    a.pop(y)
    a.insert(0, 0)
    price = 0
    for x in range(len(a)-1):
        price += abs(a[x+1] - a[x])
    price += abs(a[-1])
    print(price)
    a = list(A)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
A.append(0)
price = 0
for x in range(n+1):
    price += abs(A[x+1]-A[x])
for x in range(1, n+1):
    s = price
    s = s + abs(A[x-1]-A[x+1]) - (abs(A[x-1]-A[x])+abs(A[x]-A[x+1]))
    print(s)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = input().split()
l = set(l)
length = len(l)

if length == 4:
    print("Four")
else:
    print("Three")

Fixed submission:
print(int(input())//3)
Buggy python submission (verdict: Time Limit Exceeded):
X, Y = map(int, input().split())

for x in range(1, 10**18):
    if x % X == 0:
        if x % Y != 0:
            ans = x
            break
        else:
            ans = -1
print(ans)

        

Fixed submission:
X,Y = map(int, input().split())

if X % Y == 0:
    print(-1)
else:
    print(X)
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
total = 0
for x in range(n+1):
    X = [int(x) for x in list(str(x))]
    sum_x = sum(X)
    if a <= sum_x <= b:
        total += x
print(total)

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

if (A+B) > (C+D):
    print("Left")
elif (A+B) < (C+D):
    print("Right")
else:
    print("Balanced")

Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input())

if (A+B) > (C+D):
    print("Left")
elif (A+B) < (C+D):
    print("Right")
else:
    print("Balanced")

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

if (A+B) > (C+D):
    print("Left")
elif (A+B) < (C+D):
    print("Right")
else:
    print("Balanced")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n, k = map(int, input().split())
a = list(input().split())
counter = Counter(a)
count = 0
while len(counter) > k:
    max_c = min(counter.values())
    for name, cnt in counter.most_common():
        if cnt == max_c:
            count += cnt
            counter.pop(name)
            break
print(count)

Fixed submission:
from collections import Counter
n, k = map(int, input().split())
a = list(input().split())
len_a = len(set(a))
if len_a <= k:
    print(0)
else:
    counter = Counter(a)
    count = 0
    s = len_a - k
    sort_counter = sorted(counter.items(), key=lambda  x:x[1])
    for x in range(s):
        count += sort_counter[x][1]
    print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
x = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if a[i] < b[j] < c[k]:
                x += 1
print(x)

Fixed submission:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans = 0
for i in b:
    aa = bisect.bisect_left(a, i)
    cc = n-bisect.bisect_right(c, i)
    ans += aa*cc
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d,e,f = map(int, input().split())

sugar = []
for i in range(0, f+1):
    for j in range(0, f+1):
        y = i*c + j*d
        if y <= f:
            sugar.append(y)

water = []
for i in range(0, f+1):
    for j in range(0, f+1):
        x = i*a*100 + j*b*100
        if x <= f:
            water.append(x)
max_concentration = 0
for x in water:
    for y in sugar:
        if x == 0 and y == 0:
            continue
        elif e * (x // 100) < y:
            continue
        elif x + y > f:
            continue
        else:
            concentration = 100 * y / (x+y)
            if max_concentration <= concentration and concentration <= 100*(e/100) and x+y <= f:
                max_concentration = concentration
                ans1 = x+y
                ans2 = y
print("{} {}".format(ans1, ans2))


Fixed submission:
a,b,c,d,e,f = map(int, input().split())

sugar = []
for i in range(f):
    for j in range(f):
        y = i*c + j*d
        if y <= f:
            sugar.append(y)

water = []
for i in range(0, f//100+1):
    for j in range(0, f//100+1):
        x = i*a*100 + j*b*100
        if x <= f:
            water.append(x)
max_concentration = 0
ans1, ans2 = 0, 0
for x in water:
    for y in sugar:
        if x == 0 and y == 0:
            continue
        elif e * (x // 100) < y:
            continue
        elif x + y > f:
            continue
        else:
            concentration = (100 * y) / (x+y)
            if max_concentration <= concentration:
                max_concentration = concentration
                ans1 = x+y
                ans2 = y
print("{} {}".format(ans1, ans2))
Buggy python submission (verdict: Runtime Error):
num = list(map(int, input().split()))
num = "".join(num)

if num % 4 == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
num = list(input().split())
num = int("".join(num))


if num % 4 == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
count = 0
if a[0] >= 0:
    sym = True
else:
    sym = False
for i in range(1, n):
    if sym:
        while sum(a[0:i+1]) >= 0:
            a[i] -= 1
            count += 1
        sym = False
    else:
        while sum(a[0:i+1]) <= 0:
            a[i] += 1
            count += 1
        sym = True
print(count)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
total = 0
for i in range(len(a)):
    total += a[i]
    if i % 2 == 0:
        if total >= 0:
            cnt1 += 1 + total
            total -= 1 + total
    else:
        if total <= 0:
            cnt1 += 1 - total
            total += 1 - total
total = 0
for i in range(len(a)):
    total += a[i]
    if i % 2 != 0:
        if total >= 0:
            cnt2 += 1 + total
            total -= 1 + total
    else:
        if total <= 0:
            cnt2 += 1 - total
            total += 1 - total
print(min(cnt1, cnt2))
Buggy python submission (verdict: Runtime Error):
o = list(input())
e = list(input())
l = []
for x in range(max(len(o), len(e))):
    l.append(o[x])
    l.append(e[x])
print(''.join(l))

Fixed submission:
o = list(input())
e = list(input())
ls = []
for x in range(min(len(o), len(e))):
    ls.append(o[x])
    ls.append(e[x])
else:
    if len(o) < len(e):
        for i in range(x+1, len(e)):
            ls.append(e[i])
    elif len(o) > len(e):
        for i in range(x+1, len(o)):
            ls.append(o[i])
print(''.join(ls))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
power = 1
for x in range(1, N+1):
    power *= x
print(power%(10**9+7))

Fixed submission:
N = int(input())
power = 1
for x in range(1, N+1):
    power = (power * x) % (10**9+7)
print(power)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
count = 0
for z in range(k+1):
    for y in range(k+1):
        for x in range(k+1):
            if s == y + x + z:
                count += 1
print(count)

Fixed submission:
k, s = map(int, input().split())
count = 0
for y in range(k+1):
    for x in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
1 1000000000000000000 3

Fixed submission:
a, b, x = map(int, input().split())
print(b//x-(a-1)//x)
Buggy python submission (verdict: Runtime Error):
hthth

Fixed submission:
w = list(input())
w_set = set(w)
for s in w_set:
    count_2 = w.count(s)
    if count_2 % 2 == 0:
        result = "Yes"
    else:
        result = "No"
        break
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
s =input().split()
a=0
b=0
while a<int(s[0]) :
    b+=1
    a+=int(s[1])
    if a>int(s[0]) :
        break
    b+=1
    a=a-int(s[2])
    if a<0 :
        break
if a<0 :
    print(-1)
if a>int(s[0]) :
    print(int(b))

Fixed submission:
k, a, b = map(int, raw_input().split())
if k <= a or a <= b:
    print [-1, 1][k <= a]
else:
    print (k - b - 1) / (a - b) * 2 + 1
Buggy python submission (verdict: Runtime Error):
N=input()
A=input()
B=input()
print((2-N)(A-B))

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

min_sum = a * (n - 1) + b
max_sum = b * (n - 1) + a

print(max(max_sum - min_sum + 1, 0))

Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
if n>1 and b>=a or n==1 and a==b: 
    print ((n-2)*(b-a)+1);
else:
    print ("0");

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

min_sum = a * (n - 1) + b
max_sum = b * (n - 1) + a

print(max(max_sum - min_sum + 1, 0))
Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;cin>>a>>b>>c;
	if(b-a==c-b)cout<<"YES";
	else cout<<"NO";
	return 0;
}

Fixed submission:
a, b, c = map(int, raw_input().split())
print ['NO', 'YES'][b - a == c - b]
Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
strint s1, s2;
int leng;
int main()
{
    cin >> s1;
    for(int i = s1.size() - 1; i >= 0; i--)
        s2[leng++] = s1[i];
    for(int i = 0; i < leng; i++)
    {
        if(s1[i]=='b') s2[i] = 'd';
        else if (s1[i] == 'd') s2[i] = 'b';
        else if (s1[i] == 'p') s2[i] = 'q';
        else if (s1[i] == 'q') s2[i] = 'p';
    }
    if(!strcmp(s1,s2)) puts("Yes");
    else puts("No");
    return 0;
}

Fixed submission:
mp={'b':'d','d':'b','p':'q','q':'p'};a=list(input());print("Yes"if a==[mp[x]for x in a[::-1]]else"No");
Buggy python submission (verdict: Runtime Error):
strstart = input()
for i in strstart:
    if i == 'C':
        wzc = i
    if i == 'F':
        wzf = i
if wzc < wzf:
    print('YES')
else:
    print('NO')

Fixed submission:
s = input()
f = False
l = False
for i in range(len(s)):
    if s[i] == 'C':
        for j in range(i, len(s)):
            if s[j] == 'F':
                print('Yes')
                f = True
                l = True
                break
        if f == False:
            print('No')
            l = True
            break
        else:
            l = True
            break
if l == False:
    print('No')
Buggy python submission (verdict: Runtime Error):
s=input()
ans=0
if s[0]=='C':
    ans+=1
if s[1]='O':
    ans+=1
if s[2]='D':
    ans+=1
if s[3]='E':
    ans+=1
if s[4]='F':
    ans+=1
if s[5]='E':
    ans+=1
if s[6]='S':
    ans+=1
if s[7]='T':
    ans+=1
if s[8]='I':
    ans+=1
if s[9]='V':
    ans+=1
if s[10]='A':
    ans+=1
if s[11]='L':
    ans+=1
if s[12]='2':
    ans+=1
if s[13]='0':
    ans+=1
if s[14]='1':
    ans+=1
if s[15]='6':
    ans+=1
print(ans)

Fixed submission:
s1 = 'CODEFESTIVAL2016'
s2 = raw_input()
ans = 0
for i in range(len(s1)):
    ans += [0, 1][s1[i] != s2[i]]
print ans
Buggy python submission (verdict: Runtime Error):
ss=input()
ans=0
 for i in range(2**(len(ss)-1)):
    temp=ss[0]
    for j in range(len(ss)-1):
        if i&(1<<j)!=0:
            temp+="+"
        temp+=ss[j+1]
    ans+=eval(temp)
print(ans)

Fixed submission:
S = input()
ans = 0
 
for i in range(2**(len(S)-1)):
    temp = S[0]
    for j in range(len(S)-1):
        if i & (1<<j) != 0:
            temp += "+"
        temp += S[j+1]
    ans += eval(temp)
print(ans)
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split()))
b=1
for i in range(a[0],a[1]+1):
  b*=i
if b>0:
  print('Positive')
elif b<0:
  print('Negative')
elif b=0:
  print('Zero')

Fixed submission:
a=input().split()
a[0]=int(a[0])
a[1]=int(a[1])
if(a[0]<=0 and a[1]>=0):
    print("Zero")
elif(a[0]<0 and a[1]<0 and (a[1]-a[0])%2==0):
    print("Negative")
else:
    print("Positive")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
rev = False
ans = list(S)
for i in range(Q):
    tfc = input()
    if tfc == '1':
        rev = not rev
    else:
        t,f,c = tfc.split()
        if f == '1':
            if rev: ans = ans + [c]
            else: ans = [c] + ans
        elif f == '2':
            if rev: ans = [c] + ans
            else: ans = ans + [c]

if rev: ans.reverse()

print(''.join(ans))

Fixed submission:
from collections import deque

S = input()
Q = int(input())
rev = False
ans = deque(S)
for i in range(Q):
    tfc = input()
    if tfc == '1':
        rev = not rev
    else:
        t,f,c = tfc.split()
        if f == '1':
            if rev: ans.append(c)
            else: ans.appendleft(c)
        elif f == '2':
            if rev: ans.appendleft(c)
            else: ans.append(c)

if rev: ans.reverse()

print(''.join(ans))
Buggy python submission (verdict: Runtime Error):
    H = int(input())

    ans = 0
    t = 1
    while H > 0:
        ans += t
        H //= 2
        t *= 2
    print(ans)

Fixed submission:
H = int(input())

ans = 0
t = 1
while H > 0:
    ans += t
    H //= 2
    t *= 2
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import factorial, log, floor
N = int(input())

if N % 2 != 0: print(0)
else:
    k = N//2
    ans = 0
    for i in range(1,int(log(k,5))+1):
        ans += floor(k/5**i)
    print(ans)

Fixed submission:
from math import log
N = int(input())

if (N % 2 != 0) or N == 0: print(0)
else:
    k = N//2
    ans = 0
    for i in range(1,int(log(k,5)+1)):
        ans += k//(5**i)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
S = list(input())

com = combinations(S,3)
print(len(set(com)))

Fixed submission:
N = int(input())
S = list(input())
sS = set(S)
from itertools import product
sS = product(sS,repeat=3)
c = 0

for i in sS:
	if i[0] in S:
		a = S.index(i[0])
		if i[1] in S[a+1:]:
			b = S[a+1:].index(i[1]) + a + 1
			if i[2] in S[b+1:]:
				c += 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

ans = 0
for i in range(1000):
    tmp = 0
    v = '{:03}'.format(i)
    for j in range(N):
        if v[tmp] == S[j]: tmp += 1
        if tmp == 3:
            ans += 1
            break
print(ans)

Fixed submission:
N = int(input())
S = list(input())
sS = set(S)
from itertools import product
sS = product(sS,repeat=3)
c = 0

for i in sS:
	if i[0] in S:
		a = S.index(i[0])
		if i[1] in S[a+1:]:
			b = S[a+1:].index(i[1]) + a + 1
			if i[2] in S[b+1:]:
				c += 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
cs = set(S)

from itertools import product
pro = product(cs, repeat=3)

ans = 0
for c in pro:
    tmp = 0
    for i in range(N):
        if c[tmp] == S[i]: tmp += 1
        if tmp == 3:
            ans += 1
            break
print(ans)

Fixed submission:
N = int(input())
S = list(input())
sS = set(S)
from itertools import product
sS = product(sS,repeat=3)
c = 0

for i in sS:
	if i[0] in S:
		a = S.index(i[0])
		if i[1] in S[a+1:]:
			b = S[a+1:].index(i[1]) + a + 1
			if i[2] in S[b+1:]:
				c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
a,b,x = map(int,input().split())

half = a*a*b/2

from math import atan,pi
if x <= half:
    c = 2*x/a/b
    ans = atan(c/b)
else:
    c = 2*x/a/a - b
    ans = atan(a/(b-c))
print(90-ans*180/pi)

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

half = a*a*b/2

from math import atan,pi
if x <= half:
    c = 2*x/a/b
    ans = atan(c/b)
else:
    c = 2*x/a/a - b
    if abs(b-c) < 10**(-7):
        ans = pi / 2
    else: ans = atan(a/(b-c))
print(90-ans*180/pi)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))

num = [False] * (3001)
for i in range(N):
    num[L[i]] = True

L.sort(reverse=True)

ans = 0
for a in range(N):
    for b in range(a+1,N):
        l = L[a]-L[b]
        r = min(L[a]+L[b],L[b])
        ans += sum(num[l+1:r])
        # print(l,r,ans)
print(ans)

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

ans = 0
from bisect import bisect_left
for i in range(N):
    for j in range(i+1,N):
        t = bisect_left(L,L[i]+L[j])
        ans += max(0, t-(j+1))
print(ans)

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

L.sort(reverse=True)

ans = 0
for a in range(N):
    flgb = True
    for b in range(a+1,N):
        flgc = True
        for c in range(N-1,b,-1):
            if L[c]+L[a] <= L[b]:
                flgb = False
                break
            if L[a]+L[b] <= L[c]:
                flgc = False
                break
            if (L[a] < L[b] + L[c]) and (L[b] < L[a] + L[c]):
                ans += 1
        if not flgb: break
        if not flgc: break
    if not flgb: break
print(ans)

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

ans = 0
from bisect import bisect_left
for i in range(N):
    for j in range(i+1,N):
        t = bisect_left(L,L[i]+L[j])
        ans += max(0, t-(j+1))
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import sqrt
A,B = map(int,input().split())
dA = set([A])
dB = set([B])
r = int(sqrt(max(A,B))) + 1
for i in range(1,r+1):
    if A % i == 0:
        dA.add(i)
    if B % i == 0:
        dB.add(i)
CD = dA & dB

m = max(CD)
flg = [True] * (m+1)
flg[0] = False
for i in range(2,m+1):
    if i not in CD: flg[i] = False
    if flg[i]:
        t = i
        i += t
        while i <= m:
            flg[i] = False
            i += t

print(sum(flg))

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

from fractions import gcd
g = gcd(A,B)

a = [1]
while g % 2 == 0:
    a.append(2)
    g //= 2
f = 3
while f * f <= g:
    if g % f == 0:
        a.append(f)
        g //= f
    else:
        f += 2
if g != 1:
    a.append(g)

print(len(set(a)))

Buggy python submission (verdict: Runtime Error):
from math import sqrt
A,B = map(int,input().split())
dA = set()
dB = set()
r = int(sqrt(max(A,B))) + 1
for i in range(1,r):
    if A % i == 0:
        dA.add(i)
        dA.add(A//i)
    if B % i == 0:
        dB.add(i)
        dB.add(B//i)
# print(dA,dB)
CD = dA & dB
#print(CD)
#print(len(CD))

m = max(CD)
flg = [True] * (m+1)
flg[0] = False
for i in range(2,m+1):
    if i not in CD: flg[i] = False
    if flg[i]:
        t = i
        i += t
        while i <= m:
            flg[i] = False
            i += t
# print(flg)
print(sum(flg))

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

from fractions import gcd
g = gcd(A,B)

a = [1]
while g % 2 == 0:
    a.append(2)
    g //= 2
f = 3
while f * f <= g:
    if g % f == 0:
        a.append(f)
        g //= f
    else:
        f += 2
if g != 1:
    a.append(g)

print(len(set(a)))