Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h = int(input())
stack = deque([h])
count = 0
while (len(stack) >= 1):
    hp = stack.pop()
    count += 1
    if (hp == 1):
        continue
    else:
        hp = hp//2
        stack.append(hp)
        stack.append(hp)
print(count)


Fixed submission:
from collections import deque
h = int(input())
# stack = deque([h])
# count = 0
# while (len(stack) >= 1):
#     hp = stack.pop()
#     count += 1
#     if (hp == 1):
#         continue
#     else:
#         hp = hp//2
#         stack.append(hp)
#         stack.append(hp)
# print(count)
count = 0
hueru_ryo = 1
while h > 0:
    h = h//2
    count += hueru_ryo
    hueru_ryo *= 2
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# 多分TLE
import numpy as np
from collections import deque
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    for j in range(i + 1, n):
        ans += (a[i] ^ a[j]) % mod
print(ans % mod)


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
a = np.array(a)
ans = 0
# for bin_a in map(bin, a):
d = 1
num_of_one_per_keta = []
while d < (1 << 61):
    cnt = np.count_nonzero(a & d)
    num_of_one_per_keta.append(cnt)
    d <<= 1
ans = 0
for i, num_of_one in enumerate(num_of_one_per_keta):
    ans += (n-num_of_one)*num_of_one*pow(2, i, mod) % mod
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
S = S()
after_lis = [set() for _ in range(N+1)]
i = N-1
for s in reversed(S):
    after_lis[i] = (after_lis[i] | after_lis[i+1])
    after_lis[i].add(int(s))
    i -= 1

ans_lis = np.zeros([10, 10, 10], dtype=np.int32)

for i_100 in range(N - 2):
    s_100 = int(S[i_100])
    for i_10 in range(i_100+1, N-1):
        s_10 = int(S[i_10])
        # print(after_lis[i_10+1])
        ans_lis[s_100, s_10, list(after_lis[i_10+1])] = 1

        # sは暗証番号の一番左
print(np.sum(ans_lis))


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
S = S()
after_lis = [set() for _ in range(N+1)]
i = N-1
for s in reversed(S):
    after_lis[i] = (after_lis[i] | after_lis[i+1])
    after_lis[i].add(int(s))
    i -= 1

left_index = {}
for i, s in enumerate(S):
    if s not in left_index:
        left_index[s] = i

ans_lis = np.zeros([10, 10, 10], dtype=np.int32)

for char in left_index:
    s_100 = int(char)
    for i_10 in range(left_index[char]+1, N-1):
        # print("s_10")
        s_10 = int(S[i_10])
        ans_lis[s_100, s_10, list(after_lis[i_10+1])] = 1

        # sは暗証番号の一番左
# print(ans_lis)
print(np.sum(ans_lis))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections
import itertools
mod = 10 ** 9 + 7
N = int(input())
L = list(map(int, input().split()))
count = 0
for a, b, c in itertools.combinations(L, 3):
    if ((a < b + c) and (b < a + c) and (c < a + b)):
        count += 1
print(count)


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections
import itertools
import bisect
mod = 10 ** 9 + 7
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
count = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        a = L[i]
        b = L[j]
        idx = insert_index = bisect.bisect_left(L, a+b)
        count += max(0, idx-j-1)


print(count)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 天気の入力
s = int(input())
# 出力
lis = ['Sunny', 'Cloudy', 'Rainy']
index = lis.index(s)
index = (index+1)%len(lis)
print(lis[index])

Fixed submission:
# -*- coding: utf-8 -*-
# 天気の入力
s = (input())
# 出力
lis = ['Sunny', 'Cloudy', 'Rainy']
index = lis.index(s)
index = (index+1)%len(lis)
print(lis[index])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N, K = zz()
S = S()
change_points = [0]
if (S[0] == S[1] == 'R'):
    ans = 1
else:
    ans = 0
for i in range(1, N):
    if S[i] == 'L':
        if (S[i - 1] == 'L'):
            ans += 1
    else:
        if (i == N - 1):
            pass
        elif (S[i + 1] == 'R'):
            ans += 1

    if (S[i] != S[i - 1]):
        change_points.append(i)
# print(change_points)
# print(ans)
ans += (2*K)

print(min(ans, N-1))


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N, K = zz()
S = S()
change_points = [0]
if (N == 1):
    print(0)
    exit()
