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

Fixed submission:
import sys
t = sys.stdin.readline()

t1 = t.rstrip()

t2 = t1.split(' ')

T = int(t2[0])
A = int(t2[1])
B = int(t2[2])
p1 = A*T

if B < p1:
    print(B)
elif B > p1:
    print(p1)
else:
    print(B)

Buggy submission (verdict: Runtime Error):
import sys

t = sys.stdin.readline()
a = sys.stdin.readline()
b = sys.stdin.readline()

t1 = t.rstrip()
a1 = a.rstrip()
b1 = b.rstrip()

T = int(t1)
A = int(a1)
B = int(b1)


p1 = A*T

if B < p1:
    print(B)
elif B > p1:
    print(p1)
else:
    print(B)

Buggy submission (verdict: Runtime Error):
import sys

a = sys.stdin.readline()
b = sys.stdin.readline()
t = sys.stdin.readline()

a1 = a.rstrip()
b1 = b.rstrip()
t1 = t.rstrip()

A = int(a1)
B = int(b1)
T = int(t1)

p1 = A*T

if B < p1:
    print(B)
elif B > p1:
    print(p1)
else:
    print(B)
Problem p03337 (python)

Fixed submission:
A, B = [int(i) for i in input().split()]
List = [A+B, A-B, A*B]
List = sorted(List)
print(List[2])

Buggy submission (verdict: Runtime Error):
A, B = [int(i) for i in input().split()]
List = [A+B, A-B, A*B]
List = sorted(List)
print(List[3])
Problem p03219 (python)

Fixed submission:

# coding: utf-8

# In[1]:


x,y = map(int,input().split())


# In[2]:


y = y/2


# In[3]:


z = x + y


# In[8]:


print(int(z))

Buggy submission (verdict: Runtime Error):
X,Y = map(int,input().split())
Y = Y/2
z = Z + Y
print(z)
Problem p03238 (python)

Fixed submission:
N = int(input())
if N == 1:
    print('Hello World')
else :
    a = int(input())
    b = int(input())
    print(a + b)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print('Hello World')
else if N == 2:
    a = int(input())
    b = int(input())
    print(a + b)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print('Hello World')
else if N == 2:
    a = input(input())
    b = input(input())
    print(a + b)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print('Hello World')
else:
    a = input(input())
    b = input(input())
    print(a + b)
Problem p03238 (python)

Fixed submission:
age = int(input())
if age == 1:
  print("Hello World")
else:
  a=int(input())
  b=int(input())
  print(a+b)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n,t = map(int,input().split())
ans_no = 0
ans_cost = t

for i in range(n):
    a,b = map(int,input().split())
    if b<ans_cost:
        ans_no = a

if ans_no == 0:
    print("TLE")
else print(ans_no)
Problem p03239 (python)

Fixed submission:
# -*- coding: utf-8 -*-
n,t = map(int,input().split())
ans_cost = 10000
ans_time = t

for i in range(n):
    a,b = map(int,input().split())
    if b<=ans_time:
        if a<ans_cost:
            ans_cost = a


if ans_cost == 10000:
    print("TLE")
else:
     print(ans_cost)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n,t = map(int,input().split())
ans_cost = float('inf')
ans_time = t

for i in range(n):
    a,b = map(int,input().split())
    if b=ans_time:
        if a<ans_cost:
            ans_cost = a


if ans_cost == float('inf'):
    print("TLE")
else:
     print(ans_cost)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n,t = map(int,input().split())
ans_no = 0
ans_cost = t

for i in range(n):
    a,b = map(int,input().split())
    if b<ans_cost:
        ans_no = a

if ans_no = 0:
    print("TLE")
else print(ans_no)
Problem p03469 (python)

Fixed submission:
# -*- coding: utf-8 -*-
s = input()
print(s[:3]+"8"+s[4:])

Buggy submission (verdict: Runtime Error):
s = input()
s[3] = '8'
print(s)
Problem p03369 (python)

Fixed submission:
ans=700
for i in list(input()):
    if i=='o':
        ans += 100
print(ans)

Buggy submission (verdict: Runtime Error):
A,B,C,X,Y = map(int,input().split())

