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

Fixed submission:
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,x = na()
a = na()
dp = [i for i in a]
ans = sum(dp)

for i in range(1,n):
    for j in range(n):
        dp[(j+i)%n] = min(dp[(j+i)%n], a[j])
    ans = min(ans, sum(dp)+x*i)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,i = na()
a = na()
dp = [i for i in a]
ans = sum(dp)

for i in range(1,n):
    for j in range(n):
        dp[(j+i)%n] = min(dp[(j+i)%n], a[j])
    ans = min(ans, sum(dp)+x*i)

print(ans)
Problem p02536 (python)

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
uf = UnionFind(N+1)

for m in range(M):
  a, b = map(int, input().split())
  uf.union(a, b)
  
print(len(uf.roots()) - 1 - 1)

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
uf = UnionFind(N)

for m in range(M):
  a, b = map(int, input().split())
  uf.union(a, b)
  
print(len(uf.roots()) - 1)
Problem p02642 (python)

Fixed submission:
from numba import njit
import numpy as np

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

@njit
def main(A):
  count = np.zeros(10**6 + 10, np.int32)
  
  for i in range(N):
    a = A[i]
    if count[a] > 1:
      continue
    count[::a] += 1
    
  ans = 0
  for i in range(N):
    ans += count[A[i]] == 1
    
  #print(count[:100])
  return ans
  
print(main(np.array(A, np.int32)))

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
A = sorted(list(map(int, input().split())))

ans = 0
  
while True:
  d = A.pop(0)
  if A[0] == d:
    d = A.pop(0)
  else:
    A = list(reversed([ a for a in A[::-1] if a % d != 0]))
    ans += 1
  if A:
    True
  else:
    break
  
print(ans)
Problem p02690 (python)

Fixed submission:
X = int(input())

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)
      #else:
      #  divisors.append([i, i])
  return divisors


def solve(a, b, c):
  D = (b**2 - 4*a*c) ** (1/2)
  x_1 = (-b + D) / (2 * a)
  x_2 = (-b - D) / (2 * a)
  return x_1, x_2

for pattern in make_divisors(X):
  diff = pattern
  A = 5
  B = 5 * (diff ** 2)
  C = diff ** 4 - X//diff
  sekiss = solve(A, B, C)
  for sekis in sekiss:
    if sekis == int(sekis):
      #print(int(sekis), diff)
      kouhos = solve(1, -diff, -int(sekis))
      if kouhos[0].imag == 0.0:
        print(int(kouhos[0]), int(kouhos[0] - diff))
      break

Buggy submission (verdict: Runtime Error):
from collections import deque, Counter

N = int(input())

A = [
  int(j) - i  for i, j in enumerate(input().split())
]
cnt_A = Counter(A)

ans = 0
d = deque(A)
for i in range(N):
  a = d.popleft()
  #c = d.count(-a - 2 * i)
  c = cnt_A[-a - 2 * i]
  ans += c
print(ans)
Problem p02702 (python)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = [ input() for _ in range(N) ]
print(len(set(S)))
Problem p02768 (python)

Fixed submission:
N, A, B = map(int, input().split())
MOD = 10**9 + 7

def pow(x, y):
  if y == 0:
    return 1
  K = 1
  while y > 1:
    if y % 2 == 0:
      y = y // 2
      x = (x * x) % MOD
    else:
      K = (K * x) % MOD
      y -= 1
  return (K * (x ** y)) % MOD

def comb_mod(p, q):
  bunsi = 1
  bunbo = 1
  for i in range(q):
    bunsi = (bunsi * (p-i)) % MOD
    bunbo = (bunbo * (i+1)) % MOD
  return ((bunsi * pow(bunbo, MOD - 2)) % MOD)

print((pow(2,N) - 1 - comb_mod(N, A) - comb_mod(N, B)) % MOD)

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
MOD = 10**9 + 7

import numpy as np
 
def prepare(n, MOD):
    nrt = int(n ** 0.5) + 1
    nsq = nrt * nrt
    facts = np.arange(nsq, dtype=np.int64).reshape(nrt, nrt)
    facts[0, 0] = 1
    for i in range(1, nrt):
        facts[:, i] = facts[:, i] * facts[:, i - 1] % MOD
    for i in range(1, nrt):
        facts[i] = facts[i] * facts[i - 1, -1] % MOD
    facts = facts.ravel().tolist()
 
    invs = np.arange(1, nsq + 1, dtype=np.int64).reshape(nrt, nrt)
    invs[-1, -1] = pow(facts[-1], MOD - 2, MOD)
    for i in range(nrt - 2, -1, -1):
        invs[:, i] = invs[:, i] * invs[:, i + 1] % MOD
    for i in range(nrt - 2, -1, -1):
        invs[i] = invs[i] * invs[i + 1, 0] % MOD
    invs = invs.ravel().tolist()
 
    return facts, invs
