Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()

if n%2 != 0:
        m = int(n/2)
        x = 0
        y = 0
        z = max(a[2*m]-a[m], a[m]-a[0])
        for i in range(m):
                x += int(a[2*m-i] - a[i])
        for i in range(m-1):
                y += int(a[2*m-1-i] - a[i])
        print(x+y+z)
elif n%2 == 0:
        m = int(n/2)
        x = 0
        y = 0
        for i in range(m-1):
                x += int(a[2*m-1-i] - a[i])
        for i in range(m-2):
                y += int(a[2*m-2-i] - a[i])
        print(x+y+a[m]-a[m-2]+a[2*m-1]-a[m-1])    

Fixed submission:
s = input()

if len(s) == 2:
        print(s)
elif len(s) == 3:
        print(s[::-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n == 1:
    print('Hello World')
else:
    A,B = map(int,input().split())
    print(A+B)

Fixed submission:
n = int(input())
if n == 1:
    print('Hello World')
else:
    A = int(input())
    B = int(input())
    print(A+B)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

n,x = map(int,input().split())
A = list(map(int,input().split()))
for i in range(n):
    A[i] -= x
print(reduce(math.gcd, A))

Fixed submission:
def gcd(A,B):
    while B != 0:
        A,B = B,A%B
    return A
n,x = map(int,input().split())
li = [abs(int(i)-x) for i in input().split()]
ans = li[0]
for i in range(n):
    ans = gcd(ans,li[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
li = list(input().split())
li.sort()

print(li[2]-li[0])

Fixed submission:
li = list(map(int,input().split()))
li.sort()

print(li[2]-li[0])
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())

if max(a,b) <= 8:
        print('Yay!')
else:
        print(':(')

Fixed submission:
a,b = map(int,input().split())

if max(a,b) <= 8:
        print('Yay!')
else:
        print(':(')
Buggy python submission (verdict: Runtime Error):
d,n = map(int,input().split())

if n != 100:
        print(100**d*n)
else:
        print(100**d8(n+1))

Fixed submission:
d,n = map(int,input().split())

if n != 100:
        print(100**d*n)
else:
        print(100**d*(n+1))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())

print(max(a+b,a-b,a*b))

Fixed submission:
a,b = map(int,input().split())

print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
e_count = S.count('E')
w_count = 0
ans = e_count

for s in S:
    if s == 'E':
        e_count -= 1
    else:
        w_count += 1
    if e_count + w_count < ans:
        e_count+w_count = ans

print(ans)

Fixed submission:
N = int(input())
S = input()
e_count = S.count('E')
w_count = 0
ans = e_count

for s in S:
    if s == 'E':
        e_count -= 1
    else:
        w_count += 1
    if e_count + w_count < ans:
        ans = e_count+w_count

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 10000000

for i in range(N):
    left = S[0:i]
    right = S[i+1:N]
    count = left.count('W') + right.count('E')
    if ans > count:
        ans = count
    
print(ans)

Fixed submission:
N = int(input())
S = input()
e_count = S.count('E')
w_count = 0
ans = e_count

for s in S:
    if s == 'E':
        e_count -= 1
    else:
        w_count += 1
    if e_count + w_count < ans:
        ans = e_count+w_count

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
xarray = list(map(int,input().split()))
newArray = xarray[:]
newArray.sort()


for item in xarray:
    if newArray.index(item)<=int(n/2-1):
        print(newArray[int(n/2)])
    else:
        print(newArray[int(n/2)-1])

Fixed submission:
n = int(input())
xarray = list(map(int,input().split()))
newArray = xarray[:]
newArray.sort()

left = newArray[n//2-1]
right = newArray[n//2]


for item in xarray:
    if item<=left:
        print(right)
    else:
        print(left)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
xarray = list(map(int,input().split()))
newArray = copy.copy(xarray)
newArray.sort()


for item in xarray:
    if newArray.index(item)<=int(n/2-1):
        print(newArray[int(n/2)])
    else:
        print(newArray[int(n/2)-1])

Fixed submission:
n = int(input())
xarray = list(map(int,input().split()))
newArray = xarray[:]
newArray.sort()

left = newArray[n//2-1]
right = newArray[n//2]


for item in xarray:
    if item<=left:
        print(right)
    else:
        print(left)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int,input().split()))

for i in range(N):
    li = []
    for l in range(N):
        li.append(A_list[l])
    del li[i]
    ans = abs(li[0]) + abs(li[N-2])
    for m in range(N-2):
        ans += abs(li[m] - li[m+1])
    print(ans)


Fixed submission:
N = int(input())
A_list = list(map(int,input().split()))
a = [0]
b = [0]
point_list = a + A_list + b
S = 0
for i in range(N+1):
    S += abs(point_list[i]-point_list[i+1])

for i in range(1,N+1):
    print(S - abs(point_list[i-1] - point_list[i])
    -abs(point_list[i] - point_list[i+1])
    +abs(point_list[i-1] - point_list[i+1]))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())
if (a*b)%2 == 0:
    print('Even')
else:
    print('Odd')

Fixed submission:
a,b = map(int,input().split())
if (a*b)%2 == 0:
    print('Even')
else:
    print('Odd')

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())
if a*b%2 == 0:
    print('Even')
else:
    print('Odd')

Fixed submission:
a,b = map(int,input().split())
if (a*b)%2 == 0:
    print('Even')
else:
    print('Odd')
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())

x = a+b
y = c+d

if x>:y
    print('Left')
elif x == y:
    print('Balanced')
else:
    print('Right')

Fixed submission:
a,b,c,d = map(int,input().split())

x = a+b
y = c+d

if x>y:
    print('Left')
elif x == y:
    print('Balanced')
else:
    print('Right')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
cnt = 0
max_A = max(A)

for i in range(-1,max_A+1):
    temp_cnt = 0
    for j in range(n):
        if A[j]-1 == i or A[j] == i or A[j]+1 == i:
            temp_cnt += 1
    if temp_cnt > cnt:
        cnt = temp_cnt

print(cnt)

Fixed submission:
import collections
n = int(input())
A = list(map(int,input().split()))
counter = collections.Counter(A)
max_A = max(A)
cnt = 0

for i in range(-1,max_A):
    temp_cnt = counter[i-1] + counter[i] + counter[i+1]
    cnt = max(cnt,temp_cnt)

print(cnt)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())

