Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

ans = 0
l = 0
r = len(S)-1

while l < r :
    if S[l] == S[r] :
        l += 1
        r -= 1
    elif S[l] == "x" :
        l += 1
        ans += 1
    elif S[r] == "x" :
        r -= 1
        ans += 1
    else :
        ans = -1

print(ans)


Fixed submission:
S = input()

ans = 0
l = 0
r = len(S)-1

while l < r :
    if S[l] == S[r] :
        l += 1
        r -= 1
    elif S[l] == "x" :
        l += 1
        ans += 1
    elif S[r] == "x" :
        r -= 1
        ans += 1
    else :
        ans = -1
        break

print(ans)

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

ans = 0
l = 0
r = len(S)-1

while l < r :
    if S[l] == S[r] :
        l += 1
        r -= 1
    elif S[l] == "x" :
        l += 1
        ans += 1
    elif S[r] == "x" :
        r -= 1
        ans += 1
    else :
        ans = -1

print(ans)


Fixed submission:
S = input()

ans = 0
l = 0
r = len(S)-1

while l < r :
    if S[l] == S[r] :
        l += 1
        r -= 1
    elif S[l] == "x" :
        l += 1
        ans += 1
    elif S[r] == "x" :
        r -= 1
        ans += 1
    else :
        ans = -1
        break

print(ans)

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

ans = 0

while S :
    if S[0] == S[-1] :
        S = S[1:-1]
    elif S[0] == "x" :
        S += "x"
        ans += 1
    elif S[-1] == "x" :
        S = "x" + S
        ans += 1
    else :
        ans = -1

print(ans)


Fixed submission:
S = input()

ans = 0
l = 0
r = len(S)-1

while l < r :
    if S[l] == S[r] :
        l += 1
        r -= 1
    elif S[l] == "x" :
        l += 1
        ans += 1
    elif S[r] == "x" :
        r -= 1
        ans += 1
    else :
        ans = -1
        break

print(ans)

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

ans = 0

while S :
    if S[0] == S[-1] :
        S = S[1:-1]
    elif S[0] == "x" :
        S += "x"
        ans += 1
    elif S[-1] == "x" :
        S = "x" + S
        ans += 1
    else :
        ans = -1

print(ans)


Fixed submission:
S = input()

ans = 0
l = 0
r = len(S)-1

while l < r :
    if S[l] == S[r] :
        l += 1
        r -= 1
    elif S[l] == "x" :
        l += 1
        ans += 1
    elif S[r] == "x" :
        r -= 1
        ans += 1
    else :
        ans = -1
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
from copy import deepcopy

N,M = map(int,input().split())
Matrix = [[False for x in range(N)] for j in range(N)]

Path = []
for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    Path.append((a,b))
    Matrix[a][b] = True
    Matrix[b][a] = True

INF = 63
ans = 0
for i in range(M) :
    Matrix_duplicated = deepcopy(Matrix)
    a,b = Path[i]
    Matrix_duplicated[a][b] = False
    Matrix_duplicated[b][a] = False
    Distance = [INF for i in range(N)]
    Distance[0] = 0
    Queue = deque([0])
    while Queue :
        now = Queue.popleft()
        Visited.append(now)
        for i in range(N) :
            if Matrix_duplicated[now][i] :
                Matrix_duplicated[now][i] = False
                Matrix_duplicated[i][now] = False
                Distance[i] = min(Distance[now]+1, Distance[i])
                Queue.append(i)
    if INF in Distance :
        ans += 1
print(ans)


Fixed submission:
from collections import deque
from copy import deepcopy

N,M = map(int,input().split())
Matrix = [[False for x in range(N)] for y in range(N)]

Path = []
for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    Path.append((a,b))

for i in range(M) :
    a,b = Path[i]
    Matrix[a][b] = True
    Matrix[b][a] = True
    
