Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
for j in range(n):
    ans += 0^a[j]

if k != 0:
    for i in range(1,k+1):
        ans_temp = 0
        for j in range(n):
            ans_temp += i ^ a[j]
        ans = max(ans, ans_temp)

print(int(ans))

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 0

for i in range(40,-1,-1):
    power = 1 << i
    #<<...ビット演算子「左シフト」。(=値２倍)
    bit_count_of_1 = sum(1 for a in a if a & power != 0) #i番目のビットに1はいくつあるか?

    if power > k: # power > kなら、kの該当ビットは必ず0なので、寄与はその時点で決定
        ans += power * bit_count_of_1
    elif bit_count_of_1 > n - bit_count_of_1: #その桁で1の方が多いならxの最適解は0。
        ans += power * bit_count_of_1
    else:
        ans += power * (n - bit_count_of_1)
        k -= power

print(ans)
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
a = list(map(int,input().split()))
x =[]
for n in range(q):
    x.append(int(input()))

for i in range(q):
    ans = 0
    atemp = a.copy()
    for j in range(n+1):
        if (j % 2) == 0:
            ans += max(atemp)
            atemp.remove(max(atemp))
        else:
            atemprmv = max(atemp)
            deltmin =abs(max(atemp)-x[i])
            for k in range(len(atemp)):
                deltemp = abs(atemp[k]-x[i])
                if deltemp <= deltmin:
                    atemprmv = min(atemprmv,atemp[k])
            atemp.remove(atemprmv)
    print(int(ans))


Fixed submission:
n,q = map(int,input().split())
a = list(map(int,input().split()))
x = [int(input()) for _ in range (q)]

sort_x = sorted(x)
ans = {}
if n % 2 == 1:
    small_position = 0
    border_position = int((n-1)/2)
else:
    small_position = 1
    border_position = int(n/2)
sum_all = sum(a[border_position:])
a.append(1000000000)
a.append(1000000000)
x_index = 0
flag = False

for compare in a[border_position:]:
    compare_x = sort_x[x_index]
    small_a = a[small_position]
    while 2*sort_x[x_index] - small_a <= compare:
        ans[sort_x[x_index]] = sum_all
        x_index += 1
        if x_index == q:
            flag = True
            break
    sum_all = sum_all + small_a - compare
    small_position += 2
    if flag:
        break
for x_i in x:
    print(ans[x_i])
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
A  = list(map(int, input().split()))
MOD = 10**9+7N, K = list(map(int, input().split()))
A  = list(map(int, input().split()))
MOD = 10**9+7

#　そのブロック内での転倒数
ans1 = 0
for i in range(N):
    for j in range(i+1,N):
        if A[i] > A[j]:
            ans1 += 1

#　２つのブロック内での転倒数
ans2 = 0
B = sorted(A)
now = B[0]
cnt = 0
for i in range(1,N):
    if now != B[i]:
        cnt = i
        ans2 += cnt
        now = B[i]
    else:
        ans2 += cnt