if X>Y:
    print(min( A*X+B*Y , 2*C*X , 2*C*Y+A*(X-Y)))
else:
    print(min( A*X+B*Y , 2*C*Y , 2*C*X+A*(Y-X)))
Problem p03219 (python)

Fixed submission:
x, y = map(int, input().split())
print(x+y//2)

Buggy submission (verdict: Runtime Error):
print(int(input())+int(input())/2)
Problem p03260 (python)

Fixed submission:
a, b = map(int, input().split())
if (a*b)%2 == 0:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
c = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
for i in range(l+1, 0, -1):
    if l % i == 0:
        d = True
        for item in c:
            if item % i != 0:
                d = False
        if d:
            print(i)
            break

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
c = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
f = [l]
if l < 999999999:
    for i in range(1, l):
        if l % i == 0:
            f.append(i)
for i in range(len(f), 0, -1):
    d = True
    for item in c:
        if item % f[i-1] != 0:
            d = False
    if d:
        print(f[i-1])
        break

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
c = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
f = set()
for i in range(1, l+1):
    if l % i == 0:
        f.add(i)
for i in range(len(f), 0, -1):
    d = True
    for item in c:
        if item % i != 0:
            d = False
    if d:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
c = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
for i in range(l, 0, -1):
    d = True
    for item in c:
        if item % i != 0:
            d = False
    if d:
        print(i)
        break
Problem p03262 (python)

Fixed submission:
n, x = map(int, input().split())
c = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
for i in range(l+1, 0, -1):
    if l % i == 0:
        d = True
        for item in c:
            if item % i != 0:
                d = False
        if d:
            print(i)
            break

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
c = list(map(int, input().split()))
dis = set()
for i in range(1, n):
    dis.add(abs(c[i] - c[i-1]))
l = min(dis)
for i in range(l, 0, -1):
    d = True
    for item in dis:
        if item % i != 0:
            d = False
    if d:
        print(i)
        break
Problem p03219 (python)

Fixed submission:
number=input().split(" ")
x=int(number[0])
y=int(number[1])
z=x+y/2
print(int(z))

Buggy submission (verdict: Runtime Error):
list=input().split("\n")
number=int(list[0])
list_2=list[1].split(" ")
t=int(list_2[0])
a=int(list_2[1])
list_3=list[2].spilit(" ")
index=1
min=abs(a-(t-int(list_3[0])))
target_index=1
for height in list_3:
    temp=t-int(height)*0.006
    diff=abs(a-temp)
    if diff < min :
        min = diff
        target_index = index
    index += 1    
print(target_index)

Buggy submission (verdict: Runtime Error):
f=input.split(" ")
x=f[1]
y=f[2]
z=x+y/2
print(z)

Buggy submission (verdict: Runtime Error):
f=input().split(" ")
x=f[1]
y=f[2]
z=x+y/2
print(z)

Buggy submission (verdict: Runtime Error):
f=input()
number=f.split(" ")
x=number[1]
y=number[2]
z=x+y/2
print(z)

Buggy submission (verdict: Runtime Error):
f=input("string is:")
number=f.split(" ")
x=number[1]
y=number[2]
z=x+y/2
print(z)

Buggy submission (verdict: Runtime Error):
x=input("X:")
y=input("Y:")
z=x+y/2
print(z)

Buggy submission (verdict: Runtime Error):
x=int(input("X:"))
y=int(input("Y:"))
z=x+y/2
print(z)

Buggy submission (verdict: Runtime Error):
x=int(input("X:"))
y=eval(input("Y:"))
z=x+y/2
print(z)
Problem p03219 (python)

Fixed submission:
x,y = map(int ,input().split())
print(int(x+y/2))

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
t,a = map(int,input().split())
hight = list(map(int, input().split()))
ans = 100000
ansnumber = 0

for num,i in enumerate(hight):
    tmp = math.fabs(t-i*0.006 - a)
    if ans > tmp:
         ans = tmp
         ansnumber = num+1

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
t,a = map(int,input().split())
hight = list(map(int, input().split()))
ans = 100000
ansnumber = 0
for num,i in enumerate(hight):
    tmp = math.fabs(i - a)
    if ans > tmp:
         ans = tmp
         ansnumber = num+1
print(ansnumber)

Buggy submission (verdict: Runtime Error):
a, b = (int(i) for i in input().split())  
echo(a, b)

Buggy submission (verdict: Runtime Error):
x,y = input().split
print(int(x)+int(y)/2)

Buggy submission (verdict: Runtime Error):
x = int(input())
y = int(input())
print(x + y/2)
Problem p03311 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
a = sorted([x - i - 1 for i, x in enumerate(A)])
c = a[N // 2]
print(sum([abs(i - c) for i in a]))

Buggy submission (verdict: Runtime Error):
n = int(input())
d,x = map(int, input().split())
times = [int(input()) for i in range(n)]

count = 0
for k in range(n):
    count += int(d/times[k]) + 1

print(count + x)
Problem p03337 (python)

Fixed submission:
a,b = map(int, input().split() )
result=[]
s = a+b
result.append(s)
s = a*b
result.append(s)
s = a-b
result.append(s)
print(max(result))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(input())
count=0
counts=[]
for i in range(n):
    east,west = s[:i],s[i+1:]
    for n in east:
        if n=="W":
            count+=1
    for e in west:
        if e == "E":
            count +=1
    counts.append(count)
    
print(min(counts))
Problem p03351 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
if abs(a-b)<=d and abs(b-c)<=d:
     print("Yes")
elif abs(a-c)<=d:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
res = 1
for i in range(1,n+1):
    for k in range(2,1+n):
        num = i**k
        if num > n:
            break
        if num <= n :
            res = max(res,num)
    
print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
res = 1
for i in range(1,n+1):
    for k in range(1,1+n):
        num = i**k
        if num <= n :
            res = max(res,num)
    
print(res)
Problem p03359 (python)

Fixed submission:
a,b=map(int,input().split())
if b>=a:
  print(a)
else:
  print(a-1)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int(), input().split())
k = int(input())
kk=2**k
m = max(a,b,c)
al = a+b+c-m+kk*m
print(al)

Buggy submission (verdict: Runtime Error):
a,b = map(int() , input().split())
count=0
for i in range(1,a+1):
    for n in range(1b+1):
        if i==n:
            count+=1

Buggy submission (verdict: Runtime Error):
a,b = map(int, input().split())
count=0
for i in range(1,a+1):
    for n in range(1b+1):
        if i==n:
            count+=1

print(count)
Problem p03360 (python)

Fixed submission:
a,b,c = map(int, input().split())
k = int(input())
kk=2**k
m = max(a,b,c)
al = a+b+c-m+m*kk
print(al)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int(), input().split())
k = int(input())
kk=2**k
m = max([a,b,c])
al = a+b+c-m+kk*m
print(al)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int(), input().split())
k = int(input())
kk=2**k
m = max(a,b,c)
al = a+b+c-m+kk*m
print(al)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int(), input().split())
k = int(input())

