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: Runtime Error

Solution code:
from collections import deque
n = int(input())

lis = set()
def dfs():
    d = ['3','5','7']
    que = deque(['3','5','7'])
    while len(que) != 0:
        val = que.pop()
        #print(val)
        if len(val) < 10:
            #print(len(str(val)))
            for i in range(3):
                val2 = val + d[i]
                #print(val3[-1])
                l = list(val2)
                if '3' in l and '5' in l and '7' in l:
                    lis.add(int(val2))
                que.append(val2)

    return lis
lis = dfs()
ans = 0
for i in lis:
    if int(i) < n:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys

n, k = map(int, sys.stdin.readline().split())

def main():
    c1 = n // k
    c2 = n // (k // 2)
    if (k & 1): cnt = pow(c1, 3)
    else: cnt = pow(c1, 3) + pow(c2 - c1, 3)
    print(cnt)

if __name__ ==  '__main__':
    main()

Submission status: Runtime Error

Solution code:
def Candles(n , k , xl):

    ans = 0

    if k % 2 == 1:
        ans = (n // k)**3
    else:
        ans = (n // k)**3 + (((k / 2) + n) // k)**3

    return int(ans)

def main():
    n , k = map(int , input().split())
    xl = list(map(int , input().split()))
    print(Candles(n , k , xl))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#include <iostream>

using namespace std;

int main()
{
    long long n, k;
    cin >> n >> k;

    long long a = n / k, b = n / (k / 2) - a;
    long long c = a * a * a, d = b * b * b;
    if (k % 2 == 1)
        cout << c << endl;
    else
        cout << c + d << endl;
}

Submission status: Runtime Error

Solution code:
N=10**6
def comb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r]
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n,k=map(int,input().split())
if k==2:
  print((comb(n//2,3)+comb(n-n//2,3))*6)
else:
  print(comb(n//k,3)*6)

Submission status: Runtime Error

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

    ans+= pow(N//K,3)
    if k%2 == 0:
        ans = pow((n-k//2)//k, 3)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

num=[0]*(max(N+1,K)
for i in range(1,N+1):
    num[i%K]+=1
#print(num)
ans=0
for a in range(K):
    b=(K-a)%K#a=0なら0 a!=0ならk-aになる賢い手
    c=(K-a)%K
    if (b+c)%K!=0:
        continue
    else:
      	#print(a)
        ans+=num[a]*num[b]*num[c]
        #print(a,b,c)
print(ans)

Submission status: Runtime Error

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

num=[0]*(N+1)
for i in range(1,N+1):
    num[i%K]+=1
#print(num)
ans=0
for a in range(K):
    b=(K-a)%K#a=0なら0 a!=0ならk-aになる賢い手
    c=(K-a)%K
    if (b+c)%K!=0:
        continue
    else:
      	#print(a)
        ans+=num[a]*num[b]*num[c]
        #print(a,b,c)
print(ans)

Submission status: Runtime Error

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

num=[0]*(N)
for i in range(1,N+1):
    num[i%K]+=1
#print(num)
ans=0
for a in range(K):
    b=(K-a)%K#a=0なら0 a!=0ならk-aになる賢い手
    c=(K-a)%K
    if (b+c)%K!=0:
        continue
    else:
      	#print(a)
        ans+=num[a]*num[b]*num[c]
        #print(a,b,c)
print(ans)

Submission status: Runtime Error

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

num=[0]*(N)
for i in range(1,N+1):
    num[i%K]+=1
#print(num)

for a in range(K):
    b=(K-a)%K#a=0なら0 a!=0ならk-aになる賢い手
    c=(K-a)%K
    if (b+c)%K!=0:
        continue
    else:
      	#print(a)
        ans+=num[a]*num[b]*num[c]
        print(a,b,c)
print(ans)

Submission status: Runtime Error

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

num=[0]*(K-1)
for i in range(N):
    num[i%K]+=1

for a in range(K):
    b=(K-a)%K#a=0なら0 a!=0ならk-aになる賢い手
    c=(K-a)%K
    if (b+c)%K!=0:
        continue
    else:
        ans=num[a]*num[b]*num[c]
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=n//k
b=n//(k//2)
if k%2==1:
	print(a**3)
else:
	print((b-a)**3+a**3)

Submission status: Runtime Error

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

mm=0
for i in range(1,n+1):
    if i%k==0:
        mm1+=1
    if i%k==k//2 and k%2==0:
        mm2+=1

print(mm1**3+mm2**3)

Submission status: Runtime Error

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

mm=0
for i in range(1,n+1):
    if i%k==0:
        mm+=1
    if i%k==k//2 and k%2==0:
        mm+=1

print(C(mm**3))

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
import math
def d(n,r):
  return math.factorial(n)//math.factorial(r)//math.factorial(n-r)

if N<K:
  print(0)
else:  
  a=N//K
  ans=a
  if K%2==1:
    if a>=2:
      ans+=d(a,2)*6
    if a>=3:
      ans+=a*(a-1)*(a-2)
    print(ans)
  else:    
    if K*a+K//2<=N:
      b=a+1
    if a>=2:
      ans+=d(a,2)*6
      print(ans)
    if a>=3:
      ans+=a*(a-1)*(a-2)
    if b>=2:
      ans+=b+d(b,2)*6
    if b>=3:
      ans+=b*(b-1)*(b-2)

    print(ans)

Submission status: Runtime Error

Solution code:
def d(n,r):
  return factorial(n)//factorial(r)//factorial(n-r)

if N<K:
  print(0)
else:  
  a=N//K
  ans=a
  if K%2==1:
    if a>=2:
      ans+=d(a,2)*6
    if a>=3:
      ans+=a*(a-1)*(a-2)
    print(ans)
  else:    
    if K*a+K//2<=N:
      b=a+1
    if a>=2:
      ans+=d(a,2)*6
      print(ans)
    if a>=3:
      ans+=a*(a-1)*(a-2)
    if b>=2:
      ans+=b+d(b,2)*6
    if b>=3:
      ans+=b*(b-1)*(b-2)

    print(ans)

Submission status: Runtime Error

Solution code:
N, K = (int(i) for i in input().split())  

def dfs(a, b, c):
  lis = [''.join([str(a), str(b), str(c)])]
  if max(a, b, c) > N:
    return []
  
  lis += dfs(a + K, b, c)
  lis += dfs(a, b + K, c)
  lis += dfs(a, b, c + K)
  return lis

ans = 0
l = []
if K % 2 == 0:
  l += dfs(K//2, K//2, K//2)
  l += dfs(K, K, K)
else:
  l += dfs(K, K, K)

print(len(set(l)))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
num=[0]*k
for i in range(n):
    num[i%k]+=1
for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k!=0:continue
    res+=num[a]*num[b]*num[c]
print(res)

Submission status: Runtime Error

Solution code:
gsg

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
N_d = N*2
ans = 0
kl = [K*x for x in range(1,N_d//K+1)]
s=kl[-1]
t=kl[-2]
if K%2==1:
  a=s//K
  if a%2==0:
    b = a//2
    ans = pow(b,3)
    
  else:
    b=a//2
    ans = pow(b,3)+3
    
else:
  half_K = K//2
  a = s//K
  if a%2==0:
    b = a//2
    ans+=pow(b,3)
  else:
    b=a//2
    ans += pow(b,3)+3
    
  b = t//K
  if b%2==0:
    c = b//2
    ans+=pow(c,3)
  else:
    c=b//2
    ans+=pow(b,3)+3
  
print(ans)

Submission status: Runtime Error

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

k = k // 2
x = n // k
if x % 2 == 0:
    ans = 2 * (x / 2) ** 3
else:
    ans = ((x // 2) + 1) ** 3 + (x // 2) ** 3

print(ans)

Submission status: Runtime Error

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

k = k // 2
x = n // k
if x % 2 == 0:
    ans = 2 * (x / 2) ** 3
else:
    ans = ((x // 2) + 1) ** 3 + (x // 2) ** 3

print(int(ans))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
num=n//k
last=n%k
if last==0:
  print((num**3)*(k+2)*(k+1)//2)
else:
  totl=(num**3)*(k+2)*(k+1)//2
  for i in range(1,last+1):
    totl+=(k-j+2)*(k-j+1)
  print(totl)

Submission status: Runtime Error

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

ev = 0
ev2 = 0
od = 0
if K % 2 == 1:
    print((N//K)**3)
else:
    ans = N//K
    for i in range(1,N+1):
        if i % (K//2):
            t += 1
    print(ans + t**3)

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
ans = 0
a = [0]
b = [0]
c = [0]
for i in range(N):
    a[i] = i+1
    b[i] = i+1
    c[i] = i+1

ev = 0
ev2 = 0
od = 0
if K % 2 == 1:
    for i in range(N):
        if i % K == 0:
            od += 1

    print(od**3)
else:
    for i in range(N):
        if i % K == 0:
            ev += 1
        if i % (K/2) == 0:
            ev2 += 1
        if i % K == 0 and i % (K/2) == 0:
            od += 1
    ans = ev**3 + ev2**3 - od**3
    print(ans)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
if k % 2 == 1:
    print((n // k) ** 3)
else:
    print((n // k) ** 3 + ((n + k // 2) // k) ** 3)

Submission status: Runtime Error

Solution code:
import math

n,k=map(int,input().split())
if k%2!=0:
  nums=math.ceil(n/k)
  print(nums*3)
 
else:
  nums1=math.ceil(2*n/k)
  if nums1%2==0:
    a=int(nums1/2)
    b=nums1-a
    print(a**3+b**3)
    
    
  elif nums1%2!=0:
    a=int((num-1)/2)
    b=nums1-a
    print(a**3+b**3)

Submission status: Runtime Error

Solution code:
n, k = [int(a) for a in input().split()]
cnt = 0
for a in range(1, n / 2 + 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: Runtime Error

Solution code:
n,k = map(int, input().split())
count0 = 0
count1 = 0
for i in range(1,n+1):
    if i%k==0:
        count0+=1
    if i%k==k/2:
        count+=1

if k%2==0:
    print(count0**3+count1**3)
else:
    print(count0**3)

Submission status: Runtime Error

Solution code:
# 2019/09/10
# かんにんぐ

n,k=map(int,input().split())
cnt=0
num=[0]*(n+1)
for i in range(1,n+1):
    num[i%k]+=1

for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k:continue
    cnt+=num[a]*num[b]*num[c]
    
print(cnt)

Submission status: Runtime Error

Solution code:
import math

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

def check():
    a = []
    b = []
    count = 0
    bDict = {}
    bDict2 = {}
    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)
    count += len(a)
    
    while a != []:
        temp = a[0]
        for i in a:
            #print(i)
            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 += 3*permutations_count(bDict2[i], 2)
        if bDict2[i] > 2:
            count += permutations_count(bDict2[i], 3)

    print(count)
check()

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
mod0 = []
mod2 = []
for i in range(1, n + 1):
    if i % k == 0:d i % k == k // 2:
        mod2.append(i)
print(len(mod0) * len(mod0) * len(mod0) + len(mod2) * len(mod2) * len(mod2))

Submission status: Runtime Error

Solution code:
global ans, n, k
n,k = map(int, input().split())
ans = 0
temp = [0,0,0]

def create_nums(a, b, c):
    
    global ans, k, n
    if a > n or b > n or c > n:
        return 0

    if k % 2 == 0:
        create_nums(a+k//2, b+k//2, c+k//2)
    create_nums(a+k,  b, c)
    create_nums(a,  b+k, c)
    create_nums(a,  b, c+k)
    
if k % 2 == 0:
    create_nums(k//2, k//2 ,k//2)
    print(ans/2)
else:
    create_nums(k, k ,k)
    print(ans)

Submission status: Runtime Error

Solution code:
import itertools
N,K=map(int,input().split())
L=range(1,N+1)
T=0
for i in itertools.permutations(L, r=3):
  int(a,b,c) for a,b,c in i:
    if a+b%K==0 and b+c%K==0 and c+a%K==0:
      T+=1
print(T)

Submission status: Runtime Error

Solution code:
n, k  =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 += even
  
print(ans)

Submission status: Runtime Error

Solution code:
n, k  =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 ofr i in range(k//2, n+1, k)]
  ans += even
  
print(ans)

Submission status: Runtime Error

Solution code:
N,K = list(map(int,input().split()))
D = N//(K//2) - N//K
print(int((N//K)**3) if K%2 == 1 else int((N//K)**3)+int(D**3))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N, K = list(map(int, input().split()))
if K % 2 == 0:
    num = (N//K)**3 + (N//int(K/2)-N//K)**3
else:
    k = int(K)
    num = (N//k)**3

print(num)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
print((N//K)**3+((K+1)%2)*(N//K+(N-(N//K)*K)//(K//2))**3)

Submission status: Runtime Error

Solution code:
costs = [2,5,5,4,5,6,3,7,6]

N, M = map(int, input().split())
A = list(map(int, input().split()))
neginf = -1 * 1e10
D = [neginf]*(N+1)

def dp(n_match):
    D[0] = 0
    for n in range(1,n_match+1):
        arr = [D[n-costs[a-1]] if n-costs[a-1]>=0 else neginf for a in A]
        D[n] = max(arr)+1

def main():
    dp(N)
    n = N
    ans = ''
    while n>0:
        for a in A:
            arr = [a for a in A if D[n-costs[a-1]]==D[n]-1]
        a = max(arr)
        ans += str(a)
        n -= costs[a-1]
    print(ans)

main()

Submission status: Runtime Error

Solution code:
def solve(N, K):
    ans = 0
    k = len([n for n in range(1, N + 1) if n % K == 0])
    ans += k * k * k
    if K % 2 == 0:
        k = len([n for n in range(1, N + 1) if n % K == K // 2])
        ans += k * k * k

    return ans

if __name__ == "__main__":
    N, K = tuple(map(int, input(" ")))
    print(solve(N, K))

Submission status: Runtime Error

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

bai = 1
k_arr = []
while bai * k <= n:
    k_arr.append(bai * k)
    bai += 1


if k % 2 == 0:
    bai2 = 1
    k_arr2 = []
    while bai2 * k/2 <= n:
        k_arr2.append(bai2 * k/2)
        bai2 += 1
        k_arr2_len = len(k_arr2) - len(k_arr)
    print(len(k_arr)*len(k_arr)*len(k_arr) + k_arr2_len*k_arr2_len*k_arr2_len)

else:
    print(len(k_arr)*len(k_arr)*len(k_arr))

Submission status: Runtime Error

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

if k == 1:
    print(0)
    sys.exit()

bai = 1
k_arr = []
while bai * k <= n:
    k_arr.append(bai * k)
    bai += 1


if k % 2 == 0:
    bai2 = 1
    k_arr2 = []
    while bai2 * k/2 <= n:
        k_arr2.append(bai2 * k/2)
        bai2 += 1
        k_arr2_len = len(k_arr2) - len(k_arr)
    print(len(k_arr)*len(k_arr)*len(k_arr) + k_arr2_len*k_arr2_len*k_arr2_len)

else:
    print(len(k_arr)*len(k_arr)*len(k_arr))

Submission status: Runtime Error

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


bai = 1
k_arr = []
while bai * k <= n:
    k_arr.append(bai * k)
    bai += 1


if k % 2 == 0:
    bai2 = 1
    k_arr2 = []
    while bai2 * k/2 <= n:
        k_arr2.append(bai2 * k/2)
        bai2 += 1
        k_arr2_len = len(k_arr2) - len(k_arr)
        
    print(k_arr2_len)
    print(len(k_arr)*len(k_arr)*len(k_arr) + k_arr2_len*k_arr2_len*k_arr2_len)

else:
    print(len(k_arr)*len(k_arr)*len(k_arr))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
 
if K % 2:
  print(pow(int(N / K), 3)
else:
  even = int(N / K)
  odd = int(N / int(K / 2)) - even
  print(even, odd)
  print(pow(even, 3) + pow(odd, 3))

Submission status: Runtime Error

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

if N % 2:
  print(int(N / K))
else:
  even = int(N / K)
  odd = int(N / int(K / 2)) - even
  print(pow(even, 2) + pow(odd, 2))

Submission status: Runtime Error

Solution code:
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
a,b  = ma()
x = lma()
ans = 10 **18
for i in range(a-b+1):
    a0 = x[i]
    ab = x[i+b-1]
    if ab< 0 :
        ans = min(ans,ab)
    elif a0 <=0 and 0 <= ab:
        ans = min(ans, ab-2*a0, 2*ab-a0)
    else:
        ans = min(ans,ab)
print(ans)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
if K % 2 == 0:
    a = N // K 
    b = N // (k / 2) - a 
    print(a**3 + b ** 3)
else:
    a = N // K
    print(a**3)

Submission status: Runtime Error

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

mod = [i for i in range(K, N+1, K)]
ans += len(mod) ** 3

if K % 2 == 0:
    items = [i for i in range(K//2, N+1, K)]
    ans += len(items)

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding; utf-8 -*-
N,K = map(int,input().split())
for i in range(N):
  for j in range(N):
    for k in range (N)
      S , T , U = i+j,j+k,k+i
      
a = []
if i+j % K == 0 and j+k % K == 0 and k+i % K == 0:
  a.append(1)
print(sum(a))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
o=n//k
p=0
if (k%2==0) p=(n+(k//2))//k
print(o**3+p**3)

Submission status: Runtime Error

Solution code:
import collections
n,k=list(map(int,input().split()))
l_n=[(v+1)%k for v in range(n)]
c = collections.Counter(l_n)
m = len(c)
ret=0
if k%2==0:
    for i in range(0,m,k/2):
        for j in range(0,m,k/2):
            if (i+j)%k==0:
                for r in range(0,r,k/2):
                    if(i+r)%k==0 and(r+j)%k==0:
                        ret+=c[i]*c[j]*c[r]
else:
    for i in range(0,m,k):
        for j in range(0,m,k):
            if (i+j)%k==0:
                for r in range(0,m,k):
                    if (i+r)%k ==0 and (r+j)%k==0:
                        ret+=c[i]*c[j]*c[r]
print(ret)

Submission status: Runtime Error

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

ks = [x for x in range(1, n+1) if x % k == 0]
k2s = [x for x in range(1, n+1) if x % (k//2) == 0 and x % k != 0] 

if k % 2 == 0: # if even
    print(len(ks) ** 3 + len(k2s) ** 3)
else:
    print(len(ks) ** 3)

Submission status: Runtime Error

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

ks = [x for x in range(1, n+1) if x % k == 0]
k2s = [x for x in range(1, n+1) if x % (k//2) == 0]

if k % 2 == 0: # if even
    print(len(k2s))
else:
    print(len(ks))

Submission status: Runtime Error

Solution code:
%%test_input https://abc108.contest.atcoder.jp/tasks/abc108_c
N, K = map(int, input().split())
ans = sum(((N + a % K) // K)**2 for a in range(1, N + 1) if (2 * a) % K == 0)
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8

input_lines=input().split()

N=int(input_lines[0])
X=int(input_lines[1])

city=input().split()

D_list=[]
ans_list=[]

def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a


for i in range(0,N-1):
    temp=gcd(abs(X-int(city[i])),abs(X-int(city[i+1])))
    D_list.append(temp)

    #if D_list[-1] not in temp:
    #    temp.append(D_list[-1])

    for j in range(N):
        if abs(int(city[j])-X) % D_list[-1]!=0:
            D_list.pop()
            break

print(max(D_list))

Submission status: Runtime Error

Solution code:
# coding: utf-8

input_lines=input().split()

N=int(input_lines[0])
X=int(input_lines[1])

city=input().split()

D_list=[]
ans_list=[]

def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a


for i in range(N):
    temp=abs(X-int(city[i]))
    D_list.append(temp)

    #if D_list[-1] not in temp:
    #    temp.append(D_list[-1])

    for j in range(N):
        if abs(int(city[j])-X) % D_list[-1]!=0:
            D_list.pop()
            break

print(max(D_list))

Submission status: Runtime Error

Solution code:
n, k= map(int, input().split())
cnt=[0]*n
for i in range(1,n+1):
    cnt[i%k]+=1
ans=0
for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k==0:
        ans+=cnt[a]*cnt[b]*cnt[c]
print(ans)

Submission status: Runtime Error

Solution code:
s = input().split()
N = int(s[0])
K = int(s[1])

ans = N // K 

if K % 2 == 0:
  ans = ans + N//(K%2)

print(ans**3 )

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
m=[0]*n
for i in range(1,n+1):m[i%k]+=1
print(m[0]*3+[m[k//2]*3,0][k%2])

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
print(int(N/K)**3+[int((N+K/2)/K)**3][K%2])

Submission status: Runtime Error

Solution code:
def is calc(N, K):
  count = 0
  for a in range(1, N):
    for b in range(1, N):
      c = N - a - b
      if c > 0:
        if a + b % N == 0 and b + c % N == 0 and a + c % N == 0:
          count += 1
  return count

if __name__ == '__main__':
  N, K = map(int, input().split())
  print(calc(N, K))

Submission status: Runtime Error

Solution code:
l = list(map(int, input().split()))
N = int(l[0])
K = int(l[1])
R1 = (N // K)
R2 = (N // (K // 2))
if K % 2 == 1:
  print(R1**3)
else:
  print(R2**3 - R2 * 5 - 3)

Submission status: Runtime Error

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

# N, K = 3, 2

if K % 2 != 0:
    ans = (N // K)**3
else:
    full = []
    half = []
    for i in range(int(K/2), N+1, int(K/2)):
        if i % K == 0:
            full.append(i)
        else:
            half.append(i)

    ans += len(half) ** 3 + len(full) ** 3

print(ans)

Submission status: Runtime Error

Solution code:
N, K = (int(i) for i in input().split())
D = 0
for i in range([1], [N + 1]):
    for j in range([1], [N + 1]):
        A = i + j
        if A % K == 0:
            for j in range([1], [N + 1]):
                for k in range([1], [N + 1]):
                    B = j + k
                    C = i + k
                    if B % K == 0 and C % K == 0:
                        D += 1
print(D)

Submission status: Runtime Error

Solution code:
count=0
index=k//2
while index<=n:
    a=index
    index2=0
    index+=1
    index2=k-a
    while index2<=n:
        b=index2
        if (a+b)%k!=0:
            index2+=1
        else:
            index3=k-a
            index2+=1
            while index3<=n:
                c=index3
                if(a+c)%k==0 and (b+c)%k==0:
                    if a==b and b==c:
                        count+=1
                    elif a!=b and b!=c and c!=a:
                        count+=6
                    else:
                        count+=3
                    index3+=1
                else:
                    pass
                    index3+=1
print(count)

Submission status: Runtime Error

Solution code:
import math
n, k = map(int, input().split())
a = int(n/k)
if(a < 2):
    b = 0
else:
    b = math.factorial(a) // (math.factorial(a - 2) * 2)
if(a < 3):
    c = 0
else:
    j = math.factorial(a-3)
    c = math.factorial(a) // j * 6
ans = a + b * 6 + c * 6
if(k % 2 == 0):
    t = int(k / 2)
    if(a * k + t > n):
      ans = ans * 2
    else:
      d = a + 1
      if(d < 2):
          e = 0
      else:
          e = math.factorial(d) // j * 2
      if(d < 3):
          f = 0
      else:
          f = math.factorial(d) // (math.factorial(d - 3) * 6)
      ans += (d + e * 6 + f * 6)
print(ans)

Submission status: Runtime Error

Solution code:
N, K = (int(i) for i in input().split())
D = 0
for i in range(1, [N + 1]):
    for j in range(1, [N + 1]):
        A = i + j
        if A % K == 0:
            for j in range(1, [N + 1]):
                for k in range(1, [N + 1]):
                    B = j + k
                    C = i + k
                    if B % K == 0 and C % K == 0:
                        D += 1
print(D)

Submission status: Runtime Error

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

if k%2==0:
  a=int(2*n/k)
  if a%2==0:
    b=a/2
    print(2*b*b*b)
  else:
    b=int(b/2)
    print(b*b*b+(b+1)*(b+1)*(b+1))
else:
  a=int(n/k)
  if a%2==0:
    b=a/2
    print(2*b*b*b)
  else:
    b=int(b/2)
    print(b*b*b+(b+1)*(b+1)*(b+1))

Submission status: Runtime Error

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

if K % 2 != 0:
    ans = (N // K)**3
else:
    full = []
    for i in range(K, N, K):
        full.append(i)
        ans = len(full) ** 3

    half = []
    for i in range(int(K/2), N, int(K/2)):
        half.append(i)
        half = list(set(half) - set(full))
        ans += len(half) ** 3

print(ans)

Submission status: Runtime Error

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


cnt = {}

if K == 2:
    up = 1
else:
    up =K

for a in range(0,N+1,up):
    for b in range(0,N+1,up):
        for c in range(0,N+1,up):

            if (a+b+c) < K:
                continue
            if a == 0 or b == 0 or c == 0:
                continue
            if (a+b)%K == 0 and (b+c)%K == 0 and (c+a)%K == 0:
                ans += 1
                cnt[str(a) + "," + str(b) + "," + str(c)] = 0

print(len(cnt))

Submission status: Runtime Error

Solution code:
input = input().split()
N = int(input[0])
K = int(input[1])
target = K

for i in range(1,N+1):
    print("******")
    print(i)
    print("------")
    n1 = i
    multiple1 = K
    while(multiple1 < N+1):
        n2 = multiple1 - i
        multiple1 += K
        if(n2<N and n2!=0):

            multiple2 = K
            while(multiple2 < N+1):
                n3 = multiple2 - n2
                multiple2 += K
                if((n1+n3)%K == 0 && n3>0):
                    print(n1, end="")
                    print(" ", end="")
                    print(n2, end="")
                    print(" ", end="")
                    print(n3, end="")
                    print(" ")
                    print("success")

Submission status: Runtime Error

Solution code:
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	if a[0]%a[1] < a[1] // 2:
		print ((a[0]//a[1])**3 + ((a[0]//a[1])**3))
	else:
		print ((1 + a[0]//a[1])**3 + ((a[0]//a[1])**3))

Submission status: Runtime Error

Solution code:
#include <cstdio>
#include <algorithm>
using std::max;
#ifdef LOCAL
#include <ctime>
#endif

int MOD(int x,int y)
{
    return x-y*(x/y);
}
int main(void)
{
#ifdef LOCAL
    clock_t startTime=clock();
#endif
    int N,a[3],K,counter=0;
    scanf("%d%d",&N,&K);
    for(a[0]=1;a[0]<=N;a[0]++)
    {
        if(K-a[0]>0)
        {
            for(a[1]=K-a[0];a[1]<=N;a[1]+=K)
            {
                if(K-a[1]>0)
                    for(a[2]=K-a[1];a[2]<=N;a[2]+=K)
                    {
                        if(MOD(a[2]+a[0],K)==0)
                        {
    //                        printf("%d,%d,%d\n",a[0],a[1],a[2]);
                            counter++;
                        }
                    }
            }
        }
    }
    printf("%d\n",counter);
#ifdef LOCAL
    printf("\t[RUNTIME=%3d ms.]\n",clock()-startTime);
#endif
    return 0;
}

Submission status: Runtime Error

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

if K % 2 == 0:
	ans1 = N // K
	if (N % K) >= (K // 2):
		ans2 = ans1 + 1
	else:
		ans2 = ans1s
	ans = (ans1 ** 3) + (ans2 ** 3)
else:
	ans = (N // K)**3

print(ans)

Submission status: Runtime Error

Solution code:
n, k = [int(i) for i in input().split()]

ans = [0, 0]

for i in range(1, n+1):
    if k % 2 == 0 and i % k == d:
        ans[0] += 1
    if i % k == 0:
        ans[1] += 1

print(ans[0] ** 3 + ans[1] ** 3)

Submission status: Runtime Error

Solution code:
from math import ceil
a = [int(i) for i in input().split()]
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	print (math.ceil(a[0]/(a[1]))**3 + ((a[0]//a[1])**3))

Submission status: Runtime Error

Solution code:
import math
s = input().split

N = int(s[0])
K = int(s[1])

ct = 0

u = math.ceil(2*N/K)

def cond_e(a, b, c):
  if a+b-c > 0 and a-b+c > 0 and -a+b+c > 0 and a+b-c <= 2*N%K and a-b+c <= 2*N%K and -a+b+c <= 2*N%K:
    return True
  else:
    return False
  
def cond_o(a, b, c):
  if a+b-c > 0 and a-b+c > 0 and -a+b+c > 0 and a+b-c <= 2*N%K and a-b+c <= 2*N%K and -a+b+c <= 2*N%K and (a+b-c)%2 == 0 and (a-b+c)%2 == 0 and (-a+b+c)%2 == 0:
    return True
  else:
    return False

for a in range(u):
  for b in range(u):
    for c in range(u):
      if K%2 == 0 && cond_e(a, b, c):
        ct += 1
      elif k%2 != 0 && cond_o(a, b, c):
        ct += 1

print(str(ct))

Submission status: Runtime Error

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

num = n // k
num2 = n // (k//2) - num

if k % 2 == 0:
    print(num ** 3 + num2 ** 3)
else:
    print(num ** 3)

Submission status: Runtime Error

Solution code:
31415 9265