ans = 0
for i in range(M) :
    a,b = Path[i]
    Matrix_ = deepcopy(Matrix)
    Matrix_[a][b] = False
    Matrix_[b][a] = False
    INF = 63
    Distance = [INF for i in range(N)]
    Distance[0] = 0
    
    QUEUE = deque([0])
    while QUEUE :
        now = QUEUE.popleft()
        
        for i in range(N) :
            if Matrix_[now][i] :
                Matrix_[now][i] = False
                Matrix_[i][now] = False
                Distance[i] = min(Distance[now]+1,Distance[i])
                QUEUE.append(i)
    #print(Distance)
    if (INF in Distance) :
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

explore = 1
for h in range(1,3500) :
    if not explore : break
    for n in range(1,3500) :
        if (4*h*n - N*n - N*h) == 0 :
            continue
        elif (N*h*n % (4*h*n - N*n - N*h) == 0) and (N*h*n//(4*h*n - N*n - N*h) > 0) :
            w = N*h*n//((4*h*n - N*n - N*h))
            ans = [h,n,w]
            explore = 0
            break

print(*ans)


Fixed submission:
N = int(input())

explore = 1
for h in range(1,3500) :
    if not explore : break
    for n in range(1,3500) :
        if (4*h*n - N*n - N*h) == 0 :
            continue
        elif (N*h*n % (4*h*n - N*n - N*h) == 0) and (N*h*n//(4*h*n - N*n - N*h) > 0) :
            w = N*h*n//((4*h*n - N*n - N*h))
            ans = [h,n,w]
            explore = 0
            break

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [int(input()) for i in range(N)]
P = list(set(L))
ans = 0
for i in range(len(P)) :
    p = L.count(P[i])
    if p % 2 != 0 :
        ans += 1
print(ans)


Fixed submission:
N = int(input())
D = {}
for i in range(N) :
    index = int(input())
    if index not in D :
        D[index] = 1
    else :
        D[index] += 1
ans = 0
for i in D :
    if D[i] % 2 != 0 :
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for i in range(N)]
#P = list(set(T))

def gcd(a,b) :
    a,b = min(a,b),max(a,b)
    while b > 0 :
        a,b = b, a%b
    return a

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

for i in range(len(T)-1) :
    if i == 0 :
        ans = lcm(T[i],T[i+1])
    else :
        p = lcm(T[i],T[i+1])
        if p > ans :
            ans = p
print(ans)


Fixed submission:
N = int(input())
T = [int(input()) for i in range(N)]
#P = list(set(T))

def gcd(a,b) :
    a,b = min(a,b),max(a,b)
    while b > 0 :
        a,b = b, a%b
    return a

def lcm(a,b) :
    return a*b//gcd(a,b)
if N == 1 :
    ans = T[0]
else :
    for i in range(len(T)) :
        if i == 0 :
            ans = lcm(T[i],T[i+1])
        else :
            ans = lcm(T[i],ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for i in range(N)]
P = list(set(T))

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

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

for i in range(len(P)-1) :
    if i == 0 :
        ans = lcm(P[i],P[i+1])
    else :
        p = lcm(P[i],P[i+1])
        if p > ans :
            ans = p
print(ans)


Fixed submission:
N = int(input())
T = [int(input()) for i in range(N)]
#P = list(set(T))

def gcd(a,b) :
    a,b = min(a,b),max(a,b)
    while b > 0 :
        a,b = b, a%b
    return a

def lcm(a,b) :
    return a*b//gcd(a,b)
if N == 1 :
    ans = T[0]
else :
    for i in range(len(T)) :
        if i == 0 :
            ans = lcm(T[i],T[i+1])
        else :
            ans = lcm(T[i],ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
ANS = []
for i in range(N-1) :
    p = abs(sum(L[:i+1])-sum(L[i+1:]))
    ANS.append(p)
print(min(ANS))


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

for i in range(N-1) :
    if i == 0 :
        p = L[i]
        q = sum(L)-p
        ans = abs(p-q)
    else :
        p += L[i]
        q -= L[i]
        if ans > abs(p-q) :
            ans = abs(p-q)
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = []
for i in range(N) :
    L.append(int(input()))
A = [0]
flag = 0
button = 1
ans = 0
while flag == 0 :
    button = L[button-1]
    ans += 1
    if (button-1) == 1 :
        print(ans)
        flag = 1
    elif (button-1) in A :
        print(-1)
        flag = 1
    else :
        A.append(button-1)


Fixed submission:
N = int(input())
L = [int(input()) for i in range(N)]

flag = 0
now = 0
ans = 0
for i in range(N+1) :
    if now == 1 :
        flag = 1
        break
    else :
        now = L[now]-1
        ans += 1
if flag == 1 :
    print(ans)
else :
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = []
for i in range(N) :
    L.append(int(input()))

A = []
for i in range(N+1) :
    if i == 0 :
        button = 1
        ans = 0
    elif button == 2 :
        break
    else :
        button = L[button-1]
        if button in A :
            ans = -1
            break
        else :
            A.append(button)
            ans += 1
print(ans)   


Fixed submission:
N = int(input())
L = [int(input()) for i in range(N)]

flag = 0
now = 0
ans = 0
for i in range(N+1) :
    if now == 1 :
        flag = 1
        break
    else :
        now = L[now]-1
        ans += 1
if flag == 1 :
    print(ans)
else :
    print(-1)
Buggy python submission (verdict: Runtime Error):
S = input()
P = list(set(P))
ANS = []
for i in range(len(P)) :
    T = list(S.split(P[i]))
    U = []
    for j in range(len(T)) :
        U.append(len(T[j]))
    ANS.append(max(U))
print(min(ANS))


Fixed submission:
S = input()
ANS = []
for i in range(ord("a"),ord("z")+1) :
    p = chr(i)
    T = list(S.split(p))
    U = []
    for j in range(len(T)) :
        U.append(len(T[j]))
    ANS.append(max(U))
print(min(ANS))
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))
D = {}
p = 0
for i in range(N) :
    if L[i] < 400 :
        color = 0
    elif L[i] < 800 :
        color = 1
    elif L[i] < 1200 :
        color = 2
    elif L[i] < 1600 :
        color = 3
    elif L[i] < 2000 :
        color = 4
    elif L[i] < 2400 :
        color = 5
    elif L[i] < 2800 :
        color = 6
    elif L[i] < 3200 :
        color = 7
    else :
        p += 1
    if color not in D :
        D[color] = 1
    else :
        D[color] += 1