m = max(a,b,c)
al = a+b+c-m+m*2**k
print(al)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int(), input().split())
k = int(input())

m = max(a,b,c)
al = a+b+c-m+m**K
print(al)
Problem p03377 (python)

Fixed submission:
x,y,z=map(int,input().split())
if x <= z <= x+y :
  print("YES")
else:
  print("NO")

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

for i in range(n):
    li.sort()
    a =  li[i]
    b = li[int((n+1)/2)]
    print(b)
    li.append(a)

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

for i in range(1,1+n):
    li.sort()
    a =  li[i]
    li.pop(i)
    b = li[int((n+1)/2)]
    print(b)
    li.append(a)

Buggy submission (verdict: Runtime Error):
a,b,x = map(int(), input().split())
if a+b > x:
    print("YES")
else:
    print("NO")
Problem p03378 (python)

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

result = len(set(range(0,X))&A)
result = min(result, len(set(range(X,N))&A))

print(result)

Buggy submission (verdict: Runtime Error):
n,m,x = map(int , input().split())

tax = [input() for i in range(m)]
alltax = len(tax)
atax = len(tax[:x])
btax = alltax-atax
if atax > btax:
    print(btax)
else:
    print(atax)
Problem p03386 (python)

Fixed submission:
A,B,K = map(int,input().split())
if (B - A + 2)//2 <= K:
    L = list(range(A,B+1))
