malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q, r, c;     cin >> n >> q;     vector<vector<int>> a(2, vector<int>(n, 1));     vector<string> pass(q);     set<pair<pair<int, int>, pair<int, int>>> count;     for (int o = 0; o < q; o++) {       cin >> r >> c;       r--;       c--;       a[r][c] *= -1;       if (a[r][c] == -1) {         if (r == 1) {           if (c - 1 >= 0 && a[0][c - 1] == -1) {             count.insert({{0, c - 1}, {r, c}});             count.insert({{r, c}, {0, c - 1}});           }           if (a[0][c] == -1) {             count.insert({{0, c}, {r, c}});             count.insert({{r, c}, {0, c}});           }           if (c + 1 < n && a[0][c + 1] == -1) {             count.insert({{0, c + 1}, {r, c}});             count.insert({{r, c}, {0, c + 1}});           }         } else {           if (c - 1 >= 0 && a[1][c - 1] == -1) {             count.insert({{1, c - 1}, {r, c}});             count.insert({{r, c}, {1, c - 1}});           }           if (a[1][c] == -1) {             count.insert({{1, c}, {r, c}});             count.insert({{r, c}, {1, c}});           }           if (c + 1 < n && a[1][c + 1] == -1) {             count.insert({{1, c + 1}, {r, c}});             count.insert({{r, c}, {1, c + 1}});           }         }       } else {         if (!count.empty()) {           if (r == 1) {             if (c - 1 >= 0 && count.find({{0, c - 1}, {r, c}}) != count.end()) {               count.erase({{0, c - 1}, {r, c}});               count.erase({{r, c}, {0, c - 1}});             }             if (count.find({{0, c}, {r, c}}) != count.end()) {               count.erase({{0, c}, {r, c}});               count.erase({{r, c}, {0, c}});             }             if (c + 1 < n && count.find({{0, c + 1}, {r, c}}) != count.end()) {               count.erase({{0, c + 1}, {r, c}});               count.erase({{r, c}, {0, c + 1}});             }           } else {             if (c - 1 >= 0 && count.find({{1, c - 1}, {r, c}}) != count.end()) {               count.erase({{1, c - 1}, {r, c}});               count.erase({{r, c}, {1, c - 1}});             }             if (count.find({{1, c}, {r, c}}) != count.end()) {               count.erase({{1, c}, {r, c}});               count.erase({{r, c}, {1, c}});             }             if (c + 1 < n && count.find({{1, c + 1}, {r, c}}) != count.end()) {               count.erase({{1, c + 1}, {r, c}});               count.erase({{r, c}, {1, c + 1}});             }           }         }       }       if (count.empty())         pass[o] =  Yes ;       else         pass[o] =  No ;     }     for (int i = 0; i < q; i++) {       cout << pass[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1050;   int n, m, g[maxn][maxn], ans[maxn][maxn];   int p[4] = {4, 3, 2, 1};   bool chk1(int x, int a, int b) {     int i, st, c[2] = {a, b};     for (st = 0; st < m && !g[x][st]; st++)       ;     if (g[x][st] != c[0]) swap(c[0], c[1]);     for (i = 0; st + i < m; i++)       if (g[x][st + i] && g[x][st + i] != c[i & 1])         return 0;       else         ans[x][st + i] = c[i & 1];     for (i = 1; i <= st; i++) ans[x][st - i] = c[i & 1];     return 1;   }   bool chk2(int x, int a, int b) {     int i, st, c[2] = {a, b};     for (st = 0; st < n && !g[st][x]; st++)       ;     if (g[st][x] != c[0]) swap(c[0], c[1]);     for (i = 0; st + i < n; i++)       if (g[st + i][x] && g[st + i][x] != c[i & 1])         return 0;       else         ans[st + i][x] = c[i & 1];     for (i = 1; i <= st; i++) ans[st - i][x] = c[i & 1];     return 1;   }   void print() {     int i, j;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) printf( %d , ans[i][j]);       printf(  n );     }   }   bool check() {     int i, j;     bool z = 1;     for (i = 0; i < n; i++) z &= chk1(i, p[(i & 1) * 2], p[(i & 1) * 2 + 1]);     if (z) {       print();       return 1;     }     z = 1;     for (i = 0; i < m; i++) z &= chk2(i, p[(i & 1) * 2], p[(i & 1) * 2 + 1]);     if (z) {       print();       return 1;     }     return 0;   }   int main() {     int i, j;     scanf( %d%d n , &n, &m);     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) g[i][j] = getchar() -  0 ;       scanf(  n );     }     for (i = 0; i < 4 * 3 * 2; i++) {       next_permutation(p, p + 4);       if (check()) return 0;     }     printf( 0 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100000];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> arr[i];     for (int i = 1; n / i >= 3; ++i) {       if (n % i != 0) continue;       for (int j = 0; j < i; ++j) {         int Ok = 0;         for (int k = j; k < n; k += i) {           if (arr[k] == 1) ++Ok;         }         if (Ok == n / i) {           cout <<  YES  << endl;           return 0;         }       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k = 0;     string s;     cin >> s >> n;     vector<char> v, vv;     int len = s.size();     if (len % n != 0) {       cout <<  NO  << endl;       return 0;     }     int cnt = 0, c = 0, j;     int m = len / n;     for (int i = 0; i < n; i++) {       v.clear();       vv.clear();       for (j = c; j < len; j++) {         v.push_back(s[j]);         vv.push_back(s[j]);         cnt++;         c++;         if (cnt == m) break;       }       cnt = 0;       int pnt = 0;       reverse(vv.begin(), vv.end());       int ln = v.size();       for (int i = 0; i < ln; i++) {         if (v[i] == vv[i]) pnt++;         if (pnt == ln) {           k++;         }       }       v.clear();       vv.clear();     }     if (k == n) {       k = 0;       cout <<  YES  << endl;     } else {       k = 0;       cout <<  NO  << endl;     }     return 0;   }
#include <cmath>   #include <cstdio>   #include <string>   #include <cstring>   #include <iostream>   #include <algorithm>   using namespace std;   typedef long long ll;   const int N = 55;   const int mod = 1e9 + 7;         int t , n , m ,ans;   char s[N];   int a[N];      void solve(){       cin>>s + 1;       int len = strlen( s + 1);       int flag = 1; // 1 : smaller       int cnt = 0;       while( cnt < len ){           if( cnt < len){               for(int i = 1;i <= len; ++ i){                   if( !a[i] ) {                       a[i] = 1 , ++cnt ;                       if( s[i] !=  a  ) s[i] =  a  ;                       else s[i] =  b  ;                       break;                   }               }           }           if( cnt < len){               for(int i = 1;i <= len; ++ i){                   if( !a[i] ) {                       a[i] = 1 , ++cnt;                       if( s[i] !=  z  ) s[i] =  z  ;                       else s[i] =  y ;                       break;                   }               }           }       }       for(int i = 1;i <= len; ++ i) cout<<s[i];       memset(a ,0 , sizeof(a) );       cout<<endl;   }      int main(){       ios::sync_with_stdio(false);       cin.tie(0);       cin>>t;       while( t -- ) solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int findGreater(int compare, int startIndex, int *arr, int sizeofArray) {     for (int i = startIndex; i < sizeofArray; i++) {       if (compare < arr[i]) return i;     }     return -1;   }   int findLesser(int compare, int startIndex, int *arr, int sizeofArray) {     for (int i = startIndex; i < sizeofArray; i++) {       if (compare > arr[i]) return i;     }     return -1;   }   void initArray(int *arr, int Size) {     for (int j = 0; j < Size; j++) {       cin >> arr[j];     }   }   int main() {     int TestCases;     int Size;     int *arr;     int i;     int j;     int k;     cin >> TestCases;     for (int t = 0; t < TestCases; t++) {       cin >> Size;       arr = new int[Size];       initArray(arr, Size);       for (int i = 0; i < Size; i++) {         if (i + 1 == Size) {           cout <<  NO  << endl;         }         j = findGreater(arr[i], i + 1, arr, Size);         if (j < 0) {           continue;         }         k = findLesser(arr[j], j + 1, arr, Size);         if (k < 0) {           continue;         }         cout <<  YES  << endl;         cout << i + 1 <<     << j + 1 <<     << k + 1 << endl;         break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};   const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};   const int inf = 1e9 + 5;   const long long linf = 1e18 + 5;   const double PI = acos(-1.0);   const int MAXN = 1e6 + 5;   const int N = 4e6 + 5;   const long double eps = 1e-8;   const long double fix = 1e-2;   int n;   int a[MAXN], b[MAXN];   int l[MAXN], r[MAXN];   int s[MAXN], h = 0;   vector<int> st[MAXN], ed[MAXN];   int cnt[MAXN];   bool flag = 1;   struct node {     int i;     bool operator<(const node &t) const { return r[i] < r[t.i]; }   };   int work() {     scanf( %d , &n);     for (int i = (1), I = (2 * n) + 1; i < I; ++i) {       char t[5];       scanf( %s , t);       if (t[0] ==  + ) continue;       scanf( %d , &a[i]);     }     for (int i = (1), I = (2 * n) + 1; i < I; ++i)       if (a[i]) {         while (h && a[i] > a[s[h]]) --h;         l[a[i]] = s[h] + 1, r[a[i]] = i - 1, s[++h] = i;       }     for (int x = (1), I = (n) + 1; x < I; ++x)       st[l[x]].push_back(x), ed[r[x]].push_back(x), flag &= (r[x] >= l[x]);     set<node> s;     for (int i = (1), I = (2 * n) + 1; i < I; ++i) {       for (auto x : st[i]) s.insert({x});       if (!a[i]) {         if (s.empty())           flag = 0;         else           b[i] = s.begin()->i, s.erase(s.begin());       }       for (auto x : ed[i])         if (s.find({x}) != s.end()) flag = 0;     }     for (int i = (1), I = (2 * n) + 1; i < I; ++i)       if (b[i]) cnt[b[i]]++;     for (int i = (1), I = (n) + 1; i < I; ++i) flag &= (cnt[i] == 1);     if (!flag) return puts( NO );     puts( YES );     for (int i = (1), I = (2 * n) + 1; i < I; ++i)       if (b[i]) printf( %d  , b[i]);     return 0;   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long double PI = acos(-1);   const long double E = 2.71828183;   const int MOD = 1e9 + 7;   vector<int> bfs(vector<vector<int> > adj, int src) {     queue<int> q;     q.push(src);     vector<int> dst(adj.size(), INF);     dst[src] = 0;     while (!q.empty()) {       int c = q.front();       q.pop();       for (int nbr : adj[c]) {         if (dst[nbr] == INF) {           dst[nbr] = dst[c] + 1;           q.push(nbr);         }       }     }     return dst;   }   vector<int> bfsParents(vector<vector<int> > adj, int src) {     vector<int> parents = vector<int>(adj.size(), INF);     parents[src] = -1;     queue<int> q;     q.push(src);     vector<int> dst(adj.size(), INF);     dst[src] = 0;     while (!q.empty()) {       int c = q.front();       q.pop();       for (int nbr : adj[c]) {         if (dst[nbr] == INF) {           parents[nbr] = c;           dst[nbr] = dst[c] + 1;           q.push(nbr);         }       }     }     return parents;   }   list<int> shortestPath(vector<vector<int> > adj, int src, int dst) {     vector<int> bfsParetns = bfsParents(adj, src);     list<int> ans;     ans.push_back(dst);     while (ans.front() != src) ans.push_front(bfsParetns[ans.front()]);     return ans;   }   long long powMod(long long base, long long exp, long long mod) {     long long ans = 1;     for (long long i = 0; i < exp; i++) ans = ((ans % mod) * (base % mod)) % mod;     return ans;   }   vector<int> divisorsOf(int n) {     vector<int> ans;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) ans.push_back(i);       if (i * i != n && i != 1) ans.push_back(n / i);     }     return ans;   }   long long gcd(long long a, long long b) {     return (a % b == 0 ? b : gcd(b, a % b));   }   long double log(long double a, long double b) { return log(b) / log(a); }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long power(long long base, long long exp) {     long long res = 1;     while (exp) {       exp--;       res *= base;     }     return res;   }   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) solve();     return 0;   }   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     vector<char> v(k);     for (int i = 0; i < k; i++) cin >> v[i];     long long curr = 0;     long long ans = 0;     for (int i = 0; i < n; i++) {       bool in = false;       for (char c : v)         if (c == s[i]) in = true;       if (in) curr++;       if (!in || (in && i == n - 1)) {         ans += curr * (curr + 1) / 2;         curr = 0;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, sum, high, w, low;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout << setprecision(10) << fixed;     cin >> n >> w;     for (int i = 1; i <= n; i++) {       cin >> a;       sum += a;       if (sum > high) {         high = sum;       }       if (sum < low) {         low = sum;       }     }     cout << max(w - high + 1 + low, 0) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   const double INF = 1e18;   int n, m, c;   int a[N], p[N], f[N];   double E[N];   struct Node {     double L, M, R, S;     Node() {}     Node(double L, double M, double R, double S) : L(L), M(M), R(R), S(S) {}   };   struct SegmentTree {     Node st[4 * N];     Node Merge(Node A, Node B) {       Node C;       C.L = max(A.L, A.S + B.L);       C.R = max(B.R, B.S + A.R);       C.M = max(A.M, max(B.M, A.R + B.L));       C.S = A.S + B.S;       return C;     }     void Init(int k, int l, int r) {       if (l == r) {         double val = E[l];         st[k] = Node(val, val, val, val);         return;       }       Init(k << 1, l, ((l + r) >> 1));       Init(k << 1 | 1, ((l + r) >> 1) + 1, r);       st[k] = Merge(st[k << 1], st[k << 1 | 1]);     }     Node Query(int k, int l, int r, int i, int j) {       if (l > j || r < i) return Node(-INF, -INF, -INF, 0);       if (i <= l && r <= j) return st[k];       return Merge(Query(k << 1, l, ((l + r) >> 1), i, j),                    Query(k << 1 | 1, ((l + r) >> 1) + 1, r, i, j));     }   } ST;   double Query(int l, int r) {     Node ans = ST.Query(1, 1, n - 1, l, r);     return max(ans.L, max(ans.R, ans.M));   }   int main() {     cin >> n >> m >> c;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i < n; ++i) cin >> p[i];     for (int i = 1; i < n; ++i) {       double prob = (double)p[i] / 100;       double val = (double)(a[i + 1] - a[i]) / 2 - prob * c;       E[i] = val;     }     ST.Init(1, 1, n - 1);     double ans = 0;     while (m--) {       int u, v;       cin >> u >> v;       ans += max(0.00, Query(u, v - 1));     }     cout << fixed << setprecision(10) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int memo[500][26][26];   int son[500][26][26];   int cambios[500][26][26];   vector<string> A;   int m, n;   void solve(int x, int y, int z) {     for (int row = 0; row < x; row++)       for (int a = 0; a < y; a++)         for (int b = 0; b < z; b++) {           int &res = memo[row][a][b];           if (row == 0) {             res = cambios[0][a][b];             continue;           }           int mn = 1 << 29;           for (int i = 0; i < 26; i++)             if (i != a)               for (int j = 0; j < 26; j++)                 if (j != b) {                   int tmp = memo[row - 1][i][j] + cambios[row][a][b];                   if (mn > tmp) mn = tmp, son[row][a][b] = 1000 * i + j;                 }           res = mn;         }   }   int main() {     while (cin >> m >> n) {       memset(memo, -1, sizeof(memo));       A.clear();       string cad;       for (int i = 0; i < m; i++) cin >> cad, A.push_back(cad);       reverse((A).begin(), (A).end());       for (int row = 0; row < m; row++) {         for (int a = 0; a < 26; a++)           for (int b = 0; b < 26; b++)             if (b != a) {               int s = 0;               for (int k = 0; k < n; k++) {                 if ((k & 1) == 0 && A[row][k] -  a  != a) s++;                 if ((k & 1) == 1 && A[row][k] -  a  != b) s++;               }               cambios[row][a][b] = s;             } else               cambios[row][a][b] = 1 << 29;       }       solve(m, 26, 26);       int mn = 1 << 29;       int a, b;       for (int i = 0; i < 26; i++)         for (int j = 0; j < 26; j++)           if (j != i) {             if (mn > memo[m - 1][i][j]) mn = memo[m - 1][i][j], a = i, b = j;           }       printf( %d n , mn);       for (int row = m - 1; row >= 0; row--) {         for (int i = 0; i < n; i++) {           if ((i & 1) == 0)             cout << char(a +  a );           else             cout << char(b +  a );         }         cout << endl;         int tmp = son[row][a][b];         a = tmp / 1000;         b = tmp % 1000;       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int to, next;   } e[200005 * 2];   int d[200005], dl[200005], dr[200005], dd[200005];   int head[200005], q[200005], id[200005], a[200005];   long long ans;   int n, tot;   bool cmp(int x, int y) {     if (dd[x] != dd[y]) return dd[x] > dd[y];     return dl[x] > dl[y];   }   void add(int x, int y) {     e[++tot] = (edge){y, head[x]};     head[x] = tot;   }   void bfs(int S, int *d) {     for (int i = 1; i <= n; i++) d[i] = -1;     d[S] = 0;     q[1] = S;     for (int h = 0, t = 1; h != t;)       for (int x = q[++h], i = head[x]; i; i = e[i].next)         if (d[e[i].to] == -1) d[e[i].to] = d[x] + a[e[i].to], q[++t] = e[i].to;   }   int findmax(int *d) {     int mx = 1;     for (int i = 2; i <= n; i++)       if (d[mx] < d[i]) mx = i;     return mx;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     for (int i = 1; i <= n; i++) a[i] = 1;     bfs(1, d);     int l = findmax(d);     bfs(l, dl);     int r = findmax(dl);     bfs(r, dr);     for (int i = 1; i <= n; i++)       if (dl[i] + dr[i] == dl[r])         a[i] = 0;       else         ans += max(dl[i], dr[i]);     ans += 1ll * dl[r] * (dl[r] + 1) / 2;     printf( %I64d n , ans);     bfs(l, dd);     for (int i = 1; i <= n; i++) id[i] = i;     sort(id + 1, id + n + 1, cmp);     for (int i = 1; i < n; i++)       if (dd[id[i]]) {         int tmp = dl[id[i]] > dr[id[i]] ? l : r;         printf( %d %d %d n , tmp, id[i], id[i]);       } else         printf( %d %d %d n , l, id[i], id[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010, INF = 0x3f3f3f3f;   template <typename Tp>   inline int getmin(Tp &x, Tp y) {     return y < x ? x = y, 1 : 0;   }   template <typename Tp>   inline int getmax(Tp &x, Tp y) {     return y > x ? x = y, 1 : 0;   }   template <typename Tp>   inline void read(Tp &x) {     x = 0;     int f = 0;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) f = 1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     if (f) x = -x;   }   struct data {     int v, nxt;   } edge[maxn << 1];   int n, p, k, tot, head[maxn], w[maxn], mark[maxn];   long long mx = -INF, f[maxn];   void insert(int u, int v) {     edge[++p] = (data){v, head[u]};     head[u] = p;     edge[++p] = (data){u, head[v]};     head[v] = p;   }   void input() {     int u, v;     read(n);     for (int i = 1; i <= n; i++) read(w[i]);     for (int i = 1; i < n; i++) {       read(u);       read(v);       insert(u, v);     }   }   void dp(int x, int pre) {     f[x] = w[x];     for (int i = head[x]; i; i = edge[i].nxt)       if (edge[i].v ^ pre) {         dp(edge[i].v, x);         if (f[edge[i].v] > 0) f[x] += f[edge[i].v], mark[edge[i].v] = 1;       }     getmax(mx, f[x]);   }   void getans(int x, int pre) {     f[x] = w[x];     for (int i = head[x]; i; i = edge[i].nxt)       if (edge[i].v ^ pre) {         getans(edge[i].v, x);         if (f[edge[i].v] > 0) f[x] += f[edge[i].v], mark[edge[i].v] = 1;       }     if (f[x] == mx) ++k, f[x] = 0;   }   int main() {     input();     dp(1, 1);     getans(1, 1);     printf( %lld %d n , mx * k, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int maxn = 100000 + 5;   const long double eps = 1e-6;   long double PI = acos((long double)(-1));   long long n, m, par[maxn][20], cnt[maxn], st[maxn], fi[maxn], ti;   long long h[maxn];   long double qd[maxn], qu[maxn];   vector<int> e[maxn];   void dfs(int u, int p = -1) {     st[u] = ti++;     h[u] = ~p ? h[p] + 1 : 0;     par[u][0] = p;     bool leaf = 1;     for (int i = 1; i < 20; i++) {       if (~par[u][i - 1]) par[u][i] = par[par[u][i - 1]][i - 1];     }     int sz = e[u].size();     for (int i = 0; i < sz; i++) {       int v = e[u][i];       if (v != p) {         leaf = 0;         dfs(v, u);         cnt[u] += cnt[v] + 1;       }     }     for (int i = 0; i < sz; i++) {       int v = e[u][i];       if (v != p) qd[u] += 1.0 * cnt[v] / cnt[u] * qd[v];     }     if (~leaf) qd[u] += 1;     fi[u] = ti++;   }   void dfs_d(int u, int p = -1) {     if (~p) {       long double cntd = cnt[p] - cnt[u] - 1, nou, kcntd, kasr;       if (cntd == 0) {         kcntd = 1.0 / (n - cnt[u] - 1);         qu[u] = qu[p] * kcntd * (n - cnt[p] - 1) + (n - cnt[p]) * kcntd;       } else {         kcntd = 1.0 / cntd;         nou = qd[p] * kcntd * cnt[p] - qd[u] * kcntd * cnt[u] - cnt[u] * kcntd -               kcntd;         kasr = 1.0 / (n - cnt[u] - 1);         qu[u] = cntd * kasr * nou + qu[p] * kasr * (n - cnt[p] - 1) + 1;       }     }     int sz = e[u].size();     for (int i = 0; i < sz; i++) {       int v = e[u][i];       if (v != p) dfs_d(v, u);     }   }   int ispar(int u, int v) { return st[u] <= st[v] && fi[v] <= fi[u]; }   int up(int u, int d) {     for (int i = 20 - 1; i >= 0; i--)       if ((d >> i) & 1) u = par[u][i];     return u;   }   int lca(int u, int v) {     if (h[u] < h[v]) swap(u, v);     u = up(u, h[u] - h[v]);     if (u == v) return v;     for (int i = 20 - 1; i >= 0; i--) {       if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];     }     return par[u][0];   }   long double query(int u, int v) {     if (h[u] > h[v]) swap(u, v);     if (ispar(u, v)) {       int w = up(v, h[v] - h[u] - 1);       long double cn = 1.0 / (cnt[v] + 1) / (n - cnt[w] - 1);       long double ans = cnt[v] * (n - cnt[w] - 1) * cn * qd[v] +                         (n - cnt[w] - 1) * (cnt[v] + 1) * cn * qu[w];       return ans + h[v] - h[u];     }     int w = lca(u, v);     long double cn = 1.0 / (cnt[u] + 1) / (cnt[v] + 1);     long double ans =         cnt[u] * (cnt[v] + 1) * cn * qd[u] + cnt[v] * (cnt[u] + 1) * cn * qd[v];     return h[u] - h[w] + h[v] - h[w] + ans + 1;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin >> n >> m;     int u, v;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       u--;       v--;       e[u].push_back(v);       e[v].push_back(u);     }     dfs(0);     dfs_d(0);     cout << fixed << setprecision(8);     while (m--) {       cin >> u >> v;       cout << query(--u, --v) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)(1e5) + 5;   int l[maxn], r[maxn];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> l[i] >> r[i];     sort(l + 1, l + n + 1);     sort(r + 1, r + n + 1);     long long ret = n;     for (int i = 1; i <= n; ++i) ret += max(l[i], r[i]);     cout << ret << endl;     return 0;   }