Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for _ in range(n)]

march = 'MARCH'

h = []
for x in s:
  if x[0] in march:
    h.append(x[0])

ans = 0
import itertools
for com in itertools.combinations(h, r=3):
  for x in com:
    if not x[0] in march:
      break
  if len(com) == len(set(com)):
    ans += 1

print(ans)


Fixed submission:
n = int(input())
s = [input() for _ in range(n)]

march='MARCH'
h = []
for x in s:
  if x[0] in march:
    h.append(x[0])

d = {}
for c in march:
  d[c]=0

for x in h:
  d[x] += 1

ans=0
import itertools
for com in itertools.combinations(d.values(), r=3):
  pro=1
  for x in com:
    pro *= x
  ans+=pro

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())

cnt=0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if i+j+l==s:
        cnt+=1

print(cnt)


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

cnt=0
for i in range(k+1):
  for j in range(k+1):
    l=s-i-j
    if 0<=l<=k:
      cnt+=1

print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

s=''
for i,x in enumerate(a):
  if x != 0:
    s += str(i+1)*x
  else:
    s += '*'
s += '*'

ans=0
cnt=0
for c in s:
  if c != '*':
    cnt += 1
  else:
    ans += cnt // 2
    cnt=0
  
    
print(ans)


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]

ans = 0
cnt = 0
for x in a:
  if x != 0:
    cnt += x
  else:
    ans += cnt // 2
    cnt = 0

ans += cnt // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

prev = 1
for i in range(k):
    prev *= a[i]


for i in range(k, n):
    now = prev * a[i] // a[i-k]
    if now > prev:
        print("Yes")
    else:
        print("No")
    prev = now

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

for i in range(k, n):
    if a[i] > a[i-k]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split())) + [10 ** 10]
b = list(map(int, input().split())) + [10 ** 10]


def dfs(ai, bi, time, finished=False):
    if finished:
        return ai + bi
    
    if ai == n-1 and bi == n-1:
        return ai + bi
    
    if time >= a[ai]:
        ret1 = dfs(ai + 1, bi, time - a[ai])
    else:
        ret1 = dfs(ai, bi, time, finished=True)

    if time >= b[bi]:
        ret2 = dfs(ai, bi + 1, time - b[bi])
    else:
        ret2 = dfs(ai, bi, time, finished=True)

    return max(ret1, ret2)


print(dfs(0, 0, k))


Fixed submission:
from bisect import bisect_right
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

for i in range(m):
    b[i+1] += b[i]


def f(time, r):
    ret = bisect_right(r, time) - 1
    return ret


def fa(time):
    return f(time, a)


def fb(time):
    return f(time, b)

ans = 0

for i, ai in enumerate(a):
    k -= ai
    if k < 0:
        break
    ans = max(ans, i + fb(k))

print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))+[10**10]
b = list(map(int, input().split()))+[10**10]



def dfs(ai, bi, time, finished=False):
    if finished:
        return ai+bi

    if time >= a[ai]:
        ret1 = dfs(ai+1, bi, time-a[ai])
    else:
        ret1 = dfs(ai, bi, time, finished=True)

    
    if time >= b[bi]:
        ret2 = dfs(ai, bi+1, time-b[bi])
    else:
        ret2 = dfs(ai, bi, time, finished=True)

    return max(ret1, ret2)

print(dfs(0, 0, k))

Fixed submission:
from bisect import bisect_right
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

for i in range(m):
    b[i+1] += b[i]


def f(time, r):
    ret = bisect_right(r, time) - 1
    return ret


def fa(time):
    return f(time, a)


def fb(time):
    return f(time, b)

ans = 0

for i, ai in enumerate(a):
    k -= ai
    if k < 0:
        break
    ans = max(ans, i + fb(k))

print(ans)
Buggy python submission (verdict: Runtime Error):
def base_k(n, k=26):
    ret = []
    ny = n
    while ny:

        ret.append(ny % k)
        ny //= k
    return ret[::-1]


