Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# ABC093B - Small and Large Integers
a, b, k = list(map(int, input().rstrip().split()))
lst = []
ans = []
for i in range(a, b + 1):
    lst.append(i)
if k >= b - a:
    for i in range(a, b + 1):
        print(i)
else:
    for i in range(k):
        ans.append(a + i)
    for j in range(k):
        if b - j not in ans:
            ans.append(b - j)
    ans = sorted(ans)
    for k in ans:
        print(k)

Fixed submission:
# ABC093B - Small and Large Integers
a, b, k = list(map(int, input().rstrip().split()))
ans = []

if k >= b - a:
    for i in range(a, b + 1):
        print(i)
else:
    for i in range(k):
        ans.append(a + i)
    for j in range(k):
        if b - j not in ans:
            ans.append(b - j)
    ans = sorted(ans)
    for k in ans:
        print(k)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC093B - Small and Large Integers
a, b, k = list(map(int, input().rstrip().split()))
lst = []
ans = []
for i in range(a, b + 1):
    lst.append(i)
if k >= b - a:
    for i in lst:
        print(i)
else:
    for i in range(k):
        ans.append(lst[i])
    for j in range(-1, -k - 1, -1):
        if lst[j] not in ans:
            ans.append(lst[j])
    ans = sorted(ans)
    for k in ans:
        print(k)

Fixed submission:
# ABC093B - Small and Large Integers
a, b, k = list(map(int, input().rstrip().split()))
ans = []

if k >= b - a:
    for i in range(a, b + 1):
        print(i)
else:
    for i in range(k):
        ans.append(a + i)
    for j in range(k):
        if b - j not in ans:
            ans.append(b - j)
    ans = sorted(ans)
    for k in ans:
        print(k)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC093B - Small and Large Integers
a, b, k = list(map(int, input().rstrip().split()))
lst = []
ans = []
for i in range(a, b + 1):
    lst.append(i)
if k >= b - a:
    for i in lst:
        print(i)
else:
    for i in range(k):
        ans.append(lst[i])
    for j in range(-1, -k - 1, -1):
        if lst[j] not in ans:
            ans.append(lst[j])
    ans = sorted(ans)
    for k in ans:
        print(k)

Fixed submission:
# ABC093B - Small and Large Integers
a, b, k = list(map(int, input().rstrip().split()))
ans = []

if k >= b - a:
    for i in range(a, b + 1):
        print(i)
else:
    for i in range(k):
        ans.append(a + i)
    for j in range(k):
        if b - j not in ans:
            ans.append(b - j)
    ans = sorted(ans)
    for k in ans:
        print(k)
Buggy python submission (verdict: Time Limit Exceeded):
# ARC093C - Traveling Plan
N = int(input())
A = list(map(int, input().rstrip().split()))
for i in range(N):
    ans = 0
    cur = 0
    for j in range(N):
        if i == j:
            continue
        ans += max(cur, A[j]) - min(cur, A[j])
        cur = A[j]
    print(ans + abs(cur))

Fixed submission:
# ARC093C - Traveling Plan
N = int(input())
A = [0] + list(map(int, input().rstrip().split())) + [0]
S = 0
for i in range(1, N + 2):
    S += abs(A[i - 1] - A[i])

for i in range(1, N + 1):
    ans = S + abs(A[i - 1] - A[i + 1]) - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]))
    print(ans)
Buggy python submission (verdict: Runtime Error):
# ABC089C - March
from itertools import combinations as comb


def main():
    N, *S = open(0).read().split()
    cnt = [sum(s.startswith(i) for S) for i in "MARCH"]
    ans = sum(x * y * z for x, y, z in comb(cnt, 3))
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC089
import sys
input = sys.stdin.readline

from itertools import combinations

n = int(input())
lst = [input().rstrip() for _ in range(n)]
cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in lst:
    if i[0] in "MARCH":
        cond[i[0]] += 1
ans = 0
for x, y, z in combinations("MARCH", 3):
    ans += cond[x] * cond[y] * cond[z]
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = listmap(int, input().rstrip().split())
print("Even" if a % 2 or b % 2 else "Odd")

