Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys
from collections import Counter, defaultdict, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


H, W = LI()
B = [[1 if s == '#' else 0 for s in S()] for _ in range(H)]


dy = (0, -1, 0, 1)
dx = (1, 0, -1, 0)
def BFS(i, j):
    ans = 0
    queue = deque([(i, j)])
    visited = set()
    while queue:
        y, x = queue.pop()
        color = B[y][x]
        if color == 0 and (y, x) not in visited:
            # print(y, x)
            ans += 1
        visited.add((y, x))
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if (ny, nx) in visited:
                continue

            if ny < 0 or ny >= H or nx < 0 or nx >= W:
                continue

            if B[ny][nx] == color:
                continue

            queue.append((ny, nx))

    return ans


ans = 0
for h in range(H):
    for w in range(W):
        if B[h][w] == 1:
            ans += BFS(h, w)

print(ans)


Fixed submission:
# coding:utf-8

import sys
from collections import Counter, defaultdict, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


H, W = LI()
B = [[1 if s == '#' else 0 for s in S()] for _ in range(H)]


dy = (0, -1, 0, 1)
dx = (1, 0, -1, 0)

def BFS(i, j):
    ans = 0
    queue = deque([(i, j)])
    visited = set()
    visited_b = set()
    while queue:
        y, x = queue.pop()
        color = B[y][x]
        if color == 0 and (y, x) not in visited:
            # print(y, x)
            ans += 1
        if color == 1:
            visited_b.add((y, x))
        visited.add((y, x))
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if (ny, nx) in visited:
                continue

            if ny < 0 or ny >= H or nx < 0 or nx >= W:
                continue

            if B[ny][nx] == color:
                continue

            queue.append((ny, nx))

    return ans, visited_b


ans = 0
visited_b = set()
for h in range(H):
    for w in range(W):
        if B[h][w] == 1 and (h, w) not in visited_b:
            tmp, v = BFS(h, w)
            ans += tmp * len(v)
            visited_b |= v
            # print(ans, v)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


n, k = inpl()
H = inpl()

if k >= n: k = n - 1
H = [H[0]] + H
dp = [INF] * (n + 1)
dp[0] = 0

for i in range(1, n + 1):
    for j in range(1, k + 1):
        if i - j < 0: break
        dp[i] = min(dp[i], abs(H[i] - H[i - j]) + dp[i - j])
    # print(dp)

print(dp[n])


Fixed submission:
# coding:utf-8

import sys


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


n, k = inpl()
H = inpl()

if k >= n: k = n - 1
H = [H[0]] + H
dp = [INF] * (n + 1)
dp[0] = 0

for i in range(1, n + 1):
    for j in range(1, k + 1):
        if i - j < 0: break
        dp[i] = min(dp[i], abs(H[i] - H[i - j]) + dp[i - j])
    # print(dp)

print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, W = LI()
L = [LI() for _ in range(N)]

# dp[w]: 容量wのナップザックの価値の総和の最大値
dp = [0] * (W + 1)
for weight, value in L:
    for w in range(W + 1)[::-1]:
        if w - weight < 0:
            continue
        dp[w] = max(dp[w], dp[w - weight] + value)

print(dp[W])


Fixed submission:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, W = LI()
L = [LI() for _ in range(N)]

# dp[w]: 容量wのナップザックの価値の総和の最大値
dp = [0] * (W + 1)
for weight, value in L:
    for w in range(W + 1)[::-1]:
        if w - weight < 0:
            continue
        dp[w] = max(dp[w], dp[w - weight] + value)

print(dp[W])

Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, W = LI()
L = [LI() for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
    weight, value = L[i]
    for w in range(W + 1):
        if w - weight >= 0:
            dp[i + 1][w] = max(dp[i][w], dp[i][w - weight] + value)
        else:
            dp[i + 1][w] = dp[i][w]

print(dp[N][W])


Fixed submission:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, W = LI()
L = [LI() for _ in range(N)]

# dp[w]: 容量wのナップザックの価値の総和の最大値
dp = [0] * (W + 1)
for weight, value in L:
    for w in range(W + 1)[::-1]:
        if w - weight < 0:
            continue
        dp[w] = max(dp[w], dp[w - weight] + value)

print(dp[W])
Buggy python submission (verdict: Runtime Error):
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


s = [ord(n) for n in S()]
t = [ord(n) for n in S()]

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i][j + 1])
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

