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

Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
dp=[0,abs(h[1]-h[0])]

for ind in range(2,len(h)):
    a=abs(h[ind-1]-h[ind])
    b=abs(h[ind-2]-h[ind])
    if(a+dp[ind-1]>b+dp[ind-2]):
        dp.append(b+dp[ind-2])
    else:
        dp.append(a+dp[ind-1])
print(dp[len(dp)-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
h=[int(i) for i in input().split()]

dp=[10000 for i in range(n+1)]
dp[0]=0
for i in range(n-1):
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
    dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]))
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
h=[int(i) for i in input().split()]
dp=[10000 for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
dp[2]=abs(h[2]-h[0])

for i in range(1,len(h)-2):
    x=abs(h[i+1]-h[i])+dp[i]
    y=abs(h[i+2]-h[i])+dp[i]
    if(dp[i+1]>x):
      dp[i+1]=x
    if(dp[i+2]>y):
      dp[i+2]=y

if(dp[n-1]>abs(h[n-1]-h[n-2])+dp[n-2]):
	dp[n-1]=abs(h[n-1]-h[n-2])+dp[n-2]
print(dp[n-1])
Problem p03633 (python)

Fixed submission:
def gcd(x,y):
  if x>y: x,y = y,x
  while x:
    x,y = y%x, x
  return y

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

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)

Buggy submission (verdict: Runtime Error):

def gcd(x,y):
  if x>y: x,y = y,x
  while x:
    x,y = y%x, x
  return y

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

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math
def lcm(a,b):
    return int(a*b /math.gcd(a,b))

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
if(n==1):
    print(t[0])
    exit()
ans=lcm(t[0],t[1])
if(n==2):
    print(ans)
    exit()
for i in range(2,n):
    ans=lcm(ans,t[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math
def lcm(a,b):
    return int(a*b /math.gcd(a,b))

n=int(input())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
ans=lcm(t[0],t[1])
for i in range(2,n-1):
    ans=lcm(ans,t[i])
print(ans)
Problem p03731 (python)

Fixed submission:
n, T = map(int, input().split())
t = list(map(int, input().split()))
 
ans = 0
for i in range(1, n):
    ans += min(t[i] - t[i-1], T)
print(ans + T)

Buggy submission (verdict: Runtime Error):
from bitarray import bitarray
n,T=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]

ans=0
for i in range(n-1):
    start=t[i]
    end=start+T
    if(end>t[i+1]):
        ans+=t[i+1]-t[i]
    else:
        ans+=T
ans+=T
print(ans)

Buggy submission (verdict: Runtime Error):
from bitarray import bitarray
n,T=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]

ans=0
a = bitarray(100000)
a.setall(0)
for i in range(n):
    start=t[i]
    end=start+T
    a[start:end]=1
print(a.count())
Problem p03740 (python)

Fixed submission:
x,y=[int(i) for i in input().split()]
if(abs(x-y)<=1):
    print('Brown')
else:
    print('Alice')

Buggy submission (verdict: Runtime Error):
x=int(input())
y=int(input())
if(abs(x-y)<=1):
    print('Brown')
else:
    print('Alice')
Problem p03761 (python)

Fixed submission:
import collections
n=int(input())
c=[0]*n
alphabet=set()
for i in range(n):
    s=input()
    counter=collections.Counter(s)
    c[i]=counter
    for moji in s:
        if(moji not in alphabet):
            alphabet.add(moji)
alphabet=sorted(alphabet)
text=''
for moji in alphabet:
    count=10000
    for i in range(n):
        if(count>c[i][moji]):
            count=c[i][moji]
    text+=moji*count
print(text)

Buggy submission (verdict: Runtime Error):
import collections
n=int(input())
c=[0]*3
alphabet=set()
for i in range(n):
    s=input()
    counter=collections.Counter(s)
    c[i]=counter
    for moji in s:
        if(moji not in alphabet):
            alphabet.add(moji)
alphabet=sorted(alphabet)
text=''
for moji in alphabet:
    count1=c[0][moji]
    count2=c[1][moji]
    count3=c[2][moji]
    text+=moji*min(count1,count2,count3)
print(text)

Buggy submission (verdict: Runtime Error):
import collections
n=int(input())
c=[0]*3
alphabet=set()
for i in range(n):
    s=input()
    counter=collections.Counter(s)
    c[i]=counter
    for moji in s:
        if(moji not in alphabet):
            alphabet.add(moji)