Fixed submission:
# ABC086A - Product
a, b = list(map(int, input().rstrip().split()))
print("Even" if a % 2 == 0 or b % 2 == 0 else "Odd")
Buggy python submission (verdict: Runtime Error):
# ABC084C - Special Trains
def main():
    N = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    for i in range(n):
        cur = 0
        for c, s, f in A[i:]:
            if cur <= s:
                cur = s + c
            else:
                cur = (cur + f - 1) // f * f + c
        print(cur)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC084C - Special Trains
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().split())) for _ in range(n - 1))
    for i in range(n):
        cur = 0
        for c, s, f in arr[i:]:
            if cur <= s:
                cur = s + c
            else:
                cur = (cur + f - 1) // f * f + c
        print(cur)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ABC084C - Special Trains
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().split())) for _ in range(n - 1))
    for i in range(n - 1):
        cur = 0
        for j in range(i, n - 1):
            m, f, s = arr[j]  # move, first train, space (interval)
            if cur <= f:
                cur = f + m
            else:
                t = f  # next train to ride
                while t < cur:
                    t += s
                cur = t + m
        print(cur)
    print(0)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC084C - Special Trains
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().split())) for _ in range(n - 1))
    for i in range(n):
        cur = 0
        for c, s, f in arr[i:]:
            if cur <= s:
                cur = s + c
            else:
                cur = (cur + f - 1) // f * f + c
        print(cur)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC083B - Some Sums
def main():
    N, A, B = tuple(map(int, input().split()))
    ans = sum(i for i in range(1, N + 1) if a <= sum(map(int, str(i))) <= b)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC083B - Some Sums

n, a, b = list(map(int, input().split()))
answer = 0

for i in range(n + 1):
    total = sum(list(map(int, list(str(i)))))
    if a <= total <= b:
        answer += i
    
print(answer)

Buggy python submission (verdict: Runtime Error):
# ABC083B - Some Sums
import sys

n, a, b = list(map(int, stdin.readline().split()))
answer = 0
for i in range(1, n + 1):
    total = 0
    while i > 9:
        total += i % 10
        i //= 10
    if a <= i and i <= b:
        answer += total

print(answer)

Fixed submission:
# ABC083B - Some Sums

n, a, b = list(map(int, input().split()))
answer = 0

for i in range(n + 1):
    total = sum(list(map(int, list(str(i)))))
    if a <= total <= b:
        answer += i
    
print(answer)
Buggy python submission (verdict: Runtime Error):
# ARC087C - Good Sequence (ABC082C)
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = [0] * (10 * 9 + 1)
    for i in lst:
        cnt[i] += 1
    ans = 0
    for i, j in enumerate(cnt):
        if i > j:
            ans += j
        elif i < j:
            ans += j - i
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# ARC087C - Good Sequence (ABC082C)
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = {}
    for i in lst:
        if i not in cnt:
            cnt[i] = 0
        cnt[i] += 1
    ans = 0
    for i, j in cnt.items():
        if i > j:
            ans += j
        elif i < j:
            ans += j - i
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC081C - Not so Diverse (ARC086C)
from collections import Counter


def main():
    N, K, *A = map(int, open(0).read().split())
    C = Counter(A).values()
    C.sort(reverse=1)
    ans = sum(C[K:])
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC081C - Not so Diverse (ARC086C)
n, k = list(map(int, input().rstrip().split()))
lst = sorted(list(map(int, input().rstrip().split())))
dic = {}
for i in lst:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

