#include #include #include using namespace std; using ll = long long; vector> matpow(vector> a, ll x){ vector> res(a.size(), vector(a.size(), 1LL << 60)); for(int i = 0; i < a.size(); i++) res[i][i] = 0; for(; x > 0; x >>= 1){ if(x & 1){ vector> nres(a.size(), vector(a.size(), 1LL << 30)); for(int i = 0; i < a.size(); i++){ for(int j = 0; j < a.size(); j++){ for(int k = 0; k < a.size(); k++){ nres[i][j] = min(nres[i][j], res[i][k]+a[k][j]); } } } res = nres; } vector> na(a.size(), vector(a.size(), 1LL << 60)); for(int i = 0; i < a.size(); i++){ for(int j = 0; j < a.size(); j++){ for(int k = 0; k < a.size(); k++){ na[i][j] = min(na[i][j], a[i][k]+a[k][j]); } } } a = na; } return res; } int main(){ ll n, a, b; cin >> n >> a >> b; vector> mat(2, vector(2)); mat[0][0] = a+b; mat[0][1] = -a+b; mat[1][0] = -a-b; mat[1][1] = a-b; auto res = matpow(mat, n-1); ll ans1 = min(res[0][0]+b, res[0][1]-b); ll ans2 = min(res[1][0]+b, res[1][1]-b); cout << min(ans1, ans2) << endl; return 0; }