else:
    L = list(range(A,A+K)) + list(range(B-K+1,B+1))
for i in L:
    print(i)

Buggy submission (verdict: Runtime Error):
a,b,k = map(int,input().split())

li = [i for i in range(a,b+1)]
print(li[0])
print(li[k-1])
print(li[b+1-k-a])
print(li[b-a])

Buggy submission (verdict: Runtime Error):
a,b,k = map(int,input().split())

li = [i for i in range(a,b+1)]
print(li[0])
print(li[k-1])
print(li[-k])
print(li[-1])
Problem p03400 (python)

Fixed submission:
N=int(input())
D,X=map(int,input().split())
ans=0
for _ in[0]*N:
    A=int(input())
    ans+=(D+A-1)//A
print(ans+X)

Buggy submission (verdict: Runtime Error):
n = int(input())
d,x = map(int(), input().split())
times = [int(input()) for i in range(n)]

count = 0
for k in range(n):
    count += int(d/times[k]) + 1

print(count + x)
Problem p03219 (python)

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


def Discount_Fare():
    X, Y = [int(n) for n in input().split()]
    print(X + (Y // 2))


if __name__ == '__main__':
    Discount_Fare()

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


def ID():
    N, M = [int(n) for n in input().split()]
    lst = [[n for n in input().split()] for _ in range(M)]
    sorted_lst = sorted(lst, key=lambda x: int(x[1]))
    memo = {}
    result = {}
    for p, x in sorted_lst:
        if p not in memo:
            memo[p] = 1
        else:
            memo[p] += 1
        higher = p.zfill(6)
        lower = "{0:06d}".format(memo[p])
        result[p + x] = higher + lower

    for p, x in lst:
        print(result[p+x])


if __name__ == '__main__':
    ID()
Problem p03219 (python)

Fixed submission:
x, y = (int(i) for i in input().split())

print(int(x+y/2))

Buggy submission (verdict: Runtime Error):
N = int(input())
T, A = (int(i) for i in input().split())
H = [int(i) for i in input().split()]

H_T = [0 for i in range(len(H))]
for i in range(len(H)):
    H_T[i] = float(T) - float(H[i])*0.006

min = 1000
index = 0
for i in range(len(H_T)):
    if(abs(H_T[i] - A) < min):
        index = i
        min = abs(H_T[i] - A)
print(index+1)
Problem p03219 (python)

Fixed submission:
x,y = map(int,input().split())
print('{}'.format(int(x+(y/2))))

Buggy submission (verdict: Runtime Error):
X,Y = map(int, intput().split())
print("{}".format(X+(Y/2)))
Problem p03455 (python)

Fixed submission:
a,b=map(int,input().split())
print('Even' if a*b%2==0 else 'Odd')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input())
print('Even' if (a*b)&1==0 else 'Odd')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input())
print('Even'if((a*b)&1==0)else'Odd')
Problem p03220 (python)

Fixed submission:
def htemp(t, x):
    return float(t - 0.006 * x)
    
input()
lt, la = [int(x) for x in input().split()]
h_ary = [int(x) for x in input().split()]
    
maxdiff = float('inf')
goodpoint = 0
for i, h in enumerate(h_ary):
    diff = abs(la - htemp(lt, h))
    if diff < maxdiff:
        maxdiff = diff
        goodpoint = i
print(goodpoint+1)

Buggy submission (verdict: Runtime Error):
    def htemp(t, x):
        return float(t - 0.006 * x)
     
    input()
    lt, la = [int(x) for x in input().split()]
    h_ary = [int(x) for x in input().split()]
     
    maxdiff = float('inf')
    goodpoint = 0
    for i, h in enumerate(h_ary):
        diff = abs(la - htemp(lt, h))
        if diff < maxdiff:
            maxdiff = diff
            goodpoint = i
    print(goodpoint+1)
Problem p03455 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = a * b 
amari = c % 2
if amari == 1 :
    print("Odd")

elif amari == 0 :
    print("Even")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a = int(input())
b = int(input())
c = a * b 
amari = c % 2
if(amari == 1 ){
    print("Odd")
}
else(amari == 0){
    print("Even")
}
Problem p03282 (python)

Fixed submission:
S=input()
K=int(input())