ans11 = ans1 * K
ans22 = ans2 * (K * (K-1) // 2)
ans = ans11 + ans22
print(int(ans % MOD))


#　そのブロック内での転倒数
ans1 = 0
for i in range(N):
    for j in range(i+1,N):
        if A[i] > A[j]:
            ans1 += 1

#　２つのブロック内での転倒数
ans2 = 0
B = sorted(A)
now = B[0]
cnt = 0
for i in range(1,N):
    if now != B[i]:
        cnt = i
        ans2 += cnt
        now = B[i]
    else:
        ans2 += cnt

ans11 = ans1 * (K + 1)
ans22 = ans2 * (K * (K-1) / 2)
ans = ans11 + ans22
print(int(ans % MOD))


Fixed submission:
N, K = list(map(int, input().split()))
A  = list(map(int, input().split()))
MOD = 10**9+7

#　そのブロック内での転倒数
ans1 = 0
for i in range(N):
    for j in range(i+1,N):
        if A[i] > A[j]:
            ans1 += 1

#　２つのブロック内での転倒数
ans2 = 0
B = sorted(A)
now = B[0]
cnt = 0
for i in range(1,N):
    if now != B[i]:
        cnt = i
        ans2 += cnt
        now = B[i]
    else:
        ans2 += cnt

ans11 = ans1 * K
ans22 = ans2 * (K * (K-1) // 2)
ans = ans11 + ans22
print(ans % MOD)
Buggy python submission (verdict: Runtime Error):
import math

N, K = list(map(int, input().split()))
MOD = 10**9+7

for i in range(1,K+1):
    ans = math.factorial(N-K+1) // (math.factorial(N-K-i+1) * math.factorial(i)) * math.factorial(K-1) // (math.factorial(K-i) * math.factorial(i-1))% MOD
    print(ans)


Fixed submission:
import math

N, K = list(map(int, input().split()))
MOD = 10**9+7
i = 1
ans = math.factorial(N-K+1) // (math.factorial(N-K-i+1) * math.factorial(i)) * math.factorial(K-1) // (math.factorial(K-i) * math.factorial(i-1)) % MOD

for i in range(1,K+1):
    if i <= N-K+1:
        ans = math.factorial(N-K+1) // (math.factorial(N-K-i+1) * math.factorial(i)) * math.factorial(K-1) // (math.factorial(K-i) * math.factorial(i-1)) % MOD
    else:
        ans = 0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A = list(map(int, input().split()))
N = A.pop(3)
A.sort()
R = A[2]
G = A[1]
B = A[0]
ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        now = N - r*R - g*G
        if  now >= 0 and now % B == 0:
            ans += 1
print(ans)


Fixed submission:
R,G,B,N = list(map(int, input().split()))
ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        now = N - r*R - g*G
        if  now >= 0 and now % B == 0:
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = list(map(int, input().split()))
ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        now = N - r*R - g*G
        if  now >= 0 and now % B == 0:
            ans += 1
print(ans)


Fixed submission:
R,G,B,N = list(map(int, input().split()))
ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        now = N - r*R - g*G
        if  now >= 0 and now % B == 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def gcd_l(A):
    if len(A) == 1:
        return A[0]
    x = gcd(A[0], A[1])
    if len(A) == 2:
        return x
    for i in range(2, len(A)):
        x = gcd(x, A[i])
    return x

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

B = []
x = A[0]
for i in range(N):
    x = gcd(x, A[i])
    B.append(x)

ans = 1
for i in range(1, N-1):
    ans = max(ans, gcd(B[i-1], gcd_l(A[i+1:])))
ans = max(ans, B[N-1], gcd_l(A[1:]))

print(ans)


Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def gcd_l(A):
    if len(A) == 1:
        return A[0]
    x = gcd(A[0], A[1])
    if len(A) == 2:
        return x
    for i in range(2, len(A)):
        x = gcd(x, A[i])
    return x

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

B = []
C = []
x = A[0]
y = A[-1]
for i in range(N):
    x = gcd(x, A[i])
    B.append(x)
    y = gcd(y, A[N-1-i])
    C.append(y)
    
ans = 1

for i in range(1, N-1):
    ans = max(ans, gcd(B[i-1], C[N-2-i]))

ans = max(ans, B[N-2], C[N-2])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def gcd_l(A):
    if len(A) == 1:
        return A[0]
    x = gcd(A[0], A[1])
    if len(A) == 2:
        return x
    for i in range(2, len(A)):
        x = gcd(x, A[i])
    return x

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

ans = 1
for i in range(N):
    B = A[:i] + A[i+1:]
    ans = max(ans, gcd_l(B))

print(ans)


Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def gcd_l(A):
    if len(A) == 1:
        return A[0]
    x = gcd(A[0], A[1])
    if len(A) == 2:
        return x
    for i in range(2, len(A)):
        x = gcd(x, A[i])
    return x

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

B = []
C = []
x = A[0]
y = A[-1]
for i in range(N):
    x = gcd(x, A[i])
    B.append(x)
    y = gcd(y, A[N-1-i])
    C.append(y)
    
ans = 1

for i in range(1, N-1):
    ans = max(ans, gcd(B[i-1], C[N-2-i]))

ans = max(ans, B[N-2], C[N-2])

print(ans)
Buggy python submission (verdict: Runtime Error):
N =int(input())
S = list(input())
K = int(input())

for i in range(N):
    if S[i] == S[K]:
        pass
    else:
        S[i] = '*'

print(''.join(S))


Fixed submission:
N =int(input())
S = list(input())
K = int(input())

for i in range(N):
    if S[i] == S[K-1]:
        pass
    else:
        S[i] = '*'

print(''.join(S))
Buggy python submission (verdict: Runtime Error):
A = list(int(input()) for _ in range(5))
B = []
for i in range(5):
    if A[i] % 10 != 0:
        
        B.append(10 - A[i] % 10)
B.remove(max(B))
print(sum(A) + sum(B))


Fixed submission:
A = list(int(input()) for _ in range(5))
B = [0]
for i in range(5):
    if A[i] % 10 != 0:
        
        B.append(10 - A[i] % 10)
B.remove(max(B))
print(sum(A) + sum(B))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = list(input())
lr = list(list(map(int, input().split())) for _ in range(Q))

lst = [0] * N
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        lst[i] += 1

for i in range(Q):
    print( sum( lst[ lr[i][0] - 1 : lr[i][1] - 1 ] ) )


Fixed submission:
N, Q = map(int, input().split())
S = list(input())
lr = list(list(map(int, input().split())) for _ in range(Q))

lst = [0] * N
'''
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        lst[i] += 1

for i in range(Q):
    print( sum( lst[ lr[i][0] - 1 : lr[i][1] - 1 ] ) )
'''
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C' and i == 0:
        lst[i] += 1
    elif S[i] == 'A' and S[i+1] == 'C':
        lst[i] += 1 + lst[i-1]
    else:
        lst[i] += lst[i-1]

for i in range(Q):
    print(lst[ lr[i][1] - 2 ] - lst[ lr[i][0] - 2 ] )
Buggy python submission (verdict: Time Limit Exceeded):
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for _ in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True


def dfs(cur, last3):
    '''
    if last3 in memo[cur]:
        return memo[cur][last3]
    '''
    if cur == N:
        return 1
    ret = 0
    for x in 'ATGC':
        if ok(last3 + x):
            ret = (ret + dfs(cur + 1, last3[1:] + x)) % MOD
    #memo[cur][last3] = ret
    return ret

print(dfs(0, 'TTT'))


Fixed submission:
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for _ in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True


def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for x in 'ATGC':
        if ok(last3 + x):
            ret = (ret + dfs(cur + 1, last3[1:] + x)) % MOD
    memo[cur][last3] = ret
    return ret

print(dfs(0, 'TTT'))
Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.append(b[0])
a.append(b[1])
a.append(c[0])
a.append(c[1])
x = [0] * 4

for i in a:
    x[a] += 1

for i in range(4):
    if x[i] in [1, 2]:
        print('YES')
    else:
        print('NO')

Fixed submission:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.append(b[0])
a.append(b[1])
a.append(c[0])
a.append(c[1])
x = [0] * 4

for i in a:
    x[i-1] += 1

f = 0
for i in range(4):
    if x[i] in [1, 2]:
        f += 1

if f == 4:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
l = list(map(int, input().split()))
a = max(l)
b = l.remove(a)
c = np.sum(b)
if a < c:
    print('Yes')
else:
    print('No')

Fixed submission:
#import numpy as np
n = int(input())
l = list(map(int, input().split()))
a = max(l)
l.remove(a)

c = sum(l)
if a < c:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))
a = max(l)
b = l.remove(a)
c = sum(b)
if a < c:
    print('Yes')
