Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#ABC105 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n,m = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
    b = list(accumulate(a[i:]))
    b = list(map(lambda x:x%m,b))
    b.sort()
    ans += bisect.bisect_right(b,0) 
print(ans)


Fixed submission:
#!/usr/bin/env python3
#ABC105 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = list(accumulate(a))
b = list(map(lambda x:x % m,a))
b = list(Counter(b).items())

ans = 0
for i,j in b:
    if j >= 2:
        #nC2
        ans += j*(j-1)//2
    if i == 0:
        ans += j
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

d,g = LI()
pc = [LI() for _ in range(d)]
ans = inf
for i in permutations(range(d)):
    cnt = 0
    tmp = 0
    for j in list(i):
        p,c = pc[j]
        flg = (g-tmp) % (100*(j+1))
        t = min(p,(g - tmp)//(100*(j+1)))
        tmp += 100*(j+1)*t
        if t == p:
            tmp += c
            cnt += t
            if tmp >= g:
                break
        else:
            cnt += t + (flg != 0)
            break
    ans = min(ans,cnt)
print(ans)


Fixed submission:
#!/usr/bin/env python3
import numpy as np
import math
import re

a,b=map(int,input().split())
c=[0]+[list(map(int,input().split()))for i in range(a)]

def f(t,s):
    if t==0:
        return 10**9
    l=min(s//(t*100),c[t][0])
    k=100*t*l
    if l==c[t][0]:
        k+=c[t][1]
    if k<s:
        l+=f(t-1,s-k)
    return min(l,f(t-1,s))
print(f(a,b))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

d,g = LI()
pc = [LI() for _ in range(d)]
ans = inf
for i in permutations(range(d)):
    cnt = 0
    tmp = 0
    for j in list(i):
        flg = (g-tmp) % (100*(j+1))
        t = min(pc[j][0],(g - tmp)//(100*(j+1)))
        tmp += 100*(j+1)*t
        if t == pc[j][0]:
            tmp += pc[j][1]
            cnt += t
            if tmp >= g:
                break
        else:
            cnt += t + (flg != 0)
            break
    ans = min(ans,cnt)
print(ans)


Fixed submission:
#!/usr/bin/env python3
import numpy as np
import math
import re

a,b=map(int,input().split())
c=[0]+[list(map(int,input().split()))for i in range(a)]

def f(t,s):
    if t==0:
        return 10**9
    l=min(s//(t*100),c[t][0])
    k=100*t*l
    if l==c[t][0]:
        k+=c[t][1]
    if k<s:
        l+=f(t-1,s-k)
    return min(l,f(t-1,s))
print(f(a,b))
Buggy python submission (verdict: Runtime Error):
n = int(input())

if(n%2 == 0):
  print(n)
else:
  t=1
  while 1:
    t+=1
    n=n＊t
    if(n%2==0):
      print(n)
      break
      

Fixed submission:
#!/usr/bin/env python3

n = int(input())

if(n % 2 == 0):
    print(n)
else:
    t = 1
    while True:
        t += 1
        n = n*t
        if(n % 2 == 0):
            print(n)
            break;
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
#ABC100 D

from itertools import *

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

cakes = [list(map(int,input().split())) for _ in range(N)]

pm = (1,-1)

ans = -1
for a in product(*[pm] *3):
    cakes.sort(key = lambda y:sum(list(map(lambda x: x[0]*x[1],zip(a,y)))))
    x,y,z = zip(*cakes[:M])
    ans = max(ans,abs(sum(x))+abs(sum(y))+abs(sum(z)))
print(ans)


Fixed submission:
#!/usr/bin/env python3
#ABC100 D

from itertools import *

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

cakes = [list(map(int,input().split())) for _ in range(N)]

pm = (1,-1)
if M == 0:
    print(0)
else:
    ans = -1
    for a in product(*[pm] *3):
        cakes.sort(key = lambda y:sum(list(map(lambda x: x[0]*x[1],zip(a,y)))))
        x,y,z = zip(*cakes[:M])
        ans = max(ans,abs(sum(x))+abs(sum(y))+abs(sum(z)))
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#ABC98 C

n = int(input())
s = list(input())

x = [1 if s[i] == 'W' else 0 for i in range(n)]
y = [1 if s[i] == 'E' else 0 for i in range(n)]

mi = float('inf')
for i in range(n):
    a = sum(x[:i])
    b = sum(y[i+1:])
    mi = min(mi,a+b)
print(mi)


Fixed submission:
#!/usr/bin/env python3
#ABC98 C

#累積和を用いる
from itertools import accumulate

n = int(input())
s = list(input())

x = [0]+[1 if s[i] == 'W' else 0 for i in range(n)]
y = [1 if s[i] == 'E' else 0 for i in range(n)] + [0]

mx = list(accumulate(x))
my = list(accumulate(y[::-1]))
my = my[::-1]
mi = float('inf')
for i in range(n+1):
    a = mx[i]
    b = my[i]
    mi = min(mi,a+b)
print(mi)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#ABC94 C

from copy import deepcopy
n = int(input())
x = list(map(int,input().split()))

for i in range(n):
    y = deepcopy(x)
    y.remove(y[i])
    y.sort()
    print(y[n//2-1])


Fixed submission:
#!/usr/bin/env python3
#ABC94 C

from copy import deepcopy
from operator import itemgetter
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
c1 = y[n//2-1]
c2 = y[n//2]
for i in x:
    if i < c2:
        print(c2)
    elif i >= c2:
        print(c1)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#APC1 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b = LI()
if a % b == 0:
  print(-1)
tmp = 1
while 1:
  if tmp % a == 0 and tmp % b != 0:
    print(tmp)
    quit()
  tmp += 1
  


Fixed submission:
#!/usr/bin/env python3
#APC1 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b = LI()
if a % b == 0:
  print(-1)
else:
  print(a)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
#APC1 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b = LI()
if a % b == 0:
  print(-1)
tmp = 1
while 1:
  if tmp % a == 0 and tmp % != 0:
    print(tmp)
    quit()
  tmp += 1
  


Fixed submission:
#!/usr/bin/env python3
#APC1 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b = LI()
if a % b == 0:
  print(-1)
else:
  print(a)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#ABC84 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7


def get_prime(n):
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,n+1):
        for j in range(i*2,n+1,i):
            is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]

prime = get_prime(10**5)
ansprime = [float('inf')]*(10**5)
for i in range(1,10**5+1,2):
    if i not in prime:
        continue
    if (i+1)//2 not in prime:
        continue
    ansprime[i] = i
ansprime.sort()
q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    li = bisect.bisect_left(ansprime,l)
    ri = bisect.bisect_right(ansprime,r)
    print(ri-li)


Fixed submission:
#!/usr/bin/env python3
#ABC84 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7


def get_prime(n):
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,n+1):
        for j in range(i*2,n+1,i):
            is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]

prime = get_prime(10**5)
ansprime = [float('inf')]*(10**5)
for i in range(1,10**5+1,2):
    if i not in prime:
        continue
    if (i+1)//2 not in prime:
        continue
    ansprime[i] = i
ansprime.sort()
q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    li = bisect.bisect_left(ansprime,l)
    ri = bisect.bisect_right(ansprime,r)
    print(ri-li)
Buggy python submission (verdict: Time Limit Exceeded):
import re

a = input()
a = re.split(" ",a)

b = input()
b = re.split(" ",b)
b = list(map(int,b))
c = set(b)
c = list(map(int,c))
if((len(b) <= int(a[1])) or (len(c) <= len(a[1]))):
    print(0)
else:
    save = []
    for i in range(len(c)):
        x = b.count(c[i])
        save.append(int(x))
    save.sort()
    y = len(c)-int(a[1])
    ans = 0
    for i in range(int(y)):
        ans += int(save[i])
    print(ans)

Fixed submission:
import re
import collections

a = input()
a = re.split(" ",a)
b = input()
b = re.split(" ",b)

c = collections.Counter(b)

c = sorted(c.items(), key=lambda x: x[1])
ans = 0
for i in range(len(c)-int(a[1])):
    ans += c[i][1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import re

a = input()
a = re.split(" ",a)

b = input()
b = re.split(" ",b)
b = list(map(int,b))
c = set(b)
d = list(map(int,c))
if(len(b) <= int(a[1])):
    print(0)
else:
    save = []
    for i in range(len(d)):
        x = b.count(d[i])
        save.append(int(x))
    save.sort()
    y = len(d)-int(a[1])
    ans = 0
    for i in range(int(y)):
        ans += int(save[i])
    print(ans)


Fixed submission:
import re
import collections

a = input()
a = re.split(" ",a)
b = input()
b = re.split(" ",b)

c = collections.Counter(b)

c = sorted(c.items(), key=lambda x: x[1])
ans = 0
for i in range(len(c)-int(a[1])):
    ans += c[i][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
#CODE FESTIVAL 2017 Final A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
lst = ['A','K','I','H','B','R']
for i in range(len(s)):
    if s[i] not in lst:
        print('NO')
        quit()
a = s.count('A')
t = ''
for i in range(len(s)):
    if s[i] != 'A':
        t += s[i]
if 'KIHBR' not in t or a > 4 or 'KIH' not in s:
    print('NO')
    quit()
if t.count('K') != 1 or t.count('I') != 1 or t.count('H') != 1 or t.count('B') != 1 or t.count('R') != 1:
    print('NO')
    quit()
a = 0
for i in range(len(s)):
    if s[i] == 'K':
        if s[:i].count('A') > 1:
            print('NO')
            quit()
    if s[i] == 'H':
        for j in range(i+1.len(s)):
            if s[j] == 'B':
                if s[i:j].count('A') > 1:
                    print('NO')
                    quit()
    if s[i] == 'B':
        for j in range(i+1,len(s)):
            if s[j] == 'R':
                if s[i:j].count('A') > 1:
                    print('NO')
                    quit()
    if s[i] == 'R':
        if s[i:].count('A') > 1:
            print('NO')
            quit()
print('YES')


Fixed submission:
#!/usr/bin/env python3
#CODE FESTIVAL 2017 Final A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
lst = ['A','K','I','H','B','R']
for i in range(len(s)):
    if s[i] not in lst:
        print('NO')
        quit()
a = s.count('A')
t = ''
for i in range(len(s)):
    if s[i] != 'A':
        t += s[i]
if 'KIHBR' not in t or a > 4 or 'KIH' not in s:
    print('NO')
    quit()
if t.count('K') != 1 or t.count('I') != 1 or t.count('H') != 1 or t.count('B') != 1 or t.count('R') != 1:
    print('NO')
    quit()
for i in range(len(s)):
    if s[i] == 'K':
        if s[:i].count('A') > 1:
            print('NO')
            quit()
    if s[i] == 'H':
        for j in range(i+1,len(s)):
            if s[j] == 'B':
                if s[i:j].count('A') > 1:
                    print('NO')
                    quit()
    if s[i] == 'B':
        for j in range(i+1,len(s)):
            if s[j] == 'R':
                if s[i:j].count('A') > 1:
                    print('NO')
                    quit()
    if s[i] == 'R':
        if s[i:].count('A') > 1:
            print('NO')
            quit()
print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#ABC77 C

import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in a:
    s = 0
    x = bisect.bisect_right(b,i)
    for j in b[x:]:
        y = bisect.bisect_right(c,j)
        ans += n-y
print(ans)


Fixed submission:
#!/usr/bin/env python3
#ABC77 C

import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in b:
    x = bisect.bisect_left(a,i)
    y = bisect.bisect_right(c,i)
    ans += x*(n-y)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#ABC65 B
n = int(input())

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

bo = [1]
b = 1
c = 0
while 1:
    c += 1
    b = a[b-1]
    if b in bo:
        print(-1)
        quit()
    else:
        bo.append(b)
    if b == 2:
        break
print(c)


Fixed submission:
#!/usr/bin/env python3
#ABC65 B
n = int(input())

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

b = 1
c = 0
for i in range(n):
    c += 1
    b = a[b-1]
    if b == 2:
        print(c)
        quit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3


N = int(input())
power = 1
for i in range(1,N+1):
    power *= i
print(power % (10**9+7))


Fixed submission:
#!/usr/bin/env python3


N = int(input())
power = 1
for i in range(1,N+1):
    power *= i
    power %= 10**9+7
print(power)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
#ABC54 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,ma,mb = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
sa = 0
sb = 0
for a,b,c in x:
    sa += a
    sb += b
dp = [[float('inf')]*(sb+1) for _ in range(sa+1)]
dp[0][0] = 0
for a,b,c in x:
    y = [[0]*(sb+1) for _ in range(sb+1)]
    for i in range(sa+1):
        for j in range(sb+1):
            if i+a < sa+1 and j+b < sb+1:
                if y[i][j] == 0:
                    dp[i+a][j+b] = min(dp[i+a][j+b],dp[i][j]+c)
                    y[i+a][j+b] = 1
ans = float('inf')
for i in range(1,sa+1):
    for j in range(1,sb+1):
        if i*mb == j*ma:
            ans = min(ans,dp[i][j])
if ans == float('inf'):
    print(-1)
else:
    print(ans)


Fixed submission:
#!/usr/bin/env python3
#ABC54 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,ma,mb = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
sa = 0
sb = 0
for a,b,c in x:
    sa += a
    sb += b
dp = [[float('inf')]*(sb+1) for _ in range(sa+1)]
dp[0][0] = 0
for a,b,c in x:
    y = [[True]*(sb+1) for _ in range(sa+1)]
    for i in range(sa+1-a):
        for j in range(sb+1-b):
            if y[i][j]:
                if dp[i+a][j+b] > dp[i][j] + c:
                    dp[i+a][j+b] = dp[i][j] + c
                    y[i+a][j+b] = False
ans = float('inf')
for i in range(1,sa+1):
    for j in range(1,sb+1):
        if i*mb == j*ma:
            ans = min(ans,dp[i][j])
if ans == float('inf'):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
ans = 0
for i in range(len(S)):
    if S[i] == 'A':
        for j in range(i+1,len(S)):
            if S[j] == 'Z':
                ans = max(ans,j-i+1)
print(ans)


Fixed submission:
S = input()
ans = 0
for i in range(len(S)):
    if S[i] == 'A':
        a = i
        break
for i in range(len(S))[::-1]:
    if S[i] == 'Z':
        z = i
        break
print(z-a+1)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

n = int(input())
t = list(map(int,input().split()))
m = int(input())
px = [list(map(int,input().split())) for _ in range(m)]

for p,x in px:
    T = t.copy()
    T[p-1] = x
    print(sum(T))


Fixed submission:
#!/usr/bin/env python3

N = int(input())
T = list(map(int,input().split()))
t = sum(T)
M = int(input())
P = []
X = []
for i in range(M):
    p,x = map(int,input().split())
    P.append(p)
    X.append(x)

for i in range(M):
    s = t - T[P[i]-1] + X[i]
    print(s)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
#ABC50 C

from collections import Counter
from operator import itemgetter

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

c = Counter(a)
c = list(c.items())
cc = sorted(c,key = itemgetter(1))
ccc = sorted(c,key = itemgetter(0))
if n % 2 == 1:
    if cc[1][1] != 2:
        print(0)
        quit()
    if cc[0][0] != 0:
        print(0)
        quit()
if n % 2 == 0:
    k = 0
    for i,j in ccc:
        if j == 2 and i % 2 == 1 and i == 2*k+1:
            k += 1
            continue
        else:
            print(0)
            quit()
print(2**(n//2))


Fixed submission:
#!/usr/bin/env python3
#ABC50 C

from collections import Counter
from operator import itemgetter

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

c = Counter(a)
c = list(c.items())
ccc = sorted(c,key = itemgetter(0))
if n % 2 == 1:
    k = 0
    for i,j in ccc:
        if j == 2 and i == 2*k:
            k += 1
            continue
        if j == 1 and i == 0:
            k += 1
            continue
        else:
            print(0)
            quit()
if n % 2 == 0:
    k = 0
    for i,j in ccc:
        if j == 2 and i == 2*k+1:
            k += 1
            continue
        else:
            print(0)
            quit()
print(2**(n//2) % mod)