You wish to buy video games from the famous online video game store Mist.

Usually, all games are sold at the same price, $\boldsymbol{p}$ dollars. However, they are planning to have the seasonal Halloween Sale next month in which you can buy games at a cheaper price. Specifically, the first game will cost $\boldsymbol{p}$ dollars, and every subsequent game will cost $\boldsymbol{d}$ dollars less than the previous one. This continues until the cost becomes less than or equal to $m$ dollars, after which every game will cost $m$ dollars. How many games can you buy during the Halloween Sale?

Example 

$p=20$ 

$\boldsymbol{d}=3$ 

$m=6$ 

$s=70$. 

The following are the costs of the first $\mbox{11}$, in order:

$20,17,14,11,8,6,6,6,6,6,6$

Start at $p=20$ units cost, reduce that by $\boldsymbol{d}=3$ units each iteration until reaching a minimum possible price, $m=6$.  Starting with $s=70$ units of currency in your Mist wallet, you can buy 5 games: $20+17+14+11+8=70$.

Function Description  

Complete the howManyGames function in the editor below.  

howManyGames has the following parameters:  

int p: the price of the first game  
int d: the discount from the previous game price
int m: the minimum cost of a game  
int s: the starting budget  

Input Format

The first and only line of input contains four space-separated integers $\boldsymbol{p}$, $\boldsymbol{d}$, $m$ and $\boldsymbol{\mathrm{~s~}}$.  

Constraints

$1\leq m\leq p\leq100$  
$1\leq d\leq100$  
$1\leq s\leq10^4$  

Sample Input 0
20 3 6 80

Sample Output 0
6

Explanation 0

Assumptions other than starting funds, $\boldsymbol{\mathrm{~S~}}$, match the example in the problem statement.  With a budget of $\textbf{80}$, you can buy $\boldsymbol{6}$ games at a cost of $20+17+14+11+8+6=76$. A $7^{th}$ game for an additional $\boldsymbol{6}$ units exceeds the budget.    

Sample Input 1
20 3 6 85

Sample Output 1
7

Explanation 1

This is the same as the previous case, except this time the starting budget $s=85$ units of currency. This time, you can buy $7$ games since they cost $20+17+14+11+8+6+6=82$. An additional game at $\boldsymbol{6}$ units will exceed the budget.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
(p, d, m, s) = map(int, input().split())
i = 0
cost = p
while s - cost >= 0:
	i += 1
	s -= cost
	cost = max(cost - d, m)
print(i)


import sys

def howManyGames(p, d, m, s):
	cur_price = p
	bought = 0
	while s >= cur_price:
		bought += 1
		s -= cur_price
		cur_price -= d
		if cur_price <= m:
			cur_price = m
	return bought
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	acc = 0
	number = 0
	while acc < s:
		acc += p
		p -= d
		if p < m:
			p = m
		number += 1
	return number - 1 if acc > s else number
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	cost = p
	num = 0
	while cost <= s:
		s -= cost
		num += 1
		cost = max(cost - d, m)
	return num
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
bought = 0
cost = p
dollarsLeft = s
while True:
	if dollarsLeft < cost:
		break
	else:
		dollarsLeft -= cost
		bought += 1
		cost = max(m, cost - d)
print(bought)


import sys

def howManyGames(p, d, m, s):
	ans = 0
	while 1:
		c = max(p - d * ans, m)
		if c <= s:
			s -= c
			ans += 1
		else:
			break
	return ans
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	total = 0
	while total <= s:
		total += p
		if p - d > m:
			p -= d
		else:
			p = m
		count += 1
	return count - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while True:
		if s - p >= 0:
			s -= p
			count += 1
			if p - d >= m:
				p -= d
			else:
				p = m
		else:
			break
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
ans = 0
while s > 0 and p <= s:
	s -= p
	p = max(p - d, m)
	ans += 1
print(ans)


import sys

