CodeEff/ECCO huggingface dataset:
# Original solution
def C_Bridge(N, M, E):
    """
    N:頂点の数
    M:辺の数
    E:辺で結ばれる頂点の組
    """
    def dfs(v):
        # 現在の頂点を訪問済にする
        visited[v] = True
        for v2 in range(N):
            # 現在の頂点と次の頂点に辺がない。スキップ
            if adjacent[v][v2] == False:
                continue
            # 次の頂点が訪問済。スキップ
            if visited[v2] == True:
                continue
            dfs(v2)

    # 隣接行列の構成
    adjacent = [[0 for _ in range(N)] for _ in range(N)]
    a = [0 for _ in range(M)]
    b = [0 for _ in range(M)]  # a[i],b[i]がi番目の辺を表す
    for i in range(M):
        a[i] = E[i][0] - 1
        b[i] = E[i][1] - 1
        adjacent[a[i]][b[i]] = True
        adjacent[b[i]][a[i]] = True

    # 各辺が橋であるか？
    # グラフから辺を取り除いて、グラフが連結かを判定
    ans = 0
    visited = [False for _ in range(N)]
    for i in range(M):
        # 辺を取り除く
        adjacent[a[i]][b[i]] = False
        adjacent[b[i]][a[i]] = False

        # すべての辺を未訪問にする
        for j in range(N):
            visited[j] = False
        # 頂点0からDFS
        dfs(0)

        bridge = False
        for j in range(N):
            # すべての頂点が訪問済(訪問できた)なら連結、そうでなければ非連結
            if visited[j] == False:
                bridge = True
        if bridge:
            ans += 1
        adjacent[a[i]][b[i]] = True
        adjacent[b[i]][a[i]] = True
    return ans

N,M = [int(i) for i in input().split()]
E = [[int(i) for i in input().split()] for j in range(M)]
print((C_Bridge(N, M, E)))

# Optimized solution
def c_bridge(N, M, E):
    """
    N:頂点の数
    M:辺の数
    E:辺で結ばれる頂点の組
    """
    def dfs(v):
        # 現在の頂点を訪問済にする
        visited[v] = True
        for v2 in range(N):
            # 現在の頂点と次の頂点に辺がない。スキップ
            if adjacent[v][v2] == False:
                continue
            # 次の頂点が訪問済。スキップ
            if visited[v2] == True:
                continue
            dfs(v2)

    # 隣接行列の構成
    adjacent = [[0 for _ in range(N)] for _ in range(N)]
    for a, b in E:
        a, b = a - 1, b - 1
        adjacent[a][b] = True
        adjacent[b][a] = True

    # 各辺が橋であるか？
    # グラフから辺を取り除いて、グラフが連結かを判定
    ans = 0
    for a, b in E:
        a, b = a - 1, b - 1
        # 辺を取り除く
        adjacent[a][b] = False
        adjacent[b][a] = False

        # すべての辺を未訪問として初期化
        visited = [False for _ in range(N)]
        # 頂点0からDFS
        dfs(0)
        # すべての頂点が訪問済なら連結、そうでなければ非連結
        if not all(visited):
            ans += 1

        # 辺を復元
        adjacent[a][b] = True
        adjacent[b][a] = True
    return ans

N,M = [int(i) for i in input().split()]
E = [[int(i) for i in input().split()] for j in range(M)]
print((c_bridge(N, M, E)))
# Original solution
from collections import deque
def BFS(N,M,List):
    Edge = [[] for TN in range(N+1)]
    for TM in range(0,M):
        Edge[List[TM][0]].append(List[TM][1])
        Edge[List[TM][1]].append(List[TM][0])

    Distance = [-1]*(N+1)
    Distance[0] = 0
    Distance[1] = 0
    
    From = [0]*(N+1)
    From[1] = 1

    Deque = deque()
    Deque.append(1)
    while Deque:
        Now = Deque.popleft()
        for Con in Edge[Now]:
            if Distance[Con]==-1:
                Distance[Con] = Distance[Now]+1
                Deque.append(Con)
                From[Con] = Now

    return Distance[1:],From[1:]

