malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, l[100005], r[100005];   signed main() {     scanf( %lld , &n);     long long ans = 0;     for (register long long i = 1; i <= n; i++) {       scanf( %lld%lld , &l[i], &r[i]);     }     sort(l + 1, l + n + 1);     sort(r + 1, r + n + 1);     for (register long long i = 1; i <= n; i++) {       ans += max(l[i], r[i]);     }     ans += n;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 9;   int n, nxt[MAX], a[MAX];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 0;     for (int l = 0; l < n; l++) {       for (int i = n - 2, j = n - 1; i >= 0; i--) {         while (i < j - a[j]) j--;         nxt[i] = j;       }       for (int i = 0; i < n - 1; i = nxt[i]) ans++;       rotate(a, a + n - 1, a + n);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long sqr(long long x) { return (long long)(x * x); }   long long my_abs(long long x) {     if (x < 0) return -x;     return x;   }   const int MN = 1000 * 1000 * 10;   int main() {     long long ans = 0;     long long n, m;     cin >> n >> m;     for (long long b = 1; b <= n; b++) {       long long mx_c = min(b * b, m);       long long tmp_ans = 2ll * (long long)(mx_c);       long long up = (long long)sqrt(sqr(b) - 1.0);       long long down = (long long)ceil(sqrt((double)(sqr(b) - (long long)mx_c)));       if (down > up) {         ans += tmp_ans;         continue;       }       tmp_ans -= 2ll * (up - down + 1ll);       ans += tmp_ans;     }     for (int x = -MN; x <= -1; x++) {       int tmp1, tmp2;       if (abs(x) % 2 == 0) {         tmp1 = abs(x - 2) / 2;         tmp2 = abs(x * 2);       } else {         tmp1 = abs(x - 1) / 2;         tmp2 = abs(x);       }       if (tmp1 <= n && tmp2 <= m) ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int MOD = 1e6 + 3;   int main() {     int n, m;     scanf( %d%d , &n, &m);     char s[n][m + 1];     for (int i = (0); i < (int)(n); i++) scanf( %s , s[i]);     bool c[m][2];     bool r[n][2];     memset(c, 0, sizeof(c)), memset(r, 0, sizeof(r));     for (int i = (0); i < (int)(n); i++) {       for (int j = (0); j < (int)(m); j++) {         if (isdigit(s[i][j])) {           int first = s[i][j] -  1 ;           int R = (first / 2 + j) % 2;           int C = ((first + 1) % 4 / 2 + i) % 2;           r[i][R] = 1;           c[j][C] = 1;         }       }     }     int ans = 1;     for (int i = (0); i < (int)(m); i++) {       if (c[i][0] && c[i][1])         ans = 0;       else if (!c[i][0] && !c[i][1])         ans = ans * 2 % MOD;     }     for (int i = (0); i < (int)(n); i++) {       if (r[i][0] && r[i][1])         ans = 0;       else if (!r[i][0] && !r[i][1])         ans = ans * 2 % MOD;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 9;   struct node {     long long x, y, sum;   } st[1200005];   int n, q, type, L, R, a[300005];   long long f[300005];   void build(int id, int l, int r) {     if (l == r) {       st[id].sum = a[l];       return;     }     int mid = l + r >> 1;     build(id << 1, l, mid);     build(id << 1 | 1, mid + 1, r);     st[id].sum = (st[id << 1].sum + st[id << 1 | 1].sum) % mod;   }   void push(int id, int l, int r) {     if (st[id].x == 0 && st[id].y == 0) return;     int mid = l + r >> 1, pos = mid - l + 2;     long long x = st[id].x, y = st[id].y;     st[id << 1].x = (st[id << 1].x + x) % mod;     st[id << 1].y = (st[id << 1].y + y) % mod;     st[id << 1].sum =         (st[id << 1].sum + x * f[mid - l + 1] + y * (f[mid - l + 2] - 1)) % mod;     st[id << 1 | 1].x =         (st[id << 1 | 1].x + x * f[pos - 2] + y * f[pos - 1]) % mod;     st[id << 1 | 1].y = (st[id << 1 | 1].y + x * f[pos - 1] + y * f[pos]) % mod;     st[id << 1 | 1].sum =         (st[id << 1 | 1].sum + x * f[r - l + 1] + y * (f[r - l + 2] - 1) -          x * f[mid - l + 1] - y * (f[mid - l + 2] - 1) + mod) %         mod;     st[id].x = st[id].y = 0;   }   void update(int id, int l, int r, int u, int v) {     if (l > v or r < u) return;     if (u <= l && r <= v) {       st[id].x = (st[id].x + f[l - u + 1]) % mod;       st[id].y = (st[id].y + f[l - u + 2]) % mod;       st[id].sum = (st[id].sum + f[l - u + 1] * f[r - l + 1] % mod +                     f[l - u + 2] * (f[r - l + 2] - 1)) %                    mod;       return;     }     push(id, l, r);     int mid = l + r >> 1;     update(id << 1, l, mid, u, v);     update(id << 1 | 1, mid + 1, r, u, v);     st[id].sum = (st[id << 1].sum + st[id << 1 | 1].sum) % mod;   }   long long query(int id, int l, int r, int u, int v) {     if (l > v or r < u) return 0;     if (u <= l && r <= v) return st[id].sum;     push(id, l, r);     int mid = l + r >> 1;     return (query(id << 1, l, mid, u, v) + query(id << 1 | 1, mid + 1, r, u, v)) %            mod;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     f[1] = 1;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (i > 1) f[i] = (f[i - 1] + f[i - 2]) % mod;     }     f[n + 1] = (f[n] + f[n - 1]) % mod;     build(1, 1, n);     while (q--) {       cin >> type >> L >> R;       if (type == 1)         update(1, 1, n, L, R);       else         cout << (query(1, 1, n, L, R) + mod) % mod << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   string makeCentered(int len) {     string output;     for (int i = 0; i < 27; i++) {       output.push_back( . );     }     for (int i = 0; i < len; i++) {       output[13 + i] =  X ;       output[13 - i] =  X ;     }     return output;   }   string blank() {     string output;     for (int i = 0; i < 27; i++) {       output.push_back( . );     }     return output;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string input;     cin >> input;     vector<int> target;     for (int i = 0; i < input.size(); i++) {       target.push_back(int(input[i]));     }     vector<string> output;     int val = 0;     for (int i = 0; i < target.size(); i++) {       int curTarget = target[i];       vector<int> triSizes;       int distance = curTarget - val;       if (i != 0) distance = val - curTarget;       while (distance < 0) distance += 256;       while (distance > 0) {         if (i == 0) {           for (int j = 12; j >= (i == 0 ? 1 : 2); j--) {             int next;             if (i != 0)               next = j * j - 1;             else               next = j * j;             if (next <= distance) {               for (int k = 1; k <= j + 1; k++) {                 cout << makeCentered(k) << endl;               }               distance -= next;               val += next;               val %= 256;               cout << blank() << endl;               break;             }           }         } else {           cout << makeCentered(1) << endl;           cout << blank() << endl;           distance -= 1;           val -= 1;           if (val < 0) val += 256;         }       }       cout << blank() << endl;       string curString = blank();       curString[0] =  X ;       curString[curString.size() - 1] =  X ;       cout << curString << endl;       curString[curString.size() - 1] =  . ;       cout << curString << endl;       cout << blank() << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int INF = 0x3f3f3f3f;   int n, lm, rm;   int q[N], fa[N], sz[N];   bool use[N];   vector<pair<int, int> > g[N];   int getc(int u) {     int qn = 0;     fa[q[qn++] = u] = u;     for (int i = 0; i < qn; i++) {       u = q[i];       sz[u] = 1;       for (int j = 0; j < g[u].size(); j++) {         int v = g[u][j].first;         if (use[v] || v == fa[u]) continue;         fa[q[qn++] = v] = u;       }     }     for (int i = qn - 1; i >= 0; i--) {       int u = q[i];       if (sz[u] * 2 > qn) return u;       sz[fa[u]] += sz[u];     }   }   int dep[N];   void dfs(int u, int p) {     dep[u] = 1;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i].first;       if (v == p || use[v]) continue;       dfs(v, u);       dep[u] = max(dep[u], dep[v] + 1);     }   }   bool cmp(pair<int, int> a, pair<int, int> b) {     return dep[a.first] < dep[b.first];   }   int Maxc;   pair<int, int> f[N], ff[N];   int Q[N];   void dfs(int u, int p, int d, int val, int mid) {     f[d] = max(f[d], make_pair(val, u));     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i].first;       int w = g[u][i].second;       if (v == p || use[v]) continue;       dfs(v, u, d + 1, val + (w >= mid ? 1 : -1), mid);     }   }   pair<int, int> tmp;   bool judge(int u, int mid) {     int pre = 0;     for (int i = 0; i <= dep[u]; i++) ff[i] = make_pair(-INF, 0);     ff[0] = make_pair(0, u);     int ed = 0;     for (int ii = 0; ii < g[u].size(); ii++) {       int v = g[u][ii].first;       int w = g[u][ii].second;       if (use[v]) continue;       for (int i = 0; i <= dep[v]; i++) f[i] = make_pair(-INF, 0);       dfs(v, u, 1, w >= mid ? 1 : -1, mid);       int head = 0, rear = 0;       for (int i = 0; i <= dep[v]; i++) {         while (ed >= 0 && i + ed >= lm) {           while (head < rear && ff[Q[rear - 1]] < ff[ed]) rear--;           Q[rear++] = ed--;         }         while (head < rear && Q[head] + i > rm) head++;         if (head < rear && ff[Q[head]].first + f[i].first >= 0) {           tmp = make_pair(ff[Q[head]].second, f[i].second);           return true;         }       }       for (int i = 0; i <= dep[v]; i++) ff[i] = max(f[i], ff[i]);       ed = dep[v];     }     return false;   }   int ans = -1;   pair<int, int> an;   void cal(int u) {     dfs(u, u);     sort(g[u].begin(), g[u].end(), cmp);     int l = ans, r = Maxc;     while (l < r) {       int mid = (l + r) >> 1;       if (judge(u, mid))         l = mid + 1;       else         r = mid;     }     judge(u, l - 1);     if (ans < l - 1) {       ans = l - 1;       an = tmp;     }   }   void go(int c) {     int rt = getc(c);     use[rt] = true;     cal(rt);     for (int i = 0; i < g[rt].size(); i++) {       int v = g[rt][i].first;       if (use[v]) continue;       go(v);     }   }   int main() {     scanf( %d%d%d , &n, &lm, &rm);     int u, v, w;     for (int i = 1; i <= n - 1; i++) {       scanf( %d%d%d , &u, &v, &w);       Maxc = max(Maxc, w + 1);       g[u].push_back(make_pair(v, w));       g[v].push_back(make_pair(u, w));     }     go(1);     printf( %d %d n , an.first, an.second);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, m;     double resn, resm;     scanf( %d%d , &n, &m);     resn = m / (double)n;     resm = log(m) / log(n);     if (resn > resm) {       printf( > n );     } else if (resn < resm) {       printf( < n );     } else       printf( = n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     vector<int> a(n + 1);     for (int i = 1; i <= n; i++) {       a[i] = a[i - 1] + arr[i - 1];     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       l--;       cout << (a[r] - a[l]) / 10 << endl;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 700 + 7;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   int a[maxn];   int g[maxn][maxn];   int n;   struct as {     int l, r, v;     bool operator<(const as& b) const {       if (l < b.l) return true;       if (l > b.l) return false;       if (r < b.r) return true;       if (r > b.r) return false;       return v < b.v;     }   };   map<as, bool> mp;   int gcd(int x, int y) { return x == 0 ? y : gcd(y % x, x); }   void get() {     int i, j;     for (i = 0; i <= n; i++) {       for (j = 0; j <= n; j++) {         if (i != j && gcd(a[i], a[j]) != 1) {           g[i][j] = 1;         }       }     }     return;   }   bool solve(int l, int r, int pos) {     if (l > r) return true;     if (mp.count(as{l, r, pos})) {       return mp[as{l, r, pos}];     }     int i, j;     for (i = l; i <= r; i++) {       if (g[pos][i]) {         if (solve(l, i - 1, i) && solve(i + 1, r, i)) {           mp[as{l, r, pos}] = true;           return true;         }       }     }     mp[as{l, r, pos}] = false;     return false;   }   int main() {     int i, j, m, t, z;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     get();     if (solve(1, n, 0)) {       puts( Yes );     } else       puts( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000005], b[1000005];   int main() {     int n, ans = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       a[x]++;     }     for (int i = 1000000; i >= 1; i--) {       if (!a[i]) continue;       b[i] = 1;       for (int j = 2 * i; j <= 1000000; j += i) {         if (a[j] && b[i] < b[j] + 1) b[i] = b[j] + 1;       }       if (ans < b[i]) ans = b[i];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, vx, vy;   int refx, refy;   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return a;     }     long long res = exgcd(b, a % b, y, x);     y -= (a / b) * x;     return res;   }   int main() {     scanf( %d%d%d%d%d%d , &n, &m, &x, &y, &vx, &vy);     if (vx == 0) {       if (x == 0 || x == n) {         if (vy == 1)           printf( %d %d n , x, m);         else           printf( %d %d n , x, 0);       } else         puts( -1 );       return 0;     }     if (vy == 0) {       if (y == 0 || y == m) {         if (vx == 1)           printf( %d %d n , n, y);         else           printf( %d %d n , 0, y);       } else         puts( -1 );       return 0;     }     if (vx == -1) refx = 1, x = n - x;     if (vy == -1) refy = 1, y = m - y;     long long a, b, g;     g = exgcd(n, m, a, b);     if ((x - y) % g != 0) {       puts( -1 );       return 0;     }     long long t = (x - y) / g;     a *= t, b *= t;     int _m = m / g, _n = n / g;     long long _a = (a % _m + _m + _m - 1) % _m + 1, _b = -((x - y) - _a * n) / m;     long long ansx = n, ansy = m;     if (_a % 2 == 0) ansx = n - ansx;     if (_b % 2 == 0) ansy = m - ansy;     if (refx) ansx = n - ansx;     if (refy) ansy = m - ansy;     printf( %I64d %I64d , ansx, ansy);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 998244353;   const int sz = 1e5 + 3, inf = 1e9 + 10;   int a[sz], match[sz], c[sz];   int fr[sz];   bool vis[sz];   long long int x[sz];   void solve() {     memset(vis, 1, sizeof vis);     memset(match, 0, sizeof match);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int k;       cin >> k;       for (int j = 0; j < k; j++) cin >> a[j];       for (int j = 0; j < k; j++) {         if (vis[a[j]]) {           vis[a[j]] = 0;           match[i] = a[j];           break;         }       }     }     bool f = 0;     for (int i = 1; i <= n; i++) {       if (match[i]) continue;       for (int j = 1; j <= n; j++) {         if (vis[j]) {           cout <<  IMPROVE n ;           cout << i <<     << j <<   n ;           f = 1;           break;         }       }       if (f) break;     }     if (!f) cout <<  OPTIMAL n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 123;   long long a[maxn], b[maxn], n, m;   char s[maxn];   long long vis[20], t[20], sb[maxn];   void dfs(long long stp, long long sa) {     if (sa > sb[stp + 1]) return;     if (stp == 0) {       cout << sa << endl;       exit(0);     }     if (stp > n) {       dfs(stp - 1, sa);       return;     }     for (long long i = 9; i >= 0; i--)       if (vis[i] && sa * 10 + i <= sb[stp]) {         --vis[i];         dfs(stp - 1, sa * 10 + i);         ++vis[i];       }   }   int main() {     long long i;     scanf( %s , s + 1);     n = strlen(s + 1);     for (i = 1; i <= n; i++) a[i] = s[n - i + 1] -  0 ;     scanf( %s , s + 1);     m = strlen(s + 1);     for (i = 1; i <= m; i++) b[i] = s[m - i + 1] -  0 ;     for (i = m; i; i--) sb[i] = sb[i + 1] * 10 + b[i];     for (i = 1; i <= n; i++) ++vis[a[i]];     dfs(m, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, l[N], r[N], id[N];   bool cmp(int x, int y) { return r[x] == r[y] ? l[x] < l[y] : r[x] < r[y]; }   int main() {     cin >> n;     for (int x, w, i = 1; i <= n; ++i) {       cin >> x >> w;       l[i] = x - w, r[i] = x + w, id[i] = i;     }     sort(id + 1, id + n + 1, cmp);     int ans = 0, las = -2e9;     for (int i = 1; i <= n; ++i)       if (las <= l[id[i]]) ++ans, las = r[id[i]];     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 110, VMAX = 1000100;   int T, N;   int number[NMAX], diff[NMAX * NMAX];   int b[NMAX];   bool val[VMAX];   int main() {     int i, j, k, t;     bool flag;     scanf( %d , &T);     for (t = 0; t < T; t += 1) {       memset(val, 0, sizeof(val));       memset(diff, 0, sizeof(diff));       flag = true;       scanf( %d , &N);       for (i = 1; i <= N; i += 1) {         scanf( %d , &number[i]);         if (val[number[i]]) flag = false;         val[number[i]] = true;       }       sort(number + 1, number + N + 1);       if (!flag)         printf( NO n );       else if (N == 1)         printf( YES n1 n );       else {         for (i = 1; i <= N; i += 1) {           for (j = i + 1; j <= N; j += 1) diff[++diff[0]] = number[j] - number[i];         }         memset(val, 0, sizeof(val));         sort(diff + 1, diff + diff[0] + 1);         diff[0] = unique(diff + 1, diff + diff[0] + 1) - diff - 1;         printf( YES n );         for (i = 1; i <= N; i += 1) {           for (j = b[i - 1] + 1; val[j]; j += 1)             ;           b[i] = j;           printf( %d%c , b[i],    n [i == N ? 1 : 0]);           for (k = 1; k <= diff[0]; k += 1) val[diff[k] + b[i]] = true;         }       }     }     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long bin_pow(long long a, long long b) {     if (b == 0) {       return 1;     }     long long res = bin_pow(a, b / 2);     res *= res;     res %= mod;     if (b % 2) {       res *= a;       res %= mod;     }     return res;   }   long long inv(long long x) { return bin_pow(x, mod - 2); }   int32_t main() {     ios_base::sync_with_stdio(0);     long long n;     cin >> n;     n *= 2;     vector<long long> a(n);     for (long long i = 0; i < (long long)(n); i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     long long ans = 0;     n /= 2;     for (long long i = 0; i < (long long)(n); i++) {       ans -= a[i];     }     for (long long i = 0; i < (long long)(n); i++) {       ans += a[i + n];     }     ans %= mod;     for (long long i = 0; i < (long long)(n); i++) {       ans *= n + 1 + i;       ans %= mod;     }     for (long long i = 0; i < (long long)(n); i++) {       ans *= inv(i + 1);       ans %= mod;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   int main(int argc, char const *argv[]) {     int n, i;     scanf( %d , &n);     getchar();     char row[n];     for (i = 0; i < n; ++i) {       row[i] = getchar();     }     if (n == 1 && row[0] ==  0 ) {       printf( No n );       return 0;     }     for (i = 1; i < n; ++i) {       if (row[i] ==  1  && row[i - 1] ==  1 ) {         printf( No n );         return 0;       }     }     int cantCero = 0;     if (row[0] ==  0 ) {       cantCero++;     }     for (i = 1; i < n; ++i) {       if (row[i] ==  0 ) {         if (row[i - 1] ==  0 ) {           cantCero++;         } else {           cantCero = 1;         }         if (cantCero == 2 && (i == 1 || i == n - 1)) {           printf( No n );           return 0;         }         if (cantCero == 3) {           printf( No n );           return 0;         }       } else {         cantCero = 0;       }     }     printf( Yes n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   template <typename T1, typename T2>   inline void chkmin(T1& x, const T2& y) {     if (y < x) x = y;   }   template <typename T1, typename T2>   inline void chkmax(T1& x, const T2& y) {     if (x < y) x = y;   }   const int N = 1e5 + 10;   const int B = 300;   struct Node {     int next_node;     int prev_node;     int jump;   };   int n, q;   Node nodes[N];   bool used[N];   int find_jump(int v) {     for (int i = 0; i < B; ++i) {       v = nodes[v].next_node;     }     return v;   }   void build() {     for (int i = 0; i < n; ++i) {       if (used[i]) continue;       int v = i;       int jump = find_jump(i);       while (!used[v]) {         used[v] = true;         nodes[v].jump = jump;         v = nodes[v].next_node;         jump = nodes[jump].next_node;       }     }   }   void relax_jumps(int v) {     int jump = v;     for (int i = 0; i < B; ++i) {       v = nodes[v].prev_node;     }     for (int i = 0; i <= B; ++i) {       nodes[v].jump = jump;       v = nodes[v].next_node;       jump = nodes[jump].next_node;     }   }   void upd(int i, int j) {     int next_i = nodes[i].next_node;     int next_j = nodes[j].next_node;     nodes[i].next_node = next_j;     nodes[j].next_node = next_i;     nodes[next_i].prev_node = j;     nodes[next_j].prev_node = i;     relax_jumps(i);     relax_jumps(j);   }   int getAns(int v, int k) {     while (k) {       if (k >= B) {         v = nodes[v].jump;         k -= B;       } else {         v = nodes[v].next_node;         --k;       }     }     return v;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cout.precision(20), cout.setf(ios::fixed);     cin >> n >> q;     for (int i = 0; i < n; ++i) {       cin >> nodes[i].next_node;       --nodes[i].next_node;       nodes[nodes[i].next_node].prev_node = i;     }     build();     while (q--) {       int t;       cin >> t;       if (t == 1) {         int i, j;         cin >> i >> j;         --i;         --j;         upd(i, j);       } else if (t == 2) {         int v, k;         cin >> v >> k;         --v;         cout << getAns(v, k) + 1 <<   n ;       } else {         assert(false);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100 + 10;   pair<int, int> d[MAX];   int main() {     int i;     set<int> first, second;     for ((i) = (1); (i) <= (8); ++(i)) {       scanf( %d%d , &d[i].first, &d[i].second);       first.insert(d[i].first);       second.insert(d[i].second);     }     if (first.size() != 3 || second.size() != 3) {       cout <<  ugly  << endl;       return 0;     }     set<int>::iterator a, b;     for ((a) = (first.begin()); (a) != (first.end()); ++(a))       for ((b) = (second.begin()); (b) != (second.end()); ++(b)) {         int flag = 0;         for ((i) = (1); (i) <= (8); ++(i))           if (d[i].first == *a && d[i].second == *b) {             flag = 1;             break;           }         if (a == ++first.begin() && b == ++second.begin()) {           if (flag) {             cout <<  ugly  << endl;             return 0;           }         } else if (!flag) {           cout <<  ugly  << endl;           return 0;         }       }     cout <<  respectable  << endl;     return 0;   }