def howManyGames(p, d, m, s):
	cnt = 0
	curr = p
	while s >= curr:
		cnt += 1
		s -= curr
		curr = max(curr - d, m)
	return cnt
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	tot = 0
	i = 0
	while tot <= s:
		tot += p
		p -= d
		i += 1
		if p < m:
			p = m
	return i - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


(p, d, m, s) = list(map(int, input().split()))
ans = 0
while s >= 0:
	if s - p >= 0:
		ans += 1
		s -= p
		p = max(p - d, m)
	else:
		break
print(ans)


import sys

def howManyGames(p, d, m, s):
	price = p
	total = 0
	while s >= price:
		total += 1
		s -= price
		price -= d
		if price < m:
			price = m
	return total
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	outVal = 1
	gameNum = 0
	thisPrice = p
	keepGoing = True
	while keepGoing:
		if s >= thisPrice:
			gameNum += 1
			s -= thisPrice
		else:
			keepGoing = False
		thisPrice -= d
		if thisPrice < m:
			thisPrice = m
	return gameNum
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	temp = s
	count = 0
	price = p
	while temp - price >= 0:
		temp -= price
		count += 1
		if price - d >= m:
			price -= d
		else:
			price = m
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	x = p
	sum = 0
	c = 0
	while sum + x <= s:
		sum += x
		x -= d
		x = max(x, m)
		c += 1
	return c
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	ans = 0
	while s >= p:
		s -= p
		ans += 1
		p = max(m, p - d)
	return ans
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	n = 0
	while True:
		s -= p
		if s < 0:
			break
		if p > m:
			p -= d
			if p < m:
				p = m
		n += 1
	return n
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	c = 0
	while s >= p:
		s -= p
		if p - d > m:
			p -= d
		else:
			p = m
		c += 1
	return c
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	games = 0
	while s >= 0:
		if games == 0:
			cost = p
		elif cost == m:
			pass
		else:
			cost = cost - d
			if cost <= m:
				cost = m
		s -= cost
		games += 1
	return games - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	total = 0
	games = 0
	while True:
		total += p
		if total > s:
			break
		games += 1
		if p - d >= m:
			p = p - d
		else:
			p = m
	return games
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


def howManyGames(p, d, m, s):
	games = 0
	while s - p >= 0:
		games += 1
		s -= p
		if p - d >= m:
			p -= d
		else:
			p = m
	return games
(p, d, m, s) = input().split()
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	games = 0
	while s > 0:
		s -= p
		games += 1
		if p > m:
			p = max(p - d, m)
	if s < 0:
		games -= 1
	return games
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def nextprice(p, m, d):
	if p < m:
		return m
	if p > m:
		return p
	return m

def howManyGames(p, d, m, s):
	num = 0
	n = nextprice(p, m, d)
	while s >= n:
		s -= n
		num += 1
		p = p - d
		n = nextprice(p, m, d)
	return num
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


def howManyGames(p, d, m, s):
	result = 0
	cp = p
	while s >= cp:
		s -= cp
		cp -= d
		if cp < m:
			cp = m
		result += 1
	return result
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	money_left = s
	price_of_next_game = p
	games_bought = 0
	while money_left >= price_of_next_game:
		money_left -= price_of_next_game
		games_bought += 1
		proposed_price_of_next_game = price_of_next_game - d
		if proposed_price_of_next_game <= m:
			price_of_next_game = m
		else:
			price_of_next_game = proposed_price_of_next_game
	return games_bought
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while s >= p:
		s -= p
		count += 1
		if p - d < m:
			p = m
		else:
			p -= d
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(price, dec, minimum, wallet):
	games = 0
	while wallet >= 0:
		wallet = wallet - price
		games = games + 1 if wallet >= 0 else games
		price = price - dec if price - dec > minimum else minimum
	return games
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	ans = 0
	if s < p:
		return ans
	ans = 1
	s -= p
	cur_price = max(p - d, m)
	while s >= cur_price:
		s -= cur_price
		ans += 1
		cur_price = max(cur_price - d, m)
	return ans
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	total = 0
	many = 0
	now = p
	total = total + now
	if total <= s:
		many = 1
	else:
		return 0
	if now - d > m:
		now = now - d
	else:
		now = m
	while total + now <= s:
		total = total + now
		many = many + 1
		if now - d > m:
			now = now - d
		else:
			now = m
	return many
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	cost = 0
	i = 0
	while cost <= s:
		x = p - d * i
		i += 1
		if x <= m:
			x = m
		cost = cost + x
	return i - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


