stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>

#include <sstream>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <ctime>

#include <cstring>

#include <string>

#include <vector>

#include <stack>

#include <queue>

#include <deque>

#include <map>

#include <set>

#include <bitset>

#include <numeric>

#include <utility>

#include <iomanip>

#include <algorithm>

#include <functional>

using namespace std;



#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)



template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)

{ return s << '<' << P.first << ", " << P.second << '>'; }

template<class T> ostream& operator << (ostream &s, vector<T> P)

{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }

template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)

{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)

{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }





string str;

bool dp[210000];

string judge [4] = {"dream", "dreamer", "erase", "eraser"};



int main() {

  while (cin >> str) {

	memset(dp, 0, sizeof(dp));

	dp[0] = true;

	for (int i = 0; i < str.size(); ++i) {

	  if (!dp[i]) continue;

	  for (int j = 0; j < 4; ++j) {

		if (str.substr(i, judge[j].size()) == judge[j])

		  dp[i + judge[j].size()] = true;

	  }

	}

	if (dp[str.size()]) puts("YES");

	else puts("NO");

  }

}

		  

	  


// Optimized solution to the same problem (faster):
#include <iostream>

#include <string>

#include <algorithm>

using namespace std;



string divide[4] = {"dream", "dreamer", "erase", "eraser"};



