import sequtils, strutils let nmpq = stdin.readLine.split.map parseInt n = nmpq[0] # 初期値 m = nmpq[1] # 減 / 月 p = nmpq[2] # m2倍 q = nmpq[3] # pの長さ(ヶ月) var month = 1 cnt = n double = 0 ans = 1 while true: cnt.dec m if month == p: double = q if double > 0: cnt.dec m double.dec if cnt <= 0: break month.inc if month > 12: month = 1 ans.inc echo ans