n,a,b,c = map(int, input().split()) g = [[] for _ in range(n*2)] g[n].append((0, 0)) fact = 1 fact_ = 0 for i in range(n): g[i].append((i+1, a)) if i < n-1: g[i+n].append((i+n+1, a)) else: g[i].append((n, a)) ok = 0 for k in range(2, 30): if b ** k >= 10**9: break if i ** k >= n: ok = 1 if ok: g[i].append((pow(i, k, n)+n, b**k)) g[i+n].append((pow(i, k, n)+n, b**k)) else: g[i].append((i ** k, b**k)) g[i+n].append((pow(i, k, n)+n, b**k)) g[i+n].append((0, c)) if fact_: g[i].append((fact + n, c)) else: g[i].append((fact, c)) if fact * (i+1) >= n: fact_ = 1 fact = fact * (i+1) % n def dijkstra(s, g): from heapq import heappop, heappush n = len(g) dist = [float("inf")]*n dist[s] = 0 q = [(0, s)] while q: d, v = heappop(q) if dist[v] < d: continue for u, c in g[v]: if dist[u] > dist[v] + c: dist[u] = dist[v] + c heappush(q, (dist[u], u)) return dist dist = dijkstra(1, g) print(dist[0])