Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#200322D
N = int(input())
A = list(map(int,input().split()))
count = []

AllCount = 0
for i in range(N):
    icount = 0   
    for j in range(N):
        if A[i] == A[j]:
            icount += 1
            AllCount += 1
    count.append(icount)
            
for i in range(N):            
    print(int((AllCount-N)/2-count[i] + 1))

Fixed submission:
#200322D
from collections import Counter

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

c = Counter(A)
#print(c)
#print(c[1])
#print(c[A[0]])
L = len(c)
#print(L)

def nCm(x):
    return x * (x - 1) / 2

c_list = list(c.keys())

All = 0
for i in range(L):
    All += nCm(c[c_list[i]])

for i in range(N):
    Ans = All - (c[A[i]]) + 1
    print(int(Ans))

Buggy python submission (verdict: Time Limit Exceeded):
#200322D
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N):
    for j in range(N):
        if A[i] == A[j]:
            count += 1
All = (count - N) / 2
#print(int(All))

for i in range(N):
    count = 0
    for j in range(N):
        if A[i] == A[j]:
            count += 1
    print(int(All - count + 1))

Fixed submission:
#200322D
from collections import Counter

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

c = Counter(A)
#print(c)
#print(c[1])
#print(c[A[0]])
L = len(c)
#print(L)

def nCm(x):
    return x * (x - 1) / 2

c_list = list(c.keys())

All = 0
for i in range(L):
    All += nCm(c[c_list[i]])

for i in range(N):
    Ans = All - (c[A[i]]) + 1
    print(int(Ans))

Buggy python submission (verdict: Time Limit Exceeded):
#200322D
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N):
    for j in range(N):
        if A[i] == A[j]:
            count += 1
All = (count - N) / 2
#print(int(All))

for i in range(N):
    count = 0
    for j in range(N):
        if A[i] == A[j]:
            count += 1
    print(int(All - count + 1))

Fixed submission:
#200322D
from collections import Counter

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

c = Counter(A)
#print(c)
#print(c[1])
#print(c[A[0]])
L = len(c)
#print(L)

def nCm(x):
    return x * (x - 1) / 2

c_list = list(c.keys())

All = 0
for i in range(L):
    All += nCm(c[c_list[i]])

for i in range(N):
    Ans = All - (c[A[i]]) + 1
    print(int(Ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())+1
a = list(map(int, input().split()))
cnt = []

sum = 0
for i in range(100005):
    cnt.append(a.count(i))
    sum += i * cnt[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    sum += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sum)


Fixed submission:
n = int(input())+1
a = list(map(int, input().split()))
cnt = []
for i in range(100005):
    cnt.append(0)
sum = 0

for i in a:
    cnt[i] += 1
for i in range(100005):
    sum += i * cnt[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    sum += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())+1
a = list(map(int, input().split()))
cnt = []

sum = 0
for i in range(100005):
    cnt.append(a.count(i))
    sum += i * cnt[i]

q = int(input())
ans = []

for i in range(q):
    b, c = map(int, input().split())
    sum += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    ans.append(sum)

for i in ans:
    print(i)






Fixed submission:
n = int(input())+1
a = list(map(int, input().split()))
cnt = []
for i in range(100005):
    cnt.append(0)
sum = 0

for i in a:
    cnt[i] += 1
for i in range(100005):
    sum += i * cnt[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    sum += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())+1
a = list(map(int, input().split()))
cnt = []

for i in range(100005):
    cnt.append(0)
sum = 0
for i in range(100005):
    cnt[i] = a.count(i)
    sum += i * cnt[i]

q = int(input())
ans = []

for i in range(q):
    b, c = map(int, input().split())
    sum += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    ans.append(sum)

for i in ans:
    print(i)






Fixed submission:
n = int(input())+1
a = list(map(int, input().split()))
cnt = []
for i in range(100005):
    cnt.append(0)
sum = 0

for i in a:
    cnt[i] += 1
for i in range(100005):
    sum += i * cnt[i]

q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    sum += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    if x < y:
        x, y = y, x
    if y < 1:
        return x
    return gcd(y, x%y)

k = int(input())

sum = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        gcd_ab = gcd(a, b)
        for c in range(1, k+1):
            sum += gcd(gcd_ab, c)

print(sum)

Fixed submission:
def gcd(x, y):
    if x < y:
        x, y = y, x
    while y != 0:
        org_x = x
        x = y
        y = org_x % y
    return x

k = int(input())

sum = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        gcd_ab = gcd(a, b)
        for c in range(1, k+1):
            sum += gcd(gcd_ab, c)

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

rev = 0
for _ in range(q):
    query = list(input().split())
    if query[0] == "1":
        rev = 1 if rev == 0 else 0
    else:
        if query[1] == "1":
            if rev == 0:
                s = query[2] + s
            else:
                s = s + query[2]
        else:
            if rev == 0:
                s = s + query[2]
            else:
                s = query[2] + s
if rev == 1:
    new_s = ''.join(list(reversed(s)))
    print(new_s)
else:
    print(s)

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())