if b<=c:
    print(0)
elif a<=c and b<=d:
    print(b-c)
elif a<=c and d<=b:
    print(d-c)
elif c<=a and b<=d:
    print(b-a)
elif c<=a and d<=b:
    print(d-a)
elif d<=a
    print(0)

Fixed submission:
a,b,c,d = map(int, input().split())

if b<=c or d<=a:
    print(0)
elif a<=c and b<=d:
    print(b-c)
elif a<=c and d<=b:
    print(d-c)
elif c<=a and b<=d:
    print(b-a)
elif c<=a and d<=b:
    print(d-a)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int ,input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]
print(" ".join(map(str,b)))

Fixed submission:
n = int(input())
a = list(map(str,input().split()))
b = []

for i in range(n-1-(1-(n-1)%2),0,-2):
    b.append(a[i])
for i in range(0,n-1-(n-1)%2+1,2):
    b.append(a[i])

if n%2 == 1:
    b = b[::-1]
print(" ".join(b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
color = []
cnt = 0

for i in range(n):
    c = A[i]//400
    if c<=7:
        color.append(c)
    else:
        cnt += 1

diff = set(color)
minimum = max(len(diff),1)
maximum = min(len(diff)+cnt)

print(minimum, maximum)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
color = []
cnt = 0

for i in range(n):
    c = A[i]//400
    if c<=7:
        color.append(c)
    else:
        cnt += 1

diff = set(color)
minimum = max(len(diff),1)
maximum = len(diff)+cnt

print(minimum, maximum)
Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())
x+y = a
if a >= 10:
        print('error')
else:
        print(a)

Fixed submission:
x,y = map(int,input().split())
a = x+y
if a >= 10:
        print('error')
else:
        print(a)

Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())

if x+y >= 10:
        print('error')
else:
        print(a+b)

Fixed submission:
x,y = map(int,input().split())
a = x+y
if a >= 10:
        print('error')
else:
        print(a)
Buggy python submission (verdict: Runtime Error):
,b,c = map(int,input().split())

for i in range(1,b+1):
    if a*i%b == c:
        print('YES')
        break
else:
    print('NO')


Fixed submission:
a,b,c = map(int,input().split())

for i in range(1,b+1):
    if (a*i)%b == c:
        print('YES')
        break
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())

