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

import sys

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
C = list(map(int, input().split()))
LR = []
for i in range(q):
    l, r = map(int, input().split())
    LR.append((l, r, i))
LR.sort(key=lambda x: x[1])


BIT = [0] * (n + 1)


def update(idx, val):
    while idx <= n:
        BIT[idx] += val
        idx += idx & (-idx)


def query(idx):
    res = 0
    while idx > 0:
        res += BIT[idx]
        idx -= idx & (-idx)
    return res


pos = [-1] * (n + 1)


def func(idx):
    temp = C[idx]
    if pos[temp] == -1:
        pos[temp] = idx + 1
        update(idx + 1, 1)
    else:
        pre = pos[temp]
        pos[temp] = idx + 1
        update(pre, -1)
        update(idx + 1, 1)


ans = [0] * (q)
idx = 0
for i in range(q):
    l, r, ans_num = LR[i]
    # l,rは0-indexに戻す
    l -= 1
    r -= 1
    while idx < r + 1:  # rになるまで増やす
        if idx < n:  # n超えないように注意
            func(idx)
            idx += 1
        else:
            break
    res = 0
    res += query(r + 1)
    if l > 0:
        res -= query(l)
    ans[ans_num] = res

print(*ans, sep="\\n")


Error: TLE

Fixed submission:

import sys

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
C = list(map(int, input().split()))


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
    return c


num = 2 ** ((n - 1).bit_length())
SEG = [0] * (2 * num)


def func(a, b):
    return a | b


for idx, val in enumerate(C):
    idx += num
    SEG[idx] = 1 << (val - 1)
    while idx > 0:
        idx //= 2
        SEG[idx] = func(SEG[2 * idx], SEG[2 * idx + 1])


def query(left, right):
    resleft = 0
    resright = 0
    left += num
    right += num
    while right - left > 0:
        if left % 2 == 1:
            resleft = func(resleft, SEG[left])
            left += 1
        if right % 2 == 1:
            right -= 1
            resright = func(resright, SEG[right])
        left //= 2
        right //= 2
    return func(resleft, resright)


for _ in range(q):
    l, r = map(int, input().split())
    temp = query(l - 1, r)
    print(popcnt(temp))
Problem p02599 (Python) — buggy submission, verdict: Time Limit Exceeded

# cattuper's solution
import sys

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
c = list(map(int, input().split()))
l = [0] * q
r = [0] * q

queries = [[] for _ in range(n)]
rights = [[] for _ in range(n)]
for i in range(q):
    l[i], r[i] = map(int, input().split())
    l[i] -= 1
    queries[l[i]].append(i)

last_app = [-1] * (n + 1)
for i in range(n):
    if last_app[c[i]] != -1:
        last = last_app[c[i]]
        rights[last].append(i)
    last_app[c[i]] = i


ans = [0] * q

seg = [0] * (1 << 20)


def add(x):
    x += 1 << 19
    while x:
        seg[x] += 1
        x = x // 2


def sum_of(l, r):
    l += 1 << 19
    r += 1 << 19
    ans = 0
    while l < r:
        if l % 2 == 1:
            ans += seg[l]
            l += 1
        if r % 2 == 1:
            ans += seg[r - 1]
            r -= 1
        l //= 2
        r //= 2
    return ans


for i in range(n - 1, -1, -1):
    for right in rights[i]:
        add(right)
    for q_ind in queries[i]:
        left = l[q_ind]
        right = r[q_ind]
        ans[q_ind] = (right - left) - sum_of(left, right)

for i in range(q):
    print(ans[i])


Error: TLE

Fixed submission:

import sys

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
C = list(map(int, input().split()))


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
    return c


num = 2 ** ((n - 1).bit_length())
SEG = [0] * (2 * num)


def func(a, b):
    return a | b


for idx, val in enumerate(C):
    idx += num
    SEG[idx] = 1 << (val - 1)
for idx in range(num - 1, 0, -1):
    while idx > 0:
        SEG[idx] = func(SEG[2 * idx], SEG[2 * idx + 1])
        idx //= 2


def query(left, right):
    resleft = 0
    resright = 0
    left += num
    right += num
    while right - left > 0:
        if left % 2 == 1:
            resleft = func(resleft, SEG[left])
            left += 1
        if right % 2 == 1:
            right -= 1
            resright = func(resright, SEG[right])
        left //= 2
        right //= 2
    return func(resleft, resright)


for _ in range(q):
    l, r = map(int, input().split())
    temp = query(l - 1, r)
    print(popcnt(temp))
Problem p02600 (Python) — buggy submission, verdict: Runtime Error

X = int(input())

if 400 <= X < 600:
    result = 8
elif X < 800:
    result = 7
elif X < 1000:
    result = 6
elif X < 1200:
    result = 5
