malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void solve();   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout << fixed;     cout.precision(12);     solve();     return 0;   }   template <typename T>   void prv(vector<T> v) {     for (int __ii = 0; __ii < ((int)v.size()); __ii++) {       if (__ii) cout <<    ;       cout << v[__ii];     }     cout <<   n ;   }   template <typename T>   void prm(vector<vector<T>> v) {     for (int __ii = 0; __ii < ((int)v.size()); __ii++) {       for (int __jj = 0; __jj < v[__ii].size(); __jj++) {         if (__jj) cout <<    ;         cout << v[__ii][__jj];       }       cout <<   n ;     }   }   template <typename T>   void sc(T& x) {     cin >> x;   }   template <typename Head, typename... Tail>   void sc(Head& head, Tail&... tail) {     cin >> head;     sc(tail...);   }   template <typename T>   void pr(const T& x) {     cout << x <<   n ;   }   template <typename Head, typename... Tail>   void pr(const Head& head, const Tail&... tail) {     cout << head <<    ;     pr(tail...);   }   template <typename... T>   void err(const T&... cod) {     pr(cod...);     exit(0);   }   void solve() {     int n, m, y, x;     sc(n, m, y, x);     string s;     sc(s);     int dx = (s[1] ==  L  ? -1 : 1);     int dy = (s[0] ==  U  ? -1 : 1);     const int MAX_ITER = 1e6 + 10;     set<pair<int, int>> st;     long long ans = 1;     for (int i = 0; i < MAX_ITER; i++) {       st.emplace(y, x);       if (((int)st.size()) == n + m - 2) err(ans);       int u = (dy == -1 ? y - 1 : n - y);       int v = (dx == -1 ? x - 1 : m - x);       int w = min(u, v);       x += dx * w;       y += dy * w;       ans += w;       if (v == w) dx *= -1;       if (u == w) dy *= -1;     }     pr(-1);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     string s;     cin >> s;     string v =  aeiou ;     string c =  bcdfghjklmnpqrstvwxyz ;     map<char, int> cnt;     map<char, int> mp;     for (auto i : v) mp[i] = 1;     for (auto i : c) mp[i] = 0;     string temp =   ;     int vc = 0;     int cc = 0;     int dc = 0;     vector<string> ans;     for (int i = 0; i < s.size(); i++) {       if (mp[s[i]] == 1) {         cc = 0;         dc = 0;         for (auto j : c) cnt[j] = 0;       } else {         if (cnt[s[i]] == 0) {           cnt[s[i]]++;           dc++;           cc++;         } else {           cnt[s[i]]++;           cc++;         }       }       if (cc > 2 && dc > 1) {         ans.push_back(temp);         for (auto j : c) cnt[j] = 0;         cnt[s[i]] = 1;         cc = 1;         dc = 1;         temp = s[i];       } else         temp += s[i];     }     ans.push_back(temp);     for (auto i : ans) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   string s[10005];   int vis[10005];   int main() {     ios::sync_with_stdio(0);     int n, sum(0);     cin >> n;     for (long long i = 0; i < n; ++i) cin >> s[i], sum += s[i].size();     char c;     cin >> c;     for (long long i = 0; i < n; ++i) s[i] += c;     sort(s, s + n);     sum = sum * 2 / n + 1;     for (long long i = 0; i < n; ++i)       if (!vis[i]) {         cout << s[i];         vis[i]++;         for (long long j = i + 1; j < n; ++j)           if (!vis[j] && sum - s[i].size() == s[j].size() - 1) {             cout << s[j].substr(0, s[j].size() - 1) <<   n ;             vis[j]++;             break;           }       }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     map<int, int> used;     int ans = 0;     for (int i = n - 1; i >= 0; --i) {       if (used[a[i]] == 0) {         used[a[i]] = i;         ans = a[i];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double E = 1e-7;   const int MOD = 1e9 + 7;   const long long MAX = 1e6 + 1;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, k;     cin >> n >> k;     int ar[n];     for (int i = 0; i < n; i++) cin >> ar[i];     int ans = INT_MIN;     int a[n], b[n];     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++) {         int A = j - i + 1;         int B = n - A;         copy(ar + i, ar + j + 1, a);         copy(ar, ar + i, b);         copy(ar + j + 1, ar + n, b + i);         sort(a, a + A);         sort(b, b + B);         for (int l = 0, r = B - 1, q = k; l < A && r >= 0 && a[l] < b[r] && q;              l++, r--, --q)           swap(a[l], b[r]);         int sum = 0;         for (int i = 0; i < A; i++) sum += a[i];         ans = max(ans, sum);       }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (x > y)       return gcd(x - y, y);     else if (x == y)       return x;     else       return gcd(x, y - x);   }   int main() {     int n, m, z;     cin >> n >> m >> z;     cout << (gcd(n, m) * z) / (n * m) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p = 0, ans = 0;     string s, dvg, answ, r_dvg;     cin >> n >> s;     for (int i = 0; i < n - 1; i++) {       dvg = s.substr(i, 2);       for (int j = i; j < n - 1; j++) {         r_dvg = s.substr(j, 2);         if (dvg == r_dvg) {           p++;         }       }       if (p > ans) {         ans = p;         answ = dvg;       }       p = 0;     }     cout << answ << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     long long x, y;     void read() { scanf( %lld%lld , &x, &y); }   };   long long product(const Point &o, const Point &a, const Point &b) {     return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);   }   bool intersect(const Point &a, const Point &b, const Point &c, const Point &d) {     bool insect1 = product(a, c, d) * product(b, c, d) < 0;     bool insect2 = product(c, a, b) * product(d, a, b) < 0;     return insect1 && insect2;   }   int main() {     ios ::sync_with_stdio(false);     cout << fixed << setprecision(16);     int R, B;     scanf( %d%d , &R, &B);     vector<Point> bases(B);     vector<Point> ships(R);     vector<int> b(R);     for (int i = 0; i < R; i++) {       ships[i].read();     }     for (int i = 0; i < B; i++) {       bases[i].read();     }     if (B != R) {       puts( No );       return 0;     }     for (int i = 0; i < R; i++) {       b[i] = i;     }     bool yes = false;     do {       bool ok = true;       for (int i = 0; i < B; i++) {         for (int j = i + 1; j < B; j++) {           if (intersect(ships[b[i]], bases[i], ships[b[j]], bases[j])) {             ok = false;           }         }       }       if (ok) {         yes = true;         break;       }     } while (next_permutation(b.begin(), b.end()));     puts(yes ?  Yes  :  No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 305000;   long long mod = 1e9 + 7;   long long h, w, n;   long long dp[maxn], f[maxn], inv[maxn];   struct stu {     long long x, y;   } a[maxn];   long long cmp(stu a, stu b) {     if (a.x != b.x)       return a.x < b.x;     else       return a.y < b.y;   }   long long ksm(long long base, long long b, long long mod) {     long long ans = 1;     while (b) {       if (b & 1) {         ans *= base;         ans %= mod;       }       base *= base;       base %= mod;       b >>= 1;     }     return ans;   }   void init() {     f[0] = 1, inv[0] = 1;     for (long long i = 1; i <= 200000; i++) {       f[i] = f[i - 1] * i % mod;       inv[i] = ksm(f[i], mod - 2, mod);     }   }   long long c(long long x, long long y) {     if (x < y)       return 0;     else       return f[x] * inv[y] % mod * inv[x - y] % mod;   }   signed main() {     cin >> h >> w >> n;     init();     for (long long i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;     sort(a + 1, a + n + 1, cmp);     a[n + 1].x = h, a[n + 1].y = w;     for (long long i = 1; i <= n + 1; i++) {       dp[i] = c(a[i].x + a[i].y - 2, a[i].x - 1);       for (long long j = 1; j < i; j++) {         if (a[j].x > a[i].x || a[j].y > a[i].y) continue;         dp[i] = (dp[i] -                  dp[j] * c(a[i].x + a[i].y - a[j].x - a[j].y, a[i].x - a[j].x)) %                 mod;       }     }     cout << (dp[n + 1] + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[3005], inv = 0, n;   double sol;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (v[i] > v[j]) inv++;     sol = double(inv) - inv / 2 + (inv / 2) * 3.0;     cout << fixed;     cout << setprecision(6);     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     pair<int, int> minp1(INF, INF), minp2(INF, INF);     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       minp1 = min(minp1, pair<int, int>(x, y));     }     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       x *= -1;       y *= -1;       minp2 = min(minp2, pair<int, int>(x, y));     }     cout << minp1.first - minp2.first <<     << minp1.second - minp2.second;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     printf( %d n , (n & 1) ? (n - 1) + (n - 1) * ((n - 3) / 2) / 2                            : (n - 2) * (n - 2) / 4 + (n - 2));     if (n & 1) {       for (int i = 2; i <= n; i += 2) {         printf( %d %d %d %d n , 3, 1, i, i + 1);         printf( %d %d %d %d n , 3, 1, i, i + 1);         for (int j = 2; j < i; j += 2) {           printf( %d %d %d %d %d n , 4, i, j, i + 1, j + 1);           printf( %d %d %d %d %d n , 4, i, j, i + 1, j + 1);         }       }     } else {       puts( 4 1 2 3 4 ), puts( 4 1 3 4 2 ), puts( 4 1 4 2 3 );       for (int i = 5; i <= n; i += 2) {         printf( %d %d %d %d  n , 3, 1, i, i + 1);         printf( %d %d %d %d  n , 3, 2, i, i + 1);         printf( %d %d %d %d %d n , 4, 1, i, 2, i + 1);         for (int j = 3; j < i; j += 2) {           printf( %d %d %d %d %d n , 4, i, j, i + 1, j + 1);           printf( %d %d %d %d %d n , 4, i, j, i + 1, j + 1);         }       }     }     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 100100;   struct Gao {     int p[MAXN], q[MAXN];     bool r[MAXN];     void init(int n) {       for (int i = 0; i < n; ++i) {         q[i] = 1;         r[i] = true;       }     }     void next(int i) {       if (!r[p[i]] && p[i] != i) {         next(p[i]);         q[i] += q[p[i]];         p[i] = p[p[i]];       }     }     void kill(int i) {       if (r[i]) {         next(i);         r[i] = false;       }     }   } gao;   int main() {     int n, m, x, y, z;     static int a[MAXN], b[MAXN];     scanf( %d%d , &n, &m);     gao.init(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &gao.p[i]);       --gao.p[i];     }     for (int i = 0; i < m; ++i) {       scanf( %d , &a[i]);       --a[i];     }     for (int i = 0; i < m; ++i) {       scanf( %d , &b[i]);     }     z = 0;     for (int i = 0; i < m; ++i) {       x = (a[i] + z) % n;       y = b[i];       z = 0;       while (true) {         if (!gao.r[x]) {           gao.next(x);           y -= gao.q[x];           x = gao.p[x];         }         if (gao.r[x] && y > 0) {           ++z;           gao.kill(x);         } else {           break;         }       }       printf( %d n , z);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e4 + 5;   int pr[N], ps = 0;   bool np[N];   bool check(int n) {     if (n == 1 || n == 0) return false;     for (int i = 0; pr[i] * pr[i] <= n; ++i)       if (n % pr[i] == 0) return false;     return true;   }   int main() {     for (int i = 2; i < N; ++i)       if (!np[i]) {         pr[ps++] = i;         for (int j = i + i; j < N; j += i) np[j] = 1;       }     int n;     cin >> n;     if (check(n)) {       cout <<  1 n  << n << endl;       return 0;     }     for (int i = 0; i < ps && pr[i] <= n; ++i) {       if (check(n - pr[i])) {         cout <<  2 n  << pr[i] <<     << n - pr[i] << endl;         return 0;       }       if (pr[i] % 2 == 1 && check((n - pr[i]) / 2)) {         cout <<  3 n               << pr[i] <<     << (n - pr[i]) / 2 <<     << (n - pr[i]) / 2 << endl;         return 0;       }     }     cout <<  lol nope n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mk = 100005;   long long n;   vector<long long> g[mk];   long long find(long long A) {     if (A == 0) return 0;     long long tmp = A & 3;     long long R = (find(A / 4) << 2);     if (tmp == 0) return R;     if (tmp == 1) return (R | 2);     if (tmp == 2) return (R | 3);     if (tmp == 3) return (R | 1);   }   void init() {     long long test;     cin >> test;     for (long long i = 1; i <= test; i++) {       long long n;       cin >> n;       long long root = 1;       while (root * 4 <= n) root *= 4;       n -= (root - 1);       long long A = (root | ((n - 1) / 3));       long long B = find(A);       long long C = A ^ B;       if (n % 3 == 1) cout << A;       if (n % 3 == 2) cout << B;       if (n % 3 == 0) cout << C;       cout <<   n ;     }   }   signed main() { init(); }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 5;   pair<int, int> p[maxn];   set<pair<int, int> > s;   void solve(int l, int r) {     if (r - l < 2) return;     int mid = (l + r) / 2;     solve(l, mid), solve(mid, r);     for (int i = l; i < r; i++) s.insert(make_pair(p[mid].first, p[i].second));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++)       cin >> p[i].first >> p[i].second,           s.insert(make_pair(p[i].first, p[i].second));     sort(p, p + n);     solve(0, n);     cout << s.size() << endl;     for (pair<int, int> now : s) cout << now.first <<     << now.second << endl;     return 0;   }
#include <bits/stdc++.h>   template <class C, class E>   inline bool contains(const C& container, const E& element) {     return container.find(element) != container.end();   }   template <class T>   inline void checkmin(T& a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T& a, T b) {     if (b > a) a = b;   }   using namespace std;   class UnionFind {    public:     UnionFind(int elements) : _subsets(elements), _setCount(elements) {       for (int i = 0; i < elements; ++i) {         _subsets[i].parent = i;         _subsets[i].rank = 0;       }     }     int Find(int i) {       if (_subsets[i].parent != i) _subsets[i].parent = Find(_subsets[i].parent);       return _subsets[i].parent;     }     void Union(int x, int y) {       int xroot = Find(x);       int yroot = Find(y);       if (xroot == yroot) return;       --_setCount;       if (_subsets[xroot].rank < _subsets[yroot].rank)         _subsets[xroot].parent = yroot;       else if (_subsets[xroot].rank > _subsets[yroot].rank)         _subsets[yroot].parent = xroot;       else {         _subsets[yroot].parent = xroot;         _subsets[xroot].rank++;       }     }     struct subset {       int parent;       int rank;     };     void Trace() {       for (int i = (0), _b = ((_subsets.size()) - 1); i <= _b; i++)         cout << i <<  :  << Find(i) <<   | ;       cout << endl;     }     vector<subset> _subsets;     int _setCount;   };   struct SetInfo {     set<int> _yc;     set<int> _xc;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << std::setprecision(15);     cout << std::fixed;     long long xs, ys, q;     cin >> xs >> ys >> q;     UnionFind uf(xs + ys);     vector<pair<int, int> > p(q);     for (int i = (0), _b = ((q)-1); i <= _b; i++) {       int x, y;       cin >> p[i].first >> p[i].second;       --p[i].first;       --p[i].second;       uf.Union(p[i].first, xs + p[i].second);     }     map<int, SetInfo> ss;     for (int i = (0), _b = ((q)-1); i <= _b; i++) {       int id = uf.Find(p[i].first);       SetInfo& setInfo = ss[id];       setInfo._xc.insert(p[i].first);       setInfo._yc.insert(p[i].second);     }     long long got = 0;     long long totX = 0, totY = 0;     for (auto& p : ss) {       totX += (long long)p.second._xc.size();       totY += (long long)p.second._yc.size();     }     long long remX = xs - totX;     long long remY = ys - totY;     long long res = remX + remY - 1 + ss.size();     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   bool chmin(T& x, const T& y) {     if (x > y) {       x = y;       return true;     }     return false;   }   template <typename T>   bool chmax(T& x, const T& y) {     if (x < y) {       x = y;       return true;     }     return false;   }   string to_bin(int x) {     string ret;     while (x) {       ret = ret + (char)((x % 2) +  0 );       x /= 2;     }     return ret;   }   int main(int, char**) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long m = (n - 1) / 3;       int k = 0;       long long p = 1;       while (m >= p) {         m -= p;         k += 1;         p *= 4;       }       vector<long long> a;       for (int i = 0; i < k; ++i) {         a.push_back(m % 4);         m /= 4;       }       long long A, B;       A = 1LL << (2 * k);       B = 1LL << (2 * k + 1);       vector<long long> b = {0, 2, 3, 1};       for (int i = 0; i < k; ++i) {         A ^= a[i] << (2 * i);         B ^= b[a[i]] << (2 * i);       }       long long C = A ^ B;       long long ans;       if (n % 3 == 1) {         ans = A;       } else if (n % 3 == 2) {         ans = B;       } else {         ans = C;       }       cout << ans <<   n ;     }     cerr <<  Time execute:   << clock() / (double)CLOCKS_PER_SEC <<   sec           << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double n, m, a, b;     cin >> n >> m >> a >> b;     double s = n / m;     long long int s1 = floor(s) * m;     long long int s2 = ceil(s) * m;     long long int a1 = (n - s1) * b;     long long int a2 = (s2 - n) * a;     cout << (min(a1, a2));   }
#include <bits/stdc++.h>   using namespace std;   int res;   int tox[] = {0, 0, 1, -1};   int toy[] = {1, -1, 0, 0};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     string s;     cin >> s;     while (s.back() ==  0 ) s.erase(s.size() - 1, 1), res++;     while (s !=  1 ) {       while (s.size() && s.back() ==  1 ) s.erase(s.size() - 1, 1), res++;       res++;       if (!s.size()) break;       s.back() =  1 ;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     deque<long long int> b, g;     long long int n;     cin >> n;     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       b.push_back(temp);     }     cin >> n;     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       g.push_back(temp);     }     sort(b.begin(), b.end());     sort(g.begin(), g.end());     long long int ans = 0;     while (b.size() && g.size()) {       if (abs(b.front() - g.front()) <= 1) {         ans++;         b.pop_front();         g.pop_front();       } else {         if (b.front() < g.front())           b.pop_front();         else           g.pop_front();       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   bool comp(pair<long long, long long> p1, pair<long long, long long> p2) {     if (p1.first != p2.first) {       return p1.first < p2.first;     } else       return p2.second < p1.second;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     map<long long, vector<pair<long long, long long>>> m;     for (long long i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       long long level = max(x, y);       m[level].push_back({x, y});     }     vector<pair<long long, long long>> v;     long long dp[200006][2];     memset(dp, INT_MAX, sizeof dp);     dp[0][0] = 0;     dp[0][1] = 0;     pair<long long, long long> p_start, p_end;     p_start = {0, 0};     p_start = {0, 0};     long long i = 1;     for (auto it : m) {       for (auto it1 : it.second) {         v.push_back(it1);       }       sort(v.begin(), v.end(), comp);       pair<long long, long long> start = v[0];       pair<long long, long long> end = v[v.size() - 1];       long long di =           abs(start.first - end.first) + abs(start.second - end.second);       long long a1 = dp[i - 1][0] + abs(p_start.first - end.first) +                      abs(p_start.second - end.second) + di;       long long a2 = dp[i - 1][1] + abs(p_end.first - end.first) +                      abs(p_end.second - end.second) + di;       dp[i][0] = min(a1, a2);       a1 = dp[i - 1][0] + abs(p_start.first - start.first) +            abs(p_start.second - start.second) + di;       a2 = dp[i - 1][1] + abs(p_end.first - start.first) +            abs(p_end.second - start.second) + di;       dp[i][1] = min(a1, a2);       p_start = start;       p_end = end;       v.clear();       i++;     }     cout << min(dp[i - 1][0], dp[i - 1][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int Q = 1e9 + 7;   struct Point {     int x, y;     Point(int _x = 0, int _y = 0) : x(_x), y(_y) {}     const int sign() const { return y < 0 || y == 0 && x < 0; }     Point operator-(const Point &R) { return Point(x - R.x, y - R.y); }     long long operator^(const Point &R) const {       return (long long)x * R.y - (long long)y * R.x;     }     bool operator<(const Point &R) const {       if (sign() != R.sign()) {         return sign() < R.sign();       }       return (*this ^ R) > 0;     }   };   inline void add(long long &A, long long B) { A += B; }   Point p[N];   int n;   long long f[6][N][N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &p[i].x, &p[i].y);       f[0][i][i] = 1;     }     vector<tuple<Point, int, int>> v;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < i; ++j) {         v.emplace_back(p[j] - p[i], i, j);         v.emplace_back(p[i] - p[j], j, i);       }     }     sort(v.begin(), v.end());     for (auto &it : v) {       int x = get<1>(it);       int y = get<2>(it);       for (int i = 5; i > 0; --i) {         for (int j = 0; j < n; ++j) {           add(f[i][j][y], f[i - 1][j][x]);         }       }     }     long long res = 0;     for (int i = 0; i < n; ++i) {       add(res, f[5][i][i]);     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, r, sall, sk;     cin >> n >> k >> l >> r >> sall >> sk;     int el[n];     int div, mod, m, sm;     m = n - k;     sm = sall - sk;     if (k > 0) {       div = sk / k;       mod = sk % k;       for (int i = 0; i < k; i++) {         el[i] = div;         if (i < mod) {           el[i] += 1;         }       }     }     if (m > 0) {       div = sm / m;       mod = sm % m;       for (int i = 0; i < m; i++) {         el[i + k] = div;         if (i < mod) {           el[i + k] += 1;         }       }     }     for (int i = 0; i < n; i++) {       cout << el[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long ar[100005];   long long N;   int main() {     cin >> N;     for (long long i = 0; i < N; i++) cin >> ar[i];     long long ans = 0ll;     for (long long i = 0; i < N; i++) {       long long lft = (i == 0 ? 0 : ar[i - 1]);       if (ar[i] < lft) ans += (ar[i]) * (lft - ar[i]);       if (ar[i] > lft) ans += (ar[i] - lft) * (N - ar[i] + 1);     }     cout << ans << endl;     return (0);   }