def letter(i):
    return chr(i+97)


n = int(input())

check = 26
add = 26**2
cnt = 1
k = n
while True:
    if n <= check:
        break
    check += add
    cnt += 1
    add *= 26
k -= check//26 - 1

t = base_k(k-1)

ans = ""
if not t:
    ans = "a" * cnt
else:
    for i in range(len(t)-cnt, len(t)):
        ans += letter(t[i])

print(ans)

Fixed submission:
def base_k(n, k=26):
    ret = []
    ny = n
    while ny:

        ret.append(ny % k)
        ny //= k
    return ret[::-1]


def letter(i):
    return chr(i+97)


def solve(n):
    check = 26
    cnt = 1
    k = n
    while True:
        if n <= check:
            break
        check *= 26
        check += 26
        cnt += 1
    k -= check//26 - 1
    t = base_k(k-1)
    ans = ""
    if not t:
        ans = "a" * cnt
    else:
        for _ in range(cnt):
            if not t:
                ans += "a"
                continue
            ans += letter(t.pop())

    return ans[::-1]


n = int(input())
print(solve(n))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

res = 1
for t in a:
    res *= t

if res > 10**18:
    print(-1)
else:
    print(res)

Fixed submission:
import sys
n = int(input())
a = sorted(list(map(int, input().split())))

res = 1
for t in a:
    res *= t
    if res > 10**18:
        print(-1)
        sys.exit()
    if res == 0:
        print(res)
        sys.exit()
else:
    print(res)
Buggy python submission (verdict: Runtime Error):
s = int(input())
w = int(input())

if w >= s:
    print("unsafe")
else:
    print("safe")

Fixed submission:
s, w = map(int, input().split())

if w >= s:
    print("unsafe")
else:
    print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())
ans = [0] * n
for i in range(1, n+1):
    for j in range(1, n+1):
        r = min(
            abs(i-j),
            abs(x-i) + 1 + abs(y-j),
            abs(y-i) + 1 + abs(x-j)
        )
        if r > n-1:
            continue
        ans[r] += 1