(p, d, m, s) = (int(x) for x in input().split())
cnt = 0
k = p
while s >= 0:
	cnt += 1
	s = s - k
	k = k - d
	if k < m:
		k = m
print(cnt - 1)


import sys

def howManyGames(p, d, m, s):
	i = 0
	c = 0
	while c <= s:
		if p - d * i > m:
			c += p - d * i
		else:
			c += m
		i += 1
	return i - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	total = 0
	count = 0
	while total <= s:
		total = total + p
		count += 1
		p = p - d
		if p < m:
			p = m
	return count - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


from itertools import count

def howManyGames(p, d, m, s):
	t = 0
	for i in count(0):
		t += p
		if t > s:
			return i
		p = max(p - d, m)
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	answer = 0
	sum = 0
	while sum <= s:
		if p <= m:
			sum += m
			answer += 1
		else:
			sum += p
			p = p - d
			answer += 1
	return answer - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	sum = p
	count = 0
	while p - d > m and sum <= s:
		sum = sum + p - d
		p = p - d
		count = count + 1
	while sum <= s:
		sum = sum + m
		count += 1
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	n = 0
	while p >= m and s >= 0:
		n += 1
		s -= p
		p -= d
	while s >= 0:
		n += 1
		s -= m
	return n - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
gameCount = 0
while s >= 0:
	if p >= m:
		s = s - p
		p = p - d
		gameCount += 1
	else:
		s = s - m
		gameCount += 1
if s < 0:
	print(gameCount - 1)
else:
	print(gameCount)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while s - p >= 0:
		s = s - p
		if p - d <= m:
			p = m
		else:
			p = p - d
		count += 1
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while s >= p:
		count += 1
		s -= p
		if p - d >= m:
			p -= d
		else:
			p = m
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	curPrice = p
	res = 0
	while True:
		if s >= curPrice:
			res += 1
			s -= curPrice
		else:
			break
		if curPrice > m:
			curPrice = max(curPrice - d, m)
	return res
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	i = p
	ct = 0
	while s >= 0:
		if i <= m:
			s = s - m
		else:
			s = s - i
			i = i - d
		if s >= 0:
			ct += 1
	return ct
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def game_count(p: int, d: int, m, s) -> int:
	count = 0
	while s > 0:
		if s >= max(p, m):
			s -= max(p, m)
			p -= d
			count += 1
		else:
			break
	return count

def main():
	(p, d, m, s) = [int(x) for x in input().split()]
	result = game_count(p, d, m, s)
	print(result)
main()


import sys

def howManyGames(p, d, m, s):
	ans = 0
	nextCost = max(p, m)
	while s >= nextCost:
		p -= d
		s -= nextCost
		nextCost = max(p, m)
		ans += 1
	return ans
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


(p, d, m, mon) = map(int, input().split())
ans = 0
sum1 = 0
c = 0
while sum1 <= mon:
	ans += 1
	sum1 += p
	p -= d
	if p < m:
		p = m
print(ans - 1)


import sys

