def main0(n,k,h,y): a,b=0,0 ans=0 while a<=y: b=0 while a+b<=y: yy=y-a-b if yy%h==0: ans+=1 b+=k a+=n return ans mod=10**9+7 def gcd(a,b): while b:a,b=b,a%b return a def xgcd(a, b): x0, y0, x1, y1 = 1, 0, 0, 1 while b != 0: q, a, b = a // b, b, a % b x0, x1 = x1, x0 - q * x1 y0, y1 = y1, y0 - q * y1 return a, x0, y0 def modinv(a, m): g, x, y = xgcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m def main1(n,k,h,y): ary=[n,k,h] ary.sort() a,b,c=ary g=gcd(a,b) na,nb=a//g,b//g now=0 ans=0 while now<=y: yy=y-now now+=c if yy%g!=0:continue yy=yy//g if yy==0: ans+=1 continue if yy