else:
    print('No')

Fixed submission:
#import numpy as np
n = int(input())
l = list(map(int, input().split()))
a = max(l)
l.remove(a)

c = sum(l)
if a < c:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))

x.sort()
y = []
for i in range(m-1):
    y.append(x[i+1] - x[i])

for i in range(n-1):
    y.remove(max(y))

w = sum(y)
print(w)


Fixed submission:
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))

x.sort()
y = []
for i in range(m-1):
    y.append(x[i+1] - x[i])

y.sort()


'''
for i in range(n-1):
    y.remove(max(y))
'''
if m > n: w = sum(y[:m-n])
else: w = 0
print(w)
Buggy python submission (verdict: Time Limit Exceeded):
def f(a):
    if a % 2 == 0:
        return a // 2
    elif a % 2 == 1:
        return 3 * a + 1

s = int(input())
a = [s]
done = False
while not done:
    for i in range(len(a)):
        if a[i] != f(a[-1]):
            a.append(f(a[-1]))

        else:
            print(i)
            done = True
            break


Fixed submission:
def f(n):
    if n % 2 == 0:
        return n // 2
    elif n % 2 == 1:
        return 3 * n + 1


s = int(input())
a = [s]
done = False
while not done:
    if f(a[-1]) in a:
        print(len(a) + 1)
        done = True
        break
    else:
        a.append(f(a[-1]))

Buggy python submission (verdict: Runtime Error):
def f(a):
    if a // 2 == 0:
        return a // 2
    if a // 2 == 1:
        return 3 * a + 1

s = int(input())
a = [s]
done = False
while not done:
    for i in range(len(a)):
        if a[i] != f(a[-1]):
            a.append(f(a[-1]))

        else:
            print(i)
            done = True
            break


Fixed submission:
def f(n):
    if n % 2 == 0:
        return n // 2
    elif n % 2 == 1:
        return 3 * n + 1