int main() {

    string S;

    cin >> S;

 

    // 後ろから解くかわりにすべての文字列を「左右反転」する

    reverse(S.begin(), S.end());

    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    

    // 端から切っていく

    bool can = true;

    for (int i = 0; i < S.size();) {

        bool can2 = false; // 4 個の文字列たちどれかで divide できるか

        for (int j = 0; j < 4; ++j) {

            string d = divide[j];

            if (S.substr(i, d.size()) == d) { // d で divide できるか

                can2 = true;

                i += d.size(); // divide できたら i を進める

            }

        }

        if (!can2) { // divide できなかったら

            can = false;

            break;

        }

    }

    

    if (can) cout << "YES" << endl;

    else cout << "NO" << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>



using namespace std;



int main() {

    int dp[100005] = {1};



    string S;

    cin >> S;



	for (int i = 0; i < S.size(); i++) {

		if (dp[i] == 0) { continue; }

		if (i + 5 <= S.size() && S.substr(i, 5) == "dream") { dp[i + 5] = 1; }

		if (i + 7 <= S.size() && S.substr(i, 7) == "dreamer") { dp[i + 7] = 1; }

		if (i + 5 <= S.size() && S.substr(i, 5) == "erase") { dp[i + 5] = 1; }

		if (i + 6 <= S.size() && S.substr(i, 6) == "eraser") { dp[i + 6] = 1; }

	}



	if (dp[S.size()] == 1) { cout << "YES" << endl; }

	else { cout << "NO" << endl; }



	return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <string>



using namespace std;



// dp[i] := i文字目までを作ることができるか?

bool dp[100010];

string divide[4] = {"dream", "dreamer", "erase", "eraser"};



int main() {

  string s; cin >> s;



  dp[0] = true;

  for (int i = 0; i < s.length(); i++) {

    if (!dp[i]) { continue; }

    for (int j = 0; j < 4; j++) {

      string t = divide[j];

      if (s.substr(i, t.size()) == t) {

        dp[i+t.size()] = true;

      }

    }

  }

  cout << (dp[s.length()] ? "YES" : "NO") << endl;

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define _GLIBCXX_DEBUG

#define rep(i,n) for(int i = 0; i < (n); ++i)

#define ll long long

#define P pair<ll,ll>

#define all(v) (v).begin(),(v).end()



const ll mod = 1e9+7;

const ll INF = 1e18;

const double pi = acos(-1);





int main(void)

{

    ll r,g,b,n,cnt=0; cin>>r>>g>>b>>n;

    rep(i,n+1)rep(j,n+1){

        ll x=r*i+g*j;

        if((n-x)%b==0 && x<=n) cnt++;

    }

    cout<<cnt<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

#define _GLIBCXX_DEBUG

#define rep(i,n) for(int i = 0; i < (n); ++i)

#define ll long long

#define P pair<ll,ll>

#define all(v) (v).begin(),(v).end()



const ll mod = 1e9+7;

const ll INF = 1e18;

const double pi = acos(-1);





int main(void)

{

    ll r,g,b,n,cnt=0; cin>>r>>g>>b>>n;

    rep(i,n+1)rep(j,n+1){

        ll x=r*i+g*j;

        if(n-x>=0 && (n-x)%b==0) cnt++;

    }

    cout<<cnt<<endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main() {

  int r,g,b,n,ans=0;

  cin>>r>>g>>b>>n;

  for (int i=0;i<=n;i++){

    for(int j=0;j<=n;j++){

      if((n-(i*r)-(j*g))/b>=0 && i*r+j*g+b*((n-(i*r)-(j*g))/b)==n){

          ans++;}

      }

    }

  cout<<ans;

  return 0;

}




// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

using namespace std;

#define lli long long int



int main() {

  int R, G, B, N;

  cin >> R >> G >> B >> N;

  lli cont=0;

  for(int i=0; i<=N; i++){

    for(int j=0; j<=N; j++){

      int A = N - i*R - j*G;

      if(A>=0){

        if(A % B == 0 && A/B <= N)

          cont++;

      }

    }

  }

  cout << cont;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main(){

    long long R,G,B,N;

    cin >> R >> G >> B >> N;

    long long ans = 0;

    for(int i = 0; i <= N; i++){

        for(int j = 0; j <= N; j++){

        int X = N-R*i-G*j;       

            if(X%B == 0 && X>=0){

            ans++;

            }     

        }

    }

    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

#define int long long

typedef pair<int,int> P;

int INF = 1e18;

int mod = 1e9+7;

int dx[4] = {1, 0, -1, 0};

int dy[4] = {0, 1, 0, -1};

signed main() {

    int R,G,B,N;

    cin >> R >> G >> B >> N;

    int ans = 0;

    for(int i = 0; i*R <= N; i++) {

        for(int j = 0; i*R+j*G <= N; j++) {

            if((N-i*R-j*G)%B == 0) {

                ans++;

            }

        }

    }

    cout << ans << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;





int main() {



    int R, G, B, N;

    cin >> R >> G >> B >> N;

    long long ans = 0;

    int MAX = N + 1;

    for (int i = 0; i < MAX; ++i) {

        for (int j = 0; j < MAX; ++j) {

            long long balls = i * R + j * G;

            if ((N - balls) % B == 0 && (N - balls) / B >= 0) {

                ans++;

            }

        }

    }

    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;





int main() {



    int R, G, B, N;

    cin >> R >> G >> B >> N;

    long long ans = 0;

    int MAX = N + 1;

    for (int i = 0; i <= N / R; ++i) {

        int r = i * R;

        if (r > N){ break;}

        for (int j = 0; j <= N/ G; ++j) {

            if (i * R + j * G > N ){break;}

            long long balls = i * R + j * G;

            if ((N - balls) % B == 0 && (N - balls) / B >= 0) {

                ans++;

            }

        }

    }

    cout << ans << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

 

int main() {

  int R,G,B,N;

  cin >>R>>G>>B>>N;

  int ans=0;

  

 for(int i=0;i<=N;i++){

 for(int j=0;j<=N;j++){

   int a=N-(i*R+j*G);

   

   if(a%B==0){if(a>=0){ans++;}} 

 }

 }

  

  cout <<ans<<endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

 

int main() {

  int R,G,B,N;

  cin >>R>>G>>B>>N;

  int ans=0;

  

 for(int i=0;i<=N;i+=R){

 for(int j=0;i+j<=N;j+=G){

   int a=N-(i+j);

   

   if(a%B==0){if(a>=0){ans++;}} 

 }

 }

  

  cout <<ans<<endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>

#define rep(i,n) for (int i = 0;i < (n);i++)

#define all(v) v.begin(),v.end()

using namespace std;

using ll = long long;

using P = pair<ll,ll>;

using vl = vector<ll>;

using vvl = vector<vl>;



ll gcd(ll a,ll b){

  if(b == 0) return a;

  return gcd(b , a % b);

}



ll mod(ll a){

  return a % 1000000007;

}



ll lcm(ll a,ll b){

  return (a*b)/gcd(a,b);

}





int main(){

  ll r,g,b,n; cin >> r >> g >> b >> n; ll count = 0;

  

  for(ll i=0; i <= n; i++){

    for(ll j=0; j <= n; j++){

      if((n-r*i-g*j) % b == 0 && n-r*i-g*j >= 0) count++;

    }

  }

  

  cout << count << endl;

}

// Optimized solution to the same problem (faster):
#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>

#include<algorithm>//next_permutation

#define rep(i,n) for (int i = 0;i < (n);i++)

#define all(v) v.begin(),v.end()

#define dec(n) cout << fixed << setprecision(n);

#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

#define small "abcdefghijklmnopqrstuvwxyz"

using namespace std;

using ll = long long;

using P = pair<ll,ll>;

using vl = vector<ll>;

using vvl = vector<vl>;



ll gcd(ll a,ll b){

  if(b == 0) return a;

  return gcd(b , a % b);

}



const ll MOD = 1000000007;

const ll MAX = 2000001;



ll mod(ll a){

  return a % MOD;

}



ll lcm(ll a,ll b){

  return (a*b)/gcd(a,b);

}



ll fac[MAX], finv[MAX], inv[MAX];



void nCrprep() {

    fac[0] = fac[1] = 1;

    finv[0] = finv[1] = 1;

    inv[1] = 1;

    for (ll i = 2; i < MAX; i++){

        fac[i] = fac[i - 1] * i % MOD;

        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;

        finv[i] = finv[i - 1] * inv[i] % MOD;

    }

}



ll nCr(ll n, ll r){

    if (n < r) return 0;

    if (n < 0 || r < 0) return 0;

    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;

}



ll nCrcheep(ll n,ll r){

  if(r == 0) return 1;

  else if(r == 1) return n;

  else return nCrcheep(n-1,r-1)*n/r;

}



vector<pair<ll,ll>> prime_factorize(ll n){

  vector<pair<ll,ll>> res;

  

  for(ll i=2; i*i <= n; i++){

    if(n % i != 0) continue;

    

    ll ex = 0;

    while(n % i == 0){

      ex++;

      n /= i;

    }

    

    res.push_back({i,ex});

  }

  

  if(n != 1) res.push_back({n,1});

  

  return res;

  

}









int main(){

  ll r,g,b,n; cin >> r >> g >> b >> n;

  ll ans = 0;

  

  rep(i,n+1){

    rep(j,n+1){

      if(n-r*i-g*j >= 0 and (n-r*i-g*j) % b == 0) ans++;

    }

  }

  

  cout << ans << endl;

  

  

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

 string x;

    cin>>x;

    int a=0,b=0;

    for(int i=0;i<3;i++){

        if(x.at(i)=='A'){

            a++;

        }

        else{

            b++;

        }

    }

    if(a==0|| b==0){

        cout<<"No";

    }

    else{

        cout<<"Yes";

    }



    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main(){

	char S, A, B;

	scanf("%c%c%c", &S, &A, &B);

	if(S, A != B){

		printf("Yes\n");

	}else if(S, B != A){

		printf("Yes\n");

	}else if(A, B != S){

		printf("Yes\n");

	}else if( S == A, A == B){

		printf("No\n");

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main() {

    string a;

    cin>>a;

    set <char> s;

    for (int i=0;i<a.length();i++)

        s.insert(a[i]);

    if (s.size()==2)

        cout<<"Yes"<<endl;



    else cout<<"No"<<endl;

    

    

    

}

// Optimized solution to the same problem (faster):
#include <stdio.h>



int main(){

	char S, A, B;

	scanf("%c%c%c", &S, &A, &B);

	if(S, A != B){

		printf("Yes\n");

	}else if(S, B != A){

		printf("Yes\n");

	}else if(A, B != S){

		printf("Yes\n");

	}else if( S == A, A == B){

		printf("No\n");

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstdint>

#include <vector>

#include <algorithm>

#include <set>

#include <string>



int main() {

  char buf[4];

  scanf("%s", buf);

  std::string s = buf;



  if (s == std::string(3, 'A') || s == std::string(3, 'B')) {

    puts("No");

  } else {

    puts("Yes");

  }

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <type_traits>



int main() {

  static_assert(std::is_same<long, decltype(1234567890987654321-1234567890987654321)>::value, "");



  char s[4];

  scanf("%s", s);

  puts(((s[0]+s[1]+s[2]) % 3 == 0)? "No": "Yes");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <complex>



using namespace std;



#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define int long long

#define fori(n) for(int i = 0; i < n; ++i)

#define forj(n) for(int j = 0; j < n; ++j)

#define endl "\n";

typedef long long ll;

typedef pair<int, int> pii;



int32_t main(){

    IOS;

    string s;

    cin >> s;

    if (s == "AAA" || s == "BBB")

        cout << "No";

    else

        cout << "Yes";



}




// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

	char a, b, c;

	scanf("%c%c%c", &a, &b, &c);

	if(a==b && a!=c){

		puts("Yes");

	}

	else if(c==b && a!=c){

		puts("Yes");

	}

	else if(a==c && a!=b){

		puts("Yes");

	}

	else{

		puts("No");

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <algorithm>

#include <map>



typedef long long LL;

const int MN = 20;



int N, A[MN];



struct dat {

	dat() {}

	int a, b, c, d;

	dat(int l, int r, int cl, int cr)

		: a(l), b(r), c(cl), d(cr) {}

	friend bool operator < (dat i, dat j) {

		if (i.a != j.a) return i.a < j.a;

		if (i.b != j.b) return i.b < j.b;

		if (i.c != j.c) return i.c < j.c;

		return i.d < j.d;

	}

};

std::map<dat, LL> f;

LL F(int l, int r, int cl, int cr) {

	dat now(l, r, cl, cr);

	if (f.find(now) != f.end()) return f[now];

	if (l > r) return 0;

	LL ans = 0x3f3f3f3f3f3f3f3f;

	for (int i = l; i <= r; ++i)

		ans = std::min(ans, F(l, i - 1, cl, cl + cr) + (LL)A[i] * (cl + cr) + F(i + 1, r, cl + cr, cr));

	return f[now] = ans;

}



int main() {

	scanf("%d", &N);

	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);

	N -= 2;

	printf("%lld\n", F(1, N, 1, 1) + A[0] + A[N + 1]);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

#include <map>



typedef long long LL;

const int MN = 20;



int N, A[MN];



LL F(int l, int r, int cl, int cr) {

	if (l > r) return 0;

	LL ans = 0x3f3f3f3f3f3f3f3f;

	for (int i = l; i <= r; ++i)

		ans = std::min(ans, F(l, i - 1, cl, cl + cr) + (LL)A[i] * (cl + cr) + F(i + 1, r, cl + cr, cr));

	return ans;

}



int main() {

	scanf("%d", &N);

	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);

	N -= 2;

	printf("%lld\n", F(1, N, 1, 1) + A[0] + A[N + 1]);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

ll f[20][20][20][20];

ll a[20];

ll dfs(int l,int r,int x,int y) {

	if(l+1>=r) return 0;

	ll ans=1e18;

	for(int i=l+1;i<r;i++) {

		ans=min(ans,dfs(l,i,x,x+y)+dfs(i,r,x+y,y)+a[i]*(x+y));

	}

	return f[l][r][x][y]=ans;

}

int main() {

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);

	memset(f,-1,sizeof f);

	printf("%lld\n",a[1]+a[n]+dfs(1,n,1,1));

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

ll a[20];

ll dfs(int l,int r,int x,int y) {

	if(l+1>=r) return 0;

	ll ans=1e18;

	for(int i=l+1;i<r;i++) {

		ans=min(ans,dfs(l,i,x,x+y)+dfs(i,r,x+y,y)+a[i]*(x+y));

	}

	return ans;

}

int main() {

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);

	printf("%lld\n",a[1]+a[n]+dfs(1,n,1,1));

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <iostream>

#include <algorithm>

#include <cstring>

#include <map>

#define pii pair<int,int>

#define MP make_pair

#define fir first

#define sec second

#define PB push_back

#define db long double

#define ll long long

using namespace std;

template <class T>

inline void rd(T &x) {

	x=0; char c=getchar(); int f=1;

	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }

	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;

}

/*

f[l,r,xl,xr]:

	in range [l,r], l and r were the first values vomitted

	l is counted xl times

	r is counted xr times

	f is the minimum possible sum of the contribution of values in range (l,r) ? 

*/

const int N=20;

map<pii,ll> mp[N][N];

int n;

int a[N];

ll dfs(int l,int r,int xl,int xr) {

	if(r==l+1) return 0;

	if(mp[l][r].count(MP(xl,xr))) return mp[l][r][MP(xl,xr)];

	ll ans=1e18;

	for(int k=l+1;k<r;++k)

		ans=min(ans,dfs(l,k,xl,xl+xr)+dfs(k,r,xl+xr,xr)+(xl+xr)*(ll)a[k]);

	return mp[l][r][MP(xl,xr)]=ans;

}

int main() {

	rd(n);

	for(int i=1;i<=n;++i) rd(a[i]);

	printf("%lld\n",dfs(1,n,1,1)+a[1]+a[n]);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;

long long n,v[19],ct;

long long Min(long long a,long long b){return a<b?a:b;}

long long DP(int l,int r,int s1,int s2)

{

	if(l+1==r)return v[l]*s1+v[r]*s2;

	long long as=2e18;

	for(int i=l+1;i<r;i++)as=Min(as,DP(l,i,s1,s1+s2)+DP(i,r,s1+s2,s2)-v[i]*(s1+s2));

	return as;

}

int main(){scanf("%lld",&n);for(int i=1;i<=n;i++)scanf("%lld",&v[i]);printf("%lld\n",DP(1,n,1,1));}//

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



typedef long long ll;



int n;

ll a[20];



inline void down(ll &x, const ll y) {x > y ? x = y : 0;}



ll dfs(int l, int r, int cl, int cr) {

	if (l > r) return 0;

	int i; ll ret = LLONG_MAX;

	for (i = l; i <= r; ++i) down(ret, (cl + cr) * a[i] + dfs(l, i - 1, cl, cl + cr) + dfs(i + 1, r, cl + cr, cr));

	return ret;

}



int main() {

	int i;

	scanf("%d", &n);

	for (i = 1; i <= n; ++i) scanf("%lld", a + i);

	printf("%lld\n", a[1] + a[n] + dfs(2, n - 1, 1, 1));

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;

long long n,v[19],ct;

long long Min(long long a,long long b){return a<b?a:b;}

long long DP(int l,int r,int s1,int s2)

{

	if(l+1==r)return v[l]*s1+v[r]*s2;

	long long as=2e18;

	for(int i=l+1;i<r;i++)as=Min(as,DP(l,i,s1,s1+s2)+DP(i,r,s1+s2,s2)-v[i]*(s1+s2));

	return as;

}

int main(){scanf("%lld",&n);for(int i=1;i<=n;i++)scanf("%lld",&v[i]);printf("%lld\n",DP(1,n,1,1));}//

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <fstream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <vector>

#include <string>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <set>

#include <map>

#include <bitset>

#include <sstream>

#include <iomanip>



using namespace std;



typedef long long ll;

typedef vector <int> vi;

typedef vector <vector <int>> vii;

typedef vector <long long> vll;

typedef vector <string> vs;

typedef vector <char> vc;

typedef set <int> si;

typedef set <string> ss;

typedef queue <int> qi;

typedef queue <long long> qll;

typedef queue <string> qs;

typedef queue <char> qc;

typedef struct board board;

typedef pair <int, int> pi;

typedef pair <long long, long long> pll;

typedef pair <int, pair<int, int>> pii;



#define eb emplace_back

#define ppb pop_back

#define clr(a) a.clear()

#define F first

#define S second

#define mkp make_pair



#define sz(x) (int)(x).size()

#define all(x) (x).begin(), (x).end()



#define left(x) x * 2

#define right(x) x * 2 + 1



#define meme(a, b, c) fill(a + 1, a + 1 + b, c)



#define max(a, b) (a > b ? a : b)

#define min(a, b) (a > b ? b : a)

#define abs(a) (a > 0? a : -(a))



#define move(s) s += "#"



#define fr(i, a, b) for (ll i = a; i <= b; ++ i)

#define rf(i, a, b) for (ll i = a; i >= b; -- i)



#define eprintf(...) fprintf(stderr, __VA_ARGS__);



void to_pray() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    cerr << "Ready\n";

}



const int N = 4e6 + 10;

const int NN = 1e3 + 10;

const int NNN = 2e3 + 9;

const int MOD = 1e9 + 7;

const int INF = 1e9 + 7;

const ll LLINF = 1e17 + 7;

const ll P = 53;

const int EPS = 1e-9 - 8;

const int vN = 2e4 + 10;

const int sz = (1 << 22) - 1;

const double PI = acos(-1);



ll a[20];



ll rec(int l, int r, ll x1, ll xr) {

	if (r - l == 1)

		return a[l] * x1 + a[r] * xr;

	ll ans = 1ll << 60;

	for (int i = l + 1; i < r; ++ i) {

		ans = min(ans, rec(l, i, x1, x1 + xr) + rec(i, r, x1 + xr, xr) - (x1 + xr) * a[i]);

	}

	return ans;

}



int main () {

    to_pray();

	

    int n;

    cin >> n;

    

    for (int i = 1; i <= n; ++ i)

    	cin >> a[i];

    

    cout << rec(1, n, 1, 1);

    

    //eprllf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);

    cout << '\n';

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;

long long n,v[19],ct;

long long Min(long long a,long long b){return a<b?a:b;}

long long DP(int l,int r,int s1,int s2)

{

	if(l+1==r)return v[l]*s1+v[r]*s2;

	long long as=2e18;

	for(int i=l+1;i<r;i++)as=Min(as,DP(l,i,s1,s1+s2)+DP(i,r,s1+s2,s2)-v[i]*(s1+s2));

	return as;

}

int main(){scanf("%lld",&n);for(int i=1;i<=n;i++)scanf("%lld",&v[i]);printf("%lld\n",DP(1,n,1,1));}//

// Fastest known solution for this problem:
// Original C++ solution (slower):
//

//  main.cpp

//  chalka

//

//  Created by Бахтияр on 16/11/19.

//  Copyright © 2019 Бахтияр. All rights reserved.

//



#include <iostream>

#include <algorithm>

#include <vector>

#include <cmath>

#include <set>

#include <map>

#include <unordered_map>

#include <iomanip>

#include <stack>

#include <queue>

#include <deque>

using namespace std;

int n,a[20];

 

long long dp(int l,int r,long long xl,long long xr) {

    if(l+1==r) return 0;

    long long ret=1e18;

    for(int i=l+1;i<r;i++) ret=min(ret,dp(l,i,xl,xl+xr)+dp(i,r,xl+xr,xr)+(xl+xr)*a[i]);

    return ret;

}

 

int main() {

    cin>>n;for(int i=1;i<=n;i++) cin>>a[i];

    cout<<dp(1,n,1,1)+a[1]+a[n];

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;

long long n,v[19],ct;

long long Min(long long a,long long b){return a<b?a:b;}

long long DP(int l,int r,int s1,int s2)

{

	if(l+1==r)return v[l]*s1+v[r]*s2;

	long long as=2e18;

	for(int i=l+1;i<r;i++)as=Min(as,DP(l,i,s1,s1+s2)+DP(i,r,s1+s2,s2)-v[i]*(s1+s2));

	return as;

}

int main(){scanf("%lld",&n);for(int i=1;i<=n;i++)scanf("%lld",&v[i]);printf("%lld\n",DP(1,n,1,1));}//

// Fastest known solution for this problem: