TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
a = int(input())

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

b.sorted()

su = 0

for i in range(a-1):
  su += b[2*i]

a = int(input())

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

b.sorted()

su = 0

for i in range(a):
  su += b[2*i]

a = int(input())

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

b.sort()

su = 0

for i in range(a-1):
  su += b[2*i]
print(su)

a = int(input())

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

b.sort()

su = 0

for i in range(a):
  su += b[2*i]
print(su)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
n = int(n)
a = list(map(int, input().split()))

a.sort()

ans = 0
for i in range(n):
    ans += a[i*2]

print(ans)

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

a.sort()

ans = 0
for i in range(n):
    ans += a[i*2]

print(ans)

Verdicts: Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N):
  if i % 2 == 0:
    ans += L[i]
print (ans)

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

ans = 0
for i in range(2*N):
  if i % 2 == 0:
    ans += L[i]
print (ans)

Verdicts: Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
n = int(input())
s = list(map(int,input().split()))
s.sort()
sum = 0

for i in range(0,2n,2):
  sum += s[i]
print(sum)

n = int(input())
s = list(map(int,input().split()))
s.sort()
sum = 0

for i in range(0,2*n,2):
  sum += s[i]
print(sum)

Verdicts: Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
n=int(input())
l=list(map(int,input().split()))
 
l.sort()
k=l[::2]
sum=0
for i in range(n-2):
  sum += k[i]
  
print(sum)

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

l.sort()
k=l[::2]

print(k.sum())

n=int(input())
l=list(map(int,input().split()))
 
l.sort()
k=l[::2]
sum=0
for i in range(n):
  sum += k[i]
  
print(sum)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
n = int(input())
l = sorted(list(map(int,input().split())))

c = 0
for i in range(n):
    c +=l[i]
    print(c)

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

c = 0
for i in range(n//2):
    c +=l[i]
    print(c)

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

c = 0
for i in range(n):
    c +=l[i]
print(c)

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

c = 0
for i in range(n):
    c += l[2*i]
print(c)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):

num = int(input())
li = int(input().split())

print(num)
print(li)

n = int(input())
li = [int(x) for x in input().split()]

def skews(n,li):
    
    li = sorted(li)
    li = [l for i,l in enumerate(li) if i%2==0] 
    return sum(li)


print(skews(n,li))


Verdicts: Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=1)
ans=0
for i in range(1,n,2):
  ans+=l[i]
print(ans)

n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=1)
ans=0
for i in range(n):
  ans+=l[2*i+1]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
from collections import Counter
 
n = int(input())
 
arr = list(map(int, input().split()))
 
counts = Counter(arr)
 
res = 0
 
for k,v in counts.items():
  if v>=2:
    res += v//2
    counts[k] = v%2
    
items = sorted(counts.items())
for i in range(len(items)-1):
  res+=min(items[i], items[i+1])
  
print(res)

from collections import Counter

n = int(input())

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

counts = Counter(arr)

res = 0

for k,v in counts.items():
  if v>=2:
    res += v//2
    counts[k] = v%2
    
items = sorted(counts.items())
for i in range(len(items)-1):
  res+=min(items[i], items[i+1])
  
return res

n = int(input())
 
arr = list(map(int, input().split()))

arr.sort()

res = 0
i=0

while i<n:
  res+=min(arr[i], arr[i+1])
  i+=2
  
print(res)


n = int(input())
 
arr = list(map(int, input().split()))

arr.sort()

res = 0

for i in range(len(arr)-1):
  res+=min(arr[i], arr[i+1])
  
print(res)

n = int(input())
 
arr = list(map(int, input().split()))

arr.sort()

res = 0
i=0
l = len(arr)
while i<l:
  res+=min(arr[i], arr[i+1])
  i+=2
  
print(res)


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
N = int(input())
L = list(map(int, input().split()))
L.sort()
S = 0
for i in range (0, 2*N+1, 2):
  S += L[i]
print(S)

N = int(input())
L = list(map(int, input().split()))
L.sort()
S = 0
for i in range (1, 2*N+1, 2):
  S += L[i-1]
print(S)

Verdicts: Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
a = int(input())
b = list(map(int,input().split()))
b = sorted(b)
c = 0
for i in range(0,a,2):
    c += b[i]
print(c)

a = int(input())
b = list(map(int,input().split()))
b = sorted(b)
c = 0
for i in range(0,2*a,2):
    c += b[i]
print(c)

Verdicts: Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
a = sorted(list(map(int, input().split())))
ans = 0
for i in range(0, len(a), 2):
  ans += a[i]
print(ans)

