func_code_string: #include <bits/stdc++.h>   using namespace std;   int dp[1003][1003], a[1003];   pair<pair<int, int>, int> from[1003][1003];   vector<pair<int, int> > sol;   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; i++) cin >> a[i];     if (N % 2 == 0) {       N++;       a[N] = 0;     }     memset(dp, 0x3f3f3f3f, sizeof(dp));     dp[1][1] = 0;     for (int i = 3; i <= N; i += 2) {       for (int j = 1; j <= i - 2; j++) {         if (dp[i - 2][j] + max(a[j], a[i - 1]) < dp[i][i]) {           dp[i][i] = dp[i - 2][j] + max(a[j], a[i - 1]);           from[i][i] = make_pair(make_pair(j, i - 1), j);         }         if (dp[i - 2][j] + max(a[j], a[i]) < dp[i][i - 1]) {           dp[i][i - 1] = dp[i - 2][j] + max(a[j], a[i]);           from[i][i - 1] = make_pair(make_pair(j, i), j);         }         if (dp[i - 2][j] + max(a[i], a[i - 1]) < dp[i][j])           ;         {           dp[i][j] = dp[i - 2][j] + max(a[i], a[i - 1]);           from[i][j] = make_pair(make_pair(i, i - 1), j);         }       }     }     int best = 0x3f3f3f3f, missing;     for (int i = 1; i <= N; i++)       if (dp[N][i] + a[i] < best) {         best = dp[N][i] + a[i];         missing = i;       }     printf( %d n , best);     if (a[missing]) sol.push_back(make_pair(missing, 0));     int start = N;     while (start != 1) {       int x2 = from[start][missing].first.first;       int x3 = from[start][missing].first.second;       sol.push_back(make_pair(x2, x3));       missing = from[start][missing].second;       start -= 2;     }     for (int i = sol.size() - 1; i >= 0; i--) {       if (sol[i].second)         printf( %d %d n , sol[i].first, sol[i].second);       else         printf( %d n , sol[i].first);     }   }   