Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List = list(map(int,input().split()))
ans = 1
for item in List:
  ans *= item
  if ans > 10 **18:
    ans = -1
print(ans)

Fixed submission:
N = int(input())
List = list(map(int,input().split()))
ans = 1
for item in List:
  ans *= item
  if ans > 10 **18 or ans <= -1:
    ans = -1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List = list(map(int,input().split()))
ans = 1
for item in List:
  ans *= item
if ans > 10 **18:
  print(-1)
else:
  print(ans)

Fixed submission:
N = int(input())
List = list(map(int,input().split()))
ans = 1
for item in List:
  ans *= item
  if ans > 10 **18 or ans <= -1:
    ans = -1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input().split()))
if n == 0:
  if nums[0] == 1:
    print(1)
  else:
    print(-1)
  exit()
if n >=1 and nums[0] != 0:
  print(-1)
  exit()
n_nods = 1
ans = 1
ret = sum(nums)
for i in range(1,n+1):
  n_nods = min(n_nods*2,ret)
  ans += n_nods
  ret -= nums[i]
  n_nods -= nums[i]
  if n_nods < 0:
    print(-1)
    exxit()
  if n_nods == 0 and i < n:
    print(-1)
    exit()
print(ans)

Fixed submission:
n = int(input())
nums = list(map(int, input().split()))
if n == 0:
  if nums[0] == 1:
    print(1)
  else:
    print(-1)
  exit()
if n > 0 and nums[0] != 0:
  print(-1)
  exit()
n_nods = 1
ans = 1
ret = sum(nums)
for i in range(1,n+1):
  n_nods = min(n_nods*2,ret)
  ans += n_nods
  ret -= nums[i]
  n_nods -= nums[i]
  if n_nods < 0:
    print(-1)
    exit()
  if n_nods == 0 and i < n:
    print(-1)
    exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List = list(map(int,input().split()))
counter = 0
for i in range(N-1):
  for j in range(i+1,N):
    if List[i]+List[j] == j - i:
      counter += 1
print(counter)

Fixed submission:
from collections import defaultdict
N = int(input())
List = list(map(int,input().split()))
dicL = defaultdict(int)
dicR = defaultdict(int)
for i in range(N):
  dicL[List[i]+i] += 1
  dicR[i - List[i]] += 1
counter = 0
for item in dicL:
  if item in dicR:
    counter += dicL[item]*dicR[item]
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
import math
A,B,N = map(int,input().split())
ret = 0
ans = 0
for x in range(1,min(B,N+1)):
  temp = math.floor(A*x/B) - A*math.floor(x/B)
  if temp > ret:
    ret = temp
    ans = x
print(ret)

Fixed submission:
import math
A,B,N = map(int,input().split())
ret = 0
ans = 0
if B == 0:
  print(0)
  exit()
if B > N:
  base = N
else:
  base = B - 1
ret = math.floor(A*base/B) - A*math.floor(base/B)
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import math
A,B,N = map(int,input().split())
ret = 0
ans = 0
for x in range(1,N+1):
  temp = math.floor(A*x/B) - A*math.floor(x/B)
  if temp > ret:
    ret = temp
    ans = x
print(ret)

Fixed submission:
import math
A,B,N = map(int,input().split())
ret = 0
ans = 0
if B == 0:
  print(0)
  exit()
if B > N:
  base = N
else:
  base = B - 1
ret = math.floor(A*base/B) - A*math.floor(base/B)
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())+1
ans = 0
for i in range(1,k):
  for j in range(1,k):
    for l in range(1,k):
      ans += math.gcd(math.gcd(i,j),l)
print(ans)

Fixed submission:
from math import gcd
k = int(input())+1
ans = 0
for i in range(1,k):
  for j in range(1,k):
    for l in range(1,k):
      ans += gcd(gcd(i,j),l)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
ans = 0
for i in range(k):
  for j in range(k):
    for l in range(k):
      ans += math.gcd(math.gcd(i+1,j+1),l+1)
print(ans)

Fixed submission:
from math import gcd
k = int(input())+1
ans = 0
for i in range(1,k):
  for j in range(1,k):
    for l in range(1,k):
      ans += gcd(gcd(i,j),l)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
#K = int(input())
K = 200
def gcd_List(List):
  return reduce(gcd,List)
sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum += gcd_List([i,j,k])
print(sum)

Fixed submission:
from math import gcd
k = int(input())+1
ans = 0
for i in range(1,k):
  for j in range(1,k):
    for l in range(1,k):
      ans += gcd(gcd(i,j),l)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y = map(int,input().split())
data = [[3000]*N for _ in range(N)]
for i in range(N-1):
  data[i][i+1] = 1
  data[i+1][i] = 1
  data[i][i] = 0
data[0][0] = 0
data[X-1][Y-1] = 1
data[Y-1][X-1] = 1
for k in range(N):
  for i in range(N):
    for j in range(N):
      data[i][j] = min(data[i][j],data[i][k]+data[k][j])
for i in range(N-1):
  counter = 0
  for j in range(N):
    counter += data[j].count(i+1)
  print(int(counter//2))

Fixed submission:
N,X,Y = map(int,input().split())
a = [0]*(N-1)
for i in range(1,N):
  for j in range(i+1,N+1):
    ans = min(j-i,abs(X-i)+1+abs(Y-j),abs(X-j)+1+abs(Y-i))
    a[ans -1] += 1
for item in a:
  print(item)

Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y = map(int,input().split())
data = [[3000]*N for _ in range(N)]
edge = []
for i in range(N-1):
  edge.append((i+1,i+2))
edge.append((X,Y))
for item in edge:
  data[item[0]-1][item[1]-1] = 1
  data[item[1]-1][item[0]-1] = 1
for i in range(N):
  data[i][i] = 0
for k in range(N):
  for i in range(N):
    for j in range(N):
      data[i][j] = min(data[i][j],data[i][k]+data[k][j])
for i in range(N-1):
  counter = 0
  for j in range(N):
    counter += data[j].count(i+1)
  print(int(counter//2))

Fixed submission:
N,X,Y = map(int,input().split())
a = [0]*(N-1)
for i in range(1,N):
  for j in range(i+1,N+1):
    ans = min(j-i,abs(X-i)+1+abs(Y-j),abs(X-j)+1+abs(Y-i))
    a[ans -1] += 1
for item in a:
  print(item)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
if H == 1 or W == 1:
  print(I)
elif H*W % 2 == 0:
  print(H*W//2)
else:
  print(H*W//2+1)

Fixed submission:
H,W = map(int,input().split())
if H == 1 or W == 1:
  print(1)
elif H*W % 2 == 0:
  print(H*W//2)
else:
  print(H*W//2+1)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
reverse = 0
front = []
end = []
n = int(input())
for _ in range(n):
  List = list(input().split())
  #print(List)
  if List[0] == '1':
    reverse += 1
    front,end = end[::-1],front[::-1]
  else:
    if List[1] == '1':
      front.insert(0,List[2])
    else:
      end.append(List[2])
if reverse %2 == 1:
  S = S[::-1]
Answer = ''.join(front) + S + ''.join(end)
print(Answer)

Fixed submission:
S = input()
reverse = 0
front = []
end = []
n = int(input())
for _ in range(n):
  List = list(input().split())
  if List[0] == '1':
    reverse += 1
  else:
    if List[1] == '1':
      if reverse % 2 == 1:
        end.append(List[2])
      else:
        front.append(List[2])
    else:
      if reverse % 2 == 1:
        front.append(List[2])
      else:
        end.append(List[2])
if reverse %2 == 1:
  S = S[::-1]
  front, end = end, front
Answer = ''.join(front[::-1]) + S + ''.join(end)
print(Answer)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
if M == 0:
  if N == 1:
    print(0)
    exit()
  elif N == 2:
    print(10)
    exit()
  else:
    print(100)
    exit()
dic = {} 
for _ in range(M):
  s,c = map(int,input().split())
  if s in dic and dic[s] != c:
    print(-1)
    exit()
  else:
    dic[s] = c
if N != 1 and dic[1] == 0:
  print(-1)
  exit()
ans = ''
for i in range(N):
  if i+1 in dic:
    ans += str(dic[i+1])
  elif i+1 == 1:
    ans += '1'
  else:
    ans += '0'
print(ans)

Fixed submission:
N,M = map(int,input().split())
ret = ['a']*N
for _ in range(M):
  s,c = map(int,input().split())
  if ret[s-1] not in ['a', c]:
    print(-1)
    exit()
  ret[s-1] = c
if ret[0] == 0:
  if N != 1:
    print(-1)
    exit()
ans = ''
for i in range(N):
  if ret[i] != 'a':
    ans += str(ret[i])
  else:
    if i == 0 and N > 1:
      ans += '1'
    else:
      ans += '0'
print(int(ans))

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = ['a']*N
dic = {} 
for _ in range(M):
  s,c = map(int,input().split())
  if s in dic and dic[s] != c:
    print(-1)
    exit()
  elif s==1 and c == 0:
    print(-1)
    exit()
  else:
    dic[s] = c
  ans = ''
  for i in range(N):
    if i+1 in dic:
      ans += str(dic[i+1])
    elif i+1 == 1:
      ans += '1'
    else:
      ans += '0'
print(ans)

Fixed submission:
N,M = map(int,input().split())
ret = ['a']*N
for _ in range(M):
  s,c = map(int,input().split())
  if ret[s-1] not in ['a', c]:
    print(-1)
    exit()
  ret[s-1] = c
if ret[0] == 0:
  if N != 1:
    print(-1)
    exit()
ans = ''
for i in range(N):
  if ret[i] != 'a':
    ans += str(ret[i])
  else:
    if i == 0 and N > 1:
      ans += '1'
    else:
      ans += '0'
print(int(ans))

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = ['a']*N
for _ in range(M):
  s,c = map(int,input().split())
  if A[s-1] !='a' and A[s-1] != c:
    print(-1)
    exit()
  else:
    A[s-1] = c

for i in range(N):
  if A[0] == 'a' and N==3:
    A[0] = 1
  else A[i] == 'a':
    A[i] = 0
Answer = ''.join(map(str,A))

if Answer != '0' and len(Answer) != N:
  Answer = -1
if Answer == '000':
  Answer = -1
print(Answer)


Fixed submission:
N,M = map(int,input().split())
ret = ['a']*N
for _ in range(M):
  s,c = map(int,input().split())
  if ret[s-1] not in ['a', c]:
    print(-1)
    exit()
  ret[s-1] = c
if ret[0] == 0:
  if N != 1:
    print(-1)
    exit()
ans = ''
for i in range(N):
  if ret[i] != 'a':
    ans += str(ret[i])
  else:
    if i == 0 and N > 1:
      ans += '1'
    else:
      ans += '0'
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
List = list(map(int,input().split()))
result = [(1+i)/2 for i in List]
Answer = 0
for i in range(N-K+1):
  counter = sum(result[i:i+K])
  if counter > Answer:
    Answer = counter

print(Answer)

Fixed submission:
N,K = map(int,input().split())
List = list(map(int,input().split()))
result = [(1+i)/2 for i in List]
Answer = 0
if N == 1:
  print(result[0])
  exit()
elif N == K:
  print(sum(result))
  exit()
base = [sum(result[0:K])]
for i in range(N-K):
  counter = base[i]-result[i]+result[i+K]
  if counter > Answer:
    Answer = counter
  base.append(counter)
print(Answer)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
List = list(map(int,input().split()))
result = [(1+i)/2 for i in List]
Answer = 0
for i in range(N-K+1):
  counter = sum(result[i:i+K])
  if counter > Answer:
    Answer = counter

print(Answer)

Fixed submission:
N,K = map(int,input().split())
List = list(map(int,input().split()))
result = [(1+i)/2 for i in List]
Answer = 0
if N == 1:
  print(result[0])
  exit()
elif N == K:
  print(sum(result))
  exit()
base = [sum(result[0:K])]
for i in range(N-K):
  counter = base[i]-result[i]+result[i+K]
  if counter > Answer:
    Answer = counter
  base.append(counter)
print(Answer)
Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
magic = []
for i in range(N):
  a,b = map(int,input().split())
  magic.append((a,b))
A = [item[0] for item in magic]
maxA = max(A)
minA = min(A)
dp = [float("inf")]*(H+maxA+1)
dp[0]=0

for i in range(H+maxA):
  for j in range(N):
    dp[i] = min(dp[i],
                dp[max(i-magic[j][0],0)]+magic[j][1])

print(dp[H])

Fixed submission:
H,N = map(int,input().split())
magic = []
for i in range(N):
  a,b = map(int,input().split())
  magic.append((a,b))
A = [item[0] for item in magic]
maxA = max(A)
minA = min(A)
dp = [float("inf")]*(H+maxA+1)
dp[0]=0
for i in range(H+maxA):
  for j in range(N):
    dp[i] = min(dp[i],
                dp[max(i-magic[j][0],0)]+magic[j][1])
print(dp[H])
Buggy python submission (verdict: Runtime Error):
X = int(input())
coins = [100,101,102,103,105]
DP = [int(i%coins[0]==0) for i in range(X+1)]
for coin in coins[1:]:
  for i in range(X+1):
    DP[i] += DP[i - coin]
if DP[-1] != 0:
  print(1)
else:
  print(0)


Fixed submission:
N=int(input())
coins = [100,101,102,103,104,105]
dp = [int(i%coins[0]==0) for i in range(N+1)]
for coin in coins[1:]:
  for i in range(coin,N+1):
    dp[i] += dp[i - coin]
if dp[-1] != 0:
  print(1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
import fractions
A,B = map(int,input().split())
x = fractions.gcd(A,B)
pf = {}
for i in range(2,int(x**0.5)+2):
  while x%i == 0:
    pf[i] = pf.get(i,0) +1
    x //= i
if x > 1:
  pf[m] = 1
print(len(pf)+1)

Fixed submission:
import fractions
A,B = map(int,input().split())
x = fractions.gcd(A,B)
pf = {}
for i in range(2,int(x**0.5)+2):
  while x%i == 0:
    pf[i] = pf.get(i,0) +1
    x //= i
if x > 1:
  pf[x] = 1
print(len(pf)+1)

Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int,input().split())
 
def cf(x1,x2):
  cf=[]
  for i in range(2,min(x1,x2)+1):
    if x1 % i == 0 and x2 % i == 0:
      cf.append(i)
  return cf
 
List = cf(a, b)
import fractions
 
def check(x1, x2):
  if fractions.gcd(x1, x2) == 1:
    return 1
  else:
    return 0
 
 
Answer = []
for i in range(len(List)):
  if i == 0:
    Answer.append(List[i])
  else:
    checker = 1
    for j in range(len(Answer)):
      if check(Answer[j], List[i]) == 0:
        checker = 0
        break
    if checker == 1:
      Answer.append(List[i])

print(len(Answer)+1)

Fixed submission:
import fractions
A,B = map(int,input().split())
x = fractions.gcd(A,B)
pf = {}
for i in range(2,int(x**0.5)+2):
  while x%i == 0:
    pf[i] = pf.get(i,0) +1
    x //= i
if x > 1:
  pf[x] = 1
print(len(pf)+1)

Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int,input().split())

def cf(x1,x2):
  cf=[]
  for i in range(2,min(x1,x2)+1):
    if x1 % i == 0 and x2 % i == 0:
      cf.append(i)
  return cf

List = cf(a, b)
import fractions

def check(x1, x2):
  if fractions.gcd(x1, x2) == 1:
    return 1
  else:
    return 0


Answer = []
for i in range(len(List)):
  if i == 0:
    Answer.append(List[i])
  else:
    checker = 1
    for j in range(len(Answer)):
      checker *= check(Answer[j],List[i])
    if checker == 1:
      Answer.append(List[i])

print(len(Answer)+1)



Fixed submission:
import fractions
A,B = map(int,input().split())
x = fractions.gcd(A,B)
pf = {}
for i in range(2,int(x**0.5)+2):
  while x%i == 0:
    pf[i] = pf.get(i,0) +1
    x //= i
if x > 1:
  pf[x] = 1
print(len(pf)+1)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
dp = [float('inf')]*2 ** N
dp[0] = 0
for _ in range(N):
  a,b = map(int,input().split())
  c = sum([2**(int(i)-1) for i in input().split()])
  for s in range(2**N):
    t = s|c
    if dp[t] > dp[s] + a:
      dp[t] = dp[s] +a
ans = dp[-1]
if dp[-1] == float('inf'):
  print(-1)
else:
  print(ans)

Fixed submission:
N,M = map(int,input().split())
dp = [float('inf')]*2 ** N
dp[0] = 0
for _ in range(M):
  a, b = map(int, input().split())
  c = sum([2**(int(i)-1) for i in input().split()])
  for s in range(2**N):
    t = s|c
    if dp[t] > dp[s] + a:
      dp[t] = dp[s] +a
ans = dp[-1]
if dp[-1] == float('inf'):
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int,input().split())
List = [k for i in range(n)]
for _ in range(q):
  a = int(input())
  List[a-1] += 1
  List = [s -1 for s in List]

for t in range(n):
  if List[t] >=1:
    print('Yes')
  else:
    print('No')

Fixed submission:
n, k, q = map(int,input().split())
List = [k for i in range(n)]
counter = 0
for _ in range(q):
  a = int(input())
  List[a-1] += 1
  counter -= 1

List = [s+counter for s in List]

for t in range(n):
  if List[t] >=1:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
List = list(map(int,input().split()))
List.sort(reverse=True)
halves = [0]
max_halves = 0

for i in range(m):
  x = List.pop(0)
  if x >= max_halves:
    x = int(x/2)
    if len(List) == 0:
      List = [x]
    else:
      halves.append(x)
      if x >= max_halves:
        max_halves = x
  else:
    halves.remove(max_halves)
    halves.append(int(max_halves/2))
    max_halves = max(halves)
    List = [x]+ List
print(sum(List)+sum(halves))


Fixed submission:
import heapq
n, m = map(int,input().split())
List = list(map(int,input().split()))

List = list(map(lambda x: x*(-1), List))  # 各要素を-1倍

heapq.heapify(List)
for i in range(m):
  max = heapq.heappop(List)
  heapq.heappush(List, int(max/2))  # 要素の挿入
print(sum(List)*(-1))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
List = list(map(int,input().split()))

List.sort()
for i in range(m):
  new = max(List)
  List.remove(max(List))
  List.append((new/2)//1)

print(int(sum(List)))

Fixed submission:
import heapq
n, m = map(int,input().split())
List = list(map(int,input().split()))

List = list(map(lambda x: x*(-1), List))  # 各要素を-1倍

heapq.heapify(List)
for i in range(m):
  max = heapq.heappop(List)
  heapq.heappush(List, int(max/2))  # 要素の挿入
print(sum(List)*(-1))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
List = list(map(int,input().split()))

List.sort()
for i in range(m):
  List[n -1] = (List[n - 1]/2)//1
  List.sort()

print(int(sum(List)))

Fixed submission:
import heapq
n, m = map(int,input().split())
List = list(map(int,input().split()))

List = list(map(lambda x: x*(-1), List))  # 各要素を-1倍

heapq.heapify(List)
for i in range(m):
  max = heapq.heappop(List)
  heapq.heappush(List, int(max/2))  # 要素の挿入
print(sum(List)*(-1))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

counter = 0

for i in range(1,n):
  counter += i % (i+1)
  
print(counter)

Fixed submission:
n = int(input())

counter = n*(n-1)//2
  
print(int(counter))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
counter = 0
idx = -1
if set(t) <= set(s):
  for i in range(len(t)):
    idx = s.find(t[i],idx+1)
    if idx == -1:
      counter += 1
      idx = s.find(t[i],idx+1)
  print(counter * len(s) +idx +1)
elsse:
  print(-1)

Fixed submission:
s = input()
t = input()
counter = 0
idx = -1
if set(t) <= set(s):
  for i in range(len(t)):
    idx = s.find(t[i],idx+1)
    if idx == -1:
      counter += 1
      idx = s.find(t[i],idx+1)
  print(counter * len(s) +idx +1)
else:
  print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
S_list =[]
for _ in range(N):
  s = input()
  s = sorted(list(s))
  S_list.append(s)
counter = 0
for i in range(len(S_list)):
  for j in range(len(S_list)-1-i):
    if S_list[i] == S_list[i+j+1]:
      counter += 1
print(counter)

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

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S_list =[]
for _ in range(N):
  s = input()
  s = sorted(list(s))
  S_list.append(s)
counter = 0
for i in range(len(S_list)):
  for j in range(len(S_list)-1-i):
    if S_list[i] == S_list[i+j+1]:
      counter += 1
print(counter)

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

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S_list =[]
for _ in range(N):
  s = input()
  s = sorted(list(s))
  S_list.append(s)
counter = 0
for i in range(len(S_list)):
  for j in range(len(S_list)-1-i):
    if S_list[i] == S_list[i+j+1]:
      counter += 1
print(counter)

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

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Candidate = []

for i in range(N):
  S = input()
  letters = list(S)
  letters.sort()
  S = "".join(letters)
  Candidate.append(S)

counter = 0
for i in range(N):
  for k in range(N-i-1):
    if Candidate[i] == Candidate[i+k+1]:
      counter += 1
print(counter)

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

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Candidate = []

for i in range(N):
  S = input()
  letters = list(S)
  letters.sort()
  S = "".join(letters)
  Candidate.append(S)

Answer = []
for i in range(N):
  for k in range(N-i-1):
    if Candidate[i] == Candidate[i+k+1]:
      Answer.append([i,k])
print(len(Answer))

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

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
List = list(s)
n = len(List)
base = [1]*n
for _ in range(10**5):
  temp = [0]*n
  for i in range(n):
    if List[i] == 'R':
      temp[i+1] += base[i]
    else:
      temp[i-1] += base[i]
  base = temp
print(*base)

Fixed submission:
s = input()
List = list(s)+['R']
n=len(List)
R = 0
L = 0
ans = [0]*n
for i in range(n):
  if List[i]=='R':
    R += 1
    if L > 0:
      ans[i-L] += (L+1)//2
      ans[i-L-1] += L//2
      L = 0
  else:
    L += 1
    if R > 0:
      ans[i] +=R//2
      ans[i-1] += (R+1) //2
      R = 0
print(*ans[:-1])
Buggy python submission (verdict: Runtime Error):
N,D = map(int,input().split())
Answer = (N-1)//(2D+1)+1
print(Answer)

Fixed submission:
n, d = map(int, input().split())
Answer = n//(2*d+1)
if n%(2*d+1) != 0:
  Answer +=1
  
print(Answer)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A = []
for _ in range(n):
  x = int(input())
  A.append(x)
standard = max(A)
for i in range(n):
  if A[i] != standard:
    print(standard)
  else:
    temp = 0
    for t in range(n):
      if t != i:
        if A[t] >= temp:
          temp = A[t]
    print(temp)

Fixed submission:
n=int(input())
A = []
for _ in range(n):
  x = int(input())
  A.append(x)
standard = max(A)
counter = A.count(max(A))
for i in range(n):
  if A[i] != standard:
    print(standard)
  elif counter >=2:
    print(standard)
  else:
    temp = 0
    for t in range(n):
      if t != i:
        if A[t] >= temp:
          temp = A[t]
    print(temp)
Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())

Answers = []

for i in range(R-L):
  for j in range(R-L-i-1):
    Answers.append((L+i)*(L+i+j+1)%2019)

#print(len(Answer))

print(min(Answers))

Fixed submission:
L,R = map(int,input().split())
MOD = 2019
ans = 2020
if R - L > 2010:
  print(0)
  exit()
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,i*j%MOD)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D = map(int, input().split())

counter = 0

for n in range(B-A+1):
  if (A + n) %C !=0 and (A+n)% D != 0:
    counter += 1

print(counter)

Fixed submission:
A, B, C, D = map(int, input().split())

CSeries = B//C -(A-1)//C
DSeries = B //D - (A-1) //D

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

LCM = int(C*D/ gcd(C,D))

CDSeries = B//LCM - (A-1)//LCM

Answer2 = B-A +1 - CSeries - DSeries + CDSeries

print(Answer2)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = []
MOD = 1000000007
for _ in range(M):
  a = int(input())
  A.append(a)
DP = [0]*(N+1)
DP[0] = 1
DP[1] = 1
if 1 in A:
  DP[1] = 0
for i in range(1,N):
  DP[i+1] = DP[i-1]+DP[i]
  if i+1 in A:
    DP[i+1] = 0
print(DP[-1]%MOD)

Fixed submission:
N,M = map(int,input().split())
A = []
MOD = 1000000007
for _ in range(M):
  a = int(input())
  A.append(a)
DP = [1]*(N+1)
for i in A:
  DP[i] = 0
for i in range(2,N+1):
  DP[i] = (DP[i-1]+DP[i-2])%MOD*DP[i]
print(DP[-1])