print("\n".join(map(lambda u: str(u//2), ans[1:])))

Fixed submission:
n, x, y = map(int, input().split())
ans = [0] * n
for i in range(1, n+1):
    for j in range(i, n+1):
        r = min(
            abs(i-j),
            abs(x-i) + 1 + abs(y-j),
            abs(y-i) + 1 + abs(x-j)
        )
        ans[r] += 1

print("\n".join(map(str, ans[1:])))

Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())
ans = [0] * n
for i in range(1, n+1):
    for j in range(1, n+1):
        r = min(
            abs(i-j),
            abs(x-i) + 1 + abs(y-j),
            abs(y-i) + 1 + abs(x-j)
        )
        if r > n-1:
            continue
        ans[r] += 1

for r in ans[1:]:
    print(r//2)

Fixed submission:
n, x, y = map(int, input().split())
ans = [0] * n
for i in range(1, n+1):
    for j in range(i, n+1):
        r = min(
            abs(i-j),
            abs(x-i) + 1 + abs(y-j),
            abs(y-i) + 1 + abs(x-j)
        )
        ans[r] += 1

print("\n".join(map(str, ans[1:])))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, x, y = map(int, input().split())
dist = np.array([[i for i in range(n+1)] for _ in range(n+1)])

r = abs(x - y) - 1


for i in range(1, n+1):
    dist[i] = abs(dist[i] - i)
dist[x][y] = 1
dist[y][x] = 1
dist[x] = np.minimum(dist[x], dist[x][y] + dist[y])
dist[y] = np.minimum(dist[y], dist[y][x] + dist[x])

for i in range(n+1):
    dist[i] = np.minimum(dist[i], dist[i][y] + 1 + dist[x], dist[i][x] + 1 + dist[y])
    if i <= x:
        dist[i] = np.minimum(dist[i], dist[i][x] + 1 + dist[y])
    elif y <= i:
        dist[i] = np.minimum(dist[i], dist[i][y] + 1 + dist[x])
    else:
        dist[i] = np.minimum(dist[i],
                             dist[i][y] + 1 + dist[x]
                             )
        dist[i] = np.minimum(dist[i],
                             dist[i][x] + 1 + dist[y]
                             )



ans = np.zeros(n+1)
for row in dist[1:, 1:]:
    for j in row:
        if 0 <= j <= n-1:
            ans[j] += 1


for w in ans[1:n]:
    print(int(w//2))





Fixed submission:
n, x, y = map(int, input().split())
ans = [0] * n
for i in range(1, n+1):
    for j in range(i, n+1):
        r = min(
            abs(i-j),
            abs(x-i) + 1 + abs(y-j),
            abs(y-i) + 1 + abs(x-j)
        )
        ans[r] += 1

print("\n".join(map(str, ans[1:])))
Buggy python submission (verdict: Runtime Error):
import heapq
X, Y, a, b, c = map(int, input().split())
p = list(map(lambda x: -int(x), input().split()))
q = list(map(lambda x: -int(x), input().split()))
r = list(map(lambda x: -int(x), input().split()))

heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

ans = 0
for _ in range(X):
    ap1 = heapq.heappop(p)
    ap2 = heapq.heappop(r)
    if ap1 <= ap2:
        ans -= ap1
        heapq.heappush(r, ap2)
    else:
        ans -= ap2
        heapq.heappush(p, ap1)

for _ in range(Y):
    ap1 = heapq.heappop(q)
    ap2 = heapq.heappop(r)
    if ap1 <= ap2:
        ans -= ap1
        heapq.heappush(r, ap2)
    else:
        ans -= ap2
        heapq.heappush(q, ap1)

print(ans)

Fixed submission:
import heapq
X, Y, a, b, c = map(int, input().split())
p = list(map(lambda x: -int(x), input().split()))
q = list(map(lambda x: -int(x), input().split()))
r = list(map(lambda x: -int(x), input().split()))
p.sort()
q.sort()
t = p[:X] + q[:Y] + r

heapq.heapify(t)

ans = 0
for _ in range(X+Y):
    ap = heapq.heappop(t)
    ans -= ap

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())


def s_add(r, f):
    if r % 2 == 0:
        if f == 1:
            return True
        else:
            return False
    else:
        if f == 1:
            return False
        else:
            return True


cnt = 0
for _ in range(q):
    query = input()
    if query == "1":
        cnt += 1
    else:
        z, f, c = query.split()
        if s_add(cnt, int(f)):
            s = c + s
        else:
            s += c

if cnt % 2 == 0:
    print(s)
else:
    print(s[::-1])


Fixed submission:
s = input()
q = int(input())
left = ""
right = ""


def s_add(r, f):
    if r % 2 == 0:
        if f == 1:
            return True
        else:
            return False
    else:
        if f == 1:
            return False
        else:
            return True


cnt = 0
for _ in range(q):
    query = input()
    if query == "1":
        cnt += 1
    else:
        z, f, c = query.split()
        if s_add(cnt, int(f)):
            left += c
        else:
            right += c

if cnt % 2 == 0:
    print(left[::-1] + s + right)
else:
    print(right[::-1] + s[::-1] + left)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
q = int(input())
query = []
a = []
for _ in range(q):
    method, i, c = input().split()
    if method == "1":
        a.append([i, c])
    else:
        a.append([i, c])
        query.append(a)
        a = []
string = []
now = s
for qq in query:
    if len(qq) == 1:
        string.append("".join(now))
        continue
    for i, c in qq[:-1]:
        i = int(i)
        now[i-1] = c
    string.append("".join(now))
for qq, ss in zip(query, string):
    l, r = map(int, qq[-1])
    print(len(set(ss[l-1:r])))

Fixed submission:
class SegmentTree:

    def __init__(self, ls, ide, seg_func):
        n = len(ls)
        self.num = 2 ** (n - 1).bit_length()
        self.seg_func = seg_func
        self.ide = ide
        self.tree = [self.ide] * (2 * self.num - 1)
        for i, l in enumerate(ls):
            self.tree[i + self.num - 1] = l

        for i in range(self.num - 2, -1, -1):  # 子を束ねて親を更新
            self.tree[i] = seg_func(self.tree[2 * i + 1], self.tree[2 * i + 2])

    def update(self, i, x):
        i += self.num - 1
        self.tree[i] = x
        while i:
            i = (i-1)//2
            self.tree[i] = self.seg_func(self.tree[2 * i + 1], self.tree[2 * i + 2])

    def query(self, l, r):
        if r < l:
            return ValueError('invalid index')

        l += self.num - 1
        r += self.num - 2
        res = self.ide
        while r - l > 1:  # 右から寄りながら結果を結合していくイメージ
            if l & 1 == 0:
                res = self.seg_func(res, self.tree[l])
            if r & 1 == 1:
                res = self.seg_func(res, self.tree[r])
                r -= 1
            l = l // 2  # 親の一つ右に移動
            r = (r - 1) // 2  # 親の一つ左に移動
        if l == r:
            res = self.seg_func(res, self.tree[l])
        else:
            res = self.seg_func(res, self.tree[l])
            res = self.seg_func(res, self.tree[r])
        return res


def f(a, b):
    return a | b


n = int(input())
s = [1 << (ord(r) - ord("a")) for r in input()]
q = int(input())
st = SegmentTree(s, 0, f)

for _ in range(q):
    m, i, c = input().split()

    if int(m) - 1:
        x = st.query(int(i)-1, int(c))
        print(bin(x).count("1"))
    else:
        st.update(int(i)-1, 1 << (ord(c) - ord("a")))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())


def log(r, d):
    return np.log(d)/np.log(r)


def ceil(x):
    if x.is_integer():
        return int(x)
    return int(np.ceil(x))


print(ceil(log(k, n)))

Fixed submission:
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)


n, k = map(int, input().split())
print(len(Base_10_to_n(n, k)))
Buggy python submission (verdict: Runtime Error):
n = list(map(int, list(input())))
ans = 0
c_in = 0
q = 0


def carry(x, i, q):
    if x[i] <= 8:
        x[i] += 1
    else:
        x[i] = 0
        if x[i] == x[0]:
            x[i] = 0
            q += 1
        else:
            carry(x, i-1, q)


while len(n) > 0:
    s = n.pop()
    if 0 <= s <= 5:
        ans += s
        if c_in:
            c_in = 0
    elif 6 <= s <= 9:
        ans += 10 - s
        c_in = 1
        carry(n, -1, q)
    print(s, ans)

ans += q
print(ans)



Fixed submission:
n = [0] + list(map(int, list(input())))
ans = 0
c_in = 0

while n:
    s = n.pop()
    s += c_in
    if 0 <= s <= 4:
        ans += s
        c_in = 0
    elif 6 <= s:
        ans += abs(10 - s)
        c_in = 1
    else:
        ans += 5
        if 5 <= n[-1]:
            c_in = 1
        else:
            c_in = 0

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
sum_e = np.cumsum(p)
ans = 0
for i in range(n-k+1):
    ans = max(ans, sum_e[i+k] - sum_e[i])
print(ans)

Fixed submission:
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
sum_E = np.cumsum(p)
sum_e = np.append([0], sum_E)
ans = -1
for i in range(n-k+1):
    ans = max(ans, sum_e[i+k] - sum_e[i])
print(ans/2)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(lambda x: int(x) + 1, input().split()))
max_ans = 0
for i in range(n-k+1):
    max_ans = max(max_ans, sum(p[i:k+i]))
print(max_ans/2)

Fixed submission:
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
sum_E = np.cumsum(p)
sum_e = np.append([0], sum_E)
ans = -1
for i in range(n-k+1):
    ans = max(ans, sum_e[i+k] - sum_e[i])
print(ans/2)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
ans = np.zeros(n-k+1)
for i in range(k):
    ans += p[i:n-k+1+i]
print(max(ans)/2)

Fixed submission:
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
sum_E = np.cumsum(p)
sum_e = np.append([0], sum_E)
ans = -1
for i in range(n-k+1):
    ans = max(ans, sum_e[i+k] - sum_e[i])
print(ans/2)

Buggy python submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
ans = np.zeros(n-k+1)
for i in range(n-k+1):
    ans += p[i:k+i]
print(max(ans)/2)

Fixed submission:
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
sum_E = np.cumsum(p)
sum_e = np.append([0], sum_E)
ans = -1
for i in range(n-k+1):
    ans = max(ans, sum_e[i+k] - sum_e[i])
print(ans/2)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
max_ans = 0
for i in range(n-k+1):
    max_ans = max(max_ans, np.sum(p[i:k+i]))
print(max_ans/2)

Fixed submission:
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
sum_E = np.cumsum(p)
sum_e = np.append([0], sum_E)
ans = -1
for i in range(n-k+1):
    ans = max(ans, sum_e[i+k] - sum_e[i])
print(ans/2)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
p = np.array(list(map(int, input().split())))
ans = 1
for i in range(1, n):
    if p[i] <= min(p[:i]):
        ans += 1

print(ans)

Fixed submission:
import numpy as np
n = int(input())
p = np.array(list(map(int, input().split())))
ans = 1
min_n = p[0]
for i in range(1, n):
    min_n = min(min_n, p[i-1])
    if p[i] <= min_n:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
ans = 1
for i in range(1, n):
    if p[i] <= min(p[:i]):
        ans += 1

print(ans)


Fixed submission:
import numpy as np
n = int(input())
p = np.array(list(map(int, input().split())))
ans = 1
min_n = p[0]
for i in range(1, n):
    min_n = min(min_n, p[i-1])
    if p[i] <= min_n:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())


def judge(a, b):
    a_str, b_str = str(a), str(b)
    if a_str[0] == b_str[-1] and a_str[-1] == b_str[0]:
        return True
    else:
        return False


ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        if judge(i, j):
            ans += 1

print(ans)

Fixed submission:
n = int(input())
c = [[0] * 10 for _ in range(10)]
for k in range(1, n+1):
    i = int(str(k)[0])
    j = k % 10
    c[i][j] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
n = int(input())
s = tuple(map(int, input()))
a = tuple(set(itertools.combinations(s, 3)))
ans = len(a)
print(ans)


Fixed submission:
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())

