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

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

cnt = 0
money = 1000
b = 0
for i in range(n-1):
    if cnt == 0 and A[i] < A[i+1]:
        cnt += money//A[i]
        money %= A[i]
        b = A[i]
    else:
        money += cnt * A[i]
        cnt = 0
        if A[i] < A[i+1]:
            cnt += money//A[i]
            money %= A[i]
if cnt > 0:
    money += cnt * max(A[-1], b)
print(money)

Buggy submission (verdict: Runtime Error):
from collections import Counter 
n = int(input())
x = list(map(int, input().split()))
A = [x[i] for i in range(n) if i!=n-1 and x[i] != x[i+1]]
if A[-1] != x[-1]: A.append(x[-1])
a = Counter(A)
cnt = 0
money = 1000
b = 0
for i in range(len(A)-1):
    a[A[i]] -= 1
    if a[A[i]] == 0: a.pop(A[i])

    if i == len(A)-2 and cnt >0:
        if A[i] < A[i+1]: continue

    if b != 0 and b < A[i]:
        money += cnt * A[i]
        cnt = 0
        b = 0
    else:
        flag = False
        for j in a.keys():
            if A[i] < j:
                flag = True
                break
        if flag:
            cnt += money//A[i]
            money %= A[i]
            b = A[i]
if cnt > 0:
    money += cnt * A[-1]
print(money)
Problem p02608 (python)

Fixed submission:
n = int(input())
ans = [0] * n
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            a = x * x + y * y + z * z + x * y + x * z + y * z
            if a > n: continue
            ans[a-1] += 1
for i in ans: print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
N = 1
while N**2 < n:
    N += 1
ans = [0] * n
for x in range(1,N+1):
    for y in range(1,N+1):
        for z in range(1,N+1):
            a = x**2+y**2+z**2 + x*y+y*z+z*x
            if a >= 20: continue
            if x==y==z: b = 1
            elif x==y or y==z or x==z: b = 3
            else: b = 6
            ans[a-1] =b
            break
for i in ans: print(i)
Problem p02714 (python)

Fixed submission:
N = int(input())
S = list(input())

R = S.count("R")
G = S.count("G")
B = S.count("B")

def f(S):
  N = len(S)
  ret = 0
  for i in range(N):
    for j in range(i+1, N):
      k = j + j -i
      if k >= N:
        break
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ret += 1
  return ret

ans = R * B * G - f(S)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
S = list(input())
R_i = []
G_i = []
B_i = []
for i in range(N):
  if S[i] == "R": R_i.append(i)
  elif S[i] == "G": G_i.append(i)
  else: B_i.append(i)

r = len(R_i)
g = len(G_i)
b = len(B_i)

ans = 0
for i in range(N):
  for j in range(1, N-i):
    if S[i] == "R":
      print(i+j in G_i , b - bisect.bisect_right(B_i,i + j) > 0)
      if i+j in G_i and b - bisect.bisect_right(B_i,i + 2 * j) > 0:
        ans += b - bisect.bisect_right(B_i,i + 2 * j)
        if i + j + j in b: ans -= 1
      elif i+ j in B_i and g - bisect.bisect_right(G_i,i + 2 * j) > 0:
        ans += g - bisect.bisect_right(G_i,i + 2 * j)
        if i + j + j in g: ans -= 1
    elif S[i] == "G":
      if i+j in R_i and b - bisect.bisect_right(B_i,i + 2 * j) > 0:
        ans += b - bisect.bisect_right(B_i,i + 2 * j)
        if i + j + j in b: ans -= 1
      elif i+j in B_i and r - bisect.bisect_right(R_i,i + 2 * j) > 0:
        ans += r - bisect.bisect_right(R_i,i + 2 * j)
        if i + j + j in r: ans -= 1
    else:
      if i+j in R_i and g - bisect.bisect_right(G_i,i + 2 * j) > 0:
        ans += g - bisect.bisect_right(G_i,i + 2 * j)
        if i + j + j in g: ans -= 1
      elif i+j in G_i and r - bisect.bisect_right(R_i,i + 2 * j) > 0:
        ans += r - bisect.bisect_right(R_i,i + 2 * j)
        if i + j + j in r: ans -= 1
