malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, a[102], b[102];   pair<int, int> dp[102][2 * 10002];   bool vis[102][2 * 10002];   pair<int, int> solve(int i, int diff) {     if (i == n + 1)       return diff >= 10000 ? pair<int, int>(0, 0) : pair<int, int>(1e9, 1e9);     if (vis[i][diff]) return dp[i][diff];     vis[i][diff] = true;     pair<int, int> take = solve(i + 1, diff - a[i]);     take.second += a[i];     pair<int, int> leave = solve(i + 1, diff + b[i] - a[i]);     ++leave.first;     return dp[i][diff] = min(take, leave);   }   int main() {     cin >> n;     for (int i = (1); i <= (int)(n); ++i) scanf( %d , &a[i]);     for (int i = (1); i <= (int)(n); ++i) scanf( %d , &b[i]);     pair<int, int> ans = solve(1, 10000);     cout << ans.first <<     << ans.second;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long count[] = {0, 0, 0, 0};     long n;     cin >> n;     while (n--) {       long x;       cin >> x;       count[x] += 1;     }     cout << min(min(count[1] + count[2], count[1] + count[3]),                 count[2] + count[3]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, t[200100], ll, rr, sum;   double inv, res, f[200100], g[200100];   inline double calc(long long l, long long r) {     while (ll > l) {       --ll;       inv += 1.0 / t[ll];       sum += t[ll];       res += inv * t[ll];     }     while (rr < r) {       ++rr;       inv += 1.0 / t[rr];       sum += t[rr];       res += 1.0 * sum / t[rr];     }     while (ll < l) {       res -= inv * t[ll];       sum -= t[ll];       inv -= 1.0 / t[ll];       ll++;     }     while (rr > r) {       res -= 1.0 * sum / t[rr];       sum -= t[rr];       inv -= 1.0 / t[rr];       rr--;     }     return res;   }   inline void func(long long l, long long r, long long L, long long R) {     if (l > r || L > R) return;     register long long mid = (l + r) >> 1;     register long long mp;     register double mn = 9e18;     for (register long long i = L; i <= R; i++)       if (f[i] + calc(i + 1, mid) < mn) mn = f[i] + calc(i + 1, mid), mp = i;     g[mid] = mn;     func(l, mid - 1, L, mp), func(mid + 1, r, mp, R);   }   inline void read(long long &x) {     x = 0;     register char c = getchar();     while (c >  9  || c <  0 ) c = getchar();     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();   }   signed main() {     read(n), read(m);     for (register long long i = 1; i <= n; i++)       read(t[i]), inv += 1.0 / t[i], sum += t[i], res += 1.0 * sum / t[i],           f[i] = res;     ll = 1, rr = n;     while (--m) func(1, n, 0, n - 1), memcpy(f, g, sizeof(g));     printf( %lf n , f[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y, z;   pair<int, int> a[200005];   map<int, int> m, o;   map<pair<int, int>, int> p;   long long q;   int main() {     scanf( %d , &n);     ;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].first);       ;       scanf( %d , &a[i].second);       ;       m[a[i].first]++;       o[a[i].second]++;       p[make_pair(a[i].first, a[i].second)]++;     }     for (int i = 1; i <= n; i++) {       q += m[a[i].first] + o[a[i].second] - 1 -            p[make_pair(a[i].first, a[i].second)];     }     cout << q / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   const long long max9 = 10 + 1e9, max6 = 10 + 1e6, max12 = 10 + 1e12,                   max15 = 10 + 1e15;   const long long min6 = -1 * max6, min9 = -1 * max9, min12 = -1 * max12,                   min15 = -1 * max15;   const long long R = 7 + 1e9, NN = 10 + 1e5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     bool a[n * k + 1];     memset(a, false, sizeof(a));     int t[k];     for (int i = (0); i < (k); ++i) cin >> t[i];     for (int i = (0); i < (k); ++i) {       a[t[i] - 1] = true;     }     for (int i = (0); i < (k); ++i) {       cout << t[i] <<    ;       int o = 1;       for (int j = (0); j < (n * k + 1); ++j) {         if (!a[j]) {           cout << j + 1 <<    ;           o++;           a[j] = true;         }         if (o == n) {           cout << endl;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = int(1e6);   bool dcmp(double a, double b) { return fabs(a - b) < 1e-8; }   int Dcmp(long double a, long double b) {     return fabs(a - b) <= 1e-8 ? 0 : a < b ? -1 : 1;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void INPUT() {     cout << fixed << setprecision(13);     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);   }   int main() {     INPUT();     int n, m;     cin >> n >> m;     long long ans = 0;     string answers[n];     int grades[m];     for (int i = 0; i < (int)(n); ++i) cin >> answers[i];     for (int i = 0; i < (int)(m); ++i) cin >> grades[i];     int Most[30];     for (int i = 0; i < m; i++) {       memset(Most, 0, sizeof(Most));       for (int j = 0; j < n; ++j) {         char let = answers[j][i];         Most[let - 65]++;       }       int mx = 0;       for (int k = 0; k < 30; k++) {         mx = max(mx, Most[k]);       }       ans += grades[i] * mx;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f(long long x) { return x * (x - 1) / 2; }   vector<int> g[303];   int m1[303][303];   int m2[303][303];   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<int> a(k);     vector<int> c(n + 1, 0);     for (int i = 0; i < k; i++) {       cin >> a[i];       c[a[i]] = 1;     }     vector<pair<int, int>> r;     if (k == n) {       cout << -1;       return 0;     }     int V, X;     for (int x = 1; x <= n; x++) {       if (!c[x])         V = x;       else         X = x;     }     m--;     r.push_back({X, V});     for (int x = 1; x <= n; x++) {       if (x == V || x == X) continue;       if (m > 0) {         r.push_back({x, V});         m--;       }     }     for (int x = 1; x <= n; x++) {       if (x == V || x == X) continue;       for (int y = x + 1; y <= n; y++) {         if (y == V || y == X) continue;         if (m > 0) {           m--;           r.push_back({x, y});         }       }     }     for (int x = 1; x <= n; x++) {       if (X == x || V == x || c[x]) continue;       if (m > 0) {         m--;         r.push_back({X, x});         ;       }     }     if (m) {       cout << -1;       return 0;     }     for (int i = 0; i < r.size(); i++) {       cout << r[i].first <<     << r[i].second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long> v;     long n, i, j, k;     cin >> n;     for (i = 0; i < n; i++) {       long long a;       cin >> a;       v.push_back(a);     }     if (v[0] != v[n - 1]) {       cout << n - 1;     } else {       i = n - 1;       while (v[i] == v[0]) {         i--;       }       j = 1;       while (v[j] == v[0]) {         j++;       }       long t = max(i, n - 1 - i);       long p = max(j, n - 1 - j);       cout << max(t, p);     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[100001];   long long vis[100001];   long long level[100001];   long long nodes[100001];   void bfs(long long s) {     queue<long long> q;     q.push(s);     vis[s] = 1;     while (!q.empty()) {       long long f = q.front();       q.pop();       for (auto it = adj[f].begin(); it != adj[f].end(); ++it) {         if (vis[*it] == 0) {           q.push(*it);           level[*it] = level[f] + 1;           nodes[level[*it]]++;           vis[*it] = 1;         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     for (long long i = 2; i <= n; i++) {       long long tmp;       cin >> tmp;       adj[tmp].push_back(i);     }     nodes[0] = 1;     bfs(1);     long long mx = 0, cnt = 0, ans = 0;     for (long long i = 1; i <= n; i++) {       mx = max(mx, level[i]);     }     for (long long i = 0; i <= mx; i++) {       ans += (nodes[i] % 2);       cnt = 0;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t;     cin >> t;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       if (a < c)         cout << 1;       else         cout << -1;       cout <<    ;       if (c < a * b)         cout << b;       else         cout <<  -1 ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int dp[2100][2100] = {0};   int a[2100];   bool vis[2100][2100];   int main(int argc, const char* argv[]) {     string s, p;     cin >> s >> p;     for (int i = 0; i < s.size(); ++i) {       int tmp = 0;       int l = 0;       while (i + tmp < s.size() && l < p.size()) {         if (s[i + tmp] == p[l]) {           ++l;         }         ++tmp;       }       if (l == p.size()) {         a[i] = tmp;       } else         a[i] = -1;     }     for (int i = 0; i < s.size(); ++i) {       for (int j = 0; j <= i; ++j) {         dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);         dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]);         if (a[i] != -1 && i + a[i] <= s.size() &&             j + a[i] - p.size() + 1 <= i + a[i] + 1) {           dp[i + a[i]][j + a[i] - p.size()] =               max(dp[i + a[i]][j + a[i] - p.size()], dp[i][j] + 1);         }       }     }     for (int i = 0; i <= s.size(); ++i) {       cout << dp[s.size()][i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int md = 998244353, MX = 2020;   int n, it, cc, j, z, r, u[2][MX], c[2][MX], v[2][MX], st[MX], vst[MX], pw2[MX];   char s[MX];   bool ok;   void dfs(int i, int j, int cur, int val) {     u[i][j] = it;     c[i][j] = cur;     v[i][j] = val;     if (i == 0) {       if (u[0][n - 1 - j] != it)         dfs(0, n - 1 - j, cur, val);       else if (v[0][n - 1 - j] != val)         ok = false;       if (s[j] ==  0 ) {         if (j < it) {           if (u[1][j] != it)             dfs(1, j, cur, val);           else if (v[1][j] != val)             ok = false;         } else if (st[cur] != it) {           st[cur] = it;           vst[cur] = val;         } else if (vst[cur] != val)           ok = false;       } else if (s[j] ==  1 ) {         if (j < it) {           if (u[1][j] != it)             dfs(1, j, cur, 1 - val);           else if (v[1][j] != 1 - val)             ok = false;         } else if (st[cur] != it) {           st[cur] = it;           vst[cur] = val ^ 1;         } else if (vst[cur] != (val ^ 1))           ok = false;       }     } else {       if (u[1][it - 1 - j] != it)         dfs(1, it - 1 - j, cur, val);       else if (v[1][it - 1 - j] != val)         ok = false;       if (s[j] ==  0 ) {         if (u[0][j] != it)           dfs(0, j, cur, val);         else if (v[0][j] != val)           ok = false;       } else if (s[j] ==  1 ) {         if (u[0][j] != it)           dfs(0, j, cur, 1 - val);         else if (v[0][j] != 1 - val)           ok = false;       }     }   }   int main() {     scanf( %s , s);     n = strlen(s);     reverse(s, s + n);     for (pw2[0] = j = 1; j < MX; j++) pw2[j] = (pw2[j - 1] * 2) % md;     for (it = 1; it < n; it++) {       ok = true;       cc = 1;       dfs(0, n - 1, cc, 1);       if (st[cc] == it && vst[cc] != 0) ok = false;       st[cc] = it;       if (u[1][it - 1] == it) {         if (v[0][n - 1] != v[1][it - 1]) ok = false;       } else {         ++cc;         dfs(1, it - 1, cc, 1);         if (st[cc] == it && vst[cc] != 0) ok = false;         st[cc] = it;       }       for (j = 0; j < n - 1; j++)         if (ok && u[0][j] != it) {           ++cc;           dfs(0, j, cc, 1);         }       for (j = 0; j < it - 1; j++)         if (ok && u[1][j] != it) {           ++cc;           dfs(1, j, cc, 1);         }       if (ok) {         for (z = 0, j = 1; j <= cc; j++)           if (st[j] != it) z++;         r = (r + pw2[z]) % md;       }     }     printf( %d n , r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   using V = vector<T>;   const long long mod = 1000000007;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     string s;     V<V<size_t> > p[2];     p[0].resize(8);     p[1].resize(8);     for (__typeof(8) i = (0) - ((0) > (8)); i != (8) - ((0) > (8));          i += ((0) > (8) ? -1 : 1)) {       cin >> s;       for (__typeof(s.size()) j = (0) - ((0) > (s.size()));            j != (s.size()) - ((0) > (s.size()));            j += ((0) > (s.size()) ? -1 : 1)) {         if (s[j] ==  B )           p[0][j].push_back(i);         else if (s[j] ==  W )           p[1][j].push_back(i);       }     }     size_t mnA = INT_MAX, mnB = INT_MAX;     for (__typeof(8) i = (0) - ((0) > (8)); i != (8) - ((0) > (8));          i += ((0) > (8) ? -1 : 1)) {       if (!p[1][i].empty() && (p[0][i].empty() || p[0][i][0] > p[1][i][0])) {         mnA = min(mnA, p[1][i][0]);       }       if (!p[0][i].empty() &&           (p[1][i].empty() || p[1][i].back() < p[0][i].back())) {         mnB = min(mnB, 7 - p[0][i].back());       }     }     cout << (mnA <= mnB ?  A  :  B );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d(int n) {     if (!n) return 1;     int d = 0;     while (n) {       d++;       n /= 10;     }     return d;   }   int n, k, m;   set<int> st;   set<int>::iterator it;   void prnt() {     it = st.begin();     for (int i = 0; i < m; i++) {       printf( %08d n , *it);       it++;     }     exit(0);   }   void doit(int a, int b) {     if (!b) {       int diff = abs(abs(a) - k);       if (diff >= 10000) return;       if (d(diff * 10000 + n) <= 8) st.insert(diff * 10000 + n);       if (d(n * 10000 + diff) <= 8) st.insert(n * 10000 + diff);       if (st.size() >= m) prnt();       return;     }     doit(a + b % 10, b / 10);     doit(a - b % 10, b / 10);     doit(a * (b % 10), b / 10);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> k >> m;     for (int i = 0; true; i++) {       n = i;       doit(i % 10, i / 10);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6;   int N;   long long A[MAXN + 10], B[MAXN + 10], S;   vector<long long> prime;   int main() {     long long i, j;     scanf( %d , &N);     for (i = 1; i <= N; i++) scanf( %d , &A[i]), S += A[i];     for (i = 2; i * i <= S; i++) {       if (S % i == 0) {         prime.push_back(i);         while (S % i == 0) S /= i;       }     }     if (S != 1) prime.push_back(S);     long long ans = 1e18;     for (auto now : prime) {       long long aaa = 0;       for (i = 1; i <= N; i++) B[i] = A[i];       vector<long long> V;       long long S = 0;       for (i = 1; i <= N; i++) B[i] %= now;       for (i = 1; i <= N; i++) {         if (S + B[i] >= now)           V.push_back(now - S), S += now - S;         else           V.push_back(B[i]), S += B[i];         B[i] -= V.back();         if (S == now) {           long long t = 0;           for (j = 0; j < V.size(); j++) {             t += V[j];             if (t >= (now + 1) / 2) break;           }           long long pos = j;           for (j = 0; j < V.size(); j++) aaa += abs(pos - j) * V[j];           V.clear();           V.push_back(B[i]);           S = B[i];         }       }       ans = min(ans, aaa);     }     if (ans == 1e18) ans = -1;     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   struct Segment {     int l, r;     int id;     bool operator<(const Segment &o) const { return l < o.l; }   } a[maxn];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       scanf( %d %d , &a[i].l, &a[i].r);       a[i].id = i + 1;     }     sort(a, a + n);     priority_queue<int, vector<int>, greater<int> > que;     int ans = -1;     int L, R;     for (int i = 0; i < n; i++) {       que.push(a[i].r);       while (que.size() && que.top() == a[i].l - 1) {         que.pop();       }       while (que.size() > k) {         que.pop();       }       if (que.size() == k) {         int tmp = que.top() - a[i].l + 1;         if (tmp > ans) {           ans = tmp;           L = a[i].l;           R = que.top();         }       }     }     if (ans == -1) {       cout << 0 << endl;       for (int i = 1; i <= k; i++) {         printf( %d  , i);       }     } else {       cout << ans << endl;       int cnt = 0;       for (int i = 0; i < n; i++) {         if (a[i].l <= L && a[i].r >= R) {           printf( %d  , a[i].id);           cnt++;           if (cnt == k) break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int inf = 1e9 + 7;   void solve() {     long long int n, m;     cin >> n >> m;     vector<vector<long long int> > v(n, vector<long long int>(m));     long long int i, j;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> v[i][j];       }     }     vector<long long int> ans(n, -1);     for (i = 0; i < n; i++) {       ans[i] = i;     }     for (i = 0; i < m; i++) {       long long int mx = 0;       for (j = 1; j < n; j++) {         if (v[j][i] >= v[j - 1][i]) {           ans[j] = min(ans[j], mx);         } else {           mx = j;           ans[j] = min(ans[j], mx);         }       }     }     long long int q;     cin >> q;     while (q--) {       long long int l, r;       cin >> l >> r;       l--;       r--;       if (l >= ans[r]) {         cout <<  Yes  << endl;       } else {         cout <<  No  << endl;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   const int mod = 998244353;   int n;   long long a[N], b[N], c[N], k, ans = 2e15;   inline long long qpow(long long a, long long b, long long m) {     long long ans = 1ll;     for (; b; b >>= 1, a = a * a % m)       if (b & 1) ans = ans * a % m;     return ans;   }   inline int read() {     int xx = 0, ff = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       xx = xx * 10 + ch -  0 ;       ch = getchar();     }     return xx * ff;   }   inline int gcd(int a, int b) {     while (b ^= a ^= b ^= a %= b)       ;     return a;   }   inline int lcm(int a, int b) { return a / gcd(a, b) * b; }   inline void pre() {     for (int i = 1; i <= n; i++) b[i] = b[i - 1] + a[i];   }   inline void suf() {     for (int i = n; i >= 1; i--) c[i] = c[i + 1] + a[i];   }   inline long long minLL(long long x, long long y) { return x < y ? x : y; }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     pre();     suf();     for (int l = 1, r; l <= n; l = r + 1) {       for (r = l; a[r + 1] == a[l]; r++)         ;       if (r - l + 1 >= k) return cout << 0, 0;       long long left = 1ll * (a[l] - 1) * (l - 1) - b[l - 1],                 right = c[r + 1] - 1ll * (a[r] + 1) * (n - r),                 mid = k - r + l - 1;       if (r >= k && left + mid < ans) ans = left + mid;       if (n - l + 1 >= k) ans = min(ans, right + mid);       ans = min(ans, left + right + mid);     }     return cout << ans << endl, 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int a, b;     node(int a = 0, int b = 1e9) : a(a), b(b) {}     int get(int x) { return a * x + b; }   };   struct Eins {     vector<node> st;     int n;     Eins(int n) : n(n) { st.resize(n << 2 | 1); }     void modify(int id, int l, int r, node v) {       int mid = l + r >> 1;       if (st[id].get(mid) > v.get(mid)) {         swap(st[id], v);       }       if (l == r) return;       if (st[id].get(l) > v.get(l)) modify(id << 1, l, mid, v);       if (st[id].get(r) > v.get(r)) modify(id << 1 | 1, mid + 1, r, v);     }     int get(int id, int l, int r, int x) {       int ans = st[id].get(x);       if (l == r) return ans;       int mid = l + r >> 1;       if (x <= mid) return min(ans, get(id << 1, l, mid, x));       return min(ans, get(id << 1 | 1, mid + 1, r, x));     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<string> s(n + 1);     vector<Eins> Tree(m + 1, Eins(n + 1));     auto sqr = [&](int x) { return x * x; };     for (int i = 0; i <= n; i++) {       cin >> s[i];       int last = -1;       for (int j = 0; j <= m; j++) {         if (s[i][j] ==  1 ) {           if (last == -1) {             for (int p = 0; p <= j; p++) {               Tree[p].modify(1, 0, n, node(-2 * i, sqr(i) + sqr(p - j)));             }           } else {             for (int p = last + 1; p <= j; p++) {               Tree[p].modify(                   1, 0, n, node(-2 * i, sqr(i) + min(sqr(p - j), sqr(last - p))));             }           }           last = j;         } else if (j == m && last != -1) {           for (int p = last + 1; p <= m; p++) {             Tree[p].modify(1, 0, n, node(-2 * i, sqr(i) + sqr(p - last)));           }         }       }     }     long long ans = 0;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         ans += Tree[j].get(1, 0, n, i) + sqr(i);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   char buf[(1 << 22)], *p1 = buf, *p2 = buf;   inline int read() {     char c =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 22, stdin), p1 == p2)              ? EOF              : *p1++);     int x = 0, f = 1;     while (c< 0  | c>  9 ) {       if (c ==  - ) f = -1;       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 22, stdin), p1 == p2)                ? EOF                : *p1++);     }     while (c >=  0  && c <=  9 )       x = x * 10 + c -  0 ,       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 22, stdin), p1 == p2)                ? EOF                : *p1++);     return x * f;   }   const int maxn = 1e5 + 10;   long long h[2][maxn], dp[2][maxn][2];   int main() {     int n;     while (~scanf( %d , &n)) {       memset(dp, 0, sizeof dp);       for (int i = 1; i <= n; i++) scanf( %d , &h[0][i]);       for (int i = 1; i <= n; i++) scanf( %d , &h[1][i]);       for (int i = 1; i <= n; i++) {         for (int j = 0; j < 2; j++) {           dp[j][i][0] = max(dp[j][i][0],                             max(dp[j][i - 1][0],                                 max(dp[j][i - 1][1], max(dp[j ^ 1][i - 1][0],                                                          dp[j ^ 1][i - 1][1]))));           dp[j][i][1] =               max(dp[j][i][1], max(dp[j ^ 1][i - 1][1],                                    max(dp[j][i - 1][0], dp[j ^ 1][i - 1][0])) +                                    h[j][i]);         }       }       printf( %lld n , max(dp[0][n][1], dp[1][n][1]));     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i;     int a[100000];     double sum = 0;     int sum1 = 0, sum2 = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     sum = sum / n;     for (i = 0; i < n; i++) {       if (sum - a[i] > 0)         sum1 += fabs(sum - a[i]);       else         sum2 += fabs(sum - a[i]);     }     if (sum2 > sum1) sum1 = sum2;     printf( %d n , sum1);   }