rev = False
for _ in range(q):
    query = list(input().split())
    t = query[0]
    if t == "1":
        rev = not rev
    else:
        f = int(query[1])
        c = query[2]
        if rev:
            f = 3 - f
        if f == 1:
            s.appendleft(c)
        else:
            s.append(c)
if rev:
    s.reverse()
print(''.join(s))

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

rev = 0
for _ in range(q):
    query = list(input().split())
    if query[0] == "1":
        rev = 1 if rev == 0 else 0
    else:
        if query[1] == "1":
            if rev == 0:
                s = query[2] + s
            else:
                s = s + query[2]
        else:
            if rev == 0:
                s = s + query[2]
            else:
                s = query[2] + s
if rev == 1:
    print(s[::-1])
else:
    print(s)

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())

rev = False
for _ in range(q):
    query = list(input().split())
    t = query[0]
    if t == "1":
        rev = not rev
    else:
        f = int(query[1])
        c = query[2]
        if rev:
            f = 3 - f
        if f == 1:
            s.appendleft(c)
        else:
            s.append(c)
if rev:
    s.reverse()
print(''.join(s))
Buggy python submission (verdict: Time Limit Exceeded):
def choose(n, r, M):
    x = 1
    y = 1

    for i in range(r):
        x *= (n - i) % M
        y *= (i + 1) % M
    res = x * pow(y, M-2, M) % M
    return res

n, a, b = map(int, input().split())
M = 10 ** 9 + 7

print((pow(2, n, M) - 1 - choose(n, a, M) - choose(n, b, M)) % M)

Fixed submission:
def choose(n, r, M):
    x = 1
    y = 1

    for i in range(r):
        x = x * (n - i) % M
        y = y * (i + 1) % M
    res = x * pow(y, M-2, M) % M
    return res

n, a, b = map(int, input().split())
M = 10 ** 9 + 7

print((pow(2, n, M) - 1 - choose(n, a, M) - choose(n, b, M)) % M)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
max_d_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]

ans = sorted(max_d_list)

for i in ans:
    print(i)


Fixed submission:
n = int(input())

d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
max_d = max(d.values())
max_d_list = [kv[0] for kv in d.items() if kv[1] == max_d]

ans = sorted(max_d_list)

for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
# D - Dice in Line

n,k=map(int, input().split())
p=list(map(int, input().split()))
q=[0]*n

for i in range(n):
    q[i]=(p[i]+1)/2

max=0
for i in range(n-k+1):
    sum=0
    for j in range(i, i+k):
        sum+=q[j]
    if sum > max:
        max=sum
print(max)


Fixed submission:
# D - Dice in Line

n,k=map(int, input().split())
p=list(map(int, input().split()))
q=[0]*n

for i in range(n):
    q[i]=(p[i]+1)/2

max=0
for i in range(k):
    max+=q[i]

sum=max
for i in range(1, n-k+1):
    sum=sum-q[i-1]+q[i+k-1]
    if sum > max:
        max=sum
print(max)
Buggy python submission (verdict: Runtime Error):
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())

if m1 != m2:
    print("1")
    exit(1)

print("0")


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

if m1 != m2:
    print("1")
else:
    print("0")

Buggy python submission (verdict: Runtime Error):
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())

if m1 != m2:
    print("1")
    exit(1)

print(0)


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

if m1 != m2:
    print("1")
