malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int dx[4] = {-1, 0, 1, 0};   int dy[4] = {0, -1, 0, 1};   int n;   int map[2010][2010];   int vis[2010][2010];   int as, ac;   int go(int x, int y) {     vis[y][x] = 1;     int r = 1;     for (int i = 0; i < 4; ++i) {       int nx = x + dx[i], ny = y + dy[i];       if (map[ny][nx] == 0 || vis[ny][nx] == 1) continue;       r += go(nx, ny);     }     return r;   }   int chk(int x, int y, int r) {     int ok = 1;     for (int i = y; i < y + r && ok == 1; ++i)       for (int j = x; j < x + r && ok == 1; ++j)         if (map[i][j] != 1) ok = 0;     return ok == 1;   }   int main(void) {     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) scanf( %d , &map[i][j]);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (map[i][j] == 0 || vis[i][j] == 1) continue;         int nd = go(j, i);         int r = (int)sqrt(nd);         if (nd != r * r)           ++ac;         else {           if (chk(j, i, r) == 1)             ++as;           else             ++ac;         }       }     }     printf( %d %d n , ac, as);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 6e3 + 5;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   int main() {     int t, n, k;     char x;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n % k; i++) {         cout <<  a ;       }       for (int i = 0; i < k; i++) {         x =  a  + i;         for (int j = 0; j < n / k; j++) {           cout << x;         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, first[200050], nxt[200050], to[200050], tot;   void add(int x, int y) { nxt[++tot] = first[x], first[x] = tot, to[tot] = y; }   double w[200050], ans, sum[200050];   int fa[200050];   void dfs(int u, int f) {     ans += w[f] * (1 - w[u]);     for (int i = first[u]; i; i = nxt[i]) {       int t = to[i];       if (t == f) continue;       fa[t] = u;       sum[u] += (1 - w[t]);       dfs(t, u);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lf , &w[i]);     }     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       x++;       y++;       add(x, y);       add(y, x);     }     w[0] = 1;     dfs(1, 0);     scanf( %d , &m);     while (m--) {       int u;       double v;       scanf( %d%lf , &u, &v);       u++;       ans -= (1 - w[u]) * w[fa[u]];       ans -= w[u] * sum[u];       sum[fa[u]] -= (1 - w[u]);       w[u] = v;       sum[fa[u]] += (1 - w[u]);       ans += w[u] * sum[u];       ans += (1 - w[u]) * w[fa[u]];       printf( %0.5lf n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[200005];   int main() {     memset(x, 0, sizeof(x));     int n = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &x[i]);     }     sort(x, x + n);     double eps = 1e-10, l = 0.0, r = (double)(x[n - 1] - x[0]) / 6.0;     int p1 = 0, p2 = 0;     while (r - l > eps) {       double mid = l + (r - l) / 2.0;       p1 = upper_bound(x, x + n, x[0] + 2 * mid) - x;       if (p1 == n) {         r = mid;         continue;       }       p2 = upper_bound(x, x + n, x[p1] + 2 * mid) - x;       if (p2 == n || (double)(x[n - 1] - x[p2]) <= 2 * mid - eps) {         r = mid;       } else {         l = mid;       }     }     double tmp = x[0] + 2 * l;     int idx = lower_bound(x, x + n, (int)(tmp - 1)) - x;     for (; idx < n; ++idx) {       if (x[idx] > x[0] + (int)(2 * l + 0.1)) {         break;       }     }     printf( %.6lf n , l);     printf( %.6lf %.6lf %.6lf , (double)x[0] + l, (double)x[idx] + l,            (double)x[n - 1] - l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[400006];   vector<int> dis;   int main() {     int i, j, m, n, c, x, l, y, t, bytes;     cin >> n >> bytes;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int total = 1;     for (i = 1; i < n; i++) {       while (i < n && a[i] == a[i - 1]) {         total++;         i++;       }       dis.push_back(total);       total = 1;     }     if (a[n - 1] != a[n - 2]) dis.push_back(1);     bytes *= 8;     int bits = bytes / n;     if (bits > 31) {       cout << 0;       return 0;     }     total = pow(2, bits);     if (total >= dis.size()) {       cout << 0;       return 0;     }     int ans = 0;     int temp = 0;     for (i = 1; i < dis.size(); i++) {       dis[i] += dis[i - 1];     }     ans = dis[total - 1];     for (i = total; i < dis.size(); i++) {       ans = max(ans, dis[i] - dis[i - total]);     }     cout << n - ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 5;   int n, f[N];   struct node {     int t, d, p, id;     bool operator<(const node& other) const { return d < other.d; }   } a[N];   vector<int> g[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d %d %d , &a[i].t, &a[i].d, &a[i].p), a[i].id = i;     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       for (int j = a[i].d - 1; j >= a[i].t; j--) {         if (f[j - a[i].t] + a[i].p > f[j]) {           f[j] = f[j - a[i].t] + a[i].p;           g[j].clear();           g[j] = g[j - a[i].t];           g[j].push_back(a[i].id);         }       }     }     int ans = 0;     for (int i = 1; i <= 2000; i++)       if (f[i] > f[ans]) ans = i;     printf( %d n , f[ans]);     int len = g[ans].size();     printf( %d n , len);     for (int i = 0; i < len; i++) printf( %d  , g[ans][i]);     return 0;   }
#include <bits/stdc++.h>   int a[12] = {0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292};   int main() {     long long n;     scanf( %lld , &n);     printf( %lld n , (n < 12) ? a[n] : 292 + (n - 11) * 49);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const int N = 3e5 + 10;   const long long mod = 1e9 + 7;   const double PI = acos(-1);   inline long long mm(long long x, long long p) {     return x >= p ? x -= p : ((x < 0) ? x += p : x);   }   inline long long ab(long long x) { return x < 0 ? -x : x; }   char s[N];   int main() {     int n, x, y;     long long cnt = 0;     scanf( %d%d%d , &n, &x, &y);     scanf( %s , s);     bool flag = true;     for (int i = 0; i < n; ++i) {       if (s[i] ==  1 )         flag = true;       else {         if (flag) cnt++;         flag = false;       }     }     if (cnt)       printf( %lld n , min(cnt * y, (cnt - 1) * x + y));     else       puts( 0 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long limit = 1e9 + 7;   bool cmp(long long a, long long b) { return a > b; }   long long myceil(long long a, long long b) { return a / b + bool(a % b); }   long long mylog(long long num, long long base) {     long long ans = 0;     while (num) {       ans++;       num /= base;     }     return ans - 1;   }   long long Pow(long long a, long long b) {     long long ans = 1, mul = a;     while (b) {       if (b & 1) ans = (ans * mul) % limit;       mul = (mul * mul) % limit;       b /= 2;     }     return ans;   }   template <typename T>   ostream &operator<<(ostream &os, vector<T> &v) {     int n = v.size();     for (int i = 0; i < n; i++) os << v[i] <<    ;     os << endl;     return os;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     int n = v.size();     for (int i = 0; i < n; i++) is >> v[i];     return is;   }   string lps(string s) {     int n = s.length();     int lps[n];     lps[0] = 0;     int len = 0;     int i = 1;     while (i < n) {       if (s[i] == s[len]) {         len++;         lps[i] = len;         i++;       } else {         if (len != 0) {           len = lps[len - 1];         } else {           lps[i] = 0;           i++;         }       }     }     int res = lps[n - 1];     return s.substr(0, res);   }   vector<int> primes;   long long fact[100005], inv[100005];   ;   void pre() {     fact[0] = 1;     inv[0] = 1;     for (int i = 1; i < 100005; i++) fact[i] = (fact[i - 1] * i) % limit;     for (int i = 1; i < 100005; i++)       inv[i] = (inv[i - 1] * Pow(i, limit - 2)) % limit;   }   long long comb(long long n, long long r) {     long long ans = fact[n];     ans *= inv[n - r];     ans %= limit;     ans *= inv[r];     ans %= limit;     return ans;   }   int main() {     int t = 1;     cin >> t;     for (int test = 1; test < t + 1; test++) {       long long n, k;       cin >> n >> k;       if ((n - (k - 1) * (k - 1)) >= (2 * k - 1) && (n - (k - 1) * (k - 1)) % 2)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   int F[500005][19 + 1], i, j, m, n, p, k, a[500005], nn, G[500005], Log[500005];   int ST[19 + 1][500005];   void get_ST() {     for (i = 1; i <= nn; ++i) ST[0][i] = i;     for (i = 1; i <= 19; ++i)       for (j = 1; j + (1 << i) - 1 <= nn; ++j)         if (G[ST[i - 1][j]] < G[ST[i - 1][j + (1 << (i - 1))]])           ST[i][j] = ST[i - 1][j];         else           ST[i][j] = ST[i - 1][j + (1 << (i - 1))];   }   int Find(int x, int y) {     int e = Log[y - x + 1];     if (G[ST[e][x]] < G[ST[e][y - (1 << e) + 1]]) return ST[e][x];     return ST[e][y - (1 << e) + 1];   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]), a[i + n] = a[i];     nn = n * 2;     for (i = 1; i <= nn; ++i) G[i] = i - a[i];     for (i = 0, j = 1; j <= nn; j <<= 1, ++i) Log[j] = i;     for (i = 1; i <= nn; ++i)       if (!Log[i]) Log[i] = Log[i - 1];     get_ST();     for (i = 1; i <= nn; ++i) {       if (i - a[i] <= 0) continue;       int now = Find(i - a[i], i);       F[i][0] = now;       for (j = 1; j <= 19; ++j) F[i][j] = F[F[i][j - 1]][j - 1];     }     for (i = n + 1; i <= nn; ++i) {       ++ans;       if (i - a[i] <= i - n + 1) continue;       int cangood = 1e9, ist = 0, id = i;       for (j = 19; j >= 0; --j)         if (G[F[id][j]] <= i - n + 1)           cangood = ist + (1 << j);         else           ist += (1 << j), id = F[id][j];       ans += cangood;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int n;   int seat[100];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> seat[i];     int sum = 0;     for (int i = 0; i < n; i++) sum += seat[i];     vector<int> ans;     ans.push_back(0);     int curSum = seat[0];     for (int i = 1; i < n; i++) {       if (seat[i] * 2 <= seat[0]) {         ans.push_back(i);         curSum += seat[i];       }     }     if (curSum > sum / 2) {       cout << ans.size() <<   n ;       for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 <<    ;     } else       cout << 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a[200010], m = INT_MAX;     string s;     cin >> n >> s;     for (int i = 0; i < n; i++) cin >> a[i];     long long int j = -1;     for (long long int i = 0; i < s.length(); i++) {       if (s[i] ==  R )         j = i;       else {         if (j != -1) {           long long int temp = abs(a[i] - a[j]) / 2;           if (temp < m) m = temp;         }       }     }     if (m == INT_MAX)       cout << -1;     else       cout << m;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   void solve() {     int n, p, k;     cin >> n >> p >> k;     auto f = [&](int x) -> int {       return ((ll)x * x % p * x % p * x % p - (ll)k * x % p + p) % p;     };     map<int, int> cnt;     for (int _ = 0; _ < n; _++) {       int x;       cin >> x;       cnt[f(x)]++;     }     ll res = 0;     for (auto& kp : cnt) {       int i = kp.second;       res += (ll)i * (i - 1) / 2;     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 << 16;   map<pair<int, int>, int> dp[maxn];   int n, c[20], r[20], b[20], ed, rrr, bbb, ans = 0x3f3f3f3f;   int main() {     cin >> n;     getchar();     for (int i = 1; i <= n; i++) {       char ch;       cin >> ch >> r[i] >> b[i];       if (ch ==  R ) c[i] = 1;     }     ed = (1 << n) - 1;     dp[0][pair<int, int>(0, 0)] = 0;     for (int i = 0; i <= ed; i++) {       int rr = 0, bb = 0;       for (int t = 0; t < n; t++)         if (i & (1 << t)) ++(c[t + 1] ? rr : bb);       for (int j = 0; j < n; j++) {         if (i & (1 << j)) continue;         for (auto it : dp[i]) {           int next = i | (1 << j), need = 0;           if (it.first.first < max(r[j + 1] - rr, 0))             need = max(need, r[j + 1] - rr - it.first.first);           if (it.first.second < max(b[j + 1] - bb, 0))             need = max(need, b[j + 1] - bb - it.first.second);           int rmr = it.first.first + need - max(r[j + 1] - rr, 0),               rmb = it.first.second + need - max(b[j + 1] - bb, 0);           if (!dp[next].count(pair<int, int>(rmr, rmb)))             dp[next][pair<int, int>(rmr, rmb)] = 0x3f3f3f3f;           dp[next][pair<int, int>(rmr, rmb)] =               min(dp[next][pair<int, int>(rmr, rmb)], it.second + need);         }       }     }     for (auto it : dp[ed]) ans = min(ans, it.second);     cout << ans + n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char p[120], A[10100][120], B[10100][120], res[120];   int SA[110], SB[110], Z[110], Pre[110];   int SS[110], Suf[110];   void Do(int n) {     int i, j;     printf( ? %d %d n , 1, n);     fflush(stdout);     for (i = 0; i < n * (n + 1) / 2; i++) {       scanf( %s , A[i]);       int c = 0;       for (j = 0; A[i][j]; j++) c += A[i][j] -  a ;       int L = j;       SA[L] += c;     }     printf( ? %d %d n , 1, n - 1);     fflush(stdout);     for (i = 0; i < n * (n - 1) / 2; i++) {       scanf( %s , B[i]);       int c = 0;       for (j = 0; B[i][j]; j++) c += B[i][j] -  a ;       int L = j;       SB[L] += c;     }     for (i = 1; i <= n; i++) {       Z[i] = SA[i] - SB[i];       res[n - i] = Z[i] - Z[i - 1] +  a ;     }   }   int main() {     int i, j, k;     int n;     scanf( %d , &n);     if (n == 1) {       printf( ? %d %d n , 1, n);       fflush(stdout);       scanf( %s , p);       printf( ! %s n , p);       fflush(stdout);       return 0;     }     if (n == 2) {       printf( ? %d %d n , 1, 1);       fflush(stdout);       scanf( %s , p);       res[0] = p[0];       printf( ? %d %d n , 2, 2);       fflush(stdout);       scanf( %s , p);       res[1] = p[0];       res[2] = 0;       printf( ! %s n , res);       return 0;     }     Do((n + 1) / 2);     printf( ? %d %d n , 1, n);     fflush(stdout);     for (i = 0; i < (n + 1) / 2; i++) {       Pre[i + 1] = Pre[i] + res[i] -  a ;     }     for (i = 0; i < n * (n + 1) / 2; i++) {       scanf( %s , A[i]);       int c = 0;       for (j = 0; A[i][j]; j++) c += A[i][j] -  a ;       int L = j;       SS[L] += c;     }     int tot = SS[n];     for (i = 1; i <= n / 2; i++) {       int z = SS[n - i];       for (j = 1; j < i; j++) {         int s = 0;         for (k = 0; k < i - j; k++) {           s += res[n - k - 1] -  a ;         }         z -= tot - (s + Pre[j]);       }       z -= (tot - Pre[i]);       Suf[i] = tot - z;       res[n - i] = Suf[i] - Suf[i - 1] +  a ;     }     printf( ! %s n , res);     fflush(stdout);   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* na, Arg1&& arg1, Args&&... args) {     const char* c = strchr(na + 1,  , );     cerr.write(na, c - na) <<   :   << arg1 <<   ,  ;     __f(c + 1, args...);   }   const double pi = acos(-1.0);   const double eps = 1e-8;   const int inf = 1e9;   const long long INF = 1e18;   const int mod = 1e9 + 7;   const int N = 3e5 + 5;   void solve() {     int len, q;     cin >> len >> q;     string s;     cin >> s;     s =  #  + s;     int ans = 0;     for (int i = 1; i <= len;) {       if (s[i] ==  . ) {         int j = i;         while (j <= len && s[j] ==  . ) j++;         ans += (j - i - 1);         i = j;       } else {         i++;       }     }     while (q--) {       int pos;       string ch;       cin >> pos >> ch;       if (s[pos] !=  .  && ch[0] ==  . ) {         if (pos - 1 >= 1 && s[pos - 1] ==  . ) ans++;         if (pos + 1 <= len && s[pos + 1] ==  . ) ans++;         s[pos] =  . ;       } else if (s[pos] ==  .  && ch[0] !=  . ) {         if (pos - 1 >= 1 && s[pos - 1] ==  . ) ans--;         if (pos + 1 <= len && s[pos + 1] ==  . ) ans--;         s[pos] = ch[0];       }       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     for (int tc = 1; tc <= t; tc++) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   inline int cmp(double x, double y = 0, double tol = 1e-8) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   struct point {     double x, y;     point(double x = 0, double y = 0) : x(x), y(y) {}     point operator+(point q) { return point(x + q.x, y + q.y); }     point operator-(point q) { return point(x - q.x, y - q.y); }     point operator*(double t) { return point(x * t, y * t); }     point operator/(double t) { return point(x / t, y / t); }     double operator*(point q) { return x * q.x + y * q.y; }     double operator%(point q) { return x * q.y - y * q.x; }     double mod() { return sqrt(x * x + y * y); }     point rotate(double t) {       return point(x * cos(t) - y * sin(t), x * sin(t) + y * cos(t));     }     int cmp(point q) const {       if (int t = ::cmp(x, q.x)) return t;       return ::cmp(y, q.y);     }     bool operator==(point q) const { return cmp(q) == 0; }     bool operator!=(point q) const { return cmp(q) != 0; }     bool operator<(point q) const { return cmp(q) < 0; }     static point pivot;   };   point point::pivot;   double poly_area(vector<point>& T) {     double s = 0;     int n = T.size();     for (int i = 0; i < n; i++) s += T[i] % T[(i + 1) % n];     return s / 2;   }   point line_intersect(point p, point q, point r, point s) {     point a = q - p, b = s - r, c = point(p % q, r % s);     return point(point(a.x, b.x) % c, point(a.y, b.y) % c) / (a % b);   }   vector<point> halfplane(vector<point>& p, pair<point, point> semiplano) {     vector<point> q;     point p1 = semiplano.first, p2 = semiplano.second;     int n = p.size();     for (int i = 0; i < n; i++) {       double c = (p2 - p1) % (p[i] - p1);       double d = (p2 - p1) % (p[(i + 1) % n] - p1);       if (cmp(c) >= 0) q.push_back(p[i]);       if (cmp(c * d) < 0)         q.push_back(line_intersect(p1, p2, p[i], p[(i + 1) % n]));     }     return q;   }   vector<point> semi_plano_cruzado(vector<pair<point, point> > semiplano) {     vector<point> p;     p.push_back(point(-1e9, -1e9));     p.push_back(point(-1e9, +1e9));     p.push_back(point(+1e9, +1e9));     p.push_back(point(+1e9, -1e9));     int n = semiplano.size();     for (int i = 0; i < n; i++) {       p = halfplane(p, semiplano[i]);       if (p.size() == 0) break;     }     return p;   }   int main() {     double w, h, a;     cin >> w >> h >> a;     double gama = atan(w / h);     double beta = atan(h / w);     vector<point> p, q;     p.push_back(point(-0.5 * w, -0.5 * h));     p.push_back(point(-0.5 * w, 0.5 * h));     p.push_back(point(0.5 * w, 0.5 * h));     p.push_back(point(0.5 * w, -0.5 * h));     a = a * Pi / 180;     double teta = 0.5 * Pi + a - gama - beta;     q.push_back(point(-0.5 * w, -0.5 * h));     q.push_back(point(-0.5 * w, 0.5 * h));     q.push_back(point(0.5 * w, 0.5 * h));     q.push_back(point(0.5 * w, -0.5 * h));     for (int i = 0; i < 4; i++) q[i] = q[i].rotate(teta);     for (int i = 0; i < 4; i++) {       p = halfplane(p, make_pair(q[(i + 1) % 4], q[i]));     }     printf( %.9lf n , fabs(poly_area(p)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s1;   long long arr2[2000006];   long long dsu(long long x) { return arr2[x] == x ? x : arr2[x] = dsu(arr2[x]); }   int main() {     char ans[2000006];     long long n, t1, t2, t3, t4, t5;     cin >> n;     for (int i = 0; i < 2000006; i++) {       ans[i] =  a ;       arr2[i] = i;     }     t3 = 0;     while (n--) {       cin >> s1;       t1 = s1.length();       cin >> t2;       while (t2--) {         cin >> t4;         t4--;         if (t3 < t4 + t1 - 1) t3 = t4 + t1 - 1;         for (int i = dsu(t4); i < t4 + t1;) {           ans[i] = s1[i - t4];           arr2[i] = i + 1;           i = dsu(i);         }       }     }     t5 = 0;     while (1) {       cout << ans[t5++];       if (t5 > t3) break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   inline long long int rl() {     long long int res = 0, neg = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) neg = 1, c = getchar();     while (c >=  0  && c <=  9 ) {       res = (res << 1) + (res << 3) + c - 48;       c = getchar();     }     return neg ? -res : res;   }   inline void read(string &s) {     s =   ;     char c = getchar();     while (c !=   n ) {       s += c;       c = getchar();     }   }   int main() {     vector<std::vector<char> > a(9);     for (int i = 0; i < 9; ++i) {       for (int j = 0; j < 9; ++j) {         char c;         cin >> c;         a[i].push_back(c);       }     }     long long int x = rl() - 1, y = rl() - 1;     int i;     for (i = 3 * (x % 3); i < 3 * (x % 3 + 1); ++i)       for (int j = 3 * (y % 3); j < 3 * (y % 3 + 1); ++j) {         if (a[i][j] ==  . ) goto exit;       }   exit:;     if (i == 3 * (x % 3 + 1)) {       for (int i = 0; i < 9; ++i) {         for (int j = 0; j < 9; ++j) {           if (a[i][j] ==  . )             cout <<  ! ;           else             cout << a[i][j];           if (j % 3 == 2 && j != 8) cout <<    ;         }         cout <<   n ;         if (i % 3 == 2 && i != 8) cout <<   n ;       }     } else {       for (i = 3 * (x % 3); i < 3 * (x % 3 + 1); ++i)         for (int j = 3 * (y % 3); j < 3 * (y % 3 + 1); ++j) {           if (a[i][j] ==  . ) a[i][j] =  ! ;         }       for (int i = 0; i < 9; ++i) {         for (int j = 0; j < 9; ++j) {           cout << a[i][j];           if (j % 3 == 2 && j != 8) cout <<    ;         }         cout <<   n ;         if (i % 3 == 2 && i != 8) cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, p[200005], a[200005], pi[200005], mra[200005], t;   int mar[200005], su[200005], pr[200005], mm[200005], l, lr, r, Ilmm[200005];   vector<int> v[200005];   bool pa;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> q;     for (int i = 1; i <= n; ++i) {       cin >> p[i];       pi[p[i]] = i;     }     for (int i = 1; i <= m; ++i) {       cin >> a[i];     }     for (int i = 1; i <= m; ++i) {       mar[a[i]] = i;       if (pi[a[i]] == 1) {         pr[i] = i;       } else if (mar[p[pi[a[i]] - 1]]) {         pr[i] = pr[mar[p[pi[a[i]] - 1]]];       }     }     for (int i = 1; i <= n; ++i) mar[i] = 0;     for (int i = m; i > 0; --i) {       v[a[i]].push_back(i);       mar[a[i]] = i;       if (pi[a[i]] == n) {         su[i] = i;       } else if (mar[p[pi[a[i]] + 1]]) {         su[i] = su[mar[p[pi[a[i]] + 1]]];       }       if (!su[i]) continue;       if (pi[a[i]] > 1) {         t = p[pi[a[i]] - 1];         l = 0;         r = v[t].size();         --r;         int tp = 0;         while (l <= r) {           lr = (l + r) / 2;           if (pr[v[t][lr]] > su[i]) {             tp = v[t][lr];             l = lr + 1;           } else {             r = lr - 1;           }         }         mm[i] = tp;       } else {         mm[i] = su[i];       }     }     for (int i = m; i > 0; --i) {       Ilmm[i] = Ilmm[i + 1];       if ((mm[i] && mm[i] < Ilmm[i]) || !Ilmm[i]) {         Ilmm[i] = mm[i];       }     }     for (int i = 1; i <= q; ++i) {       cin >> l >> r;       pa = 0;       if (Ilmm[l] && Ilmm[l] <= r) {         pa = 1;       }       cout << pa;     }   }