Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
import os
import itertools
import math
f = open("C:/Users/kazuki/Documents/python/import.txt","r")
sys.stdin = f
# -*- coding: utf-8 -*-
Q = int(input())
AB = [sorted(list(map(int,input().split()))) for i in range(Q)]

for A,B in AB:
    x = math.sqrt(A*B)
    y = int(x)
    if x!=y:
        if y*(y+1)<A*B:
            print(y*2-1)
        else:
            print(y*2-2)
    else:
        if A==B:
            print(y*2-2)
        else:
            print(y*2-3)


Fixed submission:
import math
Q = int(input())
AB = [sorted(list(map(int,input().split()))) for i in range(Q)]

for A,B in AB:
    x = math.sqrt(A*B)
    y = int(x)
    if x!=y:
        if y*(y+1)<A*B:
            print(y*2-1)
        else:
            print(y*2-2)
    else:
        if A==B:
            print(y*2-2)
        else:
            print(y*2-3)

Buggy python submission (verdict: Runtime Error):
Q = int(input())
AB = [sorted(list(map(int,input().split()))) for i in range(Q)]

for A,B in AB:
    x = math.sqrt(A*B)
    y = int(x)
    if x!=y:
        if y*(y+1)<A*B:
            print(y*2-1)
        else:
            print(y*2-2)
    else:
        if A==B:
            print(y*2-2)
        else:
            print(y*2-3)

Fixed submission:
import math
Q = int(input())
AB = [sorted(list(map(int,input().split()))) for i in range(Q)]

for A,B in AB:
    x = math.sqrt(A*B)
    y = int(x)
    if x!=y:
        if y*(y+1)<A*B:
            print(y*2-1)
        else:
            print(y*2-2)
    else:
        if A==B:
            print(y*2-2)
        else:
            print(y*2-3)

Buggy python submission (verdict: Runtime Error):
Q = int(input())
AB = [sorted(list(map(int,input().split()))) for i in range(Q)]

for A,B in AB:
    x = math.sqrt(A*B)
    y = int(x)
    if x!=y:
        if y*(y+1)<A*B:
            print(y*2-1)
        else:
            print(y*2-2)
    else:
        if A==B:
            print(y*2-2)
        else:
            print(y*2-3)

Fixed submission:
import math
Q = int(input())
AB = [sorted(list(map(int,input().split()))) for i in range(Q)]

for A,B in AB:
    x = math.sqrt(A*B)
    y = int(x)
    if x!=y:
        if y*(y+1)<A*B:
            print(y*2-1)
        else:
            print(y*2-2)
    else:
        if A==B:
            print(y*2-2)
        else:
            print(y*2-3)