if m1 + 1 == m2 and d2 == 1:
    print(1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = tuple(map(int, input()))
f = [
    [] for i in range(n+1)
]
ans = 0

for i in range(n-2):
    if len(f[s[i]]) != 0:
        continue
    else:
        for j in range(i+1, n-1):
            if s[j] in f[s[i]]:
                continue
            else:
                f[s[i]].append(s[j])
                a = tuple(set(s[j+1:]))
                ans += len(a)

print(ans)


Fixed submission:
n = int(input())
s = tuple(map(int, input()))
f = [
    [] for i in range(10)
]
ans = 0

for i in range(n-2):
    if len(f[s[i]]) != 0:
        continue
    else:
        for j in range(i+1, n-1):
            if s[j] in f[s[i]]:
                continue
            else:
                f[s[i]].append(s[j])
                a = tuple(set(s[j+1:]))
                ans += len(a)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n = int(input())
s = tuple(map(int, input()))
f = []
ans = 0

for i in range(n-2):
    right = n - 1
    if s[i] in f:
        continue
    else:
        f.append(s[i])
        left = i + 1
        a = tuple(set(itertools.combinations(s[left:right+1], 2)))
        ans += len(a)

print(ans)


Fixed submission:
n = int(input())
s = tuple(map(int, input()))
f = [
    [] for i in range(10)
]
ans = 0

for i in range(n-2):
    if len(f[s[i]]) != 0:
        continue
    else:
        for j in range(i+1, n-1):
            if s[j] in f[s[i]]:
                continue
            else:
                f[s[i]].append(s[j])
                a = tuple(set(s[j+1:]))
                ans += len(a)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n = int(input())
s = tuple(map(int, input()))
a = tuple(set(itertools.combinations(s, 3)))
ans = len(a)
print(ans)


Fixed submission:
n = int(input())
s = tuple(map(int, input()))
f = [
    [] for i in range(10)
]
ans = 0

for i in range(n-2):
    if len(f[s[i]]) != 0:
        continue
    else:
        for j in range(i+1, n-1):
            if s[j] in f[s[i]]:
                continue
            else:
                f[s[i]].append(s[j])
                a = tuple(set(s[j+1:]))
                ans += len(a)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n = int(input())
s = list(map(int, input()))
a = tuple(set(itertools.combinations(s, 3)))
ans = len(a)
print(ans)


Fixed submission:
n = int(input())
s = tuple(map(int, input()))
f = [
    [] for i in range(10)
]
ans = 0

for i in range(n-2):
    if len(f[s[i]]) != 0:
        continue
    else:
        for j in range(i+1, n-1):
            if s[j] in f[s[i]]:
                continue
            else:
                f[s[i]].append(s[j])
                a = tuple(set(s[j+1:]))
                ans += len(a)

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

ans = 1
cnt = [0, 0, 0]
for i in a:
    ans *= cnt.count(i)
    cnt[cnt.index(i)] += 1
    ans %= mod
print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

ans = 1
cnt = [0, 0, 0]
for i in a:
    ans *= cnt.count(i)
    for j in range(3):
        if cnt[j] == i:
            cnt[j] += 1
            break
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
a = tuple(map(int, input().split()))
b = np.full(n, np.inf)
for i in range(n-1):
    x = abs(sum(a[:i+1])-sum(a[i+1:]))
    b[i] = x
print(int(min(b)))


Fixed submission:
import numpy as np
n = int(input())
a = tuple(map(int, input().split()))
b = np.full(n, np.inf)
f = 0
s = sum(a)
for i in range(n-1):
    f += a[i]
    s -= a[i]
    x = abs(f - s)
    b[i] = x
print(int(min(b)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = tuple(map(int, input().split()))
b = []
for i in range(n):
    x = abs(sum(a[:i+1])-sum(a[i+1:]))
    b.append(x)
print(min(b))

Fixed submission:
import numpy as np
n = int(input())
a = tuple(map(int, input().split()))
b = np.full(n, np.inf)
f = 0
s = sum(a)
for i in range(n-1):
    f += a[i]
    s -= a[i]
    x = abs(f - s)
    b[i] = x
print(int(min(b)))
Buggy python submission (verdict: Runtime Error):
import sys
x, y = map(int, input().split())


def power_func(a, b, p):
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power_func(a, b//2, p)
        return d*d % p
    if b % 2 == 1:
        return (a*power_func(a, b-1, p)) % p


def comb(n, k, p):
    from math import factorial
    if n < 0 or k < 0 or n < k:
        return 0
    if n == 0 or k == 0:
        return 1
    a = factorial(n) % p
    b = factorial(k) % p
    c = factorial(n-k) % p
    return (a*power_func(b, p-2, p)*power_func(c, p-2, p)) % p


w = (x + y) / 3
b = (- x + 2*y) // 3

if w.is_integer():
    w = int(w)
else:
    print(0)
    sys.exit()

a = min(b, w-b)
ans = comb(w, a, 10**9+7)
print(ans)


Fixed submission:
r = int(input())
print(r**2)