func_code_string: #include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout <<  [  << *it <<  :   << a <<  ] t ;     err(++it, args...);   }   const long long nax = 1e3 + 5;   long long n;   long long a[nax], dp[nax][nax];   long long fw(long long i, long long j) {     if (i == n) return 0;     if (j == n) return a[i];     if (j == n - 1) return max(a[i], a[j]);     if (dp[i][j] != -1) return dp[i][j];     long long& first = dp[i][j];     first = (long long)(1e18);     first = min(first, fw(j + 1, j + 2) + max(a[i], a[j]));     first = min(first, fw(i, j + 2) + max(a[j], a[j + 1]));     first = min(first, fw(j, j + 2) + max(a[i], a[j + 1]));     return first;   }   void bw(long long i, long long j) {     if (i == n) return;     if (j == n) {       cout << i + 1;       return;     }     if (j == n - 1) {       cout << i + 1 <<     << j + 1 <<   n ;       return;     }     long long first = dp[i][j];     if (first == max(a[i], a[j]) + fw(j + 1, j + 2)) {       cout << i + 1 <<     << j + 1 <<   n ;       bw(j + 1, j + 2);       return;     }     if (first == max(a[j], a[j + 1]) + fw(i, j + 2)) {       cout << j + 1 <<     << j + 2 <<   n ;       bw(i, j + 2);       return;     }     if (first == max(a[i], a[j + 1]) + fw(j, j + 2)) {       cout << i + 1 <<     << j + 2 <<   n ;       bw(j, j + 2);       return;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     memset(dp, -1, sizeof(dp));     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     cout << fw(0, 1) <<   n ;     bw(0, 1);     return 0;   }   