#!/bin/python3 import sys def howManyGames(p, d, m, s): # Return the number of games you can buy 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) if __name__ == "__main__": 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)