ans1 = len(list(D.keys()))
ans2 = ans1 + p
print(ans1,ans2)


Fixed submission:
N = int(input())
L = list(map(int,input().split()))
D = {}
p = 0
for i in range(N) :
    if L[i] < 400 :
        color = 0
    elif L[i] < 800 :
        color = 1
    elif L[i] < 1200 :
        color = 2
    elif L[i] < 1600 :
        color = 3
    elif L[i] < 2000 :
        color = 4
    elif L[i] < 2400 :
        color = 5
    elif L[i] < 2800 :
        color = 6
    elif L[i] < 3200 :
        color = 7
    else :
        p += 1
    if L[i] < 3200 :
        if color not in D :
            D[color] = 1
        else :
            D[color] += 1
ans1 = len(list(D.keys()))
q = 0
if ans1 == 0 :
    ans1 = 1
    q = 1
ans2 = ans1 + p - q
print(ans1,ans2)
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import csgraph_from_dense, bellman_ford
mINF = -(10**16)
n,m = map(int,input().split())
A = [0]*m
B = [0]*m
C = [0]*m
for i in range(m) :
    a, b, c = map(int,input().split())
    A[i], B[i], C[i] = a-1, b-1, -c

graph = [[mINF]*n for i in range(n)]
for i in range(m) :
    graph[A[i]][B[i]] = C[i]

graph = csgraph_from_dense(graph, null_value=mINF)
try :
    dist = bellman_ford(graph)
    print(-dist[0][n-1])
except : # NegativeCycleError in scipy
    ans = "inf"

print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N,M = map(int,input().split())
edges = []
to = [[] for i in range(N)]
rto = [[] for i in range(N)]
for i in range(M) :
    u,v,cost = map(int,input().split())
    u -= 1
    v -= 1
    cost *= -1
    edges.append([u,v,cost])
    to[u].append(v)
    rto[v].append(u)

