alexjercan/bugnet huggingface dataset:
Problem p03846 (Python) — buggy submission, verdict: Time Limit Exceeded

import collections

N = int(input())
A = [int(i) for i in input().split()]
ans = 0
di = collections.Counter(A)
if N % 2 != 0:
    num_list = [int(i) for i in range(2, N, 2)]
    for num in num_list:
        if di[num] != 2:
            break
    else:
        if A.count(0) == 1:
            ans = (2 ** (N // 2)) % (10**9 + 7)

else:
    num_list = [int(i) for i in range(1, N, 2)]
    for i in num_list:
        if di[i] != 2:
            break
    else:
        ans = (2 ** (N // 2)) % (10**9 + 7)
print(ans)


Error: TLE

Fixed submission:

N = int(input())
A = [int(i) for i in input().split()]
ans = 0
if N % 2 != 0:
    num_list = [int(i) for i in range(2, N, 2)]
    for num in num_list:
        if A.count(num) != 2:
            break
    else:
        if A.count(0) == 1:
            ans = (2 ** (N // 2)) % (10**7 + 7)

else:
    num_list = [int(i) for i in range(1, N, 2)]
    for num in num_list:
        if A.count(num) != 2:
            break
    else:
        ans = 2 ** (N // 2) % (10**7 + 7)

print(ans)
Problem p03846 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))
C = [0] * N
for a in A:
    C[a] += 1
if N % 2 == 1:
    if C[0] != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if C[i] != 2:
            print(0)
            exit()
    print(2 ** ((N - 1) // 2) % 1000000007)
else:
    for i in range(1, N, 2):
        if C[i] != 2:
            print(0)
            exit()
    print(2 ** (N // 2) % 1000000007)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))
if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    print(2 ** ((N - 1) // 2))
else:
    for i in range(1, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    print(2 ** (N // 2))
Problem p03848 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = [int(i) for i in input().split()]

check = True
A = sorted(A)
if N % 2 == 0:
    for i in range(N):
        if i % 2 == 0 and A[i] != i + 1:
            check = False
        if i % 2 == 1 and A[i] != i:
            check = False

if N % 2 != 0:
    for i in range(N):
        if i % 2 == 0 and A[i] != i:
            check = False
        if i % 2 == 1 and A[i] != i + 1:
            check = False

if check:
    print((2 ** (N // 2)) % (10**9 + 7))
else:
    print(0)


Error: TLE

Fixed submission:

N = int(input())
A = [int(i) for i in input().split()]

if N % 2 == 1:
    for i in range(N // 2):
        if A.count(i * 2) != 2 and i != 0:
            print(0)
            exit()
        if i == 0 and A.count(i) != 1:
            print(0)
            exit()

if N % 2 == 0:
    for i in range(N // 2):
        if A.count(i * 2 + 1) != 2:
            print(0)
            exit()

print(2 ** (N // 2))
Problem p03848 (Python) — buggy submission, verdict: Time Limit Exceeded

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


def solve():
    cnt = {i + (1 - N % 2): 0 for i in range(0, 2 * N // 2, 2)}
    for a in A:
        if a not in cnt:
            return 0

        if N % 2 == 1:
            if a % 2 == 1:
                return 0
            cnt[a] += 1
        else:
            if a % 2 == 0:
                return 0
            cnt[a] += 1

    for key, value in cnt.items():
        if key == 0:
            if value != 1:
                return 0
        else:
            if value != 2:
                return 0

    return 2 ** (N // 2) % (10**9 + 7)


print(solve())


Error: TLE

Fixed submission:

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


def solve():
    for a in A:
        if N % 2 == 1:
            if a % 2 == 1:
                return 0
            else:
                if a == 0 and A.count(a) != 1:
                    return 0
                elif a != 0 and A.count(a) != 2:
                    return 0
        else:
            if a % 2 == 0:
                return 0
            else:
                if A.count(a) != 2:
                    return 0
    return 2 ** (N // 2)


print(solve())
Problem p03852 (Python) — buggy submission, verdict: Runtime Error

c = input()
print("vowel" if c in "aiueo" else "consonant")


Error: ValueError: invalid literal for int() with base 10: 'a'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03852/Python/s125917047.py", line 1, in <module>
    c = int(input())
ValueError: invalid literal for int() with base 10: 'a'


Fixed submission:

c = int(input())
print("vowel" if c in "aiueo" else "consonant")
Problem p03852 (Python) — buggy submission, verdict: Runtime Error

def main():
    print("vowel" if input() in "aeiou" else "consonant")


if __name__ == "__main__":
    main()


Error: ValueError: invalid literal for int() with base 10: 'a'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03852/Python/s011405155.py", line 10, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03852/Python/s011405155.py", line 2, in main
    h, _ = map(int, input().split())
ValueError: invalid literal for int() with base 10: 'a'


Fixed submission:

def main():
    h, _ = map(int, input().split())
    c = [input() for _ in range(h)]
    for cn in c:
        print(cn)
        print(cn)


if __name__ == "__main__":
    main()
Problem p03853 (Python) — buggy submission, verdict: Runtime Error

import sys

H, W = sys.stdin.readline().split()
C = map(str, sys.stdin)
for i in C:
    print(i)
    print(i)


Error: TypeError: '_io.TextIOWrapper' object is not subscriptable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03853/Python/s894840056.py", line 2, in <module>
    for i in C[1:]:
TypeError: '_io.TextIOWrapper' object is not subscriptable


Fixed submission:

C = open(0)
for i in C[1:]:
    print(i)
    print(i)
Problem p03853 (Python) — buggy submission, verdict: Runtime Error

H, W = map(int, input().split())
px = []
ans = []
for x in range(H):
    px.append(input())
    ans.append(px[x])
    ans.append(px[x])

for x in range(len(ans)):
    print(ans[x])


Error: TypeError: 'list' object cannot be interpreted as an integer
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03853/Python/s440756858.py", line 9, in <module>
    for x in range(ans):
TypeError: 'list' object cannot be interpreted as an integer


Fixed submission:

H, W = map(int, input().split())
px = []
ans = []
for x in range(H):
    px.append(input())
    ans.append(px[x])
    ans.append(px[x])

for x in range(ans):
    print(ans[x])
Problem p03854 (Python) — buggy submission, verdict: Time Limit Exceeded

dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[lens - len(dreamer) :] == dreamer:
            S = S[: lens - len(dreamer)]
        elif S[lens - len(eraser) :] == eraser:
            S = S[: lens - len(eraser)]
        elif S[lens - len(dream) :] == dream:
            S = S[: lens - len(dream)]
        elif S[lens - len(erase) :] == erase:
            S = S[: lens - len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()


Error: TLE

Fixed submission:

import re


def main():
    S = input()
    lens = len(S)
    while len(S):
        S = re.sub("dreamer$", "", S)
        S = re.sub("eraser$", "", S)
        S = re.sub("dream$", "", S)
        S = re.sub("erase$", "", S)
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()
Problem p03854 (Python) — buggy submission, verdict: Runtime Error

S = input()

S = S[::-1]

dream = "maerd"
dreamer = "remaerd"
erase = "esare"
eraser = "resare"

if len(S) > 0:
    while len(S) > 0:
        if S.startswith(dream):
            S = S[len(dream) :]
        elif S.startswith(dreamer):
            S = S[len(dreamer) :]
        elif S.startswith(erase):
            S = S[len(erase) :]
        elif S.startswith(eraser):
            S = S[len(eraser) :]
        else:
            break
    if len(S) > 0:
        print("NO")
    else:
        print("YES")

else:
    print("NO")


Error: 0

Fixed submission:

S = input()


def is_composable(s):
    if len(s) == 0:
        return True

    if s.startswith("dreamer"):
        dream_s = s[5:]
        dreamer_s = s[7:]
        return is_composable(dream_s) or is_composable(dreamer_s)
    elif s.startswith("dream"):
        dream_s = s[5:]
        return is_composable(dream_s)
    elif s.startswith("eraser"):
        erase_s = s[5:]
        eraser_s = s[6:]
        return is_composable(erase_s) or is_composable(eraser_s)
    elif s.startswith("erase"):
        erase_s = s[5:]
        return is_composable(erase_s)
    else:
        return False


if len(S) > 0 and is_composable(S):
    print("YES")
else:
    print("NO")
Problem p03854 (Python) — buggy submission, verdict: Time Limit Exceeded

s = input()

dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


while s != "":
    if s.endswith(dreamer):
        s = s[:-7]
    elif s.endswith(eraser):
        s = s[:-6]
    elif s.endswith(dream):
        s = s[:-5]
    elif s.endswith(erase):
        s = s[:-5]
    else:
        print("NO")
        exit()

print("YES")


Error: TLE

Fixed submission:

s = list(input())

dream = list("dream")
dreamer = list("dreamer")
erase = list("erase")
eraser = list("eraser")

s.reverse()
dream.reverse()
dreamer.reverse()
erase.reverse()
eraser.reverse()

while s != []:
    if s[0:7] == dreamer:
        del s[0:7]
    elif s[0:6] == eraser:
        del s[0:6]
    elif s[0:5] == dream:
        del s[0:5]
    elif s[0:5] == erase:
        del s[0:5]
    else:
        print("NO")
        exit()

print("YES")
Problem p03854 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-

S = input()
dream_set = {"dream", "dreamer", "erase", "eraser"}
# 感動的計画法やるぞ

while len(S) > 0:
    if S.endswith("dream") or S.endswith("erase"):
        S = S[:-5]
    elif S.endswith("eraser"):
        S = S[:-6]
    elif S.endswith("dreamer"):
        S = S[:-7]
    else:
        print("NO")
        exit()

print("YES")


Error: ValueError: invalid literal for int() with base 10: 'erasedream'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03854/Python/s693915852.py", line 3, in <module>
    N = int(input())
ValueError: invalid literal for int() with base 10: 'erasedream'


Fixed submission:

# -*- coding: utf-8 -*-

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

ans = 0
new_a = A.copy()
while 1:
    new_a = [a // 2 if a % 2 == 0 else -1 for a in new_a]
    if -1 in new_a:
        print(ans)
        exit()
    ans += 1

print(ans)
Problem p03854 (Python) — buggy submission, verdict: Time Limit Exceeded

dest = input().rstrip("\\n")

suffixes = ["dream", "dreamer", "erase", "eraser"]
cut_lens = [-5, -7, -5, -6]

while True:
    for suffix, cut_len in zip(suffixes, cut_lens):
        if dest.endswith(suffix):
            dest = dest[:cut_len]
            break
    else:
        break

print("YES" if not dest else "NO")


Error: TLE

Fixed submission:

from re import sub

dest = input().rstrip("\\n")

suffixes = ["dream$", "dreamer$", "erase$", "eraser$"]

while True:
    len_before = len(dest)
    for suffix in suffixes:
        dest = sub(suffix, "", dest)
    if len(dest) == len_before:
        break

print("YES" if not dest else "NO")
Problem p03854 (Python) — buggy submission, verdict: Time Limit Exceeded

#!/usr/bin/env python3
import sys

PARTS = ["eraser", "erase", "dreamer", "dream"]
# PARTS2 = []


def main():
    global PARTS2
    sys.setrecursionlimit(100000)
    S = input()

    # for i in range(0, 4):
    #     for j in range(0, 4):
    #         PARTS2.append(PARTS[i] + PARTS[j])

    # PARTS2 = PARTS2 + PARTS

    if judgeStr2(S):
        print("YES")
    else:
        print("NO")


def judgeStr2(target: str) -> bool:
    currentStr = target
    while currentStr != "":
        isNextOK = False
        for item in PARTS:
            if not currentStr.startswith(item):
                continue

            tempStr = currentStr.replace(item, "", 1)
            if tempStr == "":
                return True

            for item2 in PARTS:
                if tempStr.startswith(item2):
                    isNextOK = True
                    break

            if isNextOK:
                currentStr = tempStr
                break
        if isNextOK:
            continue
        else:
            break
    return currentStr == ""


def judgeStr(target: str) -> bool:
    for item in PARTS:
        if target.startswith(item):
            tempStr = target.replace(item, "", 1)
            if tempStr == "" or judgeStr(tempStr):
                return True

    return False


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

#!/usr/bin/env python3
import sys

PARTS = ["eraser", "erase", "dreamer", "dream"]
PARTS2 = []


def main():
    global PARTS2
    sys.setrecursionlimit(100000)
    S = input()

    for i in range(0, 4):
        for j in range(0, 4):
            PARTS2.append(PARTS[i] + PARTS[j])

    PARTS2 = PARTS2 + PARTS

    if judgeStr(S):
        print("YES")
    else:
        print("NO")


def judgeStr(target: str) -> bool:
    for item in PARTS2:
        if target.startswith(item):
            tempStr = target.replace(item, "", 1)
            if tempStr == "" or judgeStr(tempStr):
                return True

    return False


if __name__ == "__main__":
    main()
Problem p03855 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import defaultdict
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def root(par, x):
    if par[x] == x:
        return x
    else:
        return root(par, par[x])


def unite(rank, par, x, y):
    x = root(par, x)
    y = root(par, y)

    if x == y:
        return

    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1


def main():
    N, K, L = map(int, readline().split())
    m = map(int, read().split())
    pq = list(zip(m, m))
    pq, rs = pq[:K], pq[K:]

    par = list(range(N))
    rank = [0] * N
    for p, q in pq:
        p -= 1
        q -= 1
        unite(rank, par, p, q)

    par_t = list(range(N))
    rank_t = [0] * N
    for r, s in rs:
        r -= 1
        s -= 1
        unite(rank_t, par_t, r, s)

    pp = [(0, 0)] * N
    dd = defaultdict(list)
    for i in range(N):
        par[i] = root(par, i)
        par_t[i] = root(par_t, i)
        pp[i] = (par[i], par_t[i])
        dd[pp[i]].append(i)

    cnt = [0] * N
    for i in range(N):
        cnt[i] = len(dd[pp[i]])

    print(*cnt)


main()


Error: TLE

Fixed submission:

from collections import defaultdict
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def root(par, x):
    if par[x] == x:
        return x
    else:
        return root(par, par[x])


def unite(rank, par, x, y):
    x = root(par, x)
    y = root(par, y)

    if x == y:
        return

    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1


def main():
    N, K, L = map(int, readline().split())
    m = map(int, read().split())
    pq = list(zip(m, m))
    pq, rs = pq[:K], pq[K:]

    d_c = defaultdict(list)
    d_t = defaultdict(list)

    par = list(range(N))
    rank = [0] * N
    for p, q in pq:
        p -= 1
        q -= 1
        unite(rank, par, p, q)

    par_t = list(range(N))
    rank_t = [0] * N
    for r, s in rs:
        r -= 1
        s -= 1
        unite(rank_t, par_t, r, s)

    for i in range(N):
        par[i] = root(par, i)
        par_t[i] = root(par_t, i)
        d_c[par[i]].append(i)
        d_t[par_t[i]].append(i)

    for i in range(N):
        d_c[i] = d_c[par[i]]
        d_t[i] = d_t[par_t[i]]

    cnt = [0] * N
    for i in range(N):
        cnt[i] = len(list(set(d_c[i]) & set(d_t[i])))

    print(*cnt)


main()
Problem p03857 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import defaultdict


class UnionFind3:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.root(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2


n, k, l = map(int, input().split())
ufd, ufr = UnionFind3(n), UnionFind3(n)
for _ in range(k):
    p, q = map(int, input().split())
    ufd.union(p - 1, q - 1)
for _ in range(l):
    r, s = map(int, input().split())
    ufr.union(r - 1, s - 1)
d = defaultdict(int)
for i in range(n):
    d[ufd.root(i), ufr.root(i)] += 1
print(*(d[ufd.root(i), ufr.root(i)] for i in range(n)))


Error: TLE

Fixed submission:

class UnionFind3:
    def __init__(self, size):
        # 負の値はルート (集合の代表) で集合の個数
        # 正の値は次の要素を表す
        self.table = [-1 for _ in range(size)]

    # 集合の代表を求める
    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    # 併合
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                # 小さいほうが個数が多い
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False


n, k, l = map(int, input().split())
ufd, ufr = UnionFind3(n), UnionFind3(n)
for _ in range(k):
    p, q = map(int, input().split())
    ufd.union(p - 1, q - 1)
for _ in range(l):
    r, s = map(int, input().split())
    ufr.union(r - 1, s - 1)
result = [1] * n
for i in range(n):
    for j in range(i + 1, n):
        if ufd.find(i) == ufd.find(j) and ufr.find(i) == ufr.find(j):
            result[i] += 1
            result[j] += 1
print(*result)
Problem p03860 (Python) — buggy submission, verdict: Runtime Error

[print(i[0], end="") for i in input().split()]
print()


Error: ValueError: too many values to unpack (expected 3)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03860/Python/s197123700.py", line 1, in <module>
    a, b, c = str(input().split())
ValueError: too many values to unpack (expected 3)


Fixed submission:

a, b, c = str(input().split())
print(a[0], b[0], c[0])
Problem p03860 (Python) — buggy submission, verdict: Runtime Error

a, s, c = map(str, input().split())
print(a[0] + s[0] + c[0])


Error: ValueError: invalid literal for int() with base 10: 'AtCoder'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03860/Python/s937750481.py", line 1, in <module>
    a, s, c = map(int, input().split())
ValueError: invalid literal for int() with base 10: 'AtCoder'


Fixed submission:

a, s, c = map(int, input().split())
print(a[0] + s[0] + c[0])
Problem p03860 (Python) — buggy submission, verdict: Runtime Error

a, b, c = map(str, input().split())
print(a[0] + b[0] + c[0])


Error: ValueError: invalid literal for int() with base 10: 'AtCoder'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03860/Python/s356083073.py", line 1, in <module>
    a, b, c = map(int, input().split())
ValueError: invalid literal for int() with base 10: 'AtCoder'


Fixed submission:

a, b, c = map(int, input().split())
print(a[0] + b[0] + c[0])
Problem p03860 (Python) — buggy submission, verdict: Runtime Error

S = input().split()
ans = f"A{S[1][0]}C"
print(ans)


Error: ValueError: invalid literal for int() with base 10: 'AtCoder'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03860/Python/s510991095.py", line 1, in <module>
    N, x = map(int, input().split())
ValueError: invalid literal for int() with base 10: 'AtCoder'


Fixed submission:

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

if len(A) % 2 == 0:
    A = A + [0]
# print('A', A)

ans = 0
for i in range(1, N, 2):
    total = A[i - 1] + A[i]
    diff = total - x
    if diff <= 0:
        continue
    v1 = min(A[i], diff)
    v2 = diff - v1
    A[i] -= v1
    A[i - 1] -= v2
    ans += v1 + v2
    # print('A', A)
print(ans)
Problem p03861 (Python) — buggy submission, verdict: Time Limit Exceeded

a, b, x = [int(n) for n in input().split()]

qa = a // x
qb = b // x
ra = a % x
rb = b % x
res = qb - qa
if ra == 0:
    res += 1

print(res)


Error: TLE

Fixed submission:

a, b, x = [int(n) for n in input().split()]

res = 0
for n in range(a, b + 1):
    if n % x == 0:
        res += 1
print(res)
Problem p03861 (Python) — buggy submission, verdict: Time Limit Exceeded

a, b, x = map(int, input().split())


ans = b // x - (a - 1) // x


print(ans)


Error: TLE

Fixed submission:

a, b, x = map(int, input().split())

ans = 0
for i in range(a, b + 1):
    if i % x == 0:
        ans += 1

print(ans)
Problem p03861 (Python) — buggy submission, verdict: Runtime Error

a, b, x = map(int, input().split())
print(b // x - (a - 1) // x)


Error: WA

Fixed submission:

a, b, x = map(int, input().split())

if x % a == 0:
    print((b - a + 1) // x + 1)
else:
    print((b - a + 1) // x)
Problem p03861 (Python) — buggy submission, verdict: Time Limit Exceeded

a, b, x = tuple(int(x) for x in input().split())

if a == 0:
    y = 0
else:
    y = x * ((a - 1) // x + 1)


if y == -1:
    ans = 0
else:
    ans = (b - y) // x + 1

print(ans)


Error: TLE

Fixed submission:

a, b, x = tuple(int(x) for x in input().split())

y = -1
for i in range(a, b + 1):
    if i % x == 0:
        y = i
        break

if y == -1:
    ans = 0
else:
    ans = (b - y) // x + 1

print(ans)
Problem p03861 (Python) — buggy submission, verdict: Time Limit Exceeded

a, b, x = map(int, input().split())
if a == 0:
    print(b // x + 1)
else:
    print((b // x) - ((a - 1) // x))


Error: TLE

Fixed submission:

a, b, x = map(int, input().split())
while b % x:
    b -= 1
if a == 0:
    print(b // x + 1)
else:
    print((b // x) - ((a - 1) // x))
Problem p03861 (Python) — buggy submission, verdict: Time Limit Exceeded

a, b, x = map(int, input().split())
print(b // x - (a - 1) // x)


Error: TLE

Fixed submission:

a, b, x = map(int, input().split())
int_list = [i for i in range(a, b + 1)]
counter = 0
for i in range(len(int_list)):
    if int_list[i] % x == 0:
        counter += 1

print(counter)
Problem p03861 (Python) — buggy submission, verdict: Time Limit Exceeded

a, b, x = map(int, input().split())

start = 0
end = b
if a > x:
    if a % x == 0:
        start = a
    else:
        start = x * (a // x + 1)
else:
    start = x

if start > end:
    result = 0
else:
    result = (end - start) // x + 1
if a == 0:
    result += 1
print(result)


Error: TLE

Fixed submission:

a, b, x = map(int, input().split())

start = a if a >= x else x
end = b
while start <= end:
    if start % x == 0:
        break
    if start == end:
        print(0)
        exit()
    start += 1

result = (end - start) // x + 1
if a == 0:
    result += 1
print(result)