Buggy python submission (verdict: Runtime Error):
a = set(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"])
s = input()
for i in range(len(s)):
    a.remove(s[i])
b = list(a).sort()
if b:
    print(s[i]+b[0])
else:
    for i in range(2,27):
        if s[-i] < s[-i+1]:
            break
        if i == 26:
            print(-1)
            exit()
    for j in sorted(s[-i+1:]):
        if j > s[-i]:break
    print(s[:-i]+j)


Fixed submission:
a = set(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"])
s = input()
if len(s)<26:
    b = list(a-set(s))
    b.sort()
    print(s+b[0])
else:
    for i in range(2,27):
        if s[-i] < s[-i+1]:
            break
        if i == 26:
            print(-1)
            exit()
    for j in sorted(s[-i+1:]):
        if j > s[-i]:break
    print(s[:-i]+j)

Buggy python submission (verdict: Runtime Error):
a = set(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"])
s = input()
for i in range(len(s)):
    a.remove(s[i])
b = list(a).sort()
if b:
    print(s[i]+s[0])
else:
    for i in range(2,27):
        if s[-i] < s[-i+1]:
            break
        if i == 26:
            print(-1)
            exit()
    for j in sorted(s[-i+1:]):
        if j > s[-i]:break
    print(s[:-i]+j)

Fixed submission:
a = set(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"])
s = input()
if len(s)<26:
    b = list(a-set(s))
    b.sort()
    print(s+b[0])
else:
    for i in range(2,27):
        if s[-i] < s[-i+1]:
            break
        if i == 26:
            print(-1)
            exit()
    for j in sorted(s[-i+1:]):
        if j > s[-i]:break
    print(s[:-i]+j)
Buggy python submission (verdict: Time Limit Exceeded):
H,W,D = map(int,input().split())
A = [0]*(H*W+1)
for i in range(H):
    a = list(map(int,input().split()))
    for j in range(W):
        A[a[j]] = (i,j)
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    ans = 0
    while R > L:
        ans += abs(A[L][0]-A[L+D][0]) + abs(A[L][1]-A[L+D][1])
        L += D
    print(ans)


Fixed submission:
H,W,D = map(int,input().split())
A = [0]*(H*W+1)
for i in range(H):
    a = list(map(int,input().split()))
    for j in range(W):
        A[a[j]] = (i,j)
d = [0]*(H*W+1)
for i in range(D+1,H*W+1):
    d[i] = d[i-D]+abs(A[i][0]-A[i-D][0])+abs(A[i][1]-A[i-D][1])
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    print(d[R]-d[L])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
ans = 0
for i,j in c.items():
    if j>=i:
        ans += j-i
    else:
        ans += j
print(ans)


Fixed submission:
from collections import Counter
inf = 10**10


N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
ans = 0
for i,j in c.items():
    if j>=i:
        ans += j-i
    else:
        ans += j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
d =  {}
a = list(map(int,input().split()))
for i in range(N):
    if a[i] not in d.keys():
        d[a[i]] = 1
    else:
        d[a[i]] +=1
ans = 0
for k,v in d.items():
    if v < k:
        ans += v
    else:
        ans += abs(v-k)
print(ans)


Fixed submission:
from collections import Counter
inf = 10**10


N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
ans = 0
for i,j in c.items():
    if j>=i:
        ans += j-i
    else:
        ans += j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
d =  {}
a = list(map(int,input().split()))
for i in range(N):
    if a[i] not in d.keys():
        d[a[i]] = 1
    else:
        d[a[i]] +=1
ans = 0
for k,v in d.items():
    if v < k:
        ans += v
    else:
        ans += abs(v-k)
print(ans)


Fixed submission:
from collections import Counter
inf = 10**10


N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
ans = 0
for i,j in c.items():
    if j>=i:
        ans += j-i
    else:
        ans += j
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input().split("T")
x,y = map(int,input().split())
xmove = []
ymove = []
for i in range(1,len(s)):
    if i % 2 == 0:
        xmove.append(s[i].count("F"))
    else:
        ymove.append(s[i].count("F"))
dpx = [[False]*(16001) for i in range(len(xmove)+1)]
dpy = [[False]*(16001) for i in range(len(ymove)+1)]
dpx[0][s[0].count("F")+8000] = True
dpy[0][8000] = True
for i in range(len(xmove)):
    for j in range(16001):
        if dpx[i][j]:
            if 0<=j-xmove[i]:
                dpx[i+1][j-xmove[i]] = True
            if j+xmove[i] <= 16001:
                dpx[i+1][j+xmove[i]] = True
for i in range(len(ymove)):
    for j in range(16001):
        if dpy[i][j]:
            if 0<=j-ymove[i]:
                dpy[i+1][j-ymove[i]] = True
            if j+ymove[i] <= 16001:
                dpy[i+1][j+ymove[i]] = True

if dpx[len(xmove)][x+8000] and dpy[len(ymove)][y+8000]:
    print("Yes")
else:
    print("No")

Fixed submission:
s = input().split("T")
x,y = map(int,input().split())
xmove = []
ymove = []
for i in range(len(s)):
    if i % 2 == 1:
        ymove.append(s[i].count("F"))
    else:
        xmove.append(s[i].count("F"))
#リストで持つdpだとTLEしたのでメモ化再帰で書く

def solve(l,cor):
    dp = {0}
    for c in l:
        dp = {c+i for i in dp}|{i-c for i in dp}
    return cor in dp

if solve(xmove[1:],x-xmove[0]) and solve(ymove,y):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
F =[list(map(int,input().split())) for i in range(n)]
P =[list(map(int,input().split())) for i in range(n)]

ans = -INF
for i in range(1,1024):
    profit = 0
    for j in range(n):
        cnt = 0
        for x in range(10):
            if (i >> x) %2 == 1 and F[j][x] == 1:
                cnt += 1
        profit += P[j][cnt]
    ans = max(ans,profit)
print(ans) 

Fixed submission:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

n = int(input())
F =[list(map(int,input().split())) for i in range(n)]
P =[list(map(int,input().split())) for i in range(n)]

ans = -INF
for i in range(1,1024):
    profit = 0
    for j in range(n):
        cnt = 0
        for x in range(10):
            if (i >> x) %2 == 1 and F[j][x] == 1:
                cnt += 1
        profit += P[j][cnt]
    ans = max(ans,profit)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
c = Counter(s)
cnt = 0
a = list()
for v in c.values():
    a.append(v)
if max(a)-min(a)>=2:
    print("NO")
else:
    print("Yes")

Fixed submission:
s = input()
abc = [0]*(3)
for i in range(len(s)):
    if s[i] == "a":
        abc[0] += 1
    elif s[i] =="b":
        abc[1] += 1
    else:
        abc[2] += 1
if max(abc)-min(abc) >= 2:
    print("NO")
else:
    print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

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 range(N):
    r1 = bisect.bisect_right(B,A[i])
    for j in range(r1,N):
        r2 = bisect.bisect_right(C,B[j])
        ans += N - r2
print(ans)


Fixed submission:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

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 range(N):
    l = bisect.bisect_left(A,B[i])
    r = bisect.bisect_right(C,B[i])
    ans += l*(N-r)

print(ans)

Buggy python submission (verdict: Runtime Error):
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 range(N):
    r1 = bisect.bisect_right(B,A[i])
    for j in range(r1,N):
        r2 = bisect.bisect_right(C,B[j])
        ans += N - r2
print(ans)


Fixed submission:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

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 range(N):
    l = bisect.bisect_left(A,B[i])
    r = bisect.bisect_right(C,B[i])
    ans += l*(N-r)

print(ans)
Buggy python submission (verdict: Runtime Error):
#s,t間に奇数長のパスが存在したならば必ずs,t間には辺が張られる
#グラフが二部グラフでないならば奇数長のサイクルが存在して任意の(s,t)間に奇数長パスが作れる
#グラフが二部グラフであるならば異なるカラーグループ間の頂点には必ず辺が張られる
n,m = map(int,input().split())
G = defaultdict(set)
color = [0 for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    G[a-1].add(b-1)
    G[b-1].add(a-1)
#二部グラフ判定
color[0]=1
que = deque([0])
bipartite = True
while len(que):
    p = que.popleft()
    for q in list(G[p]):
        if color[q] == 0:
            color[q] = -color[p]
            que.append(q)
        elif color[q] == color[p]:
            bipartite = False
            break
if bipartite:
    print(color.count(1)*color.count(-1)-m)
else:
    print(n*(n-1)//2-m)

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

#s,t間に奇数長のパスが存在したならば必ずs,t間には辺が張られる
#グラフが二部グラフでないならば奇数長のサイクルが存在して任意の(s,t)間に奇数長パスが作れる
#グラフが二部グラフであるならば異なるカラーグループ間の頂点には必ず辺が張られる
n,m = map(int,input().split())
G = defaultdict(set)
color = [0 for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    G[a-1].add(b-1)
    G[b-1].add(a-1)
#二部グラフ判定
color[0]=1
que = deque([0])
bipartite = True
while len(que):
    p = que.popleft()
    for q in list(G[p]):
        if color[q] == 0:
            color[q] = -color[p]
            que.append(q)
        elif color[q] == color[p]:
            bipartite = False
            break
if bipartite:
    print(color.count(1)*color.count(-1)-m)
else:
    print(n*(n-1)//2-m)
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(N):
    if p[i] == i+1:
        p[i+1]=p[i]
        ans += 1
    else:
        continue
print(ans)

Fixed submission:
N = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(N):
    if p[i] == i+1 and i<N-1:
        p[i+1]=p[i]
        ans += 1
    elif p[i] == N and i == N-1:
        ans +=1
    else:
        continue
print(ans)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
 if a < b:
    a, b = b, a
 if b == 0:
    return a
 c = a % b
 return gcd(b, c)
def lcm(a,b):
  return int(a*b/gcd(a,b))

N = int(input())
T = [int(input()) for i in range(N)]
ans = T[0]
for i in T[1:]:
    ans = lcm(ans,i)

print(ans)

Fixed submission:
N = int(input())
T = [int(input()) for i in range(N)]

from functools import reduce
from fractions import gcd

def lcm(a,b):
  return a*b //gcd(a,b)

print(reduce(lcm,T))

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
 if a < b:
    a, b = b, a
 if b == 0:
    return a
 c = a % b
 return gcd(b, c)
def lcm(a,b):
  return float(a*b/gcd(a,b))

N = int(input())
ans = 1
for i in range(N):
    t = float(input())
    ans = lcm(t,ans)

print(ans)

Fixed submission:
N = int(input())
T = [int(input()) for i in range(N)]

from functools import reduce
from fractions import gcd

def lcm(a,b):
  return a*b //gcd(a,b)

print(reduce(lcm,T))

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
 if a < b:
    a, b = b, a
 if b == 0:
    return a
 c = a % b
 return gcd(b, c)
def lcm(a,b):
  return int(a*b/gcd(a,b))

N = int(input())
ans = 1
for i in range(N):
    t = float(input())
    ans = lcm(t,ans)

print(ans)

Fixed submission:
N = int(input())
T = [int(input()) for i in range(N)]

from functools import reduce
from fractions import gcd

def lcm(a,b):
  return a*b //gcd(a,b)

print(reduce(lcm,T))

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
 if a < b:
    a, b = b, a
 if b == 0:
    return a
 c = a % b
 return gcd(b, c)
def lcm(a,b):
  return int(a*b/gcd(a,b))

N = int(input())
ans = 1
for i in range(N):
    t = int(input())
    ans = lcm(t,ans)

print(ans)

Fixed submission:
N = int(input())
T = [int(input()) for i in range(N)]

from functools import reduce
from fractions import gcd

def lcm(a,b):
  return a*b //gcd(a,b)

print(reduce(lcm,T))
Buggy python submission (verdict: Runtime Error):

N,M = map(int,input().split())
ab =[list(map(int,input().split())) for i in range(M)]
dist = [INF]*(N)
for i in range(M):
    if ab[i][0] == 1:
        dist[ab[i][1]-1] = 1
for i in range(M):
    if ab[i][1] == N:
        if dist[ab[i][0]-1] <= 1:
            print("POSSIBLE")
            exit()
        else:
            continue
print("IMPOSSIBLE")

Fixed submission:
INF = float("inf")


N,M = map(int,input().split())
ab =[list(map(int,input().split())) for i in range(M)]
dist = [INF]*(N)
for i in range(M):
    if ab[i][0] == 1:
        dist[ab[i][1]-1] = 1
for i in range(M):
    if ab[i][1] == N:
        if dist[ab[i][0]-1] <= 1:
            print("POSSIBLE")
            exit()
        else:
            continue
print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())

if (A % 3 == 0) or(B%3==0) or((A+B)%3==):
  print("Possible")
else:
  print("Impossible")

Fixed submission:
A,B = map(int,input().split())
 
if (A%3==0) or(B%3==0) or((A+B)%3==0):
  print("Possible")
else:
  print("Impossible")
Buggy python submission (verdict: Runtime Error):
l =[map(int,input().split())]
print(l[0]+l[1])

Fixed submission:
l = list(map(int,input().split()))
l.sort()
print(l[0]+l[1])

Buggy python submission (verdict: Runtime Error):
l =[map(int,input().split())]
print(l[0]+l[1])

Fixed submission:
l = list(map(int,input().split()))
l.sort()
print(l[0]+l[1])
Buggy python submission (verdict: Runtime Error):
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from collections import Counter
inf = 10**10
from functools import reduce

s = input()
ans = len(s)
for i in set(s):
    t = s.split(i)
    c = 0
    for j in t:
        c = max(c,len(j))
    ans = min(ans,c)
print(ans)

Fixed submission:
s = input()
ans = len(s)
for i in set(s):
    t = s.split(i)
    c = 0
    for j in t:
        c = max(c,len(j))
    ans = min(ans,c)
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
A = set()
ans = inf
for i in range(len(s)):
    A.add(s[i])
for v in A:
    cur = 0
    vstep = 0
    for i in range(len(s)):
        if s[i] != v:
            cur += 1
        else:
            vstep = max(cur,vstep)
            cur = 0
    vstep = max(cur,vstep)
    ans = min(ans,vstep)
print(ans)

Fixed submission:
s = input()
ans = len(s)
for i in set(s):
    t = s.split(i)
    c = 0
    for j in t:
        c = max(c,len(j))
    ans = min(ans,c)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = ""
for i in range(3):
  a = input()
  s += a
if eval(s) % 4 == 0:
  print("YES")
else:
  print("NO")

Fixed submission:
s = ""
a = list(input().split())
for i in range(3):
  s += a[i]
if eval(s) % 4 == 0:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
INF = float("inf")

H,W = map(int,input().split())
ans = INF
for i in range(1,H):
    SA = i * W
    #横半分に分割するケース
    h = math.ceil((H-i)/2)
    SB1 = h * W
    SC1 = (H-i-h)*W
    S1 = max(SA,SB1,SC1)-min(SA,SB1,SC1)
    #縦半分に分割するケース
    w = math.ceil(W/2)
    SB2 = (H-i)*w
    SC2 = (H-i)*(W-w)
    S2 = max(SA,SB2,SC2)-min(SA,SB2,SC2)
    ans = min(ans,S1,S2)
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")

H,W = map(int,input().split())
ans = INF

for i in range(1,H):
    SA = i * W
    h = (H-i)//2
    w = W//2
    SB2 = (H-i)*w
    SC2 = H*W-(SA+SB2)
    SB1 = h * W
    SC1 = H*W-(SA+SB1)
    S1 = max(SA,SB1,SC1)-min(SA,SB1,SC1)
    S2 = max(SA,SB2,SC2)-min(SA,SB2,SC2)
    ans = min(ans,S1,S2)

for i in range(1,W):
    SA = H * i
    #横半分に分割するケース
    h = H//2
    w = (W-i)//2
    SB1 = h * (W-i)
    SC1 = H*W-(SA+SB1)
    S1 = max(SA,SB1,SC1)-min(SA,SB1,SC1)
    #縦半分に分割するケース
    SB2 = H*w
    SC2 = H*W -(SA+SB2)
    S2 = max(SA,SB2,SC2)-min(SA,SB2,SC2)
    ans = min(ans,S1,S2)

print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
edge=[]
for i in range(m):
    a, b, c = map(int, input().split())
    edge.append([a,b,-c])

def BellmanFord(edges,num_v,source):
  #グラフの初期化
  dist=[inf for i in range(num_v)]
  dist[source-1]=0
  #辺の緩和
  for i in range(num_v):
    for e in edges:
      if e[0] != inf and dist[e[1]-1] > dist[e[0]-1] + e[2]:
        dist[e[1]-1] = dist[e[0]-1] + e[2]
        if i == num_v-1:dist[e[1]-1] = inf

  return dist

d = BellmanFord(edge,n,1)

if d[n-1]==inf:
    print("inf")
else:
    print(-d[n-1])

Fixed submission:
from itertools import accumulate
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float('inf')
from functools import reduce

n,m = map(int,input().split())
edge=[]
for i in range(m):
    a, b, c = map(int, input().split())
    edge.append([a,b,-c])

dist = [inf]*n
dist[0] = 0
for i in range(1,n):
    for j in range(m):
        if dist[edge[j][1]-1] > dist[edge[j][0]-1]+edge[j][2]:
            dist[edge[j][1]-1] = dist[edge[j][0]-1]+edge[j][2]

ans = dist[n-1]

for j in range(m):
    if dist[edge[j][1]-1] > dist[edge[j][0]-1]+edge[j][2]:
        dist[edge[j][1]-1] = dist[edge[j][0]-1]+edge[j][2]
if dist[n-1]<ans:
    print("inf")
else:
    print(-ans)
Buggy python submission (verdict: Runtime Error):
a,b = input()

if len(a) < len(b):
  print("LESS")
  exit()
elif len(a) > len(b):
  print("GREATER")
  exit()
else:
  for i in xrange(len(a)):
    if a[i] > b[i]:
      print("GREATER")
      exit()
    elif a[i] < b[i]:
      print("LESS")
      exit()
    else:
      continue
print("EQUAL")

Fixed submission:
a = input()
b = input() 
if len(a) < len(b):
  print("LESS")
  exit()
elif len(a) > len(b):
  print("GREATER")
  exit()
else:
  for i in range(len(a)):
    if a[i] > b[i]:
      print("GREATER")
      exit()
    elif a[i] < b[i]:
      print("LESS")
      exit()
print("EQUAL")
Buggy python submission (verdict: Runtime Error):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
def comb(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)
max_mean = sum(v[0:a])/a
print(max_mean)
#選び方の総数を求める
c = Counter(v)
i = 0
num = 0
ans = 0
while num<=a:
    if num+c[v[i]]>=a:
        num += c[v[i]]
    else:
        i +=1
        num += c[v[i]]
if i > 0:
    ans += comb(c[v[i]],a)
    print(ans)
else:
    for i in range(a,b+1):
        if c[v[0]] >=i:
            ans += comb(c[v[0]],i)
    print(ans)

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
def comb(n,r):
    if r > n:
        return 0
    else:
        return factorial(n)//(factorial(n-r)*factorial(r))
n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse=True)
max_mean = sum(v[0:a])/a
print(max_mean)
#選び方の総数を求める
c = Counter(v)
i = 0
num = 0
ans = 0
while num<a:
    if num+c[v[i]]>=a:
        num += c[v[i]]
    else:
        num += c[v[i]]
        i += 1
num -= c[v[i]]

if i > 0:
        ans += comb(c[v[i]],a-num)
        print(ans)
else:
    for j in range(a,b+1):
        if c[v[0]] >=j:
            ans += comb(c[v[0]],j)
    print(ans)