print(ans)
Problem p02732 (python)

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

a = list(set(A))
a_c = {}
for v in A:
  if v in a_c:
    a_c[v] += 1
  else:
    a_c[v] = 1

def cmb(n):
  if n < 2: return 0
  else:
    return n * (n-1)//2

S = 0
for k in a_c:
  S += cmb(a_c[k])

for i in range(N):
  print(S - cmb(a_c[A[i]]) + cmb(a_c[A[i]]-1))

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

import math

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n,r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // math.factorial(r)

a = list(set(A))
a_n = []
c = []
new = []
if len(a) != N:
  for i in range(len(a)):
    x = A.count(a[i])
    a_n.append(x)
    c.append(ncr(x,2))
    if x > 2: new.append(ncr(x-1,2))
    else: new.append(0)

  ans = sum(c)
  for i in range(N):
    n = a.index(A[i])
    print(ans-c[n]+new[n])
else:
  for _ in range(N):
    print(0)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

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

a = list(set(A))
a_n = []
c = []
new = []
if len(a) != N:
  for i in range(len(a)):
    x = A.count(a[i])
    a_n.append(x)
    c.append(cmb(x,2, mod))
    if x >= 2: new.append(cmb(x-1,2, mod))
    else: new.append(0)

  ans = sum(c)
  for i in range(N):
    n = a.index(A[i])
    print(ans-c[n]+new[n])
else:
  for _ in range(N):
    print(0)
Problem p02760 (python)

Fixed submission:
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
b = [int(input()) for _ in range(N)]

for i in range(N):
  if b[i] in A1:
    if len(list(set(A1))) == 1:
      A1 = [0] * 3
    else:
      A1[A1.index(b[i])] = 0
  elif b[i] in A2:
    if len(list(set(A2))) == 1:
      A2 = [0] * 3
    else:
      A2[A2.index(b[i])] = 0
  elif b[i] in A3:
    if len(list(set(A3))) == 1:
      A3 = [0] * 3
    else:
      A3[A3.index(b[i])] = 0


if A1[0] == 0 and A1[0] == A2[0] == A3[0]:
  ans = "Yes"
elif A1[1] == 0 and A1[1] == A2[1] == A3[1]:
  ans = "Yes"
elif A1[2] == 0 and A1[2] == A2[2] == A3[2]:
  ans = "Yes"
elif A1[0] == 0 and A1[0] == A2[1] == A3[2]:
  ans = "Yes"
elif A1[2] == 0 and A1[2] == A2[1] == A3[0]:
  ans = "Yes"
elif A1 == [0] * 3 or A2 == [0] * 3 or A3 == [0] * 3:
  ans = "Yes"
else:
  ans = "No"

print(ans)

Buggy submission (verdict: Runtime Error):
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
b = [int(input()) for _ in range(N)]

for i in range(N):
  if b[i] in A1:
    if len(list(set(A1))) == 1:
      A1 = [0] * 3
    else:
      A1[A1.index(b[i])] = 0
  elif b[i] in A2:
    if len(list(set(A2))) == 1:
      A2 = [0] * 3
    else:
      A2[A2.index(b[i])] = 0
  elif b[i] in A3:
    if len(list(set(A3))) == 1:
      A3 = [0] * 3
    else:
      A3[A3.index(b[i])] = 0


if A1[0] == 0 and A1[0] == A2[0] == A3[0]:
  ans = "Yes"
elif A1[1] == 0 and A1[1] == A2[1] == A3[1]:
  ans = "Yes"
elif A1[2] == 0 and A1[2] == A2[2] == A3[2]:
  ans = "Yes"
elif A1[0] == 0 and A1[0] == A2[1] == A3[2]:
  ans = "Yes"
elif A1[2] == 0 and A1[2] == A2[1] == A3[0]:
  ans = "Yes"
elif A[0] == [0] * 3 or A[1] == [0] * 3 or A[2] == [0] * 3:
  ans = "Yes"
else:
  ans = "No"

print(ans)
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = ["0"] * N
if N > 1: ans[0] = "1"
rep = {}

ok = True
for s, c in sc:
  ans[s - 1] = str(c)
  if s in rep and rep[s] != str(c):
    ok = False
  else:
    rep[s] = str(c)