s = int(input())
a = [s]
done = False
while not done:
    if f(a[-1]) in a:
        print(len(a) + 1)
        done = True
        break
    else:
        a.append(f(a[-1]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
x = {}
y = {}
h = {}
for i in range(N):
  x[i], y[i], h[i] = map(int, input().split())
  if h[i] != 0:
    x0, y0, h0 = x[i], y[i], h[i]
    break
for cx in range(101):
  for cy in range(101):
    H = h0 + abs(cx - x0) + abs(cy - y0)
    for i in range(N):
      if max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]:
        break
    else:
      print(cx, cy, H)
      break
    continue
  else:
    continue
  break


Fixed submission:
N = int(input())
x = {}
y = {}
h = {}
for i in range(N):
  x[i], y[i], h[i] = map(int, input().split())
  if h[i] != 0:
    x0, y0, h0 = x[i], y[i], h[i]
for cx in range(101):
  for cy in range(101):
    H = h0 + abs(cx - x0) + abs(cy - y0)
    for i in range(N):
      if max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]:
        break
    else:
      print(cx, cy, H)
      break
    continue
  else:
    continue
  break
Buggy python submission (verdict: Runtime Error):
n = input()

lst = list(map(int, list(n)))
print(sum(lst[0], lst[0] - 1 + 9 * (len(lst) - 1)))


Fixed submission:
n = input()

lst = list(map(int, list(n)))
print(max(sum(lst), lst[0] - 1 + 9 * (len(lst) - 1)))

Buggy python submission (verdict: Runtime Error):
s = input()

n = int(s)
lst = list(map(int, list(s)))
lst_uniq = list(set(lst))
#lst_ans = [9] * (len(lst) - 1)

if lst_uniq == [9] or len(lst) == 1:
    ans = sum(lst)
elif lst[0] == 1:
    ans = 9 * (len(lst) - 1)
else:
    #lst_ans = [lst[0] - 1] + lst_ans
    ans = lst[0] - 1 + 9 : (len(lst) - 1)

print(ans)


Fixed submission:
n = input()

lst = list(map(int, list(n)))
print(max(sum(lst), lst[0] - 1 + 9 * (len(lst) - 1)))

Buggy python submission (verdict: Runtime Error):
s = input()

n = int(s)
lst = list(map(int, list(s)))
lst_uniq = list(set(lst))
lst_ans = [9] * (len(lst) - 1)

if lst_uniq == [9] or len(n) == 1:
    ans = sum(lst)
elif lst[0] == 1:
    ans = sum(lst_ans)
else:
    lst_ans = [lst[0] - 1] + lst_ans
    ans = sum(lst_ans)

print(ans)


Fixed submission:
n = input()

lst = list(map(int, list(n)))
print(max(sum(lst), lst[0] - 1 + 9 * (len(lst) - 1)))
Buggy python submission (verdict: Runtime Error):
s=input()
s[3]=8
print(s)

Fixed submission:
s=list(input())
s[3]='8'
print(''.join(s))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
B = []
for a in A:
    if a in B:
        B.remove(a)
    else:
        B.append(a)

print(len(B))


Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
A.append(10**9+1)

now = 0
cnt = 0
ans = 0
for a in A:
    if a == now:
        cnt += 1
    else:
        now = a
        ans += cnt % 2
        cnt = 1

print(ans)
Buggy python submission (verdict: Runtime Error):
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
Traceback (most recent call last):
  File "C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py", line 13, in <module>
    print(gcd_list(a))
  File "C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py", line 9, in gcd_list
    for i in range(len(n)):
NameError: name 'n' is not defined
>>> 
======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
None

======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
6

======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
6

======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
3

======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
3 7
9 3 4
Traceback (most recent call last):
  File "C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py", line 19, in <module>
    if A[-1] > k and (A[-1] - k) % gcd_lst(A) == 0:
NameError: name 'gcd_lst' is not defined
>>> 
======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
3 7
9 3 4
POSSIBLE
>>> 
======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
3 5
6 9 3
IMPOSSIBLE
>>> 
======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
4 11
11 3 7 15
POSSIBLE
>>> 
======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py =======
5 12
10 2 8 6 4
IMPOSSIBLE
>>> 

Fixed submission:
def gcd(a, b):
    if  b == 0:
        return a
    else:
        return gcd(b, a % b)

def gcd_list(a):
    x = a[0]
    for i in range(len(a)):
        x = gcd(a[i], x)
    return x
        

n, k = map(int, input().split())
A = list(map(int, input().split()))

ans = 'IMPOSSIBLE'
A.sort()
if A[-1] >= k and (A[-1] - k) % gcd_list(A) == 0:
    ans = 'POSSIBLE'