ans = '1'
pos = 0

while(ans=='1' and pos<K):
  if S[pos] != '1':
    ans = S[pos]
  pos+=1
  
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())

ans = '1'
pos = 0

while(ans=='1' and pos<=K):
  if S[pos] != '1':
    ans = S[pos]
  pos+=1
  
print(ans)
Problem p03220 (python)

Fixed submission:
N=int(input())
T,A=list(map(lambda x:float(x),input().split()))
H_list = list(map(lambda x:float(x),input().split()))
diff = [abs(T-x*0.006-A) for x in H_list]
i=diff.index(min(diff))
print(i+1)

Buggy submission (verdict: Runtime Error):
N=int(input())
T,A=list(map(lambda x:float(A),input().split()))
H_list = list(map(lambda x:float(A),input().split()))
diff = [abs(T-x*0.006-A) for x in H_list]
i=diff.index(min(diff))
print(i+1)
Problem p03231 (python)

Fixed submission:
import sys,fractions
N,M=map(int,input().split())
S=input()
T=input()

x=1

gcd=fractions.gcd(M,N)

if gcd==0:
  print(-1)
  sys.exit()

if S[0]!=T[0]:
  print(-1)
  sys.exit()

lst=[S[0]]


lcm=(M*N)//gcd
dn=lcm//N
dm=lcm//M

dlcm=(dn*dm)//fractions.gcd(dn,dm)