else:
    print("0")
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(m):
    maxid = a.index(max(a))
    a[maxid] = a[maxid] // 2
print(sum(a))

Fixed submission:
from heapq import heapify, heappop, heappush
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = a[i] * -1
heapify(a)
for _ in range(m):
    minval = heappop(a)
    heappush(a, math.ceil(minval / 2))
ans = 0
for i in range(n):
    ans += int(a[i])
print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(m):
    a.sort(reverse=True)
    a[0] = a[0] // 2
print(sum(a))

Fixed submission:
from heapq import heapify, heappop, heappush
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = a[i] * -1
heapify(a)
for _ in range(m):
    minval = heappop(a)
    heappush(a, math.ceil(minval / 2))
ans = 0
for i in range(n):
    ans += int(a[i])
print(-ans)
Buggy python submission (verdict: Runtime Error):
ans=0
bef=-10
for i in range(n):
    ans+=b[a[i]-1]
    if a[i]-1 == bef:
        ans+=c[a[i]-2]
    bef=a[i]
print(ans)

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

ans=0
bef=-10
for i in range(n):
    ans+=b[a[i]-1]
    if a[i]-1 == bef:
        ans+=c[a[i]-2]
    bef=a[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for _ in range(N):
    s.append(sorted(input()))

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if s[i] == s[j]:
            count+=1

print(count)

Fixed submission:
N = int(input())
S = {}

for i in range(N):
    str = ''.join(sorted(input()))
    if str in S.keys():
        S[str] += 1
    else:
        S.setdefault(str, 1)

cnt = 0
for v in S.values():
    cnt += (v * (v-1) // 2)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for _ in range(N):
    s.append(input())

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if sorted(s[i]) == sorted(s[j]):
            count+=1

print(count)

Fixed submission:
N = int(input())
S = {}

for i in range(N):
    str = ''.join(sorted(input()))
    if str in S.keys():
        S[str] += 1
    else:
        S.setdefault(str, 1)

cnt = 0
for v in S.values():
    cnt += (v * (v-1) // 2)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for _ in range(N):
    s.append(input())

count = 0
for i in range(N):
    for j in range(i+1, N):
        if sorted(s[i]) == sorted(s[j]):
            count+=1

print(count)

Fixed submission:
N = int(input())
S = {}

for i in range(N):
    str = ''.join(sorted(input()))
    if str in S.keys():
        S[str] += 1
    else:
        S.setdefault(str, 1)

cnt = 0
for v in S.values():
    cnt += (v * (v-1) // 2)

print(cnt)
Buggy python submission (verdict: Runtime Error):
n = input()
s = list(map(int, input().split()))
ans = 1
if 0 in ans:
  print(0)
else:
  for i in s:
    if ans > 10**18:
      break
    ans *= int(i)
  if ans > 10**18:
    print(-1)
  else:
    print(ans)



Fixed submission:
n = int(input())
arr = list(map(int, input().split()))
total = 1
if 0 in arr:
    print(0)
else:
    for num in arr:
        if total > 10**18:
            break
        total *= num
    if total > 10**18:
        print(-1)
    else:
        print(total)

Buggy python submission (verdict: Runtime Error):
n = input()
s = input().split(" ")
ans = 1
for i in s:
  ans *= i
print(ans)

Fixed submission:
n = int(input())
arr = list(map(int, input().split()))
total = 1
if 0 in arr:
    print(0)
else:
    for num in arr:
        if total > 10**18:
            break
        total *= num
    if total > 10**18:
        print(-1)
    else:
        print(total)

Buggy python submission (verdict: Runtime Error):
n = input()
s = input()
s = s.split()
ans = 1
for i in range(n):
  ans *= int(i)
if ans >= 1000000000000000000:
  print(-1)
else:
 	print(ans)

Fixed submission:
n = int(input())
arr = list(map(int, input().split()))
total = 1
if 0 in arr:
    print(0)
else:
    for num in arr:
        if total > 10**18:
            break
        total *= num
    if total > 10**18:
        print(-1)
    else:
        print(total)

Buggy python submission (verdict: Runtime Error):
s = input()
s = s.split()
ans = 1
for i in s:
  ans *= int(i)
  
 print(ans)

Fixed submission:
n = int(input())
arr = list(map(int, input().split()))
total = 1
if 0 in arr:
    print(0)
else:
    for num in arr:
        if total > 10**18:
            break
        total *= num
    if total > 10**18:
        print(-1)
    else:
        print(total)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N=int(input())
X=input()

value = int(X,2)
#print(value)
TFlist =[]
for i in range(N):
  if X[i] == '0':
  	TFlist.append(False)
  else:
    TFlist.append(True)
#print(TFlist)
p = sum(TFlist)


def count_ones_by_bin(num):
    bin_num = bin(num)[2:]
    count = 0
    for i in bin_num:
            count += int(i)
    return count
  
def popcount(n):
 # print("popcount",n)
  return (n  % count_ones_by_bin(n))

for i in range(N):
#  print("N", N)
  cnt = 0
  tmp = 0
  if p != 1 or (not TFlist[i]):
    if TFlist[i]: tmp = (value - (pow(2,(N-i-1), (p-1)))) % (p-1)
    else: tmp = (value +  pow(2,(N-i-1), (p+1) )  ) % (p+1)
    # print(tmp)
    cnt += 1
  while tmp != 0:
    cnt+= 1
    tmp = popcount(tmp)
  print(cnt)

Fixed submission:
from collections import Counter
N=int(input())
X=input()

value = int(X,2)
#print(value)
TFlist =[]
for i in range(N):
  if X[i] == '0':
  	TFlist.append(False)
  else:
    TFlist.append(True)
#print(TFlist)
p = sum(TFlist)


def count_ones_by_bin(num):
    bin_num = bin(num)[2:]
    count = 0
    for i in bin_num:
            count += int(i)
    return count
  
def popcount(n):
 # print("popcount",n)
  return (n  % count_ones_by_bin(n))

for i in range(N):
#  print("N", N)
  cnt = 0
  tmp = 0
  if p != 1 or (not TFlist[i]):
    if TFlist[i]: tmp = (value % (p-1) - (pow(2,(N-i-1), (p-1)))) % (p-1)
    else: tmp = (value % (p+1) + (pow(2,(N-i-1) , (p+1) ) ) ) % (p+1)    
    cnt += 1
  while tmp != 0:
    cnt+= 1
    tmp = popcount(tmp)
  print(cnt)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
X=input()
value = int(X,2)
#print(value)
TFlist =[]
for i in range(N):
  if X[i] == '0':
  	TFlist.append(False)
  else:
    TFlist.append(True)
#print(TFlist)
p = sum(TFlist)


def count_ones_by_bin(num):
    bin_num = bin(num)[2:]
    count = 0
    for i in bin_num:
            count += int(i)
    return count
  
def popcount(n):
 # print("popcount",n)
  return (n  % count_ones_by_bin(n))

for i in range(N):
#  print("N", N)
  cnt = 0
  if TFlist[i]: tmp = (value % (p-1) - (pow(2,(N-i-1), (p-1)))) % (p-1)
  else: tmp = (value % (p+1) + ( pow(2,(N-i-1), (p+1) ) ) ) % (p+1)
 # print(tmp)
  cnt += 1
  while tmp != 0:
    cnt+= 1
    tmp = popcount(tmp)
  print(cnt)

Fixed submission:
from collections import Counter
N=int(input())
X=input()

value = int(X,2)
#print(value)
TFlist =[]
for i in range(N):
  if X[i] == '0':
  	TFlist.append(False)
  else:
    TFlist.append(True)
#print(TFlist)
p = sum(TFlist)


def count_ones_by_bin(num):
    bin_num = bin(num)[2:]
    count = 0
    for i in bin_num:
            count += int(i)
    return count
  
def popcount(n):
 # print("popcount",n)
  return (n  % count_ones_by_bin(n))

for i in range(N):
#  print("N", N)
  cnt = 0
  tmp = 0
  if p != 1 or (not TFlist[i]):
    if TFlist[i]: tmp = (value % (p-1) - (pow(2,(N-i-1), (p-1)))) % (p-1)
    else: tmp = (value % (p+1) + (pow(2,(N-i-1) , (p+1) ) ) ) % (p+1)    
    cnt += 1
  while tmp != 0:
    cnt+= 1
    tmp = popcount(tmp)
  print(cnt)
Buggy python submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cum_A=[]
cum_B=[]
for i in range(N):
  cum_A.append(cum_A[-1]+A[i])
  cum_B.append(cum_B[-1]+B[i])
ans, j = 0,M
for i in range(N+1):
  if a[i] > K :
    break
  while b[j] > K-a[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)

Fixed submission:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cum_A=[0]
cum_B=[0]
for i in range(N):
  cum_A.append(cum_A[-1]+A[i])
for i in range(M):
  cum_B.append(cum_B[-1]+B[i])
ans, j = 0,M
for i in range(N+1):
  if cum_A[i] > K:
    break
  while cum_B[j] > K-cum_A[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
mod = 10**9+7
def fact_list(a):
  ans = [1]
  for i in range(1,a+1):
    ans.append(ans[-1]*i % mod)
  return ans

factlist = fact_list(M)

def comb_mod(a,b):
  return (factlist[a]*pow(factlist[b],mod-2,mod)*pow(factlist[a-b],mod-2,mod) )% mod

def permu_mod(a,b):
  return (factlist[a]*pow(factlist[a-b],mod-2,mod) % mod)

ans = 0
for i in range(N+1):
  ans += comb_mod(N,i)*(-1)**i*permu_mod(M,i)*permu_mod(M-i,N-i)**2 
  ans = ans % mod
print(ans)


Fixed submission:
N,M=map(int,input().split())
mod = 10**9+7
def fact_list(a):
  ans = [1]
  for i in range(1,a+1):
    ans.append(ans[-1]*i % mod)
  return ans

factlist = fact_list(M)

def comb_mod(a,b):
  return (factlist[a]*pow(factlist[b],mod-2,mod)*pow(factlist[a-b],mod-2,mod) )% mod

def permu_mod(a,b):
  return (factlist[a]*pow(factlist[a-b],mod-2,mod) % mod)

ans = 0
for i in range(N+1):
  ans += comb_mod(N,i)*(-1)**i*permu_mod(M,i)*permu_mod(M-i,N-i)**2 
  ans = ans % mod
print(ans)
Buggy python submission (verdict: Runtime Error):
L=[26**i for i in range(12)]
#print(L)
gun=[sum(L[1:i])for i in range(2,12)]
#print(gun)
N=int(input())
i=0
while N > gun[i]:
  i += 1
#print(i)
if i != 0:
  N = N - gun[i-1] #これを26進法
N -= 1
#print(N)
L=[]
for k in range(1,i+2):
   L.append(N//(26**(i+1-k)))
   N = N % (26**(i+1-k))
#print(L)
L=[chr(i+97) for i in L]
#print(L)
print(''.join(L))

Fixed submission:
L=[26**i for i in range(13)]
#print(L)
gun=[sum(L[1:i])for i in range(2,13)]
#print(gun)
N=int(input())
i=0
while N > gun[i]:
  i += 1
#print(i)
if i != 0:
  N = N - gun[i-1] #これを26進法
N -= 1
#print(N)
L=[]
for k in range(1,i+2):
   L.append(N//(26**(i+1-k)))
   N = N % (26**(i+1-k))
#print(L)
L=[chr(i+97) for i in L]
#print(L)
print(''.join(L))
Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())
S=input()

len_S=len(S)

#逆元を用いたコンビネーション
mod = 10**9+7
def mul_mod(a,b):
  return (a*b) % mod

def fact_inv(a):
  ans = 1
  for i in range(1,a+1):
    ans = (pow(i,mod-2,mod) * ans) % mod
  return ans

fact_list = [1]
for i in range(1,len_S+K):
  fact_list.append(mul_mod(fact_list[-1],i))

fact_list_inv = [1]
for i in range(1,len_S+K):
  fact_list_inv .append((pow(i,mod-2,mod) * fact_list_inv[-1]) % mod)

def comb_inv_mod(a,b):
  return (fact_list[a]*fact_list_inv[b]*fact_list_inv[a-b]) % mod

ans = 0
for i in range(len_S-1,len_S+K): #Snの位置
  #print(i)
  #ans += comb_inv(len_S+K-(len_S+K-i-1)-1,N-1)*pow(25,(K-(len_S+K-i-1)),mod)*pow(26,len_S+K-i-1,mod)
  A = comb_inv_mod(i,len_S-1)*pow(25,i-len_S+1,mod) % mod 
  A = A*pow(26,len_S+K-i-1,mod) % mod
  ans += A
  #print(ans)
  ans = ans % mod
print(ans)

Fixed submission:
K=int(input())
S=input()

len_S=len(S)

#逆元を用いたコンビネーション
mod = 10**9+7
def mul_mod(a,b):
  return (a*b) % mod

def fact_inv(a):
  ans = 1
  for i in range(1,a+1):
    ans = (pow(i,mod-2,mod) * ans) % mod
  return ans

fact_list = [1]
for i in range(1,len_S+K):
  fact_list.append(mul_mod(fact_list[-1],i))

fact_list_inv = [1]
for i in range(1,len_S+K):
  fact_list_inv .append((pow(i,mod-2,mod) * fact_list_inv[-1]) % mod)
def comb_inv_mod(a,b):
  tmp = (fact_list[a]*fact_list_inv[b]) % mod
  return (tmp*fact_list_inv[a-b]) % mod

ans = 0
for i in range(len_S-1,len_S+K): #Snの位置
  #print(i)
  #ans += comb_inv(len_S+K-(len_S+K-i-1)-1,N-1)*pow(25,(K-(len_S+K-i-1)),mod)*pow(26,len_S+K-i-1,mod)
  A = comb_inv_mod(i,len_S-1)*pow(25,i-len_S+1,mod) % mod 
  A = A*pow(26,len_S+K-i-1,mod) % mod
  ans += A
  #print(ans)
  ans = ans % mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans =1
for i in range(N):
  ans *= A[i]
if ans > 10**18:
  print(-1)
else:
  print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
if min(A) == 0:
  print(0)
  exit()
else:
  ans =1
for i in range(N-1):
  ans *= A[i]
  if ans > 10**18:
    print(-1)
    exit()
ans *= A[N-1]
if ans > 10**18:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,S=map(int,input().split())
A=[0]+list(map(int,input().split()))
         
mod = 998244353

note = [[0 for i in range(S+1)] for n in range(N+1)]

for n in range(1,N+1):
  for i in range(1,S+1):
    if A[n]>i:
      note[n][i] = (note[n-1][i]*2) % mod
    elif A[n] == i:
      note[n][i] = note[n-1][i]*2 + pow(2,n-1,mod)
      note[n][i] = note[n][i] % mod 
    else:
      note[n][i] = note[n-1][i] * 2 + note[n-1][i-A[n]]
      note[n][i] = note[n][i] % mod
  #print(note)
print(note[N][S] % mod)
  
    
       

Fixed submission:
N,S=map(int,input().split())
A=[0]+list(map(int,input().split()))
       
mod = 998244353

note = [[0 for i in range(S+1)] for n in range(N+1)]

for n in range(1,N+1):
  for i in range(1,S+1):
    if A[n]>i:
      note[n][i] = (note[n-1][i]*2) % mod
    elif A[n] == i:
      note[n][i] = (note[n-1][i]*2 + pow(2,n-1,mod)) % mod
      note[n][i] = note[n][i] % mod 
    else:
      note[n][i] = (note[n-1][i] * 2 + note[n-1][i-A[n]]) % mod
      note[n][i] = note[n][i] % mod
  #print(note)
print(note[N][S] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[]
for i in range(M):
  L.append(list(map(int,input().split())))
#print(L)
ans=[i for i in range(N)]
for i in range(M):
  ori=L[i][0]-1
  dest=L[i][1]-1
 # print(ori,dest)
  if H[ori] <= H[dest]:
    if ori in ans: ans.remove(ori)
  if H[ori] >= H[dest]:
    if dest in ans: ans.remove(dest)

#print(ans)
print(len(ans))

Fixed submission:
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[]
for i in range(M):
  L.append(list(map(int,input().split())))
#print(L)
bad=[]
for i in range(M):
  ori=L[i][0]-1
  dest=L[i][1]-1
 # print(ori,dest)
  if H[ori] <= H[dest]:
    bad.append(ori)
  if H[ori] >= H[dest]:
    bad.append(dest)

deletes=set(bad)
print(N-len(deletes))
#print(ans)
#print(len(ans))