if ok:
  if ans[0] == "0" and N > 1:
    ok = False

print("".join(ans) if ok else -1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ok = False
n = [-1] * M
for s, c in sc:
  if n[s-1] != -1:
    if n[s-1] == c: continue
    ans = -1
    ok = True
    break
  n[s-1] = c

if n[0] == 0:
  ans = -1
  ok = True
if not ok:
  ans = ""
  for i in range(M):
    if i == 0 and n[i] == -1:
      ans += "1"
    elif n[i] == -1:
      ans += "0"
    else:
      ans += str(n[i])
print(ans)
Problem p02780 (python)

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

a = 0
for i in range(N - K + 1):
  if i == 0:
    b = sum(p[0:K])
  else:
    b = b - p[i-1] + p[i + K - 1]
  
  if b > a:
    a = b
    f = i

ans = 0
for j in range(K):
  ans += (p[f + j] + 1) / 2

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
p = [int(x) for x in input().split()]

p_sum = sum(p[:K])
n = 0
for i in range(1, N-K+1):
  a = p_sum - p[i-1] + p[i+K-1]
 if p_sum < a:
   p_sum = a
   n = i

def allsum(x):
  return x * (x+1) // 2

ans = 0
for j in range(K):
  ans += allsum(p[n+j]) / p[n+j]
print(ans)
Problem p02797 (python)

Fixed submission:
n,k,s = map(int, input().split())
if s < 10 ** 9:
    ans = [s+1] * n
else:
    ans = [1] * n
ans[:k] = [s] * k
print(" ".join(map(str, ans)))

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

ans = [1] * n
if k * 2 <= n:
    i = 0
    while k > 0:
        ans[i], ans[i+1] = 1, s-1
        k -= 1
        i += 2
else:
    if s % 2 == 0:
        i = 0
        while k > 0:
            ans[i] = ans[i+1] = s//2
            k -= 1
            i += 1
    else:
        i = 0
        while k-1 > 0:
            ans[i], ans[i+1] = 1, s-1
            k -= 1
            i += 2
        ans[i] = s
print(" ".join(map(str, ans)))

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

ans = [1] * n
ans[0] = s
if k % 2 == 0:
    i = 1
    while k > 1:
        ans[i], ans[i+1] = 1, s-1
        i += 2
        k -= 1
else:
    for i in range(1,k+1):
        ans[i] = s//2
print(" ".join(map(str, ans)))
Problem p02854 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
m = sum(A) // 2
n = 0
if N > 2:
  for i in range(N):
    if n < m:
      n += A[i]
    elif n >= m and i == N - 1:
      a = i
    elif n >= m and i != N - 1:
      a = i
      break
  if a == 0:
    print(abs(A[a]-sum(A[a:])))
  elif abs(sum(A[:a-1]) - sum(A[a-1:])) > abs(sum(A[:a]) - sum(A[a:])):
    print(abs(sum(A[:a]) - sum(A[a:])))
  else:
    print(abs(sum(A[: a - 1]) - sum(A[a - 1 :])))
else:
  print(abs(A[0]-A[1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
m = sum(A) // 2
n = 0
for i in range(N):
  if n < m:
    n += A[i]
  elif n >= m and i != N-1:
    a = i
    break
  elif n >= m and i == N - 1:
    a = i
if a == 0:
  print(abs(A[a]-sum(A[a:])))
elif abs(sum(A[:a-1]) - sum(A[a-1:])) > abs(sum(A[:a]) - sum(A[a:])):
  print(abs(sum(A[:a]) - sum(A[a:])))
else:
  print(abs(sum(A[:a-1]) - sum(A[a-1:])))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
m = sum(A) // 2
n = 0
for i in range(N):
  if n < m:
    n += A[i]
  elif n >= m:
    a = i
    break

if abs(sum(A[:a-1]) - sum(A[a-1:])) > abs(sum(A[:a]) - sum(A[a:])):
  print(abs(sum(A[:a]) - sum(A[a:])))
else:
  print(abs(sum(A[:a-1]) - sum(A[a-1:])))
Problem p02855 (python)

Fixed submission:
h,w,k = map(int, input().split())
S = [list(input()) for _ in range(h)]
ans = []
n = 1
cnt = 0
for i in range(h):
    if "#" in S[i]:
        ans = []
        for j in range(w):
            if S[i][j] == "#":
                for _ in range(j+1-len(ans)):
                    ans.append(str(n))
                n += 1
        if len(ans) < w:
            x = ans[-1]
            for _ in range(w-len(ans)):
                ans.append(x)
    if ans:
        for _ in range(i+1-cnt):
            print(" ".join(ans))
            cnt += 1

Buggy submission (verdict: Runtime Error):
h,w,k = map(int, input().split())
s = [input() for _ in range(h)]
now = 1
flag = False
Ans = []
for i in range(h):
    if s[i] == "." * w:
        if i > 0: 
            Ans.append(Ans[-1])
        continue
    ans = []
    if i%2==0: x = s[i]
    else: x = s[i][::-1]
    for j in range(w):
        if x[j] == "#":
            if flag: now += 1
            else: flag = True
        ans.append(now)
    if i%2!=0: ans = ans[::-1]
    for _ in range(i+1-len(Ans)): Ans.append(ans)
for x in Ans:
    print(" ".join(list(map(str, x))))

Buggy submission (verdict: Runtime Error):
h,w,k = map(int, input().split())
s = [list(input()) for _ in range(h)]

ans = []
n = 1
cnt = 0
for i in range(h):
    if "#" in s[i]:
        ans = []
        for s[i][j] == "#":
            for _ in range(j+1-len(ans)):
                ans.append(str(n))
            n += 1
        if len(ans) < w:
            x = ans[-1]
            for _ in range(w-len(ans)):
                ans.append(x)
    if ans:
        for _ in range(i+1-cnt):
            print(" ".join(ans))
            cnt += 1
Problem p02888 (python)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

Buggy submission (verdict: Runtime Error):
= int(input())
L = map(int, input().split())

import itertools
l = list(itertools.combinations(L, 3))

a = 0
n = 0

for x in range(len(l)):
  if max(l[n]) < sum(l[n]) - max(l[n]):
    a += 1
    n += 1
  else:
    n += 1
    
print(a)
Problem p02899 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
         
ans = [0] * N
for i in range(N):
         ans[A[i] - 1] = i + 1
    
print(" ".join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split())
         
ans = [0] * N
for i in range(N):
         ans[A[i] - 1] = i + 1
    
print(" ".join(map(str, ans)))
Problem p02923 (python)

Fixed submission:
N = int(input())
H = [int(x) for x in input().split()]

if N == 1:
  print(0)
else:
  ans = []
  c = 0
  for i in range(N - 1):
    if H[i] >= H[i + 1]:
      c += 1
      if i == N - 2:
        ans.append(c)
    elif H[i] < H[i + 1]:
      ans.append(c)
      c = 0
  print(max(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
H = [int(x) for x in input().split()]

ans = []
c = 0
for i in range(N - 1):
  if H[i] >= H[i + 1]:
    c += 1
    if i == N - 2:
      ans.append(c)
  elif H[i] < H[i + 1]:
    ans.append(c)
    c = 0
  
print(max(ans))
Problem p02924 (python)

Fixed submission:
N = int(input())
print((N * (N-1)) //2)

Buggy submission (verdict: Runtime Error):
N = int(input())
l = list(range(1, N+1))

ans = 0
for i in range(N):
  if i == N-1:
    ans += l[i] % 1
  else: ans += l[i] % (l[i] + 1)
print(ans)
Problem p02945 (python)

Fixed submission:
A, B = (int(x) for x in input().split() )

print(max(A+B, A-B, A*B))

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

list = [a + b, a - b, a * b]

if a > 0:
  if b > 0:
    print(list[2])
  else:
    print(list[1])

else:
  if b > 0:
    print(list[0])
  else:
    print(list[2])
Problem p02975 (python)

Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())))
c0 = a.count(0)

ans = "No"
if c0==n: ans = "Yes"
elif len(set(a)) == 2:
    c = a.count(a[-1])
    if c == (2*n)//3 and c0 == n//3: ans = "Yes"
elif len(set(a)) == 3:
    x,y,z = list(set(a))
    if a.count(x) == a.count(y) == a.count(z):
        if int(bin(x ^ y ^ z),2) == 0: ans = "Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int, input().split())))
c0 = a.count(0)

ans = "No"
if c0==n: ans = "Yes"
elif len(set(a)) == 2:
    c = a.count(set(a)[-1])
    if c == (2*n)//3 and c0 == n//3: ans = "Yes"
elif len(set(a)) == 3:
    x,y,z = list(set(a))
    if int(bin(x ^ y ^ z),2) == 0: ans = "Yes"
print(ans)
Problem p02983 (python)

Fixed submission:
l,r = map(int, input().split())
ans = 10**10

for i in range(l,r):
    for j in range(i+1,r+1):
        a = (i*j) % 2019
        if a == 0:
            print(0)
            exit()
        elif a < ans:
            ans = a
print(ans)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())
if l >= 2019: 
  i = l
  j = l+1
elif r <= 2019:
  i = r - 1
  j = r
print((i*j) % 2019)
Problem p02995 (python)

Fixed submission:
from fractions import gcd
a,b,c,d = map(int, input().split())
x = (c*d) // gcd(c,d)
c1, d1, cd1 = b // c, b // d, b // x
c2, d2, cd2 = (a-1) // c, (a-1) // d, (a-1) // x
ans = (c1+d1-cd1) - (c2+d2-cd2)
print(b-a+1-ans)

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int, input().split())
e = (c*d)//math.gcd(c,d)
A = (a-1)//c + (a-1)//d - (a-1)//e
B = b//c + b//d - b//e
print((b-a+1)-(B-A))
Problem p03000 (python)

Fixed submission:
N, X = map(int, input().split())
L = list(map(int, input().split()))
l = [0]
if L[0] <= X:
  l.append(L[0])
  for x in range(N - 1):
    a = l[-1] + L[x + 1]
    if a <= X:
      l.append(a)
    elif a > X:
      break

print(len(l))

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(input().split())
D = 1
l = [0]
if N == 1:
  print(1)
else:
  while max(l) < X:
    if int(l[-1]) + int(L[D - 1]) <= X:
      l.append(int(l[-1]) + int(L[D - 1]))
      D += 1
    else:
      break
  print(len(l))

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(input().split())
D = 1
l = [0]
while max(l) < X:
  if int(l[-1]) + int(L[D - 1]) <= X:
    l.append(int(l[-1]) + int(L[D - 1]))
    D += 1
  else:
    break
print(len(l))
Problem p03062 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 0
m = 10 ** 9 #絶対値の最小
c = 0 #マイナスの数
for i in range(N):
  ans += abs(A[i])
  if m > abs(A[i]):
    m = abs(A[i])
  if A[i] < 0: c += 1
print(ans if c % 2 == 0 else ans - 2 * m)

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

l = ""
r = ""
for i in range(N):
    if l == "" and A[i] < 0: l = i
    if A[i] < 0:r = i
if (r-l+1) % 2 == 0 or (l == 0 and r == N-1):
    print(sum([abs(x) for x in A]))
else:
    a = [abs(x) for x in A]
    print(sum(a) - min(a)*2)
Problem p03085 (python)

Fixed submission:
b = input()

if b == "A":
  print("T")
elif b == "C":
  print("G")
elif b == "G":
  print("C")
else:
  print("A")

Buggy submission (verdict: Runtime Error):
b = input()
x = ["A", "C"]
y = ["T", "G"]
print(y[x.index(b)])
Problem p03086 (python)

Fixed submission:
S = input()
a = ["A", "C", "G", "T"]
ans = 0
count = 0
for i in S:
  if i in a:
    count += 1
  elif ans < count:
    ans = count
    count = 0

if count != 0:
  if ans < count:
    ans = count

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
l = []
a = ["A", "C", "G", "T"]
n = 0
for i in S:
  if i in a:
    n += 1
  else:
    l.append(n)
    n = 0
print(max(l))
Problem p03087 (python)

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

ans = [0] * N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i] + 1)
    else:
        ans[i+1] = ans[i]