import copy
N,M = (int(T) for T in input().split())
List = [[] for TM in range(0,M)]
for TM in range(0,M):
    List[TM] = [int(T) for T in input().split()]
Count = 0
for TM in range(0,M):
    ListCopy = copy.deepcopy(List)
    del ListCopy[TM]
    Distance,From = BFS(N,M-1,ListCopy)
    if -1 in Distance:
        Count += 1
print(Count)

# Optimized solution
def FindParent(X):
    if Parent[X]==X:
        return X
    else:
        Parent[X] = FindParent(Parent[X])
        return Parent[X]

def UniteParent(X,Y):
    X = FindParent(X)
    Y = FindParent(Y)
    if X==Y:
        return 0
    if Rank[X]<Rank[Y]:
        Parent[X] = Y
    else:
        Parent[Y] = X
        if Rank[X]==Rank[Y]:
            Rank[X] += 1

import copy
N,M = (int(T) for T in input().split())
List = [[] for TM in range(0,M)]
for TM in range(0,M):
    List[TM] = [int(T) for T in input().split()]
    
Count = 0
for TM in range(0,M):
    ListCopy = copy.deepcopy(List)
    del ListCopy[TM]
    
    Parent = [I for I in range(N+1)]
    Rank = [0]*(N+1)
    for TTM in range(0,M-1):
        UniteParent(ListCopy[TTM][0],ListCopy[TTM][1])
    for TN in range(1,N+1):
        FindParent(TN)
    if len(set(Parent[1:]))>1:
        Count += 1
print(Count)
# Original solution
# https://atcoder.jp/contests/abc075/tasks/abc075_c
class UnionFind():
    def __init__(self, N):
        self._root = [-1 for _ in range(N)]

    def find(self, x):
        if self._root[x] < 0: return x
        self._root[x] = self.find(self._root[x])
        return self._root[x]

    def unite(self, x, y):
        gx = self.find(x)
        gy = self.find(y)
        if gx == gy: return False
        if self._root[gx] > self._root[gy]:
            gx, gy = gy, gx
        self._root[gx] += self._root[gy]
        self._root[gy] = gx
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -(self._root[self.find(x)])

    def roots(self):
        return [i for i in self._root if i < 0]


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

nodes = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    nodes.append((a, b))

cnt = 0
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if i != j:
          uf.unite(nodes[j][0]-1, nodes[j][1]-1)
    cnt += (len(uf.roots()) != 1)
print(cnt)

# Optimized solution
# I used the below code as a reference.
# https://atcoder.jp/contests/abc075/submissions/10369947
class UnionFind():
    def __init__(self, N):
        self._root = [-1 for _ in range(N)]

    def find(self, x):
        if self._root[x] < 0: return x
        self._root[x] = self.find(self._root[x])
        return self._root[x]

    def unite(self, x, y):
        gx = self.find(x)
        gy = self.find(y)
        if gx == gy: return False
        if self._root[gx] > self._root[gy]:
            gx, gy = gy, gx
        self._root[gx] += self._root[gy]
        self._root[gy] = gx
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -(self._root[self.find(x)])

    def roots(self):
        return [i for i in self._root if i < 0]

n, m = list(map(int, input().split()))
nodes = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    nodes.append((a, b))

cnt = 0
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if i != j:
            uf.unite(nodes[j][0]-1, nodes[j][1]-1)
    cnt += (len(uf.roots()) != 1)
print(cnt)
# Original solution
# ABC075 C - Bridge
def dfs(v):
    visited[v]=True
    for nv in range(n):
        if G[v][nv]==False:
            continue
        if visited[nv]:
            continue
        dfs(nv)

n,m = list(map(int,input().split()))
G = [[False]*n for _ in range(n)]
ans = 0
visited = [False for _ in range(n)]
A,B = [],[]
for i in range(m):
    a,b = list(map(int,input().split()))
    A.append(b-1)
    B.append(a-1)
    G[a-1][b-1]=G[b-1][a-1]=True

for i in range(m):
    G[A[i]][B[i]]=G[B[i]][A[i]]=False
    visited = [False for _ in range(n)]
    dfs(0)
    if all(visited):
        ans += 1
    G[A[i]][B[i]]=G[B[i]][A[i]]=True