elif X < 1400:
    result = 4
elif X < 1600:
    result = 3
elif X < 1800:
    result = 2
elif X < 2000:
    result = 1

print(result)


Error: 0

Fixed submission:

X = int(input())

if 400 <= X < 600:
    result = 8
elif X < 800:
    result = 7
elif X < 1000:
    result = 6
elif X < 1200:
    result = 5
elif X < 1400:
    result = 4
elif X < 1600:
    result = 3
elif X < 1800:
    result = 2
elif X < 200:
    result = 1

print(result)
Problem p02601 (Python) — buggy submission, verdict: Time Limit Exceeded

A, B, C = map(int, input().split())
K = int(input())

for i in range(K):
    if B <= A:
        B *= 2
    else:
        if C <= B:
            C *= 2

if A < B < C:
    print("Yes")
else:
    print("No")


Error: TLE

Fixed submission:

A, B, C = map(int, input().split())
K = int(input())

i = 0
while i < K:
    if B <= A:
        B *= 2
        i += 1
    else:
        if C <= B:
            C *= 2
            i += 1

if A < B < C:
    print("Yes")
else:
    print("No")
Problem p02601 (Python) — buggy submission, verdict: Time Limit Exceeded

A, B, C = map(int, input().split())
K = int(input())

while K > 0:
    if A >= B:
        B *= 2
        K -= 1
    elif B >= C:
        C *= 2
        K -= 1
    if C > B and B > A:
        break
if C > B and B > A:
    print("Yes")
else:
    print("No")


Error: TLE

Fixed submission:

A, B, C = map(int, input().split())
K = int(input())

while K > 0:
    if A >= B:
        B *= 2
        K -= 1
    elif B >= C:
        C *= 2
        K -= 1
if C > B and B > A:
    print("Yes")
else:
    print("No")
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

N, K = [int(x) for x in input().split(" ")]
A = [int(x) for x in input().split(" ")]


for i in range(K, N):
    if A[i - K] < A[i]:
        print("Yes")
    else:
        print("No")


Error: TLE

Fixed submission:

import itertools
import operator

N, K = [int(x) for x in input().split(" ")]
A = [int(x) for x in input().split(" ")]

pro = [1] + list(itertools.accumulate(A, func=operator.mul))

for i in range(K + 1, N + 1):
    if pro[i] * pro[i - K - 1] > pro[i - K] * (pro[i - 1]):
        print("Yes")
    else:
        print("No")
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a_array = input_to_int_tuple()

    for k_val, pre_k_val in zip(a_array[k:], a_array[k - k :]):
        if k_val > pre_k_val:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a_array = input_to_int_tuple()

    temp = [1]
    val = 1
    for a in a_array:
        val *= a
        temp.append(val)

    pre_k_val = temp[k + 1 - 1]
    ini_pre_k_val = temp[k + 1 - 1 - k]
    pre_k_val /= ini_pre_k_val
    for i in range(k + 1, n + 1):
        k_val = temp[i]
        ini_k_val = temp[i - k]
        k_val /= ini_k_val

        if pre_k_val < k_val:
            print("Yes")
        else:
            print("No")

        pre_k_val = k_val


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

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

for i in range(k, n):
    if a[i - k] < a[i]:
        print("Yes")
    else:
        print("No")


Error: TLE

Fixed submission:

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

score: list = []
for i in range(k - 1, n):
    tmp_score = 1
    for j in range(k):
        tmp_score *= a[i - j]
    score.append(tmp_score)

for i in range(len(score) - 1):
    # print(score[i], score[i + 1])
    if score[i + 1] > score[i]:
        print("Yes")
    else:
        print("No")
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

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

for i in range(k, n):
    if a[i - k] < a[i]:
        print("Yes")
    else:
        print("No")


Error: TLE

Fixed submission:

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

result = 1

for i in range(k):
    result *= a[k - i]

for i in range(k, n):
    before_result = result
    result /= a[i - k]
    result *= a[i]
    if before_result < result:
        print("Yes")
    else:
        print("No")
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

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

a_lst = list(map(int, input().split(" ")))

for i in range(k, n):
    if a_lst[i] > a_lst[i - k]:
        print("Yes")
    else:
        print("No")


Error: TLE

Fixed submission:

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

a_lst = list(map(int, input().split(" ")))

# previousの値を取っておいて真に掛け算した評定が高かったかを判定
previous = 1
for i in range(k):
    previous *= a_lst[i]
for i in range(k, n):
    now = previous / a_lst[i - k] * a_lst[i]
    if now > previous:
        print("Yes")
    else:
        print("No")
    previous = now
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

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

    for j in range(k + 1, n + 1):
        if A[j - k - 1] < A[j - 1]:
            print("Yes")
        else:
            print("No")