canVisitFromS = [False]*N
canVisitFromG = [False]*N

def dfs(u) :
    if canVisitFromS[u] : return
    canVisitFromS[u] = True
    for v in to[u] :
        dfs(v)

def rdfs(v) :
    if canVisitFromG[v] : return
    canVisitFromG[v] = True
    for u in rto[v] :
        rdfs(u)

dfs(0)
rdfs(N-1)

OK = [canVisitFromS[i] * canVisitFromG[i] for i in range(N)]

dist = [float("inf")]*N
dist[0] = 0

update = True
step = 0
ans = 0

while update :
    update = False
    for i in range(M) :
        u,v,cost = edges[i]
        if OK[u] * OK[v] == 0 : continue
        if dist[v] > dist[u] + cost :
            dist[v] = dist[u] + cost
            update = True
    step += 1
    if step > N :
        ans = "inf"
        break
if ans != "inf" :
    ans = dist[N-1] * (-1)
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
if A > B :
    print("GREATER")
elif A < B :
    print("LESS")
else :
    print("EQUAL")
    

Fixed submission:
A = int(input())
B = int(input())
if A > B :
    print("GREATER")
elif A < B :
    print("LESS")
else :
    print("EQUAL")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

ans = 0


sum_A = A[0]
for i in range(1,N) :
    if ((sum_A + A[i]) == 0) or (sum_A *(sum_A + A[i]) >= 0) :
        if sum_A > 0 :
            ans += 1 + sum_A + A[i]
            #print("ans += {}".format(1 + sum_A + A[i]))
            sum_A = -1
        elif sum_A < 0 :
            ans += 1 - (sum_A + A[i])
            #print("ans += {}".format(1 - (sum_A + A[i])))
            sum_A = 1
        
    else :
        sum_A += A[i]
        #print("else")
    record.append(sum_A)

print(ans)


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

calc1 = 0
calc2 = 0

L = A

if L[0] > 0 :
    su = L[0]
else :
    su = 1
    calc1 += 1 + abs(L[0])

for i in range(1,N) :
    su += L[i]
    if i % 2 :
        if su >= 0 :
            calc1 += 1 + abs(su)
            su = -1
    else :
        if su <= 0 :
            calc1 += 1 + abs(su)
            su = 1

L = A

if L[0] < 0 :
    su = L[0]
else :
    su = -1
    calc2 += 1 + abs(L[0])

for i in range(1,N) :
    su += L[i]
    if not i % 2 :
        if su >= 0 :
            calc2 += 1 + abs(su)
            su = -1
    else :
        if su <= 0 :
            calc2 += 1 + abs(su)
            su = 1
print(min(calc1,calc2))
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if A==b and b==c:
    print("YES")
else:
    print("NO")
    
    

Fixed submission:
a,b,c=map(int,input().split())
if a-b == b-c:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
L = sorted(L,reverse=True)
ans = 0
while len(L) > 0 :
    L.pop(0)
    ans += L[0]
    L.pop(0)
    L.pop(-1)
