Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) \
            and c.most_common()[0][1] < 4:
        return print(0)
    d = [i[0] for i in c.items() if i[1] >= 2]
    d.sort()
    e = [i[0] for i in c.items() if i[1] >= 4]
    e.sort()
    print(max(d[-1] * d[-2], e[-1]*e[-1]))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) \
            and c.most_common()[0][1] < 4:
        return print(0)
    d = [i[0] for i in c.items() if i[1] >= 2]
    if d:
        d.sort()
    e = [i[0] for i in c.items() if i[1] >= 4]
    if e:
        e.sort()
    if d and e:
        print(max(d[-1] * d[-2], e[-1]*e[-1]))
    elif d:
        print(d[-1] * d[-2])
    else:
        print(e[-1]*e[-1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    cnt = [0]*9
    for a in A:
        cnt[a//400] += 1
    ans = sum(int(a > 0) for a in cnt[:-1])
    print(ans, ans+cnt[-1])


if __name__ == '__main__':
    main()


Fixed submission:
from bisect import bisect
def grade(rate,breakpoints=[400,800,1200,1600,2000,2400,2800,3200],grades=["gray","brown","green","light blue","blue","yellow","orange","red","anything"]):
    i = bisect(breakpoints,rate)
    return grades[i]

n = int(input())
a = [int(i) for i in input().split()]
colors = [grade(r) for r in a]
anything_count = colors.count("anything")
ans = len(set(colors))
print(*(ans,ans) if anything_count == 0 else (ans-1+(1 if ans == 1 else 0),ans-1+anything_count))
Buggy python submission (verdict: Runtime Error):
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    import sys
    read = sys.stdin.read
    N, K = (int(i) for i in input().split())
    A = [int(s) for s in read().rstrip().split('\n')]
    from itertools import accumulate
    S = list(accumulate([0] + A))
    B = [s - K*i for i, s in enumerate(S)]
    c = {b: i+1 for i, b in enumerate(sorted(set(B)))}
    f = Bit(N)
    ans = 0
    for j in range(N+1):
        ans += f.sum(c[B[j]])
        f.add(c[B[j]], 1)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    import sys
    read = sys.stdin.read
    N, K = (int(i) for i in input().split())
    A = [int(s) for s in read().rstrip().split('\n')]
    from itertools import accumulate
    S = list(accumulate([0] + A))
    B = [s - K*i for i, s in enumerate(S)]
    c = {b: i+1 for i, b in enumerate(sorted(set(B)))}
    f = Bit(N+1)
    ans = 0
    for j in range(N+1):
        ans += f.sum(c[B[j]])
        f.add(c[B[j]], 1)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, W = (int(i) for i in input().split())
    WV = [[int(i) for i in input().split()] for j in range(N)]
    w0 = WV[0][0]
    Ws = [w[0] for w in WV]
    Vs = [v[1] for v in WV]
    from collections import defaultdict
    dp = defaultdict(int)
    for i in range(N):
        for j in range(w0, W+1):
            dp[i+1, j] = max(dp[i+1, j], dp[i, j])
            if 0 <= j - Ws[i]:
                dp[i+1, j] = max(dp[i+1, j], dp[i, j - Ws[i]] + Vs[i])
    print(dp[N, W])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N, W = (int(i) for i in input().split())
    WV = [[int(i) for i in input().split()] for j in range(N)]
    for i in range(1, N):
        WV[i][0] -= WV[0][0]
    w0 = WV[0][0]
    WV[0][0] = 0
    V = {i: [] for i in range(4)}
    for w, v in WV:
        V[w].append(v)
    for i in range(4):
        V[i].sort(reverse=True)
    S = [[0] for i in range(4)]
    for i in range(4):
        for b in V[i]:
            S[i].append(S[i][-1] + b)
    ans = 0
    for i, v0 in enumerate(S[0]):
        for j, v1 in enumerate(S[1]):
            for k, v2 in enumerate(S[2]):
                for m, v3 in enumerate(S[3]):
                    w_cur = w0*(i+j+k+m) + j + 2*k + 3*m
                    if W < w_cur:
                        continue
                    ans = max(ans, v0+v1+v2+v3)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    from itertools import accumulate
    S = [i for i in accumulate(range(1, N+1))]

    def is_ok(mid):
        if N <= S[mid]:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right

    ans = binary_search_meguru() + 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    from itertools import accumulate
    S = [i for i in accumulate(range(1, min(N+1, 100000)))]

    def is_ok(mid):
        if N <= S[mid]:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = len(S)
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right

    ans = binary_search_meguru() + 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    from itertools import accumulate
    S = [i for i in accumulate(range(1, N+1))]

    def is_ok(mid):
        if N <= S[mid]:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right

    ans = binary_search_meguru() + 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    from itertools import accumulate
    S = [i for i in accumulate(range(1, min(N+1, 100000)))]

    def is_ok(mid):
        if N <= S[mid]:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = len(S)
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right

    ans = binary_search_meguru() + 1
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

power = 1
for i in range(1,n+1):
    power = power * i

print(power%(7+10**9))


Fixed submission:
n = int(input())

power = 1
for i in range(1,n+1):
    power = power * i
    power = power%(7+10**9)

print(power%(7+10**9))

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

power = 1
for i in range(1,n+1):
    power = power * i

print(power%(7+10**9))


Fixed submission:
n = int(input())

power = 1
for i in range(1,n+1):
    power = power * i
    power = power%(7+10**9)

print(power%(7+10**9))
Buggy python submission (verdict: Runtime Error):
def main():
    n, m = (int(i) for i in input().split())
    a = [input() for i in range(n)]
    b = [input() for i in range(m)]
    
    equal_flag = False
    k = 0
    for i in range(n):
        for j in range(n-m+1):
            if a[i][j:j+m] == b[k]:
                plus = 1
                while k+plus != m:
                    if a[i+plus][j:j+m] != b[k+plus]:
                        break
                    plus += 1
                else:
                    equal_flag = True
        if equal_flag:
            print("Yes")
            break
    else:
        print("No")

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, m = (int(i) for i in input().split())
    a = [input() for i in range(n)]
    b = [input() for i in range(m)]
    
    equal_flag = False
    k = 0
    for i in range(n):
        for j in range(n-m+1):
            if a[i][j:j+m] == b[k]:
                plus = 1
                while k+plus != m:
                    if i+plus >= n or a[i+plus][j:j+m] != b[k+plus]:
                        break
                    plus += 1
                else:
                    equal_flag = True
        if equal_flag:
            print("Yes")
            break
    else:
        print("No")
 
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = 0
    changing = [a[0]]
    direct_flag = False #False > True <
    for i in range(1,n):
        if len(changing) == 1:
            changing.append(a[i])
            if changing[0] < changing[1]:
                direct_flag = True
        else:
            if direct_flag and changing[-1] < a[i]:
                changing.append(a[i])
            elif not direct_flag and changing[-1] > a[i]:
                changing.append(a[i])
            else:
                m = len(changing)
                iterange = (range(m) if direct_flag else range(m)[::-1])
                for j in iterange:
                    if j != 0:
                        makable = min(changing[j-1],changing[j])
                        ans += makable
                        changing[j-1] -= makable
                        changing[j] -= makable
                    if j != m-1:
                        makable = min(changing[j],changing[j+1])
                        ans += makable
                        changing[j] -= makable
                        changing[j+1] -= makable
                    if changing[j] >= 2:
                        makable = changing[j] // 2
                        ans += makable
                        changing[j] -= makable * 2
                changing = [a[i]]
                direct_flag = False
        if i == n-1:
            if len(changing) == 1:
                ans += changing[0] // 2
            else:
                iterange = (range(m) if direct_flag else range(m)[::-1])
                for j in iterange:
                    if j != 0:
                        makable = min(changing[j-1],changing[j])
                        ans += makable
                        changing[j-1] -= makable
                        changing[j] -= makable
                    if j != m-1:
                        makable = min(changing[j],changing[j+1])
                        ans += makable
                        changing[j] -= makable
                        changing[j+1] -= makable
                    if changing[j] >= 2:
                        makable = changing[j] // 2
                        ans += makable
                        changing[j] -= makable * 2
    print(ans)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = 0
    for i in range(n):
        if a[i] == 0:
            continue
        ans += a[i]//2
        if i != n-1 and a[i]&1 and a[i+1] != 0:
            ans += 1
            a[i+1] -= 1
    print(ans)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mul = 1
for i in range(n):
  mul *= a[i]
if (mul > 1000000000000000000):
  print(-1)
else:
  print(mul)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
if 0 in a:
  print(0)
  exit(0)

mul = 1
for i in range(n):
  mul *= a[i]
  if (mul > 1000000000000000000):
  	print(-1)
  	exit(0)

print(mul)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
print("Yes" if A==B else "No)

Fixed submission:
N, M = map(int, input().split())
if N == M:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = flag2 = flag3 = False
            for l in range(n):
                if not flag1 and i == int(s[l]):
                    flag1 = True
                    continue
                if flag1 and not flag2 and j == int(s[l]):
                    flag2 = True
                    continue
                if flag1 and flag2 and not flag3 and k == int(s[l]):
                    flag3 = True
            if flag3:
                cnt += 1
print(cnt)

Fixed submission:
n = int(input())
s = input()
cnt = 0
for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c != -1:
                cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = flag2 = flag3 = False
            for l in range(n):
                if not flag1 and str(i) == s[l]:
                    flag1 = True
                    continue
                if flag1 and not flag2 and not flag3 and str(j) == s[l]:
                    flag2 = True
                    continue
                if flag1 and flag2 and not flag3 and str(k) == s[l]:
                    flag3 = True
                    continue
            if flag1 and flag2 and flag3:
                cnt += 1
print(cnt)

Fixed submission:
n = int(input())
s = input()
cnt = 0
for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c != -1:
                cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
print(int(int(input()**2))

Fixed submission:
print(int(int(input())**2))
Buggy python submission (verdict: Time Limit Exceeded):
def sigma(n):
    return n * (n + 1) // 2

s = input()
l = [s[0]]
for c in s[1:]:
    if c in l[-1]:
        l[-1] += c
    else:
        l.append(c)
ans = 0
now = 0
for c in l:
    if '>' in c:
        ans -= min(now, len(c))
    ans += sigma(len(c))
    now = len(c)
print(ans)

Fixed submission:
def sigma(n):
    return n * (n + 1) // 2

s = list(map(lambda x : 1 if x == '<' else -1, input()))
l = [s[0]]
for c in s[1:]:
    if c * l[-1] > 0:
        l[-1] += c
    else:
        l.append(c)
ans = 0
now = 0
for c in l:
    if c < 0:
        ans -= min(now, abs(c))
    ans += sigma(abs(c))
    now = abs(c)
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
l = [s[0]]
for c in s[1:]:
    if c in l[-1]:
        l[-1] += c
    else:
        l.append(c)
a = []
now = 0
for c in l:
    if '<' in c:
        if now == 0:

            for i in range(len(c) + 1):
                a.append(i)
        else:
            for i in range(1, len(c) + 1):
                a.append(i)
        now = len(c)
    if '>' in c:
        if now <= len(c):
            a.pop()
            for i in reversed(range(len(c) + 1)):
                a.append(i)
        else:
            for i in reversed(range(len(c))):
                a.append(i)
        now = len(c) + 1
print(sum(a))

Fixed submission:
def sigma(n):
    return n * (n + 1) // 2

s = list(map(lambda x : 1 if x == '<' else -1, input()))
l = [s[0]]
for c in s[1:]:
    if c * l[-1] > 0:
        l[-1] += c
    else:
        l.append(c)
ans = 0
now = 0
for c in l:
    if c < 0:
        ans -= min(now, abs(c))
    ans += sigma(abs(c))
    now = abs(c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
*L, = map(int, input().split())
L.sort()
count = 0
for a in reversed(range(0, N)):
  for b in range(1, a):
    range_c = L[:b]
    key = L[a] - L[b]
    left = -1
    right = len(range_c)
    while right - left > 1:
      mid = int((left + right) / 2)
      if range_c[mid] > key:
        right = mid
      else:
        left = mid
    count += len(range_c)-right
print(count)

Fixed submission:
N = int(input())
*L, = map(int, input().split())
L.sort()
count = 0
for a in reversed(range(0, N)):
  for b in range(1, a):
    range_c = L[:b]
    key = L[a] - L[b]
    left = -1
    right = len(range_c)
    while right - left > 1:
      mid = int((left + right) / 2)
      if range_c[mid] > key:
        right = mid
      else:
        left = mid
    count += len(range_c)-right
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def is_anagram(s1, s2):
  d1 = {c1: s1.count(c1) for c1 in s1}
  d2 = {c2: s2.count(c2) for c2 in s2}
  return d1 == d2

n = int(input())
s = ['']*n
for i in range(n):
  s[i] = ''.join(sorted(list(input())))

num = 0
for i in range(n-1):
  for j in range(i+1, n):
    num += s[i] ==  s[j]
print(num)
  

Fixed submission:
n = int(input())
s = ['']*n
for i in range(n):
  s[i] = input()
dict = {}
num = 0
for i in range(n):
  k = ''.join(sorted(s[i]))
  if k not in dict.keys():
    dict[k] = 1
  else:
    num += dict[k]
    dict[k] += 1  
print(num)
Buggy python submission (verdict: Runtime Error):
S = input()
s1 = int(S[:2])
s2 = int(S[2:])

if 1 <= s1 <= 12 and 1 <= s2 <= 12:
  print('AMBIGUOUS')
elif 1 <= s1 <= 12 and (s2 == 0 or s2 >= 13):
  print('MMYY')
elif (s1 == 0 or s1 >= 13) and 1 <= s2 <= 12:
  print('YMMM')
elif (s1 == 0 or s1 >= 13) and (s2 == 0 or s2 >= 13)
  print('NA')

Fixed submission:
S = input()
s1 = int(S[:2])
s2 = int(S[2:])

def may_month(s):
  return 1<=s<=12

# どっちもMMかもしれない
if may_month(s1) and may_month(s2):
  print("AMBIGUOUS")
  
# どっちもMMじゃない
elif not (may_month(s1) or may_month(s2)):
  print("NA")

# 前半がMMかもしれない
elif may_month(s1):
  print("MMYY")
  
# 後半がMMかもしれない
elif may_month(s2):
  print("YYMM")
Buggy python submission (verdict: Runtime Error):
print(["Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve", "Christmas"][int(input())+22]) 

Fixed submission:
print(["Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve", "Christmas"][int(input())-22])
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if a + b > c + d: print('Left')
elif a + b == c + d: print('Balanced')
else print('Right')


Fixed submission:
a, b, c, d = map(int, input().split())
if a + b > c + d:
  print('Left')
elif a + b == c + d:
  print('Balanced')
else:
  print('Right')

Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if (a + b > c + d) print('Left')
elif (a + b == c + d) print('Balanced')
else print('Right')

Fixed submission:
a, b, c, d = map(int, input().split())
if a + b > c + d:
  print('Left')
elif a + b == c + d:
  print('Balanced')
else:
  print('Right')
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
print(min(n*A,B))

Fixed submission:
n,a,b=map(int,input().split())
print(min(n*a,b))
Buggy python submission (verdict: Runtime Error):
print(-int(input()+2*int(input()))


Fixed submission:
print(-int(input())+2*int(input()))
Buggy python submission (verdict: Runtime Error):
A, B = int(input())
if A > B:
    print('GREATER')
elif A < B:
    print('LESS')
else:
    print('EQUAL')

Fixed submission:
A, B = int(input()), int(input())
if A > B:
    print('GREATER')
elif A < B:
    print('LESS')
else:
    print('EQUAL')
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from decimal import Decimal
N, *A = [Decimal(_) for _ in open(0).read().split()]
N = int(N)
c = [[0, 0] for _ in range(N)]
for i, a in enumerate(A):
    a = int(a * 10**9)
    while True:
        if a % 2:
            break
        c[i][0] += 1
        a //= 2
    while True:
        if a % 5:
            break
        c[i][1] += 1
        a //= 5
c.sort()

#cum[i][j]:c[x][1]>=i (j<=x)となるようなxの個数
cum = [[0] * (N + 1) for _ in range(19)]
for i in range(19):
    for j in range(N - 1, -1, -1):
        cum[i][j] = cum[i][j + 1]
        if c[j][1] >= i:
            cum[i][j] += 1
ans = 0
for i, c2c5 in enumerate(c):
    c2, c5 = c2c5
    if c2 > 9 or (c2 == 9 and c5 >= 9):
        i2 = i + 1
    else:
        i2 = bisect.bisect_left(c, [18 - c2, -1])
    ans += cum[18 - c5][i2]
print(ans)


Fixed submission:
import bisect
from decimal import Decimal
N, *A = open(0).read().split()
N = int(N)
c = [[0, 0] for _ in range(N)]
for i, a in enumerate(A):
    if '.' in a:
        p, q = a.split('.')
        q += '0' * (9 - len(q))
    else:
        p = a
        q = '0' * 9
    a = int(p + q)
    while True:
        if a % 2:
            break
        c[i][0] += 1
        a //= 2
    while True:
        if a % 5:
            break
        c[i][1] += 1
        a //= 5
c.sort()

#cum[i][j]:c[x][1]>=i (j<=x)となるようなxの個数
cum = [[0] * (N + 1) for _ in range(19)]
for i in range(19):
    for j in range(N - 1, -1, -1):
        cum[i][j] = cum[i][j + 1]
        if c[j][1] >= i:
            cum[i][j] += 1
ans = 0
for i, c2c5 in enumerate(c):
    c2, c5 = c2c5
    if c2 > 9 or (c2 == 9 and c5 >= 9):
        i2 = i + 1
    else:
        i2 = bisect.bisect_left(c, [18 - c2, -1])
    ans += cum[18 - c5][i2]
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
N = int(input())
S = input()
cnt = 0
while True:
    while i < N and S[i] == 'R':
        i += 1
    while 0 <= j and S[j] == 'W':
        j -= 1
    if j < i:
        break
    cnt += 1
    i += 1
    j -= 1
print(cnt)


Fixed submission:
import itertools
N = int(input())
S = input()
cnt = i = 0
j = N - 1
while True:
    while i < N and S[i] == 'R':
        i += 1
    while 0 <= j and S[j] == 'W':
        j -= 1
    if j < i:
        break
    cnt += 1
    i += 1
    j -= 1
print(cnt)