if a*b >= c*d:
    print(a*b)
elif c*d > a*b:
    print(c*d)

Fixed submission:
x,y,z,w = map(int, input().split())

if x*y >= z*w:
        print(x*y)
else:
        print(z*w)

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

Fixed submission:
x,y,z,w = map(int, input().split())

if x*y >= z*w:
        print(x*y)
else:
        print(z*w)

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

Fixed submission:
x,y,z,w = map(int, input().split())

if x*y >= z*w:
        print(x*y)
else:
        print(z*w)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
ans = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i+j+l == s:
                ans += 1

print(ans)

Fixed submission:
k,s = map(int, input().split())
a = (s+2)*(s+1)/2
b = (s-k+1)*(s-k)/2
c = (s-2*k)*(s-2*k-1)/2

if s <= k:
    print(int(a))
elif s <= 2*k+1:
    print(int(a-3*b))
elif s <= 3*k:
    print(int(a-3*b+3*c))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))

if n%2 == 0:
    for i in range(1,n,2):
        if not A.count(i) == 2:
            print(0)
            break
    else:
        print(2**(n//2)%(10**9+7))
else:
    if not A.count(0) == 1:
        print(0)
    else:
        for i in range(2,n,2):
            if not A.count(i) == 2:
                print(0)
                break
        else:
            print(2**((n-1)//2)%(10**9+7))

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
A.sort()

if n%2 == 0:
    for i in range(n):
        if i%2 == 0:
            if not A[i] == i+1:
                print(0)
                break
        else:
            if not A[i] == i:
                print(0)
                break
    else:
        print(2**(n//2)%(10**9+7))
else:
    if not A[0] == 0:
        print(0)
    else:    
        for i in range(1,n):
            if i%2 == 0:
                if not A[i] == i:
                    print(0)
                    break
            else:
                if not A[i] == i+1:
                    print(0)
                    break
        else:
            print(2**((n-1)//2)%(10**9+7))
Buggy python submission (verdict: Runtime Error):
count = 0
a = min(m,n)
b = max(m,n)

if a/x == int(a//x) and b/x == int(b//x):
    print(int(1 + b//x - a//x))

elif a/x == int(a//x) and b/x != int(b//x):
    print(int(int(b//x) - int(a//x) + 1))

elif a/x != int(a//x) and b/x == int(b//x):
    print(int(int(b//x) - int(a//x)))

elif a/x != int(a//x) and b/x != int(b//x):
    print(int(int(b//x) - int(a//x)))

Fixed submission:
a,b,x = map(int,input().split())
print(b//x-(a-1)//x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
Ratio = [list(map(int,input().split())) for _ in range(n)]
t,a = Ratio[0][0],Ratio[0][1]

for i in range(1,n):
    count = 1
    while True:
        if Ratio[i][0]*count >= t and Ratio[i][1]*count >= a:
            t,a = Ratio[i][0]*count,Ratio[i][1]*count
            break
        else:
            count += 1

print(t+a)

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

for i in range(n):
    x = max((t+Ratio[i][0]-1)//Ratio[i][0],(a+Ratio[i][1]-1)//Ratio[i][1])
    t,a = Ratio[i][0]*x,Ratio[i][1]*x
print(int(t+a))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()

min_dist = 10**10
for i in range(len(S) - len(T) + 1):
    for k in range(len(T)):
        dist = sum(s != t for s, t in zip(S[i:i + len(T)], T))
        min_dist = min(dist, min_dist)
        if min_dist == 0:
            print(0)
            exit()

print(min_dist)


Fixed submission:
S = input()
T = input()

min_dist = 10**10
for i in range(len(S) - len(T) + 1):
    for k in range(len(T)):
        dist = 0
        for s, t in zip(S[i:i + len(T)], T):
            if s != t:
                dist += 1
            if dist >= min_dist:
                break

        min_dist = min(dist, min_dist)
        if min_dist == 0:
            print(0)
            exit()

print(min_dist)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()

min_dist = 10**10
for i in range(len(S) - len(T) + 1):
    for k in range(len(T)):
        dist = sum(s != t for s, t in zip(S[i:i + len(T)], T))
        min_dist = min(dist, min_dist)
        if min_dist == 0:
            print(0)
            exit()

print(min_dist)


Fixed submission:
S = input()
T = input()

min_dist = 10**10
for i in range(len(S) - len(T) + 1):
    for k in range(len(T)):
        dist = 0
        for s, t in zip(S[i:i + len(T)], T):
            if s != t:
                dist += 1
            if dist >= min_dist:
                break

        min_dist = min(dist, min_dist)
        if min_dist == 0:
            print(0)
            exit()

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

N = int(input())

for n in range(1, N + 1):
    count = 0
    ub = int(math.sqrt(n))
    for x in range(1, ub + 1):
        for y in range(x, ub + 1):
            for z in range(y, ub + 1):
                if x * x + y * y + z * z + x * y + y * z + z * x == n:
                    s = len(set([x, y, z]))
                    if s == 1:
                        count += 1
                    elif s == 2:
                        count += 3
                    else:
                        count += 6
                    break
    print(count)


Fixed submission:
import math

N = int(input())

for n in range(1, N + 1):
    count = 0
    ub = int(math.sqrt(n))
    for x in range(1, ub + 1):
        for y in range(x, ub + 1):
            r = 4 * n - 3 * x * x - 2 * x * y - 3 * y * y
            if r < 0:
                break
            z = (math.sqrt(r) - x - y) / 2
            if z - int(z) < 1e-9:
                z = int(z)
            elif z - int(z + 1) < 1e-9:
                z = int(z + 1)
            else:
                break

            if y > z or z > ub:
                break
            if abs(x * x + y * y + z * z + x * y + y * z + z * x - n) < 1e-9:
                #print(x, y, round(z), z)
                s = len(set([x, y, round(z)]))
                if s == 1:
                    count += 1
                elif s == 2:
                    count += 3
                else:
                    count += 6

    print(count)

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

N = int(input())

for n in range(1, N + 1):
    count = 0
    for x, y, z in product(range(1, int(math.sqrt(N)) + 1), repeat=3):
        if x * x + y * y + z * z + x * y + y * z + z * x == n:
            count += 1
    print(count)


Fixed submission:
import math

N = int(input())

for n in range(1, N + 1):
    count = 0
    ub = int(math.sqrt(n))
    for x in range(1, ub + 1):
        for y in range(x, ub + 1):
            r = 4 * n - 3 * x * x - 2 * x * y - 3 * y * y
            if r < 0:
                break
            z = (math.sqrt(r) - x - y) / 2
            if z - int(z) < 1e-9:
                z = int(z)
            elif z - int(z + 1) < 1e-9:
                z = int(z + 1)
            else:
                break

            if y > z or z > ub:
                break
            if abs(x * x + y * y + z * z + x * y + y * z + z * x - n) < 1e-9:
                #print(x, y, round(z), z)
                s = len(set([x, y, round(z)]))
                if s == 1:
                    count += 1
                elif s == 2:
                    count += 3
                else:
                    count += 6

    print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
connections = [[] for _ in range(N)]
for a, b in AB:
    connections[a - 1].append(b - 1)
    connections[b - 1].append(a - 1)
    
markers = [-1] * N
    
queue = [0]
steps = [-1] * N
steps[0] = 0
while len(queue) >= 1:
    room = queue.pop(0)
    for r in connections[room]:
        if steps[r] >= 0:
            continue
        queue.append(r)
        steps[r] = steps[room] + 1
        markers[r] = str(room + 1)
    
print("Yes")
print("\n".join(markers[1:]))

Fixed submission:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
connections = [[] for _ in range(N)]
for a, b in AB:
    connections[a - 1].append(b - 1)
    connections[b - 1].append(a - 1)

markers = [-1] * N

queue = [0]
steps = [-1] * N
steps[0] = 0
while len(queue) >= 1:
    room = queue.pop(0)
    for r in connections[room]:
        if steps[r] >= 0:
            continue
        queue.append(r)
        steps[r] = steps[room] + 1
        markers[r] = str(room + 1)

print("Yes")
print("\n".join(markers[1:]))
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
dists = [[-1] * N for _ in range(N)]
graph = [[1]]
graph .extend([i - 1, i + 1] for i in range(1, N - 1))
graph.append([N - 2])
graph[X - 1].append(Y - 1)
graph[Y - 1].append(X - 1)

d_count = [0] * N

for i in range(N):
    q = [i]
    dists[i][i] = 0
    while len(q) >= 1:
        n = q.pop(0)
        for n_next in graph[n]:
            if dists[i][n_next] >= 0:
                continue
            dists[i][n_next] = dists[i][n] + 1
            d_count[dists[i][n_next]] += 1
            q.append(n_next)

print("\n".join(str(d_count[i] // 2) for i in range(1, N)))

Fixed submission:
N, X, Y = map(int, input().split())
dists = [[-1] * N for _ in range(N)]
graph = [[1]]
graph .extend([i - 1, i + 1] for i in range(1, N - 1))
graph.append([N - 2])
graph[X - 1].append(Y - 1)
graph[Y - 1].append(X - 1)

d_count = [0] * N

for i in range(N):
    q = [i]
    dists[i][i] = 0
    while len(q) >= 1:
        n = q.pop(0)
        for n_next in graph[n]:
            if dists[i][n_next] >= 0:
                continue
            dists[i][n_next] = dists[i][n] + 1
            d_count[dists[i][n_next]] += 1
            q.append(n_next)

print("\n".join(str(d_count[i] // 2) for i in range(1, N)))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = deque(list(input()))
Q = int(input())
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        S.reverse()
    else:
        f, c = q[1:]
        if f == "1":
            S.appendleft(c)
        else:
            S.append(c)

print("".join(S))

Fixed submission:
from collections import deque

S = deque(list(input()))
Q = int(input())
r = False
left = deque()
right = deque()
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        r = not r
    else:
        f, c = q[1:]
        if f == "1":
            if r:
                right.append(c)
            else:
                left.appendleft(c)
        else:
            if r:
                left.appendleft(c)
            else:
                right.append(c)

S, left, right = map(list, (S, left, right))
left.extend(S)
left.extend(right)
print("".join(left[::-1] if r else left))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = [int(p) for p in input().split()]

me = 0
for i in range(N - K + 1):
    e = sum((1 + p) / 2 for p in P[i: i + K])
    me = max(e, me)

print(me)

Fixed submission:
N, K = map(int, input().split())
P = [int(p) for p in input().split()]
P_cum = [0] * N
P_cum[0] = P[0]
for i in range(1, len(P)):
    P_cum[i] = P_cum[i - 1] + P[i]

me = 0
for i in range(N - K + 1):
    if i >= 1:
        e = (P_cum[i + K - 1] - P_cum[i - 1] + K) / 2
    else:
        e = (P_cum[i + K - 1] + K) / 2
    me = max(e, me)

print(me)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
if N <= 9:
    print(N)
    exit()

tot_count = 0
for af in map(str, range(1, 10)):
    for bf in map(str, range(1, 10)):
        a_count = 0
        b_count = 0
        for a in map(str, range(1, N + 1)):
            if a[0] == af and a[-1] == bf:
                a_count += 1
        for b in map(str, range(1, N + 1)):
            if b[0] == bf and b[-1] == af:
                b_count += 1

        tot_count += a_count * b_count

print(tot_count)

Fixed submission:

N = int(input())
if N <= 9:
    print(N)
    exit()

tot_count = 0
for af in map(str, range(1, 10)):
    for bf in map(str, range(1, 10)):
        a_count = 0
        b_count = 0
        for a in map(str, range(1, N + 1)):
            if a[0] == af and a[-1] == bf:
                a_count += 1
        for b in map(str, range(1, N + 1)):
            if b[0] == bf and b[-1] == af:
                b_count += 1

        tot_count += a_count * b_count

print(tot_count)
Buggy python submission (verdict: Runtime Error):
X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print("0")
    exit()

n = (-X + 2 * Y) / 3
m = (2 * X - Y) / 3
if n < 0 or m < 0:
    print("0")
else:
    import math
    n, m = int(n), int(m)
    s = 0
    for i in range(2, m + n + 1):
        s += math.log(i)
    for i in range(2, m + 1):
        s -= math.log(i)
    for i in range(2, n + 1):
        s -= math.log(i)
    
    print(int(math.exp(s)) % (10**9 + 7))

Fixed submission:
X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print("0")
    exit()

n_right = (-X + 2 * Y) / 3
n_up = (2 * X - Y) / 3
if n_right < 0 or n_up < 0:
    print("0")
    exit()


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7  # 出力の制限
N = 10**6
g1, g2, inverse = [1, 1], [1, 1], [0, 1]

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

n_right, n_up = int(n_right), int(n_up)
print(cmb(n_right + n_up, min((n_right, n_up)), mod))