import itertools


N, L = list(map(int,input().strip().split()))
alist = list(map(int,input().strip().split()))

count = N 	# 1 factor array must satisfy the condition
for x in itertools.combinations(range(N), 2):
	i, j = x[0], x[1]
	# print(i,j)

# for x in range(1):
# 	i, j = 1,8

	target_list = alist[i:j+1]
	maximum = max(target_list)
	k = maximum+1 # level
	needed_length = L**(k-2)
	length = 0
	condition = True
	count1 = 0
	belowlevel = 0

	for index in range(len(target_list)):
		if target_list[index]==1:
			count1 = count1+1

			if index==len(target_list)-1:
				cluster_num = int(count1/L)
				if cluster_num==0:
					condition = False
					break
				else:
					length = length+cluster_num
					count1 = 0
			elif target_list[index+1]!=1:
				cluster_num = int(count1/L)
				if cluster_num==0:
					condition = False
					break
				else:
					length = length+cluster_num
					count1 = 0
		elif target_list[index]==maximum:
			belowlevel= belowlevel+1+int(length/(needed_length/L))
			length = 0
		else:
			length = length+L**(target_list[index]-2)

	belowlevel = belowlevel+int(length/(needed_length/L))

	if (length!=0) and (length<needed_length/L):
		condition = False

	if (condition==True) and belowlevel>=3:
		count = count+1
		# print(i,j)

print(count)
