Problem:


Score : 300 points

Problem Statement

You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.
The order of a,b,c does matter, and some of them can be the same.

Constraints

1 \leq N,K \leq 2\times 10^5

N and K are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.

Sample Input 1

3 2

Sample Output 1

9

(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.

Sample Input 2

5 3

Sample Output 2

1

Sample Input 3

31415 9265

Sample Output 3

27

Sample Input 4

35897 932

Sample Output 4

114191



Sample input:
3 2


Sample output:
9

Submission status: Time Limit Exceeded

Solution code:
# abc108_c.py
# https://atcoder.jp/contests/abc108/tasks/arc102_a

# C - Triangular Relationship /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 整数 N,Kが与えられます。
# N 以下の正の整数の組 (a,b,c) であって、a+b,b+c,c+a がすべて K の倍数であるようなものの個数を求めてください。 
# ただし、a,b,c の順番を入れ替えただけの組も異なるものとして数えます。また、a,b,cの中に同じものがあっても構いません。

# 制約
#     1≤N,K≤2×10^5
#     N,Kは整数である

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N K

# 出力
# N以下の正の整数の組 (a,b,c) であって、a+b,b+c,c+a がすべて Kの倍数であるようなものの個数を出力せよ。

# 入力例 1
# 3 2

# 出力例 1
# 9

# (1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1),(3,3,3)が条件を満たします。

# 入力例 2
# 5 3

# 出力例 2
# 1

# 入力例 3
# 31415 9265

# 出力例 3
# 27

# 入力例 4
# 35897 932

# 出力例 4
# 114191


def calculation(lines):
    # N = int(lines[0])
    N, K = list(map(int, lines[0].split()))
    if K % 2 == 0:
        k = int(K/2)
    else:
        k = K
    x, y = divmod(N, k)
    cnt = 0
    for a in range(x):
        for b in range(x):
            for c in range(x):
                if k == K:
                    cnt += 1
                else:
                    if (a+b)*k % K == 0 and (b+c)*k % K == 0 and (c+a)*k % K == 0:
                        cnt += 1
    # for a in range(1, N+1):
    #     print(f'a=[{str(a)}]')
    #     if a % k == 0:
    #         for b in range(1, N+1):
    #             if b % k == 0:
    #                 for c in range(1, N+1):
    #                     if c % k == 0:
    #                         if k == K:
    #                             cnt += 1
    #                         else:
    #                             if (a+b) % K == 0 and (b+c) % K == 0 and (c+a) % K == 0:
    #                                 cnt += 1
    #                             # if (a+b) % K != 0:
    #                             #     pass
    #                             # elif (b+c) % K != 0:
    #                             #     pass
    #                             # elif (c+a) % K != 0:
    #                             #     pass
    #                             # else:
    #                             #     cnt += 1
    return [cnt]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 2']
        lines_export = [9]
    if pattern == 2:
        lines_input = ['5 3']
        lines_export = [1]
    if pattern == 3:
        lines_input = ['31415 9265']
        lines_export = [27]
    if pattern == 4:
        lines_input = ['35897 932']
        lines_export = [114191]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N,K = map(int, input().split())
#Kの倍数（２N以下）⓵
multip_K =[i for i in range(0,2*N+1,K)]
#multip_K =multip[K::K]

#2数の和が上記⓵ ⇒a,bの候補探す
from collections import defaultdict
ad =defaultdict(list)
ad_set =set()
for i in multip_K:
    for j in range(1,N+1):
        if 0 < i-j <=N:
            ad[i].append((j,i-j))
            ad_set.add((j,i-j))

#cを探す
count =0

for i in range(1,N+1):
    for ab in ad.values():
        for abc in ab:
            if (abc[0],i) in ad_set and (abc[1],i) in ad_set:
                count +=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

N,K = list(map(int,input().split()))
target =[]
i=3
x = i/2*K
while x <= 3*N:
    if x == int(x):
        target.append(int(x))
    i += 1
    x = i/2*K
count = 0
if K%2 == 0:
    A = list(range(K//2,N+1,K//2))
else:
    A = list(range(K,N+1,K))


for trg in target:
    for a in A:
        for b in range((a//K+1)*K-a,N+1,K):
            c = trg - a - b
            #print(a,b,c,target)
            if  0 < c <= N  and (b+c)%K == 0 and (c+a)%K ==0:
                #print(a,b,c)
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
n,k=map(int,input().split())
if k%2==1:
    l=[i for i in range(k,n+1,k)]
    ans=len(list(product(l,repeat=3)))
if k%2==0:
    l=[i for i in range(k//2,n+1,k)]
    ll=[i for i in range(k,n+1,k)]
    ans=len(list(product(l,repeat=3)))+len(list(product(ll,repeat=3)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def odd(N, K):
    count = 0
    for x in range(1, N + 1):
        if x % K == 0:
            for y in range(1, N + 1):
                if y % K == 0:
                    for z in range(1, N + 1):
                        if z % K == 0:
                            count += 1
    return count


def even(N, K):
    count = 0
    for x in range(1, N + 1):
        if x % K == 0:
            for y in range(1, N + 1):
                if y % K == 0:
                    for z in range(1, N + 1):
                        if z % K == 0:
                            count += 1
    for x in range(1, N + 1):
        if x % K == K // 2:
            for y in range(1, N + 1):
                if y % K == K // 2:
                    for z in range(1, N + 1):
                        if z % K == K // 2:
                            count += 1
    return count


if __name__ == "__main__":
    n, k = map(int, input().split())
    ans = 0
    if k % 2 == 0:
        ans = even(n, k)
    else:
        ans = odd(n, k)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
ans=0
a=int(2*N/K)
for i in range(1,a+1):
  if i*K%2==1:
    continue
  for j in range(1,a+1):
    if j*K%2==1:
      continue
    for l in range(1,a+1):
      if l*K%2==1:
        continue
      if ((i+j)*K//2)%K==((l+j)*K//2)%K==((i+l)*K//2)%K==0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
s=0
if k%2==0:
    l=k//2
    for a in range(1,n+1):
        if a%k==0:
            for b in range(1,n+1):
                if b%k==0:
                    for c in range(1,n+1):
                        if c%k==0:
                            s+=1
        elif a%k==l:
            for b in range(1,n+1):
                if b%k==l:
                    for c in range(1,n+1):
                        if c%k==l:
                            s+=1
else:
    for a in range(1,n+1):
        if a%k==0:
            for b in range(1,n+1):
                if b%k==0:
                    for c in range(1,n+1):
                        if c%k==0:
                            s+=1
print(s)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
from itertools import combinations_with_replacement

# a+b % K == 0
# b+c % K == 0
# c+a % K == 0

# a が Kで割り切れる場合
#   -> bもcもKで割り切れる
#   -> a,b,cともにKの倍数
#   -> Kの倍数の個数(N//K) ** 3

# a がKで割れきれない場合
#   -> 同じくbもcもKで割り切れない
#   Q. Kが奇数の場合
#     -> それを満たす(a,b,c)の組み合わせはあり得ない
#   よってKは偶数
#     K=2のとき例より (a,b,c)=(1,1,1),(1,3,3),...
#     K=4のとき(a,b,c)=(2,2,2),(2,6,6),...
#     K=6のとき(a,b,c)=(3,3,3),(3,3,9),...
#   よりa % K == K/2である必要がある
#     a = x*K+K/2 (x=0以上の整数)

num_double = N//K
if K % 2 == 1:
    # Kが奇数の場合
    #  (1) (a,b,c)ともにKの倍数
    print(num_double ** 3)
else:
    # Kが偶数の場合,
    #  (1) (a,b,c)ともにKの倍数
    #  (2) (a,b,c)がいずれも Kで割った余りがK/2となる
    s = K // 2
    nums = [a for a in range(s, N+1, K)]
    count = 0
    for a, b, c in combinations_with_replacement(nums, 3):
        if a == b and b == c:
            count += 1
        elif a == b or b == c:
            count += 3
        else:
            count += 6
    print(num_double ** 3 + count)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
import itertools
count = 0
for i in itertools.product(range(1,n+1), repeat = 3):
    if (i[0]+i[1]) % k == 0 and (i[0]+i[2]) % k == 0 and (i[2]+i[1]) % k == 0:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import*
n, k = map(int, input().split())
a, b = divmod(n, k)
t = 0 if k%2 else a + (b >= k//2)
j = lambda i: len(list(product(range(i), repeat=3)))
print(j(a)+j(t))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
if K%2==1:
  print((N//K)**3)
else:
  k=K//2
  ans=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)%K==0 and (b+c)%K==0 and (c+a)%K==0:
          if a==b==c:
            ans+=1
          elif a==b or b==c or c==a:
            ans+=3
          else:
            ans+=6
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
def ABC108C(n, k):
    K = [k * i for i in range(1, -(-2*n // k) + 1)]
    m = len(K)
    count = 0
    for x in K:
        for y in K:
            for z in K:
                a =  (x - y + z)/2
                if a == int(a) and 1 <= a <= n:
                    b =  (x + y - z)/2
                    if b == int(b) and 1 <= b <= n:
                        c = (-x + y + z)/2
                        if c == int(c) and 1 <= c <= n:
                            count += 1
                            # print(f"{count}  {a} {b} {c}")
    print(count)

n, k = map(int, input().split())
ABC108C(n, k)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())

A = []
for i in range(2, 2*N+1):
    if i%K == 0:
        A.append(i)

ans = 0
for x in range(len(A)):
    for y in range(len(A)):
        for z in range(len(A)):
            a = (A[x]-A[y]+A[z])/2
            if int(a) == a and 1 <= a <= N and 1 <= A[x]-a <= N and 1 <= A[z]-a <= N:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
Count = 0
AnswerK = []
for i in range(1,2*N//K+1):
  AnswerK.append(i*K)
for j in range(len(AnswerK)):
    for k in range(len(AnswerK)):
        for l in range(1,N+1):
            if ((AnswerK[j]-l) + (AnswerK[k]-l))%K ==0 and 1<=AnswerK[j]-l<=N and 1<=AnswerK[k]-l<=N:
                Count +=1
print(Count)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
Count = 0
AnswerK = []
for i in range(1,3*N//K+1):
  AnswerK.append(i*K)
for j in range(len(AnswerK)):
    for k in range(len(AnswerK)):
        for l in range(1,N+1):
            if ((AnswerK[j]-l) + (AnswerK[k]-l))%K ==0 and 1<=AnswerK[j]-l<=N and 1<=AnswerK[k]-l<=N:
                Count +=1
print(Count)

Submission status: Time Limit Exceeded

Solution code:


def submit():
    n, k = map(int, input().split())

    k_cand = [i * k for i in range(1, (2 * n) // k + 1)]

    ans = []
    for i in range(1, n + 1):
        a = i
        for k1 in k_cand:
            b = k1 - a
            if b <= 0 or b > n:
                continue

            for k2 in k_cand:
                c = k2 - b
                if c <= 0 or c > n:
                    continue

                if (a + c) % k == 0:
                    ans.append((a, b, c))

    print(len(ans))
        

if __name__ == "__main__":
    submit()

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
l = [_ for _ in range(1,n+1)]
#print(n,k,l)

x = []
for i in range(n):
    for j in range(n):
        if (l[i] + l[j]) % k == 0:
            x.append([l[i], l[j]])
#print(x)

y = 0
for p in range(len(x)):
    for q in range(n):
        if (x[p][0] + l[q]) % k == 0 and (x[p][1] + l[q]) % k == 0:
            y += 1
print(y)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations

N, K = map(int, input().split())
A = []
for  i in range(1,N+1):
    A.append(i)
    A.append(i)
    A.append(i)

B = []
for i in permutations(A,3):
    B.append(i)
B = set(B)
B = list(B)
#print(B)

cnt = 0
for i in range(len(B)):
    if (B[i][0]+B[i][1])%K == (B[i][1]+B[i][2])%K == (B[i][2]+B[i][0])%K == 0 :
        cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
#a%kを決めればb%kとc%kが決まる
cnt=0
for a_mod in range(k):
  if a_mod==0:
    b_mod,c_mod=0,0
  else:
    b_mod=k-a_mod
    c_mod=k-b_mod
    if c_mod!=k-a_mod:
      continue
  for a in range(a_mod,n+1,k):
    for b in range(b_mod,n+1,k):
      for c in range(c_mod,n+1,k):
        if a!=0 and b!=0 and c!=0:
          cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
#a%kを決めればb%kとc%kが決まる
cnt=0
for a_mod in range(k):
  if a_mod==0:
    b_mod,c_mod=0,0
  else:
    b_mod=k-a_mod
    c_mod=k-b_mod
    if c_mod!=k-a_mod:
      continue
  for a in range(a_mod,n+1,k):
    for b in range(b_mod,n+1,k):
      for c in range(c_mod,n+1,k):
        if a!=0 and b!=0 and c!=0:
          cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count1 = count2 = 0

n,k=map(int,input().split())
count1+=n//k
if k%2==0:count2+=(n+k//2)//k
# for ii in itertools.product(range(1,n//k+2), repeat=3):
#     print(ii)
# print(count)
a=len(list(itertools.product(range(count1),repeat=3)))
b=len(list(itertools.product(range(count2),repeat=3)))
print(a+b)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
from itertools import permutations
input = sys.stdin.readline

N, K = [int(x) for x in input().strip().split()]
l1 = deque([])
l2 = deque([])
ans = deque([])
c = K
while c <= N:
    l1.append(c)
    c += K
for i in l1:
    for j in l1:
        for k in l1:
            ans.append((i, j, k))

if K % 2 == 0:
    c = K / 2
    while c <= N:
        l2.append(c)
        c += K
    for i in l2:
        for j in l2:
            for k in l2:
                ans.append((i, j, k))

print(len(list(set(ans))))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k = map(int,input().split())
if k%2!=0:
  ans = len(list(itertools.product(range(1,n//k+1),repeat=3)))
  print(ans)
else:
  ans = len(list(itertools.product(range(1,n//k+1),repeat=3))) + len(list(itertools.product(range(1,(2*n)//k-n//k+1),repeat=3)))
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
def Count(a,b,c,K):
    if (a+b)%K==0 and (a+c)%K==0 and (b+c)%K==0:
        return 1;
    else:
        return 0;

N,K=(int(i) for i in input().split())
count=0

for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            count=count+Count(i,j,k,K)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())

t=0
v=2*n//k

for apb in range(k,k*(v+1),k):
  for bpc in range(k,k*(v+1),k):
    for cpa in range(k,apb+bpc,k):
      if (apb+bpc+cpa)%2:
        continue
      a = (apb+bpc+cpa - 2*bpc)//2
      b = (apb+bpc+cpa - 2*cpa)//2
      c = (apb+bpc+cpa - 2*apb)//2
      if 0 < a and a <= n and 0 < b and b<=n and 0 < c and c <= n:
        t += 1

print(t)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())

t=0
v=2*n//k

for apb in range(k,k*(v+1),k):
  for bpc in range(k,k*(v+1),k):
    for cpa in range(k,k*(v+1),k):
      if (apb+bpc+cpa)%2:
        continue
      a = (apb+bpc+cpa - 2*bpc)//2
      b = (apb+bpc+cpa - 2*cpa)//2
      c = (apb+bpc+cpa - 2*apb)//2
      if 0 < a and a <= n and 0 < b and b<=n and 0 < c and c <= n:
        t += 1

print(t)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

# 2a = xk, 2b = ykのとき a+b = (x+y)k/2
# x+yが偶数、すなわちx,yの偶奇が一致するならばa+bはkの倍数となる。他の組合せでも同様
# a,b,cの候補リストを用意して重複順列計算

abc_list_even = []
abc_list_odd = []

for a in range(1, N+1):
    if (2*a)%K == 0:
        if ((2*a)//K)%2 == 0:
            abc_list_even.append(a)
        else:
            abc_list_odd.append(a)

print(len(list(itertools.product(abc_list_even, repeat=3))) + len(list(itertools.product(abc_list_odd, repeat=3))))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

# 2a = xk, 2b = ykのとき a+b = (x+y)k/2
# x+yが偶数、すなわちx,yの偶奇が一致するならばa+bはkの倍数となる。他の組合せでも同様
# a,b,cの候補リストを用意して重複順列計算

abc_list = []
for a in range(1, N+1):
    if (2*a)%K == 0:
        abc_list.append(a)

abc_list_even = []
abc_list_odd = []

for a in abc_list:
    if ((2*a)//K)%2 == 0:
        abc_list_even.append(a)
    else:
        abc_list_odd.append(a)


print(len(list(itertools.product(abc_list_even, repeat=3))) + len(list(itertools.product(abc_list_odd, repeat=3))))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations_with_replacement

N,K = map(int,input().split())
ans = 0
for cmb in combinations_with_replacement([i for i in range(1,N+1)],3):
  if all([True if a%K ==0 else False for a in [cmb[0]+cmb[1], cmb[1]+cmb[2],cmb[2]+cmb[0]]]):
    set_num = len(set(cmb))
    if set_num == 1: ans += 1
    elif set_num == 2: ans += 3
    elif set_num == 3: ans += 6
  #print(ans, cmb)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = [int(a) for a in input().split()]
cnt = 0
for a in range(1, n + 1, 1):
    for b in range(a, n + 1, k):
        if ((a - b) % k != 0 or (a + b) % k != 0):
            continue
        for c in range(b, n + 1, k):
            if ((a - c) % k != 0 or (b - c) % k != 0)  :
                continue
            if (a == b and a == c and b == c):
                cnt += 1
            elif (a == b or a == c or b == c):
                cnt += 3
            else:
                cnt += 6
print (cnt)

Submission status: Time Limit Exceeded

Solution code:
N, K = list(map(int, input().split()))
c = 0
for i in range(1, N + 1):
    a = 0
    if (i + i) % K == 0:
        for j in range(1, N + 1):
            if (i + j) % K == 0:
                a += 1
    c += a * a
print(c)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
ans = 0
if K % 2 != 0:
    M = [a for a in range(0, N+1, K)]
    M.pop(0)
else:
    M = [a for a in range(0, N+1, K//2)]
    M.pop(0)
for a in M:
    for b in M:
        if (a + b) % K != 0:
            continue
        for c in M:
            if ((a + c) % K != 0) or ((b + c ) % K != 0):
                continue
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
ans = 0
if K % 2 != 0:
    M = [a for a in range(0, N+1, K)]
    M.pop(0)
else:
    M = [a for a in range(0, N+1, K//2)]
    M.pop(0)
for a in M:
    for b in M:
        for c in M:
            if ((a+b)%K) == ((b+c)%K) == ((c+a)%K) == 0:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

def main():
    N,K = map(int,input().split())
    ans = 0
    if K%2==0:
        a0 = K//2
    else:
        a0 = K
    for a in range(a0, N+1, a0):
        for _ in range(K - a%K, N+1, K):
            for _ in range(K - a%K, N+1, K):
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

def main():
    N,K = map(int,input().split())
    ans = 0
    if K%2==0:
        a0 = K//2
    else:
        a0 = K
    for a in range(a0, N+1, a0):
        for b in range(K - a%K, N+1, K):
            for c in range(K - a%K, N+1, K):
                if (b+c)%K == 0:
#                    print(a,b,c)
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def check():
    a = []
    bDict2 = {}
    count = 0
    removeList = []
    N, K = [int(i) for i in input().split(' ')]
    for i in range(1,N+1):
        if (2*i)%K == 0:
            a.append(i)


    while a != []:
        temp = a[0]
        for i in a:
            if (temp+i)%K == 0:
                removeList.append(i)
                if str(temp) not in bDict2:
                    bDict2[str(temp)] = 1
                else:
                    bDict2[str(temp)] += 1  
                    
        for i in removeList:
            a.remove(i)
        removeList.clear()
            
    for i in bDict2:
        count += bDict2[i]**3

    print(count)
check()

Submission status: Time Limit Exceeded

Solution code:
import math

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

def check():
    a = []
    b = []
    count = 0
    bDict = {}
    N, K = [int(i) for i in input().split(' ')]
    for i in range(1,N+1):
        if (2*i)%K == 0:
            a.append(i)
    #print(a)
    for i in a:
        for j in range(1,N+1):
            if (i + j)%K == 0 and i != j:
                b.append((i,j))
                if str(i) not in bDict:
                    bDict[str(i)] = 1
                else:
                    bDict[str(i)] += 1
    
    for i in bDict:
        if bDict[i] > 1:
            count += permutations_count(bDict[i]+1, 3)//(bDict[i]+1)

    #print(b)
    print(3*len(b)+len(a)+count)
check()

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(nk) for nk in input().split()]

ans = 0
# a+b=pK b+c=qK c+a=rK
for p in range(1, ((2*N)//K)+1):#1<=p<=(2*N)//K
  for q in range(1, ((2*N)//K)+1):
    b0 = (( p+q-1)*K)/2
    if b0 < 1:
      continue
    for r in range(1, ((2*N)//K)+1):
      a = (( p-q+r)*K)/2
      b = (( p+q-r)*K)/2
      c = ((-p+q+r)*K)/2
      if b < 1:
        break
      elif a > N or c > N:
        break
      elif b > N:
        continue
      elif a < 1 or c < 1:
        continue
      elif a == int(a) and b == int(b) and c == int(c):
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(nk) for nk in input().split()]

ans = 0
# a+b=pK b+c=qK c+a=rK
for p in range(1, ((2*N)//K)+1):#1<=p<=(2*N)//K
  for q in range(1, ((2*N)//K)+1):
    for r in range(1, ((2*N)//K)+1):
      a = (( p-q+r)*K)/2
      b = (( p+q-r)*K)/2
      c = ((-p+q+r)*K)/2
      if b < 1:
        break
      elif a > N or c > N:
        break
      elif b > N:
        continue
      elif a < 1 or c < 1:
        continue
      elif a == int(a) and b == int(b) and c == int(c):
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(nk) for nk in input().split()]

ans = 0
# a+b=pK b+c=qK c+a=rK
for p in range(1, ((2*N)//K)+1):#1<=p<=(2*N)//K
  for q in range(1, ((2*N)//K)+1):
    for r in range(1, ((2*N)//K)+1):
      a = (( p-q+r)*K)/2
      b = (( p+q-r)*K)/2
      c = ((-p+q+r)*K)/2
      if b < 1:
        break
      elif b > N:
        continue
      elif a < 1 or c < 1:
        continue
      elif a > N or c > N:
        break
      else:
        if a == int(a) and b == int(b) and c == int(c):
          ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())

if k % 2 == 0:
  li = []
  for i in range(k//2, n+1, k//2):
    li.append(i)
  
else:
  li = []
  for i in range(k, n+1, k):
    li.append(i)


count = 0
for a in li:
  for b in li:
    for c in li:
      if (a+b) % k == 0 and (b+c) % k == 0 and (a+c) % k == 0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())

ans = 0
for a in range(1, N+1):
    cnt = 0
    tmp = K - a % K
    if tmp > N:
        continue
    for b in range(tmp, N+1, K):
        if K - b % K != tmp:
            continue
        for c in range(tmp, N+1, K):
            cnt += 1
    ans += cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
ablist = [(a, k*i-a, k*j-a) 
            for a in range(1,n+1)
              for i in range(a//k+1,(n+a)//k+1)
                for j in range(a//k+1,(n+a)//k+1)
                 if ((k*(i+j)-2*a)%k==0)]
print(len(ablist))
# print(ablist)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
# m = (n+k-1)//k
# ans = 0
# k1 = k
ablist = [(a, k*i-a, k*j-a) 
            for a in range(1,n+1)
              for i in range(1,(n+a)//k+1)
                for j in range(1,(n+a)//k+1)
                 if (0<k*i-a<=n
                 and 0<k*j-a<=n
                 and (k*(i+j)-2*a)%k==0)]
print(len(ablist))
# print(ablist)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())

ans = 0
for i in range(1,N+1):
  for j in range(1,N+1):
      for k in range(1,N+1):
        if ((i + j) % K == 0 and (j + k) % K == 0 and (k + i) % K == 0):
          ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
m = (n+k-1)//k
ans = 0
i = 1
while k*i <= 2*n:
    ablist = [(a, k*i-a) for a in range(1,n+1) if 0<k*i-a<=n]
    # print(ablist)
    for j in range(1, 2*m+1):
        for (a, b) in ablist:
            c = k*j - a
            if 0 < c <= n and (b+c)%k==0:
                # print(a,b,c)
                ans += 1
    i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n, k = map(int, input().split())
cnt = 0
for i in itertools.combinations_with_replacement(range(1, n + 1), 3):
    if (i[0] + i[1]) % k == 0 and (i[1] + i[2]) % k == 0 and (i[2] + i[0]) % k == 0:
        cnt += len(list(set((itertools.permutations(i)))))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
ans = 0
for a in range(1, N + 1):
    for b in range(1, N + 1):
        if (a + b) % K == 0:
            for c in range(1, N + 1):
                if (b + c) % K == 0 and (c + a) % K == 0:
                    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())

#print(n,k)

cnt=0
quo=n//k+1

for x in range(1,n+1):
	mod=k-x%k
	if k-mod<=mod:
		for i in range(quo):
			y=k*i+mod
			#print(i)
			if x<=y and y<=n:
				for j in range(i,quo):
					z=k*j+mod
					#z=y+k*j
					if z<=n:
						if (y+z)%k==0:
							#print(x,y,z)
							if x==y and x==z:
								cnt+=1
							else:
								if x<y and y<z:
									cnt+=6
								else:
									cnt+=3

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

a, b = map(int, input().split())
c = []
for i in range(1, a + 1):
    if i % b == 0 or i % b == b / 2:
        c.append(i)
d = 0
for i in itertools.product(c, repeat=3):
    if (i[0] + i[1]) % b == 0 and (i[0] + i[2]) % b == 0 and (i[1] + i[2]) % b == 0:
        d += 1
print(d)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
ret = 0
for x in range(1, N + 1):
    for y in range(K - x, N + 1, K):
        for z in range(K - y, N + 1, K):
            if  y > 0 and z > 0 and (z + x) % K == 0:
                ret += 1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())

if K%2==1:
    s=K
else:
    s=K//2

ans=[]

for i in range((N-s)//s+1):
    for j in range((N-s)//s+1):
        for k in range(N-s//s+1):
            if s+max(i,j,k)*s <= N and (2+i+j)*s%K==0 and (2+j+k)*s%K==0 and (2+k+i)*s%K==0:
                ans.append((s+i*s,s+j*s,s+k*s))

print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
count = 0


for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            a = (i+j) % K
            b = (j+k) % K
            c = (k+i) % K
            if a == 0 and b == 0 and c == 0:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
p=0
for a in range(1,n+1):
  for b in range(1,n+1):
    for c in range(1,n+1):
      if (a+b)%k==0 and (b+c)%k==0 and (c+a)%k==0:
        p+=1
print(p)

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(i) for i in input().split()]
cnt = 0
for i in range(max(2//K,1), (2*N)//K+1):
    for j in range(max(2//K, 1), (2*N)//K+1):
        for m in range(max(2 // K, 1), (2 * N) // K+1):
            if 2/K<=i-j+m<=2*N/K and 2/K<=j-m+i<=2*N/K and 2/K<=m-i+j<=2*N/K:
                if K%2 == 0:
                    cnt+=1
                    #print((i-j+m)*K//2, (j-m+i)*K//2, (m-i+j)*K//2)
                elif (i+j+m)%2==0:
                    cnt+=1
                    #print((i-j+m)*K//2, (j-m+i)*K//2, (m-i+j)*K//2)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())

if k % 2 == 0:
    check = k // 2
else:
    check = k

cnt = 0
for a in range(check, n+1, check):
    for b in range(check, n+1, check):
        for c in range(check, n+1, check):
            if (a + b) % k or (b + c) % k or (c + a) % k:
                continue
            else:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
N, K = map(int, input().split())
x = list(product(range(1, N + 1), repeat=3))
ans = 0
for q in x:
    w = [q[0] + q[1], q[0] + q[2], q[1] + q[2]]
    if all(list(map(lambda x: x % K == 0, w))):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

comb = []
if K % 2 != 0:
    tail = N//K+1
    for a in range(1, tail):
        for b in range(1, tail):
            for c in range(1, tail):
                # print('odd:', a*K, b*K, c*K)
                comb.append((a, b, c))
else:
    tail = N//K+1
    for a in range(1, tail):
        for b in range(1, tail):
            for c in range(1, tail):
                # print('even_1:', a*K, b*K, c*K)
                comb.append((a, K, b, K, c, K))
    tail = (2*N+K)//(2*K)+1
    for a in range(1, tail):
        for b in range(1, tail):
            for c in range(1, tail):
                # print('even_2:', a*K-K//2, b*K-K//2, c*K-K//2)
                comb.append((a, K, 1, b, K, 1, c, K, 1))


print(len(set(comb)))