solve()


Error: TLE

Fixed submission:

def solve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    tmp = 1
    for i in range(k):
        tmp *= A[i]

    for j in range(k + 1, n + 1):
        x = tmp * 1
        tmp //= A[j - k - 1]
        tmp *= A[j - 1]
        if tmp > x:
            print("Yes")
        else:
            print("No")


solve()
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
a = list(map(int, input().split()))
score = sum(a[:k])
top = 0
for i in range(k, n):
    if a[i] > a[top]:
        print("Yes")
    else:
        print("No")
    top += 1


Error: TLE

Fixed submission:

n, k = map(int, input().split())
a = list(map(int, input().split()))
score = 1
for i in range(k):
    score *= a[i]
top = 0
for i in range(k, n):
    pre_score = score
    score /= a[top]
    top += 1
    score *= a[i]
    if score > pre_score:
        print("Yes")
    else:
        print("No")
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
a = list(map(int, input().split()))
ma = min(a)

a = list(map(lambda x: x - ma, a))

befscore = 1
score = 1
f = True
for i in range(n):
    score = score + a[i]

    if i >= k:
        score = int(score - a[i - k])
        if befscore >= score:
            print("No")
        else:
            print("Yes")

    befscore = score


Error: TLE

Fixed submission:

n, k = map(int, input().split())
a = list(map(int, input().split()))
ma = min(a)

a = list(map(lambda x: x - ma + 1, a))

befscore = 1
score = 1
f = True
for i in range(n):
    score = score * a[i]

    if i >= k:
        score = int(score / a[i - k])
        if befscore >= score:
            print("No")
        else:
            print("Yes")

    befscore = score
Problem p02602 (Python) — buggy submission, verdict: Runtime Error

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

res = list()

for i in range(k, n):
    if a[i - k] < a[i]:
        res.append("Yes")
    else:
        res.append("No")

for r in res:
    print(r)


Error: TLE

Fixed submission:

import numpy as np

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

res = list()

res.append(np.prod(a[:k]))
tmp = res[0]

for i in range(k, n):
    tmp /= a[i - k]
    tmp *= a[i]
    res.append(tmp)

for i in range(1, n - k + 1):
    if res[i - 1] < res[i]:
        print("Yes")
    else:
        print("No")
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

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

for j in range(n - k):
    if A[k + j] > A[j]:
        print("Yes")
    else:
        print("No")


Error: TLE

Fixed submission:

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

for i in range(k):
    keep *= A[i]


for j in range(n - k):
    if A[k + j] > A[j]:
        print("Yes")
    else:
        print("No")
    keep = keep * A[k + j] / A[j]
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

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

for i in range(N - K):
    if A[K + i] > A[i]:
        print("Yes")
    else:
        print("No")


Error: TLE

Fixed submission:

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

c = 1
for i in range(K):
    c *= A[i]

C = c
for i in range(0, N - K):
    c //= A[i]
    c *= A[K + i]

    if c > C:
        print("Yes")
    else:
        print("No")
    C = c
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

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

for i in range(n - k):
    if a_list[i] < a_list[i + k]:
        print("Yes")
    else:
        print("No")


Error: TLE

Fixed submission:

n, k = map(int, input().split())
a_list = list(map(int, input().split()))
prev = 1

for i in range(n - k + 1):
    score = 1
    for j in range(k):
        score *= a_list[i + j]
    if i != 0:
        if prev < score:
            print("Yes")
        else:
            print("No")
    prev = score
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

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

for i in range(n - k):
    if a[k + i] > a[i]:
        print("Yes")
    else:
        print("No")


Error: TLE

Fixed submission:

n, k = map(int, input().split())
a = list(map(int, input().split()))
score = 1
for j in range(k):
    score *= a[j]

for i in range(n - k):
    score2 = score / a[i] * a[k + i]
    if score2 > score:
        print("Yes")
    else:
        print("No")
    score = score2
Problem p02602 (Python) — buggy submission, verdict: Time Limit Exceeded

# vim: fileencoding=utf-8


def main():
    n, k = map(int, input().split())
    aList = list(map(int, input().split()))
    hyoukaList = []
    c = 1
    for i in range(n):
        if i < k:
            continue
        b = aList[i - k]
        a = aList[i]

        if b < a:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

# vim: fileencoding=utf-8


def main():
    n, k = map(int, input().split())
    aList = list(map(int, input().split()))
    hyoukaList = []
    c = 1
    for i in aList:
        hyoukaList.append(i)
        b = hyoukaList[0]

        if c <= k:
            c += 1
            continue

        hyoukaList = hyoukaList[1:]
        if b < i:
            print("Yes")
        else:
            print("No")


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

from collections import deque