s, _ = prepare(N, MOD)
print((2**N - s[N]//(s[A]*s[N-A]) - s[N]//(s[B] * s[N-B]) - 1) % MOD)
Problem p02813 (python)

Fixed submission:
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

all_pattern = list(itertools.permutations([i for i in range(1,N+1)]))
#print(all_pattern)

for i, node in enumerate(all_pattern):
  if node == P:
    p = i
  if node ==  Q:
    q = i
    
    
print(abs(p-q))

Buggy submission (verdict: Runtime Error):
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

all_pattern = list(itertools.permutations([i for i in range(1,N+1)]))
#print(all_pattern)

for i, node in enumerate(all_pattern):
  if node == P:
    p = i
  elif node  ==  Q:
    q = i
    
    
print(abs(p-q))
Problem p02814 (python)

Fixed submission:
from functools import reduce
import fractions

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

N, M = map(int, input().split())
a_list = list(set(list(map(int, input().split()))))

lcm = 1

for a in a_list:
  lcm = lcm_base(lcm, a)

for a in a_list:
  if (lcm // a) % 2 == 0:
    lcm = 0
    break
if lcm == 0:
  print(0)
elif M == 1 and lcm == 2:
  print(1)
else:
  print(int(-(-M//(lcm//2))/2))

Buggy submission (verdict: Runtime Error):
from functools import reduce
import fractions

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

N, M = map(int, input().split())
a_list = list(map(int, input().split()))

lcm = lcm_list(a_list)

print(int(-(-(M//(lcm/2)) // 2)))
Problem p02911 (python)

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

n, k, q = map(int, input().split(' '))
t = [int(input()) for i in range(q)] 
 
ans = [k - q] * n

t_cnt = collections.Counter(t)
for i, j in t_cnt.items():
  ans[i-1] += j

for i in ans:
  if i > 0:
    print('Yes')
  else:
    print('No')

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

n, k, q = map(int, input().split(' '))
t = [int(input()) for i in range(q)] 
 
ans = [k - q] * n

t_cnt = collections.Counter(t)
for i, j in t_cnt.items():
  ans[i] += j
    
for i in ans:
  if i > 0:
    print('Yes')
  else:
    print('No')
Problem p02921 (python)

Fixed submission:
predict_weather = str(input())
real_weather = str(input())

predict_list = list(predict_weather)
real_list = list(real_weather)

cnt = 0
for i in range(3):
  if predict_list[i] == real_list[i]:
    cnt += 1
    
print(cnt)

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

i = 1
while True:
  max = a * i + 1 - i
  if max >= b:
    break
    
  i += 1
  

print(i)
Problem p03032 (python)

Fixed submission:
import heapq

N, K = map(int, input().split())
V = list(map(int, input().split()))
V += V

ans = [V[0]]
for i in range(min(N, K)+1):
  for j in range(i+1):
    #print(i-j, j)
    # i-j個左から、i個右から取る
    lst = V[:i-j] + V[2*N-j:]
    #print(lst)
    heapq.heapify(lst)
    for _ in range(K-i):
      if len(lst) == 0:
        break
      elif min(lst) >= 0:
        ans.append(sum(lst))
        break
      else:
        heapq.heappop(lst)
        ans.append(sum(lst))
        #print(ans)
print(max(ans))

Buggy submission (verdict: Runtime Error):
import heapq

N, K = map(int, input().split())
V = list(map(int, input().split()))
V += V

ans = []
for i in range(min(N, K)+1):
  for j in range(i+1):
    #print(i-j, j)
    # i-j個左から、i個右から取る
    lst = V[:i-j] + V[2*N-j:]
    #print(lst)
    heapq.heapify(lst)
    for _ in range(K-i):
      if len(lst) == 0:
        break
      elif min(lst) >= 0:
        ans.append(sum(lst))
        break
      else:
        heapq.heappop(lst)
        ans.append(sum(lst))
        #print(ans)
print(max(ans))

Buggy submission (verdict: Runtime Error):
import heapq

N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = []
for i in range(min(N, K)):
  for j in range(i+1):
    # i-j個左から、i個右から取る
    lst = V[:i-j] + V[N-j:]
    #print(lst)
    heapq.heapify(lst)
    for _ in range(K-i):
      if len(lst) == 0:
        break
      elif min(lst) >= 0:
        ans.append(sum(lst))
        break
      else:
        heapq.heappop(lst)
        ans.append(sum(lst))
        #print(ans)
print(max(ans))

Buggy submission (verdict: Runtime Error):
import heapq

N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = []
for i in range(min(N, K)):
  for j in range(i+1):
    #print(i-j, j)
    # i-j個左から、i個右から取る
    lst = V[:i-j] + V[N-j:]
    #print(lst)
    heapq.heapify(lst)
    for _ in range(K-i):
      if len(lst) == 0:
        break
      elif heapq.heappop(lst) >= 0:
        break
      else:
        ans.append(sum(lst))
print(max(ans))
Problem p02585 (python)

Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = map(int, readline().split())
    p = list(map(int, readline().split()))
    p = [x - 1 for x in p]
    c = list(map(int, readline().split()))
    ans = -INF

    for i in range(n):
        cur = i
        nx = -1
        cnt = 0
        score_dict = dict()
        score_dict[0] = 0
        score = 0
        rem = k
        while rem > 0 and nx != i:
            cnt += 1
            rem -= 1
            nx = p[cur]
            score += c[nx]
            score_dict[cnt] = score
            ans = max(ans, score)
            cur = nx

        if rem > 0 and score > 0:
            loop = (rem - 1) // cnt
            if loop > 0:
                score += score * loop
                rem -= loop * cnt
            for j in range(rem + 1):
                st = score + score_dict[j]
                ans = max(ans, st)

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = map(int, readline().split())
    p = list(map(int, readline().split()))
    p = [x - 1 for x in p]
    c = list(map(int, readline().split()))
    ans = -INF

    for i in range(n):
        cur = i
        nx = -1
        cnt = 0
        score_dict = dict()
        score_dict[0] = 0
        score = 0
        rem = k
        while rem > 0 and nx != i:
            cnt += 1
            rem -= 1
            nx = p[cur]
            score += c[nx]
            score_dict[cnt] = score
            ans = max(ans, score)
            cur = nx

        if rem > 0 and score > 0:
            loop = (rem // cnt) - 1
            if loop > 0:
                score += score * loop
                rem -= loop * cnt
            for j in range(rem + 1):
                st = score + score_dict[j]
                ans = max(ans, st)

    print(ans)


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

Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x = int(readline())
    kyu = 0

    if 400 <= x <= 599:
        kyu = 8
    if 600 <= x <= 799:
        kyu = 7
    if 800 <= x <= 999:
        kyu = 6
    if 1000 <= x <= 1199:
        kyu = 5
    if 1200 <= x <= 1399:
        kyu = 4
    if 1400 <= x <= 1599:
        kyu = 3
    if 1600 <= x <= 1799:
        kyu = 2
    if 1800 <= x <= 1999:
        kyu = 1

    print(kyu)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
x = int(readline())
y = x // 200
print(10 - y)
Problem p02601 (python)

Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, c = map(int, readline().split())
    k = int(readline())
    cnt = 0

    while a >= b:
        b *= 2
        cnt += 1

    while b >= c:
        c *= 2
        cnt += 1

    if cnt <= k:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

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

cnt = 0

while a >= b:
  b *= 2
  cnt += 1

  while b >= c:
    c *= 2
    cnt += 1

    if cnt <= k:
      print("Yes")
      else:
        print("No")
Problem p02663 (python)

Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, c, d, e = list(map(int, readline().split()))

    x = a * 60 + b
    y = c * 60 + d
    z = y - x

    print(z-e)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
h1, m1, h2, m2, k = list(map(int, readline().split()))

x = (h2 - h1) * 60 + (m2 - m1)  # 起きている時間の長さ（分）
print(x - k)
Problem p02677 (python)

Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, h, m = list(map(int, readline().split()))
    deg_a = 30 * h + (m / 60) * 30
    deg_b = 6 * m
    if deg_a > deg_b:
        deg = deg_a - deg_b
    else:
        deg = deg_b - deg_a
    import math
    if deg > 180:
        deg = 360 - deg

    c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(deg))
    print(c2 ** 0.5)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
a, b, h, m = list(map(int, readline().split()))
deg_a = (60*h + m) * 0.5
deg_b = 6 * m
deg = abs(deg_a-deg_b)
rad = math.radians(deg)

c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(c2 ** 0.5)
Problem p02734 (python)

Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 998244353
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, s = map(int, readline().split())
    a = list(map(int, readline().split()))
    dp = [[0] * (s + 1) for _ in range(n + 1)]
    dp[0][0] = 1

    for i in range(n):
        cur = a[i]
        dp[i + 1][0] += 1
        for j in range(s + 1):
            dp[i + 1][j] += dp[i][j]
            dp[i + 1][j] %= MOD
            nx = cur + j
            if nx <= s:
                dp[i + 1][nx] += dp[i][j]
                dp[i + 1][nx] %= MOD
    ans = 0

    for i in range(1, n + 1):
        ans += dp[i][s]
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# from numba import jit

# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, s = list(map(int, readline().split()))
    a = list(map(int, readline().split()))

    dp = [[0] * 6001 for _ in range(n + 1)]
    s_appeared = {0}

    for ai in range(n):
        s_add=set()
        w = a[ai]
        dp[ai][0] += 1

        for si in s_appeared:
            dp[ai + 1][si] += dp[ai][si]
            dp[ai + 1][si + w] += dp[ai][si]
            s_add.add(si + w)
        s_appeared = s_appeared|s_add

    ans = 0
    for ai in range(n + 1):
        ans += dp[ai][s]

    print(ans % 998244353)


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

Fixed submission:
def main():
    c = ord(input())
    c += 1
    if c == 123:
        c = 97
    print(chr(c))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from fractions import gcd
from itertools import permutations, combinations, accumulate
from collections import deque
from heapq import heappush, heappop, heapify
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
MOD = 10**9 + 7

def main():
    c = ord(input())
    c += 1
    if c == 123:
        c = 97
    print(chr(c))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from fractions import gcd
from itertools import permutations, combinations, accumulate
from collections import deque
from heapq import heappush, heappop, heapify
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
MOD = 10**9 + 7

def main():
    c = ord(input())
    c += 1
    if c == 123:
        c = 97
    print(chr(c))

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

Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from fractions import gcd

    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    cnt = [0] * n

    for i, elem in enumerate(a):
        x = elem
        c = 0
        while x % 2 == 0:
            x //= 2
            c += 1
        cnt[i] = c

    ans = 0

    if len(set(cnt)) == 1:
        lcm = a[0]
        for elem in a[1:]:
            lcm = (lcm * elem) // gcd(lcm, elem)
        ans = (m + (lcm // 2)) // lcm

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from math import gcd

    n0, m0 = list(map(int, readline().split()))
    a0 = list(map(int, readline().split()))
    ahalf = [x // 2 for x in a0]
    ans = 0

    if all([x % 2 == 0 for x in ahalf]):
        if all([(x - ahalf[0]) % 4 == 0 for x in ahalf]):
            lcm = a0[0]
            for elem in a0[1:]:
                lcm = (lcm * elem) // gcd(lcm, elem)
            ans = (m0 + (lcm // 2)) // lcm
    elif all([x % 2 == 1 for x in ahalf]):
        lcm = a0[0]
        for elem in a0[1:]:
            lcm = (lcm * elem) // gcd(lcm, elem)
        ans = (m0 + (lcm // 2)) // lcm

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n, m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]

a = set(a)
a = list(map(lambda x: x/2, a))
mp = a[0]
g= a[0]

for i in range(1,len(a)):
    g = gcd(g,a[i])
    mp = a[i] * mp

hlcm = int(mp/g)

if hlcm % 2 == 1:
    ans = m // hlcm - (m // (hlcm*2))
else:
    ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n, m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]

a = set(a)
a = list(map(lambda x: x/2, a))
mp = a[0]
g= a[0]

for i in range(len(a)):
    g = gcd(g,a[i])
    mp = a[i] * mp

hlcm = int(mp/g)

ans = m // hlcm - (m // (hlcm*2))

print(ans)
Problem p02844 (python)

Fixed submission:
#import math
#import bisect
#import numpy as np
import itertools
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')
sys.setrecursionlimit(10**5)

def main():
    n = int(input())
    s = input()
    ans = 0
    pin = list(itertools.product(range(10), repeat=3))

    for cur in pin:
        a, b, c = map(str,cur)
        if a in s:
            aidx = s.index(a)
            if b in s[aidx+1:]:
                bidx = s[aidx+1:].index(b) + (aidx + 1)
                if c in s[bidx+1:]:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#import math
#import bisect
#import numpy as np
#import itertools
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')
sys.setrecursionlimit(10**5)

def main():
    n = int(input())
    s = input()
    ans = 0
    pin = list(itertools.product(range(10), repeat=3))

    for cur in pin:
        a, b, c = map(str,cur)
        if a in s:
            aidx = s.index(a)
            if b in s[aidx+1:]:
                bidx = s[aidx+1:].index(b) + (aidx + 1)
                if c in s[bidx+1:]:
                    ans += 1

    print(ans)


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

Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    cnt = [0] * 3
    ans = 1

    for x in a:
        p = cnt.count(x)
        if p == 0:
            return print(0)
        ans *= p
        ans %= MOD
        cnt[cnt.index(x)] += 1

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    cnt = [0] * 3
    ans = 1

    for x in a:
        p = cnt.count(x)
        ans *= p
        ans %= MOD
        cnt[cnt.index(x)] += 1

    print(ans)


if __name__ == '__main__':
    main()