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

H,W=map(int,input().split())
s=[]
for i in range(H):
    si=[]
    Si=input()
    for j in range(W):
        si.append(Si[j]=='.')
    s.append(si)

# 左に照らした場合 行ごとに見てゆく
L=[[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if j==0 and s[i][j]:
            L[i][j]=1
        elif s[i][j]:
            L[i][j]=L[i][j-1]+1

# 右に照らした場合 行ごとに見てゆく
R=[[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in reversed(range(W)):
        if j==W-1 and s[i][j]:
            R[i][j]=1
        elif s[i][j]:
            R[i][j]=R[i][j+1]+1

# 上に照らした場合 列ごとに見てゆく
U=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in range(H):
        if i==0 and s[i][j]:
            U[i][j]=1
        elif s[i][j]:
            U[i][j]=U[i-1][j]+1

# 下に照らした場合 列ごとに見てゆく
D=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in reversed(range(H)):
        if i==H-1 and s[i][j]:
            D[i][j]=1
        elif s[i][j]:
            D[i][j]=D[i+1][j]+1

ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

### FIXED CODE ###

H,W=map(int,input().split())
s=[]
for i in range(H):
    si=[]
    Si=input()
    for j in range(W):
        si.append(Si[j]=='.')
    s.append(si)

# 左に照らした場合 行ごとに見てゆく
L=[[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if j==0 and s[i][j]:
            L[i][j]=1
        elif s[i][j]:
            L[i][j]=L[i][j-1]+1

# 右に照らした場合 行ごとに見てゆく
R=[[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in reversed(range(W)):
        if j==W-1 and s[i][j]:
            R[i][j]=1
        elif s[i][j]:
            R[i][j]=R[i][j+1]+1

# 上に照らした場合 列ごとに見てゆく
U=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in range(H):
        if i==0 and s[i][j]:
            U[i][j]=1
        elif s[i][j]:
            U[i][j]=U[i-1][j]+1

# 下に照らした場合 列ごとに見てゆく
D=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in reversed(range(H)):
        if i==H-1 and s[i][j]:
            D[i][j]=1
        elif s[i][j]:
            D[i][j]=D[i+1][j]+1

ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

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

# -*- coding: utf-8 -*-
#ABC137C
import copy
import sys
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))
#k=hoge[0]
#x=hoge[1]

list = [[0 for i in range(26)] for j in range(n)]
#list[0][1]=1
#print(list)

hash=[]
for i in range(0,300):
	hash.append([])

for i in range(0,n):
	tmp=input()
	hoge=0
	for j in range(0,10):
		list[i][ord(tmp[j])-ord("a")]+=1
		hoge+=ord(tmp[j])-ord("a")
	hoge=hoge%300
	hash[hoge].append(i)
#print(hash)

sum=0

for i in range(0,300):
	for j in range(0,len(hash[i])-1):
		for k in range(j+1,len(hash[i])):
			#print(i)
			#print(hash[i][j])
			#print(hash[i][k])
			for m in range(0,26):
				if(list[hash[i][j]][m]!=list[hash[i][k]][m]):
					break
				elif(m==25):
					sum+=1


#for i in range(0,n-1):
#	for j in range(i+1,n):
#		for k in range(0,26):
#			if(list[i][k]!=list[j][k]):
#				break
#			elif(k==25):
#				sum+=1

print(sum)

#print(list)
#print(list[0][:])



### FIXED CODE ###

# -*- coding: utf-8 -*-
#ABC137C
import copy
import sys
import math

n = int(input())
fuga = [0 for i in range(10)]

wordlist={}
for i in range(0,n):
	tmp=input()
	for j in range(0,10):
		fuga[j]=tmp[j]
	fuga.sort()
	hoge=fuga[0]+fuga[1]+fuga[2]+fuga[3]+fuga[4]+fuga[5]+fuga[6]+fuga[7]+fuga[8]+fuga[9]

	if(hoge in wordlist):
		wordlist[hoge]+=1
	else:
		wordlist[hoge]=1

#print(hoge)
#print(wordlist)

total=0
for i in wordlist:
	t=wordlist[i]
	if(t>=2):
		total+=t*(t-1)//2


print(total)
### BUGGY CODE ###

n = int(input())

a = [0] * n

a = list(map(int, input().split()))


ans = 1
for i in range(n):
  ans *= a[i]

if ans > 10 ** 18:
  print(-1)
else:
    print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

ans = 1

if all([i > 0 for i in a]):
  for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
      ans = -1
      break

  print(ans)

else:
  print(0)
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()
for i in range(q):
    l,r = map(int,input().split())
    print(s[l-1:r].count("AC"))

### FIXED CODE ###

n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])
### BUGGY CODE ###

array1 = [int(input()) for i in range(6)]
array2 = array1[1:6]
array2.append(0)
array3 = [array1[0], 0, 0, 0, 0, 0]
move = [0, 0, 0, 0, 0]
t = 0
while (array3[-1] != array1[0]):
  for i in range(5):
    if ( array3[i] >= array2[i]):
      move[i] = array2[i]
    else:
      if (array3[i] == 0):
        move[i] = 0
      else:
        move[i] = array3[i]
  for i in range(5):
    array3[i] = array3[i] - move[i]
    array3[i+1] = array3[i+1] + move[i]
  t += 1
print(t)

### FIXED CODE ###

import math
array1 = [int(input()) for i in range(6)]
array2 = array1[1:6]
num = array1[0]
minimum = min(array2)
print(math.ceil(num / minimum) + 4)
### BUGGY CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
V,C = zip(*CA.most_common())
S = 0
for i in range(len(C)):
    L = C[i]
    if L == 1:
        break
    S += int(L*(L-1)/2)
for k in range(N):
    SS = S - A.count(A[k]) + 1
    print(SS)

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)//2
for x in A:
    print(S - CA[x] + 1)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
M=0
X=[]
for i in range(N-1,-1,-1):
  _=0
  for x in X:
    if x%(i+1)==0:
      _+=1
  if A[i]==0 and _%2==1:
    M+=1
    X.append(i+1)
  elif A[i]==1 and _%2==0:
    M+=1
    X.append(i+1)
print(M)
print(*X)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
M=0
X=[]
XX=[0]*N
for i in range(N-1,-1,-1):
  _=0
  for j in range(i+1,N+1,i+1):
    _+=XX[j-1]
  if A[i]==0 and _%2==1:
    M+=1
    X.append(i+1)
    XX[i]=1
  elif A[i]==1 and _%2==0:
    M+=1
    X.append(i+1)
    XX[i]=1
print(M)
print(*X)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
s = [0]
b = c = d = 0

for i in range(n):
    s.append(s[i] + a[i])
s.sort()

for i in set(s):
    b = s.count(i)
    if b > 1:
        c += int(b*(b-1)/2)
print(c)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
s = [0]
b = 1
c = 0

for i in range(n):
    s.append(s[i] + a[i])
s.sort()
s.append('\0')

for i in range(1, len(s)):
    if s[i] == s[i-1]:
        b += 1
        continue
    c += int(b*(b-1)/2)
    b = 1
print(c)
### BUGGY CODE ###

def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = collections.deque(sorted(list(map(int, input().rstrip('\n').split()))))
    cnt = 0
    for i in range(n-2):
        p = l.popleft()
        for j in range(n-i-1):
            t = p + l[j]
            for k in range(j+1, n-i-1):
                if t > l[k]:
                    cnt += 1
                else:
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


### FIXED CODE ###

def slove():
    import sys
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            t = l[i] + l[j]
            p = bisect.bisect_left(l, t)
            cnt += (p - j - 1)
    print(cnt)


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

import itertools

N = int(input())

def g(x, y, z):
    g_xyz = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    return g_xyz

N2 = int(N ** (1 /2) / 2) + 1

list_ans = []

for target in range(1, N + 1):
    b = 0
    for x in range(1, N2 + 1):
        for y in range(x, N2 + 1):
            for z in range(y, N2 + 1):
            #   print("x, y, z, g(x, y, z) =", x, y, z, g(x, y, z))
              if g(x, y, z) == target:
                  tmp = ["".join(map(str, v)) for v in itertools.permutations([x, y, z])]
                  a = set(tmp)
                  b = len(a)
    list_ans.append(b)

for i in list_ans:
    print(i)

### FIXED CODE ###

def g(x, y, z):
    g_xyz = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    return g_xyz


N = int(input())
ans_list = [0 for _ in range(60000)]
for x in range(1, 100):
  for y in range(1, 100):
      for z in range(1, 100):
          ans_list[g(x=x, y=y, z=z) - 1] += 1
           
for i in range(N):
    print(ans_list[i])
### BUGGY CODE ###

n, s = [int(i) for i in  raw_input().split()]
weights = []
values = []

for _ in range(n):
    w, v = [int(i) for i in raw_input().split()]
    weights.append(w)
    values.append(v)

def knapsack(weights, values, limit):
    n = len(weights)
    # f = [[0 for _ in range(limit+1)] for _ in range(n)]

    prev = [0 for _ in range(limit+1)]

    if weights[0] <= limit:
        for w in range(weights[0], limit+1):
            prev[w] = values[0]

    for i in range(1, n):
        # print prev
        current = [0] * (limit+1)
        for w in range(1, limit+1):
            current[w] = max(prev[w], current[w])
            if weights[i] <= w:
                current[w] = max(current[w], prev[w-weights[i]] + values[i])
        prev = list(current)

    return prev[-1]

# weights = [10, 20, 30]
# values = [60, 100, 120]
print(knapsack(weights, values, s))

### FIXED CODE ###

n, s = [int(i) for i in  raw_input().split()]
weights = []
values = []

for _ in xrange(n):
    w, v = [int(i) for i in raw_input().split()]
    weights.append(w)
    values.append(v)

def knapsack(weights, values, limit):
    n = len(weights)
    # f = [[0 for _ in xrange(limit+1)] for _ in xrange(n)]

    prev = [0 for _ in xrange(limit+1)]

    if weights[0] <= limit:
        for w in xrange(weights[0], limit+1):
            prev[w] = values[0]

    for i in xrange(1, n):
        # print prev
        current = [0] * (limit+1)
        for w in xrange(1, limit+1):
            current[w] = max(prev[w], current[w])
            if weights[i] <= w:
                current[w] = max(current[w], prev[w-weights[i]] + values[i])
        prev = list(current)

    return prev[-1]

# weights = [10, 20, 30]
# values = [60, 100, 120]
print(knapsack(weights, values, s))
### BUGGY CODE ###

k = int(input())
z=1
n=1
while z<=k:
    a=1
    l=len(str(n))
    s = str(n)
    x = list(map(int, list(s)))
    while a<=l:
        if x[0]==1 and l>3:
            if l-a-1==0:
                print(n)
                a=a+100
                z=z+1
            elif n==19:
                print(19)
                a=a+100
                z=z+1
            elif x[l-a]==9:
                a=a+1
            else:
                a=a+100
        else:
            if a-l==0:
                print(n)
                a=a+100
                z=z+1
            elif n==19:
                print(19)
                a=a+100
                z=z+1
            elif x[l-a]==9:
                a=a+1
            else:
                a=a+100
    n=n+1

### FIXED CODE ###

k = int(input())
n=0
a=1
b=0
if a==1 and n<9:
    while n<9 and b<k:
        n+=1
        print(n)
        b+=1
    a+=1
if a==2:
    while n<90 and b<k:
        n+=10
        print(n)
        b+=1
    a+=1
while b<k:
    n+=10**(a-1)
    print(n)
    b+=1
    if (n>((a-1)*10**a-10**(a-1)) and a<12) or (n>((a-2)*10**a-10**(a-1)) and a>=12):
        a+=1
### BUGGY CODE ###

from bisect import bisect_left as bisect

def index(I, CNT, ANS):
    LIST = alp[ord(I) - 97]
    NUM = bisect(LIST, CNT)
    ANS += (NUM == len(LIST)) * len(s)
    CNT = (LIST[NUM % len(LIST)] + 1) % len(s)
    return ANS, CNT

s, t = input(), input()

if not all(i in s for i in t):
    print(-1)
    exit()

alp = [[] for i in range(26)]
for i, si in enumerate(s):
    alp[ord(si) - 97].append(i)

ans, cnt = 1 - len(s), 0
for i in t:
    ans += (cnt == 0) * len(s)
    ans, cnt = index(i, cnt, ans)
print(ans + (cnt - 1) % len(s))


### FIXED CODE ###

from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

alp = defaultdict(list)
for i, si in enumerate(s):
    alp[si].append(i)

ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens 
print(ans + (cnt - 1) % lens)
### BUGGY CODE ###

a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = set(ar)
n = len(br) - b
cr = []
for r in br:
    cr.append(ar.count(r))
count = 0
cr.sort()
for i in range(n):
    count += cr[i]
print(count)

### FIXED CODE ###

import collections
a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = set(ar)
cr = collections.Counter(ar)
n = len(br) - b
dr = []
for v in cr.values():
    dr.append(v)
dr.sort()
count = 0
for i in range(n):
    count += dr[i]
print(count)
### BUGGY CODE ###

import sys
# import pdb
input = sys.stdin.readline

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

dp_list = [-1 for _ in range(N)]
dp_list[0] = 0
dp_list[1] = abs(hs[1] - hs[0])

import heapq

sys.setrecursionlimit(1000000)
def dp_memo(p):
  if dp_list[p] != -1:
    return dp_list[p]

  costs = []
  heapq.heapify(costs)
  if K <= p:
    for i in range(1,K+1):
        heapq.heappush(costs, dp_memo(p-i) + abs(hs[p] - hs[p-i]))
        # costs.append(dp_memo(p-i) + abs(hs[p] - hs[p-i]))
  else:
    for i in range(1,p+1):
        heapq.heappush(costs, dp_memo(p-i) + abs(hs[p] - hs[p-i]))
        # costs.append(dp_memo(p-i) + abs(hs[p] - hs[p-i]))
  # result = min(costs)
  result = heapq.heappop(costs)
  dp_list[p] = result
  return result


def dp_recur():
  costs = []
  costs[0] = 0

  if N == 2:
    print(cost2)
    exit()
  # pdb.set_trace()
  for i in range(2, N):
    cost3 = min(cost2 + abs(hs[i] - hs[i-1]), cost1 + abs(hs[i] - hs[i-2]))
    cost1 = cost2
    cost2 = cost3
  return cost3

# print(dp_recur())
print(dp_memo(N-1))


### FIXED CODE ###

import sys
# import pdb
input = sys.stdin.readline

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

inf = 1e10

dp_list = [inf for _ in range(N)]
dp_list[0] = 0

# import heapq

sys.setrecursionlimit(1000000)
def dp_memo(p):
  if dp_list[p] != -1:
    return dp_list[p]

  costs = []
  # heapq.heapify(costs)
  if K <= p:
    for i in range(1,K+1):
        # heapq.heappush(costs, dp_memo(p-i) + abs(hs[p] - hs[p-i]))
        costs.append(dp_memo(p-i) + abs(hs[p] - hs[p-i]))
  else:
    for i in range(1,p+1):
        # heapq.heappush(costs, dp_memo(p-i) + abs(hs[p] - hs[p-i]))
        costs.append(dp_memo(p-i) + abs(hs[p] - hs[p-i]))
  result = min(costs)
  # result = heapq.heappop(costs)
  dp_list[p] = result
  return result


def dp_recur(N):
  for i in range(1, N):
    for j in range(1,K+1):
      if i-j < 0:
        break
      dp_list[i] = min(dp_list[i], dp_list[i-j] + abs(hs[i] - hs[i-j]))
  return dp_list[N-1]

print(dp_recur(N))
# print(dp_memo(N-1))
### BUGGY CODE ###

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

biggest = 0
humidai = 0

result = 0


for i in range(N-1):
    for j in range(i+1,N):
        result += A[i]*A[j]

result = result%(10**9+7)

print(result)

### FIXED CODE ###

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

biggest = 0
humidai = 0

result = 0

tmp_list = []

tmp=sum(A)

for i in range(N-1):

    # for j in range(i+1,N):
        # tmp += A[j]
    tmp -= A[i]
    
    result += A[i]*tmp

    if result>10**9+7:
        result = result%(10**9+7)

result = result%(10**9+7)

print(result)
### BUGGY CODE ###

# ABC172c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

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

    def dfs(i, j, s):
        t = 0
        if i < n and s + a[i] <= k:
            t = dfs(i + 1, j, s + a[i])+1
        if j < m and s + b[j] <= k:
            t = max(t, dfs(i, j + 1, s + b[j])+1)
        return t

    print(dfs(0, 0, 0))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# ABC172c


def main():
    import sys
    import bisect
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

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

    def cum(array):  # result[i]=i番目まで（1-indexed）の累積和
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    bc = cum(b)
    ac = cum(a)
    ans = 0
    for i in range(n + 1):
        if ac[i] <= k:
            #print(i, bisect.bisect_left(bc, k - ac[i])-1)
            ans = max(ans, i + bisect.bisect_right(bc, k - ac[i])-1)
    print(ans)


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

from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    cnt = 0
    for i in range(len_S):
        for j in range(i+3,len_S):
            if j == i+3:
                mod = int(S[len_S-j-1:len_S-i])%3
            else:
                mod = (mod+int(S[len_S-j-1]))%3
            if mod == 0:
                _ = int(S[len_S-j-1:len_S-i])
                if _%673==0:
                    cnt += 1
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


def ans():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    cnt = 0
    mod_arr = {}
    for i in range(2019):
        mod_arr[i] = 0
    mod_arr[0] += 1
    for i in range(0,len_S+1):
        _ = int(S[len_S-i-1:])
        if i>0: mod = (mod+int(S[len_S-i-1])*10**i)%2019
        else:   mod = _%2019
        mod_arr[mod]+=1
    for value in mod_arr.values():
        if value>1:
            cnt += value*(value-1)//2
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


if __name__ == "__main__":
    #main()
    ans()


### FIXED CODE ###

from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    cnt = 0
    for i in range(len_S):
        for j in range(i+3,len_S):
            if j == i+3:
                mod = int(S[len_S-j-1:len_S-i])%3
            else:
                mod = (mod+int(S[len_S-j-1]))%3
            if mod == 0:
                _ = int(S[len_S-j-1:len_S-i])
                if _%673==0:
                    cnt += 1
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    mod_arr = [0] * 2019
    mod_arr[0] += 1

    num, dec = 0, 1
    for s in S[::-1]:
        num += int(s)*dec
        num %= 2019
        dec *= 10
        dec %= 2019
        mod_arr[num] += 1

    for i in range(2019):
        if mod_arr[i] > 0:
            cnt += mod_arr[i]*(mod_arr[i]-1)//2
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)
### BUGGY 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)


### FIXED CODE ###

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

a = 0
for i in range(n):
    if l[i] % k == 0:
        a += 1
#print(a)

b = 0
for j in range(n):
    if l[j] % k == k/2:
        b += 1
#print(b)

if k % 2 == 1:
    print(a**3)
else:
    print(a**3 + b**3)
### BUGGY CODE ###

import sys
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    for j in range(i+1,N):  
        if A[i] == A[j]:
            print("NO")
            sys.exit()
else:
    print("YES")

### FIXED CODE ###

import sys
N = int(input())
A = list(map(int, input().split()))
A2 = sorted(A)
for i in range(N-1): 
        if A2[i] == A2[i+1]: 
            print("NO")
            sys.exit()
else:
    print("YES")
### BUGGY CODE ###

def main():
    S = raw_input()
    Q = int(raw_input())

    is_reversed = False

    for _ in range(Q):
        query = raw_input().split()
        if query[0] == "1":
            is_reversed = not is_reversed
        elif query[0] == "2":
            F = int(query[1])
            C = query[2]
            if F == 1:
                if not is_reversed:
                    S = C + S
                else:
                    S = S + C
            elif F == 2:
                if not is_reversed:
                    S = S + C
                else:
                    S = C + S


    if not is_reversed:
        ans =  S
    else:
        ans = S[::-1]
    print ans

if __name__ == "__main__":
    main()



### FIXED CODE ###

def main():
    S = raw_input()
    Q = int(raw_input())

    is_reversed = False
    sentou = []
    owari = []

    for _ in range(Q):
        query = raw_input().split()
        if query[0] == "1":
            is_reversed = not is_reversed
        elif query[0] == "2":
            F = query[1]
            C = query[2]
            if F == "1":
                if not is_reversed:
                    sentou.append(C)
                else:
                    owari.append(C)
            elif F == "2":
                if not is_reversed:
                    owari.append(C)
                else:
                    sentou.append(C)

    S = "".join(sentou[::-1]+list(S)+owari)


    if not is_reversed:
        print S
    else:
        print S[::-1]

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

def rabin_karp(T, P, d, q):
    n = len(T)
    m = len(P)
    if n < m:
        return
    h = pow(d, m - 1) % q
    p = 0
    t0 = 0
    for i in range(m):
        p = (d * p + P[i]) % q
        t0 = (d * t0 + T[i]) % q
    for s in range(n - m + 1):
        if p == t0:
            if P[0:(m - 1)] == T[s:(s + m - 1)]:
                print(s)
        if s < n - m:
            t0 = (d * (t0 - T[s] * h) + T[s + m]) % q


d = 122
q = 127
t = list(map(ord, input()))
p = list(map(ord, input()))

rabin_karp(t, p, d, q)


### FIXED CODE ###

def compute_prefix_function(p):
    m = len(p)
    pi = [0 for _ in range(m + 1)]
    pi[1] = 0
    k = 0
    for q in range(2, m + 1):
        while k > 0 and p[k] != p[q - 1]:
            k = pi[k]
        if p[k] == p[q - 1]:
            k += 1
        pi[q] = k
    return pi


def kmp_matcher(t, p):
    n = len(t)
    m = len(p)
    pi = compute_prefix_function(p)
    q = 0
    for i in range(1, n + 1):
        while q > 0 and p[q] != t[i - 1]:
            q = pi[q]
        if p[q] == t[i - 1]:
            q += 1
        if q == m:
            print(i - m)
            q = pi[q]


t = input()
p = input()
kmp_matcher(t, p)