cnt = sorted([i for i in dic.values()], reverse=True)
ans = 0
for i in range(len(cnt)):
    if k > 0:
        k -= 1
        continue
    ans += cnt[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
# cf17-finalA - AKIBA
def main():
    S = input().rstrip()
    flg = S.replace("A", "") == "KIHBR" and "AA" not in S and "KA
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()

Fixed submission:
# cf17-finalA - AKIBA
def main():
    S = input().rstrip()
    flg = (
        S.replace("A", "") == "KIHBR"
        and "AA" not in S
        and "KA" not in S
        and "IA" not in S
    )
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# ABC084C - Snuke Festival
n = int(input())
lst = [list(map(int, input().rstrip().split())) for _ in range(3)]
ans = 0
for i in lst[0]:
    for j in lst[1]:
        if j > i:
            for k in lst[2]:
                if k > j:
                    ans += 1
print(ans)

Fixed submission:
# ABC084C - Snuke Festival
from bisect import bisect_left, bisect_right

n = int(input())
lst_a = sorted(list(map(int, input().rstrip().split())))
lst_b = list(map(int, input().rstrip().split()))
lst_c = sorted(list(map(int, input().rstrip().split())))
lgth = len(lst_c)
ans = 0
for i in lst_b:
    ans += bisect_left(lst_a, i) * (lgth - bisect_right(lst_c, i))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC084C - Snuke Festival
n = int(input())
lst = [list(map(int, input().rstrip().split())) for _ in range(3)]
ans = 0
for i in lst[0]:
    for j in lst[1]:
        if j > i:
            for k in lst[2]:
                if k > j:
                    ans += 1
print(ans)

Fixed submission:
# ABC084C - Snuke Festival
from bisect import bisect_left, bisect_right

n = int(input())
lst_a = sorted(list(map(int, input().rstrip().split())))
lst_b = list(map(int, input().rstrip().split()))
lst_c = sorted(list(map(int, input().rstrip().split())))
lgth = len(lst_c)
ans = 0
for i in lst_b:
    ans += bisect_left(lst_a, i) * (lgth - bisect_right(lst_c, i))
print(ans)
Buggy python submission (verdict: Runtime Error):
# code-festival-2017-qualcC - Inserting 'x'
def main():
    S = input().rstrip()
    ans, l, r = 0, 0, len(S) - 1
    while l != r:
        if S[l] == S[r]:
            l += 1
            r -= 1
        else:
            ans += 1
            if S[l] == "x":
                l += 1
            elif S[r] == "x":
                r -= 1
            else:
                print(-1)
                return
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# code-festival-2017-qualcC - Inserting 'x'
from collections import deque


def main():
    S = deque(list(input().rstrip()))
    ans = 0
    while len(S) >= 2:
        l, r = S[0], S[-1]
        if l == r:
            S.popleft(), S.pop()
        else:
            ans += 1
            if l == "x":
                S.append("x")
            elif r == "x":
                S.appendleft("x")
            else:
                print(-1)
                return
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC075B - Minesweeper
def check_neighbors(i: int, j: int) -> int:
    # count the number of landmines adjacent to S[i][j]
    ret = 0
    for x, y in neighbors:
        a, b = i + x, j + y
        if 0 <= a < H and 0 <= b < W:
            ret += 1 if S[a][b] == "#" else 0
    return ret


def main():
    global S, neighbors
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    neighbors = [(-1, -1), (-1, 0), (-1, 1), (0, -1)]
    neighbors += [(0, 1), (1, -1), (1, 0), (1, 1)]
    A = [""] * H
    for i, s in enumerate(S):
        for j, a in enumerate(s):
            if a == "#":
                A[i] += "#"
            else:
                cnt = check_neighbors(i, j)
                A[i] += str(cnt)
    print(*A, sep="\n")


if __name__ == "__main__":
    main()

Fixed submission:
# ABC075B - Minesweeper
h, w = list(map(int, input().rstrip().split()))
lst = [list(input().rstrip()) for _ in range(h)]
emp_lst = ["."] * (w + 2)

for i in lst:
    i.append(".")
    i.insert(0, ".")

lst.append(emp_lst)
lst.insert(0, emp_lst)

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if lst[i][j] == ".":
            count = 0
            if lst[i - 1][j - 1] == "#":
                count += 1
            if lst[i - 1][j] == "#":
                count += 1
            if lst[i - 1][j + 1] == "#":
                count += 1
            if lst[i][j - 1] == "#":
                count += 1
            if lst[i][j + 1] == "#":
                count += 1
            if lst[i + 1][j - 1] == "#":
                count += 1
            if lst[i + 1][j] == "#":
                count += 1
            if lst[i + 1][j + 1] == "#":
                count += 1
            lst[i][j] = count

for i in range(1, h + 1):
    for j in range(1, w + 1):
        print(lst[i][j], end="")
    print()
Buggy python submission (verdict: Runtime Error):
# tenka1-2017-beginnerB - Different Distribution
def main():
    N, *AB = map(int, open(0).read().split())
    A = [sum(i, j) for i, j in zip(*[iter(AB)] * 2)]
    ans = max(A)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# tenka1-2017-beginnerB - Different Distribution
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = sorted(tuple(map(int, input().rstrip().split())) for _ in range(n))
    print(A[-1][0] + A[-1][1])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# tenka1-2017-beginnerB - Different Distribution
def main():
    N, *AB = map(int, open(0).read().split())
    A = [sum(i, j) for i, j in zip(*[iter(AB)] * 2)]
    ans == max(A)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# tenka1-2017-beginnerB - Different Distribution
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = sorted(tuple(map(int, input().rstrip().split())) for _ in range(n))
    print(A[-1][0] + A[-1][1])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# tenka1-2017-beginnerC - 4/N
# exhaustive search
def main():
    N = int(input())
    for h in range(1, 3501):
        for n in range(1, 3501):
            numerator = N * h * n
            denominator = 4 * h * n - N * n - N * h
            if denominator > 0 and numerator % denominator == 0:
                w = numerator // denominator
                print(h, n, w)
                return


if __name__ == "__main__":
    main()

Fixed submission:
# tenka1-2017-beginnerC - 4/N
# exhaustive search
def main():
    N = int(input())
    for h in range(1, 3501):
        for n in range(1, 3501):
            numerator = N * h * n
            denominator = 4 * h * n - N * n - N * h
            if denominator > 0 and numerator % denominator == 0:
                w = numerator // denominator
                print(h, n, w)
                return


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC072B - OddString
s = input()
ans = ""
for i in range(0, len(s) + 1, 2):
    ans += s[i]
print(ans)

Fixed submission:
# ABC072B - OddString
s = input()
ans = ""
for i in range(0, len(s), 2):
    ans += s[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
# ABC070D - Transit Tree Path
import sys
input = sys.stdin.readline

def dfs(v: int, p: int) -> None:
    d = dist[v]
    for u, c in G[v]:  # search vertices available from v recursively
        if u != p:  # p: parent
            dist[u] += d + c  # dist(K, v) + dist(v, u) == d + c
            dfs(u, v)


def main():
    global G, dist
    N = int(input())
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    Q, K = tuple(map(int, input().split()))
    X = tuple(tuple(map(int, input().split())) for _ in range(Q))
    G = [[] for _ in range(N + 1)]  # graph, N+1: 1-idx
    for v, u, c in E:  # construct a graph
        G[v] += [(u, c)]
        G[u] += [(v, c)]
    dist = [0] * (N + 1)  # distance from vertex K
    dfs(K, -1)
    ans = [dist[x] + dist[y] for x, y in X]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Fixed submission:
# ABC070D - Transit Tree Path
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def dfs(v: int, p: int) -> None:
    d = dist[v]
    for u, c in G[v]:  # search vertices available from v recursively
        if u != p:  # p: parent
            dist[u] += d + c  # dist(K, v) + dist(v, u) == d + c
            dfs(u, v)


def main():
    global G, dist
    N = int(input())
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    Q, K = tuple(map(int, input().split()))
    X = tuple(tuple(map(int, input().split())) for _ in range(Q))
    G = [[] for _ in range(N + 1)]  # graph, N+1: 1-idx
    for v, u, c in E:  # construct a graph
        G[v] += [(u, c)]
        G[u] += [(v, c)]
    dist = [0] * (N + 1)  # distance from vertex K
    dfs(K, -1)
    ans = [dist[x] + dist[y] for x, y in X]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC067D - Fennec VS. Snuke (ARC078D)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v: int, x: int, y: int) -> None:
    D[y][v] = x
    for u in G[v]:
        if not D[y][u]:
            dfs(u, x + 1, y)


def main():
    global G, D
    N = int(input())
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    G = [[] for _ in range(N + 1)]
    for v, u in E:
        G[v] += [u]
        G[u] += [v]
    D = [[0] * (N + 1) for _ in range(2)]
    dfs(1, 1, 0), dfs(N, 1, 1)
    b, w = 0, 0
    for i, j in zip(*D[1:]):
        if i <= j:
            b += 1
        else:
            w += 1
    flg = b > w
    print("Fennec" if flg else "Snuke")


if __name__ == "__main__":
    main()

Fixed submission:
# ABC067D - Fennec VS. Snuke (ARC078D)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

from collections import deque


def bfs(s, d) -> None:
    q = deque([s])
    while q:
        v = q.popleft()
        for u in G[v]:
            if not d[u]:
                q.append(u)
                d[u] = d[v] + 1


def main():
    global G, DB, DW
    N = int(input())
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    G = [[] for _ in range(N + 1)]
    for v, u in E:
        G[v] += [u]
        G[u] += [v]
    DB, DW = [0] * (N + 1), [0] * (N + 1)
    bfs(1, DB), bfs(N, DW)
    b, w = 0, 0
    for i, j in zip(DB[1:], DW[1:]):
        if i <= j:
            b += 1
        else:
            w += 1
    flg = b > w
    print("Fennec" if flg else "Snuke")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC066C - pushpush (ARC077)
def main():
    N, *A = map(int, open(0).read().split())
    if int(N) & 1:
        B = A[::2][::-1] + A[1::2]
    else:
        B = A[1::2][::-1] + A[::2]
    print(" ".join(B))


if __name__ == "__main__":
    main()

Fixed submission:
# ABC066C - pushpush (ARC077)
from collections import deque

n = int(input())
lst = list(map(int, input().rstrip().split()))
b = deque()
parity = n % 2
for i, j in enumerate(lst, start=1):
    if i % 2 == parity:
        b.appendleft(j)
    else:
        b.append(j)
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC066C - pushpush (ARC077)
n = int(input())
lst = list(map(int, input().rstrip().split()))
b = []
parity = n % 2
for i in lst:
    if i % 2 == parity:
        b = [i] + b
    else:
        b += [i]
print(*b)

Fixed submission:
# ABC066C - pushpush (ARC077)
from collections import deque

n = int(input())
lst = list(map(int, input().rstrip().split()))
b = deque()
parity = n % 2
for i, j in enumerate(lst, start=1):
    if i % 2 == parity:
        b.appendleft(j)
    else:
        b.append(j)
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC066C - pushpush (ARC077)
n = int(input())
lst = list(map(int, input().rstrip().split()))
b = []
for i in lst:
    b += [i]
    b = b[::-1]
print(*b)

Fixed submission:
# ABC066C - pushpush (ARC077)
from collections import deque

n = int(input())
lst = list(map(int, input().rstrip().split()))
b = deque()
parity = n % 2
for i, j in enumerate(lst, start=1):
    if i % 2 == parity:
        b.appendleft(j)
    else:
        b.append(j)
print(*b)
Buggy python submission (verdict: Runtime Error):
# ABC064D - Insertion
def main():
    # count shortages on both sides -> restore
    N = int(input())
    S = input().rstrip()
    l, r = i.count("("), i.count(")")
    ans = "(" * max(0, r - l) + i + ")" * max(0, l - r)
    print(ans)
    


if __name__ == "__main__":
    main()

Fixed submission:
# ABC064D - Insertion
# https://www.hamayanhamayan.com/entry/2017/06/10/224823
def main():
    N = int(input())
    S = input().rstrip()
    cnt, pre = 0, 0
    for i in S:
        if i == "(":
            cnt += 1
        else:
            cnt -= 1
            if cnt < 0:
                pre = max(pre, abs(cnt))
    S = "(" * pre + S
    cnt = 0
    for i in S:
        if i == "(":
            cnt += 1
        else:
            cnt -= 1
    S += ")" * cnt
    print(S)
    


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# AGC015A - A+...+B Problem
import sys
sys.setrecursionlimit(10 ** 9)

from itertools import product


def main():
    n, a, b = tuple(map(int, input().rstrip().split()))
    if a > b or (n == 1 and abs(a - b) > 1):
        print(0)
        return
    if (n == 1 and a == b) or n == 2:
        print(1)
        return
    ans = {sum(i) for i in product(range(a, b + 1), repeat=n - 2)}
    print(len(ans))


if __name__ == "__main__":
    main()

Fixed submission:
# AGC015A - A+...+B Problem
def main():
    n, a, b = tuple(map(int, input().rstrip().split()))
    if a > b or (n == 1 and a != b):
        print(0)
    elif n == 1 and a == b:
        print(1)
    else:
        print((n - 2) * (b - a) + 1)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# AGC015A - A+...+B Problem
from itertools import product


def main():
    n, a, b = tuple(map(int, input().rstrip().split()))
    if a > b or (n == 1 and abs(a - b) > 1):
        print(0)
        return
    if (n == 1 and a == b) or n == 2:
        print(1)
        return
    ans = {sum(i) for i in product(range(a, b + 1), repeat=n - 2)}
    print(len(ans))


if __name__ == "__main__":
    main()

Fixed submission:
# AGC015A - A+...+B Problem
def main():
    n, a, b = tuple(map(int, input().rstrip().split()))
    if a > b or (n == 1 and a != b):
        print(0)
    elif n == 1 and a == b:
        print(1)
    else:
        print((n - 2) * (b - a) + 1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# ABC060C - Sentou (ARC073C)
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, i[0]
for i in lst[1:]:
    ans += min(t, i - cur)
ans += t
print(ans)

Fixed submission:
# ABC060C - Sentou (ARC073C)
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, lst[0]
for i in lst[1:]:
    ans += min(t, i - cur)
    cur = i
ans += t
print(ans)