veg,meat,mul,limit = map(int,input().split()) assert 1<=veg<=100 assert 1<=meat<=100 assert 1<=mul<=100 assert 1<=limit<=100 vegs = [] for i in range(1,veg+1): for j in range(1,meat+1): if meat == i*mul: if limit > i+j: vegs.append(i) elif limit == i+j: vegs.append(i) if len(vegs) > 1: print(max(vegs)) else: print(0)