Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
a=[1/A for i in A]
x=sum(a)
print(float(1/x))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
a=[1/float(num) for num in A]
x=sum(a)
print(1/float(x))
Buggy python submission (verdict: Runtime Error):
K, X = map(int, input().split())
 for i in range(X - K + 1, X + K):
     if i < X + K - 1:
        print(i, end=' ')
     else:
        print(i)


Fixed submission:
a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))

Buggy python submission (verdict: Runtime Error):
K, X = map(int, input().split())
 for i in range(X - K + 1, X + K):
  if i < X + K - 1:
    print(i, end=' ')
  else:
    print(i)


Fixed submission:
a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))

Buggy python submission (verdict: Runtime Error):
K, X = map(int, input().split())
 for i in range(X - K + 1, X + K):
 if i < X + K - 1:
 print(i, end=' ')
 else:
 print(i)

Fixed submission:
a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))

Buggy python submission (verdict: Runtime Error):
K, X = map(int, input().split())
 for i in range(X - K + 1, X + K):
    if i < X + K - 1:
 print(i, end=' ')
 else:
 print(i)
 K, X = map(int, input()

Fixed submission:
a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))

Buggy python submission (verdict: Runtime Error):
K, X = map(int, input().split())
2 for i in range(X - K + 1, X + K):
3 if i < X + K - 1:
4 print(i, end=' ')
5 else:
6 print(i)
1 K, X = map(int, input()

Fixed submission:
a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(max([a+b,a-b,a*b]))


Fixed submission:
a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
print(max([a+b,a-b,a*b]))


Fixed submission:
a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
print(max([a+b,a-b,a*b]))


Fixed submission:
a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
print(max([a+b,a-b,a*b]))

Fixed submission:
a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))
Buggy python submission (verdict: Runtime Error):
K, X = map(int, input().split())
 for i in range(X - K + 1, X + K):
      if i < X + K - 1:
         print(i, end=' ')
      else:
         print(i)


Fixed submission:
K, X = map(int, input().split())
print(' '.join(map(str, range(X - K + 1, X + K))))
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N<10:
  print(N)
elif 10=<N<100:
  print(9)
elif 100=<N<1000:
  print(N-90)
elif 1000=<N<10000:
  print(909)
elif 10000=<N<100000:
  print(N-9090)
else:
  print(90909)

Fixed submission:
N=int(input())
if N<10:
  print(N)
elif 10<=N<100:
  print(9)
elif 100<=N<1000:
  print(N-90)
elif 1000<=N<10000:
  print(909)
elif 10000<=N<100000:
  print(N-9090)
else:
  print(90909)
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))

ans=0
while sum(h)>0:
  for i in range(n):
    if i<n-1 and h[i]>0 and h[i+1]==0:
      ans+=1
    else:
      if i==N-1 and h[i]>0:
        ans+=1
    if h[i]>0:
      h[i]-=1
print(ans)      

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

ans=0
while sum(h)>0:
  for i in range(N):
    if i<N-1 and h[i]>0 and h[i+1]==0:
      ans+=1
    else:
      if i==N-1 and h[i]>0:
        ans+=1
    if h[i]>0:
      h[i]-=1
  #print(h)
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
ans=0
while sum(h)>0:
  for i in range(n):
    if i<n-1 and h[i]>0 and h[i+1]==0:
      ans+=1
    else:
      if i==N-1 and h[i]>0:
        ans+=1
    if h[i]>0:
      h[i]-=1
print(ans)      

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

ans=0
while sum(h)>0:
  for i in range(N):
    if i<N-1 and h[i]>0 and h[i+1]==0:
      ans+=1
    else:
      if i==N-1 and h[i]>0:
        ans+=1
    if h[i]>0:
      h[i]-=1
  #print(h)
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().spliy()))
ans=0
while sum(h)>0:
  for i in range(n):
    if i<n-1 and h[i]>0 and h[i+1]==0:
      ans+=1
    else:
      if i==N-1 and h[i]>0:
        ans+=1
    if h[i]>0:
      h[i]-=1
print(ans)      

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

ans=0
while sum(h)>0:
  for i in range(N):
    if i<N-1 and h[i]>0 and h[i+1]==0:
      ans+=1
    else:
      if i==N-1 and h[i]>0:
        ans+=1
    if h[i]>0:
      h[i]-=1
  #print(h)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M,X,Y=map(int, input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
