malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int oo = (int)2147483647;   const double PI = 2 * acos(0.0);   const long double eps = 1e-11;   int diri[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};   int dirk[] = {1, 0, -1, 0, 1, -1, 1, -1, 0};   int main() {     int n, m;     double k;     cin >> n >> m >> k;     k += eps;     map<string, int> mp;     for (int i = ((int)0); i <= ((int)n - 1); i++) {       string s;       int l;       cin >> s >> l;       if (l * k >= 100) mp[s] = (int)l * k;     }     for (int i = ((int)0); i <= ((int)m - 1); i++) {       string s;       cin >> s;       if (!mp[s]) mp[s] = 0;     }     cout << mp.size() << endl;     for (__typeof(mp).begin() it = (mp).begin(); it != (mp).end(); it++)       cout << it->first <<     << it->second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000500;   typedef struct treap *ptreap;   struct treap {     int v, c, y;     ptreap l, r;     treap() {}     treap(int v) : v(v), c(1), y(rand()), l(0), r(0) {}   };   int cnt(ptreap t) { return t ? t->c : 0; }   void recalc(ptreap t) {     if (t) t->c = cnt(t->l) + cnt(t->r) + 1;   }   void split(ptreap t, int key, ptreap &l, ptreap &r) {     if (!t) {       l = r = 0;       return;     }     int cur_key = cnt(t->l);     if (key < cur_key) {       split(t->l, key, l, t->l);       r = t;     } else {       split(t->r, key - cur_key - 1, t->r, r);       l = t;     }     recalc(t);   }   void merge(ptreap l, ptreap r, ptreap &t) {     if (!l || !r) {       t = l ? l : r;       return;     }     if (l->y < r->y) {       merge(l->r, r, l->r);       t = l;     } else {       merge(l, r->l, r->l);       t = r;     }     recalc(t);   }   void print(ptreap t) {     if (!t) return;     print(t->l);     cout << t->v;     print(t->r);   }   int n, m, val, r, cur, a[maxn];   ptreap t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     srand(time(0));     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> a[i];       --a[i];     }     for (int i = 0; i < n; ++i) {       cin >> val;       if (val == -1) {         for (int j = 0; j < r; ++j) {           ptreap q, w;           split(t, a[j] - j, q, t);           split(q, a[j] - j - 1, w, q);           merge(w, t, t);         }         cur -= r;         while (r > 0 && a[r - 1] > cur - 1) --r;       } else {         ptreap tmp = new treap(val);         merge(t, tmp, t);         ++cur;         if (a[r] == cur - 1) ++r;       }     }     if (!cur)       cout <<  Poor stack! ;     else       print(t);     return 0;   }
////#include <iostream>   ////#include <cstdio>   ////#include <cstring>   ////#include <algorithm>   ////   ////#define LL long long   ////   ////LL gcd(LL a,LL b) {   ////    if(b == 0) return a;   ////    else return gcd(b,a % b);   ////}   ////   ////inline LL calc(LL x) {   ////    LL ret = 0;   ////    while(x) {   ////        ret += x % 10;   ////        x /= 10;   ////    }   ////    return ret;   ////}   ////   ////int main() {   ////    int T; scanf( %d ,&T);   ////    LL n,x;   ////    while(T--) {   ////        scanf( %lld ,&n);   ////        x = 0;   ////        for(LL i=n; i; i++) {   ////            if(gcd(i,calc(i)) >= 2) {   ////                printf( %lld n ,i);   ////                break;   ////            }   ////        }   ////    }   ////    return 0;   ////}   //   //#include <iostream>   //#include <cstring>   //#include <cstdio>   //#include <algorithm>   //#include <map>   //#define Maxn 100005   //using namespace std;   //int a[1005000];   //map<int,int> mp;   //int main(int argc,char* argv[]) {   //    int T; scanf( %d ,&T);   //   //    while(T--) {   //        mp.clear();   //        int k = 524288,tmp = k;   //        while (tmp) {   //            a[tmp] = 0;   //            tmp >>= 1;   //        }   //        int n,w,x,ans = 0;   //        cin >> n >> w;   //        for(int i=0; i<n; i++) cin >> x,a[x]++;   //        while(n) {   //            int tmp = k,sum = w;   //            while(tmp) {   //                if(a[tmp]) {   //                    int cnt = sum / tmp;   //                    cnt = min(cnt,a[tmp]);   //                    sum -= cnt * tmp;   //                    a[tmp] -= cnt;   //                    n -= cnt;   //                }   //                tmp >>= 1;   //            }   //            ans++;   //        }   //        cout << ans << endl;   //    }   //    return 0;   //}      #include <iostream>   #include <cstring>   #include <cstdio>   #define Maxn 1005   using namespace std;   int dp[Maxn][Maxn];   const int Mod = 1e9 + 7;      int solve(int n,int k,int total) {       if(n <= 0 || k <= 1) return 1;       else {           if(dp[n][k] == -1)               dp[n][k] = ((solve(n - 1,k,total) % Mod + solve(total - n,k - 1,total) % Mod)) % Mod;           return (dp[n][k] % Mod);       }   }      int main(int argc,char* argv[]) {       int T,n,k; scanf( %d ,&T);       while(T--) {           scanf( %d %d ,&n,&k);           memset(dp,-1,sizeof(dp));           cout << solve(n,k,n) << endl;       }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int n;     int fn[200005] = {};     int a, b, c;     vector<string> st(t);     for (int j = 0; j < t; j++) {       cin >> n;       int rn[n];       for (int i = 0; i < n; i++) {         cin >> rn[i];         fn[rn[i]] = i + 1;       }       string s =  1 ;       a = min(fn[1], fn[2]);       b = max(fn[1], fn[2]);       for (int i = 2; i <= n; i++) {         c = fn[i];         if (a >= c)           a = c;         else if (b <= c)           b = c;         if (b - a == i - 1)           s.insert(i - 1,  1 );         else           s.insert(i - 1,  0 );       }       st[j] = s;     }     for (int j = 0; j < t; j++) {       cout << st[j] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n + 1];     for (int i = 0; i < n; i++) {       int k;       cin >> k;       arr[k] = i + 1;     }     int m;     long long int vas = 0, pet = 0;     cin >> m;     for (int i = 0; i < m; i++) {       int k;       cin >> k;       vas += arr[k];       pet += n + 1 - arr[k];     }     cout << vas <<     << pet;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, j;     cin >> t;     for (j = 0; j < t; j++) {       long long a, b, c, p = 0, r = 0;       cin >> a >> b >> c;       if (a >= c)         p = -1;       else         p = 1;       if ((c / b) >= a)         r = -1;       else         r = b;       cout << p <<     << r << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   long long f[N][2];   long long a[N];   long long n, r1, r2, r3, d;   int main() {     cin >> n >> r1 >> r2 >> r3 >> d;     for (int i = 1; i <= n; i++) cin >> a[i];     memset(f, 0x3f, sizeof f);     f[1][0] = r1 * a[1] + r3;     f[1][1] = min(r1 * (a[1] + 1), r2);     for (int i = 1; i < n; i++) {       long long t0 = r1 * a[i + 1] + r3;       long long t11 = r2;       long long t12 = r1 * (a[i + 1] + 1);       f[i + 1][1] = min(f[i + 1][1], f[i][0] + d + min(t11, t12));       f[i + 1][1] = min(f[i + 1][1], f[i][1] + d + min(t11, t12) + d + r1 + d);       f[i + 1][0] = min(f[i + 1][0], f[i][0] + d + t0);       f[i + 1][0] =           min(f[i + 1][0], f[i][1] + d + min(t11, t12) + 2 * d + 2 * r1);       f[i + 1][0] = min(f[i + 1][0], f[i][1] + t0 + r1 + 3 * d);     }     cout << min(f[n][0], f[n - 1][1] + d + r1 * a[n] + r3 + d + r1) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   multiset<int> gr[maxn];   vector<int> order, odd;   int n, m;   void go(int cur) {     for (auto it = gr[cur].begin(); gr[cur].size() != 0; it = gr[cur].begin()) {       int v = *it;       gr[cur].erase(it);       gr[v].erase(gr[v].find(cur));       go(v);     }     order.push_back(cur);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       gr[a].insert(b);       gr[b].insert(a);     }     for (int i = 0; i < n; i++)       if (gr[i].size() % 2 != 0) odd.push_back(i);     for (int i = 0; i < (int)odd.size() / 2; i++) {       gr[odd[2 * i]].insert(odd[2 * i + 1]);       gr[odd[2 * i + 1]].insert(odd[2 * i]);     }     if ((odd.size() / 2 + m) % 2 == 1) {       gr[0].insert(0);       gr[0].insert(0);     }     go(0);     printf( %d n , order.size() - 1);     for (int i = 0; i < (int)order.size() - 1; i++) {       if (i % 2 == 0)         printf( %d %d n , order[i] + 1, order[i + 1] + 1);       else         printf( %d %d n , order[i + 1] + 1, order[i] + 1);     }     return 0;   }
#include <iostream>   #include <iomanip>   #include <cstdio>   #include <vector>   #include <algorithm>   #include <cmath>   #include <cstring>   #include <cassert>   #include <string>   #include <set>   #include <map>   #include <random>   #include <bitset>   #include <string>   #include <unordered_set>   #include <unordered_map>   #include <deque>   #include <queue>   #define rep(i, n) for (int i = 0; i < (n); i++)   #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()      using namespace std;   using ll = long long;   using ul = unsigned long long;   using ld = long double;      const int MOD = 998244353, N = 100002;   ll f[N], rf[N];      ll pw(ll x, ll k) {     ll r = 1;     while (k) {       if (k & 1)         r = r * x % MOD;       x = x * x % MOD;       k >>= 1;     }     return r;   }      ll c(ll n, ll k) {     return f[n] * rf[k] % MOD * rf[n - k] % MOD;   }      int main() {     ios_base::sync_with_stdio(0); cin.tie(0);     f[0] = 1;     for (int i = 1; i < N; ++i)       f[i] = f[i - 1] * i % MOD;     rf[N - 1] = pw(f[N - 1], MOD - 2);     for (int i = N - 1; i > 0; --i)       rf[i - 1] = rf[i] * i % MOD;     int t, n;     cin >> t;     while (t--) {       string s;       cin >> n >> s;       int l = 1, z = 0, g = 0;       rep(i, n)         if (s[i] ==  0 ) {           z++;           if (l == i % 2)             g++;           l = i % 2;         }       cout << c((n - z - g) / 2 + z, z) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e6 + 50;   vector<int> v;   int vis[N] = {0}, n;   int flag[N] = {0}, ans = 0;   void dfs(int k) {     if (vis[k]) return;     vis[k] = 1;     if (flag[k]) dfs(k ^ ((1 << n) - 1));     for (int i = 0; i < n; i++)       if ((1 << i) & k) dfs(k ^ (1 << i));   }   int main() {     int m;     scanf( %d %d , &n, &m);     int temp;     for (int i = 1; i <= m; i++) {       scanf( %d , &temp);       v.push_back(temp);       flag[temp] = 1;     }     for (auto vv : v) {       if (!vis[vv]) {         ans++;         vis[vv] = 1;         dfs(vv ^ ((1 << n) - 1));       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int cnt[10];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int sum = 0;       memset(cnt, 0, sizeof(cnt));       for (int i = 0; i < n; i++) {         int j;         scanf( %d , &j);         cnt[j]++;         sum += j;       }       int ans = -1;       for (int i = 0; i <= n; i++)         if (4 * i <= sum && (sum - 4 * i) % 3 == 0 &&             (sum - 4 * i) / 3 <= n - i) {           int j = (sum - 4 * i) / 3;           int cost = min(max(cnt[4] - i, 0), j);           int p = cnt[1] + cnt[2] + cnt[3] + cnt[4];           for (int k = 1; k <= 4 && p > i + j; k++) {             cost += min(p - i - j, cnt[k]) * k;             p -= min(p - i - j, cnt[k]);           }           if (cost < ans || ans == -1) ans = cost;         }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   struct node {     int v, nxt;   } edge[maxn << 1];   int first[maxn], tot = 0;   void add(int u, int v) {     edge[++tot].v = v;     edge[tot].nxt = first[u];     first[u] = tot;   }   int n, m;   double dp[maxn], p[maxn], ans = 0;   int f[maxn];   void dfs(int u, int fa) {     ans += (1.0 - p[u]) * p[fa];     for (int i = first[u]; i; i = edge[i].nxt) {       int v = edge[i].v;       if (v == fa) continue;       dfs(v, u);       f[v] = u;       dp[u] += 1.0 - p[v];     }   }   int main() {     scanf( %d , &n);     p[0] = 1.0;     for (int i = 1; i <= n; i++) scanf( %lf , &p[i]);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       x++, y++;       add(x, y);       add(y, x);     }     dfs(1, 0);     scanf( %d , &m);     while (m--) {       int u;       double pp;       scanf( %d%lf , &u, &pp);       u++;       ans -= dp[u] * p[u] + (1.0 - p[u]) * p[f[u]];       dp[f[u]] -= 1.0 - p[u];       p[u] = pp;       ans += dp[u] * p[u] + (1.0 - p[u]) * p[f[u]];       dp[f[u]] += 1.0 - p[u];       printf( %.5f n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Ask(int x1, int y1, int x2, int y2, bool rot = false) {     if (!rot) {       cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 << endl;     } else {       cout <<  ?   << y1 <<     << x1 <<     << y2 <<     << x2 << endl;     }   }   int Find(int n, bool rot) {     int l = 1, r = n;     while (l < r) {       int m = (l + r) >> 1;       Ask(1, 1, m, n, rot);       int res;       cin >> res;       if (res == 0) {         l = m + 1;       } else {         r = m;       }     }     Ask(1, 1, l, n, rot);     int res;     cin >> res;     if (res != 1) {       return -1;     }     int v = l;     ++l;     r = n;     while (l < r) {       int m = (l + r) >> 1;       Ask(l, 1, m, n, rot);       int res;       cin >> res;       if (res == 0) {         l = m + 1;       } else {         r = m;       }     }     Ask(v + 1, 1, l, n, rot);     cin >> res;     if (res != 1) {       return -1;     }     return v;   }   int FindR(int x1, int y1, int x2, int y2, bool rot) {     int l = x1, r = x2;     while (l < r) {       int m = (l + r) >> 1;       Ask(x1, y1, m, y2, rot);       int res;       cin >> res;       if (res == 0) {         l = m + 1;       } else {         r = m;       }     }     return l;   }   int FindL(int x1, int y1, int x2, int y2, bool rot) {     int l = x1, r = x2;     while (l < r) {       int m = (l + r + 1) >> 1;       Ask(m, y1, x2, y2, rot);       int res;       cin >> res;       if (res == 0) {         r = m - 1;       } else {         l = m;       }     }     return l;   }   int FindD(int x1, int y1, int x2, int y2, bool rot) {     int l = y1, r = y2;     while (l < r) {       int m = (l + r) >> 1;       Ask(x1, y1, x2, m, rot);       int res;       cin >> res;       if (res == 0) {         l = m + 1;       } else {         r = m;       }     }     return l;   }   int FindU(int x1, int y1, int x2, int y2, bool rot) {     int l = y1, r = y2;     while (l < r) {       int m = (l + r + 1) >> 1;       Ask(x1, m, x2, y2, rot);       int res;       cin >> res;       if (res == 0) {         r = m - 1;       } else {         l = m;       }     }     return l;   }   int main() {     std::ios_base::sync_with_stdio(false);     int n;     cin >> n;     bool rot = false;     int line = Find(n, rot);     if (line == -1) {       rot = true;       line = Find(n, rot);     }     int x11 = FindL(1, 1, line, n, rot);     int x12 = FindR(1, 1, line, n, rot);     int y11 = FindU(1, 1, line, n, rot);     int y12 = FindD(1, 1, line, n, rot);     int x21 = FindL(line + 1, 1, n, n, rot);     int x22 = FindR(line + 1, 1, n, n, rot);     int y21 = FindU(line + 1, 1, n, n, rot);     int y22 = FindD(line + 1, 1, n, n, rot);     if (rot) {       swap(x11, y11);       swap(x12, y12);       swap(x21, y21);       swap(x22, y22);     }     cout <<  !   << x11 <<     << y11 <<     << x12 <<     << y12;     cout <<     << x21 <<     << y21 <<     << x22 <<     << y22 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solution() {     int n, k, i, j, sum = 0;     cin >> n >> k;     string s;     cin >> s;     if (k == 2) {       int c1 = 0, c2 = 0;       for (i = 0; i < n; i++) {         c1 += abs(s[i] - 65 - (i % 2));         c2 += abs(s[i] - 65 - (i + 1) % 2);       }       if (c1 < c2) {         cout << c1 <<   n ;         for (i = 0; i < n; i++) cout << (char)(65 + i % 2);       } else {         cout << c2 <<   n ;         for (i = 0; i < n; i++) cout << (char)(65 + (i + 1) % 2);       }       return;     }     for (i = 0; i < n - 1; i++) {       char c =  A ;       if (s[i] == s[i + 1]) {         sum++;         while (s[i + 2] == c || s[i] == c) {           c = (char)(c + 1);         }         s[i + 1] = c;       }     }     cout << sum <<   n  << s;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solution();     }     cerr <<   n  << (float)clock() / CLOCKS_PER_SEC * 1000 <<   ms  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1100;   const long long M = 260;   const long long mod = 998244353;   const long long MOD = 998244353;   const long double eps = 0.000000001;   const long long P = 1336;   const long long inf = 1e16;   mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());   long long n, k;   vector<pair<long long, long long> > a;   long long dp[N][N];   long long solve(long long x) {     for (long long j = 0; j < k; j++) {       for (long long i = 0; i < n; i++) {         dp[j][i] = 0;         if (j == 0) dp[j][i] = 1;       }     }     long long ans = 0;     for (long long j = 1; j < k; j++) {       long long uk = 0, s = 0;       for (long long i = 0; i < n; i++) {         while (uk < n && a[uk].first + x <= a[i].first) {           s += dp[j - 1][uk];           s %= mod;           uk++;         }         dp[j][i] = s;         if (j == k - 1) {           ans += dp[j][i];           ans %= mod;         }       }     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     srand(time(0));     cin >> n >> k;     a.resize(n);     long long ma = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       ma = max(ma, a[i].first);       a[i].second = i;     }     sort(a.begin(), a.end());     long long ans = 0, s = 0;     for (long long i = ma / (k - 1); i >= 1; i--) {       long long c = solve(i);       c -= s;       c += mod;       c %= mod;       s += c;       s %= mod;       c *= i;       c %= mod;       ans += c;       ans %= mod;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using uint = unsigned int;   using ull = unsigned long long;   template <typename T>   using pair2 = pair<T, T>;   using pii = pair<int, int>;   using pli = pair<ll, int>;   using pll = pair<ll, ll>;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   inline void fmin(ll &x, ll y) {     if (y < x) x = y;   }   inline void fmax(ll &x, ll y) {     if (y > x) x = y;   }   double startTime;   double getCurrentTime() {     return ((double)clock() - startTime) / CLOCKS_PER_SEC;   }   const ll INF = 0x3f3f3f3f3f3f3f3f;   const int N = 100100;   const int M = (1 << 7) + 7;   vector<int> a[N];   int n, k, p;   int ppc[M];   ll dp[2][M];   int main() {     for (int i = 0; i < M; i++) ppc[i] = ppc[i / 2] + (i & 1);     scanf( %d%d%d , &n, &p, &k);     for (int i = 0; i < n; i++) {       a[i].resize(p + 1);       scanf( %d , &a[i][0]);     }     for (int i = 0; i < n; i++)       for (int j = 1; j <= p; j++) scanf( %d , &a[i][j]);     sort(a, a + n);     reverse(a, a + n);     for (int mask = 0; mask < 1 << p; mask++) dp[0][mask] = -INF;     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int mask = 0; mask < 1 << p; ++mask) dp[1][mask] = -INF;       for (int mask = 0; mask < (1 << p); ++mask) {         for (int j = 0; j < p; j++) {           if (mask & (1 << j)) continue;           fmax(dp[1][mask | (1 << j)], dp[0][mask] + a[i][j + 1]);         }         ll w = dp[0][mask];         if (ppc[mask] + k > i) w += a[i][0];         fmax(dp[1][mask], w);       }       for (int mask = 0; mask < (1 << p); ++mask) dp[0][mask] = dp[1][mask];     }     printf( %lld n , dp[0][(1 << p) - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[200005];   int sz[200005];   int n, k;   long long int ans;   void dfs(int u, int p) {     for (int v : adj[u]) {       if (v == p) continue;       dfs(v, u);       sz[u] += sz[v];       ans += min(sz[v], 2 * k - sz[v]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < 2 * k; i++) {       int x;       cin >> x;       sz[x] = 1;     }     int u, v;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int spf[5000002];   int f[5000002];   void init() {     spf[0] = spf[1] = 1;     for (int i = 2; i < 5000002; ++i) {       if (spf[i] == 0) {         spf[i] = i;         long long int start = 1LL * i * i;         for (long long int j = start; j < 5000002; j += i) {           if (spf[j] == 0) spf[j] = i;         }       }     }     f[0] = f[1] = 0;     for (int i = 2; i < 5000002; ++i) {       int x = spf[i];       int y = i / x;       long long int val = 1LL * y * x * (x - 1) / 2 + f[y];       f[i] = val % 1000000007;     }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     init();     int t, l, r;     cin >> t >> l >> r;     long long int ans = 0, mul = 1;     for (int i = 0; i <= r - l; ++i) {       ans = ans + (mul * f[i + l]) % 1000000007;       mul = (mul * t) % 1000000007;     }     cout << ans % 1000000007 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   long long mas[1000100];   long long dmas[1000100];   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     long long x;     long long ans = -100000000000000000;     int ansl, ansr;     for (int i = 0; i < n; ++i) {       cin >> x;       dmas[i] = x;       if (x >= 0) mas[i] = x;       if (i > 0) mas[i] += mas[i - 1];       if (mp.count(x) == 0)         mp[x] = i;       else {         long long d = 0;         if (x < 0) d = x * 2;         ans = max(ans, mas[i] - mas[mp[x] - 1] + d);         if (ans == mas[i] - mas[mp[x] - 1] + d) {           ansl = mp[x];           ansr = i;         }       }     }     cout << ans <<    ;     int c = 0;     for (int i = 0; i < n; ++i) {       if (i < ansl)         ++c;       else if (i > ansr)         ++c;       else if (i < ansr && i > ansl && dmas[i] < 0)         ++c;     }     cout << c <<   n ;     for (int i = 0; i < n; ++i) {       if (i < ansl)         cout << i + 1 <<    ;       else if (i > ansr)         cout << i + 1 <<    ;       else if (i < ansr && i > ansl && dmas[i] < 0)         cout << i + 1 <<    ;     }     return 0;   }