Lisa just got a new math workbook.  A workbook contains exercise problems, grouped into chapters.  Lisa believes a problem to be special if its index (within a chapter) is the same as the page number where it's located.  The format of Lisa's book is as follows:

There are $n$ chapters in Lisa's workbook, numbered from $\mbox{1}$ to $n$.
The $i^{\mbox{th}}$ chapter has $arr\left[i\right]$ problems, numbered from $\mbox{1}$ to $arr\left[i\right]$.
Each page can hold up to $\boldsymbol{\mbox{k}}$ problems. Only a chapter's last page of exercises may contain fewer than $\boldsymbol{\mbox{k}}$ problems.
Each new chapter starts on a new page, so a page will never contain problems from more than one chapter.
The page number indexing starts at $\mbox{1}$.

Given the details for Lisa's workbook, can you count its number of special problems?

Example 

$arr=[4,2]$ 

$k=3$   

Lisa's workbook contains $ar r[1]=4$ problems for chapter $\mbox{1}$, and $arr[2]=2$ problems for chapter $2$.  Each page can hold $k=3$ problems.  

The first page will hold $3$ problems for chapter $\mbox{1}$.  Problem $\mbox{1}$ is on page $\mbox{1}$, so it is special.  Page $2$ contains only Chapter $\mbox{1}$, Problem $\begin{array}{c}4\end{array}$, so no special problem is on page $2$.  Chapter $2$ problems start on page $3$ and there are $2$ problems.  Since there is no problem $3$ on page $3$, there is no special problem on that page either.  There is $\mbox{1}$ special problem in her workbook.

Note: See the diagram in the Explanation section for more details.  

Function Description  

Complete the workbook function in the editor below.     

workbook has the following parameter(s):  

int n: the number of chapters       
int k: the maximum number of problems per page  
int arr[n]: the number of problems in each chapter  

Returns 

- int: the number of special problems in the workbook   

Input Format

The first line contains two integers $n$ and $\boldsymbol{\mbox{k}}$, the number of chapters and the maximum number of problems per page. 

The second line contains $n$ space-separated integers $arr\left[i\right]$ where $arr\left[i\right]$ denotes the number of problems in the $i^{\mbox{th}}$ chapter.

Constraints

$1\leq n,k,ar r[i]\leq100$

Sample Input
STDIN       Function
-----       --------
5 3         n = 5, k = 3
4 2 6 1 10  arr = [4, 2, 6, 1, 10]

Sample Output
4

Explanation

The diagram below depicts Lisa's workbook with $n=5$ chapters and a maximum of $k=3$ problems per page. Special problems are outlined in red, and page numbers are in yellow squares.

