Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys

def f(s):
    if s=="A":
        return 0
    elif s=="B":
        return 1
    else:
        return 2

S=list(map(f,input()))
N=len(S)

if N<=2:
    print(0)
    sys.exit()

T=0
F=True
while F:
    F=False
    for i in range(N-2):
        if (S[i]==0) and (S[i+1]==1) and (S[i+2]==2):
            T+=1
            S[i],S[i+1],S[i+2]=1,2,0
            F=F or True

print(T)
            


### FIXED CODE ###

import sys

def f(s):
    if s=="A":
        return 0
    elif s=="B":
        return 1
    else:
        return 2

S=list(map(f,input()))
N=len(S)

if N<=2:
    print(0)
    sys.exit()

T=0
U=0

I=0
K=0
while I<N-2:
    if (S[I]==0) and (S[I+1]==1) and (S[I+2]==2):
        U+=1
        T+=U
        I+=3
    elif S[I]==0:
        U+=1
        I+=1
    elif (S[I]==1) and (S[I+1]==2):
        T+=U
        I+=2
    else:
        U=0
        I+=1

if (S[-2]==1 and S[-1]==2) and S[-3]!=0:
    T+=U
    
print(T)
### BUGGY CODE ###

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

a = [0]*5
n = int(input())
a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())

b = [0] * 6
b[0] = n

cnt = 0
def move():
    global b,cnt
    c = b[:]
    if b[0] < a[0]:
        c[0] -= b[0]
        c[1] += b[0]
    else:
        c[0] -= a[0]
        c[1] += a[0]
    if b[1] < a[1]:
        c[1] -= b[1]
        c[2] += b[1]
    else:
        c[1] -= a[1]
        c[2] += a[1]
    if b[2] < a[2]:
        c[2] -= b[2]
        c[3] += b[2]
    else:
        c[2] -= a[2]
        c[3] += a[2]
    if b[3] < a[3]:
        c[3] -= b[3]
        c[4] += b[3]
    else:
        c[3] -= a[3]
        c[4] += a[3]
    if b[4] < a[4]:
        c[4] -= b[4]
        c[5] += b[4]
    else:
        c[4] -= a[4]
        c[5] += a[4]
    b = c[:]
    cnt += 1
    if b[5] == n:
        return True
    else:
        return False

reached = False
while(not reached):
    reached = move()

print(cnt)


### FIXED CODE ###

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

a = [0]*5
n = int(input())
a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())

bottle = min(a[0],a[1],a[2],a[3],a[4])

time = 0

if n % bottle == 0:
    time = int(n / bottle)