n, k = map(int, input().split())
a = list(map(int, input().split()))
queue = deque()
for i in range(n):
    if i <= k - 1:
        queue.append(a[i])
    elif i >= k:
        x = queue.popleft()
        if x < a[i]:
            print("Yes")
        else:
            print("No")
        queue.append(a[i])


Error: 0

Fixed submission:

from collections import deque

n, k = map(int, input().split())
a = list(map(int, input().split()))
queue = deque()
for i in range(n):
    if i < k - 1:
        queue.append(a[i])
    elif i >= k:
        x = queue.popleft()
        if x < a[i]:
            print("Yes")
        else:
            print("No")
        queue.append(a[i])
Problem p02603 (Python) — buggy submission, verdict: Time Limit Exceeded

from typing import List


def solve(A: List[int], N: int) -> int:
    current_money = 1000
    for i in range(N - 1):
        stocks = 0

        if A[i] < A[i + 1]:
            stocks = current_money // A[i]
        current_money += (A[i + 1] - A[i]) * stocks
    return current_money


def main():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

    print(solve(A, N))


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

import threading
import sys
import functools


def main():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

    @functools.lru_cache(maxsize=None)
    def solve(stock: int, money: int, day: int, end_day: int) -> int:
        if end_day == day:
            return money

        current_price = A[day]

        money_buy = money - (money // current_price) * current_price
        stock_buy = (money // current_price) + stock

        money_sell = money + stock * current_price
        stock_sell = 0

        return max(
            solve(stock, money, day + 1, end_day),
            solve(stock_buy, money_buy, day + 1, end_day),
            solve(stock_sell, money_sell, day + 1, end_day),
        )

    print(solve(0, 1000, 0, N))


if __name__ == "__main__":

    sys.setrecursionlimit(1024 * 1024 * 2)
    threading.stack_size(128 * 1024 * 1024 * 2)
    threading.Thread(target=main).start()
Problem p02603 (Python) — buggy submission, verdict: Runtime Error

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

money = 1000
ticket = 0
for i in range(N - 1):
    # buy
    if A[i] < A[i + 1]:
        ticket += money // A[i]
        money -= (money // A[i]) * A[i]
    elif A[i] == A[i + 1]:
        pass
    # sell
    else:
        money += A[i] * ticket
        ticket = 0

money += A[-1] * ticket

print(money)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02603/Python/s130468405.py", line 8, in <module>
    if A[i] < A[i + 1]:
IndexError: list index out of range


Fixed submission:

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

money = 1000
ticket = 0
for i in range(N):
    # buy
    if A[i] < A[i + 1]:
        money -= (money // A[i]) * A[i]
        ticket += money // A[i]
    elif A[i] == A[i + 1]:
        pass
    # sell
    else:
        money += A[i] * ticket
        ticket = 0
Problem p02603 (Python) — buggy submission, verdict: Runtime Error

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

money = 1000
stock = 0
for i in range(n):
    # 売る
    money += stock * a[i]
    stock = 0

    # 買う
    if i != n - 1 and a[i] < a[i + 1]:
        stock = money // a[i]
        money %= a[i]

print(money)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02603/Python/s929174190.py", line 10, in <module>
    if a[i] < a[i + 1]:
IndexError: list index out of range


Fixed submission:

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

money = 1000
stock = 0
for i in range(n):
    money += stock * a[i]
    stock = 0

    if a[i] < a[i + 1]:
        stock = money // a[i]
        money %= a[i]

print(money)
Problem p02607 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(0, n, 2):
    if a[i] % 2 != 0:
        res += 1

print(res)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02607/Python/s671759343.py", line 5, in <module>
    if a[i] % 2 != 0:
IndexError: list index out of range


Fixed submission:

n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(1, n + 1, 2):
    if a[i] % 2 != 0:
        res += 1

print(res)
Problem p02608 (Python) — buggy 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):
            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)


Error: TLE

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):
            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)
Problem p02608 (Python) — buggy submission, verdict: Time Limit Exceeded

import math

n = int(input())
ans = [0] * n

for i in range(1, int(math.sqrt(n))):
    for j in range(1, i + 1):
        for k in range(1, j + 1):
            fn = i * i + j * j + k * k + i * j + j * k + k * i
            if fn > n:
                break
            if i != j and j != k and k != i:
                ans[fn - 1] += 6
            elif i == j and j == k:
                ans[fn - 1] += 1
            else:
                ans[fn - 1] += 3

for i in range(n):
    print(ans[i])


Error: TLE

Fixed submission:

n = int(input())
ans = [0] * n

for i in range(1, n):
    for j in range(1, n):
        for k in range(1, n):
            fn = i * i + j * j + k * k + i * j + j * k + k * i
            if fn > n:
                break
            ans[fn - 1] += 1

for i in range(n):
    print(ans[i])