if (S[0] == S[1] == 'R'):
    ans = 1
else:
    ans = 0
for i in range(1, N):
    if S[i] == 'L':
        if (S[i - 1] == 'L'):
            ans += 1
    else:
        if (i == N - 1):
            pass
        elif (S[i + 1] == 'R'):
            ans += 1

    if (S[i] != S[i - 1]):
        change_points.append(i)
# print(change_points)
# print(ans)
ans += (2*K)

print(min(ans, N-1))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


s = S()
t = S()
set_s = set(s)
set_t = set(t)
if (set_t <= set_s) is False:
    print(-1)
    exit()
alphabet2index = defaultdict(list)
for i, alphabet in enumerate(s):
    alphabet2index[alphabet].append(i+1)
ans = 0
pos = 0
prev_pos = 0
base = 0
n = -1
c = 0
for _t in t:
    n = s.find(_t, n+1)
    if (n == -1):
        c += 1
        n = s.find(_t)
ans = n + c*len(s) + 1
"""

    ng_flg = True
    while ng_flg:
        pos_lis = alphabet2index[_t]
        i = 0
        while len(pos_lis) > i:
            if (pos_lis[i] >= pos):
                pos = pos_lis[i]
                ans += (pos_lis[i]-prev_pos)
                # print(pos_lis[i], prev_pos, )
                prev_pos = pos
                ng_flg = False
                break
            i += 1
        else:
            prev_pos = pos - len(s)
            # print(prev_pos)
            # print('base', base)
            pos = 0
    """
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


s = S()
t = S()
set_s = set(s)
set_t = set(t)
if (set_t <= set_s) is False:
    print(-1)
    exit()
alphabet2index = defaultdict(list)
for i, alphabet in enumerate(s):
    alphabet2index[alphabet].append(i+1)
ans = 0
pos = 0
prev_pos = 0
base = 0
n = -1
c = 0
for _t in t:
    n = s.find(_t, n+1)
    if (n == -1):
        c += 1
        n = s.find(_t)
ans = n + c*len(s) + 1
"""

    ng_flg = True
    while ng_flg:
        pos_lis = alphabet2index[_t]
        i = 0
        while len(pos_lis) > i:
            if (pos_lis[i] >= pos):
                pos = pos_lis[i]
                ans += (pos_lis[i]-prev_pos)
                # print(pos_lis[i], prev_pos, )
                prev_pos = pos
                ng_flg = False
                break
            i += 1
        else:
            prev_pos = pos - len(s)
            # print(prev_pos)
            # print('base', base)
            pos = 0
    """
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
move = pow(10, 100)
S = input()
ans = np.zeros(len(S), np.int64)
for i in range(len(S)):
    pre_pos = -1
    pre_pre_pos = -1
    pos = i
    move_count = 0
    while pre_pre_pos != pos:
        move_count += 1
        if (S[pos] == 'L'):
            pre_pre_pos = pre_pos
            pre_pos = pos
            pos -= 1
        else:
            pre_pre_pos = pre_pos
            pre_pos = pos
            pos += 1
    if move_count % 2 == 0:
        ans[pos] += 1
    else:
        ans[pre_pos] += 1