def howManyGames(p, d, m, s):
	g = 0
	while p > m and s >= p:
		g += 1
		s -= p
		p -= d
	if p < m:
		p = m
	if s >= p:
		g += int(s / p)
	return g
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	x = 0
	flag = 1
	while 1:
		if s - p < 0:
			return x
		else:
			s -= p
			x += 1
		if p - d > m and flag:
			p -= d
		else:
			flag = 0
			p = m
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	if s < p:
		return 0
	if s == p:
		return 1
	if p == m:
		return s // m
	else:
		return 1 + howManyGames(max(p - d, m), d, m, s - p)
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	k = 0
	while s > 0:
		s = s - p
		if s < 0:
			break
		p = p - d
		if p <= m:
			p = m
		k += 1
	return k
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	buyable = 0
	total = 0
	i = 0
	while True:
		if p - i * d <= m:
			total += m
		else:
			total += p - i * d
		if total > s:
			return i
			break
		i += 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	k = int((p - m) / d)
	ans = 0
	if (k + 1) * p - k * (k + 1) / 2 * d < s:
		left = s - (k + 1) * p + k * (k + 1) * d / 2
		ans = k + 1
		while left >= 0:
			left = left - m
			ans = ans + 1
		ans = ans - 1
		return ans
	else:
		left = s
		for j in range(k + 1):
			left = left - p + j * d
			if left >= 0:
				ans = ans + 1
			else:
				return ans
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	c = 0
	while p > m and s >= p:
		c += 1
		s -= p
		p = max(p - d, m)
	return c + s // p
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while s > 0:
		if s >= p and p >= m + d:
			s -= p
			count += 1
			p -= d
		elif s >= p and p < m + d and (p >= m):
			s -= p
			p = m
			count += 1
		if s < p:
			s = 0
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	i = 0
	total = 0
	while total <= s:
		term = p - i * d
		if term < m:
			term = m
		total += term
		i += 1
	return i - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	pur = 0
	while pur <= s:
		pur = pur + p
		if p - d >= m:
			p = p - d
		else:
			p = m
		count = count + 1
	return count - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


def howManyGames(p, d, m, s):
	count = 0
	sumi = 0
	while sumi <= s:
		if p < m:
			sumi = sumi + m
		else:
			sumi = sumi + p
			p = p - d
		count = count + 1
	return count - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while True:
		if p > m:
			if s - p < 0:
				break
			s = s - p
			p = p - d
			count += 1
		else:
			if s - m < 0:
				break
			s = s - m
			count += 1
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	k = (p - m) / d
	if k % 1 != 0:
		k = int(k) + 1
	cost = 0
	count = 0
	i = 0
	while cost < s:
		if count < k:
			cost += p - i * d
		else:
			cost += m
		count += 1
		i += 1
	r = 0
	if cost == s:
		r = count
	elif cost > s:
		r = count - 1
	return r
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys
import math

def howManyGames(p, d, m, s):
	i = 0
	remaining = s
	price = p
	while remaining >= price:
		i = i + 1
		remaining -= price
		if price > m:
			price = max(m, price - d)
	return i
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	if s < p:
		return 0
	else:
		quotient = s // p
		diffquotient = (p - m) // d
		if quotient <= diffquotient:
			cost = quotient * p - d * quotient * (quotient - 1) // 2
			newP = p - quotient * d
			return quotient + howManyGames(newP, d, m, s - cost)
		cost = diffquotient * p - d * diffquotient * (diffquotient - 1) // 2
		newP = p - diffquotient * d
		if newP > m:
			cost += newP
			newP = m
			if quotient > diffquotient + 1:
				cost += m * (quotient - diffquotient - 1)
			return quotient + howManyGames(newP, d, m, s - cost)
		cost += m * (quotient - diffquotient)
		newP = m
		return quotient + howManyGames(newP, d, m, s - cost)
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


[p, d, m, s] = map(int, input().split())
count = 0
sum = p
while 1:
	if s >= sum:
		count += 1
		s = s - sum
	else:
		break
	if sum - d >= m:
		sum = sum - d
	else:
		sum = m
print(count)


import sys