# 最長共通部分列の長さ
# print(dp[-1][-1])

ans = ''
i = len(s)
for j in range(len(t) + 1)[::-1]:
    if dp[i][j] != dp[i][j - 1]:
        while dp[i][j] == dp[i - 1][j]:
            i -= 1
        ans += chr(t[j - 1])
        i -= 1

print(ans[::-1])


Fixed submission:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


s = [ord(n) for n in S()]
t = [ord(n) for n in S()]

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i][j + 1])
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

# 最長共通部分列の長さ
# print(dp[-1][-1])

ans = ''
i = len(s)
for j in range(len(t) + 1)[::-1]:
    if dp[i][j] != dp[i][j - 1]:
        if i == 0 or j == 0: break
        while dp[i][j] == dp[i - 1][j]:
            i -= 1
        ans += chr(t[j - 1])
        i -= 1

print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
P = LF()

# dp[i]: i枚のコインが表になる確率
dp = [1]

# 調和級数
# O(NlogN)
for i in range(n):
    tmp = [0] * (i + 2)
    p = P[i]
    q = 1 - P[i]
    for j in range(i + 1):
        tmp[j] += dp[j] * q
        tmp[j + 1] += dp[j] * p
    dp = tmp

print(sum(dp[n // 2 + 1:]))


Fixed submission:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
P = LF()

# dp[i][j]: i番目のコインまで投げた時，j枚のコインが表になる確率
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1

# 調和級数
# O(NlogN)
for i in range(n):
    for j in range(i + 1):
        if dp[i][j] == 0:
            continue
        # P[i]が裏
        dp[i + 1][j] += dp[i][j] * (1 - P[i])
        # P[i]が表
        dp[i + 1][j + 1] += dp[i][j] * P[i]

print(sum(dp[n][n // 2 + 1:]))

Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
P = LF()

# dp[i][j]: i番目のコインまで投げた時，j枚のコインが表になる確率
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1

# 調和級数
# O(NlogN)
for i in range(n):
    for j in range(i + 1):
        if dp[i][j] == 0:
            continue
        # P[i]が裏
        dp[i + 1][j] += dp[i][j] * (1 - P[i])
        # P[i]が表
        dp[i + 1][j + 1] += dp[i][j] * P[i]

print(sum(dp[n][n // 2 + 1:]))


Fixed submission:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
P = LF()

# dp[i][j]: i番目のコインまで投げた時，j枚のコインが表になる確率
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1

# 調和級数
# O(NlogN)
for i in range(n):
    for j in range(i + 1):
        if dp[i][j] == 0:
            continue
        # P[i]が裏
        dp[i + 1][j] += dp[i][j] * (1 - P[i])
        # P[i]が表
        dp[i + 1][j + 1] += dp[i][j] * P[i]

print(sum(dp[n][n // 2 + 1:]))
Buggy python submission (verdict: Runtime Error):
n=input()
p=1
for i in range(n):
    a=input()
    if a%2:
        p=0
print(['first','second'][p])

Fixed submission:
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()

D = []
for i in range(1, N):
    D.append(A[i] - A[i - 1])

if A[-1] % 2 == 1:
    print('first')
else:
    cnt_e, cnt_o = 0, 0
    for i in range(N - 1):
        if A[i] % 2 == 0:
            cnt_e += 1
        else:
            cnt_o += 1

    if cnt_o > 0:
        print('first')
    else:
        print('second')
Buggy python submission (verdict: Runtime Error):
# coding:utf-8

import sys
from collections import Counter, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()
A = [I() for _ in range(N)]

A.sort()
B = deque()

state = 1
for i in range(N // 2):
    if state:
        B.append(A[i])
        B.appendleft(A[-(i + 1)])
    else:
        B.append(A[-(i + 1)])
        B.appendleft(A[i])
    state ^= 1
if N % 2:
    C = deque(B)
    B.append(A[N // 2])
    C.appendleft(A[N // 2])

ans1 = 0
ans2 = 0
for i in range(N - 1):
    ans1 += abs(B[i] - B[i + 1])
    ans2 += abs(C[i] - C[i + 1])

print(max(ans1, ans2))


Fixed submission:
# coding:utf-8

import sys
from collections import Counter, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()
A = [I() for _ in range(N)]

A.sort()
B = deque()

state = 1
for i in range(N // 2):
    if state:
        B.append(A[i])
        B.appendleft(A[-(i + 1)])
    else:
        B.append(A[-(i + 1)])
        B.appendleft(A[i])
    state ^= 1
if N % 2:
    C = deque(B)
    B.append(A[N // 2])
    C.appendleft(A[N // 2])
else:
    C = A[:]

ans1 = 0
ans2 = 0
for i in range(N - 1):
    ans1 += abs(B[i] - B[i + 1])
    ans2 += abs(C[i] - C[i + 1])

print(max(ans1, ans2))
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

import sys


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


# aのp乗を求めるアルゴリズム
# MOD版
def pow_mod(a, p):
    if p == 0: return 1

    if p % 2 == 0:
        half_p = p // 2
        half = pow_mod(a, half_p)
        return half * half % MOD
    else:
        return a * pow_mod(a, p - 1) % MOD


def solve(N, A):
    # 階乗N!を求める
    fact = [1] * N
    for i in range(1, N):
        fact[i] = fact[i - 1] * (i + 1)

    # 1/N!の逆元を求める
    fact_inv = [1] * N
    fact_inv[-1] = pow_mod(fact[-1], MOD - 2)
    for i in range(N - 1, 0, -1):
        tmp = fact_inv[i] * (i + 1)
        tmp %= MOD
        fact_inv[i - 1] = tmp

    # 1/kを求める
    inv = [1]
    for i in range(1, N):
        inv.append((fact[i - 1] * fact_inv[i]) % MOD)

    # 1/kの累積和を求める
    inv_sum = [1]
    for i in range(1, N):
        inv_sum.append((inv_sum[-1] + inv[i]) % MOD)

    # 累積和の結果を係数としてAiに掛けて、加算する
    ans = 0
    for i in range(N):
        ans += A[i] * (inv_sum[i] + inv_sum[N - 1 - i] - 1)
        ans %= MOD

    # ansにN!を掛けたものを返す
    return ans * fact[-1] % MOD


N = int(input())
A = inpl()
print(solve(N, A))


Fixed submission:
# coding:utf-8

import sys


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


# aのp乗を求めるアルゴリズム
# MOD版
def pow_mod(a, p):
    if p == 0: return 1

    if p % 2 == 0:
        half_p = p // 2
        half = pow_mod(a, half_p)
        return half * half % MOD
    else:
        return a * pow_mod(a, p - 1) % MOD


def solve(N, A):
    # 1/1 + 1/2 + 1/3 + ... + 1/Nの累積和を求めておく
    inv_sum = [0]
    for i in range(N):
        inv_sum.append((inv_sum[-1] + pow_mod(i + 1, MOD - 2)) % MOD)
    del inv_sum[0]

    # 各iについて、Σ(j=1, N) 1/(|j - i| + 1)を求めて、
    # それらを係数としてA[i]に掛け、加算する
    ans = 0
    for i in range(N):
        ans += + A[i] * (inv_sum[N - 1 - i] + inv_sum[i] - 1)
        ans %= MOD

    # ansにN!を掛ける
    for i in range(N):
        ans *= (i + 1)
        ans %= MOD
    return ans


N = int(input())
A = inpl()
print(solve(N, A))
Buggy python submission (verdict: Runtime Error):
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def solve():
    for cx in range(101):
        for cy in range(101):
            ch = D[0][0] + abs(D[0][1] - cx) + abs(D[0][2] - cy)
            for h, x, y in D:
                if h != max(ch - (abs(x - cx) + abs(y - cy)), 0):
                    break
            else:
                return cx, cy, ch


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])

    h_min = max(D)[0]
    ans = solve()
    print(' '.join(map(str, ans)))


Fixed submission:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def solve():
    for x in range(101):
        for y in range(101):
            for h in range(h_min, h_min + 201):
                for i in range(N):
                    if D[i][0] != max(h - abs(D[i][1] - x) - abs(D[i][2] - y), 0):
                        break
                else:
                    return x, y, h


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])

    h_min = max(D)[0]
    ans = solve()
    print(' '.join(map(str, ans)))

Buggy python submission (verdict: Runtime Error):
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def solve():
    for cx in range(101):
        for cy in range(101):
            ch = D[0][0] + abs(D[0][1] - cx) + abs(D[0][2] - cy)
            for h, x, y in D:
                if h != ch - (abs(x - cx) + abs(y - cy)):
                    break
            else:
                return cx, cy, ch


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])

    h_min = max(D)[0]
    ans = solve()
    print(' '.join(map(str, ans)))


Fixed submission:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def solve():
    for x in range(101):
        for y in range(101):
            for h in range(h_min, h_min + 201):
                for i in range(N):
                    if D[i][0] != max(h - abs(D[i][1] - x) - abs(D[i][2] - y), 0):
                        break
                else:
                    return x, y, h


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])

    h_min = max(D)[0]
    ans = solve()
    print(' '.join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
# coding:utf-8
def inpl(): return list(map(int, input().split()))
N, M = inpl()
i = 2
tmp = []
MM = M
while i * i <= MM:
    if MM % i == 0:
        tmp.append(i)
        while MM % i == 0:
            MM //= i
    i += 1
if MM != 1:
    tmp.append(MM)
n = M // N
sub = tmp[0]
while n > 0:
    if M % n == 0:
        print(n)
        break
    else:
        n -= sub

Fixed submission:
# coding:utf-8


def inpl(): return list(map(int, input().split()))


N, M = inpl()

n = M // N
while n > 0:
    if M % n == 0:
        print(n)
        break
    else:
        n -= 1

Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, M = inpl()

n = M // N
while n > 0:
    if M % n == 0:
        print(n)
        break
    else:
        n -= 1


Fixed submission:
# coding:utf-8


def inpl(): return list(map(int, input().split()))


N, M = inpl()

n = M // N
while n > 0:
    if M % n == 0:
        print(n)
        break
    else:
        n -= 1
Buggy python submission (verdict: Runtime Error):
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def move(x, y):
    command = ''
    if x > 0:
        command += 'R' * x
    else:
        command += 'L' * abs(x)
    if y > 0:
        command += 'U' * y
    else:
        command += 'D' * abs(y)
    command += 'RL' * ((max_length - abs(x) - abs(y)) // 2)
    return command


N = int(input())
point = []
max_length = 0
for i in range(N):
    x, y = inpl()
    max_length = max(max_length, abs(x) + abs(y))
    point.append([x, y])

tmp = sum(point[0]) % 2
judge = True
for p in point:
    if tmp ^ sum(p) % 2:
        judge = False

if judge:
    print(max_length)
    print(' '.join(['1'] * max_length))
    for x, y in point:
        print(move(x, y))
else:
    print(-1)


Fixed submission:
# coding:utf-8

import sys
input = sys.stdin.readline
INF = float('inf')


def inpl(): return list(map(int, input().split()))


def move_uv(x, y):
    ut = x + y
    vt = x - y
    command = ''
    u, v = 0, 0
    for i in range(len(D)):
        if u <= ut and v <= vt:
            command += 'R'
            u += D[i]
            v += D[i]
        elif u <= ut and v > vt:
            command += 'U'
            u += D[i]
            v -= D[i]
        elif u > ut and v <= vt:
            command += 'D'
            u -= D[i]
            v += D[i]
        else:
            command += 'L'
            u -= D[i]
            v -= D[i]

    return command


N = int(input())
point = []
max_length = 0
for i in range(N):
    x, y = inpl()
    max_length = max(max_length, abs(x) + abs(y))
    point.append([x, y])

parity = sum(point[0]) % 2
judge = True
for p in point:
    if parity ^ sum(p) % 2:
        judge = False
        break

if not judge:
    print(-1)
else:
    D = [2 ** i for i in range(len(bin(max_length)) - 1)]
    D.reverse()

    # X + Yが偶数の時は長さ1の腕を足す
    if parity == 0:
        D.append(1)
    print(len(D))
    print(' '.join(map(str, D)))
    for i in range(N):
        print(move_uv(point[i][0], point[i][1]))
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8

INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


# nの素因数分解を求めるアルゴリズム
def p_factorization(n):
    tmp = []
    i = 2
    cnt = 0
    while n > 1:
        if n % i == 0:
            cnt += 1
            n //= i
        else:
            tmp.append([i, cnt])
            i += 1
            cnt = 0
    tmp.append([i, cnt])
    return tmp


# aのp乗を求めるアルゴリズム
# MOD版
# O(logp)
def pow_mod(a, p):
    if p == 0: return 1
    if p % 2 == 0:
        half_p = p // 2
        half = pow_mod(a, half_p)

        return half * half % MOD
    else:
        return a * pow_mod(a, p - 1) % MOD


# 組み合わせnCrを求めるアルゴリズム
# 逆元を使って計算
# MOD版
def cmb_mod(n, r):
    # 5C3 -> 5C2
    if r > n - r: return cmb_mod(n, n - r)
    ans_mul = 1
    ans_div = 1
    for i in range(r):
        ans_mul *= n - i
        ans_div *= i + 1
        ans_mul %= MOD
        ans_div %= MOD

    # ans_mul / ans_divをしたい
    # ans_divの逆元を使って求める
    ans = ans_mul * pow_mod(ans_div, MOD - 2) % MOD
    return ans


N, M = inpl()

fact = p_factorization(M)
ans = 1
for n, p in fact:
    ans *= cmb_mod(N - 1 + p, p)
    ans %= MOD

print(ans)


Fixed submission:
# coding:utf-8

INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


# aのp乗を求めるアルゴリズム
# MOD版
# O(logp)
def pow_mod(a, p):
    if p == 0: return 1
    if p % 2 == 0:
        half_p = p // 2
        half = pow_mod(a, half_p)

        return half * half % MOD
    else:
        return a * pow_mod(a, p - 1) % MOD


# 組み合わせnCrを求めるアルゴリズム
# 逆元を使って計算
# MOD版
def cmb_mod(n, r):
    # 5C3 -> 5C2
    if r > n - r: return cmb_mod(n, n - r)
    ans_mul = 1
    ans_div = 1
    for i in range(r):
        ans_mul *= n - i
        ans_div *= i + 1
        ans_mul %= MOD
        ans_div %= MOD

    # ans_mul / ans_divをしたい
    # ans_divの逆元を使って求める
    ans = ans_mul * pow_mod(ans_div, MOD - 2) % MOD
    return ans


N, M = inpl()
ans = 1
i = 2
while i * i <= M:
    if M % i == 0:
        cnt = 0
        while M % i == 0:
            cnt += 1
            M //= i
        ans *= cmb_mod(N - 1 + cnt, cnt)
        ans %= MOD
    i += 1

if M != 1:
    ans *= cmb_mod(N - 1 + 1, 1)
    ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


x1, y1, x2, y2 = inpl()

diff_y = y2 - y1
diff_x = x2 - x1
ans1 = [x2 - diff_y, y2 + diff_x]
ans2 = [ans1[0] - diff_x, ans1[1] - diff_y]
ans = ans1 + ans2
print(' '.join(map(str, ans))

Fixed submission:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


x1, y1, x2, y2 = inpl()

diff_y = y2 - y1
diff_x = x2 - x1
ans1 = [x2 - diff_y, y2 + diff_x]
ans2 = [ans1[0] - diff_x, ans1[1] - diff_y]
ans = ans1 + ans2
ans = ' '.join(map(str, ans))
print(ans)