print((m-ans))


# Optimized solution
class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        # union by rank
        self.r = [1]*n
 
    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]
 
    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)
 
        if rx != ry:
            if self.r[rx] > self.r[ry]:
                rx, ry = ry, rx
            if self.r[rx] == self.r[ry]:
                self.r[ry] += 1
            self.p[ry] += self.p[rx]
            self.p[rx] = ry
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def count_member(self, x):
        return -self.p[self.find(x)]

n,m=list(map(int,input().split()))
e=[]
for i in range(m):
  a,b=list(map(int,input().split()))
  e.append((a-1,b-1))
ans=0
for i in range(m):
  uf=UnionFind(n)
  ok=False
  for j in range(m):
    if i!=j:
      a,b=e[j]
      uf.union(a,b)
  for k in range(n):
    t=uf.count_member(k)
    if t!=n:
      ok=True
      break
  if ok:ans+=1
print(ans)
# Original solution
def multival(): return list(map(int,input().split()))
def data(N=1): return [list(map(int,input().split())) for _ in range(N)]
mod = 10**9 + 7
inf = float("inf")


N,M = multival()
nemat = [[0]*N for _ in range(N)]
ans = M
info = []
for _ in range(M):
    a,b = multival()
    a -= 1; b-= 1
    nemat[a][b] = 1
    nemat[b][a] = 1
    info.append([a,b])

def dfs(now,visited):
    visited[now] = True
    if all(visited):
        global ans
        ans -= 1
        return
    for ne in range(N):
        if nemat[now][ne] == 1 and visited[ne] is False:
            dfs(ne,visited)
    
for i,j in info:
    nemat[i][j] = 0
    nemat[j][i] = 0
    dfs(0,[False]*N)
    nemat[i][j] = 1
    nemat[j][i] = 1

print(ans)