def howManyGames(p, d, m, s):
	money = s
	price = p
	count = 0
	while money >= price:
		money -= price
		count += 1
		price -= d
		if price < m:
			price = m
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	x = p
	while p <= s:
		if x - d >= m:
			p = p + (x - d)
			count += 1
			x = x - d
		else:
			p = p + m
			x = m
			count += 1
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	cost = 0
	counter = 0
	while s - p >= 0:
		s -= p
		counter += 1
		if p - d >= m:
			p -= d
		else:
			p = m
	return counter
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	b = 0
	i = 0
	while True:
		b += p if p > m else m
		i += 1
		p -= d
		if b == s:
			break
		if b > s:
			i -= 1
			break
	return i
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	ans = 0
	while True:
		s -= p
		if s < 0:
			break
		p -= d
		if p < m:
			p = m
		ans += 1
	return ans
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	cost = 0
	while s >= 0:
		if count == 0:
			cost = p
		else:
			cost = max(cost - d, m)
		s -= cost
		count += 1
	return count - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	c = 0
	while s >= 0:
		s -= p
		if p > m:
			p -= d
		if p <= m:
			p = m
		c += 1
	return c - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	current_price = p
	count = 0
	while s - current_price >= 0:
		s -= current_price
		count += 1
		if current_price > m:
			current_price -= d
			if current_price < m:
				current_price = m
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	ammount = 0
	while s >= m:
		if p >= m:
			if s < p:
				break
			ammount += 1
			s -= p
			p -= d
		else:
			ammount += 1
			s -= m
	return ammount
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while s >= p:
		count = count + 1
		s = s - p
		if p - d >= m:
			p = p - d
		else:
			p = m
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while s >= p:
		count += 1
		s -= p
		if p >= m:
			p = max(m, p - d)
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	l = list()
	count = 0
	while s > 0:
		if p - d > m:
			s = s - p
			p = p - d
			if s >= 0:
				count = count + 1
		elif p - d <= m:
			s = s - p
			p = m
			if s >= 0:
				count = count + 1
		if s - p < 0:
			break
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	if p > s:
		return 0
	count = 0
	sum = 0
	while p > m:
		k = sum
		sum = sum + p
		p = p - d
		count = count + 1
		if sum > s:
			return count - 1
	count = count + (s - sum) // m
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	cusum = 0
	cout = 0
	nxt = p
	while cusum + nxt <= s:
		cusum += nxt
		if nxt - d <= m:
			nxt = m
		else:
			nxt -= d
		cout += 1
	return cout
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys
import math

