malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct vals {     bool vd;     char val[1010];     bool cur;     int idx[2];     string nome, op;   } s[5020];   bool valdef(bool k, int vv, int curidx) {     if (s[curidx].idx[vv] == -1) return k;     return s[s[curidx].idx[vv]].cur;   }   bool value(string op, bool k, int curidx) {     if (op ==  XOR ) {       return valdef(k, 0, curidx) ^ valdef(k, 1, curidx);     } else if (op ==  OR ) {       return valdef(k, 0, curidx) | valdef(k, 1, curidx);     } else if (op ==  AND ) {       return valdef(k, 0, curidx) & valdef(k, 1, curidx);     }   }   int main() {     int n, m;     char c;     char aux1[12], aux2[1010], aux3[5], aux4[12];     map<string, int> mpi;     cin >> n >> m;     for (int i = 0; i < (n); ++i) {       scanf( %s := %s%c , aux1, aux2, &c);       mpi[string(aux1)] = i;       if (c ==    ) {         scanf( %s %s , aux3, aux4);         if (string(aux2) !=  ? )           s[i].idx[0] = mpi[string(aux2)];         else           s[i].idx[0] = -1;         s[i].op = string(aux3);         if (string(aux4) !=  ? )           s[i].idx[1] = mpi[string(aux4)];         else           s[i].idx[1] = -1;         s[i].vd = false;       } else if (c ==   n  or c ==   r ) {         strcpy(s[i].val, aux2);         s[i].vd = true;       } else         cout <<  erro  << endl;     }     string sauxmax =   ;     string sauxmin =   ;     for (int i = 0; i < (m); ++i) {       vector<int> vsoma(2, 0);       for (int k = 0; k < (2); ++k) {         for (int j = 0; j < (n); ++j) {           bool baux;           if (s[j].vd) {             baux = s[j].val[i] -  0 ;             s[j].cur = baux;           } else {             baux = value(s[j].op, k, j);             s[j].cur = baux;           }           vsoma[k] += baux;         }       }       if (vsoma[1] > vsoma[0])         sauxmax +=  1 , sauxmin +=  0 ;       else if (vsoma[1] == vsoma[0])         sauxmax +=  0 , sauxmin +=  0 ;       else if (vsoma[1] < vsoma[0])         sauxmax +=  0 , sauxmin +=  1 ;     }     cout << sauxmin << endl << sauxmax << endl;   }
#include <bits/stdc++.h>   using namespace std;   string A[8];   int dx[9] = {-1, -1, -1, 0, 1, 1, 1, 0, 0};   int dy[9] = {-1, 0, 1, 1, 1, 0, -1, -1, 0};   bool dfs(int x, int y, int tour) {     if (x == 0 && y == 7) return 1;     if (tour > 8) return true;     for (int k = 0; k <= 8; k++) {       int nx = x + dx[k], ny = y + dy[k];       if (nx < 0 || ny < 0 || nx > 7 || ny > 7) continue;       if (nx - tour >= 0 && A[nx - tour][ny] ==  S ) continue;       if (nx - tour - 1 >= 0 && A[nx - tour - 1][ny] ==  S ) continue;       if (dfs(nx, ny, tour + 1)) return 1;     }     return 0;   }   int main() {     vector<pair<int, int> > S;     for (int i = 0; i < 8; i++) {       cin >> A[i];     }     if (dfs(7, 0, 0))       cout <<  WIN  << endl;     else       cout <<  LOSE  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void io() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 2e5 + 9;   const long long MOD = 1e9 + 7;   const int INF = 1e9;   int dx[5] = {0, -1, 1, 0, 0};   int dy[5] = {0, 0, 0, -1, 1};   char dc[5] = { 0 ,  U ,  D ,  L ,  R };   int main() {     int test;     test = 1;     while (test--) {       int x, y;       cin >> x >> y;       int ans = 0;       while (x > 0 && y > 0) {         if (x > y) swap(x, y);         if (x < 100) x++;         y -= 2;         if (y < 0) break;         ans++;       }       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, d[N], a[N];   bool flag[N];   bool check(int x) {     memset(flag, 0, sizeof(flag));     int cur = x - 1;     for (int i = x; i >= 1; i--) {       cur = min(cur, i - 1);       if (d[i] && !flag[d[i]] && a[d[i]] <= cur) {         flag[d[i]] = 1;         cur -= a[d[i]] + 1;       }     }     for (int i = 1; i <= m; i++) {       if (!flag[i]) return 0;     }     return 1;   }   int main() {     int ans = -1;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , d + i);     for (int i = 1; i <= m; i++) scanf( %d , a + i);     int l = 1, r = n, mid;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid))         r = mid - 1, ans = mid;       else         l = mid + 1;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   struct ma : array<T, N> {     T &operator[](size_t n) { return (*static_cast<array<T, N> *>(this))[n]; }   };   template <class T>   string to_str(const T &a) {     ostringstream os;     os << a;     return os.str();   }   template <>   string to_str<long double>(const long double &a) {     ostringstream os;     os.precision(10);     os.setf(ios::fixed);     os << a;     return os.str();   }   template <class T>   T from_str(const string &s) {     istringstream is;     T val;     is >> val;     return val;   }   int cond = (long long)0;   void solve() {     int n, m;     scanf( %d%d , &n, &m);     vector<int> co(n);     for (auto i = (0); i < (n); ++i) scanf( %d , &co[i]);     long long ret = 0;     for (auto i = (0); i < (m); ++i) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       ret += min(co[a], co[b]);     }     cout << ret << endl;   }   void brute() {}   void gen(int i, int n, int k) {}   int main(int argc, char **argv) {     ios::sync_with_stdio(false);     vector<string> args;     int nr_test = -1;     int t = 1;     for (auto i = (1); i <= (argc - 1); ++i) args.push_back(argv[i]);     for (auto &it : (args))       if (it ==  q ) cond = 10000000;     for (auto &it : (args))       if (it ==  all ) t = 1000;     for (auto &it : (args))       if (atoi(it.c_str()) > 0) nr_test = atoi(it.c_str());     for (auto &it : (args))       if (it ==  b ) {         brute();         return 0;       }     for (auto &it : (args))       if (it ==  g  && args.size() >= 4) {         gen(atoi(args[1].c_str()), atoi(args[2].c_str()), atoi(args[3].c_str()));         return 0;       }     for (auto i = (1); i <= (t); ++i) {       if (nr_test == -1 || i <= nr_test) solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     char tmp =  z ;     cin >> str;     for (int i = 0; i < str.length(); i++) {       if (str[i] <= tmp) {         tmp = str[i];         cout <<  Mike  << endl;       } else {         cout <<  Ann  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, m, a, b;     cin >> n >> m >> a >> b;     long long int res, ans;     res = n / m;     if (n % m) res++;     res = (res * m - n) * a;     ans = (n % m) * b;     cout << min(res, ans) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long min(long long a, long long b) { return (a < b) ? a : b; }   long long max(long long a, long long b) { return (a > b) ? a : b; }   long long fp(long long a, long long b) {     if (b == 0) return 1;     long long x = fp(a, b / 2);     x = (x * x) % mod;     if (b & 1) x = (x * a) % mod;     return x;   }   const long long N = 2e5 + 5;   long long a[N];   long long n;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     long long cnt[60] = {0};     for (long long i = 1; i <= n; i++) {       cin >> a[i];       for (long long b = 0; b < 20; b++) {         if ((a[i] >> b) & 1) {           cnt[b]++;         }       }     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       long long x = 0;       for (long long b = 0; b < 20; b++) {         if (cnt[b]) {           cnt[b]--;           x |= (1ll << b);         }       }       ans += x * x;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x;   vector<pair<int, int> > leti[26];   vector<pair<int, int> > shift;   vector<int> dis[26];   int main() {     cin >> n >> m >> x;     int d = x * x;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char t;         cin >> t;         if (t ==  S )           shift.push_back(pair<int, int>(i, j));         else           leti[t -  a ].push_back(pair<int, int>(i, j));       }     }     for (int i = 0; i < 26; i++) {       for (int j = 0; j < leti[i].size(); j++) {         int mn = 0x7fffffff;         for (int k = 0; k < shift.size(); k++) {           int dx = shift[k].first - leti[i][j].first;           int dy = shift[k].second - leti[i][j].second;           mn = min(mn, dx * dx + dy * dy);         }         dis[i].push_back(mn);       }     }     int q;     cin >> q;     int cnt = 0;     for (int i = 0; i < q; i++) {       char t;       cin >> t;       if (((t -  a ) >= 0) && leti[t -  a ].empty()) {         cout << -1 << endl;         return 0;       }       if (((t -  a ) < 0) && leti[t -  A ].empty()) {         cout << -1 << endl;         return 0;       }       if (((t -  a ) < 0) && shift.empty()) {         cout << -1 << endl;         return 0;       }       if ((t -  a ) < 0) {         int flag = true;         for (int j = 0; j < leti[t -  A ].size(); j++) {           if (dis[t -  A ][j] <= d) {             flag = false;             break;           }         }         if (flag)           cnt++;         else           flag = true;       }     }     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long int Maxn3 = 1e3 + 10;   const long long int Maxn4 = 1e4 + 10;   const long long int Maxn5 = 1e5 + 10;   const long long int Maxn6 = 1e6 + 10;   const long long int Maxn7 = 1e7 + 10;   const long long int Maxn8 = 1e8 + 10;   const long long int Maxn9 = 1e9 + 10;   const long long int Maxn18 = 1e18 + 10;   const long long int Mod1 = 1e7 + 7;   const long long int Mod2 = 1e9 + 7;   const long long int LLMax = LLONG_MAX;   const long long int LLMin = LLONG_MIN;   const long long int INTMax = INT_MAX;   const long long int INTMin = INT_MIN;   long long int mn = LLMax, mx = LLMin;   bool prime(int x) {     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return 0;     return 1;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     if (prime(n) == 1)       return cout <<  1 n  << n, 0;     else {       cout <<  3 n3  ;       n -= 3;       for (int i = 3; i < n; i += 2)         if (prime(n - i) and prime(i)) return cout << i <<     << n - i, 0;     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   FILE *in = stdin, *out = stdout;   using namespace std;   #pragma comment(linker,  /stack:36777216 )   int n;   char a[300005];   int D[300005];   void input() {     fscanf(in,  %d , &n);     fscanf(in,  %s , &a[1]);   }   bool isSame(int x) {     if (x & 1) return false;     for (int i = (1); i <= (x / 2); i++) {       if (a[i] != a[i + x / 2]) return false;     }     return true;   }   void pro() {     int ans = n;     for (int i = (1); i <= (n); i++) {       if (isSame(i)) ans = min(ans, i / 2 + 1 + (n - i));     }     fprintf(out,  %d , ans);   }   int main() {     input();     pro();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 110, M = 10010;   int n;   long double x;   int c[N], all;   long double binom[N][N];   long double f[N][M];   int main() {     cin >> n >> x;     for (int i = 1; i <= n; i++) scanf( %d , &c[i]), all += c[i];     f[0][0] = 1;     for (int i = 0; i <= n; i++) {       binom[i][0] = binom[i][i] = 1;       for (int j = 1; j < i; j++)         binom[i][j] = binom[i - 1][j] + binom[i - 1][j - 1];     }     f[0][0] = 1;     for (int id = 1; id <= n; id++) {       for (int i = id; i; i--) {         for (int j = all; j >= c[id]; j--) {           f[i][j] += f[i - 1][j - c[id]];         }       }     }     long double ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= all; j++) {         long double v = f[i][j];         v /= binom[n][i];         v *= min(x / 2 + x / 2 * n / i, (long double)j / (long double)i);         ans += v;       }     }     printf( %.15Lf n , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long k, l, g = 0, h = 0;   int a, b, p[3][3], q[3][3], t, u, v, c;   vector<pair<int, int> > s;   bool con;   int gg(int a, int b) {     if (a == b + 1 || a == b - 2) return 1;     return 0;   }   void sim(int x, int t, int u) {     while (x > 0) {       g += gg(t, u);       h += gg(u, t);       v = t;       t = p[t][u];       u = q[v][u];       x--;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> k >> a >> b;     a--, b--;     for (int i = 0; i < (3); i++)       for (int j = 0; j < (3); j++) cin >> p[i][j];     for (int i = 0; i < (3); i++)       for (int j = 0; j < (3); j++) cin >> q[i][j];     for (int i = 0; i < (3); i++)       for (int j = 0; j < (3); j++) q[i][j]--, p[i][j]--;     s.push_back({a, b});     t = p[a][b], u = q[a][b];     while (true) {       con = false;       for (int i = 0; i < (s.size()); i++) {         if (s[i].first == t && s[i].second == u) con = true;       }       if (con)         break;       else {         s.push_back({t, u});         v = t;         t = p[t][u];         u = q[v][u];       }       con = false;     }     for (int i = 0; i < (s.size()); i++) {       if (s[i].first == t && s[i].second == u) c = s.size() - i;     }     if (k < 10000) {       sim(k, a, b);     } else {       l = (k - s.size() + c) / c;       sim(c, t, u);       g *= l;       h *= l;       sim(s.size() - c, a, b);       sim((k - s.size() + c) % c, t, u);     }     cout << g <<     << h << endl;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysecdesc(const pair<long long, long long> &a,                      const pair<long long, long long> &b) {     if (a.first == b.first)       return a.second > b.second;     else       return 0;   }   const long long N = 100010;   bool prime[N];   void SieveOfEratosthenes() {     long long n = N - 3;     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   long long i, j;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     SieveOfEratosthenes();     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11) {         cout <<  -1  <<   n ;       } else if (n % 4 == 0) {         cout << n / 4 <<   n ;       } else if (n == 6) {         cout << 1 <<   n ;       } else {         long long temp = n / 4;         long long x = n - temp * 4;         if (x == 1) {           cout << 1 + (n - 9) / 4 <<   n ;         } else if (x == 2) {           cout << 1 + (n - 6) / 4 <<   n ;         } else if (x == 3) {           cout << 2 + (n - 15) / 4 <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fastpower(long long power, long long base) {     if (power == 0) return (1 % 1000000007);     long long sum;     sum = fastpower(power / 2, base) % 1000000007;     sum = ((sum % 1000000007) * (sum % 1000000007)) % 1000000007;     if (power & 1) sum = ((sum % 1000000007) * (base % 1000000007)) % 1000000007;     return (sum % 1000000007);   }   int main() {     ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),         cout.tie(0);     ;     string s;     long long k, sum = 0;     cin >> s >> k;     long long rn =         (fastpower((long long)s.size() * k, 2) - 1 + 1000000007) % 1000000007;     long long r =         (fastpower((long long)s.size(), 2) - 1 + 1000000007) % 1000000007;     long long d = fastpower(1000000007 - 2, r);     for (int i = 0; i < (int)s.size(); ++i) {       if (s[i] ==  0  || s[i] ==  5 ) {         long long a = fastpower(i, 2);         sum = (sum % 1000000007 + a * rn % 1000000007 * d % 1000000007) %               1000000007;       }     }     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getn() {     int h;     scanf( %d , &h);     return h;   }   template <class T, class U>   ostream& operator<<(ostream& out, const pair<T, U>& par) {     cout <<  [  << par.first <<  ;  << par.second <<  ] ;     return out;   }   vector<vector<int> > mini;   int n;   int nacitaj(int i, int j) {     mini[i][j] = getn();     i = (i != n - 1 ? i + 1 : 0);     j = (i != 0 ? j : j + 1);     return (j != n ? nacitaj(i, j) : 1);   }   int floydwardshal(int i, int j, int l) {     mini[i][j] = min(mini[i][j], mini[i][l] + mini[l][j]);     i = (i != n - 1 ? i + 1 : 0);     j = (i != 0 ? j : j + 1);     j = (j >= n ? 0 : j);     l = (i == 0 && j == 0 ? l + 1 : l);     return (l != n ? floydwardshal(i, j, l) : 0);   }   int maxi(int i, int j) {     int mx = mini[i][j];     i = (i != n - 1 ? i + 1 : 0);     j = (i != 0 ? j : j + 1);     return (j != n ? max(maxi(i, j), mx) : mx);   }   int main() {     n = getn();     mini.resize(n, vector<int>(n, 0));     nacitaj(0, 0);     floydwardshal(0, 0, 0);     cout << maxi(0, 0) << endl;   }
#include <bits/stdc++.h>   int main() {     int sum = 0, a, n, m, i;     scanf( %d %d , &n, &m);     for (i = 1; i <= n; i++) {       sum = sum + i;       if (m > sum && i == n) {         i = 0;       }       a = m - sum;       if (a < i + 1) {         printf( %d , a);         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000000 + 10;   int a[N], b[N];   int n, m;   int main() {     int x, y;     scanf( %d%d , &n, &m);     {       for (int i = 0; i < m; i++) {         scanf( %d%d , &x, &y);         x--;         y--;         a[x]++;         a[y]++;       }       for (int i = 0; i < n; i++) b[i] = n - 1 - a[i];       long long total = 0;       for (int i = 0; i < n; i++) total += (long long)a[i] * b[i];       total /= 2;       cout << (long long)n * (n - 1) / 2 * (n - 2) / 3 - total << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mult(long long a, long long b, long long p = 1000000007) {     return ((a % p) * (b % p)) % p;   }   long long add(long long a, long long b, long long p = 1000000007) {     return (a % p + b % p) % p;   }   long long sub(long long a, long long b, long long p = 1000000007) {     return (a % p - b % p + p) % p;   }   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = mult(r, n, p);       n = mult(n, n, p);     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   map<long long, vector<long long> > m;   int main() {     long long n, k;     cin >> n >> k;     long long a[n], c[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]].push_back(i);     }     bool f = 1;     long long mx = 1;     long long it = 1;     for (auto i : m) {       if (i.second.size() > k) f = 0;       for (auto j : i.second) {         c[j] = it;         mx = max(mx, it);         ++it;         if (it > k) {           it = 1;           mx = k;         }       }     }     if (f && mx == k) {       cout <<  YES n ;       for (int i = 0; i < n; i++) cout << c[i] <<    ;     } else       cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 100 * 1000;   long double l[N];   long double Maks(long double dod, int n) {     int i;     long double as, mi, w;     mi = 0;     w = -10000000000000;     as = 0;     for (i = 1; i <= n; ++i) {       as += (l[i] - dod);       w = max(w, as - mi);       mi = min(mi, as);     }     return w;   }   long double Minim(long double dod, int n) {     int i;     long double as, ma, w;     ma = 0;     w = 10000000000000;     as = 0;     for (i = 1; i <= n; ++i) {       as += (l[i] - dod);       w = min(w, as - ma);       ma = max(ma, as);     }     return w;   }   long double TS(long double p, long double k, int n) {     int i;     long double s1, s2, w1, w2;     for (i = 1; i <= 100; ++i) {       s1 = p + ((k - p) / 3);       s2 = k - ((k - p) / 3);       w1 = max(abs(Maks(s1, n)), abs(Minim(s1, n)));       w2 = max(abs(Maks(s2, n)), abs(Minim(s2, n)));       if (w1 < w2)         k = s2;       else         p = s1;     }     return p;   }   void WczytajLiczby(int &n) {     int i;     cin >> n;     for (i = 1; i <= n; ++i) cin >> l[i];   }   void Weakness() {     int n;     long double w;     WczytajLiczby(n);     w = TS(-10000, 10000, n);     w = max(abs(Minim(w, n)), abs(Maks(w, n)));     cout << fixed << setprecision(10) << w <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     Weakness();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], lg[100005];   int rmq[100005][20];   struct trie {     struct node {       node *edge[2];       vector<int> ps[2];       node() {         for (int i = 0; i < 2; i++) edge[i] = 0;         ps[0].clear();         ps[1].clear();       }     } * root;     trie() { root = new node(); }     void insert(int v, int p) {       node *t = root;       for (int po = 29; po >= 0; po--) {         int x = (bool)(v & (1 << po));         if (!t->edge[x]) t->edge[x] = new node();         t->ps[x].push_back(p);         t = t->edge[x];       }     }     void remove(int v) {       node *t = root;       for (int po = 29; po >= 0; po--) {         int x = (bool)(v & (1 << po));         t->ps[x].pop_back();         t = t->edge[x];       }     }     long long query(int v, int last) {       node *t = root;       int res = 0;       for (int po = 29; po >= 0; po--) {         int x = (bool)(v & (1 << po));         x = !x;         if (!t->ps[x].empty() && t->ps[x].back() > last) {           res += (1 << po);           t = t->edge[x];         } else           t = t->edge[!x];       }       return res;     }   };   int q(int l, int r) {     if (l > r) swap(l, r);     int po = lg[r - l + 1];     return max(rmq[l][po], rmq[r - (1 << po) + 1][po]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     lg[0] = -1;     for (int i = 1; i < 100005; i++) lg[i] = lg[i - 1] + !(i & (i - 1));     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) rmq[i][0] = a[i];     for (int i = 1; i <= lg[n]; i++)       for (int j = 0; j + (1 << i) <= n; j++)         rmq[j][i] = max(rmq[j][i - 1], rmq[j + (1 << (i - 1))][i - 1]);     long long res = 0;     trie t;     t.insert(a[0], 0);     stack<pair<long long, long long> > ms;     ms.push(pair<long long, long long>(a[0], 0));     for (int i = 1; i < n; i++) {       int p1 = -1;       for (int po = (1 << 17); po; po >>= 1)         if (p1 + po < i && q(p1 + po, i) > a[i]) p1 += po;       int p2 = -1;       if (p1 > 0)         for (int po = (1 << 17); po; po >>= 1)           if (p2 + po <= p1 - 1 && q(p2 + po, p1 - 1) > a[i]) p2 += po;       res = max(res, t.query(a[i], p2));       while (!ms.empty() && ms.top().second > p1) {         t.remove(ms.top().first);         ms.pop();       }       t.insert(a[i], i);       ms.push(pair<long long, long long>(a[i], i));     }     cout << (res) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, g[20][20], r, c, k, ans = 0, x, y;   bool chk(int a, int b, int c, int d) {     int cnt = 0;     for (int i = a; i <= a + c; i++) {       for (int j = b; j <= b + d; j++) {         cnt += g[i][j];         if (cnt >= k) return 1;       }     }     return 0;   }   int main() {     scanf( %d%d%d%d , &r, &c, &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       g[x][y] = 1;     }     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= c; j++) {         for (int e = 0; e + i <= r; e++) {           for (int f = 0; f + j <= c; f++) {             ans += chk(i, j, e, f);           }         }       }     }     cout << ans;     return 0;   }