print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split())).sort()
A.revrese
print(sum(A[:K]))

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A.reverse()
print(sum(A[:K]))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split())).sort().reverse()

print(sum(A[:K]))

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A.reverse()
print(sum(A[:K]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

B = [1]
i = 0
flag = False
for _ in range(N):
    if 2 in B:
        flag = True
        break
    elif A[i] in B:
        break
    B.append(A[i])
    i = A[i] - 1

print(len(B) - 1) if flag else print(-1)


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

B = [1]
i = 0
cnt = 0
flag = False
for _ in range(N):
    i = A[i] - 1
    cnt += 1
    if i == 1:
        flag = True
        break

print(cnt) if flag else print(-1)
Buggy python submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())
N, M = max(N,M), min(N,M)
MOd = 10**9+7

if N == M:
    ans = math.factorial(N) ** 2 * 2
elif N - M == 1:
    ans = math.factorial(M) ** 2 * N
else:
    ans = 0

print(ans // MOD)

Fixed submission:
import math

N, M = map(int, input().split())
N, M = max(N,M), min(N,M)
MOD = 10**9+7

if N == M:
    ans = math.factorial(N) ** 2 * 2
elif N - M == 1:
    ans = math.factorial(M) ** 2 * N
else:
    ans = 0

print(ans % MOD)

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

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

if N == M:
    ans = math.factorial(N) ** 2 * 2
elif N - M == 1:
    ans = math.factorial(N) * math.factorial(M)
else:
    ans = 0

print(ans)


Fixed submission:
import math

N, M = map(int, input().split())
N, M = max(N,M), min(N,M)
MOD = 10**9+7

if N == M:
    ans = math.factorial(N) ** 2 * 2
elif N - M == 1:
    ans = math.factorial(M) ** 2 * N
else:
    ans = 0

print(ans % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = []
for _ in range(N):
    a, b = map(int, input().split())
    A += [a] * b

A.sort()
print(A[K-1])


Fixed submission:
N, K = map(int, input().split())
AB = list(list(map(int, input().split())) for _ in range(N))

AB.sort()
if AB[0][1] >= K:
    ans = AB[0][0]
else:
    for i in range(1,N):
        AB[i][1] += AB[i-1][1]
        if AB[i][1] >= K:
            ans = AB[i][0]
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

if A > B:
    ans = 'GREATER'
elif A == B:
    ans = 'EQUAL'
else:
    ans = 'LESS'

Fixed submission:
A = int(input())
B = int(input())
if A > B:
    ans = 'GREATER'
elif A == B:
    ans = 'EQUAL'
else:
    ans = 'LESS'

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

for i in range(1,N):
    if i * i <= N:
        if N % i == 0:
            ans = i
    else:
        break
print(len(str(N // ans)))


Fixed submission:
N = int(input())

for i in range(1,N+1):
    if i * i <= N:
        if N % i == 0:
            ans = i
    else:
        break
print(len(str(N // ans)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 1
for i in range(N):
    ans *= i+1

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


Fixed submission:
import math

N = int(input())
print(math.factorial(N) % (10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
ans = 0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x + y + z == S:
                ans += 1

print(ans)


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

for x in range(K+1):
    for y in range(K+1):
        z = S - y - x
        if 0 <= z <= K:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
A, op,B = list(input())
A = int(A)
B = int(B)
if op == '+':
    ans = A + B
else:
    ans = A - B
print(ans)

Fixed submission:
A, op,B = input().split()
A = int(A)
B = int(B)
if op == '+':
    ans = A + B
else:
    ans = A - B
print(ans)

Buggy python submission (verdict: Runtime Error):
str = input().split()

if str[1] == "+":
  print str[0]+str[2]
else:
  print str[0]-str[2]


Fixed submission:
str = input().split()

if str[1] == "+":
  print(int(str[0]) + int(str[2]))
else:
  print(int(str[0]) - int(str[2]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ln = []
ans = 0

for i in range(n):
    ln.append(''.join(sorted(input())))

for i in range(len(ln)):
    for j in range(i+1,len(ln)):
        if ln[i] == ln[j]:
            ans += 1
            continue

print(ans)


Fixed submission:
n = int(input())
ln = []
cnt = 1
ans = 0

for i in range(n):
    ln.append(''.join(sorted(input())))

ln.sort()

for i in range(len(ln)-1):
    if ln[i] == ln[i+1]:
        cnt += 1
    else:
        ans += cnt*(cnt - 1)/2
        cnt = 1

ans += cnt*(cnt - 1)/2

print(int(ans))