def howManyGames(p, d, m, s):
	n = math.floor((p - m) / d + 1)
	sum1 = 0
	c = 0
	for i in range(0, n):
		sum1 += p
		p -= d
		c += 1
		if sum1 > s:
			return c - 1
	for i in range(n, s):
		sum1 += m
		c += 1
		if sum1 > s:
			return c - 1
	return c
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	price = p
	totprice = 0
	ngames = 0
	while totprice + price <= s:
		totprice += price
		ngames += 1
		if price - d < m:
			price = m
		else:
			price -= d
	return ngames
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	no = 0
	while s > 0:
		if s >= p:
			no += 1
		s -= p
		if p - d < m:
			p = m
		else:
			p = p - d
	return no
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	if s < p:
		return 0
	if s > p and p >= m:
		return 1 + howManyGames(p - d, d, m, s - p)
	elif s > p and p < m:
		return int(s / m)
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	c = 0
	while True:
		if s >= p:
			c += 1
			s -= p
			p -= d
			if p < m:
				p = m
		else:
			break
	return c
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	amountOfGames = 0
	while s > 0:
		s = s - p
		if s < 0:
			break
		amountOfGames += 1
		p = p - d
		if p <= m:
			p = m
	return amountOfGames
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	g = 0
	c = p
	while True:
		s = s - c
		if s < 0:
			break
		g = g + 1
		if c - d >= m:
			c = c - d
		else:
			c = m
	return g
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	sum = 0
	dam = p
	counter = 0
	while sum <= s:
		if dam > m:
			sum = sum + dam
			dam = dam - d
			counter = counter + 1
		else:
			sum = sum + m
			counter = counter + 1
	if sum == s:
		return counter
	else:
		return counter - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	sum = 0
	n = 0
	count = 0
	cost = 0
	while True:
		if sum <= s:
			cost = p - n * d
			if cost >= m:
				sum = sum + cost
				n = n + 1
				count = count + 1
			elif cost < m:
				sum = sum + m
				count = count + 1
		elif sum > s:
			return count - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	games = 0
	currentSum = p
	while currentSum <= s:
		if p - d > m:
			currentSum += p - d
			p = p - d
		else:
			currentSum += m
		games += 1
	return games
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	c = 0
	while s >= 0:
		if p > m:
			s -= p
			p -= d
		else:
			s -= m
		c += 1
	return c - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	if s < p:
		return 0
	elif s == p:
		return 1
	else:
		while s >= p:
			s = s - p
			count = count + 1
			if count >= 1 and p >= m:
				p = p - d
				if p < m:
					p = m
		return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while s >= 0:
		s -= p
		count += 1
		if p - d >= m:
			p -= d
		else:
			p = m
	return count - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	result = 0
	if p == s:
		return 1
	elif p > s:
		return 0
	while s > 0:
		s = s - p
		p = p - d
		if p <= m:
			p = m
		if s >= 0:
			result = result + 1
	return result
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


def howManyGames(p, d, m, s):
	count = 0
	while s >= p and p >= m:
		count += 1
		s = s - p
		if p - d < m:
			p = m
		else:
			p = p - d
	return count
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	if s < p:
		return 0
	if p <= m:
		p = m
		return s // p
	return 1 + howManyGames(p - d, d, m, s - p)
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	i = 0
	while s >= 0:
		s = s - p
		if p - d >= m:
			p = p - d
		else:
			p = m
		i = i + 1
	if s == 0:
		return i
	else:
		return i - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def price(p, d, m, games):
	prices = p - d * games
	if prices < m:
		return m
	else:
		return prices

def howManyGames(p, d, m, s):
	games = 0
	while s >= 0:
		s -= price(p, d, m, games)
		games += 1
	games -= 1
	return games
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	count = 0
	snew = 0
	while s >= snew:
		if count == 0:
			snew += p
			count += 1
		else:
			p = p - d
			if p >= m:
				snew = snew + p
				count += 1
			else:
				snew = snew + m
				count += 1
	return count - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	ans = 0
	while s > 0:
		if s >= p:
			s -= p
			ans += 1
		else:
			s = 0
		p -= d
		if p < m:
			p = m
	return ans
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	ca = 0
	count = 0
	rate = p
	while True:
		count = count + rate
		rate = rate - d
		if rate <= m:
			rate = m
		ca = ca + 1
		if count > s:
			return ca - 1
		elif count == s:
			return ca
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
cost = p
item = 0
sale = p
while cost <= s:
	sale -= d
	item += 1
	if sale <= m:
		cost += m
	else:
		cost += sale
print(item)


import sys

def howManyGames(p, d, m, s):
	count = 0
	while s >= 0:
		s = s - p
		if p - d >= m:
			p = p - d
		elif p - d <= m:
			p = m
		count = count + 1
	return count - 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)


import sys

def howManyGames(p, d, m, s):
	if p > s:
		return 0
	steps = (p - m) // d
	pre = (p + p - d * steps) * (steps + 1) // 2
	if pre > s:
		i = 0
		while s >= p:
			s -= p
			p -= d
			i += 1
		return i
	else:
		return (s - pre) // m + steps + 1
(p, d, m, s) = input().strip().split(' ')
(p, d, m, s) = [int(p), int(d), int(m), int(s)]
answer = howManyGames(p, d, m, s)
print(answer)