# Optimized solution
class Unionfind:

    __slots__ = ['nodes']

    def __init__(self, n):
        self.nodes = [-1]*n

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

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        rank_x = -self.nodes[x]; rank_y = -self.nodes[y]
        if rank_x < rank_y:
            x, y = y, x
        if rank_x == rank_y:
            self.nodes[x] -= 1
        self.nodes[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def rank(self, x):
        return -self.nodes[self.root(x)]

N,M = list(map(int,input().split()))
info = [list(map(int,input().split())) for i in range(M)]

def bridge(k):
    uf = Unionfind(N)
    for i,pair in enumerate(info):
        if i == k: continue
        a = pair[0] - 1; b = pair[1] - 1
        uf.unite(a,b)
    s = {uf.root(i) for i in range(N)}
    if len(s) != 1:
        return True
    return False

cnt = 0
for k in range(M):
    if bridge(k):
        cnt += 1

print(cnt)
# Original solution
import sys
sys.setrecursionlimit(10**5)
a, b, c = list(map(int, input().split()))

M = 100
memo = {}
def dfs(a, b, c):
    if (a, b, c) in memo:
        return memo[a,b,c]
    if a == b == c:
        return 0
    res = 10**9+7
    if a < M:
        res = min(res, dfs(a+2, b, c) + 1)
    if b < M:
        res = min(res, dfs(a, b+2, c) + 1)
    if c < M:
        res = min(res, dfs(a, b, c+2) + 1)
    if a < M and b < M:
        res = min(res, dfs(a+1, b+1, c) + 1)
    if b < M and c < M:
        res = min(res, dfs(a, b+1, c+1) + 1)
    if a < M and c < M:
        res = min(res, dfs(a+1, b, c+1) + 1)
    memo[a, b, c] = res
    return res
print((dfs(a, b, c)))

# Optimized solution
a, b, c= list(map(int, input().split()))
ans = 0
def calc(a, b):
    if a < b:
        r = b-a
        if r % 2:
            return r//2 + 2
        return r//2
    else:
        return a-b
def solve(a, b, c):
    return calc(a, c) + calc(b, c)
print((min(solve(a, b, c), solve(b, c, a), solve(c, a, b))))
# Original solution
a, b, c= list(map(int, input().split()))
ans = 0
def calc(a, b):
    if a < b:
        r = b-a
        if r % 2:
            return r//2 + 2
        return r//2
    else:
        return a-b
def solve(a, b, c):
    return calc(a, c) + calc(b, c)
print((min(solve(a, b, c), solve(b, c, a), solve(c, a, b))))


# Optimized solution
a, b, c = sorted(map(int, input().split()))
a = c-a; b = c-b
p = a%2; q = b%2
if p and q:
    print((a//2+b//2+1))
elif p or q:
    print((a//2+b//2+2))
else:
    print((a//2+b//2))
# Original solution
a=list(map(int,input().split()))
m=max(a)
t=0
if (m*3-sum(a))%2==1:t=3
print(((m*3-sum(a)+t)//2))


# Optimized solution
a=list(map(int,input().split()))
m=max(a)
t=m*3-sum(a)
if t%2==1:t+=3
print((t//2))
# Original solution
def noofrupees(x,y,z):
    if(x==y and x==z):
        return 0
    elif(x==y):
        if(x<z):
            return z-x
        else:
            if(x%2==0 and z%2==0):
                return int((x-z)/2)
            elif(x%2!=0 and z%2!=0):
                return int((x-z)/2)
            else:
                z = z-1
                return int((x-z)/2)+1
    elif(x==z):
        if(x<y):
            return y-x
        else:
            if(x%2==0 and y%2==0):
                return int((x-y)/2)
            elif(x%2!=0 and y%2!=0):
                return int((x-y)/2)
            else:
                y = y-1
                return int((x-y)/2)+1
    elif(y==z):
        if(y<x):
            return x-y
        else:
            if(y%2==0 and x%2==0):
                return int((y-x)/2)
            elif(y%2!=0 and x%2!=0):
                return int((y-x)/2)
            else:
                x = x-1
                return int((y-x)/2)+1
    
#t= int(input())
t=1;
for v in range(t):
    x,y,z = list(map(int,input().split()))
    if(x!=y and x!=z and y!=z):
        list1 = [x,y,z]
        list1.sort()
        s = list1[2] - list1[1]
        list1[0]+=s
        list1[1]+=s
        print((s+noofrupees(list1[0],list1[1],list1[2])))
    else:
        print((noofrupees(x,y,z)))
    
        
        
                
                
                
                
        

# Optimized solution
#t=int(input())
t=1
for i in range(t):
	x,y,z=list(map(int,input().split()))
	ma=max(x,y,z)
	mi=min(x,y,z)
	if(x==ma):
		if(y<z):
			m=x-y
			n=x-z
		else:
			m=x-z
			n=x-y
	elif(y==ma):
		if(x<z):
			m=y-x
			n=y-z
		else:
			m=y-z
			n=y-x
	else:
		if(x<y):
			m=z-x
			n=z-y
		else:
			m=z-y
			n=z-x
	ans=n+(m-n)//2
	if((m-n)%2==1):
		ans+=2
	print(ans)
# Original solution
N = int(eval(input()))
Ss = input().replace(" ", '')
part = ""
for n, i in enumerate(Ss):
	if n != 0:
		if i == part[0]:
			Ss_cp = Ss[::1]
			Ss_cp = Ss_cp.replace(part, '')
			if Ss_cp == '':
				print((N//len(part)))
				exit()
	part += Ss[n]
else:
	print((1))


# Optimized solution
N = int(eval(input()))
Ss = input().split()
res = 1
for t in range(1, N+1):
	if (N%t != 0): continue
	f = False
	for i in range(N-t):
		if (Ss[i] == Ss[i + t]): continue
		f = True
		break
	if (f): continue
	res = N // t
	break

print(res)
# Original solution
int_1, int_2 = list(map(int, input().split()))
answer = int_1 + int_2

if 10 <= answer:
    print('error')
else:
    print(answer)

# Optimized solution
a, b = list(map(int, input().split()))
answer = a + b
print(('error' if 10 <= answer else answer))
# Original solution
a,b=list(map(int,input().split()))
print((a+b if a+b<10 else "error"))

# Optimized solution
A,B = list(map(int,input().split()))
print((A+B if A+B < 10 else "error"))
# Original solution
a,b=list(map(int,input().split()))
if a+b<10:
    print((a+b))
else:
    print("error")

# Optimized solution
a,b=list(map(int,input().split()))
print((a+b if a+b<10 else"error"))
# Original solution
a,b = list(map(int,input().split()))
if (a + b) < 10:
	print(a+b)
else:
	print("error")

# Optimized solution
a,b = list(map(int,input().split()))
sum = a+b
if sum >= 10:
   print("error")
else:
  print(sum)
# Original solution
N, K = list(map(int, input().split()))

count = 0
for a in range(1, N+1):
    b = K - a % K
    while b <= N:
        if (a % K) == (b % K):
            c = K - a % K
            count += (N - c) // K + 1
        b += K

print(count)


# Optimized solution
N, K = list(map(int, input().split()))

count = 0
for a in range(1, N+1):
    b = K - a % K
    if (a % K) == (b % K):
        count += ((N - b) // K + 1) ** 2

print(count)
# Original solution
n,k=list(map(int,input().split()))
d=0
for a in range(1,n+1):
 for b in range(k-a%k,n+1,k):
   for c in range(k-a%k,n+1,k):
    if (a+b)%k==0 and (b+c)%k==0 and (c+a)%k==0:d+=1
print(d)

# Optimized solution
n,k=list(map(int,input().split()))
if k%2==0:
 if n%k<k/2:print(((n//k)**3+(n//k)**3))
 else:print(((n//k)**3+((n//k)+1)**3))
else:print(((n//k)**3))
# Original solution
n, k = list(map(int, input().split()))
import itertools
ans = 0
for a, b, c in itertools.product(list(range(1,n+1)), repeat=3):
  if (a+b)%k == 0 and (b+c)%k == 0 and (c+a)%k == 0:
    ans += 1
print(ans)

# Optimized solution
n, k = list(map(int, input().split()))
ans = 0
temp = n // k
ans += temp ** 3

if k % 2 == 0:
  n += k // 2
  temp = n // k
  ans += temp ** 3
  
print(ans)
# Original solution
N, K = list(map(int, input().split()))
num = [0 for _ in range(K)]
for i in range(1, N + 1):
    num[i % K] += 1
ans = 0
for a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K == 0:
        ans += num[a] * num[b] * num[c]
print(ans)




# Optimized solution
N, K = list(map(int, input().split()))
num = [0 for _ in range(K)]
for i in range(1, N + 1):
    num[i % K] += 1
ans = 0
if K % 2 == 0:
    ans += num[0] ** 3 + num[K // 2] ** 3
else:
    ans += num[0] ** 3
print(ans)
# Original solution
N,K = list(map(int,input().split()))
odd = []
even1 = []
even2 = []
if K % 2 == 1:
    for i in range(1,N+1):
        if i % K == 0:
            odd += [i]
    ans = len(odd) ** 3
else:
    for i in range(1,N+1):
        if i % K == 0:
            even1 += [i]
        elif i % (K/2) == 0:
            even2 += [i]
    ans = len(even1) ** 3 + len(even2) ** 3
print(ans)

# Optimized solution
N,K = list(map(int,input().split()))
ary1 = []
ary2 = []
if K % 2 == 1:
    for i in range(K,N+1,K):
        ary1 += [i]
    print((len(ary1)**3))
else:
    for i in range(1,N+1):
        if i % K == 0:
            ary1 += [i]
        elif i % (K//2) == 0:
            ary2 += [i]
    print(((len(ary1) ** 3) + (len(ary2) ** 3)))
# Original solution
n, k  =list(map(int, input().split()))

ans = 0
#ｋで割り切れるn以下の数のリスト
odd = [i for i in range(k, n+1, k)] #kから始まり、nまで、ｋ刻み
ans += len(odd) ** 3 #abcの選び方のため3乗

if k % 2 == 0:
  #k/2から始まり、nまでで、kで割ると余りがk/2になる
  even = [i for i in range(k//2, n+1, k)]
  ans += len(even) ** 3
  
print(ans)


# Optimized solution

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

a = N // K 
b = 0
if K % 2 == 0:
    b = a+1 if N - a*K >= K/2 else a
print((a**3 + b**3))
# Original solution
from itertools import product
N, K = list(map(int, input().split()))
x = list(product(list(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([x % K == 0 for x in w])):
        ans += 1
print(ans)

# Optimized solution
N, K = list(map(int, input().split()))
if K % 2 == 1:
    print((sum(1 for n in range(1, N + 1) if n % K == 0) ** 3))
else:
    print((sum(1 for n in range(1, N + 1) if n % K == 0) ** 3 + sum(1 for n in range(1, N + 1) if n % K == K // 2) ** 3))
# Original solution
N, K = list(map(int, input().split()))
if K % 2 == 1:
    print((sum(1 for n in range(1, N + 1) if n % K == 0) ** 3))
else:
    print((sum(1 for n in range(1, N + 1) if n % K == 0) ** 3 + sum(1 for n in range(1, N + 1) if n % K == K // 2) ** 3))


# Optimized solution
N, K = list(map(int, input().split()))
ans = (N // K) ** 3
ans += ((N + K // 2) // K) ** 3 if K % 2 == 0 else 0
print(ans)
# Original solution
import sys
input=sys.stdin.readline

def main():
    N,K = list(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()

# Optimized solution
import sys
input=sys.stdin.readline

def main():
    N,K = list(map(int,input().split()))
    r1 = 0
    for i in range(1,N+1):
        if i%K == 0:
            r1 += 1
    if K%2 == 1:
        print((r1**3))
    else:
        r2 = 0
        for i in range(1,N+1):
            if i%K == K//2:
                r2 += 1
        print((r1**3+r2**3))
    
if __name__ == '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    ans = 0
    if K & 1:
        print(((N // K) ** 3))
    else:
        ans += (N // K) ** 3
        ans += ((N + K // 2) // K) ** 3
        print(ans)



if __name__ == '__main__':
    main()



# Optimized solution
N, K = [int(x) for x in input().split()]

ans = 0

ans += (N // K) ** 3

if K % 2 == 0:
    ans += ((N - K // 2) // K + 1) ** 3


print(ans)
# Original solution
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N,K = list(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 list(ad.values()):
        for abc in ab:
            if (abc[0],i) in ad_set and (abc[1],i) in ad_set:
                count +=1

print(count)

# Optimized solution
#プログラミング日記   一寸先は闇が人生
# https://pyteyon.hatenablog.com/entry/2018/09/02/094228
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N,K = list(map(int, input().split()))

# 偶数、奇数共に
# a,b,c mod 0,0,0 ⇒Kの倍数
multip_K =[i for i in range(K,N+1,K)]

#multip_Kから３つ選び並べる順列組み合わせ
le =len(multip_K)
ans_mod_0 =le **3

# 偶数のみ
# a,b,c mod K/2,K/2,K/2 
ans_mod_haf =0
if K%2 ==0:
    multip_haf =[i for i in range(1,N+1) if i %K ==K//2 ]
    le_haf =len(multip_haf)
    ans_mod_haf =le_haf **3

ans =ans_mod_0 +ans_mod_haf
print(ans)
# Original solution
import math
N,K = (int(i) for i in input().split())

count = 0
minus = []
for i in range(1,N+1):
    
    a = i
    b = i
    c = i
    if (a + b) % K == 0:
        count += 1
        count += len(minus) * (3*2)
        if len(minus) >= 2:
            kumiawase = math.factorial(len(minus))/(math.factorial(len(minus)-2)*math.factorial(2))
            count += kumiawase * (3*2)
    if i % K == 0:
        minus.append(i)

print((int(count)))

# Optimized solution
#import math
N,K = (int(i) for i in input().split())

count = 0
minus = []
for i in range(1,N+1):
    
    a = i
    b = i
    c = i
    if (a + b) % K == 0:
        count += 1
        count += len(minus) * (3*2)
        if len(minus) >= 2:
            #kumiawase = math.factorial(len(minus))/(math.factorial(len(minus)-2)*math.factorial(2))
            kazu = len(minus)
            kumiawase = kazu * (kazu - 1) / 2
            count += kumiawase * (3*2)
    if i % K == 0:
        minus.append(i)

print((int(count)))
# Original solution
N, K = list(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)))

# Optimized solution
N, K = list(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)