print("No War" if (max(x)<min(y) and X<Y and X<min(y) and Y>max(x)) else "War")

Fixed submission:
A,B,C=sorted(map(int,input().split()))
print(10*C+B+A)

Buggy python submission (verdict: Runtime Error):
N,M,X,Y=map(int, input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
print('War' if int(X-max(x))>=int(Y-max(y)) else 'No War')

Fixed submission:
A,B,C=sorted(map(int,input().split()))
print(10*C+B+A)

Buggy python submission (verdict: Runtime Error):
N,M,X,Y=map(int, input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
print('War' if max(x)>=max(y) else 'No War')

Fixed submission:
A,B,C=sorted(map(int,input().split()))
print(10*C+B+A)
Buggy python submission (verdict: Runtime Error):
N,M,X,Y=map(int, input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.apped(X)
y.apped(Y)
print('War' if max(x)>=min(y) else 'No War')

Fixed submission:
N,M,X,Y=map(int, input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
print("No War" if (max(x)<min(y) and X<Y and X<min(y) and Y>max(x)) else "War")
Buggy python submission (verdict: Runtime Error):
a,b,c=input()
if a==c, print('Yes')
else print('No')

Fixed submission:
a,b,c=input()
print('Yes'  if a==c else  'No')

Buggy python submission (verdict: Runtime Error):
a,b,c=input()
print('Yes' if a==c,else 'No')

Fixed submission:
a,b,c=input()
print('Yes'  if a==c else  'No')

Buggy python submission (verdict: Runtime Error):
a,b,c=input()
print('yes' if a==c,else 'no')

Fixed submission:
a,b,c=input()
print('Yes'  if a==c else  'No')
Buggy python submission (verdict: Runtime Error):
a,b=input()
print('H' if a==H & b==H or a==D & b==D else 'D')


Fixed submission:
a,_,b=input()
print('H' if a==b else 'D')

Buggy python submission (verdict: Runtime Error):
a,_,b=input()
print('H' if a==H & b==H or a==D & b==D else 'D')


Fixed submission:
a,_,b=input()
print('H' if a==b else 'D')

Buggy python submission (verdict: Runtime Error):
a,b=input()
print('H' if a==H and b==H or a==D and b==D else 'D')


Fixed submission:
a,_,b=input()
print('H' if a==b else 'D')
Buggy python submission (verdict: Runtime Error):
n,l =map(int,input().split())
s=sorted([input(),for i in range(n)])
print(*s,sep='')


Fixed submission:
n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print(*s,sep="")

Buggy python submission (verdict: Runtime Error):
n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print(*n,sep="")

Fixed submission:
n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print(*s,sep="")
Buggy python submission (verdict: Time Limit Exceeded):
aa, bb = map(int, input().split())
A = max(aa, bb)
B = min(aa, bb)


def get_max(a, b):
    while True:
        c = a % b
        if c == 0:
            return b
        a = b
        b = c


B = get_max(A, B)

temp = []
for i in range(1, B + 1):
    if B % i == 0:
        temp.append(i)

flag = [0] * len(temp)
count = len(temp)
for i in range(0, len(temp)):
    for j in range(i + 1, len(temp)):
        if flag[j] == 0:
            max_ = get_max(temp[i], temp[j])
            if max_ != 1:
                flag[j] = 1
                count -= 1

print(count)


Fixed submission:
aa, bb = map(int, input().split())
A = max(aa, bb)
B = min(aa, bb)


def get_max(a, b):
    while True:
        c = a % b
        if c == 0:
            return b
        a = b
        b = c


def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct


B = get_max(A, B)
factors = factorize(B)

if len(factors) == 0:
    print(1)
else:
    count = 1
    for i in range(0, len(factors) - 1):
        if factors[i] != factors[i + 1]:
            count += 1
    print(count + 1)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()


def counthappy(s):
    happy = 0
    for i in range(0, len(s)):
        if i != 0 and s[i] == 'L':
            if s[i - 1] == 'L':
                happy += 1
        elif i != len(s) - 1 and s[i] == 'R':
            if s[i + 1] == 'R':
                happy += 1
    return happy


def replace(s, k_):
    for l in range(0, N - 1):
        for r in range(l + 1, N):
            part_l = s[0:l]
            part = s[l:r+1]
            part_r = s[r+1:N][::-1]

            part = part.replace('L', '-')
            part = part.replace('R', 'L')
            part = part.replace('-', 'R')
            s_ = part_l + part + part_r

            if k_ < K:
                replace(s_, k_ + 1)

            happy = counthappy(s_)
            global answer
            if answer < happy:
                answer = happy


answer = counthappy(S)
replace(S, 1)

print(answer)

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


def counthappy(s):
    happy = 0
    for i in range(0, len(s)):
        if i != 0 and s[i] == 'L':
            if s[i - 1] == 'L':
                happy += 1
        elif i != len(s) - 1 and s[i] == 'R':
            if s[i + 1] == 'R':
                happy += 1
    return happy


flag = 0
S = S + 'J'
s_ = []
for i in range(0, N):
    if S[i] != S[i + 1]:
        s_.append(S[flag:i + 1])
        flag = i + 1

count = 0
for i in range(1, len(s_), 2):
    count += 1
    if s_[i][0] == 'L':
        s_[i] = s_[i].replace('L', 'R')
    elif s_[i][0] == 'R':
        s_[i] = s_[i].replace('R', 'L')

    if count == K:
        break

s_join = ''.join(s_)

happy = counthappy(s_join)
print(happy)
Buggy python submission (verdict: Runtime Error):

def gcdm(g,l):
    while(l):
        g,l=l,g%l
    return g
def mota(l,r,a):
    if r<a:
        total=0
    else:
        
        if l<a:
            first=a
        elif l>=a:
            if l%a==0:
                first=l
            else:
                first=(l//a + 1)*a
        #print(a,first)
        last=r-r%a
    
        total=((last-first)//a)+1
    return total
a,b,c,d=list(map(int,input().split()))
p=[c,d]
p.sort()
c,d=p[0],p[1]
total1=mota(a,b,c)

#print(total1)
total2=mota(a,b,d)
#print(total2)
h=(c*d)//gcdm(c,d)
total3=mota(a,b,h)
#print(h)
#print(total3)
print(b-a+1-(total1+total2-total3))
    


    


Fixed submission:
s=input().rstrip()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
    print('Bad')
else:
    print('Good')
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

for i in range(N):
    D = A[i::]
    B += np.sum(D < A[i]) % (10**9 + 7)
    C += np.sum(A < A[i]) % (10**9 + 7)
    
E = B * K % (10**9 + 7)
F = C * (np.sum(np.arange(K-1)+1) % (10**9 + 7)) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))

Fixed submission:
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

mod = 10**9 + 7

for i in range(N):
    D = A[i:]
    B = (B + np.sum(D < A[i])) % mod 
    C = (C + np.sum(A < A[i])) % mod 
    
k_sum = int((K-1) * K//2) % mod 

E = (B * K) % mod 
F = (C * k_sum) % mod 

print(int((E+F) % mod ))

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)

B = np.zeros(N)
C = np.zeros(N)

for i in range(N):
    D = A[i::]
    B[i] = np.sum(D < A[i]) % (10**9 + 7)
    C[i] = np.sum(A < A[i]) % (10**9 + 7)
    
E = np.sum(B) * K % (10**9 + 7)
F = np.sum(C) * (np.sum(np.arange(K-1)+1) % (10**9 + 7)) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))

Fixed submission:
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

mod = 10**9 + 7

for i in range(N):
    D = A[i:]
    B = (B + np.sum(D < A[i])) % mod 
    C = (C + np.sum(A < A[i])) % mod 
    
k_sum = int((K-1) * K//2) % mod 

E = (B * K) % mod 
F = (C * k_sum) % mod 

print(int((E+F) % mod ))

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)

B = np.zeros(N)
C = np.zeros(N)

for i in range(N):
    D = A[i::]
    B[i] = np.sum(D < A[i]) % (10**9 + 7)
    C[i] = np.sum(A < A[i]) % (10**9 + 7)
    
E = np.sum(B) * K % (10**9 + 7)
F = np.sum(C) * np.sum(np.arange(K-1)+1) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))

