n,a,b,c=map(int,input().split()) inf=1<<62 dp=[inf]*n res=0 for i in range(n): dp[i%n]=a*i+(i>0)*b from heapq import heappop,heappush ans=dp.copy() ans0=inf for j in range(1,60): res+=c hq=[] ndp=[inf]*n d=pow(2,j,n) for i in range(n): ndp[(i+d)%n]=dp[i]+a+b heappush(hq,(dp[i]+a+b,(i+d)%n)) while hq: val,idx=heappop(hq) if idx==0: ans0=min(ans0,val+res) if ndp[idx]+a