n = input()
a = sorted(list(map(int, input().split())))
ans = 0
for i in range(0, len(a), 2):
  ans += a[i]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
def tri_len(x,y):
  if x== y:
    return x
  elif x < y:
    return tri_len(y-x,x)+2*x
  else:
    return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(10000)

n,x= list(map(int,input().split(" ")))

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

a = input()
lst = input().split(" ")
lst.sort()
ans=0
for i in range(int(len(lst))):
  ans += lst[len(lst)-2*i-2]

print(ans)

def tri_len(x,y):
  if x== y:
    return x
  elif x < y:
    return tri_len(y-x,x)+2*x
  else:
    return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(100000)

n,x= list(map(int,input().split(" ")))

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

a = input()
lst = list(map(int,input().split(" ")))
lst.sort()
ans=0
for i in range(int(len(lst)/2)):
  ans += lst[len(lst)-2*i-2]
 
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(a[::2])

n = int(input())
a = list(map(int, input().split()))
a.sort()
print(sum(a[::2]))

Verdicts: Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
ans=0
N=int(input())
kushi=[]
for s in range(N):
	kushi.append(input())
for s in range(N):
	kushi1="".join(kushi[s]).rstrip("\n").split(" ")
	for j in range(N-s):

		if j==0:	continue
		kushi2="".join(kushi[s+j]).rstrip("\n").split(" ")
		n=int(kushi1[0])+int(kushi2[0])+int(kushi1[1])+int(kushi2[1])
		k=int(kushi1[1])+int(kushi2[1])
		for m in range(k-1):
			n=n*(n-1)
			k=k*(k-1)
		ans+=n/k
		print(ans)

NX = input()
NX = "".join(NX).split(" ")
NX = [int(s) for s in NX]
D = NX[0]-NX[1]
if NX[0] ==0 or NX[1]==0:
	print(str(0))
if NX[1]<D:
	Mod = D%NX[1]
	if Mod!=0:
		print(int(2*NX[1]+NX[1]+(D-NX[1]/2)*3))
	else:
		print(int(NX[1]*4+D))
elif NX[1]==D:
	print(int(3*NX[1]))
elif NX[1]>D:	
	Mod = NX[1]%D
	if Mod!=0:
		print(int(NX[1]+(Mod*3)+D+(D*2*int(NX[1]/D))))
	else:
		print(int(NX[1]+int((NX[1]/D))*2*D))

N = int(input())
K = input()
K = "".join(K).split(" ")
K = [int(s) for s in K]
K.sort()
ans=0
for s in range(N):
	if int(K[-1])> int(K[-2]):
		ans+=int(K[-2])
	else:
		ans+=int(K[-1])
	del K[-2:]

print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
x,y=map(int,input().split())
z=3.5*y+x
print(z)

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

x=input()
y = sorted(list(map(int, input().split())))
i=1
z=0
for i in range(int(len(y)/2)):
     z+=y[-2*i]
     i+=1

print(z)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
n=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(0,n,2):
  ans+=L[i]
print(ans)


n=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(0,n*2,2):
  ans+=L[i]
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
#! /usr/bin/env python3

N, X = map(int, input().split())
if X*2 == N:
    print(X*3)