Fixed submission:
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

mod = 10**9 + 7

for i in range(N):
    D = A[i:]
    B = (B + np.sum(D < A[i])) % mod 
    C = (C + np.sum(A < A[i])) % mod 
    
k_sum = int((K-1) * K//2) % mod 

E = (B * K) % mod 
F = (C * k_sum) % mod 

print(int((E+F) % mod ))

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = np.zeros(N)
C = np.zeros(N)

for i in range(N):
    D = A[i::]
    B[i] = np.sum(D < A[i])
    C[i] = np.sum(A < A[i])
    
E = np.sum(B) * K % (10**9 + 7)
F = np.sum(C) * np.sum(np.arange(K-1)+1) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))

Fixed submission:
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

mod = 10**9 + 7

for i in range(N):
    D = A[i:]
    B = (B + np.sum(D < A[i])) % mod 
    C = (C + np.sum(A < A[i])) % mod 
    
k_sum = int((K-1) * K//2) % mod 

E = (B * K) % mod 
F = (C * k_sum) % mod 

print(int((E+F) % mod ))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import copy
  
N = int(input())  
A = np.zeros(N)

for i in range(N):
    A[i] = int(input())

B = copy.deepcopy(A)

for i in range(N):
    B = np.delete(A, i)
    print(int(np.max(B)))
    B = copy.deepcopy(A)

Fixed submission:
import numpy as np
import copy
  
N = int(input())  
A = np.zeros(N)

for i in range(N):
    A[i] = int(input())

ans = int(np.max(A))
K = np.where(A == ans)[0]
k = np.where(A == ans)[0][0]

if K.size > 1:
    for i in range(N):
        print(ans)
        
else:
    for i in range(N):
        if i == k:
            B = np.delete(A, i)
            print(int(np.max(B)))
    
        else:
            print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

for i in range(N):
    A[i], B[i] = map(int, input().split())
    
B1 = B[np.argsort(B)]

ans = "Yes"
 
k = 0
for i in range(N):
    k += A[B1[i]]
    if k > B[B1[i]]:
        ans = "No"
 
print(ans)

Fixed submission:
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

for i in range(N):
    A[i], B[i] = map(int, input().split())
    
B1 = np.argsort(B)

ans = "Yes"
 
k = 0
for i in range(N):
    k += A[B1[i]]
    if k > B[B1[i]]:
        ans = "No"
 
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

for i in range(N):
    A[i], B[i] = map(int, input().split())

a = 0
for i in range(1000000):
    C = np.random.permutation(np.arange(N))
    k = 0
    a = 0
    b = 0
    for j in range(N):
        k += A[C[i]]
        if  k > B[i]:
            a = 1
            
    if a == 0:
        b = 1
        print('Yes')
        break
    
if b == 0:
    print('No')
    

Fixed submission:
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

for i in range(N):
    A[i], B[i] = map(int, input().split())
    
B1 = np.argsort(B)

ans = "Yes"
 
k = 0
for i in range(N):
    k += A[B1[i]]
    if k > B[B1[i]]:
        ans = "No"
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
##############################

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

if N == 1:
    A[0] //= (2**M)
    print(A[0])
    exit()

A.sort(reverse=True)
count = 0

A[0] //= 2
M -= 1
while M > 0:
    max_i = 0
    max_p = A[0]

    for i in range(1, N):
        if max_p < A[i]:
            max_p = A[i]
            max_i = i

        if A[i-1] < A[i]:
            break

    A[max_i] //= 2
    M -= 1

print(sum(A))


Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

import heapq

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

if N == 1:
    A[0] //= (2**M)
    print(A[0])
    exit()

hq = []
for a in A:
    heapq.heappush(hq, -a)

while M > 0:
    high = -1 * heapq.heappop(hq)
    high //= 2
    M -= 1
    heapq.heappush(hq, -high)

ans = 0
for i in range(N):
    ans += heapq.heappop(hq)

print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
##############################

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

count = 0
while M > 0:
    A.sort(reverse=True)
    A[0] = A[0]//2
    M -= 1

print(sum(A))


Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

import heapq

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

if N == 1:
    A[0] //= (2**M)
    print(A[0])
    exit()

hq = []
for a in A:
    heapq.heappush(hq, -a)

while M > 0:
    high = -1 * heapq.heappop(hq)
    high //= 2
    M -= 1
    heapq.heappush(hq, -high)

ans = 0
for i in range(N):
    ans += heapq.heappop(hq)

print(-ans)
Buggy python submission (verdict: Runtime Error):
x

Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

S = list(input().rstrip())
T = list(input().rstrip())

count = 0
for i in range(3):
    if S[i] == T[i]:
        count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N = int(input())

count = 0
for i in range(N):
    if i == (N-1):
        count += (i+1) % (1)
    else:
        count += (i+1) % (i+2)

print(count)


Fixed submission:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N = int(input())

# まず等差数列の和
n = N-2
count = (n*(4+(n-1)))//2

#print(count)

# 最終項
count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N = int(input())

count = 0
for i in range(N):
    if i == (N-1):
        count += (i+1) % (1)
    else:
        count += (i+1) % (i+2)

print(count)



Fixed submission:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N = int(input())

# まず等差数列の和
n = N-2
count = (n*(4+(n-1)))//2

#print(count)

# 最終項
count += 1

print(count)

Buggy python submission (verdict: Runtime Error):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


count = 0
for i in range(N):
    if i == (N-1):
        count += (i+1) % (1)
    else:
        count += (i+1) % (i+2)

print(count)


Fixed submission:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N = int(input())

# まず等差数列の和
n = N-2
count = (n*(4+(n-1)))//2

#print(count)

# 最終項
count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import deque

N = int(input())
p = deque()
for i in range(N):
    p.append(i+1)

x = p.popleft()
p.append(x)

#p = [2,3,4,5,6,7,8,9,10,11,12,13,1]

#print(p)
count = 0
for i in range(N):
    count += (i+1) % p[i]

print(count)

Fixed submission:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N = int(input())

# まず等差数列の和
n = N-2
count = (n*(4+(n-1)))//2

#print(count)

# 最終項
count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(input())
p = []
for i in range(N):
    p.append(i+1)

x = p.pop(0)
p.append(x)
#p.reverse()

#p = [2,3,4,5,6,7,8,9,10,11,12,13,1]

#print(p)
count = 0
for i in range(N):
    count += (i+1) % p[i]

print(count)

Fixed submission:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N = int(input())

# まず等差数列の和
n = N-2
count = (n*(4+(n-1)))//2

#print(count)

# 最終項
count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
str = []
for i in range(n):
    str.append(''.join(sorted(input())))

count = 0
for i in range(len(str)):
    for j in range(i+1, len(str)):
        if str[i] == str[j]:
            count += 1

print(count)

Fixed submission:

import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
str = []
for i in range(n):
    str.append(''.join(sorted(input())))

c = collections.Counter(str)

count = 0
for k, v in c.items():
    if v > 1:
        count += combinations_count(v, 2)

print(count)

Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
str = []
for i in range(n):
    str.append(''.join(sorted(input())))

count = 0
for i in range(len(str)):
    for j in range(i+1, len(str)):
        if str[i] == str[j]:
            count += 1

print(count)

Fixed submission:

import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
str = []
for i in range(n):
    str.append(''.join(sorted(input())))

c = collections.Counter(str)

count = 0
for k, v in c.items():
    if v > 1:
        count += combinations_count(v, 2)

print(count)
Buggy python submission (verdict: Runtime Error):

N = int(input())
A = [int(input()) for _ in range(N)]

L = [0] * (max(A)+1)
R = [0] * (max(A)+1)

L[0] = 0
for i in range(1, N+1):
    L[i] = max(A[i-1], L[i-1])

R[N] = 0
for i in range(N-1, 0, -1):
    R[i] = max(R[i+1], A[i])

#print(L)
#print(R)

for i in range(N):
    ans = max(L[i], R[i+1])
    print(ans)


Fixed submission:

n = int(input())
A = [int(input()) for _ in range(n)]

first = max(A)
second = sorted(A)[-2]
for i in range(n):
    if first == A[i]:
        print(second)
    else:
        print(first)
Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

L, R = map(int, input().split())

ans = float('inf')
for i in range(L, R):
    for j in range(L+1, R+1):
        ans = min(ans, i*j % 2019)

print(ans)

Fixed submission:

l, r = map(int, input().split())

least = 2*(10**9)+1
for i in range(l, r):
    for j in range(i+1, r+1):
        if (i * j % 2019) == 0:
            print(0)
            exit()
        least = min(least, (i * j % 2019))

print(least)