else:
    time = int(n // bottle) + 1

if bottle >= n:
    print(5)
else:
    print(time+4)
### BUGGY CODE ###

N, M = list(map(int, input().strip().split(' ')))
k = abs(N-M)
def kaijou(n):
  if n == 0:
    return(1)
  else:
    c = 1
    while n != 1:
      c *= n
      n -= 1
    return(c)
if k > 1:
  print(0)
elif k == 1:
  ans = (kaijou(N)*kaijou(M))%(10**9+7)
  print(ans)
elif k == 0:
  ans = (kaijou(N)*kaijou(M)*2)%(10**9+7)
  print(ans)
  

### FIXED CODE ###

import math
N, M = list(map(int, input().strip().split(' ')))
k = abs(N-M)
if k > 1:
  print(0)
elif k == 1:
  ans = (math.factorial(N)*math.factorial(M))%(10**9+7)
  print(ans)
elif k == 0:
  ans = (math.factorial(N)*math.factorial(M)*2)%(10**9+7)
  print(ans)
### BUGGY CODE ###

n = int(input())
T=[int(input()) for i in range(n)]
T = sorted(T,reverse=True)

a = T[0]
i =1
while True:
  if sum(map(lambda x:T[0]%x, T)) !=0:
    T[0] += a
  else:
    print(T[0])
    exit()
  i += 1

### FIXED CODE ###

n = int(input())
T=[int(input()) for i in range(n)]


def euclid(a,b):
  r = a % b
  return euclid(b,r) if r else b

def lcm(a,b):
  return a * b //euclid(a,b)

num = T[0]
for i in range(1,n):
  num = lcm(num, T[i])
print(num)
### BUGGY CODE ###

N,M = list(map(int,input().split()))
x = []
y = []

for i in range(M):
    u,v = map(int,input().split())
    x.append(u-1)
    y.append(v-1)
    
red = [0]
mas = [1 for i in range(N)]

for j in range(M):
    mas[x[j]] -= 1
    mas[y[j]] += 1
    if x[j] in red:
        if y[j] not in red:
            red.append(y[j])
        if mas[x[j]] == 0:
            red.remove(x[j])

print(len(red))


### FIXED CODE ###

N,M = list(map(int,input().split()))
x = []
y = []
red = [0 for i in range(N)]
mas = [1 for i in range(N)]
red[0] = 1

for i in range(M):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    mas[x] -= 1
    mas[y] += 1
    if red[x] == 1:
        if red[y] == 0:
            red[y] = 1
        if mas[x] == 0:
            red[x] = 0

print(sum(red))
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    N,K = map(int,input().split())
    a = list(map(int,input().split()))
    f = list(map(int,input().split()))
    a.sort()
    f.sort(reverse = True)
    def func(x):
        count = 0
        for co,ha in zip(a,f):
            tr = x//ha
            if co <= tr:
                continue
            count += co-tr
        if K < count:
            return True
        else:
            return False
    l,r = -1,a[-1]*f[0]+1
    while r-l > 1:
        mid = (l+r)//2
        if func(mid):
            l = mid
        else:
            r = mid
            
    print(r)
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N,K = map(int,input().split())
    a = list(map(int,input().split()))
    f = list(map(int,input().split()))
    a.sort()
    f.sort(reverse=True)

    if sum(a) <= K:
        print(0)
    else:
        a = np.array(a)
        f = np.array(f)
        left,right = 0,max(a)*max(f)
        while right-left > 1:
            mid = (left+right)//2
            pra = a-mid//f
            pra[pra<0] = 0
            if np.sum(pra) > K:
                left = mid
            else:
                right = mid
        print(right)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

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

ans_list = []

for i in range(n + 1):
  #print(int((a * i) / b), a * int(i / b), int((a * i) / b) - a * int(i / b))
  ans = int((a * i) / b) - a * int(i / b)
  ans_list.append(ans)
print(max(ans_list))



### FIXED CODE ###

# -*- coding: utf-8 -*-
# x = p * b + q
# 0 <= q < b
# int(a * p + a * q / b) - a * int(p - q / b)
# = a * p + int(a * q / b) - a * p
# = int(a * q / b)

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

print(a * min(b - 1, n) //  b)
### BUGGY CODE ###

temp = input().split(" ")
N = int(temp[0])
M = int(temp[1])
H = input().split(" ")
good = list(range(N))
for i in range(M):
    root = input().split(" ")
    a = int(root[0])-1
    b = int(root[1])-1
    if H[a]>H[b]:
        try:
            good.remove(b)
        except ValueError:
            pass
    elif H[a]<H[b]:
        try:
            good.remove(a)
        except ValueError:
            pass
    else:
        try:
            good.remove(a)
        except ValueError:
            pass
        try:
            good.remove(b)
        except ValueError:
            pass
print(len(good))

### FIXED CODE ###

temp = input().split(" ")
N = int(temp[0])
M = int(temp[1])
H = input().split(" ")
good = [1] * N
for i in range(M):
    root = input().split(" ")
    a = int(root[0])-1
    b = int(root[1])-1
    if int(H[a])>=int(H[b]):
        good[b] = 0
    if int(H[a])<=int(H[b]):
        good[a] = 0
print(sum(good))
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
tmp = 1
for a in A:
    tmp *= a

print(tmp if tmp <= 10**18 else '-1')

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 1
if min(A) == 0:
    ans = 0
else:
    for a in A:
        ans *= a
        if ans > 10 ** 18:
            ans = '-1'
            break


print(ans)
### BUGGY CODE ###

from itertools import permutations
n,m,q=map(int,input().split())
a=[]
for i in range(q):
  a.append(list(map(int,input().split())))
ans=0
data=set([''.join(list(i)) for i in list(permutations('1'*(m-1)+'0'*n))])
for i in data:
  s=[1]*(n+m)
  cnt=0
  t=[]
  for j in range(n+m-1):
    if i[j]=='1':s[j]+=1
    else:t.append(s[j])
    s[j+1]=s[j]
  for x,y,z,w in a:
    if t[y-1]-t[x-1]==z:cnt+=w
  ans=max(ans,cnt)
print(ans)

### FIXED CODE ###

n,m,q=map(int,input().split())
e=[list(map(int,input().split())) for _ in range(q)]
ans=0
for i in range(1<<(m+n)):
  a=[1]
  for j in range(m+n):
    if (i>>j)&1:a[-1]+=1
    else:a+=[a[-1]]
    if a[-1]>m:
      flag=0
      break
    if len(a)>n:
      flag=1
      break
  else:flag=1
  if flag==0 or len(a)<n:continue
  cnt=0
  for s,t,u,v in e:
    if a[t-1]-a[s-1]==u:cnt+=v
  ans=max(ans,cnt)
print(ans)
### BUGGY CODE ###

from collections import deque

N, Q = map(int, input().split())
S = input()


ac_idx = deque()
for i in range(N-1):
    if S[i:i+2] == 'AC':
        ac_idx.append(i)

for _ in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for idx in ac_idx:
        if idx >= l-1 and idx+1 <= r-1:
            cnt += 1
    print(cnt)

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

ac_cnt = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        ac_cnt[i] = ac_cnt[i-1] + 1
    else:
        ac_cnt[i] = ac_cnt[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    ans = ac_cnt[r-1] - ac_cnt[l-1]
    print(ans)
### BUGGY CODE ###

import itertools
N = int(input())
stick = list(map(int, input().split()))
combi = itertools.combinations(stick, 3)
ans = [1 for a,b,c in combi if a < b+c and b < c+a and c < a+b]
print(len(ans))

### FIXED CODE ###

import time
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
#print(l)
#start = time.time()
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        #print(l[i], l[j],ab , c_index, j+1, res)
        res += c_index - j - 1
print(res)
### BUGGY CODE ###

h,w,m = map(int,input().split())
hw = [list(map(int,input().split()))for _ in range(m)]

tate = [0]*(h+1)
yoko = [0]*(w+1)

for x,y in hw:
    tate[x] += 1
    yoko[y] += 1

ans_x = []
ans_y = []
x_max = max(tate)
y_max = max(yoko)
for i in range(len(tate)):
    if tate[i] == x_max:
        ans_x.append(i)
for i in range(len(yoko)):
    if yoko[i] == y_max:
        ans_y.append(i)

ans = x_max + y_max
kaburi = True
for x in ans_x:
    for y in ans_y:
        if [x,y] in hw:
            continue
        else:
            kaburi = False
print(ans - int(kaburi))

### FIXED CODE ###

import sys
input = sys.stdin.readline
h,w,m = map(int,input().rstrip().split())
hw = [list(map(int,input().rstrip().split()))for _ in range(m)]

tate = [0]*(h+1)
yoko = [0]*(w+1)
bombpoint = set()

for x,y in hw:
    tate[x] += 1
    yoko[y] += 1
    bombpoint.add((x,y))

ans_x = []
ans_y = []
x_max = max(tate)
y_max = max(yoko)
for i in range(len(tate)):
    if tate[i] == x_max:
        ans_x.append(i)
for i in range(len(yoko)):
    if yoko[i] == y_max:
        ans_y.append(i)

ans = x_max + y_max
for x in ans_x:
    for y in ans_y:
        if (x,y) not in bombpoint:
            print(ans)
            exit()
print(ans - 1)
### BUGGY CODE ###

N, P = map(int, input().split())
S = list(input())

if P != 2 and P != 5:
    count = [0] * P
    ans = 0
    tmp = 0
    for i in range(N - 1, -1, -1):
        tmp += int(S[i]) * 10 ** (N - 1 - i)
        ans += count[tmp % P]
        count[tmp % P] += 1
    ans += count[0]

    # print (count)
    print (ans)

if P == 2:
    count = 0
    for index, s in enumerate(S):
        if int(s) % 2 == 0:
            count += (index + 1)
    print (count)

if P == 5: 
    count = 0
    for index, s in enumerate(S):
        if int(s) % 5 == 0:
            count += (index + 1)
    print (count)

### FIXED CODE ###

N, P = map(int, input().split())
S = list(input())

if P != 2 and P != 5:
    count = [0] * P
    ans = 0
    tmp = 0
    for i in range(N - 1, -1, -1):
        tmp += int(S[i]) * pow(10, (N - 1 - i), P)
        tmp %= P
        ans += count[tmp]
        count[tmp] += 1
    ans += count[0]

    # print (count)
    print (ans)

if P == 2:
    count = 0
    for index, s in enumerate(S):
        if int(s) % 2 == 0:
            count += (index + 1)
    print (count)

if P == 5: 
    count = 0
    for index, s in enumerate(S):
        if int(s) % 5 == 0:
            count += (index + 1)
    print (count)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
#隣接リスト
adjacent_list = [[] for i in range(n+1)]
#入力されたデータを保存しておくやつ
data = []
#最終的に色を入れておくやつ。
#edgedata[12] => 1->2の辺の色を入れておく
edgedata = {}
for i in range(n-1):
    a, b = list(map(int, input().split()))
    data.append([a,b])
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
#つながってるノードが一番多いやつを保存しておく
max_node = 0
#探索が終わったやつを入れる
finished = set()
for i in range(1,n):
    if len(adjacent_list[i]) > len(adjacent_list[max_node]):
        max_node = i
#kには色の種類を入れる
k = len(adjacent_list[max_node])
#print("k => {}".format(k))
def dfs(node, num):
    #隣接リストの中身を、つながってるノード順にソート
    node_list = sorted(adjacent_list[node], key = lambda x:len(adjacent_list[x]))
    #さっきつかったいろは使わないようにする
    color_list = [i for i in range(1,k+1) if i != num]
    c_i = 0
    finished.add(node)
    for i in node_list:
        #まだ見てなかったら、dfsを掛ける
        if i not in finished:
            s = min(node, i)
            t = max(node, i)
            #小さいほうから大きいほうに文字を並べ、ハッシュに値を保存
            #print("{}".format(color_list))
            #print("c_i =>{}  node =>{}".format(c_i,node))

            edgedata[(s, t)] = color_list[c_i]
            #color_list[c_i]は使ったので、使った色として引数で渡す。
            dfs(i, color_list[c_i])
            #この色は使ったから、一個ずらす
            c_i += 1
#一番のノードを根とし、dfsをかける
dfs(k,-1)
print(k)
for i in data:
    print(edgedata[tuple(i)])
#output k


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
#隣接リスト
adjacent_list = [[] for i in range(n+1)]
#入力されたデータを保存しておくやつ
data = [None] * (n - 1)
#最終的に色を入れておくやつ。
#edgedata[(1,2)] => 1->2の辺の色を入れておく
edgedata = {}
for i in range(n-1):
    a, b = list(map(int, input().split()))
    data[i] = [a, b]
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
#つながってるノードが一番多いやつを保存しておく
max_node = 0
#探索が終わったやつを入れる
finished = set()
for i in range(1,n):
    if len(adjacent_list[i]) > len(adjacent_list[max_node]):
        max_node = i
#kには色の種類を入れる
k = len(adjacent_list[max_node])
#print("k => {}".format(k))
def dfs(node, num):
    #隣接リストの中身を、つながってるノード順にソート
    node_list = sorted(adjacent_list[node], key = lambda x:len(adjacent_list[x]))
    #さっきつかったいろは使わないようにする
    color_list = [i for i in range(1,len(node_list) + 2) if i != num]
    c_i = 0
    finished.add(node)
    for i in node_list:
        #まだ見てなかったら、dfsを掛ける
        if i not in finished:
            #小さいほうから大きいほうに文字を並べ、ハッシュに値を保存
            #print("{}".format(color_list))
            #print("c_i =>{}  node =>{}".format(c_i,node))
            edgedata[(min(node, i), max(node, i))] = color_list[c_i]
            #color_list[c_i]は使ったので、使った色として引数で渡す。
            dfs(i, color_list[c_i])
            #この色は使ったから、一個ずらす
            c_i += 1
#一番のノードを根とし、dfsをかける
dfs(k,-1)
print(k)
for i in data:
    print(edgedata[tuple(i)])
#output k
### BUGGY CODE ###

R, G, B, N = [int(n) for n in input().split()]

count = 0
for r in range(N//R + 1):
    for g in range((N-r*R)//G + 1):
        b_ = N - (R * r + G * g) 
        if b_ % B == 0 and 0 <= b_ / B:
                count += 1

print(count)

### FIXED CODE ###

R, G, B, N = [int(n) for n in input().split()]

count = 0
for r in range(N//R + 1):
    for g in range((N-r*R)//G + 1):
        b_ = N - (R * r + G * g) 
        if b_ % B == 0:
                count += 1

print(count)
### BUGGY CODE ###

def slove():
    import sys
    input = sys.stdin.readline
    s = [int(v) if v != "?" else -1 for v in list(str(input().rstrip('\n')))]
    dp = [[0] * 13 for _ in range(2)]
    mod = 10 ** 9 + 7
    for i in range(len(s)):
        if s[-i-1] == -1:
            for j in range(10):
                if i == 0:
                    dp[1][j % 13] += 1
                else:
                    for k in range(13):
                        dp[1][((10 ** i) % 13 * j + k) % 13] += (dp[0][k] % mod)
        else:
            if i == 0:
                dp[1][s[-i-1] % 13] += 1
            else:
                for k in range(13):
                    dp[1][((10 ** i) % 13 * s[-i-1] + k) % 13] += (dp[0][k] % mod)
        for j in range(13):
            dp[0][j] = dp[1][j]
            dp[1][j] = 0
    print(dp[0][5] % mod)


if __name__ == '__main__':
    slove()


### FIXED CODE ###

def slove():
    import sys
    input = sys.stdin.readline
    s = [int(v) if v != "?" else -1 for v in list(str(input().rstrip('\n')))]
    dp = [[0] * 13 for _ in range(2)]
    mod = 10 ** 9 + 7

    for i in range(1):
        if s[-i-1] == -1:
            for j in range(10):
                dp[0][j % 13] += 1
        else:
            dp[0][s[-i - 1] % 13] += 1

    for i in range(1, len(s)):
        m = pow(10, i, 13)
        if s[-i-1] == -1:
            for j in range(10):
                mj = m * j
                for k in range(13):
                    dp[1][(mj + k) % 13] += dp[0][k]
        else:
            for k in range(13):
                dp[1][(m * s[-i-1] + k) % 13] += dp[0][k]
        for j in range(13):
            dp[0][j] = dp[1][j] % mod
            dp[1][j] = 0
    print(dp[0][5] % mod)


if __name__ == '__main__':
    slove()
### BUGGY CODE ###

import numpy as np

n = int(input())

L = list(map(int, input().split()))
L = sorted(L)

res = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        npl = np.array(L[j+1:])
        res += len(npl[npl<L[i]+L[j]])

print(res)

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
res = 0
for i in range(N):
    for j in range(i+1, N):
        idx = bisect_left(L, L[i]+L[j])
        res += max(0,idx-(j+1))
print(res)
### BUGGY CODE ###

import heapq
x, y, z, k = [ int(v) for v in input().split() ]
x_list = sorted([ int(v) for v in input().split() ], reverse = True)
y_list = sorted([ int(v) for v in input().split() ], reverse = True)
z_list = sorted([ int(v) for v in input().split() ], reverse = True)
check_list = [ [ [ False for i in range(x) ] for j in range(y) ]  for l in range(z)]
check_list_x, check_list_y, check_list_z = [ 0 for i in range(x) ], [ 0 for i in range(y) ], [ 0 for i in range(z) ]
cake_list = []

def maling_cake(a,b,c):
    d = x_list[a]+y_list[b]+z_list[c]
    return (-d,a,b,c)

for i in range(k):
    if i == 0:
        print(-maling_cake(0,0,0)[0])
        check_list[0][0][0] = 1
        if x > 1: 
            heapq.heappush(cake_list, maling_cake(1,0,0))
            check_list[1][0][0] = 1
        if y > 1: 
            heapq.heappush(cake_list, maling_cake(0,1,0))
            check_list[0][1][0] = 1
        if z > 1: 
            heapq.heappush(cake_list, maling_cake(0,0,1))
            check_list[0][0][1] = 1
        
    else:
        di, ai, bi, ci = heapq.heappop(cake_list)
        if ai < x - 1:
            if check_list[ai+1][bi][ci] == 0:
                heapq.heappush(cake_list, maling_cake(ai+1,bi,ci))
                check_list[ai+1][bi][ci] = 1
        if bi < y - 1:
            if check_list[ai][bi+1][ci] == 0:
                heapq.heappush(cake_list, maling_cake(ai,bi+1,ci))
                check_list[ai][bi+1][ci] = 1
        if ci < z - 1:
            if check_list[ai][bi][ci+1] == 0:
                heapq.heappush(cake_list, maling_cake(ai,bi,ci+1))
                check_list[ai][bi][ci+1] = 1

        print(-di)

### FIXED CODE ###


import heapq
x, y, z, k = [ int(v) for v in input().split() ]
x_list = sorted([ int(v) for v in input().split() ], reverse = True)
y_list = sorted([ int(v) for v in input().split() ], reverse = True)
z_list = sorted([ int(v) for v in input().split() ], reverse = True)

cake_list = []
num_set = set([0])

def hash2(a,b,c):
    return 10**8*a+10**4*b+c


def maling_cake(a,b,c):
    d = x_list[a]+y_list[b]+z_list[c]
    return (-d,a,b,c)

for i in range(k):
    if i == 0:
        print(-maling_cake(0,0,0)[0])
        if x > 1: 
            heapq.heappush(cake_list, maling_cake(1,0,0))
            num_set.add(hash2(1,0,0))
        if y > 1: 
            heapq.heappush(cake_list, maling_cake(0,1,0))
            num_set.add(hash2(0,1,0))
        if z > 1: 
            heapq.heappush(cake_list, maling_cake(0,0,1))
            num_set.add(hash2(0,0,1))
        
    else:
        di, ai, bi, ci = heapq.heappop(cake_list)
        if ai < x - 1:
            if hash2(ai+1,bi,ci) not in num_set:
                heapq.heappush(cake_list, maling_cake(ai+1,bi,ci))
                num_set.add(hash2(ai+1,bi,ci))
        if bi < y - 1:
            if hash2(ai,bi+1,ci) not in num_set:
                heapq.heappush(cake_list, maling_cake(ai,bi+1,ci))
                num_set.add(hash2(ai,bi+1,ci))
        if ci < z - 1:
            if hash2(ai,bi,ci+1) not in num_set:
                heapq.heappush(cake_list, maling_cake(ai,bi,ci+1))
                num_set.add(hash2(ai,bi,ci+1))
        print(-di)
### BUGGY 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)


### FIXED CODE ###

n,k=map(int,input().split())
#a%kを決めればb%kとc%kが決まる
cnt=0
ans=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

  cnt_a=0
  for a in range(a_mod,n+1,k):
    if a!=0:
      cnt_a+=1
  ans+=cnt_a**3
print(ans)
### BUGGY CODE ###

import numpy as np
import heapq

INF=10**14
N,M=map(int,input().split())
adj=[[] for i in range(N)]
for i in range(M):
    L,R,C=map(int,input().split())
    L-=1
    R-=1
    adj[L].append((R,C))
    adj[R].append((L,C))
for i in range(N-1):
    adj[i+1].append((i,0))
    
s=0
g=N-1
heap=[]
table=np.array([INF for i in range(N)])
table[s]=0
heapq.heappush(heap,(s,table[s]))
                
while heap:
    q=heapq.heappop(heap)
    a=q[0]
    if q[1]>table[a]: continue
    for ne in adj[a]:
        p=ne[0]
        co=ne[1]
        if table[p]>table[a]+co:
            table[p]=table[a]+co
            heapq.heappush(heap,(p,table[p]))
ans=table[g]
if ans==INF:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import numpy as np
import heapq

INF=10**15
N,M=map(int,input().split())
adj=[[] for i in range(N)]
for i in range(M):
    L,R,C=map(int,input().split())
    L-=1
    R-=1
    adj[L].append((R,C))
    adj[R].append((L,C))
for i in range(N-1):
    adj[i+1].append((i,0))
    
s=0
g=N-1
heap=[]
table=np.array([INF for i in range(N)])
table[s]=0
heapq.heappush(heap,(table[s],s))
                
while heap:
    q=heapq.heappop(heap)
    a=q[1]
    if q[0]>table[a]: continue
    for ne in adj[a]:
        p=ne[0]
        co=ne[1]
        if table[p]>table[a]+co:
            table[p]=table[a]+co
            heapq.heappush(heap,(table[p],p))
ans=table[g]
if ans==INF:
    print(-1)
else:
    print(ans)