for i in range(lcm//dlcm):
  if S[dlcm*i//dn] != T[dlcm*i//dm]:
    print(-1)
    sys.exit()
print(lcm)

Buggy submission (verdict: Runtime Error):
import sys,fractions
N,M=map(int,input().split())
S=input()
T=input()

x=1

gcd=fractions.gcd(M,N)

if gcd==0:
  print(-1)
  sys.exit()

if S[0]!=T[0]:
  print(-1)
  sys.exit()

lst=[S[0]]


lcm=(M*N)//gcd
dl=lcm//N
for i in range(1,N):
  lst+=['-']*(dl-1)+[S[i]]

dl=lcm//M
for i in range(1,M):

  if len(lst)<(i*dl):
    lst+=['-']*(i*dl-len(lst))
  if lst[i*dl] == '-' or lst[i*dl] == T[i]:
    lst[i*dl]=T[i]
  else:
    print(-1)
    sys.exit()
print(lcm)

Buggy submission (verdict: Runtime Error):
import sys,fractions
N,M=map(int,input().split())
S=input()
T=input()

x=1

if S[0]!=T[0]:
  print(-1)
  sys.exit()

lst=[S[0]]


lcm=(M*N)//fractions.gcd(M,N)
dl=lcm//N
for i in range(1,N):
  lst+=['-']*(dl-1)+[S[i]]

dl=lcm//M
for i in range(1,M):

  if len(lst)<(i*dl):
    lst+=['-']*(i*dl-len(lst))
  if lst[i*dl] == '-' or lst[i*dl] == T[i]:
    lst[i*dl]=T[i]
  else:
    print(-1)
    sys.exit()
print(lcm)
Problem p03254 (python)

Fixed submission:
N,x=map(int,raw_input().split())
a=sorted(map(int,raw_input().split()))
ans=0
for i in xrange(N):
  x-=a[i]
  if x<0 or i==N-1 and x>0:
    break
  else:
    ans+=1
print ans

Buggy submission (verdict: Runtime Error):
a=sorted(map(int,raw_input().split()))
ans=0
for i in xrange(N):
  x-=a[i]
  if x<0 or i==N-1 and x>0:
    break
  else:
    ans+=1
print ans
Problem p03223 (python)

Fixed submission:
def main():
    N = int(input())
    A=[int(input()) for x in range(N)]

    A.sort()
    s = 0
    e = N - 1
    L = A[0]
    R = A[e]
    ret1 = R - L
    while True:
        ss = s + 1
        ee = e - 1

        b = max(abs(L - A[ss]), abs(R - A[ss])) > max(abs(L - A[ee]), abs(R - A[ee]))

        if b:
            s += 1
            if abs(L - A[s]) < abs(R - A[s]):
                ret1 += abs(R - A[s])
                R = A[s]
            else:
                ret1 += abs(L - A[s])
                L = A[s]
        else:
            e -= 1
            if s == e: break
            if abs(L - A[e]) < abs(R - A[e]):
                ret1 += abs(R - A[e])
                R = A[e]
            else:
                ret1 += abs(L - A[e])
                L = A[e]
        if s == e: break

    # 出力
    print("{}".format(ret1))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A=[int(input()) for x in range(N)]

    A.sort()
    s = 0
    e = N - 1
    L = A[0]
    R = A[e]
    ret1 = R - L
    while True:
        ss = s + 1
        ee = e + 1

        b = max(abs(L - A[ss]), abs(R - A[ss])) > max(abs(L - A[ee]), abs(R - A[ee]))

        if b:
            s += 1
            if abs(L - A[s]) < abs(R - A[s]):
                ret1 += abs(R - A[s])
                R = A[s]
            else:
                ret1 += abs(L - A[s])
                L = A[s]
        else:
            e -= 1
            if s == e: break
            if abs(L - A[e]) < abs(R - A[e]):
                ret1 += abs(R - A[e])
                R = A[e]
            else:
                ret1 += abs(L - A[e])
                L = A[e]
        if s == e: break

    # 出力
    print("{}".format(ret1))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():

    N = int(input())

    A.sort()
    s=0
    e=N-1
    L=A[0]
    R=A[e]
    ret1 = R-L
    while True:
        ss=s+1
        ee=e+1

        b=max(abs(L-A[s]),abs(R-A[s])) > max(abs(L-A[e]),abs(R-A[e]))

        if b:
            s+=1
            if abs(L-A[s]) < abs(R-A[s]):
                ret1 += abs(R-A[s])
                R=A[s]
            else:
                ret1 += abs(L-A[s])
                L=A[s]
        else:
            e-=1
            if s == e: break
            if abs(L-A[e]) < abs(R-A[e]):
                ret1 += abs(R-A[e])
                R=A[e]
            else:
                ret1 += abs(L-A[e])
                L=A[e]
        if s==e: break



    # 出力
    print("{}".format(ret1))

if __name__ == '__main__':
    main()
Problem p03231 (python)

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

import sys
import itertools
import math

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

def main():
    N, M = map(int, input().split())
    S = input()
    T = input()

    if N < M:
        t = M
        M = N
        N = t
        q = S
        S = T
        T = q

    d = gcd(N,M)
    c = N * M // d

    ret = -1
    slen = c
    nstep = slen // N
    mstep = slen // M

    dd = gcd(nstep, mstep)
    cc = nstep * mstep // dd

    good = True
    for k in range(0, slen, cc):
        u = (k // nstep) % N
        j = (k // mstep) % M
        if S[u] != T[j]:
            good = False
            break
    if good:
        ret = slen

    # 出力
    print("{}".format(ret))


if __name__ == '__main__':
    main()

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

import sys
import itertools
import math

N, M = map(int, input().split())
S = input()
T = input()

if N < M:
    t = M
    M = N
    N = t
    q = S
    S = T
    T = q

d = math.gcd(N, M)

n = N / d

ret = -1
for step in range(1, M+1):
    slen = step * N
    if slen % M != 0:
        continue
    mstep = slen // M
    good = True
    for i in range(N):
        u = (step * i) % mstep
        if u != 0:
            continue
        j = (step * i) // mstep
        if S[i] != T[j]:
            good = False
            break
    if good:
        ret = step * N
        break

# 出力
print("{}".format(ret))

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

import sys
import itertools
import math

def main():
    N, M = map(int, input().split())
    S = input()
    T = input()

    if N < M:
        t = M
        M = N
        N = t
        q = S
        S = T
        T = q

    d = math.gcd(N, M)

    n = N / d

    ret = -1
    for step in range(1, M+1):
        slen = step * N
        if slen % M != 0:
            continue
        mstep = slen // M
        good = True
        for i in range(N):
            u = (step * i) % mstep
            if u != 0:
                continue
            j = (step * i) // mstep
            if S[i] != T[j]:
                good = False
                break
        if good:
            ret = step * N
            break

    # 出力
    print("{}".format(ret))


if __name__ == '__main__':
    main()