Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().strip().split())
result = 0
num = N // K
result += num
if num == 2:
    result += num * (num - 1) * 3
elif num > 2:
    result += num * (num - 1) * 3
    result += num * (num - 1) * (num - 2)


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    for a in range(start, N + 1, K):
        for b in range(a, N + 1, K):
            for c in range(b, N + 1, K):
                if a == b and b == c:
                    result += 1
                elif a == b or b == c:
                    result += 3
                else:
                    result += 6
    print(result)

Fixed submission:
N, K = map(int, input().strip().split())
result = 0
num = N // K
result += num
if num == 2:
    result += num * (num - 1) * 3
elif num > 2:
    result += num * (num - 1) * 3
    result += num * (num - 1) * (num - 2)


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    num = (N - start) // K + 1
    result += num
    if num == 2:
        result += num * (num - 1) * 3
    elif num > 2:
        result += num * (num - 1) * 3
        result += num * (num - 1) * (num - 2)
    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().strip().split())
result = 0
for a in range(K, N+1, K):
    for b in range(a, N + 1, K):
        for c in range(b, N + 1, K):
            if a == b and b == c:
                result += 1
            elif a == b or b == c:
                result += 3
            else:
                result += 6

if K % 2 == 1:
    print(result)
else:
    start = K // 2
    for a in range(start, N + 1, K):
        for b in range(a, N + 1, K):
            for c in range(b, N + 1, K):
                if a == b and b == c:
                    result += 1
                elif a == b or b == c:
                    result += 3
                else:
                    result += 6
    print(result)

Fixed submission:
N, K = map(int, input().strip().split())
result = 0
num = N // K
result += num
if num == 2:
    result += num * (num - 1) * 3
elif num > 2:
    result += num * (num - 1) * 3
    result += num * (num - 1) * (num - 2)


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    num = (N - start) // K + 1
    result += num
    if num == 2:
        result += num * (num - 1) * 3
    elif num > 2:
        result += num * (num - 1) * 3
        result += num * (num - 1) * (num - 2)
    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().strip().split())
result = 0
for a in range(K, N+1, K):
    for b in range(a, N + 1, K):
        for c in range(b, N + 1, K):
            if a == b and b == c:
                result += 1
            elif a == b or a == c or b == c:
                result += 3
            else:
                result += 6


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    for a in range(start, N + 1, K):
        for b in range(a, N + 1, K):
            for c in range(b, N + 1, K):
                if a == b and b == c:
                    result += 1
                elif a == b or a == c or b == c:
                    result += 3
                else:
                    result += 6
    print(result)

Fixed submission:
N, K = map(int, input().strip().split())
result = 0
num = N // K
result += num
if num == 2:
    result += num * (num - 1) * 3
elif num > 2:
    result += num * (num - 1) * 3
    result += num * (num - 1) * (num - 2)


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    num = (N - start) // K + 1
    result += num
    if num == 2:
        result += num * (num - 1) * 3
    elif num > 2:
        result += num * (num - 1) * 3
        result += num * (num - 1) * (num - 2)
    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().strip().split())
count = set()
for a in range(K, N+1, K):
    for b in range(K, N + 1, K):
        for c in range(K, N + 1, K):
            count.add((a, b, c))

if K % 2 == 1:
    print(len(count))
else:
    start = K // 2
    for a in range(start, N + 1, K):
        for b in range(start, N + 1, K):
            for c in range(start, N + 1, K):
                count.add((a, b, c))
    print(len(count))

Fixed submission:
N, K = map(int, input().strip().split())
result = 0
num = N // K
result += num
if num == 2:
    result += num * (num - 1) * 3
elif num > 2:
    result += num * (num - 1) * 3
    result += num * (num - 1) * (num - 2)


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    num = (N - start) // K + 1
    result += num
    if num == 2:
        result += num * (num - 1) * 3
    elif num > 2:
        result += num * (num - 1) * 3
        result += num * (num - 1) * (num - 2)
    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().strip().split())
count = set()
for a in range(1, N+1):
    if a % K == 0:
        for b in range(K, N + 1, K):
            for c in range(K, N + 1, K):
                count.add((a, b, c))
    else:
        start = K - a % K
        for b in range(start, N + 1, K):
            for c in range(start, N + 1, K):
                if (b + c) % K == 0:
                    count.add((a, b, c))
print(len(count))

Fixed submission:
N, K = map(int, input().strip().split())
result = 0
num = N // K
result += num
if num == 2:
    result += num * (num - 1) * 3
elif num > 2:
    result += num * (num - 1) * 3
    result += num * (num - 1) * (num - 2)


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    num = (N - start) // K + 1
    result += num
    if num == 2:
        result += num * (num - 1) * 3
    elif num > 2:
        result += num * (num - 1) * 3
        result += num * (num - 1) * (num - 2)
    print(result)