else:
    print(X*3*((N-X)//X + (1 if (N-X)%X>0 else 0)))

#! /usr/bin/env python3

N = int(input())
L = list(sorted(map(int, input().split())))
ans = 0
for i in range(N):
    ans += min(L[i*2], L[i*2+1])
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
import random

N = int(input())
L =[]
for i in range(N*2):
    guzai=random.randint(1,100)
    L.append(guzai)

L.sort()

print(L)
#print(L)
L_even=L[0::2]

goukei=sum(L_even)
print(str(goukei))


import random

N = int(input())
L =[]
for i in range(N*2):
    guzai=random.randint(1,100)
    L.append(guzai)

L.sort()
L_even=L[0::2]
goukei=sum(L_even)
print(str(goukei))

N = int(input())
L =[]

guzai=int(input())
L.append(guzai)

L.sort()
L_even=L[0::2]
goukei=sum(L_even)
print(str(goukei))


import random

N = int(input())
L =[]
for i in range(N*2):
    guzai=random.randint(1,100)
    L.append(guzai)

L.sort()

print(L)
L_even=L[0::2]

goukei=sum(L_even)
print(str(goukei))


N = int(input())
L =[]
for i in range(N*2):
    guzai=int(input())
    L.append(guzai)

L.sort()
L_even=L[0::2]
goukei=sum(L_even)
print(str(goukei))

import random

N = int(input('Nの値を決めてください(1<=N<=100)'))
L =[]
for i in range(N*2):
    guzai=random.randint(1,100)
    L.append(guzai)

L.sort()
print(L)
L_even=L[0::2]

goukei=sum(L_even)
print(str(goukei))


N = [int(v) for v in input().split()]
L = [int(v) for v in input().split()]
L.sort()
L_even=L[0::2]
goukei=sum(L_even)
print(str(goukei))


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
n = int(input())
L = list(map(int, input().split())
L.sort()
array_L = []
for m in [i * 2 for i in range(n)]:
    array_L.append(L[m])
print(sum(array_L))
    

n = int(input())
L = list(map(int, input().split()))
L.sort()
array_L = []
for m in [i * 2 for i in range(n)]:
    array_L.append(L[m])
print(sum(array_L))
    


Verdicts: Runtime Error

Accepted
Problem: Snuke is having a barbeque party.  At the party, he will make N servings of _Skewer Meal_.    Example of a serving of Skewer Meal  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i. Also, he has an infinite supply of ingredients.  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.  What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Submission attempts (in order):
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=sum(l[1::2])
print(ans)

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = sum(l[0::2])
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)

n, x = map(int, input().split())
print(3*gcd(n, x))

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)

n, x = map(int, input().split())
print(3*(n - gcd(n, x)))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, X = map(int, input().split())
Y = N - X

if 2 * X == N:
	print(X*3)
elif 2 * X < N:
	ans = Y + 3 * X
	a = N-2*X
	b = X
	
	if a < b:
		ans += ((X // a) * 2 - 1) * a
	else:
		ans += ((X // b) * 2 - 1) * b
	raise NameError('NG!')
	print(ans)
else:  # 2 * X < N
	ans = X
	ans += ((X // Y) * 2) * Y
	print(ans)


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

ans = N

while True:
	if X == Y:
		ans += X
		break
	else:
		if X > Y:
			tmp = X
			X = Y
			Y = tmp
		a = Y % X
		b = Y // X
		if a == 0:
			ans += (b*2 - 1) * X
			break
		else:
			ans += b*2*X
		Y = X
		X = a
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,X = map(int, input().split())
print(N)
print(X)

def para(a,b):
    if a > b:
        return 2*b + para(b,a-b)
    if a < b:
        return 2*a + para(b-a,a)
    if a == b:
        return a
print(N+para(X,N-X))

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

def para(a,b):
    if a > b:
        return a+b + para(b,a-b)
    if a < b:
        return 2*a + para(a,b-a)
    if a == b:
        return 3*a
print(X+para(X,N-X))

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))


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))

N,X = map(int,input().split(" "))
 
Y,X = sorted([N - X,X])
 
s = 0
while Y:
    s += (X//Y)*Y*3
    Y,X = [X%Y,Y]
 
print(s)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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
    m = x*(y//x)
    res += m*2
    y -= m
res -= x
print(res)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
sys.setrecursionlimit(1500)

def f(x, y):
    if y == 0:
        return 0
    if x == y:
        return x
    x, y = min(x, y), max(x, y)
    return 2 * (y // x) * x + f(x, y % x)

N, X = list(map(int, input().split()))
print(f(X, N-X) + N)


import sys
sys.setrecursionlimit(1500)

def f(x, y):
    if x == y:
        return x
    x, y = min(x, y), max(x, y)
    return 2 * (y // x) * x + f(x, y % x)

N, X = list(map(int, input().split()))
print(f(X, N-X) + N)


import sys
sys.setrecursionlimit(1500)

def f(x, y):
    if x == 0:
        return 0
    if x == y:
        return x
    return 2 * (y // x) * x + f(y % x, x)

N, X = list(map(int, input().split()))
print(f(X, N-X) + N)


import sys
sys.setrecursionlimit(1500)

def f(x, y):
    if x == 0:
        return 0
    if y % x == 0:
        return 2 * (y // x) * x - x
    return 2 * (y // x) * x + f(y % x, x)

N, X = list(map(int, input().split()))
print(f(X, N-X) + N)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    n,x=map(int,input().split())
    a,b=n-x,x
    if(a<b):
       a,b=b,a
    path_length = calc_path(a,b,n)
    print(path_length)

def  calc_path(a1,b1,c1):
    q , mod=divmod(a1,b1)
    count=0
    if mod==0:
         print(c1)
         c2=c1+2*b1*q-b1
         print(c2)
         return c2
    else:
        count=count+1
        c2=c1+2*b1*q
        a2=a1-b1*q
        b2=b1
        if(a2<b2):
           a2,b2=b2,a2
        return calc_path(a2,b2,c2)
if __name__=='__main__':
  main()


def main():
    n,x=map(int,input().split())
    a,b=n-x,x
    if(a<b):
       a,b=b,a
    path_length = calc_path(a,b,n)
    print(path_length)

def  calc_path(a1,b1,c1):
    q , mod=divmod(a1,b1)
    count=0
    if mod==0:
         c2=c1+2*b1*q-b1
         return c2
    else:
        count=count+1
        c2=c1+2*b1*q
        a2=a1-b1*q
        b2=b1
        if(a2<b2):
           a2,b2=b2,a2
        return calc_path(a2,b2,c2)
if __name__=='__main__':
  main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def gcd(a,b):
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
N,X=map(int,input().split())
print(3*(N-gcd(N,X))


def gcd(a,b):
  if a%b==0:
    return b
  else:
    return gcd(b,a%b):
N,X=map(int,input().split())
print(3*(N-gcd(N,X))

def gcd(a,b):
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
N,X=map(int,input().split())
print(3*(N-gcd(N,X)))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)

def rec(a: int, b: int) -> int:
    mx = max(a,b)
    mn = min(a,b)
    if gcd(a,b) == mn:
        return (2 * (mx // mn) - 1) * mn
    
    else:
        return (2 * (mx // mn) * mn)  + rec(mn, mn * (mx // mn))
    
n,x = li()
print(n + rec(x, n-x))

import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)

def rec(a: int, b: int) -> int:
    mx = max(a,b)
    mn = min(a,b)
    if gcd(a,b) == mn:
        return (2 * (mx // mn) - 1) * mn
    
    else:
        return (2 * (mx // mn) * mn)  + rec(mn, mx - mn * (mx // mn))
    
n,x = li()
print(n + rec(x, n-x))
    

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from math import floor
N, X = [int(x) for x in input().split()]

print(N, X)

x0 = N
x1 = X
x2 = x0-x1
L = 2*X
c = 1
while x2 > 0:
	k = floor(x0/(x1/2))-1
	L += x1*k
	x0, x1, x2 = (x1, x2, x0-x1)

print(L)

# your code goes here
from math import floor
N, X = [int(x) for x in input().split()]

y = N-X
x = X
L = X
while x > 0:
#	k = 2*floor(y/x)
	k, z = divmod(y, x)
	dL = x*(2*k-1)+y
	L += x*(2*k-1)+y
	print(x, y, k, dL)
	y, x = (x, z)

#L += y
print(L)

# your code goes here
from math import floor
N, X = [int(x) for x in input().split()]

y = N-X
x = X
L = X
while x > 0:
#	k = 2*floor(y/x)
	k, z = divmod(y, x)
#	dL = x*(2*k-1)+y
	L += x*(2*k-1)+y
#	print(x, y, k, dL)
	y, x = (x, z)

#L += y
print(L)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def f(a,b):
	return 2*a + f_fast(a,b-a)



def f_fast(a,b):
	if a==b:
		return a+b
	elif a < b:
		if b%a == 0:
			return f(a,b)
		else:
			d = b//a
			return 2*a*d + f_fast(a,b%a)
	else:
		return f_fast(b,a)


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

print(N+f_fast(N-X,X))

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


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

print(N+f(N-X,X))

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


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

print(N+f(N-X,X))

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


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

print(N+f(N-X,X))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**15)

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

N,X=map(int,input().split())
print(f(X,N-X)+N)


import sys
sys.setrecursionlimit(10**7)

def f(a,b):
    if a==b:return a
    if not a<b:a,b=b,a
    return 2*(b//a)*a+f(a,b%a) if b%a else 2*(b//a)*a-a

N,X=map(int,input().split())
print(f(X,N-X)+N)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math
n, x = map(int, input().split())
print(3 * (n - gcd(n, x)))


import math
n, x = map(int, input().split())
print(3 * (n - math.gcd(n, x)))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n, x = map(int, input().split())

def func(a, b):
    if a < b:
        if b%a == 0:
            return b/a*2 - 1
        else:
            return 2*a + func(a, b-a)
    else:
        if a%b == 0:
            return a/b*2 - 1
        else:
            return 2*b + func(a-b, b)
            
if x == n/2:
    print(3*x)
else:
    print(x+(n-x)+func(x,n-x))

# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, x = LI()

    b, a = sorted([x, n - x])
    ans = a + b
    while b:
        q, mod = divmod(a, b)
        ans += (2 * q - (not mod)) * b
        a, b = b, mod

    return ans


print(main())


Verdicts: Runtime Error

Accepted