print(*list(ans))


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
S = input()
ans = np.zeros(len(S), np.int64)
pos = 0
last_R = 0
while pos < (len(S)):
    if S[pos] == 'R':
        move_count = 0
        while S[pos] == 'R':  # Lを探す
            last_R = pos
            move_count += 1
            pos += 1
        # 'L'発見 S[pos] == L
        ans[pos] += (move_count)//2
        ans[pos-1] += (move_count - (move_count)//2)
    else:  # S[pos] == 'L':
        move_count = 0
        # print('found L')
        while pos < len(S):
            # print(pos, len(S))
            if S[pos] == 'L':  # 'R'を探す
                pos += 1
            else:
                break
        # R発見
        move_count = pos-1 - last_R
        # print(move_count, '=', pos, '-', last_R)
        ans[last_R] += (move_count)//2
        ans[last_R+1] += (move_count - (move_count)//2)


print(*list(ans))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
box = np.zeros(N+1, np.int32)
ans = []
for i in reversed(range(1, N+1)):
    # iの倍数の箱の合計
    if sum(box[i::i]) % 2 != A[i-1]:
        box[i] = 1
        ans.append(i)
    # sum(box[i::i]) % 2 == A[i]
print(len(ans))
print(*ans)


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
box = [0] * (N+1)
ans = []
for i in reversed(range(1, N+1)):
    # iの倍数の箱の合計
    if sum(box[i::i]) % 2 != A[i-1]:
        # sum_ = sum([box[i*j] for j in range(1, N//i+1)])
        box[i] = 1
        ans.append(i)
print(len(ans))
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, K = zz()
A, B = [0]*N, [0]*N
lis = []
for i in range(N):
    a, b = zz()
    lis.extend([a]*b)
lis = sorted(lis)
print(lis[K-1])


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, K = zz()
A, B = [0]*N, [0]*N
# 力技はだめ
for i in range(N):
    A[i], B[i] = zz()
A, B = zip(*sorted(zip(A, B)))
all_num = 0
for i, b in enumerate(B):
    all_num += b
    if (all_num >= K):
        print(A[i])
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
s=len(input())

def cmb(n,r,mod):
  if r<0 or n<r:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

mod=10**9+7

g1=[1,1]#元table
g2=[1,1]#逆元table
inv=[0,1]#逆元table計算用

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

ans=1
for i in range(1,k+1):
  ans=(ans*26+cmb(i+s-1,s-1,mod)*pow(25,i,mod))%mod
print(ans)

Fixed submission:
k=int(input())
s=len(input())

def cmb(n,r,mod):
  if r<0 or n<r:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

mod=10**9+7

g1=[1,1]#元table
g2=[1,1]#逆元table
inv=[0,1]#逆元table計算用

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

ans=1
for i in range(1,k+1):
  ans=(ans*26+cmb(i+s-1,s-1,mod)*pow(25,i,mod))%mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
a.sort()
cnt=[0]*(a[-1]+1)
while a:
  m=a.pop(0)
  cnt[m]+=1
  i=0
  while i<len(a):
    if a[i]%m==0 and a[i]//m>1:
      a.pop(i)
      continue
    i+=1
ans=0
for ci in cnt:
  ans+=(1 if ci==1 else 0)
print(ans)

Fixed submission:
n,*a=map(int,open(0).read().split())
a.sort()
m=a[-1]+1
cnt=[0]*m
for ai in a:
  if cnt[ai]!=0:
    cnt[ai]+=1
    continue
  for i in range(ai,m,ai):
    cnt[i]+=1
ans=0
for ai in a:
  ans+=(cnt[ai]==1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
a.sort()
cnt=[0]*(a[-1]+1)
while a:
  m=a.pop(0)
  cnt[m]+=1
  i=0
  while i<len(a):
    if a[i]%m==0 and a[i]//m>1:
      a.pop(i)
      continue
    i+=1
ans=0
for ci in cnt:
  ans+=(1 if ci==1 else 0)
print(ans)

Fixed submission:
n,*a=map(int,open(0).read().split())
a.sort()
m=a[-1]+1
cnt=[0]*m
for ai in a:
  if cnt[ai]!=0:
    cnt[ai]+=1
    continue
  for i in range(ai,m,ai):
    cnt[i]+=1
ans=0
for ai in a:
  ans+=(cnt[ai]==1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,s,*a=map(int,open(0).read().split())
mod=998244353
dp=[[0]*(s+1) for _ in range(n+1)]
dp[0][0]=pow(2,n,mod)
for i in range(n):
  for j in range(s+1):
    dp[i+1][j]+=dp[i][j]
    dp[i+1][j]%=mod
    if j+a[i]<=s:
      dp[i+1][j+a[i]]+=dp[i][j]*(mod+1)//2
      dp[i+1][j+a[i]]%=mod
print(dp[n][s])

Fixed submission:
n,s,*a=map(int,open(0).read().split())
mod=998244353
dp=[[0]*(s+1) for _ in range(n+1)]
dp[0][0]=pow(2,n,mod)
for i in range(n):
  for j in range(s+1):
    dp[i+1][j]+=dp[i][j]
    dp[i+1][j]%=mod
    if j+a[i]<=s:
      dp[i+1][j+a[i]]+=dp[i][j]*(mod+1)//2
      dp[i+1][j+a[i]]%=mod
print(dp[n][s])
Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,open(0).read().split())
mod=998244353
c=[1]*(k+1)
for i in range(1,k+1):
  c[i]=c[i-1]*(n-i)//i
ans=0
for i in range(k+1):
  ans+=m*pow(m-1,n-1-i,mod)*(c[i]%mod)
  ans%=mod
print(ans)

Fixed submission:
n,m,k=map(int,open(0).read().split())
p=998244353
'''
c=[1]*(k+1)
for i in range(1,k+1):
  c[i]=c[i-1]*(n-i)//i
  c[i-1]%=mod
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 998244353
N = n  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
ans=0
for i in range(k+1):
  ans+=m*pow(m-1,n-1-i,p)*cmb(n-1,i, p)
  ans%=p
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
u=int(s[-1])
s=s[:-1]
l=[0]*2019
l[0]=1
for i in s[::-1]:
  u=int(i)*10**len(str(u))+u
  l[u%2019]+=1
ans=0
for i in l:
  ans+=i*(i-1)//2
print(ans)

Fixed submission:
s=input()
ans=0
u=0
l=[0]*2019
l[0]=1
for i,n in enumerate(map(int,s)):
  u=(u+n*pow(10,len(s)-i,2019))%2019
  l[u]+=1
for i in l:
  ans+=i*(i-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
a=sorted([(j,i) for i,j in enumerate(a)])[::-1]
dp=[[-1]*(n+1) for _ in range(n+1)]
dp[0][0]=0
for m,(a_k,k) in enumerate(a):
  for i in range(m+1):
    j=m-i
    dp[i+1][j]=max(dp[i+1][j],dp[i][j]+a_k*abs(k-i))
    dp[i][j+1]=max(dp[i][j+1],dp[i][j]+a_k*abs(k-((n-1)-j)))
ans=0
for i in range(n+1):
  ans=max(ans,dp[i][n-i])
print(ans)

Fixed submission:
n,*a=map(int,open(0).read().split())
a=sorted([(j,i) for i,j in enumerate(a)])[::-1]
dp=[[-1]*(n+1) for _ in range(n+1)]
dp[0][0]=0
for m,(a_k,k) in enumerate(a):
  for i in range(m+1):
    j=m-i
    dp[i+1][j]=max(dp[i+1][j],dp[i][j]+a_k*abs(k-i))
    dp[i][j+1]=max(dp[i][j+1],dp[i][j]+a_k*abs(k-((n-1)-j)))
ans=0
for i in range(n+1):
  ans=max(ans,dp[i][n-i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
k=int(input())
ans=0
for p in range(1,k+1):
  for q in range(1,k+1):
    for r in range(1,k+1):
      ans+=gcd(p,gcd(q,r))
print(ans)

Fixed submission:
from math import gcd
k=int(input())
ans=0
for p in range(1,k+1):
  for q in range(1,k+1):
    for r in range(1,k+1):
      ans+=gcd(p,gcd(q,r))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
k=int(input())
ans=0
for p in range(1,k+1):
  for q in range(1,k+1):
    for r in range(1,k+1):
      ans+=gcd(p,gcd(q,r))
print(ans)

Fixed submission:
from math import gcd
k=int(input())
ans=0
for p in range(1,k+1):
  for q in range(1,k+1):
    for r in range(1,k+1):
      ans+=gcd(p,gcd(q,r))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
flag=0
for _ in range(q):
  query=input().split()
  if len(query)==1:
    flag=(flag+1)%2
  else:
    if (int(query[1])+flag)%2:
      s=query[2]+s
    else:
      s=s+query[2]
print(s if flag==0 else s[::-1])

Fixed submission:
from collections import deque
s=deque(input())
q=int(input())
flag=0
for _ in range(q):
  query=input().split()
  if len(query)==1:
    flag=(flag+1)%2
  else:
    if (int(query[1])+flag)%2:
      s.appendleft(query[2])
    else:
      s.append(query[2])
print(''.join(s) if flag==0 else ''.join(reversed(s)))
Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
mx=max(a for a,b in ab)
dp=[float('inf')]*(h+1+mx)
dp[0]=0
for i in range(1,h+1+mx):
  dp[i]=min(dp[i-a]+b for a,b in ab)
print(min(dp[h:]))

Fixed submission:
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
mx=max(a for a,b in ab)
dp=[10**10]*(h+1+mx)
dp[0]=0
for i in range(1,h+1+mx):
  dp[i]=min(dp[i-a]+b for a,b in ab)
print(min(dp[h:]))
Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
mod=10**9+7
ans=0
for j in range(60):
  cnt=0
  for i in range(n):
    cnt+=a[i]&1
    a[i]=(a[i]>>1)
  ans+=(cnt*(n-cnt)%mod)*pow(2,j,mod)
  ans%=mod
print(ans)

Fixed submission:
n,*a=map(int,open(0).read().split())
mod=10**9+7
ans=0
for j in range(60):
  cnt=0
  for i in range(n):
    cnt+=a[i]&1
    a[i]=(a[i]>>1)
  ans+=(cnt*(n-cnt)%mod)*pow(2,j,mod)
  ans%=mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=0
for i in range(1000):
  t=str(i).zfill(3)
  j=0
  for s_i in s:
    if j<3 and t[j]==s_i:
      j+=1
  if j==3:
    ans+=1
print(ans)

Fixed submission:
n=int(input())
s=input()
ans=0
for i in range(1000):
  t=str(i).zfill(3)
  j=0
  for s_i in s:
    if j<3 and t[j]==s_i:
      j+=1
  if j==3:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
mod=10**9+7
l=[0]*n
l[0]=3
ans=1
for ai in a:
  ans*=l[ai]
  ans%=mod
  l[ai]-=1
  l[ai+1]+=1
print(ans)

Fixed submission:
n,*a=map(int,open(0).read().split())
mod=10**9+7
l=[0]*(n+1)
l[0]=3
ans=1
for ai in a:
  ans*=l[ai]
  ans%=mod
  l[ai]-=1
  l[ai+1]+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n=int(input())
tree=[[] for _ in range(n+1)]
for i in range(1,n):
  a,b=map(int,input().split())
  tree[a].append([b,i])
  tree[b].append([a,i])
queue=deque([[1,1]])
ans=[-1]*(n+1)

while queue:
  v,i=queue.popleft()
  color=1
  for nv,j in tree[v]:
    if ans[i]==color:
      color+=1
    if not ans[nv]==-1:
      continue
    queue.append([nv,color])
    ans[j]=color
    color+=1
print(max(ans))
for i in range(1,n):
  print(ans[i])

Fixed submission:
from collections import deque
n=int(input())
tree=[[] for _ in range(n+1)]
for i in range(1,n):
  a,b=map(int,input().split())
  tree[a].append([b,i])
  tree[b].append([a,i])
queue=deque([[1,0]])
ans=[0]*(n+1)
ans[1]=1
visited=[0]*(n+1)

while queue:
  v,c=queue.popleft()
  color=1
  for nv,i in tree[v]:
    if c==color:
      color+=1
    if visited[i]==1:
      continue
    visited[i]=1
    queue.append([nv,color])
    ans[i]=color
    color+=1
print(max(ans))
for i in range(1,n):
  print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n=int(input())
tree=[[] for _ in range(n+1)]
for i in range(1,n):
  a,b=map(int,input().split())
  tree[a].append([b,i])
  tree[b].append([a,i])
queue=deque([[1,1]])
ans=[-1]*(n+1)

while queue:
  v,i=queue.popleft()
  color=1
  for nv,j in tree[v]:
    if ans[i]==color:
      color+=1
    if not ans[nv]==-1:
      continue
    queue.append([nv,color])
    ans[j]=color
    color+=1
print(max(ans))
for i in range(1,n):
  print(ans[i])

Fixed submission:
from collections import deque
n=int(input())
tree=[[] for _ in range(n+1)]
for i in range(1,n):
  a,b=map(int,input().split())
  tree[a].append([b,i])
  tree[b].append([a,i])
queue=deque([[1,0]])
ans=[0]*(n+1)
ans[1]=1
visited=[0]*(n+1)

while queue:
  v,c=queue.popleft()
  color=1
  for nv,i in tree[v]:
    if c==color:
      color+=1
    if visited[i]==1:
      continue
    visited[i]=1
    queue.append([nv,color])
    ans[i]=color
    color+=1
print(max(ans))
for i in range(1,n):
  print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q,*a=map(int,open(0).read().split())
for i in range(1,n+1):
  print('Yes' if k-q+a.count(i)>0 else 'No')

Fixed submission:
from collections import Counter
n,k,q,*a=map(int,open(0).read().split())
a=Counter(a)
for i in range(1,n+1):
  print('Yes' if k-q+a[i]>0 else 'No')