malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long const M = 2e5 + 10, M2 = 1e7 + 10, mod = 1e9 + 7, inf = 1e9 + 10,                   sq = 450;   long long a[M], cnt[M], t1, t2, t0, x1;   pair<long long, long long> good, ans;   bool check(long long ind, long long sum) {     if (sum - ind > x1) return 0;     long long res = t2 * ind + t1 * (sum - ind);     if (res >= sum * t0) return 1;     return 0;   }   int32_t main() {     long long x2;     cin >> t1 >> t2 >> x1 >> x2 >> t0;     bool flag = 0;     good = make_pair(-1, -1);     if (t1 > t2) swap(t1, t2), swap(x1, x2), flag = 1;     for (long long i = 1; i <= x1 + x2; i++) {       long long lo = 0, hi = min(x2, i);       if (!check(hi, i)) continue;       while (hi > lo + 1) {         long long mid = (lo + hi) / 2;         if (check(mid, i))           hi = mid;         else           lo = mid + 1;       }       long long best = hi;       if (check(lo, i)) best = lo;       long long res = best * t2 + t1 * (i - best);       if (good.first == -1 || (res * good.second <= good.first * i))         good = make_pair(res, i), ans = make_pair(best, i - best);     }     swap(ans.first, ans.second);     if (flag)       cout << ans.second <<     << ans.first;     else       cout << ans.first <<     << ans.second;   }
#include <bits/stdc++.h>   int pct(int x) { return __builtin_popcount(x); }   using namespace std;   char grid[101][101];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, m;     char c;     cin >> n >> m >> c;     int row;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> grid[i][j];       }     }     set<char> s;     long long ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (grid[i][j] != c && grid[i][j] !=  . ) {           if (i + 1 < n && grid[i + 1][j] == c && s.find(grid[i][j]) == s.end()) {             ans++;             s.insert(grid[i][j]);           } else if (i - 1 >= 0 && grid[i - 1][j] == c &&                      s.find(grid[i][j]) == s.end()) {             ans++;             s.insert(grid[i][j]);           } else if (j + 1 < m && grid[i][j + 1] == c &&                      s.find(grid[i][j]) == s.end()) {             ans++;             s.insert(grid[i][j]);           } else if (j - 1 >= 0 && grid[i][j - 1] == c &&                      s.find(grid[i][j]) == s.end()) {             ans++;             s.insert(grid[i][j]);           }         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 100;   const long long INF = 1e12;   int solve(long long x) {     int res = 0;     while (x) {       res += (x % 10);       x /= 10;     }     return res;   }   int main() {     ios::sync_with_stdio(false);     long long n;     while (cin >> n) {       long long tmp = 0, b = 0;       while (1) {         tmp = tmp * 10 + 9;         if (tmp > n) break;         b = tmp;       }       cout << solve(b) + solve(n - b) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string lower(string s) {     for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);     return s;   }   vector<string> sep(string s, char c) {     string temp;     vector<string> res;     for (int i = 0; i < s.size(); i++) {       if (s[i] == c) {         if (temp !=   ) res.push_back(temp);         temp =   ;         continue;       }       temp = temp + s[i];     }     if (temp !=   ) res.push_back(temp);     return res;   }   template <class T>   T toint(string s) {     stringstream ss(s);     T ret;     ss >> ret;     return ret;   }   template <class T>   string tostr(T inp) {     string ret;     stringstream ss;     ss << inp;     ss >> ret;     return ret;   }   template <class T>   void D(T A[], int n) {     for (int i = 0; i < n; i++) cout << A[i] <<    ;     cout << endl;   }   template <class T>   void D(vector<T> A, int n = -1) {     if (n == -1) n = A.size();     for (int i = 0; i < n; i++) cout << A[i] <<    ;     cout << endl;   }   vector<int> edge[1001];   vector<int> cost[1001];   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int> > lst;     for (int(i) = (0); (i) < (n); (i)++) {       int pq;       scanf( %d , &pq);       lst.push_back((make_pair(pq, i)));     }     sort(lst.rbegin(), lst.rend());     int m;     scanf( %d , &m);     for (int(i) = (0); (i) < (m); (i)++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       edge[b].push_back((a));       cost[b].push_back((c));     }     long long ans = 1000000000000LL;     for (int(i) = (0); (i) < (n); (i)++) {       long long total = 0;       bool tval = 1;       for (int(j) = (0); (j) < (n); (j)++) {         if (i == j) continue;         if (edge[j].size() == 0) {           tval = 0;           break;         }         long long chs = 1000000000000LL;         for (int(k) = (0); (k) < (edge[j].size()); (k)++)           chs = min(chs, (long long)cost[j][k]);         total += chs;       }       if (!tval) continue;       ans = min(ans, total);     }     if (ans == 1000000000000LL)       cout << -1 << endl;     else       cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     bool F = 1;     for (int i = 2; (long long)i * i <= n; i++) {       if (n % i == 0) {         F = 0;         break;       }     }     bool F2 = 1;     for (int i = 2; (long long)i * i <= n - 2; i++) {       if ((n - 2) % i == 0) {         F2 = 0;         break;       }     }     printf( %d n , F ? 1 : n % 2 == 0 || F2 ? 2 : 3);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     os <<  ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, set<T> S) {     os <<  {  ;     for (auto s : S) os << s <<    ;     return os <<  } ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class L, class R>   ostream &operator<<(ostream &os, map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ;     return os <<  } ;   }   vector<long long> adj[500050];   long long a[500050], b[500050];   set<long long> s;   void dfs(long long x, long long pr) {     for (long long i = 0; i < adj[x].size(); i++)       if (adj[x][i] != pr) a[adj[x][i]] = *s.begin(), s.erase(s.begin());     b[x] = *s.begin();     s.erase(s.begin());     for (long long j = adj[x].size() - 1; j >= 0; j--)       if (adj[x][j] != pr) dfs(adj[x][j], x);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, x, y;     cin >> n;     if (n == 1) {       cout <<  1 2 ;       return 0;     }     for (long long i = 2; i < 2 * n + 1; i++) s.insert(i);     for (long long i = 0; i < n - 1; i++)       cin >> x >> y, adj[x].push_back(y), adj[y].push_back(x);     a[1] = 1;     dfs(1, -1);     for (long long i = 1; i < n + 1; i++) cout << a[i] <<     << b[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   int n;   int a[15][15];   void dp() {     for (int i = 1; i <= n; i++) a[i][1] = 1;     for (int j = 1; j <= n; j++) a[1][j] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 2; j <= n; j++) {         a[i][j] = a[i - 1][j] + a[i][j - 1];       }     }   }   int main() {     scanf( %d , &n);     dp();     printf( %d , a[n][n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<pair<pair<long long, long long>, long long>> v;     long long n, k;     cin >> n >> k;     long long p[n], c[n], ans[n];     for (int i = 0; i < n; i++) cin >> p[i];     for (int i = 0; i < n; i++) {       cin >> c[i];       ans[i] = c[i];     }     for (int i = 0; i < n; i++) {       v.push_back({{p[i], c[i]}, i});     }     sort(v.begin(), v.end());     multiset<long long, greater<long long>> s;     for (int i = 0; i < n; i++) {       pair<long long, long long> x = v[i].first;       long long in = v[i].second;       long long coin = x.second;       int cnt = 0;       for (auto e : s) {         if (cnt >= k) break;         ans[in] += e;         cnt++;       }       s.insert(coin);     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void debug_out(const char* name, Arg1&& arg1) {     cout << name <<   =   << arg1 <<   ]  <<   n ;   }   template <typename Arg1, typename... Args>   void debug_out(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   =   << arg1 <<  , ;     debug_out(comma + 1, args...);   }   mt19937_64 rang(       chrono::high_resolution_clock::now().time_since_epoch().count());   const long long mod = 1e9 + 7;   const long long N = 3e5, M = N;   void Solve_main() {     long long n, m, k;     string s;     char won =  # ;     cin >> n >> s;     deque<long long> d, r;     for (long long i = (0); i < (n); ++i) {       if (s[i] ==  D ) {         d.push_back(i);       } else {         r.push_back(i);       }     }     while (!d.empty() && !r.empty()) {       if (d.front() < r.front()) {         r.pop_front();         long long temp = d.front() + n;         d.pop_front();         d.push_back(temp);       } else {         d.pop_front();         long long temp = r.front() + n;         r.pop_front();         r.push_back(temp);       }     }     if (!d.empty()) {       cout <<  D  <<   n ;     } else {       cout <<  R  <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     long long tc = 1;     for (long long i = 0; i < tc; i++) {       Solve_main();     }     cerr <<  [time:  << 1.0 * clock() / CLOCKS_PER_SEC <<  s]  ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void ckmax(T& x, T y) {     x = (y > x ? y : x);   }   template <typename T>   inline void ckmin(T& x, T y) {     x = (y < x ? y : x);   }   namespace Fread {   const int SIZE = 1 << 21;   char buf[SIZE], *S, *T;   inline char getchar() {     if (S == T) {       T = (S = buf) + fread(buf, 1, SIZE, stdin);       if (S == T) return EOF;     }     return *S++;   }   }  // namespace Fread   namespace Fwrite {   const int SIZE = 1 << 21;   char buf[SIZE], *S = buf, *T = buf + SIZE;   inline void flush() {     fwrite(buf, 1, S - buf, stdout);     S = buf;   }   inline void putchar(char c) {     *S++ = c;     if (S == T) flush();   }   struct NTR {     ~NTR() { flush(); }   } ztr;   }  // namespace Fwrite   namespace Fastio {   struct Reader {     template <typename T>     Reader& operator>>(T& x) {       char c = Fread ::getchar();       T f = 1;       while (c <  0  || c >  9 ) {         if (c ==  - ) f = -1;         c = Fread ::getchar();       }       x = 0;       while (c >=  0  && c <=  9 ) {         x = x * 10 + (c -  0 );         c = Fread ::getchar();       }       x *= f;       return *this;     }     Reader& operator>>(char& c) {       c = Fread ::getchar();       while (c ==   n  || c ==    ) c = Fread ::getchar();       return *this;     }     Reader& operator>>(char* str) {       int len = 0;       char c = Fread ::getchar();       while (c ==   n  || c ==    ) c = Fread ::getchar();       while (c !=   n  && c !=    ) {         str[len++] = c;         c = Fread ::getchar();       }       str[len] =   0 ;       return *this;     }     Reader() {}   } cin;   const char endl =   n ;   struct Writer {     template <typename T>     Writer& operator<<(T x) {       if (x == 0) {         Fwrite ::putchar( 0 );         return *this;       }       if (x < 0) {         Fwrite ::putchar( - );         x = -x;       }       static int sta[45];       int top = 0;       while (x) {         sta[++top] = x % 10;         x /= 10;       }       while (top) {         Fwrite ::putchar(sta[top] +  0 );         --top;       }       return *this;     }     Writer& operator<<(char c) {       Fwrite ::putchar(c);       return *this;     }     Writer& operator<<(char* str) {       int cur = 0;       while (str[cur]) Fwrite ::putchar(str[cur++]);       return *this;     }     Writer& operator<<(const char* str) {       int cur = 0;       while (str[cur]) Fwrite ::putchar(str[cur++]);       return *this;     }     Writer() {}   } cout;   }  // namespace Fastio   const int MAXN = 2e5;   int n;   void solve_case() {     Fastio ::cin >> n;     int ans = n;     for (int i = n - 1; i >= 1; --i) {       ans = (ans + i + 1) / 2;     }     Fastio ::cout << ans << Fastio ::endl;     ans = n;     for (int i = n - 1; i >= 1; --i) {       Fastio ::cout << ans <<     << i << Fastio ::endl;       ans = (ans + i + 1) / 2;     }   }   int main() {     int T;     Fastio ::cin >> T;     while (T--) {       solve_case();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long c0, c1, n;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lls[31];   long long comb(long long a, long long b) {     long long s = 1, x, g;     for (long long i = 0; ++i <= b; lls[i] = i)       ;     for (long long i = -1; ++i < b;) {       x = a + b - i;       for (long long j = 0; ++j <= b;) {         g = gcd(lls[j], x);         x /= g;         lls[j] /= g;       }       if (x > 2147483647 / s) return 2147483647;       s *= x;     }     return s;   }   bool check(long long x) {     long long tmp = x / c0 + x / c1 + 1;     if (tmp > n) return 1;     for (long long i = 0; ++i <= 26;) {       for (long long j = i - 1; (++j) * c0 + i * c1 <= x;)         if ((tmp += comb(j, i)) > n) return 1;       for (long long j = i; (++j) * c1 + i * c0 <= x;)         if ((tmp += comb(j, i)) > n) return 1;     }     return 0;   }   void work(long long x, long long &tmp, long long &ans) {     tmp = x / c0 + x / c1 + 1;     ans = ((x / c0) * (x / c0 + 1) * c0 + (x / c1) * (x / c1 + 1) * c1) >> 1;     long long c;     for (long long i = 1; i <= 26; ++i) {       for (long long j = i; j * c0 + i * c1 <= x; ++j) {         c = comb(j, i);         tmp += c;         ans += c * (j * c0 + i * c1);       }       for (long long j = i + 1; j * c1 + i * c0 <= x; ++j) {         c = comb(j, i);         tmp += c;         ans += c * (j * c1 + i * c0);       }     }   }   int main() {     scanf( %lld%lld%lld , &n, &c0, &c1);     --n, c0 > c1 && (swap(c0, c1), 1);     if (!c0) {       printf( %lld n , n * c1);       return 0;     }     long long l = 0, r = c1 * 26, mid;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid))         r = mid - 1;       else         l = mid + 1;     }     long long c, s;     work(l - 1, c, s);     s += (n - c) * l + n * (c0 + c1);     printf( %lld n , s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 5;   int grid[maxn][maxn];   int main() {     int n, ans = 0;     scanf( %d , &n);     for (int i = 0, x1, x2, y1, y2; i < n; i++) {       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       ans += (x2 - x1 + 1) * (y2 - y1 + 1);     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const long long MAX = 2e9 + 7;   const long long mod = 1e9 + 7;   const long long maxn = 1e3 + 7;   int n;   string s[maxn];   set<string> ss;   int jude(string s) {     set<char> q;     int a = s.size();     for (int i = 0; i < s.size(); i++) q.insert(s[i]);     if (q.size() == a)       return 1;     else       return 0;   }   int main() {     cin >> n;     int k = 0;     for (int i = 0; i < n; i++) {       cin >> s[i];       sort(s[i].begin(), s[i].end());       s[i].erase(unique(s[i].begin(), s[i].end()), s[i].end());       int flag = 1;       if (jude(s[i])) ss.insert(s[i]);     }     cout << ss.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   std::mt19937 rnd(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 300000;   struct Res {     int with, without, best;   };   int n;   vector<int> adj[MAXN];   Res dfs(int at, int par) {     int nch = ((int)(adj[at]).size()) - (par != -1 ? 1 : 0);     Res ret;     ret.with = 1;     ret.without = nch;     ret.best = 0;     int without1 = 0, without2 = 0;     int any1 = 0, any2 = 0;     for (int i = (0); i < (((int)(adj[at]).size())); ++i) {       int to = adj[at][i];       if (to == par) continue;       Res sub = dfs(to, at);       ret.with = max(ret.with, sub.without + 1);       ret.without = max(ret.without, max(sub.with, sub.without) + nch - 1);       ret.best = max(ret.best, sub.best);       int anyc = max(sub.with, sub.without);       if (anyc > any1)         any2 = any1, any1 = anyc;       else if (anyc > any2)         any2 = anyc;       int withoutc = sub.without;       if (withoutc > without1)         without2 = without1, without1 = withoutc;       else if (withoutc > without2)         without2 = withoutc;     }     ret.best = max(ret.best, max(ret.with, ret.without));     if (nch >= 2)       ret.best = max(ret.best, max(without1 + without2 + 1,                                    any1 + any2 + ((int)(adj[at]).size()) - 2));     return ret;   }   int solve() { return dfs(0, -1).best; }   void run() {     scanf( %d , &n);     for (int i = (0); i < (n - 1); ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       adj[a].push_back(b), adj[b].push_back(a);     }     printf( %d n , solve());   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int main() {     long long n;     int k, cnt = 0;     scanf( %lld %d , &n, &k);     for (int i = 0; i < 63; i++) {       if (n >> i & 1) {         mp[i] = 1;         ++cnt;       }     }     if (cnt > k) return puts( No ), 0;     puts( Yes );     int st, pre;     for (int i = 62; i >= -62; i--) {       if (mp[i] + cnt <= k) {         pre = i - 1;         mp[i - 1] += 2 * mp[i];         cnt += mp[i];         mp[i] = 0;       } else         break;     }     int x;     for (int i = -62; i < 62; i++) {       if (mp.count(i)) {         x = i;         break;       }     }     vector<int> v;     int res = k - cnt;     if (res > 0) {       --mp[x];       for (int i = 1; i <= res; i++) v.push_back(x - i);       v.push_back(x - res);     }     for (int i = -62; i < 62; i++)       for (int j = 0, y = mp[i]; j < y; j++) v.push_back(i);     sort(v.begin(), v.end(), greater<int>());     for (int i = 0; i < v.size(); i++)       printf( %d%c , v[i],    n [i == v.size() - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[1024][1024];   inline bool u(int i, int j) {     return 0 <= i && i < n && 0 <= j && j <= m && s[i][j] ==  . ;   }   int p[1024 * 1024], c[1024 * 1024];   bool b[1024][1024];   int sid(int x) {     int y, z = x;     for (; (y = p[z]) != z; z = y)       ;     for (; x != z; x = y) {       y = p[x];       p[x] = z;     }     return x;   }   int f(int x, int y) { return sid(x * m + y); }   bool bad(int i, int j) {     return u(i, j) && !u(i - 1, j) && !u(i + 1, j) && !u(i, j - 1) &&            !u(i, j + 1);   }   void unite(int i, int j) {     c[i] += c[j];     p[j] = i;   }   vector<int> adj[1024 * 1024];   void updc(int i) {     if (c[i] < 0) {       int z = 0;       for (int j : adj[i])         if (c[j] >= 0) z |= 1 << (c[j] -  0 );       c[i] =  0  + __builtin_ctz(~z);     }   }   int main() {     cin >> n >> m;     for (int i(0); i < n; ++i) scanf( %s , s[i]);     for (int i(0); i < n; ++i)       for (int j(0); j < m; ++j) {         if (!u(i, j)) continue;         p[i * m + j] = i * m + j;         c[i * m + j] = 1;         if (bad(i, j)) {           puts( -1 );           return 0;         }       }     for (int i(0); i < n; ++i)       for (int j(0); j < m; ++j)         if (u(i, j) && !b[i][j]) {           int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};           for (int k(0); k < 4; ++k) {             int x = i + dx[k], y = j + dy[k];             if (u(x, y) && !b[x][y]) {               b[i][j] = b[x][y] = true;               unite(f(i, j), f(x, y));               break;             }           }         }     for (int i(0); i < n; ++i) {       for (int j(0); j < m; ++j)         if (u(i, j) && !b[i][j]) {           int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};           for (int k(0); k < 4; ++k) {             int x = i + dx[k], y = j + dy[k];             if (u(x, y) && c[f(x, y)] + c[f(i, j)] <= 5) {               unite(f(x, y), f(i, j));               b[i][j] = true;               break;             }           }         }     }     for (int i(0); i < n; ++i)       for (int j(0); j < m; ++j)         if (u(i, j)) {           if (u(i + 1, j) && f(i, j) != f(i + 1, j)) {             adj[f(i, j)].push_back(f(i + 1, j));             adj[f(i + 1, j)].push_back(f(i, j));           }           if (u(i, j + 1) && f(i, j) != f(i, j + 1)) {             adj[f(i, j)].push_back(f(i, j + 1));             adj[f(i, j + 1)].push_back(f(i, j));           }           c[f(i, j)] = -1;         }     for (int i(0); i < n; ++i)       for (int j(0); j < m; ++j)         if (u(i, j)) {           updc(f(i, j));           s[i][j] = c[f(i, j)];         }     for (int i(0); i < n; ++i) puts(s[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   long long x, b;   void run(int a) {     if (a < 10)       x += a;     else {       x += a - a % 10;       run(a / 10 + a % 10);     }   }   int main() {     cin >> t;     int s[10005];     for (int i = 0; i < t; i++) cin >> s[i];     for (int i = 0; i < t; i++) {       x = 0;       run(s[i]);       cout << x << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   const int MOD = 1000000007;   const int N = 1E5 + 15;   const int maxn = 2e5 + 14;   const int INF = (1 << 30) - 1;   const int letter = 130;   const double pi = acos(-1.0);   const double eps = 1e-8;   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, q;   long long a[N], b[N];   long long L[N], R[N];   int s[N], top;   void solve(int l, int r) {     int cnt = 0;     for (int i = l; i < r; i++) b[++cnt] = a[i];     b[0] = INF;     b[cnt + 1] = INF;     s[top = 0] = 0;     for (int i = 1; i <= cnt + 1; i++) {       if (b[i] <= b[s[top]])         s[++top] = i;       else {         while (top >= 0 && b[s[top]] < b[i]) R[s[top]] = i - s[top], top--;         s[++top] = i;       }     }     s[top = 0] = cnt + 1;     for (int i = cnt; i >= 0; i--) {       if (b[i] < b[s[top]])         s[++top] = i;       else {         while (top >= 0 && b[s[top]] <= b[i]) L[s[top]] = s[top] - i, top--;         s[++top] = i;       }     }     long long ans = 0;     for (int i = 1; i <= cnt; i++) {       ans += L[i] * R[i] * b[i];     }     printf( %I64d n , ans);   }   int main() {     int x, y;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %I64d , a + i);     for (int i = 1; i < n; i++) a[i] = abs(a[i + 1] - a[i]);     while (q--) {       scanf( %d%d , &x, &y);       solve(x, y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, m = 0, k = 0, arr[101], seg[100001][3];     long long sum = 0;     cin >> n >> m >> k;     for (int i = 0; i < m; i++) cin >> seg[i][0] >> seg[i][1] >> seg[i][2];     for (int i = 0; i < k; i++) cin >> arr[i];     for (int i = 0; i < k; i++) {       for (int j = 0; j < m; j++) {         if (arr[i] < seg[j][0] || arr[i] > seg[j][1]) continue;         sum += (arr[i] - seg[j][0]) + seg[j][2];       }     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t n, s, ans = -1, x, y;   int main() {     cin >> n >> s;     while (n--) {       cin >> x >> y;       if (x < s || (x == s && !y)) ans = max(ans, !y ? 0 : 100 - y);     }     cout << ans << endl;     return 0;   }