alphabet=sorted(alphabet)
text=''
for moji in alphabet:
    count1=c[0][moji]
    count2=c[1][moji]
    count3=c[2][moji]
    text+=moji*min(count1,count2,count3)
print(text)
Problem p03853 (python)

Fixed submission:
h,w=[int(i) for i in input().split()]
for i in range(h):
    lst=[i for i in input().split()]
    for j in lst:
        print(j)
    for j in lst:
        print(j)

Buggy submission (verdict: Runtime Error):
h,w=[int(i) for i in input().split()]
for i in range(w):
    lst=[i for i in input().split()]
    for j in lst:
        print(j)
    for j in lst:
        print(j)
Problem p03860 (python)

Fixed submission:
a,b,c=[i for i in input().split()]
print('A'+b[0]+'C')

Buggy submission (verdict: Runtime Error):
a,b,x=[int(i) for i in input().split()]
count=0
count=[_ for i in range(a,b+1) if i%x==0]
print(len(count))
'''for i in range(a,b+1):
    if(i%x==0):
        count+=1
print(count)'''
Problem p03861 (python)

Fixed submission:
a,b,x=[int(i) for i in input().split()]
print(b//x-(a-1)//x)

Buggy submission (verdict: Runtime Error):
a,b,x=[int(i) for i in input().split())]
print((b-a)//x)

Buggy submission (verdict: Runtime Error):
a,b,x=[int(i) for i in input().split()]
count=0
count=[_ for i in range(a,b+1) if i%x==0]
print(len(count))
'''for i in range(a,b+1):
    if(i%x==0):
        count+=1
print(count)'''
Problem p03962 (python)

Fixed submission:
iro=[int(i) for i in input().split()]
x=set(iro)
print(len(x))

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
A=B=1
for i in range(n):
    x,y=[int(i) for i in input().split()]
    n=max(-(-A//x),-(-B//y))
    A=n*x
    B=n*y
print(A+B)
Problem p03997 (python)

Fixed submission:
a=int(input())
b=int(input())
h=int(input())

print(int((a+b)*h/2))

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
h=int(input())

print(int((a+b)*h/2)
Problem p04029 (python)

Fixed submission:
N=int(input())

def souwa(n):
    if n==1:
        return 1
    else:
        return n+souwa(n-1)

x=souwa(N)
print(x)

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;

int f(int x);

int main(){
    int n,ans;
    cin >> n;
    ans = f(n);
    cout << ans << endl; 

}

int f(int x){
    if (x==1){
        return 1;
    }
    else{
        return x+f(x-1);
    }
}
Problem p02615 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
ans = 0
for i in range(0,n):
        if i == 0:
            ans += 0
        else:
            ans += b[n-(i//2)-1]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
b = sorted(a,reverse = True)
ans = 0
if n % 2 == 0:
    for i in range(0,n//2):
        if i == 0:
            ans += b[0]
        else:
            ans += 2*b[i]
else:
    for i in range(0,n):
        if i == 0:
            ans += 0
        else:
            ans += b[n-i//2]
print(ans)
Problem p02922 (python)

Fixed submission:
a, b = map(int, input().split())
tap = a - 1
count = 1
while True:
  if b == 1:
    count = 0
    break
  elif a == b:
    break
  elif a + tap * (count - 1) < b:
    count += 1
  else:
    break
print(count)

Buggy submission (verdict: Runtime Error):
, b = map(int, input().split())
tap = a - 1
count = 0
while True:
  if a == b:
    count = 1
    break
  elif a + tap * count < b:
    count += 1
  else:
    count += 1
    break
print(count)
Problem p03048 (python)

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

for a in range(n+1):
  for c in range(n+1):
    Bb = n - r*a - g*c
    if Bb >= 0:
      if Bb % b == 0:
        count += 1
    else:
      break

print(count)

Buggy submission (verdict: Runtime Error):
r, g, b, n = map(int, input().split())
count = 0

for a in range(n+1):
  for c in range(n+1):
    Bb = N - r*a - g*c
    if Bb > N:
      if Bb % 2 == 0:
        count += 1
    else:
      break

print(count)
Problem p03086 (python)

Fixed submission:
s = input()
ans1 = 0
ans2 = 0

for a in s:
  if a == "A" or a == "T" or a == "C" or a == "G":
    ans2 += 1
  else:
    if ans1 < ans2:
      ans1 = ans2
      ans2 = 0
    else:
      ans2 = 0
print(max(ans1, ans2))

Buggy submission (verdict: Runtime Error):
s = input()
ans = 0
lis = []

for a in s:
  if a == "A" or a == "T" or a == "C" or a == "G":
    ans += 1
  else:
    lis.append(ans)
    ans = 0

print(max(lis))
Problem p03423 (python)

Fixed submission:
n = int(input())
print(n // 3)

Buggy submission (verdict: Runtime Error):
n = input()
print(n//3)
Problem p03434 (python)

Fixed submission:
n = int(input())
lis = [int(x) for x in input().split(" ")]
lis.sort(reverse=True)
lis_Alice = []
lis_Bob = []

if n % 2 == 0:
  for a in range(0, n, 2):
    lis_Alice.append(lis[a])
  for b in range(1, n+1, 2):
    lis_Bob.append(lis[b])
else:
  for a in range(0, n+1, 2):
    lis_Alice.append(lis[a])
  for b in range(1, n, 2):
    lis_Bob.append(lis[b]) 

print(sum(lis_Alice) - sum(lis_Bob))

Buggy submission (verdict: Runtime Error):
n = int(input())
lis = [int(x) for x in input().split(" ")]
lis.sort(reverse=True)
lis_Alice = []
lis_Bob = []

for a in range(0, n, 2):
  lis_Alice.append(lis[a])

for b in range(1, n+1, 2):
  lis_Bob.append(lis[b])

print(sum(lis_Alice) - sum(lis_Bob))
Problem p03545 (python)

Fixed submission:
a, b, c, d = list(input())
en = ["+", "-"]
for x in en:
  for y in en:
    for z in en:
      s = a + x + b + y + c + z + d
      if eval(s) == 7:
        print(s + "=7")
        exit()

Buggy submission (verdict: Runtime Error):
qq
Problem p04012 (python)

Fixed submission:
w = input()
lis = []
for a in set(w):
  b = w.count(a)
  if b % 2 == 1:
    print("No")
    break
  else:
    lis.append(b)
if len(lis) == len(set(w)):
  print("Yes")

Buggy submission (verdict: Runtime Error):
q
Problem p04043 (python)

Fixed submission:
a,b,c = map(int, input().split())
if a*b*c==5*5*7:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
while True:
    s = str(n)
    poss = False
    for i in s:
        if int(i) in a:
            poss = True
            break
    if not poss:
        print(n)
        exit(0)
    n += 1
Problem p02664 (python)

Fixed submission:
s = input()
t = ''
for i in range(0, len(s)):
    if s[i] == '?':
        t += 'D'
    else:
        t += s[i]
print(t)

Buggy submission (verdict: Runtime Error):
s = input()
t = ''
if s[0] == '?':
    if s[1] == 'D':
        t = 'P'
    else:
        t = 'D'
else:
    t = s[0]
for i in range(1, len(s)):
    if s[i] == '?':
        if t[-1] == 'P':
            t += 'D'
        else:
            t += 'P'
    else:
        t += s[i]
print(t)
Problem p02743 (python)

Fixed submission:
a, b, c = map(int, input().split())
if (c-a-b) ** 2 - 4*a*b > 0 and c-a-b > 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
from math import pow
a, b, c = map(int, input().split())
mod = 10**9+7
if 4*a*b < pow(c-a-b, 2, mod):
    print('Yes')
else:
    print('No')
Problem p02756 (python)

Fixed submission:
import sys
input = sys.stdin.readline

S = input().rstrip()
Q = int(input())
head = ''
tail = ''
rev = False

for _ in range(Q):
    query = list(input().split())
    if query[0] == '1':
        if rev:
            rev = False
        else:
            rev = True
    elif query[0] == '2':
        f = query[1]
        c = query[2].rstrip()
        if f == '1':
            if rev:
                tail = tail + c
            else:
                head = c + head
        else:
            if rev:
                head = c + head
            else:
                tail = tail + c
if rev:
    tmp = head + S + tail
    print(tmp[::-1])
else:
    print(head + S + tail)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input().rstrip()
Q = int(input())
head = ''
tail = ''
rev = False

for _ in range(Q):
    query = list(input().split())
    for i in range(10**5):
        if query[0] == '1':
            if flag:
                rev = False
            else:
                rev = True
            continue
        elif query[0] == '2':
            f = query[1]
            c = query[2].rstrip()
            if f == '1':
                if rev:
                    tail = tail + c
                else:
                    head = c + head
            elif:
                if rev:
                    head = c + head
                else:
                    tail = tail + c
if flag:
    print(head + S + tail)
else:
    tmp = head + S + tail
    print(tmp[::-1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input().rstrip()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]

ans = S
flag = True

for i in range(Q):
    if query[i][0] == '1':
        if flag:
            flag = False
        else:
            flag = True
        continue
    elif query[i][0] == '2':
        f = query[i][1]
        c = query[i][2].rstrip()
        if f == '1' and flag:
            ans = c + ans
        elif f == '1' and not flag:
            ans = ans + c
        elif f == '2' and flag:
            ans = ans + c
        elif f == '2' and not flag:
            ans = c + ans
if flag:
    print(ans)
else:
    print(''.join(list(ans).reverse()))
Problem p02806 (python)

Fixed submission:
n = int(input())
st = [input().split() for _ in range(n)]
x = input()
flag = False
ans = 0
for s, t in st:
    if flag:
        ans += int(t)
    if s == x:
        flag = True
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
st = [input().split() for _ in range(n)]
x = input()
flag = False
ans = 0
for s, t in st:
    if flag:
        ans += int(t)
    if s == x:
        flag = True
print(ans
Problem p02899 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    b.append([i, a[i]])
b = sorted(b, key=lambda x: x[1])
c = []
for k, v in b:
    c.append(k+1)
print(' '.join(map(str, c)))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    b.append([i, a[i]])
b = sorted(b, key=lambda x: x[1])
c = []
for k, v in b:
    c.append(k+1)
print(' '.join(map(str, c))
Problem p02900 (python)

Fixed submission:
import math


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


def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct


a, b = map(int, input().split())
c = gcd(a, b)
d = factorize(c)
print(len(set(d))+1)

Buggy submission (verdict: Runtime Error):
from math import gcd as bltin_gcd


def coprime2(a, b):
    return bltin_gcd(a, b) == 1


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


def cf(x1, x2):
    cf = []
    for i in range(1, min(x1, x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf


c = cf(a, b)
len_c = len(c)

d = [1]
for i in range(1, len(c)):
    coprime_flag = True
    for j in range(0, len(d)):
        if not coprime2(c[i], d[j]):
            coprime_flag = False
            break
    if coprime_flag:
        d.append(c[i])
print(len(d))
Problem p02952 (python)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
digit_count = len(str(N))
if digit_count == 1:
    print(N)
elif (digit_count % 2 == 1):
    print(N - int(str(90) * (digit_count//2)))
else:
    total = 0
    for i in range(0, digit_count//2):
        total += 9*(100**i)
    print(total)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
digit_count = len(str(N))
if digit_count == 1:
    print(N)
if (digit_count % 2 == 1):
    print(N - int(str(90) * (digit_count//2)))
else:
    total = 0
    for i in range(0, digit_count//2):
        total += 9*(100**i)
    print(total)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N= int(input())
if N == 1:
# -*- coding: utf-8 -*-
N = int(input())
digit_count = len(str(N))
if digit_count == 1:
    print(N)
if (digit_count % 2 == 1):
    print(N - int(str(90) * (digit_count//2)))
else:
    total = 0
    for i in range(0, digit_count//2):
        total += 9*(100**i)
    print(total)
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())
ans = float('inf')
for i in range(L, R+1):
    for j in range(i+1, R+1):
        ans = min(ans, i * j % 2019)
        if ans == 0:
            print(0)
            exit()
print(ans)

Buggy submission (verdict: Runtime Error):
import math

L, R = map(int, input().split())
ans = math.inf
for i in range(L, R+1):
    for j in range(i+1, R+1):
        ans = min(ans, i * j % 2019)
        if ans == 0:
            print(0)
            exit()
print(ans)
Problem p02993 (python)

Fixed submission:
S = input()
tmp = S[0]
for num in S[1:]:
    if num == tmp:
        print('Bad')
        exit()
    tmp = num
print('Good')

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
p_list = []
for i in range(1, N+1):
    p_list += [L + i - 1]
print(sum(p_list) - sorted(p_list, key=abs)[0])
Problem p03000 (python)

Fixed submission:
N, X = map(int, input().split())
L = list(map(int, input().split()))
d = 0
if L[0] > X:
    print(0)
for i in range(1, N + 1):
    d += L[i - 1]
    if d > X:
        print(i)
        exit()
print(N + 1)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))
d = 0
for i in range(1, N + 2):
    d += L[i - 1]
    if d > X:
        print(i)
        exit()
Problem p03024 (python)

Fixed submission:
s = input()
rest = 15 - len(s)
if s.count('o') + rest > 7:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
s = input()
rest = 15 - len(s)
if s.count('o') + rest > 7:
    print('YES')
else:
    print('NO'
Problem p03061 (python)

Fixed submission:
import fractions
n = int(input())
a = [0] + list(map(int, input().split())) + [0]

# 前処理。left, rightでそれぞれ累積gcdを作っておく
left = [0] * (n + 2)
right = [0] * (n + 2)

for i in range(n):
    left[i] = fractions.gcd(left[i - 1], a[i])

for i in range(n, 0, -1):
    right[i] = fractions.gcd(right[i + 1], a[i])

for i in range(1, n):
    right[-i - 1] = fractions.gcd(right[-i], a[-i - 1])

ans = 1
for i in range(1, n + 1):
    ans = max(ans, fractions.gcd(left[i - 1], right[i + 1]))
print(ans)

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

ans = 1
# 1つ使わない中で最大公約数が最大のものを求める
for i in range(0, n):
    if i == 0:
        gcd_num = a[1]
    else:
        gcd_num = a[0]
    for j in range(1, n):
        if i == j:
            continue
        gcd_num = math.gcd(gcd_num, a[j])
    ans = max(ans, gcd_num)
print(ans)

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

ans = 1
gcd_num = a[0]
# 1つ使わない中で最大公約数が最大のものを求める
for i in range(0, n):
    if i == 0:
        gcd_num = a[1]
    else:
        gcd_num = a[0]
    for j in range(0, n):
        if i == j:
            continue
        gcd_num = math.gcd(gcd_num, a[j])
    ans = max(ans, gcd_num)
print(ans)
Problem p03086 (python)

Fixed submission:
S = input()
ACGT = ['A', 'C', 'G', 'T']
count = 0
max_count = 0
for w in S:
    if w in ACGT:
        count += 1
    if count > max_count:
        max_count = count
    if w not in ACGT:
        count = 0
print(max_count)

Buggy submission (verdict: Runtime Error):
S = input()
ACGT = ['A', 'C', 'G', 'T']
count = 0
max_count = 0
for w in S:
    if w in ACGT:
        count += 1
    else:
        if count > max_count:
            max_count += count
print(max_count
Problem p03125 (python)

Fixed submission:
a, b = map(int, input().split())
if b % a == 0:
    print(a + b)
else:
    print(b - a)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
if b % a == 0:
    print(a + b)
else:
    print(b - a)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
if a % b == 0:
    print(a + b)
else:
    print(b - a)
Problem p03131 (python)

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

max_change = max(0, (k - (a - 1)) // 2)
print(max(k+1, 1+k-max_change*2 + (b-a)*max_change))

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

max_change = max(0, (k - (a - 1)) // 2)
print(max(k+1, 1+k-max_change*2 + (b-a)*max_change)
Problem p03231 (python)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


N, M = map(int, input().split())
S = input()
T = input()
x = gcd(N, M)
n = N // x
m = M // x

for i in range(x):
    if S[n*i] != T[m*i]:
        print(-1)
        exit()
print(N*M//x)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


N, M = map(int, input().split())
S = input()
T = input()
x = gcd(N, M)
n = N // x
m = M // x

for i in range(3):
    if S[n*i] == T[m*i]:
        print(-1)
        break
print(N*M//x)
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())
for i in range(len(s)):
    if s[i] != '1' and i < k:
        print(s[i])
        exit()
print('1')

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
for i in len(s):
    if s[i] != '1' and i < k:
        print(s[i])
        exit()
print('1')