malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void wri(long long a) {     write(a);     putchar(   );   }   inline void writeln(long long a) {     write(a);     puts(  );   }   const int N = 1 << 17 | 2, mod = 998244353;   int sum, A[N], B[N], C[N], f[N];   long long ksm(long long a, int b) {     a %= mod;     int ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;     }     return ans;   }   void FWT(int *a, int n) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < (1 << n); j++)         if (j >> i & 1) {           int x = a[j];           a[j] = a[j ^ (1 << i)] >= x ? a[j ^ (1 << i)] - x                                       : a[j ^ (1 << i)] - x + mod;           a[j ^ (1 << i)] = a[j ^ (1 << i)] + x >= mod ? a[j ^ (1 << i)] + x - mod                                                        : a[j ^ (1 << i)] + x;         }     }   }   void ba(int &a) {     if (a > mod / 2) a = a - mod;   }   signed main() {     int n = read(), k = read();     int x = read(), y = read(), z = read();     for (int i = 0; i < n; i++) {       int a = read(), b = read() ^ a, c = read() ^ a;       sum ^= a;       A[b]++;       B[c]++;       C[b ^ c]++;     }     FWT(A, k);     FWT(B, k);     FWT(C, k);     for (int i = 0; i < (1 << k); i++) {       int t1 = n, t2 = A[i], t3 = B[i], t4 = C[i];       ba(t2);       ba(t3);       ba(t4);       f[i] = ksm((long long)x + y + z, (t1 + t2 + t3 + t4) / 4) *              ksm((long long)x + y - z, (t1 + t2 - t3 - t4) / 4) % mod *              ksm((long long)x - y + z, (t1 - t2 + t3 - t4) / 4) % mod *              ksm((long long)x - y - z, (t1 - t2 - t3 + t4) / 4) % mod;       f[i] = (f[i] + mod) % mod;     }     FWT(f, k);     long long in = ksm(1 << k, mod - 2);     for (int i = 0; i < (1 << k); i++) f[i] = f[i] * in % mod;     for (int i = 0; i < (1 << k); i++) {       wri(f[i ^ sum]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 28;   vector<int> g[N];   int vis[2000000];   int main() {     int k, n;     string ss, s;     cin >> k >> ss;     for (int i = 0; i < k; ++i) s += ss;     for (int i = 0; i != s.size(); ++i) g[s[i] -  a ].push_back(i);     cin >> n;     vector<int>::iterator it;     for (int i = 0; i < n; ++i) {       cin >> k >> ss;       it = g[ss[0] -  a ].begin();       g[ss[0] -  a ].erase(it + k - 1);     }     memset(vis, 0, sizeof(vis));     for (int i = 0; i < 26; ++i)       for (int j = 0; j < g[i].size(); ++j) vis[g[i][j]] = 1;     for (int i = 0; i != s.size(); ++i)       if (vis[i]) cout << s[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   int n, m;   int adj[N][N], d[N][N];   bool check(int a, int b) {     if (a >= 0 && a < n && b >= 0 && b < m && adj[a][b] != -1) return 1;     return 0;   }   void bfs(int x, int y) {     d[x][y] = 0;     queue<pair<int, int> > q;     q.push({x, y});     while (!q.empty()) {       int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};       pair<int, int> p = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         int ii = dir[i][0] + p.first;         int jj = dir[i][1] + p.second;         if (check(ii, jj) && d[ii][jj] == -1) {           q.push({ii, jj});           d[ii][jj] = d[p.first][p.second] + 1;         }       }     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) d[i][j] = -1;     pair<int, int> e, s;     char c;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> c;         if (c ==  E ) {           e.first = i;           e.second = j;           adj[i][j] = 0;         } else if (c ==  S ) {           s.first = i;           s.second = j;           adj[i][j] = 0;         } else if (c ==  T )           adj[i][j] = -1;         else           adj[i][j] = (c -  0 );       }     }     bfs(e.first, e.second);     int len = d[s.first][s.second];     long long int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (d[i][j] != -1 && d[i][j] <= len) ans += adj[i][j];     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline string GetString() {     char S[1000005];     scanf( %s , S);     string ret = S;     return ret;   }   inline char getc() {     char c =    ;     while (c ==     || c ==   t  || c ==   r  || c ==   n ) c = getchar();     return c;   }   template <typename t>   t getnum() {     t res = 0;     char c;     int sign = 1;     while (1) {       c = getchar();       if (c ==     || c ==   n )         continue;       else         break;     }     if (c ==  + ) {     } else if (c ==  - )       sign = -1;     else       res = c -  0 ;     while (1) {       c = getchar();       if (c >=  0  && c <=  9 )         res = res * 10 + c -  0 ;       else         break;     }     return res * sign;   }   int main(int argc, char** argv) {     int n = getnum<int>();     int m = getnum<int>();     int i = getnum<int>();     int j = getnum<int>();     int a = getnum<int>();     int b = getnum<int>();     int satu = 10000000, dua = 10000000, tiga = 10000000, empat = 10000000;     if ((i - 1) % a == 0 && (j - 1) % b == 0) {       int x = (i - 1) / a, y = (j - 1) / b;       if (x % 2 == y % 2) satu = max(x, y);     }     if ((i - 1) % a == 0 && (m - j) % b == 0) {       int x = (i - 1) / a, y = (m - j) / b;       if (x % 2 == y % 2) dua = max(x, y);     }     if ((n - i) % a == 0 && (j - 1) % b == 0) {       int x = (n - i) / a, y = (j - 1) / b;       if (x % 2 == y % 2) tiga = max(x, y);     }     if ((n - i) % a == 0 && (m - j) % b == 0) {       int x = (n - i) / a, y = (m - j) / b;       if (x % 2 == y % 2) empat = max(x, y);     }     int ans = min(satu, min(dua, min(tiga, empat)));     if (ans != 0 && (a > n - 1 || b > m - 1)) ans = 10000000;     if (ans == 10000000)       puts( Poor Inna and pony! );     else       printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[1003][1003];   int n, m;   int dp[1003][1003];   int vis[1003][1003];   int dx[4] = {0, 1, 0, -1};   int dy[4] = {1, 0, -1, 0};   int dfs(int i, int j, int x) {     if (vis[i][j] == 2) {       printf( Poor Inna! n );       exit(0);     }     if (dp[i][j] != -1) return dp[i][j];     vis[i][j] = 2;     int temp2 = 0;     int temp3 = 0;     if (arr[i][j] == 3) temp3 = 1;     for (int k = 0; k < 4; k++) {       int ee = i + dx[k];       int rr = j + dy[k];       if (ee >= 0 & ee < n && rr >= 0 && rr < m && arr[ee][rr] == (x + 1) % 4) {         temp2 = max(temp2, dfs(ee, rr, (x + 1) % 4));       }     }     temp2 += temp3;     vis[i][j] = 1;     if (arr[i][j] == 0) dp[i][j] = temp2;     return temp2;   }   int main() {     char temp;     for (int i = 0; i < 1003; i++)       for (int j = 0; j < 1003; j++) {         dp[i][j] = -1;         vis[i][j] = 0;       }     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> temp;         if (temp ==  D ) arr[i][j] = 0;         if (temp ==  I ) arr[i][j] = 1;         if (temp ==  M ) arr[i][j] = 2;         if (temp ==  A ) arr[i][j] = 3;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (arr[i][j] == 0 && vis[i][j] == 0) {           int temp1 = dfs(i, j, 0);         }       }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (ans < dp[i][j]) ans = dp[i][j];     if (ans == 0)       printf( Poor Dima! n );     else       printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ex, ey;   bool a[207][207];   bool vis[207][207];   int dx[4] = {0, 0, 1, -1};   int dy[4] = {-1, 1, 0, 0};   int bfs() {     queue<pair<int, int>> q;     vis[100][100] = true;     q.push(make_pair(100, 100));     int dep = 0;     while (int(q.size())) {       int size = int(q.size());       while (size--) {         pair<int, int> top = q.front();         q.pop();         vis[top.first][top.second] = true;         if (top.first == ex && top.second == ey) return dep;         for (int i = 0; i < int(4); i++) {           int nx = top.first + dx[i];           int ny = top.second + dy[i];           if (a[nx][ny] && !vis[nx][ny]) {             q.push(make_pair(nx, ny));           }         }       }       dep++;     }     return -1;   }   int main() {     string second;     cin >> second;     ex = ey = 100;     for (int i = 0; i < int(int(second.size())); i++) {       a[ex][ey] = true;       if (second[i] ==  R ) ex++;       if (second[i] ==  L ) ex--;       if (second[i] ==  U ) ey--;       if (second[i] ==  D ) ey++;       if (a[ex][ey]) {         puts( BUG );         return 0;       }     }     a[ex][ey] = true;     int ans = bfs();     ans < int(second.size()) ? puts( BUG ) : puts( OK );   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 513;   int N, ans[MAXN];   multiset<int> m;   int gcd(int a, int b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   void solve() {     for (int k = N; k >= 1; k--) {       ans[k] = -(*m.begin());       m.erase(m.find(-ans[k]));       for (int i = k + 1; i <= N; i++) {         m.erase(m.find(-gcd(ans[k], ans[i])));         m.erase(m.find(-gcd(ans[k], ans[i])));       }     }   }   int main() {     scanf( %d , &N);     int x;     for (int i = 1; i <= N * N; i++) {       scanf( %d , &x);       m.insert(-x);     }     solve();     for (int i = 1; i <= N; i++) printf( %d%c , ans[i],    n [i == N]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-6;   const long double pi = acos(-1.0);   int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0},       dy[] = {1, 0, -1, 0, 1, -1, 1, -1, 0};   int aq[5][5];   int main() {     int n;     cin >> n;     for (int i = 0; i < (int)(n); ++i) {       int x, y;       cin >> x >> y;       aq[x - 1][y - 1] = aq[y - 1][x - 1] = 1;     }     int ap = 0, nap = 0;     for (int i = 0; i < (int)(5); ++i)       for (int j = 0; j < (int)(i); ++j)         for (int k = 0; k < (int)(j); ++k) {           if (aq[i][j] && aq[j][k] && aq[k][i]) ap = 1;           if (!aq[i][j] && !aq[j][k] && !aq[k][i]) nap = 1;         }     if (ap || nap)       cout <<  WIN  << endl;     else       cout <<  FAIL  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int64_t INF = 0x3f3f3f3f;   const int64_t INFLL = 0x3f3f3f3f3f3f3f3f;   const int64_t MOD = 1e9 + 7;   const double EPS = 1e-9;   const double PI = acos(-1);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int64_t rand(int64_t x, int64_t y) {     return uniform_int_distribution<int64_t>(x, y)(rng);   }   int64_t mul(int64_t a, int64_t b) {     int64_t ret = (1ll * (a % MOD) * (b % MOD)) % MOD;     return (ret + MOD) % MOD;   }   int64_t add(int64_t a, int64_t b) {     int64_t ret = (1ll * (a % MOD) + (b % MOD)) % MOD;     return (ret + MOD) % MOD;   }   int64_t pow_exp(int64_t n, int64_t p) {     if (!p) return 1;     if (p & 1) return mul(n, pow_exp(n, p - 1));     int64_t tmp = pow_exp(n, p / 2);     return mul(tmp, tmp);   }   const int64_t MAX = 2e5 + 10;   const int64_t NMAX = 2e5 + 10;   const int64_t MMAX = 2e5 + 10;   const int64_t LOG_MAX = ceil(log2(double(NMAX)));   const int64_t BLOCK = ceil(sqrt(double(NMAX)));   int64_t n;   string str[20];   map<int64_t, vector<int64_t> > mp[20];   int64_t tot[20];   int64_t mem[1 << 20];   int64_t go(int64_t msk, int64_t sm) {     if (msk + 1 == 1 << n) {       return 0;     }     int64_t &ret = mem[msk];     if (ret + 1) return ret;     int64_t ans = 0;     for (int64_t i = 0; i < n; i++)       if (((msk >> i) & 1) == 0) {         int64_t mn = mp[i].begin()->first;         if (sm + mn >= 0) {           int64_t cans = 0;           cans += go(msk ^ (1 << i), sm + tot[i]);           auto it = mp[i].find(-sm);           if (it != mp[i].end()) cans += it->second.size();           ans = max(ans, cans);         } else {           auto it = mp[i].find(-sm);           if (it == mp[i].end()) {             continue;           }           if (it == mp[i].begin()) {             int64_t cans = it->second.size();             ans = max(ans, cans);           } else {             auto &v = mp[i][-sm];             int64_t r = (--it)->second.front();             int64_t cans = lower_bound(v.begin(), v.end(), r) - v.begin();             ans = max(ans, cans);           }         }       }     return ret = ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int64_t i = 0; i < n; i++) {       cin >> str[i];     }     for (int64_t i = 0; i < n; i++) {       int64_t sm = 0;       for (int64_t j = 0; j < str[i].size(); j++) {         sm += str[i][j] ==  (  ? +1 : -1;         mp[i][sm].push_back(j);       }       tot[i] = sm;     }     memset(mem, -1, sizeof mem);     cout << go(0, 0) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const double inf = 1e10;   int n, m, q, Eu[N], Ev[N], all[N], vis[N];   vector<int> V;   map<pair<int, int>, int> F, S;   struct P {     double x, y;   } p[N];   inline P operator+(const P& a, const P& b) { return (P){a.x + b.x, a.y + b.y}; }   inline P operator-(const P& a, const P& b) { return (P){a.x - b.x, a.y - b.y}; }   inline double operator*(const P& a, const P& b) {     return a.x * b.y - b.x * a.y;   }   inline double operator/(const P& b, const P& a) {     return atan2(b.y - a.y, b.x - a.x);   }   inline bool operator<(const P& a, const P& b) {     return a.x != b.x ? a.x < b.x : a.y < b.y;   }   inline double crs(P p, P a, P b) { return (a - p) * (b - p); }   struct E {     int v;     double a;   };   inline bool operator<(const E& a, const E& b) { return a.a < b.a; }   vector<E> G[N];   inline void add(int u, int v) {     G[u].push_back((E){v, p[v] / p[u]});     F[make_pair(u, v)] = 0;   }   int dfs(int x, int p) {     vis[x] = 1;     int s = 1;     for (int i = 0; i < G[x].size(); i++) {       int y = G[x][i].v;       if (!vis[y]) s += dfs(y, x);     }     if (p) {       F[make_pair(p, x)] += s;       F[make_pair(x, p)] -= s;     }     return s;   }   inline int calc(int a, int b, int c) {     return ((p[b] / p[a]) < (p[c] / p[a]) ? 0 : all[a]) + S[make_pair(a, c)] -            S[make_pair(a, b)] - F[make_pair(a, c)];   }   int main() {     scanf( %d%d , &n, &m);     int T = n + 1;     p[T] = (P){-inf, 0};     for (int i = 1; i <= m; i++) scanf( %d%d , &Eu[i], &Ev[i]);     for (int i = 1; i <= n; i++) scanf( %lf%lf , &p[i].x, &p[i].y);     for (int i = 1; i <= m; i++) add(Eu[i], Ev[i]), add(Ev[i], Eu[i]);     int x = 1;     for (int i = 2; i <= n; i++)       if (p[i] < p[x]) x = i;     add(T, x);     add(x, T);     dfs(T, 0);     for (int i = 1; i <= n + 1; i++) sort(G[i].begin(), G[i].end());     for (int i = 1; i <= n + 1; i++) {       int x = i;       S[make_pair(i, i)] = 0;       for (int j = 0; j < G[i].size(); j++) {         int y = G[i][j].v;         all[i] += F[make_pair(i, y)];         S[make_pair(i, y)] = S[make_pair(i, x)] + F[make_pair(i, y)];         x = y;       }     }     scanf( %d , &q);     while (q--) {       int k;       scanf( %d , &k);       V.clear();       for (int i = 1, x; i <= k; i++) scanf( %d , &x), V.push_back(x);       int ans = 0, cc = V.size();       double s = 0;       p[0] = (P){0, 0};       for (int i = 0; i < cc; i++)         s += crs(p[0], p[V[i ? i - 1 : cc - 1]], p[V[i]]);       if (s > 0) reverse(V.begin(), V.end());       for (int i = 0; i < cc; i++)         ans += calc(V[i], V[i ? i - 1 : cc - 1], V[(i + 1) % cc]);       printf( %d n , ans + cc);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, c, d, flag = 0;     scanf( %d %d %d %d , &a, &b, &c, &d);     if (a + b > c && b + c > a && c + a > b)       flag = 1;     else if (b + c > d && c + d > b && d + b > c)       flag = 1;     else if (c + d > a && d + a > c && a + c > d)       flag = 1;     else if (a + b > d && b + d > a && d + a > b)       flag = 1;     if (flag == 1)       printf( TRIANGLE );     else {       if (a + b == c || b + c == a || c + a == b)         flag = 2;       else if (b + c == d || c + d == b || d + b == c)         flag = 2;       else if (c + d == a || d + a == c || a + c == d)         flag = 2;       else if (a + b == d || b + d == a || d + a == b)         flag = 2;     }     if (flag == 2)       printf( SEGMENT );     else if (flag == 0)       printf( IMPOSSIBLE );   }
#include <bits/stdc++.h>   const int MAXN = 1000;   int ba[MAXN], bb[MAXN];   int a, b, da, db, t, x, l1, l2;   int main() {     scanf( %d %d %d %d %d %d , &x, &t, &a, &b, &da, &db);     int tm = 0;     while (a >= 0) {       ba[l1++] = a;       a -= da;       tm++;       if (tm >= t) break;     }     tm = 0;     while (b >= 0) {       bb[l2++] = b;       b -= db;       tm++;       if (tm >= t) break;     }     for (int i = 0; i < l1; i++)       if (ba[i] == x) {         printf( YES n );         return 0;       }     if (x == 0) {       printf( YES n );       return 0;     }     for (int i = 0; i < l2; i++)       if (bb[i] == x) {         printf( YES n );         return 0;       }     for (int i = 0; i < l1; i++)       for (int j = 0; j < l2; j++)         if (ba[i] + bb[j] == x) {           printf( YES n );           return 0;         }     printf( NO n );     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Item {     int id, t, d, p;     Item(int _id = 0, int _t = 0, int _d = 0, int _p = 0)         : id(_id), t(_t), d(_d), p(_p) {}     bool operator<(const Item &rhs) const { return d < rhs.d; }   };   constexpr int kN = 101, kT = 2001;   Item a[kN];   int dp[kN][kT];   int tk[kN][kT];   int main() {     int n;     scanf( %d , &n);     int t, d, p;     for (int i = 0; i < n; ++i) {       scanf( %d %d %d , &t, &d, &p);       a[i] = Item(i + 1, t, d, p);     }     sort(a, a + n);     for (int i = 0; i < n; ++i) {       for (int j = 0; j + a[i].t < a[i].d; ++j) {         if (dp[i][j] + a[i].p > dp[i + 1][j + a[i].t]) {           dp[i + 1][j + a[i].t] = dp[i][j] + a[i].p;           tk[i + 1][j + a[i].t] = 1;         }       }       for (int j = 0; j < kT; ++j) {         if (dp[i][j] > dp[i + 1][j]) {           dp[i + 1][j] = dp[i][j];           tk[i + 1][j] = 0;         }       }     }     int x = 0;     for (int i = 0; i < a[n - 1].d; ++i) {       if (dp[n][i] > dp[n][x]) {         x = i;       }     }     printf( %d n , dp[n][x]);     vector<int> ans;     for (int i = n; i > 0; --i) {       if (tk[i][x]) {         ans.push_back(a[i - 1].id);         x -= a[i - 1].t;       }     }     reverse(ans.begin(), ans.end());     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); ++i) {       printf( %d  , ans[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     set<int> s;     while (1) {       int k = s.size();       s.insert(n);       int m = s.size();       if (k == m) break;       n = n + 1;       while (n % 10 == 0) {         n = n / 10;       }     }     cout << s.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     return a.first > b.first;   }   long long findBest(vector<pair<long long, long long> >& ps, long long x) {     long long res = 0;     for (long long i = 0; i < ps.size(); i++) {       long long num = ps[i].second;       long long diff = ps[i].first;       if (x - num >= 0) {         res += (num * diff);         x -= num;       } else {         res += (x * diff);         break;       }     }     return res;   }   int main() {     long long n, s;     cin >> n >> s;     vector<pair<long long, long long> > ps;     long long total = 0;     long long positives = 0;     long long pieces = 0;     for (long long i = 0; i < n; i++) {       long long num, a, b;       cin >> num >> a >> b;       ps.push_back(make_pair(a - b, num));       total += num * b;       pieces += num;       if (a - b > 0) {         positives += num;       }     }     sort(ps.begin(), ps.end(), comp);     long long pizzas = (pieces % s == 0) ? (pieces / s) : (pieces / s + 1);     long long extra = pizzas * s - pieces;     long long best = total;     if (positives > 0) {       best = max(best, findBest(ps, positives / s * s) + total);       if (positives % s != 0) {         long long x = max(positives, (positives / s + 1) * s - extra);         best = max(best, findBest(ps, x) + total);       }     }     cout << best << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int i;     int num;   } a[1005];   bool cmp(node x, node y) { return x.num < y.num; }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, m;       scanf( %d %d , &n, &m);       int i, j;       int ans = 0;       for (i = 1; i <= n; i++) {         scanf( %d , &a[i].num);         a[i].i = i;         ans += a[i].num;       }       if (m < n || n <= 2) {         printf( -1 n );         continue;       }       ans *= 2;       sort(a + 1, a + 1 + n, cmp);       int num = a[1].num + a[2].num;       ans += (m - n) * num;       printf( %d n , ans);       for (i = 2; i <= n; i++) {         printf( %d %d n , i - 1, i);       }       printf( 1 %d n , n);       for (i = 0; i < (m - n); i++) {         if (a[1].i > a[2].i)           printf( %d %d n , a[2].i, a[1].i);         else           printf( %d %d n , a[1].i, a[2].i);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 7, MAX_SUM = 10 * 1000 + 7,             DELTA = 1000 * 1000 * 1000 + 7;   long long inputArray[MAXN], numberOfSubarrays[MAXN][2 * MAX_SUM], PSum;   int main() {     int numberOfInput;     cin >> numberOfInput;     for (int i = 0; i < numberOfInput; ++i) {       cin >> inputArray[i];       PSum += inputArray[i];     }     numberOfSubarrays[0][MAX_SUM + inputArray[0]] =         numberOfSubarrays[0][MAX_SUM - inputArray[0]] = 1;     for (int i = 1; i < numberOfInput; ++i) {       for (int j = 0; j < 2 * MAX_SUM; ++j) {         numberOfSubarrays[i][j] += numberOfSubarrays[i - 1][j - inputArray[i]];       }       for (int j = 2 * MAX_SUM - 1; j >= 0; --j) {         numberOfSubarrays[i][j] += numberOfSubarrays[i - 1][j + inputArray[i]];         numberOfSubarrays[i][j] %= DELTA;       }       numberOfSubarrays[i][MAX_SUM + inputArray[i]] =           numberOfSubarrays[i][MAX_SUM + inputArray[i]] + 1;       numberOfSubarrays[i][MAX_SUM - inputArray[i]] =           numberOfSubarrays[i][MAX_SUM - inputArray[i]] + 1;     }     long long ans = 0;     for (int i = 0; i < numberOfInput; ++i) {       ans += numberOfSubarrays[i][MAX_SUM];       ans %= DELTA;     }     cout << ans << endl;     return 0;   }