print(ans)


Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L = sorted(L,reverse=False)
L = L[N:]
ans = 0
for i in range(N) :
    ans += L[2*i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
answer = 1
for i in range(N) :
    answer *= (i+1)
answer = answer % (10**9+7)
print(answer)


Fixed submission:
N = int(input())
answer = 1
for i in range(N) :
    answer = (answer*(i+1))%(10**9+7)
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
ans = 0
for i in range(K+1) :
    for j in range(K+1) :
        for k in range(K+1) :
            if (i+j+k) == S :
                ans += 1
print(ans)


Fixed submission:
K,S = map(int,input().split())
answer = 0
for i in range(K+1) :
    for j in range(K+1) :
        if (i+j) >= (S-K) and (i+j) <= S :
            answer += 1
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x = map(int,input().split())
answer = 0
flag = 0
for i in range(a,b+1) :
    if i % x == 0 :
        answer += 1
        p = i
        flag += 1
        break
if flag == 1 :
    q = b-p
else :
    q = b-a
answer += q//x
print(answer)


Fixed submission:
a,b,x = map(int,input().split())
B = b//x
A = (a-1)//x
print(B-A)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,x = map(int,input().split())
answer = 0
flag = 0
for i in range(a,b+1) :
    if i % x == 0 :
        answer += 1
        p = i
        flag += 1
        break
if flag == 1 :
    q = b-p
else :
    q = b-a
answer += q//x
print(answer)


Fixed submission:
a,b,x = map(int,input().split())
B = b//x
A = (a-1)//x
print(B-A)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

N = int(input())

L = [0]
l = 0
for i in range(1,10**6) :
    l += i
    L.append(l)
ans = []
while N > 0 :
    for i in range(len(L))  :
        #print(L[i],N,L[i+1])
        if (L[i]+1 <= N <= L[i+1]) :
            ans.append(i+1)
            N -= i+1
            break
    
print(*ans,sep="\n")


Fixed submission:
import sys
import bisect

sys.setrecursionlimit(10**9)

N = int(input())

L = [0]
l = 0
for i in range(1,10**6) :
    l += i
    L.append(l+1)
ans = []
while N > 0 :
    tmp = bisect.bisect(L,N)
    
    ans.append(tmp)
    N -= tmp
    
print(*ans,sep="\n")

Buggy python submission (verdict: Runtime Error):
N = int(input())

L = [0]
l = 0
for i in range(1,100) :
    l += i
    L.append(l)
ans = []
while N > 0 :
    for i in range(len(L))  :
        #print(L[i],N,L[i+1])
        if (L[i]+1 <= N <= L[i+1]) :
            ans.append(i+1)
            N -= i+1
            break
    
print(*ans,sep="\n")


Fixed submission:
import sys
import bisect

sys.setrecursionlimit(10**9)

N = int(input())

L = [0]
l = 0
for i in range(1,10**6) :
    l += i
    L.append(l+1)
ans = []
while N > 0 :
    tmp = bisect.bisect(L,N)
    
    ans.append(tmp)
    N -= tmp
    
print(*ans,sep="\n")
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))

A = [i*N for i in range(1,N+1)]
B = A[::-1]

for i,p in enumerate(P) :
    A[p] += i
    B[p] += i

print(*A)
print(*B)


Fixed submission:
N = int(input())
P = list(map(lambda x: int(x)-1, input().split()))

A = [i*N for i in range(1,N+1)]
B = A[::-1]

for i,p in enumerate(P) :
    A[p] += i
    B[p] += i