for _ in range(Q):
    l, r = map(int, input().split())
    print(ans[r-1] - ans[l-1])

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right
n,q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

numbers = []
for i in range(n-1):
    if s[i]+s[i+1] == "AC":
        numbers.append(i+1)
for l,r in lr:
    x,y = bisect_left(numbers, l), bisect_right(numbers, r)
    if numbers[y-1]+1 <= r:print(y-x)
    else: print(y-x-1)
Problem p03231 (python)

Fixed submission:
from fractions import gcd
n,m = map(int, input().split())
s = input()
t = input()
# Xの長さLはnとmで割り切れる
# Xの1, L/n + 1, ..., (n-1) * L/n + 1 番目の文字をつなげるとSになる
# Xの1, L/m + 1, ..., (m-1) * L/m + 1 番目の文字をつなげるとTになる

ans = -1
if n==m:
    if s==t: ans= n
else:
    gcd_nm = gcd(n,m)
    for i in range(gcd_nm):
        if s[n//gcd_nm*i] != t[m//gcd_nm*i]: break
    else: ans = n*m//gcd_nm
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
n,m = map(int, input().split())
s = input()
t = input()
# Xの長さLはnとmで割り切れる
# Xの1, L/n + 1, ..., (n-1) * L/n + 1 番目の文字をつなげるとSになる
# Xの1, L/m + 1, ..., (m-1) * L/m + 1 番目の文字をつなげるとTになる

ans = [""] * (n*m//gcd(n,m))
N,M = 1,1
for i in range(len(ans)):
    if i == 0: 
        if s[i] != t[i]:
            print(-1)
            exit()
        ans[0] = s[i]
    else:
        if i % (len(ans)//n) == 0: 
            ans[i] = s[N]
            N += 1
        if i % (len(ans)//m) == 0:
            if ans[i] == "" or ans[i] == t[M]:
                ans[i] = t[M]
                M += 1
            else:
                print(-1)
                exit()
print(n*m//gcd(n,m))
Problem p03241 (python)

Fixed submission:
n,m = map(int, input().split())

def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n%i == 0:
      divisors.append(i)
      if i != n//i:
        divisors.append(n//i)
  divisors.sort(reverse=True)
  return divisors

numbers = make_divisors(m)
for i in range(len(numbers)):
  if numbers[i] <= m/n:
    print(numbers[i])
    break

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

N = sympy.divisors(m)

for i in range(len(N)):
    if N[i] <= m/n:
        print(N[i])
        break
Problem p03262 (python)

Fixed submission:
import math
import fractions
from functools import reduce
N, X = map(int, input().split())
x = list(map(int, input().split()))

ans = []
for i in range(N):
 ans.append(abs(X- x[i]))
ans = tuple(ans)

print(reduce(fractions.gcd, ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, X = map(int, input().split())
x = list(map(int, input().split()))

ans = []
for i in range(N):
 ans.append(abs(X- x[i]))
print(np.gcd.reduce(ans))
Problem p03328 (python)

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

ans = round((b - a) * (b - a + 1) / 2 - b)
print(ans)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
count = 0
n = 0
l = []

for i in range(10):
  n += count + 1
  count += 1
  if n > min(a, b):
    l.append(n-min(a,b))
  if n > max(a, b) and n-max(a,b) in l:
    N = n-max(a,b)
    break
if len(l) == 1:
  print(1)
else:
  print(N)
Problem p03331 (python)

Fixed submission:
n = int(input())
N = n//2
ans = float("INF")
for i in range(1,N+1):
  a,b = list(str(i)), list(str(n-i))
  A,B = sum(list(map(int, a))), sum(list(map(int, b)))
  if ans > A+B: ans = A+B
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = []
for x in range(2,n//2+1):
    y = n-x
    X = sum(list(map(int, list((str(x))))))
    Y = sum(list(map(int, list((str(y))))))
    ans.append(X+Y)
print(min(ans))
Problem p03352 (python)

Fixed submission:
X = int(input())
l = [1]
for i in range(2,32):
  p = 2
  while i ** p <= 1000:
   l.append(i ** p)
   p += 1

while not X in l:
  X -= 1

print(X)

Buggy submission (verdict: Runtime Error):
x = int(input())
ans = [1]
b = 2
p = 2
while b**p < x:
  while b**p<x:
    ans.append(b**p)
    p += 1
  b += 1
  p = 2
print(ans[-1] if ans[-1]<x else ans[-2])