There are $\begin{array}{c}4\end{array}$ special problems and thus we print the number $\begin{array}{c}4\end{array}$ on a new line.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
a = 0
pg = [[]]
(x, y) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
for i in l:
	k = [[] for _ in range(100)]
	for j in range(i):
		k[j // y].append(j + 1)
	for i in k:
		if i != []:
			pg.append(i)
for i in range(len(pg)):
	if i in pg[i]:
		a += 1
print(a)


import sys
from random import randint

def read_ints(inp=sys.stdin):
	return list(map(int, next(inp).strip().split()))

def brute(seq):
	return 0

def sol1(n, k, t):
	page = 1
	acc = 0
	for nb in t:
		pb = 1
		while pb <= nb:
			(fst, lst) = (pb, min(pb + k - 1, nb))
			if fst <= page <= lst:
				acc += 1
			page += 1
			pb += k
	return acc
if 0:
	inp = iter('5 3\n4 2 6 1 10\n'.split('\n'))
else:
	inp = sys.stdin
T = 1
for _ in range(T):
	(N, k) = read_ints(inp)
	T = read_ints(inp)
	print(sol1(N, k, T))

def testseq():
	for n in range(1, 100):
		seq = [randint(n) for _ in range(n)]
		ref = brute(seq)
		r1 = sol1(seq)
		if ref != r1:
			print(n)
			print(seq)
			print(ref)
			print(r1)
			assert False


def find_special_problems(n, k, t):
	page = 1
	count = 0
	for i in range(1, n + 1):
		j = 1
		while j <= t[i - 1]:
			if j == page:
				count += 1
			if j % k == 0:
				page += 1
			j += 1
		if t[i - 1] % k != 0:
			page += 1
	return count
(n, k) = map(int, input().split())
t = list(map(int, input().split()))
print(find_special_problems(n, k, t))


(n, k) = map(int, input().strip().split())
t_list = [int(x) for x in input().strip().split()]
cnt = 0
page = 1
for t in t_list:
	_t = t
	lower = 1
	upper = min(k, _t)
	while _t > 0:
		if lower <= page <= upper:
			cnt += 1
		_t -= upper - lower + 1
		lower = upper + 1
		upper += min(k, _t)
		page += 1
print(cnt)


def main():
	(chapters, problems_per_page) = input().split()
	problems_per_chapter = [int(number) for number in input().split()]
	page = 0
	overall_count = 0
	for problems_in_chapter in problems_per_chapter:
		(count, page) = find_special_problems_for_chapter(page, int(problems_in_chapter), int(problems_per_page))
		page += 1
		overall_count += count
	print(overall_count)

def find_special_problems_for_chapter(start_page, problems_in_chapter, problems_per_page):
	count = 0
	for problem in range(problems_in_chapter):
		new_page = start_page + problem // problems_per_page
		if new_page == problem:
			count += 1
	return (count, new_page)
main()


(n, k) = input().strip().split()
n = int(n)
k = int(k)
t = [int(x) for x in input().strip().split()]
startPage = {1: 1}
for i in range(1, n):
	pages = 1 + (t[i - 1] - 1) // k
	startPage[i + 1] = startPage[i] + pages
count = 0
for chap in range(1, n + 1):
	for prob in range(1, t[chap - 1] + 1):
		page = startPage[chap] + (prob - 1) // k
		if page == prob:
			count += 1
print(count)


from math import ceil
(nchap, mpp) = map(int, input().split())
pchap = map(int, input().split())
pg = 1
p = 1
count = 0
for c in pchap:
	for i in range(c):
		if i + 1 == pg + i // mpp:
			count += 1
	pg += ceil((i + 1) / mpp)
print(count)


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
(cc, cp, ct, v) = (0, 1, 1, 0)
while cc < n:
	nt = min(ct + k, t[cc] + 1)
	if cp in range(ct, nt):
		v += 1
	ct = nt
	if ct > t[cc]:
		cc += 1
		ct = 1
	cp += 1
print(v)


import math
(n, k) = input().split(' ')
(n, k) = [int(n), int(k)]
t = [int(x) for x in input().split(' ')]
spec_pb = 0
first_page = 1
for i_chap in range(1, n + 1):
	for i_prob in range(1, t[i_chap - 1] + 1):
		page = first_page + math.floor((i_prob - 1) / k)
		if page == i_prob:
			spec_pb += 1
	first_page += math.floor((t[i_chap - 1] - 1) / k) + 1
print(spec_pb)


(N, K) = map(int, input().split())
T = list(map(int, input().split()))
P = []
for t in T:
	for p in range(1, t + 1, K):
		P.append(set(range(p, min(p + K, t + 1))))
count = 0
for (i, p) in enumerate(P, 1):
	if i in p:
		count += 1
print(count)


def count_special(n, k, num_probs):
	pages = []
	for c in num_probs:
		curr_page = []
		first_prob = 0
		for i in range(c):
			if i > first_prob + k - 1:
				pages.append(curr_page)
				curr_page = []
				first_prob += k
			curr_page.append(i)
		pages.append(curr_page)
	special_count = 0
	for i in range(len(pages)):
		for p in pages[i]:
			if i == p:
				special_count += 1
	print(special_count)
str = input().strip()
(n, k) = [int(s) for s in str.split()]
str = input().strip()
prob_num = [int(s) for s in str.split()]
count_special(n, k, prob_num)


(n, k) = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
page = 1
count = 0
for i in range(0, len(t)):
	t_i = t[i]
	problems_on_page_start = 1
	while t_i > 0:
		problems_on_page_end = problems_on_page_start + min(t_i, k) - 1
		if problems_on_page_start <= page <= problems_on_page_end:
			count += 1
		t_i -= problems_on_page_end - problems_on_page_start + 1
		problems_on_page_start = problems_on_page_end + 1
		page += 1
print(count)


data = input().split()
n = int(data[0])
k = int(data[1])
nbPb = input().split()
for i in range(len(nbPb)):
	nbPb[i] = int(nbPb[i])
nbPbs = sum(nbPb)
Page = 1
result = 0
Chapter = 1
pageBfr = 1
index = 1
for problems in range(nbPbs):
	if index == Page:
		result += 1
	if index % k == 0:
		Page += 1
	if index == nbPb[Chapter - 1]:
		Chapter += 1
		if index % k != 0:
			Page += 1
		index = 1
	else:
		index += 1
print(result)


def solution(N, K, problems):
	page = 1
	ans = 0
	for c in range(1, N + 1):
		for problem in range(1, problems[c - 1] + 1):
			if problem == page:
				ans += 1
			if problem % K == 0:
				page += 1
		if problem % K != 0:
			page += 1
	return ans

def read_input():
	(N, K) = [int(i) for i in input().strip().split()]
	problems = list(map(int, input().strip().split()))
	return (N, K, problems)
(N, K, problems) = read_input()
print(solution(N, K, problems))


line = input().split()
n = int(line[0])
k = int(line[1])
chapters = [int(x) for x in input().split()]
result = 0
page = 1
for c in chapters:
	pageInChapter = 0
	newC = c
	while newC > 0:
		if page > k * pageInChapter and page <= min(k * (pageInChapter + 1), c):
			result += 1
		newC -= k
		page += 1
		pageInChapter += 1
print(result)


constraints = input().split(' ')
(n_chapters, max_per_page) = [int(constraints[0]), int(constraints[1])]
problems_per_chapter = list(map(int, input().split(' ')))
total = 0
pages = 0
for i in range(n_chapters):
	pages = pages + 1
	current_problem_count = 0
	for j in range(problems_per_chapter[i]):
		current_problem_count = current_problem_count + 1
		if current_problem_count > max_per_page:
			pages = pages + 1
			current_problem_count = 1
		if pages == j + 1:
			total = total + 1
print(total)


(n, k) = [int(x) for x in input().strip().split()]
chapters = [int(x) for x in input().strip().split()]
page = 0
result = 0
for x in chapters:
	pages = (x - 1) // k + 1
	for y in range(pages):
		page += 1
		if page in range(y * k + 1, (y + 1) * k + 1) and (y < pages - 1 or x % k == 0):
			result += 1
		elif y == pages - 1 and page in range(y * k + 1, y * k + x % k + 1):
			result += 1
print(result)


import sys
(n, k) = map(int, sys.stdin.readline().strip().split())
t = list(map(int, sys.stdin.readline().strip().split()))
page = 0
n_special = 0
for i in range(n):
	page += 1
	for j in range(1, t[i] + 1):
		if j == page:
			n_special += 1
		if j != 0 and j % k == 0 and (j < t[i]):
			page += 1
print(n_special)


def main():
	nbSpecial = 0
	startPage = 1
	(n, k) = list(map(int, input().split()))
	t = list(map(int, input().split()))
	for chapter in range(1, n + 1):
		for prob_i in range(1, t[chapter - 1] + 1):
			if startPage + (prob_i - 1) // k == prob_i:
				nbSpecial += 1
		startPage += (t[chapter - 1] - 1) // k + 1
	print(nbSpecial)
main()


import math
(n, k) = tuple(map(int, input().strip().split()))
caps = tuple(map(int, input().strip().split()))
pag = 1
especiales = 0
for i in range(n):
	for j in range(math.ceil(caps[i] / k)):
		lim = j * k + 1
		resto = k if caps[i] - lim + 1 >= k else (caps[i] - lim + 1) % k
		if pag >= lim and pag <= lim + resto - 1:
			especiales += 1
		pag += 1
print(especiales)


from collections import deque
(n, k) = map(int, input().strip().split())
t = deque(map(int, input().strip().split()))
page = 0
count = 0
while t:
	ex = range(1, t.popleft() + 1)
	while ex:
		page += 1
		(x, ex) = (ex[:k], ex[k:])
		if page in x:
			count += 1
print(count)


(m, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
page = 0
total = 0
for i in range(m):
	for j in range(1, a[i] + 1, k):
		page += 1
		flag = 0
		tt = j + k
		if tt > a[i]:
			tt = a[i] + 1
		for l in range(j, tt):
			if l == page:
				flag = 1
		if flag:
			total += 1
print(total)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
page = 1
count = 0
for i in range(n):
	flag = 0
	while arr[i] > 0:
		problems = arr[i]
		problemstart = 1 + flag * k
		if arr[i] < k:
			problemend = problemstart + arr[i] - 1
		else:
			problemend = problemstart + k - 1
		if page in range(problemstart, problemend + 1):
			count += 1
		arr[i] -= k
		flag += 1
		page += 1
print(count)


(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
p = 0
c = 1
ans = 0
for x in a:
	p += 1
	c = 1
	t = 1
	for i in range(1, x + 1):
		if c > k:
			c = 1
			p += 1
		if t == p:
			ans += 1
		c += 1
		t += 1
print(ans)


(n, k) = map(int, input().split())
num_problems = list(map(int, input().split()))
count = 0
cur_problem = 1
cur_page = 1
for chapter in range(1, n + 1):
	cur_problem = 1
	while cur_problem <= num_problems[chapter - 1]:
		if cur_page in range(cur_problem, min(cur_problem + k - 1, num_problems[chapter - 1]) + 1):
			count += 1
		cur_problem += k
		cur_page += 1
print(count)


import sys
(n, k) = input().strip().split(' ')
(n, k) = (int(n), int(k))
page = 0
specials = 0
T = [int(t) for t in input().strip().split(' ')]
for t in T:
	problems = list(range(1, t + 1))
	while problems:
		page += 1
		if page in problems[:k]:
			specials += 1
		problems = problems[k:]
print(specials)


(n, k) = map(int, input().split())
ts = map(int, input().split())

def pages(ts, k):
	for t in ts:
		for x in range(1, t + 1, k):
			yield range(x, x + min(k, t - x + 1))

def solve(ts, k):
	pbs = enumerate(pages(ts, k), 1)
	return sum((i in pb for (i, pb) in pbs))
print(solve(ts, k))


l1 = input().split(' ')
n = int(l1[0])
k = int(l1[1])
l2 = input().split(' ')
t = list(map(int, l2))
page_hash = {}
page_no = 0
for ii in range(1, n + 1):
	prob_count = 0
	page_no += 1
	for jj in range(1, t[ii - 1] + 1):
		if prob_count >= k:
			page_no += 1
			prob_count = 0
		if page_no not in page_hash.keys():
			page_hash[page_no] = [jj]
		else:
			page_hash[page_no].append(jj)
		if prob_count < k:
			prob_count += 1
spec_pages = 0
for i in page_hash.keys():
	for j in page_hash[i]:
		if i == j:
			spec_pages += 1
print(spec_pages)


(n, k) = input().strip().split()
(n, k) = [int(n), int(k)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
special = 0
pagenumber = 1
for i in range(1, n + 1):
	for j in range(1, a[i - 1] + 1):
		if j == pagenumber:
			special = special + 1
		if j % k == 0 and j < a[i - 1]:
			pagenumber = pagenumber + 1
	pagenumber = pagenumber + 1
print(special)


(chapters, problems_per_page) = [int(x) for x in input().strip().split(' ')]
(chapters, problems_per_page) = [chapters, problems_per_page]
problems_per_chapter = [int(x) for x in input().strip().split(' ')]
special_count = 0
page_index = 0
problem_index = 1
for problems in problems_per_chapter:
	pages = problems // problems_per_page
	if problems % problems_per_page > 0:
		pages += 1
	for pn in range(pages):
		page_index += 1
		for p0 in range(pn * problems_per_page + 1, (pn + 1) * problems_per_page + 1):
			if p0 > problems:
				break
			if p0 == page_index:
				special_count += 1
print(special_count)


import math
(n, k) = list(map(int, input().split(' ')))
t = list(map(int, input().split(' ')))
next_page = 1
special_count = 0
for problem_count in t:
	problems_in_chapter = [p for p in list(range(1, problem_count + 1))]
	pages_needed = math.ceil(problem_count / k)
	pages = list(range(next_page, next_page + pages_needed))
	next_page += pages_needed
	problems_by_page = [problems_in_chapter[i * k:(i + 1) * k] for i in range(pages_needed)]
	for (page, problems) in zip(pages, problems_by_page):
		if page in problems:
			special_count += 1
print(special_count)


import math
(chapter, max_problem_per_page) = list(map(int, input().split(' ')))
problems = list(map(int, input().split(' ')))
problems_page = [(number, math.ceil(number / max_problem_per_page)) for number in problems]
current_page = 0
result = 0
for (problem, page) in problems_page:
	for number in range(page):
		min_problem = number * max_problem_per_page
		max_problem = min((number + 1) * max_problem_per_page, problem)
		current_page += 1
		if min_problem < current_page <= max_problem:
			result += 1
print(result)


(n, k) = map(int, input().strip().split())
t = [int(x) for x in input().strip().split()]
cur_chapter = 1
cur_page = 1
special = 0
while True:
	chpro = t[cur_chapter - 1]
	for p in range(1, chpro + 1):
		if p == cur_page:
			special += 1
		if p % k == 0:
			cur_page += 1
	if p % k != 0:
		cur_page += 1
	cur_chapter += 1
	if cur_chapter > n:
		break
print(special)


import sys
(a, n_pb) = input().strip().split(' ')
n_pb = int(n_pb)
book = [int(arr_temp) for arr_temp in input().strip().split(' ')]
current_page = 0
special = 0
for chap in book:
	pb = 1
	current_page += 1
	count = 1
	while pb <= chap:
		if pb == current_page:
			special += 1
		if pb == chap:
			count = 0
		if count == n_pb:
			current_page += 1
			count = 0
		pb += 1
		count += 1
print(special)


from collections import defaultdict
(n, k) = [int(x) for x in input().strip().split(' ')]
chapters = [int(x) for x in input().strip().split(' ')]
pages = defaultdict(list)
idx = 1
answer = 0
for t in chapters:
	questions = [x + 1 for x in range(0, t)]
	while questions:
		if len(pages[idx]) >= k:
			idx += 1
		question = questions.pop(0)
		if question == idx:
			answer += 1
		pages[idx].append(question)
	idx += 1
print(answer)


(the_number_of_chapters, the_maximum_number_of_problems_per_page) = (int(x) for x in input().split())
the_number_of_problems_per_chapter = [int(x) for x in input().split()]
current_page = 0
the_number_of_special_problems = 0
for current_chapter in range(1, the_number_of_chapters + 1):
	current_problem = 1
	current_page += 1
	for current_problem in range(1, the_number_of_problems_per_chapter[current_chapter - 1] + 1):
		if current_problem > 1 and current_problem % the_maximum_number_of_problems_per_page == 1:
			current_page += 1
		elif the_maximum_number_of_problems_per_page == 1 and current_problem != 1:
			current_page += 1
		if current_problem == current_page:
			the_number_of_special_problems += 1
print(the_number_of_special_problems)


(n, k) = map(int, input().split())
t = map(int, input().split())
special = 0
page = 0
for i in t:
	for j in range(0, i):
		if j % k == 0:
			page += 1
		if j + 1 == page:
			special += 1
print(special)


(n, k) = input().strip().split()
(n, k) = (int(n), int(k))
t = [int(i) for i in input().split()]
p = 0
s = 0
for i in range(n):
	j = 0
	p += 1
	for j in range(1, t[i] + 1):
		if j == p:
			s += 1
		if j % k == 0 and j != t[i]:
			p += 1
print(s)


inp = input()
inp = [int(n) for n in inp.split()]
(n_chap, max_prob) = (inp[0], inp[1])
inp = input()
n_prob_list = [int(n) for n in inp.split()]
n_special = 0
workbook = list()
for n in n_prob_list:
	n_prob = 1
	while n_prob <= n:
		chapter = list()
		for i in range(max_prob):
			if n_prob <= n:
				chapter.append(n_prob)
			n_prob += 1
		workbook.append(chapter)
for i in range(len(workbook)):
	for problem in workbook[i]:
		if problem == i + 1:
			n_special += 1
print(n_special)


[n, k] = map(int, input().split(' '))
t = list(map(int, input().split(' ')))
pages_total = 0
special = 0
for chapter in range(n):
	pages_in_chapter = (t[chapter] - 1) // k + 1
	page_index = 1
	for page in range(pages_total + 1, pages_total + pages_in_chapter + 1):
		if page in range(k * (page_index - 1) + 1, min(k * page_index + 1, t[chapter] + 1)):
			special += 1
		page_index += 1
	pages_total += page_index - 1
print(special)


(n, k) = list(map(int, input().strip().split()))
problems = list(map(int, input().strip().split()))
page = 1
special = 0
counter = 0
for i in problems:
	for j in range(i):
		if j + 1 == page:
			special += 1
		counter += 1
		if counter == k:
			page += 1
			counter = 0
	if counter > 0:
		counter = 0
		page += 1
print(special)


(n, k) = [int(x) for x in input().split()]
problems_array = (int(x) for x in input().split())
page_number = 1
special = 0
for n_problems in problems_array:
	chapter_page = 0
	while n_problems > 0:
		rng = range(1 + k * chapter_page, 1 + min(n_problems, k) + k * chapter_page)
		special += 1 if page_number in rng else 0
		chapter_page += 1
		n_problems -= k
		page_number += 1
print(special)


(n, k) = [int(num) for num in input().strip().split(' ')]
t = [int(num) for num in input().strip().split(' ')]
pages = []
for i in range(n):
	prob = 1
	while prob <= t[i]:
		pages.append([])
		for p in range(k):
			if prob + p <= t[i]:
				pages[-1].append(prob + p)
		prob += k
NumSpecials = 0
for i in range(len(pages)):
	if i + 1 in pages[i]:
		NumSpecials += 1
print(NumSpecials)


(n, k) = [int(i) for i in input().strip().split(sep=' ')]
list_prob = [int(i) for i in input().strip().split(sep=' ')]
list_check = []
for prob in list_prob:
	prob_temp = 0
	list = [i for i in range(1, prob + 1)]
	while prob_temp < prob:
		t_list = []
		for ind in range(k):
			t_list.append(list[prob_temp])
			prob_temp += 1
			if prob_temp == prob:
				break
		list_check.append(t_list)
count = 0
for page_no in range(len(list_check)):
	if page_no + 1 in list_check[page_no]:
		count += 1
print(count)


(chapters, probs_per_page) = (int(x) for x in input().strip().split(' '))
probs_per_chapter = tuple((int(x) for x in input().strip().split(' ')))
page = 1
chapter = 1
problem = 1
num_special = 0
while True:
	last_problem = min(probs_per_chapter[chapter - 1], problem + probs_per_page - 1)
	if problem <= page <= last_problem:
		num_special += 1
	problem += probs_per_page
	if problem > probs_per_chapter[chapter - 1]:
		problem = 1
		chapter += 1
	if chapter > chapters:
		break
	page += 1
print(num_special)


import sys
(n, k) = input().strip().split(' ')
(n, k) = [int(n), int(k)]
chaps = [int(c) for c in input().strip().split(' ')]
cpage = 1
spec = 0
for chap in chaps:
	ppc = 0
	for i in range(1, chap + 1):
		ppc = ppc + 1
		if i == cpage:
			spec = spec + 1
		if ppc == k:
			cpage = cpage + 1
			ppc = 0
	if ppc != 0:
		cpage = cpage + 1
print(spec)


(chap, page_limit) = input().strip().split(' ')
(chap, page_limit) = [int(chap), int(page_limit)]
num_probs = [int(prob) for prob in input().strip().split(' ')]
page_num = 1
special = 0
for ch in range(chap):
	pr = 1
	while pr <= num_probs[ch]:
		on_page = 0
		while on_page < page_limit and pr <= num_probs[ch]:
			on_page += 1
			if pr == page_num:
				special += 1
			pr += 1
		page_num += 1
print(special)


(n, k) = [int(x) for x in input().strip().split()]
t = [int(x) for x in input().strip().split()]
page = 0
special = 0
for i in t:
	for j in range(i):
		if not j % k:
			page += 1
		if j + 1 == page:
			special += 1
print(special)


import math
(n, k) = input().split()
n = int(n)
k = int(k)
problems = [int(x) for x in input().split()]
book = []
page = 1
result = 0
for i in problems:
	required_pages = math.ceil(i / k)
	problem_start = 1
	for j in range(required_pages):
		if problem_start + k - 1 >= i:
			problem_end = i
		else:
			problem_end = problem_start + k - 1
		if page in range(problem_start, problem_end + 1):
			result += 1
		page += 1
		problem_start = problem_end + 1
print(result)


import sys
(n, k) = (int(x) for x in input().split())
chapter_problem_count = (int(x) for x in input().split())
special_count = 0
page_count = 0
require_new_page = True
for c in chapter_problem_count:
	if require_new_page:
		page_count += 1
	for x in range(1, c + 1):
		if page_count == x:
			special_count += 1
		if x % k == 0:
			page_count += 1
	require_new_page = c % k != 0
print(special_count)


from math import ceil
(n, k) = list(map(int, input().strip().split()))
p = list(map(int, input().strip().split()))
x = [list(range(1, i + 1)) for i in p]
y = [i[j * k:(j + 1) * k] for i in x for j in range(0, ceil(len(i) / k))]
z = set([j for i in range(len(y)) for j in y[i] if i + 1 == j])
print(len(z))


z = input().strip().split(' ')
maxChapters = int(z[0])
probsPerPage = int(z[1])
problems = [int(each) for each in input().strip().split(' ')]
i = 0
page = 0
count = 0
while i < maxChapters:
	total = problems[i]
	prob = 0
	while prob < total:
		page += 1
		for each in range(probsPerPage):
			if prob < total:
				prob += 1
				if prob == page:
					count += 1
	i += 1
print(count)


import math
(chapters, problems_page) = [int(x) for x in input().split(' ')]
problems = [int(x) for x in input().split(' ')]
chapter = 1
page = 1
specials = 0
for problem in problems:
	index = 1
	while index + problems_page - 1 < problem:
		if page in range(index, index + problems_page):
			specials += 1
		index += problems_page
		page += 1
	if index <= problem:
		if page in range(index, problem + 1):
			specials += 1
		page += 1
print(specials)


import sys
import math
(n, k) = input().strip().split(' ')
(n, k) = [int(n), int(k)]
t = [int(arr_temp) for arr_temp in input().strip().split(' ')]
p = 0
count = 0
for i in range(1, n + 1):
	q = 0
	for j in range(1, t[i - 1] + 1):
		q = q + 1
		if q > k:
			q = q - k
			p = p + 1
		if j == 1:
			p = p + 1
		if p == j:
			count = count + 1
print(count)


g_page = 0
g_special = 0
value = input()
value = value.split()
chapter = int(value[0])
problem_per_page = int(value[1])
problem_per_chapter = input().split()
for problems in problem_per_chapter:
	problems = int(problems)
	for problem in range(1, problems + 1):
		if problem == 1:
			g_page += 1
		if problem - 1 != 0 and (problem - 1) % problem_per_page == 0:
			g_page += 1
		if g_page == problem:
			g_special += 1
print(g_special)


(n, k) = [int(x) for x in input().strip().split()]
problems = [int(x) for x in input().strip().split()]
current_page = 1
problem_counter = 0
special_problem_counter = 0
for chapter in range(1, n + 1):
	problem_counter = 0
	chapter_problems = problems[chapter - 1]
	for problem in range(1, chapter_problems + 1):
		problem_counter += 1
		if problem == current_page:
			special_problem_counter += 1
		if problem_counter == k or problem == chapter_problems:
			current_page += 1
			problem_counter = 0
print(special_problem_counter)


from collections import *
from itertools import *
import sys

def read_ints():
	return map(int, next(sys.stdin).split())

def print_ints(l):
	print(' '.join(map(str, l)))

def special(T, n, k):
	special = 0
	page = -1
	for t in T:
		for i in range(t):
			if i % k == 0:
				page += 1
			if i == page:
				special += 1
	return special

def main():
	(n, k) = read_ints()
	T = read_ints()
	print(special(T, n, k))
main()


(n, k) = input().split()
t = input().split()
page = 1
special_problems = 0
for chapter in range(0, int(n)):
	for problem in range(0, int(t[chapter])):
		if problem + 1 == page:
			special_problems += 1
		if (problem + 1) % int(k) == 0 and problem + 1 != int(t[chapter]):
			page += 1
	page += 1
print(special_problems)


(n, k) = [int(x) for x in input().strip().split(' ')]
chapters = [int(x) for x in input().strip().split(' ')]
last_page = 0

def foo(l_page, pb_c, k):
	c_page = l_page + 1
	j = 1
	chapter = {}
	for i in range(c_page, c_page + int(pb_c / k)):
		chapter[i] = [x for x in range(j, j + k)]
		j += k
		c_page += 1
	if pb_c % k != 0:
		chapter[c_page] = [x for x in range(j, j + pb_c % k)]
		c_page += 1
	found = 0
	for (k, v) in chapter.items():
		if k in v:
			found += 1
	return (found, c_page - 1)
special_pb = 0
for i in chapters:
	(spb, last_page) = foo(last_page, i, k)
	special_pb += spb
print(special_pb)


import sys
input_list = input().split()
n = int(input_list[0])
k = int(input_list[1])
input_list = input().split()
t = [True]
for i in range(n):
	t.append(int(input_list[i]))

def lisas_workbook(n, k, t):
	page = 1
	special = 0
	turned = 1
	for i in range(1, n + 1):
		for j in range(1, t[i] + 1):
			if j > k * turned:
				turned += 1
				page += 1
			if j == page:
				special += 1
		page += 1
		turned = 1
	return special
print(lisas_workbook(n, k, t))


def count_specials(n, k, t):
	current_page = 1
	counter = 0
	for i in t:
		x = 1
		for p in range(1, i + 1):
			if p > k * x:
				x += 1
				current_page += 1
			if p is current_page:
				counter += 1
		current_page += 1
	return counter
(n, k) = input().strip().split(' ')
n = int(n)
k = int(k)
t = [int(t_i) for t_i in input().strip().split(' ')]
print(count_specials(n, k, t))


import math
(n, k) = [int(n) for n in input().split()]
t = [int(n) for n in input().split()]
nSpecial = 0
chapterStart = 1
for chapter in range(n):
	for problemNumber in range(1, t[chapter] + 1):
		pageNumber = chapterStart + (math.ceil(problemNumber / k) - 1)
		if pageNumber == problemNumber:
			nSpecial += 1
	chapterStart += math.ceil(t[chapter] / k)
print(nSpecial)


line = input().split(' ')
chapters = int(line[0])
max_page = int(line[1])
t_values = input().split(' ')
t_values = [int(t_values[i]) for i in range(chapters)]
book = []
pageCount = 0
supe = 0
for i in range(chapters):
	qus = t_values[i]
	pageCount += 1
	count = 0
	for index in range(1, qus + 1):
		if count == max_page:
			count = 0
			pageCount += 1
		if index == pageCount:
			supe += 1
		count += 1
print(supe)


(n, k) = map(int, input().split())
t = map(int, input().split())
page = 0
ct_special = 0
for chap in t:
	for index in range(1, chap + 1):
		if (index - 1) % k == 0 or index == 1:
			page += 1
		if page == index:
			ct_special += 1
print(ct_special)


(n, k) = input().strip().split(' ')
(n, k) = (int(n), int(k))
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
p = 0
s = 0
for c in range(1, n + 1):
	p += 1
	for x in range(1, arr[c - 1] + 1):
		if p == x:
			s += 1
		if x % k == 0 and x < arr[c - 1]:
			p += 1
print(s)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
page = 1
count = 0
for i in range(n):
	flag = 0
	while arr[i] > 0:
		problems = arr[i]
		problemstart = 1 + flag * k
		if arr[i] < k:
			problemend = problemstart + arr[i] - 1
		else:
			problemend = problemstart + k - 1
		if page in range(problemstart, problemend + 1):
			count += 1
		arr[i] -= k
		flag += 1
		page += 1
print(count)


import math
curr_page_num = 0
num_matches = 0
(n, k) = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
for i in range(n):
	for j in range(math.ceil(t[i] / k)):
		curr_page_num += 1
		sub_range = list(range(k * j + 1, k * j + k + 1))
		sub_range = [item for item in sub_range if item <= t[i]]
		if curr_page_num in sub_range:
			num_matches += 1
print(num_matches)


(n, k) = [int(x) for x in input().split(' ')]
ti = [int(x) for x in input().split(' ')]
total = sum(ti)
res = 0
page = 1
for lim in ti:
	for num in range(1, lim + 1):
		if num == page:
			res += 1
		if num % k == 0 and num != lim:
			page += 1
	page += 1
print(res)


(num_chapters, max_problems_per_page) = [int(x) for x in str(input()).split()]
problems_per_chapter = [int(x) for x in list(str(input()).split())]
current_page = 1
current_problem_on_page = 0
current_problem_in_set = 0
specials = 0
for problem_set in problems_per_chapter:
	while current_problem_in_set < problem_set:
		current_problem_in_set += 1
		if current_problem_on_page == max_problems_per_page:
			current_problem_on_page = 1
			current_page += 1
		else:
			current_problem_on_page += 1
		if current_problem_in_set == current_page:
			specials += 1
	current_page += 1
	current_problem_on_page = 0
	current_problem_in_set = 0
print(specials)


(n, k) = [int(x) for x in input().strip().split(' ')]
prob = [int(x) for x in input().strip().split(' ')]
spec = 0
page = 0
for chap in range(n):
	page += 1
	pr = 1
	pr_in_page = 1
	while pr <= prob[chap]:
		if pr == page:
			spec += 1
		if pr_in_page == k:
			if pr != prob[chap]:
				page += 1
			pr_in_page = 1
		else:
			pr_in_page += 1
		pr += 1
print(spec)


import sys
import math
inp1 = [int(i) for i in input().strip().split()]
chaps = inp1[0]
maxProbsPerChap = inp1[1]
probsPerChap = [int(i) for i in input().strip().split()]
page = 0
spclProb = 0
for probs in probsPerChap:
	page = page + 1
	i = 1
	count = 0
	while i <= probs:
		count = count + 1
		if count > maxProbsPerChap:
			page = page + 1
			count = 1
		if i == page:
			spclProb = spclProb + 1
		i = i + 1
print(spclProb)


def rulebook(num_prob, curr_page, k):
	if k == 1:
		return [num_prob, curr_page + 1]
	else:
		prob_page = {}
		i = 1
		count = 0
		while i <= num_prob:
			if i % k == 1:
				curr_page = curr_page + min(1, int(i / k))
			prob_page[i] = curr_page
			if i == prob_page[i]:
				count = count + 1
			i = i + 1
		return [count, curr_page + 1]
(n, k) = input().strip().split(' ')
(n, k) = [int(n), int(k)]
chapters = input().strip().split(' ')
i = 0
count = 0
curr_page = 1
while i < len(chapters):
	chapters[i] = int(chapters[i])
	count = count + rulebook(chapters[i], curr_page, k)[0]
	curr_page = rulebook(chapters[i], curr_page, k)[1]
	i = i + 1
print(count)


(N, K) = input().split(' ')
N = int(N)
K = int(K)
arr = [int(probs) for probs in input().split(' ')]
results = 0
current_problem = arr[0]
current_chapter = 0
current_prob_pointer = 1
current_pages = 1
while current_problem > 0:
	if current_problem >= K:
		if current_pages in range(current_prob_pointer, current_prob_pointer + K):
			results += 1
	elif current_pages in range(current_prob_pointer, arr[current_chapter] + 1):
		results += 1
	if current_problem <= K:
		current_prob_pointer = 1
		current_chapter += 1
		if current_chapter < N:
			current_problem = arr[current_chapter]
		else:
			current_problem = 0
	else:
		current_prob_pointer += K
		current_problem -= K
	current_pages += 1
print(results)


from math import ceil, floor
(n, k) = [int(x) for x in input().strip().split(' ')]
t = [int(y) for y in input().strip().split(' ')]
cur_page = 1
special = 0
for probs in t:
	even = probs % k == 0
	page_count = floor(probs / k)
	for i in range(page_count):
		lower_bound = i * k + 1
		upper_bound = (i + 1) * k
		if cur_page <= upper_bound and cur_page >= lower_bound:
			special += 1
		cur_page += 1
	if not even:
		lower_bound = page_count * k + 1
		upper_bound = probs
		if cur_page <= upper_bound and cur_page >= lower_bound:
			special += 1
		cur_page += 1
print(special)


from math import ceil

def get_split(x, k):
	r = []
	for i in range(ceil(x / k)):
		r.append(tuple(range(i * k + 1, min((i + 1) * k, x) + 1)))
	return r
(n, k) = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
p = [ceil(x / k) for x in t]
r = [i for s in [get_split(x, k) for x in t] for i in s]
s = 0
for i in range(sum(p)):
	if i + 1 in r[i]:
		s += 1
print(s)


(n, k) = list(map(int, input().split()))
chap = list(map(int, input().split()))
pages = []
import math
for c in chap:
	tasks = list(range(1, c + 1))
	pages_needed = math.ceil(c / k)
	for p in range(pages_needed):
		pages.append(set(tasks[k * p:(p + 1) * k]))
count = 0
for (i, v) in enumerate(pages):
	if i + 1 in v:
		count += 1
print(count)


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
page_no = 0
count = 0
for num_problems in t:
	bpn = 0
	while num_problems > 0:
		epn = bpn + (k if num_problems > k else num_problems) - 1
		if page_no >= bpn and page_no <= epn:
			count += 1
		num_problems -= epn - bpn + 1
		page_no += 1
		bpn = epn + 1
print(count)


(n, k) = [int(num) for num in input().split()]
chapters = [int(num) for num in input().split()]
matches = 0
page = 0
for chapter in chapters:
	numOnPage = 0
	page += 1
	for problem in range(1, chapter + 1):
		if numOnPage + 1 > k:
			page += 1
			numOnPage = 1
		else:
			numOnPage += 1
		if problem == page:
			matches += 1
print(matches)


(n, k) = input().strip().split(' ')
(n, k) = (int(n), int(k))
t = input().strip().split(' ')
t = [int(t_i) for t_i in t]
pages = []
for t_i in t:
	i = 0
	while t_i >= i * k:
		page = []
		page = [entry + 1 for entry in range(i * k, i * k + k) if entry + 1 <= t_i]
		i = i + 1
		if len(page) > 0:
			pages.append(page)
special = 0
for i in range(len(pages)):
	page = pages[i]
	if i + 1 in page:
		special = special + 1
print(special)


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
speciaux = 0
page = 0
for chapter in range(n):
	problems = t[chapter]
	for p in range(0, problems, k):
		if p <= page < min(p + k, problems):
			speciaux += 1
		page += 1
print(speciaux)


__author__ = 'sunghyo.jung'
(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
r = 0
p = 1
for c in a:
	for i in range(1, c + 1):
		if p == i:
			r += 1
		if i % k == 0 and i != 0 and (i != c):
			p += 1
	p += 1
print(r)


(n, k) = [int(x) for x in input().strip().split(' ')]
problems = [int(x) for x in input().strip().split(' ')]
pageIndex = 1
answer = 0
for p in problems:
	for index in range(1, p + 1):
		if index == pageIndex:
			answer += 1
		if index % k == 0 or index == p:
			pageIndex += 1
print(answer)


(n, k) = input().split()
(n, k) = (int(n), int(k))
prob = [int(x) for x in input().split()]
page = 0
specials = 0
for c in prob:
	for q in range(1, c + 1):
		if q == 1 or (q > 1 and (q - 1) % k == 0):
			page += 1
		if q == page:
			specials += 1
print(specials)


def inps():
	return [int(get) for get in input().strip().split(' ')]
(n, k) = inps()
a = inps()
(c, op) = (0, 1)
for j in a:
	for i in range(1, j + 1):
		p = op + (i - 1) // k
		if i == p:
			c += 1
	op = p + 1
print(c)


(n, k) = map(int, input().split())
count = 0
special = 0
arr = [int(x) for x in input().split()]
for i in range(n):
	if arr[i] <= k:
		if count + 1 >= 1 and count + 1 <= arr[i]:
			special += 1
		count += 1
	else:
		bulk = arr[i] // k
		for b in range(bulk):
			if count + b + 1 >= k * (b + 1) - k + 1 and count + b + 1 <= k * (b + 1):
				special += 1
		count += bulk
		mod = arr[i] % k
		if mod > 0:
			count += 1
		if mod > 0 and count >= arr[i] - mod + 1 and (count <= arr[i]):
			special += 1
print(special)


import math
(n, k) = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
count = 0
index = [1]
for i in range(0, n - 1):
	index.append(index[i] + math.ceil(t[i] / k))
for i in range(n):
	for j in range(t[i]):
		if j + 1 == index[i] + j // k:
			count += 1
print(count)


import sys
import math
(n, k) = input().strip().split(' ')
(n, k) = [int(n), int(k)]
exercises = [int(arr_temp) for arr_temp in input().strip().split(' ')]
num_pages = 0
result = 0
for num_exs in exercises:
	pages_per_chapter = math.ceil(num_exs / k)
	excer_per_chapter = list(range(1, num_exs + 1))
	for i in range(1, pages_per_chapter + 1):
		num_pages += 1
		page = excer_per_chapter[(i - 1) * k:i * k]
		if num_pages in page:
			result += 1
print(result)


import functools, math
(_, max_p) = [int(i) for i in input().strip().split(' ')]
arr = [int(i) for i in input().strip().split(' ')]
print(len([_ for (pg, (ch_, prob_num)) in [(i_ // max_p + 1, tup) for (i_, tup) in enumerate(functools.reduce(lambda x, y: x + y, [list(zip([ch] * padded_p, range(1, padded_p + 1))) for (ch, padded_p) in [(i + 1, max_p * int(math.ceil(p / max_p))) for (i, p) in enumerate(arr)]]))] if pg == prob_num and prob_num <= arr[ch_ - 1]]))


(n, k) = input().split()
(n, k) = (int(n), int(k))
arr = [int(x) for x in input().split()]
pgno = 1
chapter = 0
prob = 1
special = 0
for _ in range(sum(arr)):
	if pgno == prob:
		special += 1
	if prob == arr[chapter]:
		pgno += 1
		prob = 1
		chapter += 1
	else:
		if prob % k == 0:
			pgno += 1
		prob += 1
print(special)


import sys
(n, k) = input().split()
(n, k) = (int(n), int(k))
arr = [int(arr_temp) for arr_temp in input().split()]
count = 0
page = 0
for i in range(n):
	page += 1
	for j in range(1, arr[i] + 1):
		if j > 1 and (j - 1) % k == 0:
			page += 1
		if page == j:
			count += 1
print(count)


import sys
(n, k) = list(map(int, input().split()))
cs = list(map(int, input().split()))
css = [list(range(1, x + 1)) for x in cs]
print(css, file=sys.stderr)
book = []
book.append([])
while len(css):
	chapter = css.pop(0)
	pages = []
	while len(chapter) > k:
		pages.append(chapter[0:k])
		chapter = chapter[k:]
	if len(chapter):
		pages.append(chapter)
	book.extend(pages)
res = 0
print(book, file=sys.stderr)
for i in range(len(book)):
	for j in book[i]:
		if j == i:
			res += 1
print(res)


(n, k) = [int(i) for i in input().strip().split(' ')]
t = [int(i) for i in input().strip().split(' ')]
page = 1
special = 0
for i in range(n):
	problem = 1
	problemOnPage = 0
	for j in range(t[i]):
		if problem == page:
			special += 1
		problem += 1
		problemOnPage += 1
		if problemOnPage == k and j != t[i] - 1:
			page += 1
			problemOnPage = 0
	page += 1
print(special)


import math
(total_c, max_p) = map(int, input().strip().split(' '))
p_nums = list(map(int, input().strip().split(' ')))
special_num = 0
cur_page = 1
for ch_p in p_nums:
	adding = math.ceil(ch_p / max_p)
	ch_pages = [x for x in range(cur_page, cur_page + adding)]
	num_p = [x for x in range(1, ch_p + 1)]
	index = 0
	for each in ch_pages:
		special_num += 1 if each in num_p[max_p * index:max_p * (index + 1)] else 0
		index += 1
	cur_page += adding
print(special_num)


import sys
(n, k) = input().strip().split(' ')
(n, k) = [int(n), int(k)]
chaps = [int(chaps_temp) for chaps_temp in input().strip().split(' ')]
cnt = 0
page = 0
for probs in chaps:
	pmin = 1
	pmax = 0
	while pmax < probs:
		page = page + 1
		pmax = min(pmin + k - 1, probs)
		if page >= pmin:
			if page <= pmax:
				cnt = cnt + 1
		pmin = pmin + k
print(cnt)


(n, k) = [int(x) for x in input().strip().split(' ')]
ch = [int(x) for x in input().strip().split(' ')]
pgs = []
for p in ch:
	pg = list(range(1, p + 1))
	for i in range(0, p, k):
		pgs.append(pg[i:i + k])
sp = 0
for pgn in range(1, len(pgs) + 1):
	try:
		ex = pgs[pgn - 1].index(pgn)
		sp += 1
	except:
		pass
print(sp)


inp0 = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
(n, k) = (inp0[0], inp0[1])
current_page = -1
special = 0
for i in range(n):
	for j in range(t[i]):
		if j % k == 0:
			current_page += 1
		if j == current_page:
			special += 1
print(special)


def lisa(k, i):
	counter = 0
	pages = 0
	for nr in i:
		counter2 = 1
		prob = 1
		pages += 1
		while nr > 0:
			if counter2 == k + 1 and nr != 0:
				pages += 1
				counter2 = 1
			if prob == pages:
				counter += 1
			prob += 1
			counter2 += 1
			nr -= 1
	return counter
(n, k) = map(int, input().split())
i = list(map(int, input().split()))
print(lisa(k, i))


import sys, math
from collections import defaultdict
num = list(map(int, input().strip().split(' ')))
num_chapters = num[0]
max_problems = num[1]
problems = list(map(int, input().strip().split(' ')))
ref = defaultdict(list)
page_num = 1
problem_count = 0
count = 0
boo = False
for p in problems:
	for i in range(1, p + 1):
		ref[page_num].append(i)
		if i % max_problems == 0:
			page_num += 1
			if i == p:
				boo = True
	if boo == False:
		page_num += 1
	boo = False
for key in ref:
	for i in ref[key]:
		if i == key:
			count += 1
print(count)


import math
(_, problems_per_page) = [int(x) for x in input().strip().split(' ')]
all_chapter_problems = [int(x) for x in input().strip().split(' ')]
book = []
for num_chapter_problems in all_chapter_problems:
	chapter_problems = list(range(num_chapter_problems))
	book += [chapter_problems[i:i + problems_per_page] for i in range(0, num_chapter_problems, problems_per_page)]
print(sum((page_number in page_problems for (page_number, page_problems) in enumerate(book))))


import math
(n, k) = input().strip().split(' ')
(n, k) = [int(n), int(k)]
questions = [int(ques) for ques in input().strip().split(' ')]
total_pages = 0
special_problem = 0
for chap in range(n):
	ques_in_chap = questions[chap]
	pages_in_chap = math.ceil(ques_in_chap / k)
	for page in range(pages_in_chap):
		total_pages = total_pages + 1
		if k * page + 1 <= total_pages <= k * (page + 1) and total_pages <= ques_in_chap:
			special_problem = special_problem + 1
print(special_problem)