print(*A)
print(*B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
B = []
for i in range(N) :
    in_a,in_b = map(int,input().split())
    A.append(in_a)
    B.append(in_b)
    
for i in range(1,N) :
    a = A[i]
    b = B[i]
    while ((A[i-1] > a) or (B[i-1] > b)) :
        a += A[i]
        b += B[i]
    A[i] = a
    B[i] = b
ans = A[-1] + B[-1]
print(ans)


Fixed submission:
N = int(input())
A = []
B = []
for i in range(N) :
    in_a,in_b = map(int,input().split())
    A.append(in_a)
    B.append(in_b)
    
for i in range(1,N) :
    if A[i-1] > A[i] :
        if A[i-1] % A[i] == 0 :
            a = A[i-1]//A[i]
        else :
            a = A[i-1]//A[i] + 1
    else :
        a = 1
    
    if B[i-1] > B[i] :
        if B[i-1] % B[i] == 0 :
            b = B[i-1]//B[i]
        else :
            b = B[i-1]//B[i] + 1
    else :
        b = 1
    
    p = max(a,b)
    
    A[i] *= p
    B[i] *= p

ans = A[-1] + B[-1]

print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
ans=(a+b)*h*0.5
print(int(ans))



Fixed submission:
a=int(input())
b=int(input())
h=int(input())
ans=(a+b)*h*0.5
print(int(ans))

Buggy python submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
ans=(a+b)*h*0.5
print(ans)



Fixed submission:
a=int(input())
b=int(input())
h=int(input())
ans=(a+b)*h*0.5
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N,A = map(int,input().split())
L = list(map(int,input().split()))
#for i in range(N) :
#    L[i] -= A
#L = sorted(L)
ans = 0
for bit in range(1 << N) :
    calc = 0
    ctr = 0
    for k in range(N) :
        if bit & (1 << k) :
            calc += L[k]
            ctr += 1
    if calc == 0 :
        continue
    if calc == A*ctr :
        ans += 1
print(ans)


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

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

ma = max(X)

dp = [[[0 for s in range(ma*N+1)] for k in range(N+1)] for i in range(N+1)]

dp[0][0][0] = 1

for i in range(1,N+1) :
    for k in range(i+1) :
        for s in range(ma*N+1) :
            if (k >= 1) and (s >= X[i-1]) :
                dp[i][k][s] = dp[i-1][k][s] + dp[i-1][k-1][s-X[i-1]]
            else :
                dp[i][k][s] = dp[i-1][k][s]

ans = 0

for k in range(1,N+1) :
    if k*A > ma*N :
        break
    ans += dp[N][k][k*A]

print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c =map(int(input().split()))
L=[]
L.append(a)
L.append(b)
L.append(c)
if L.count(5)==2 and L.count(7)==1 :
    print("YES")
else :
    print("NO")
    
    

Fixed submission:
a,b,c =map(int,input().split())
L=[]
L.append(a)
L.append(b)
L.append(c)
if L.count(5)==2 and L.count(7)==1 :
    print("YES")
else :
    print("NO")
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(0,2*N,2) :
    ans += L[i]
print(ans)


Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
answer = 0
for i in range(len(L)) :
    if i % 2 == 0 :
        answer += L[i]
print(answer)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

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

def f(a,b) :
    if a < b :
        return 2*a + f(a,b-a)
    elif a > b :
        return 2*b + f(b,a-b)
    else :
        return a

ans = N + f(X,N-X)

print(ans)


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

def f(a,b) :
    if a > b :
        a,b = b,a
    if b % a == 0 :
        return 2*(b//a-1)*a + a
    else :
        return 2*(b//a)*a + f(a,b%a)
        
ans = N + f(X,N-X)

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**12+1)

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

def f(a,b) :
    if a < b :
        return 2*a + f(a,b-a)
    elif a > b :
        a,b = b,a
        return 2*a + f(a,b-a)
    else :
        return a

ans = N + f(X,N-X)

print(ans)


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

def f(a,b) :
    if a > b :
        a,b = b,a
    if b % a == 0 :
        return 2*(b//a-1)*a + a
    else :
        return 2*(b//a)*a + f(a,b%a)
        
ans = N + f(X,N-X)

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

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

def f(a,b) :
    if a < b :
        return 2*a + f(a,b-a)
    elif a > b :
        a,b = b,a
        return 2*a + f(a,b-a)
    else :
        return a

ans = N + f(X,N-X)

print(ans)


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

def f(a,b) :
    if a > b :
        a,b = b,a
    if b % a == 0 :
        return 2*(b//a-1)*a + a
    else :
        return 2*(b//a)*a + f(a,b%a)
        
ans = N + f(X,N-X)

print(ans)

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

def f(a,b) :
    if a < b :
        return 2*a + f(a,b-a)
    elif a > b :
        a,b = b,a
        return 2*a + f(a,b-a)
    else :
        return a

ans = N + f(X,N-X)

print(ans)


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

def f(a,b) :
    if a > b :
        a,b = b,a
    if b % a == 0 :
        return 2*(b//a-1)*a + a
    else :
        return 2*(b//a)*a + f(a,b%a)
        
ans = N + f(X,N-X)

print(ans)

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

def f(a,b) :
    if a < b :
        return 2*a + f(a,b-a)
    elif b == 0 :
        return 0
    else :
        return ((a//b)*2-1)*b

ans = N + f(X,N-X)

print(ans)


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

def f(a,b) :
    if a > b :
        a,b = b,a
    if b % a == 0 :
        return 2*(b//a-1)*a + a
    else :
        return 2*(b//a)*a + f(a,b%a)
        
ans = N + f(X,N-X)

print(ans)