Problem:


Score : 500 points

Problem Statement

Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light.

Three mirrors of length N are set so that they form an equilateral triangle.
Let the vertices of the triangle be a, b and c.

Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc.

The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.

The following image shows the ray's trajectory where N = 5 and X = 2.

It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X.
Find the total length of the ray's trajectory.

Constraints

2≦N≦10^{12}

1≦X≦N-1

N and X are integers.

Partial Points

300 points will be awarded for passing the test set satisfying N≦1000.

Another 200 points will be awarded for passing the test set without additional constraints.

Input

The input is given from Standard Input in the following format:

N X

Output

Print the total length of the ray's trajectory.

Sample Input 1

5 2

Sample Output 1

12

Refer to the image in the Problem Statement section.
The total length of the trajectory is 2+3+2+2+1+1+1 = 12.



Sample input:
5 2


Sample output:
12

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
def f(a,b):
    if a>b: b,a=a,b 
    if b%a==0: return 2*(b//a)-1
    return 2*a*(b//a)+ f(b%a,a)
print(n+ f(x,n-x))

Submission status: Wrong Answer

Solution code:
N, X = list(map(int, input().split()))

ans = N
N, X = X, N - X
while N and X:
  if X > N:
    d, m = divmod(X, N)
    if m == 0:
      ans += (d * 2 - 1) * N
    else:
      ans += d * 2 * N
    N, X = N, m
  else:
    d, m = divmod(N, X)
    ans += (d * 2 - 1) * X + m * 2
    N, X = m, X - m

print(ans)

Submission status: Wrong Answer

Solution code:
N, X = list(map(int, input().split()))

ans = N
N, X = X, N - X
while N and X:
  if X > N:
    d, m = divmod(X, N)
    ans += d * 2 * N
    N, X = N, m
  else:
    d, m = divmod(N, X)
    ans += (d * 2 - 1) * X + m * 2
    N, X = m, X - m

print(ans)

Submission status: Wrong Answer

Solution code:
N, X = list(map(int, input().split()))

ans = N
N, X = X, N - X
while N and X:
  if X > N:
    d, m = divmod(X, N)
    ans += d * 2 * N
    N, X = N + m, X - d * N
  else:
    d, m = divmod(N, X)
    ans += d * X + m * 2
    N, X = m, X - m

print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
print(4*n-4*x)

Submission status: Wrong Answer

Solution code:
import math
n,x = map(int,input().split())
a = n+(n-x)//x*x*2
b = math.gcd(n-x,x)
if b == x:
    print(a-x)
else:
    print(int(a+(x/b*2-1)*b))

Submission status: Wrong Answer

Solution code:
import math
n,x = map(int,input().split())
a = n+(n-x)//x*x*2
b = math.gcd(n-x,x)
if b == x:
    print(a-x)
else:
    print(a+(x*2-1)*b)

Submission status: Wrong Answer

Solution code:
import math
n,x = map(int,input().split())
a = n+(n-x)//x*x*2
b = math.gcd(n-x,x)
if b == x:
    print(a-x)
else:
    print(a+b*3)

Submission status: Wrong Answer

Solution code:
import math
n,x = map(int,input().split())
print(n+(n-x)//x*x*2+math.gcd(n-x,x)*3)

Submission status: Wrong Answer

Solution code:
import math
n,x = map(int,input().split())
print(n+n//x*x+math.gcd(n-x,x)*3)

Submission status: Wrong Answer

Solution code:
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,x = map(int,input().split())
print(n-x+sum(make_divisors(x))*3)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())

ans = x
e = n-x
count = 0
while True:
    
    if x%e == 0:
        if count == 0:
            ans += x//e*(e*2)
        else:
            ans += x//e*(e*2)-e
        break
    else:
        if count%2 == 0:
            ans += e+(x//e)*e*2
        else:
            ans += (x//e)*e*2
        x,e = e,x%e
    count += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
ans=0
t=n-x
tt=x//t
ans+=x
while True:
    if x%t==0:
        ans+=tt*t*2
        print(ans)
        exit()
    else:
        ans+=tt*t*2+t
        x=t
        t=n-t*tt
        tt=x//t

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
print(3*(n-1))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
print(3 * x if n / x == 2 else 3 * (n - 1))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
print((a[0]*(a[1]*2)) - (a[1]*(a[1]*2)))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
print((a[0]*4) - (a[1]*4))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
print(a[0]*4 + a[1]*4)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
print(a[0] * 4, a[1] * 4)

Submission status: Wrong Answer

Solution code:
N, X = [int(x) for x in input().split()]
#answer = 

if N//2 >= X:
  print(X + N-X + X + X + 2*X-1)
else: #N//2 < X
  print(0)

Submission status: Wrong Answer

Solution code:
N,X = input().split()
N,X = int(N), int(X)
answer = X+ (N-X)


def rhombus(N,X):
    if X==1: 
        return N+1
    if X==0:
        return 0

    if N%X == 0:
        return X*(N//X)*2-X
      
    else: 
        k = N//X
        return k*2*X + rhombus(X,N-(k*X))

      

answer = answer + rhombus(N-X,X)
print(answer)

Submission status: Wrong Answer

Solution code:
N,X = input().split()
N,X = int(N), int(X)
answer = X+ (N-X)


def rhombus(N,X):
    if X==1: 
        return N+1
    if X==0:
        return 0

    if N%X == 0:
        return X*(N//X)*2-1
      
    else: 
        k = N//X
        return k*2*X + rhombus(X,N-(k*X))

      

answer = answer + rhombus(N-X,X)
print(answer)

Submission status: Wrong Answer

Solution code:
N,X = input().split()
N,X = int(N), int(X)
answer = X+ (N-X)


def rhombus(N,X):
    if X==1: 
        return N+1
    if X==0:
        return 0

    if N%X == 0:
        return (N//X)*2-1
      
    else: 
        k = N//X
        return k*2*X + rhombus(X,N-(k*X))

      

answer = answer + rhombus(N-X,X)
print(answer)

Submission status: Wrong Answer

Solution code:
n, x = list(map(int, input().split()))
ans = 3 * 3 * x / 2 + n - x
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
print(4*(n-x))

Submission status: Wrong Answer

Solution code:
n, x = [int(i) for i in input().split()]

print(int(x + (n-x) + x + x + x/2 + x/2 + x/2))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())

print(3 * (N - X))

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
if N%X==0:
  print((N-X)*3)
else:
  print(N*3-3)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
if N%2==0 and N//2==X:
  print(3*X)
else:
  print(N*3-3)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())

ans = X
base = N - X
elem = X
while True:
    div, mod = divmod(base, elem)
    ans += div * elem * 2

    if mod == 0:
        ans += base
        break

    base = elem
    elem = mod


print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
if n<=2*x:print(int(1.5*x))
else:
    k=(2*(x/(n-2*x)))*(n-2*x)
    ans=4*x+k 
    print(int(ans))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
print(6*x)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
print(3*x+n+1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, X = map(int, input().split())
def solve(n, x):
  if n == 0:
    return 0
  if x == 1: return n * 3
  m = x
  y = n - n // x * x
  if y == 0: return n // x * x * 3
  return solve(m, y) + y * 3 * x
print(solve(max(N - X, X), min(N - X, X)))

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n,x = myinput()

def mycalc(a,b):
    if b==0:
        return 0
    else:
        return ( (a//b) * 3 * b ) + mycalc(b,a%b)

if n%2==1:
    ans = (n-1)*3
else:
    # if x==1:
    #     ans = (n-1)*3
    # else:
    ans = mycalc(n-x,x)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n,x = myinput()

def mycalc(a,b):
    if b==0:
        return 0
    else:
        return ( (a//b) * 3 * b ) + mycalc(b,a%b)

if n%2==1:
    ans = (n-1)*3
else:
    # if x>(n//2):
    #     x = n - x
    if x==1:
        ans = (n-1)*3
    else:
        ans = mycalc(n-x,x)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n,x = myinput()

def mycalc(a,b):
    if b==0:
        return 0
    else:
        return ( (a//b) * 3 * b ) + mycalc(b,a%b)

if n%2==1:
    ans = (n-1)*3
else:
    if x>n//2:
        x = n - x
    if x==1:
        ans = (n-1)*3
    else:
        ans = mycalc(n-x,x)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n,x = myinput()
ans = (n-1)*3
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=n-x
b=a-x
s=x+a+x+x+b+b+b
print(s)

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    L = LI()
    L.sort()
    ans = sum(L[::2])
    print(ans)
    return

def examB():
    N, X = LI()
    ans = N-X
    while(X>0):
        ans += (2 * (N//X) - 1) * X
        #print(ans,N,X)
        next_N = X
        next_X = N%X
        N = next_N
        X = next_X
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
print(N*3)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
if x < n/2:
  print(n + int(3.5 * x))
elif x == n/2:
  print(3 * x)
else:
  if x % (n-x) == 0:
    print((n-x) * 3 * (x // (n-x)))
  else:
    q=n-x
    r= x % (n-x)
    ans = (n-x) * ((x//(n-x))*3 + 1)
    while r != 0:
      if q % r == 0:
        ans += ((q//r - 1) * 2 + 1) * r
        r=0
      elif q % r != 0:
        ans += (q//r) * 2 * r
        q,r = r, q % r
    print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
if x < n/2:
  print(n + 3.5 * x)
elif x == n/2:
  print(3 * x)
else:
  if x % (n-x) == 0:
    print((n-x) * 3 * (x // (n-x)))
  else:
    q=n-x
    r= x % (n-x)
    ans = (n-x) * ((x//(n-x))*3 + 1)
    while r != 0:
      if q % r == 0:
        ans += ((q//r - 1) * 2 + 1) * r
        r=0
      elif q % r != 0:
        ans += (q//r) * 2 * r
        q,r = r, q % r
    print(ans)

Submission status: Wrong Answer

Solution code:
num = [int(x) for x in input().split()]
N = num[0]
X = num[1]
result = N
a = N -X
b = X
if a < b:
    c = a
    a = b
    b = c
while b >= 1:
    result += (2*(a//b))*b
    c = a%b
    a = b
    b = c
print(result)

Submission status: Wrong Answer

Solution code:
Input_num = [int(x) for x in input().split()]
N = Input_num[0]
X = Input_num[1]
Total_Length = 2*X + N + 3*(X//2)
print(Total_Length)

Submission status: Wrong Answer

Solution code:
def run():
  N, X = map(int, input().split())
  y = N-X
  ans = N
  while True:
    y, X = max(y, X), min(y, X)
    a = y//X
    ans += a*X*2
    if y%X == 0:
      break
    y, X = X, a
  print(ans-X)
  
  
if __name__ == '__main__':
  run()

Submission status: Wrong Answer

Solution code:
n,x = [int(i) for i in input().split()]

length = n
n=n-x
while True:
    if x==0:
        length-=x
        break
    t=n//x
    length+=2*t*x
    a=n
    n=x
    x=a-t*x
print(length)

Submission status: Wrong Answer

Solution code:
n,x = [int(i) for i in input().split()]
length = n
n=n-x
while True:
    if x==0:
        break
    t=n//x
    length+=2*t*x
    a=n
    n=x
    x=a-t*x
print(length)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
if X<=N/2:
  print(4*(N-X))
else:
  print(3*X)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
print(x*3 + (n-x)*2)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X = MAP()

if X <= N/2:
	print(4*N-4*X)
else:
	print(6*N-5*X)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
print(2 * n + x)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())

ans = n

wall_side = n - x
light_length = n - (n - x)
while True:
    if wall_side % light_length == 0:
        ans += (wall_side // light_length - 1) * 2 + 1
        break
    else:
        ans += 2 * (wall_side // light_length) * light_length
        wall_side, light_length = light_length, wall_side % light_length
        

print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
if n-3*x>0:
    total=2*n
else:
    total=n+4*x-1
print(total)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, X = MAP()

if N%2 == 1:
    print((N-1)*3)
else:
    print(N*3//2+abs(X-N//2)*3)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a, b = max(n-x,x),min(n-x,x)
res = a+b
while b!=0:
    q = a/b
    r = a%b
    res += (b*2)*q
    if (r==0):
        res -= b
    a, b = b, r

print(res)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
ans = 0
a, b = max(n-x,x),min(n-x,x)
res = a+b
while b:
    q = a/b
    r = a%b
    res += (b*2)*q
    if (r==0):
        res -= b
    a, b = b, r

print(res)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())


if (n%2 == 1):
    print((n-1)*3)
elif (n==2):
    print(3)
else:
    k=n/2
    if (x<k):
        print(int((k*3)+(3*(k-x))))
    elif(x==k):
        print(int(k*3))
    else:
        print(int((k*3)+(3*(k-(n-x)))))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())

if (n%2 == 1):
    print((n-1)*3)
elif (n==2):
    print(3)
else:
    k=n//2
    if (x<k):
        print(int((n-x)*k))
    elif(x==k):
        print(int(k*3))
    else:
        print(int(x*k))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
if (n%2 ==1):
    print((n-1)*3)
elif (n==2):
    print(3)
else:
    k=n/2
    if (x<k):
        print((n-x)*k)
    elif(x==k):
        print(k*3)
    else:
        print(x*k)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())

print((n-1)*3)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())


ans = []
for i in range(1,n):
    k=i*3
    ans.append(k)

print(ans[n-2])

Submission status: Wrong Answer

Solution code:
N, X = input().split()

print(3 * (int(N) - 1))

Submission status: Wrong Answer

Solution code:
N, X = input().split()

print(3 * int(N))

Submission status: Wrong Answer

Solution code:
N, X = input().split()

print(6 * int(X))

Submission status: Wrong Answer

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, X = map(int, input().split())

    if X * 2 > N:
        print(3 * X)
    elif X * 2 == N:
        print(3 * X)
    else:
        print(4 * (N - X))

sol()

Submission status: Wrong Answer

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, X = map(int, input().split())

    if X * 2 > N:
        print(2 * X / (N - X))
    elif X * 2 == N:
        print(3 * X)
    else:
        print(4 * (N - X))

sol()

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
	return a and gcd(b%a,a)or b
N,X=map(int,input().split())
g=gcd(N,X)
z=N//g
b=(N-X)//g
a=min(X,N-X)//g
while a>1:
	c=b
	while c:
		z+=2*a
		c//=a
	a,b=b%a,a
print(g*(z-1))

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
z=3.5*y+x
print(z)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
sum_lec = x + (n - x) + x + x +(n - 2 * x) * 3
print(sum_lec)

Submission status: Wrong Answer

Solution code:
def trajectory_cal(N, X):
    length =  4*N - 4*X
    return length

N, X =  input().split()
value = trajectory_cal(int(N), int(X))
print(value)

Submission status: Wrong Answer

Solution code:
N,X = [int(zz) for zz in input().split()]

print(6*X)

Submission status: Wrong Answer

Solution code:
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5)
N, X = map(int, input().split())
if N > 1000:
    exit()

if 2 * X > N:
    X = N - X

#座標の作成
dp = [[-1] * (N+3)]
for i in range(N+1):
    tmp = [-1]
    for j in range(N+1):
        if i <= j:
            tmp.append(0) #到達していないマス
        else:
            tmp.append(-1) #壁(範囲外)
    tmp.append(-1)
    tmp.reverse()
    dp.append(tmp)
dp.append([-1] * (N+3))
# print (np.array(dp))


#m: 0:右へ, 1:左下へ, 2:左上へ
def moving(x, y, total, m):
    if x == X and y == 1 and dp[x][y] == 1:
        # print ('D')
        return total
    if m == 0: #右に動く時
        tmp = 0
        while dp[x-1][y+1] == 0: #右に進める時
            dp[x-1][y+1] = 1 #右進んだマスを到達したことにする
            tmp += 1
            x -= 1
            y += 1
        if dp[x-1][y+1] == -1: #右側が壁の時-->左下に進む
            # print ('1-B')
            return moving(x, y, total + tmp, 1)
        if dp[x-1][y+1] == 1: #右側が光の線の時-->左上へ進む
            tmp += 1
            # print ('1-C')
            return moving(x-1, y+1, total + tmp, 2)
    
    if m == 1: #左下へ動く時
        tmp = 0
        while dp[x+1][y] == 0: #左下に進める時
            dp[x+1][y] = 1
            tmp += 1
            x += 1
        if dp[x+1][y] == -1: #左下が壁の時-->左上に進む
            # print ('2-C')
            return moving(x, y, total + tmp, 2)
        if dp[x+1][y] == 1: #左下が光の線の時-->左上に進む
            tmp += 1
            # print ('2-C')
            return moving(x+1, y, total + tmp, 2)
    
    if m == 2: #左上に動く時
        tmp = 0
        while dp[x][y-1] == 0: #左上に進める時
            dp[x][y-1] = 1
            tmp += 1
            y -= 1
        if dp[x][y-1] == -1: #左上が壁の時-->右に進む
            # print ('3-A')
            return moving(x, y, total + tmp, 0)
        if dp[x][y-1] == 1: #左上が光の線の時-->左下に進む
            tmp += 1
            # print ('3-B')
            return moving(x, y-1, total + tmp, 1)

X += 1
print (moving(X, 1, 0, 0))
# print (np.array(dp))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
import math

def f(x,y):
    a = min(x,y)
    b = max(x,y)    
    if a == 0:
        return 0
    elif b%a == 0:
        return 2*b-1
    else:
        return 2*a*math.floor(b/a) + f(a,b%a)

print(n+f(x,n-x))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
if 2 * X > N:
    X = N - X

# if N == 2 * X:
#     print (3 * X)
#     exit()

# if X == 1:
#     print (3 * X * (N - 1))
#     exit()

# if X == 2:
#     print (3 * X  * 2)
#     exit()

x = 3 * X
n = (N - 1)//X
print (x * n)

Submission status: Wrong Answer

Solution code:
n, x = list(map(int, input().split()))
ans = x
a = x
b = n - x
while b > 0:
	ans += (a // b) * 2 * b
	if a % b > 0:
		ans += 1
	a, b = b, a % b
print(ans)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
print(a * 2 + b)

Submission status: Wrong Answer

Solution code:
def is_prime(n: int)->bool:
    d = 2
    while d * d <= n:
        if n % d == 0:
            return False
        d += 1
    return True


def mysterious_light(N: int, X: int)->int:
    if is_prime(N):
        return 3*(N-1)
    return 3*max(N-X, X)


if __name__ == "__main__":
    N, X = map(int, input().split())

    ans = mysterious_light(N, X)
    print(ans)

Submission status: Wrong Answer

Solution code:
def is_prime(n: int)->bool:
    d = 2
    while d * d <= n:
        if n % d == 0:
            return False
        d += 1
    return True


def mysterious_light(N: int, X: int)->int:
    if is_prime(N):
        return 3*(N-1)
    return 3*(N-X)


if __name__ == "__main__":
    N, X = map(int, input().split())

    ans = mysterious_light(N, X)
    print(ans)

Submission status: Wrong Answer

Solution code:
N,X = map(int, input().split())
 
 
def para(a,b):
    if a == b:
        return a
    else:
        if a%b == 0:
            return (2*(a//b) -1)*b
        if a%b != 0:
            return  (2*(a//b) -1)*b + para(b,a%b)
if X >= N-X:
     print(N+para(X,N-X))
else:
     print(N+para(N-X,X))

Submission status: Wrong Answer

Solution code:
N,X = map(int, input().split())


def para(a,b):
    if a == b:
        return a
    else:
        if a%b == 0:
            return (2*(a//b) -1)*b
        if a%b != 0:
            return  (2*(a//b) -1)*b + para(b,a%b)
if X >= N-X:
     print(N+para(X,N-X))
if X <= N-X:
     print(N+para(N-X,X))

Submission status: Wrong Answer

Solution code:
N,X = map(int, input().split())


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

Submission status: Wrong Answer

Solution code:
N,X = map(int, input().split())


def para(a,b):
    if a == b:
        return a
    else:
        if a%b == 0:
            return (2*a//b -1)*b
        if a%b != 0:
            return  (2*a//b -1)*b + para(b,a%b)
if X >= N-X:
     print(N+para(X,N-X))
if X <= N-X:
     print(N+para(N-X,X))

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
x = X
y = N-X
if x<y:
    x,y = y,x
res = N
while y>0:
    x,y = y,x
    print(x,y)
    m = x*(y//x)
    res += m*2
    y -= m
res -= x
print(res)

Submission status: Wrong Answer

Solution code:
def calc(a,b,ans):
  if b==0:
    return ans
  else:
    if b!=1:
      return calc(b,a%b,ans+b*3)
    else:
      return calc(b,a%b,ans+a*3)

n,x=map(int,input().split())
n=n-x
n,x=max(n,x),min(n,x)
print(calc(n,x,0))

Submission status: Wrong Answer

Solution code:
def calc(a,b,ans):
  if b==0:
    return ans
  else:
    if b!=1:
      return calc(b,a%b,ans+b*3)
    else:
      return calc(b,a%b,ans+a*3)

n,x=map(int,input().split())
n,x=max(n,x),min(n,x)
print(calc(n,x,0))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
print((N-1)*3)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
ans=0
if x<n/2:
    a=x
    b=n-x
    ans+=n-x
    while True:
        if b%a==0:
            ans+=a*2*(b//a)
            break
        else:
            ans+=a*2*(b//a)
            a,b=b%a,a
elif x==n/2:
    ans=3*x
elif x>n/2:
    a=n-x
    b=x
    ans+=x
    while True:
        if b%a==0:
            ans+=a*2*(b//a)
            break
        else:
            ans+=a*2*(b//a)
            a,b=b%a,a

print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
ans=0
if x<n/2:
    a=x
    b=n-x
    ans+=x+n
    while True:
        if b%a==0:
            ans+=a*2*(b//a-1)
            break
        else:
            ans+=a*2*(b//a)
            a,b=b%a,a
elif x==n/2:
    ans=3*x
elif x>n/2:
    a=n-x
    b=x
    ans+=x
    while True:
        if b%a==0:
            ans+=a*2*(b//a)
            break
        else:
            ans+=a*2*(b//a)
            a,b=b%a,a

print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
ans=0
if x<n/2:
    a=x
    b=n-x
    ans+=x+n
    while True:
        if b%a==0:
            ans+=a*2*(b/a)
            break
        else:
            ans+=a*2*(b//a)
            a,b=b%a,a
elif x==n/2:
    ans=3*x
elif x>n/2:
    a=n-x
    b=x
    ans+=x
    while True:
        if b%a==0:
            ans+=a*2*(b/a)
            break
        else:
            ans+=a*2*(b//a)
            a,b=b%a,a

print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
print(n//2*3 if n/2==m else n*3-3)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
print(n//2*3 if n//2==m else n*3-3)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
print(n*3-3)

Submission status: Wrong Answer

Solution code:
n, x = [int(i) for i in input().split()]

cnt=0

short = min(x,n-x)
long  = max(x, n-x)
cnt += n
#cnt += x*(2*(n//x)-1) + (n-x)

while(1):
    c = long % short
    a = long //short
    if c==0:
        break
    else:
        cnt += short * 2 * a
        long = short
        short = c

cnt += short * 2 * a -1
print(cnt)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())

print(X * 6)

Submission status: Wrong Answer

Solution code:
N, X = list(map(int, input().split()))
ans = N
a, b = sorted([X, N - X])
while True:
    if b % a == 0:
        ans += (int(b / a) * 2 - 1)
        break
    else:
        ans += int(b // a) * a * 2
        a, b = b % a, a

print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
total = n
a = x
b = n - x
while a > 0:
    total += (a * 2) * (b // a)
    a, b = b % a, a
if n % 2 == 0:
    print(total)
else:
    print(total - 1)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
total = n
a = x
b = n - x
while a > 0:
    total += (a * 2) * (b // a)
    a, b = b % a, a
print(total - 1)

Submission status: Wrong Answer

Solution code:
n,x=map(int,raw_input().split())
if n<x:
    tmp=n
    n=x
    x=tmp
print 3*(n-1)

Submission status: Wrong Answer

Solution code:
n,x=map(int,raw_input().split())
print 3*(n-1)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
def f(a,b):
    if a>b:
        return f(b,a)
    if b%a==0:
        return a*(2*(b//a) + 1)
    return 2*(b//a) + f(b%a,a)
print(N+f(X,N-X))