malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct T {     long long nu, p;     bool operator<(const T& o) const {       if (nu > o.nu) return true;       if (nu == o.nu && p > o.p) return true;       return false;     }   };   long long n, k, m;   T plazas[111111];   long long sum[111111];   long long donde[111111];   int main() {     cin >> n >> k >> m;     for (int i = 0; i < n; i++) cin >> plazas[i].nu, plazas[i].p = i;     n--;     sort(plazas, plazas + n);     for (int i = 0; i < n; i++) {       donde[plazas[i].p] = i;       sum[i] = plazas[i].nu;       if (i) sum[i] += sum[i - 1];     }     if (sum[n - 1] <= m)       cout << n + 1;     else {       bool ok = false;       long long ss = 0, tt;       ss = sum[k - 1];       if (ss <= m)         cout << n + 1;       else {         ss = 0;         if (k > 1) ss = sum[k - 2];         for (int i = 0; i < n && !ok; i++) {           long long p = donde[i];           long long tss = ss;           if (p < k - 2)             tss += plazas[k - 1].nu;           else             tss += plazas[p].nu;           if (tss > m) {             ok = true;             cout << i + 1;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const double inf = 1e9;   int n, m, x[N], b[N], pre[N];   double dp[N];   bool check(double mid) {     for (int i = 1; i <= n; i++) dp[i] = inf;     for (int i = 0; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         double tmp = dp[i] + sqrt(abs(x[j] - x[i] - m)) - 1.0 * mid * b[j];         if (dp[j] > tmp) {           dp[j] = tmp;           pre[j] = i;         }       }     }     return dp[n] >= 0;   }   void prnt(int x) {     if (x == 0) return;     prnt(pre[x]);     printf( %d  , x);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d%d , &x[i], &b[i]);     double l = 0.0, r = 1e5;     while (r - l > 1e-8) {       double mid = (l + r) / 2;       if (check(mid))         l = mid;       else         r = mid;     }     prnt(n);     return printf(  n ), 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long a, b, c, d, e, i, j, k, l;       cin >> a >> b;       if (a <= b)         cout << abs(a - b) << endl;       else if (a % 2 + b % 2 == 1)         cout << 1 << endl;       else         cout << 0 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[200001];   long long search(long long l, long long h, long long target) {     if (h - l <= 1) {       if (a[l] > target)         return l;       else         return h;     }     long long mid = (l + h) / 2;     if (a[mid] > target)       return search(l, mid, target);     else       return search(mid + 1, h, target);   }   int main() {     int N, M;     cin >> N >> M;     for (int i = 0; i < N; i++) {       cin >> a[i];     }     sort(a, a + N);     for (int j = 0; j < M; j++) {       int b;       cin >> b;       if (a[N - 1] > b) {         cout << search(0, N - 1, b) <<    ;       } else {         cout << N <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, nn;     cin >> n;     nn = n * 2;     vector<int> arr(nn);     for (int i = 0; i < nn; ++i) cin >> arr[i];     sort(arr.begin(), arr.end());     long long ans, now;     ans = arr[nn - 1] - arr[n];     ans *= arr[n - 1] - arr[0];     for (int i = 1; i < n; ++i) {       now = arr[n - 1 + i] - arr[i];       now *= arr[nn - 1] - arr[0];       ans = min(ans, now);     }     cout << ans;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long llinf = (1LL << 62);   const int inf = (1 << 30);   const long long nmax = 5e5 + 50;   const int mod = 1e9 + 7;   using namespace std;   int n, m, i, x, a[nmax], p[nmax], q, st[4 * nmax], ans[nmax], j;   long long nr[nmax], k;   vector<int> b[nmax];   vector<pair<int, int> > qr[nmax];   pair<int, int> pr;   pair<int, int> fnd(long long y) {     int l = 0, r = n, mid, rs = n, i;     while (l <= r) {       mid = (l + r) / 2;       if (nr[mid] > y)         rs = mid, r = mid - 1;       else         l = mid + 1;     }     for (i = max(rs - 1, 0); i <= min(rs + 1, n); i++)       if (nr[i] >= y) break;     rs = i;     if (rs <= n) {       if (rs) y -= nr[rs - 1];       return make_pair(rs, y);     } else {       y -= nr[n];       if (y % m == 0) return make_pair(m, -1);       return make_pair(y % m, -1);     }   }   void upd(int nod, int l, int r, int p) {     if (l == r) {       st[nod] = 1;       return;     }     int mid = (l + r) / 2;     if (p <= mid)       upd(2 * nod, l, mid, p);     else       upd(2 * nod + 1, mid + 1, r, p);     st[nod] = st[2 * nod] + st[2 * nod + 1];   }   int qry(int nod, int l, int r, int z) {     if (z > st[nod]) return -1;     if (l == r) return l;     int mid = (l + r) / 2;     if (st[nod * 2] >= z) return qry(2 * nod, l, mid, z);     return qry(2 * nod + 1, mid + 1, r, z - st[nod * 2]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (i = 1; i <= n; i++) {       cin >> x;       a[x]++;     }     for (i = 1; i <= m; i++) {       nr[a[i]]++;       b[a[i]].push_back(i);     }     p[0] = b[0].size();     for (i = 1; i <= n; i++) p[i] = p[i - 1] + b[i].size();     for (i = 1; i <= n; i++) nr[i] += nr[i - 1];     for (i = 1; i <= n; i++) nr[i] += nr[i - 1];     for (i = 1; i <= q; i++) {       cin >> k;       k -= n;       pr = fnd(k);       if (pr.second == -1)         ans[i] = pr.first;       else         qr[pr.first].push_back(make_pair(pr.second, i));     }     for (i = 0; i <= n; i++) {       for (j = 0; j < b[i].size(); j++) upd(1, 1, m, b[i][j]);       for (j = 0; j < qr[i].size(); j++)         ans[qr[i][j].second] = qry(1, 1, m, qr[i][j].first);     }     for (i = 1; i <= q; i++) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100100, L = 18;   int n, m, Q;   int dep[N], p[N][L];   set<int> adj[N];   map<int, int> mp[N];   int get(int par, int i) {     if (mp[par][i] == i) return i;     return mp[par][i] = get(par, mp[par][i]);   }   void mrg(int par, int u, int v) {     u = get(par, u);     v = get(par, v);     if (u == v) return;     if (rand() & 1) swap(u, v);     mp[par][u] = mp[par][v];   }   int LCA(int u, int v) {     if (u == v) return 0;     int u0 = u, v0 = v;     if (dep[u] < dep[v]) swap(u, v);     int k = dep[u] - dep[v];     for (int i = 0; i < L; i++)       if (k & (1 << i)) u = p[u][i];     if (u == v) return k;     for (int i = L - 1; i >= 0; i--)       if (p[u][i] != p[v][i]) u = p[u][i], v = p[v][i];     int ret = dep[u0] + dep[v0] - 2 * dep[p[u][0]];     int par = p[u][0];     if (get(par, u) == get(par, v)) ret--;     return ret;   }   int main() {     srand(time(0));     scanf( %d %d %d , &n, &m, &Q);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].insert(v);       adj[v].insert(u);     }     queue<int> q;     q.push(1);     dep[1] = 1;     p[1][0] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       for (auto v : adj[u]) mp[u][v] = v;       for (auto v : adj[u]) {         if (p[u][0] == v) continue;         if (dep[v]) {           mrg(p[u][0], u, v);           continue;         }         dep[v] = 1 + dep[u];         p[v][0] = u;         for (int i = 1; i < L; i++) p[v][i] = p[p[v][i - 1]][i - 1];         q.push(v);       }     }     while (Q--) {       int u, v;       scanf( %d %d , &u, &v);       printf( %d n , LCA(u, v));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T b, T p, T m) {     T ret;     if (p == 0) return 1;     if (p & 1) {       ret = (bigmod(b, p / 2, m) % m);       return ((b % m) * ret * ret) % m;     } else {       ret = (bigmod(b, p / 2, m) % m);       return (ret * ret) % m;     }   }   int dx4[] = {1, -1, 0, 0};   int dy4[] = {0, 0, 1, -1};   int dx6[] = {0, 0, 1, -1, 0, 0};   int dy6[] = {1, -1, 0, 0, 0, 0};   int dz6[] = {0, 0, 0, 0, 1, -1};   int dx8[] = {1, -1, 0, 0, -1, 1, -1, 1};   int dy8[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dkx8[] = {-1, 1, -1, 1, -2, -2, 2, 2};   int dky8[] = {2, 2, -2, -2, 1, -1, 1, -1};   int tc = 1;   const double eps = 1e-9;   const double pi = acos(-1.0);   const long long int mx = 5e5;   const long long int mod = 1e9 + 7;   string str;   int n, k;   int main() {     int i, j, cnt, a, b;     ios::sync_with_stdio(0);     while (cin >> n >> k >> str) {       cnt = 0;       if (k == 2) {         a = 0;         b = 0;         for (i = 0; i < n; i++) {           if (i % 2 == 0) {             if (str[i] ==  B ) a++;             if (str[i] ==  A ) b++;           } else {             if (str[i] ==  A ) a++;             if (str[i] ==  B ) b++;           }         }         if (a < b) {           cout << a <<   n ;           for (i = 0; i < n; i++) cout << ((i % 2 == 0) ?  A  :  B );           cout <<   n ;         } else {           cout << b <<   n ;           for (i = 0; i < n; i++) cout << ((i % 2 != 0) ?  A  :  B );           cout <<   n ;         }         continue;       }       for (i = 0; i < n - 1; i++) {         if (str[i] == str[i + 1] && str[i] == str[i + 2]) {           for (j = 0; j < k; j++) {             if (str[i + 1] != (j +  A )) {               str[i + 1] = (j +  A );               cnt++;               break;             }           }         } else if (str[i] == str[i + 1]) {           for (j = 0; j < k; j++) {             if (i > 0 && str[i - 1] != (j +  A ) && str[i] != (j +  A )) {               str[i] = (j +  A );               cnt++;               break;             } else if (i == 0 && str[i] != (j +  A )) {               str[i] = (j +  A );               cnt++;               break;             }           }         }       }       cout << cnt <<   n ;       cout << str <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200000], dp[600000];   int main() {     int n, l;     cin >> n >> l;     for (int i = 1; i <= n; i++) {       double x;       cin >> a[i] >> x;     }     int maxx = -1;     for (int i = 1; i <= n; i++) {       dp[i] = 1;       for (int j = 1; j < i; j++) {         if (a[i] >= a[j]) dp[i] = max(dp[i], dp[j] + 1);         maxx = max(maxx, dp[i]);       }     }     if (n == 1)       cout << 0 << endl;     else       cout << n - maxx << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int j, i, k, n, m, x;     float d[6000], a[5008], b[5009];     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> a[i] >> b[i];       d[i] = (float)(1.0 * a[i]) / b[i];     }     sort(d, d + n);     printf( %.8f , d[0] * m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long a, b, c;     cin >> a >> b >> c;     a *= 10;     long long q = 0;     for (long long j = 0; j <= 9; j++) {       a += j;       if (a % b == 0) {         q = 1;         break;       } else         a -= j;     }     if (q == 0) {       cout << -1 << endl;       return 0;     }     cout << a;     for (long long i = 0; i < c - 1; i++) cout << 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     stack<int> s;     int ans = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       while (!s.empty()) {         ans = max(ans, s.top() ^ x);         if (x > s.top()) {           s.pop();         } else {           break;         }       }       s.push(x);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   int n, d;   const int geta = 260;   const int MX = 30000;   int dp[30010][520];   int cnt[30010];   int main() {     scanf( %d %d , &n, &d);     for (int i = 0; i < n; i++) {       int k;       scanf( %d , &k);       cnt[k]++;     }     memset(dp, -1, sizeof(dp));     dp[d][geta] = cnt[d];     int ans = 0;     for (int i = d; i <= MX; i++) {       for (int j = 0; j < 520; j++) {         if (dp[i][j] == -1) continue;         chmax(ans, dp[i][j]);         int len = d + (j - geta);         if (len > 1 && i + len - 1 <= MX)           chmax(dp[i + len - 1][j - 1], dp[i][j] + cnt[i + len - 1]);         if (i + len <= MX) chmax(dp[i + len][j], dp[i][j] + cnt[i + len]);         if (i + len + 1 <= MX)           chmax(dp[i + len + 1][j + 1], dp[i][j] + cnt[i + len + 1]);       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long sb[5050], dp[5050][5050], sum[5050], num[5050];   int n, i, j, k;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %lld , &sb[i]);     }     sort(sb + 1, sb + n + 1);     for (i = n, j = n; i >= 1; i--) {       dp[1][i] = 1;       for (; j >= 1; j--) {         if (sb[j] * 2 <= sb[i]) {           num[i] = j;           break;         }       }       num[i] += 2;     }     for (i = 2; i <= n; i++) {       for (j = 1; j <= n; j++) {         dp[i][j] = dp[i - 1][j] * max(num[j] - i, 0ll) % 998244353;         dp[i][j] = (dp[i][j] + sum[num[j] - 2]) % 998244353;         sum[j] = sum[j - 1] + dp[i - 1][j];       }     }     printf( %lld , dp[n][n]);   }
#include <bits/stdc++.h>   using namespace std;   deque<int> check(deque<int> mas) {     int l = 0, r = mas.size() - 1;     bool flag = true;     for (; l < mas.size() / 2; l++, r--) {       if (mas[r] < 0) {         mas[r - 1]--;         mas[r] += 10;       }       if (mas[l] == mas[r] + 1 && l != r - 1) {         mas[l + 1] += 10;         mas[l]--;       }       if (mas[l] == mas[r] + 10 && l != r - 1) {         mas[r - 1]--;         mas[r] += 10;       }       if (mas[l] == mas[r] + 11) {         mas[l]--;         mas[l + 1] += 10;         if (l != r - 1) {           mas[r] += 10;           mas[r - 1]--;         }       }       if (mas[l] != mas[r]) {         flag = false;         break;       }       if (mas[l] > 18) {         flag = false;         break;       }     }     if (flag == false || mas[0] == 0 || mas[mas.size() - 1] == 0) {       deque<int> ans;       ans.push_back(0);       return ans;     } else {       if (mas.size() % 2 == 1 && (mas[l] % 2 == 1 || mas[l] < 0)) {         deque<int> ans;         ans.push_back(0);         return ans;       } else {         deque<int> ans = mas;         l = 0;         r = mas.size() - 1;         for (; l < mas.size() / 2; l++, r--) {           ans[l] = mas[l] - mas[l] / 2;           ans[r] = mas[l] - ans[l];         }         if (mas.size() % 2 == 1) {           ans[l] = mas[l] / 2;         }         return ans;       }     }   }   int main() {     deque<int> x1;     char c;     while (cin >> c) x1.push_back(int(c) - int( 0 ));     deque<int> x2 = x1;     if (x2.size() >= 2) {       x2[1] += x2[0] * 10;       x2.pop_front();     }     deque<int> ans1 = check(x1);     deque<int> ans2 = check(x2);     if (ans1.size() > ans2.size()) {       for (int i = 0; i < ans1.size(); i++) cout << ans1[i];     } else {       for (int i = 0; i < ans2.size(); i++) cout << ans2[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long fac[1100000], inv[1100000], p[1100000];   long long pow_mod(long long a, long long b, long long m) {     long long ans = 1LL;     a %= m;     while (b) {       if (b & 1) ans = ans * a % m;       a = a * a % m;       b >>= 1;     }     return ans;   }   int main() {     fac[0] = 1LL;     inv[0] = pow_mod(fac[0], MOD - 2, MOD);     for (long long i = 1; i <= 1010000; ++i) {       fac[i] = i * fac[i - 1] % MOD;       inv[i] = pow_mod(fac[i], MOD - 2, MOD);     }     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= k + 2; ++i) {       p[i] = p[i - 1] + pow_mod(i, k, MOD);       p[i] %= MOD;     }     if (n <= k + 2) {       cout << p[n] << endl;       return 0;     }     long long x = 1LL;     for (int i = 1; i <= k + 2; ++i) {       x *= (n - i);       x %= MOD;     }     long long ans = 0LL, flag;     for (int i = 1; i <= k + 2; ++i) {       if ((k + 2 - i) & 1)         flag = -1;       else         flag = 1;       ans += x * flag * pow_mod(n - i, MOD - 2, MOD) % MOD * inv[i - 1] % MOD *              inv[k + 2 - i] % MOD * p[i];       (ans += MOD) %= MOD;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int readInt() {     static int n, ch;     n = 0, ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) n = n * 10 + ch -  0 , ch = getchar();     return n;   }   const int MAX_N = 500000 + 3;   int n, k, a[MAX_N], b[MAX_N];   struct Data {     long long val;     bool isA;     Data(long long val, bool isA) : val(val), isA(isA) {}     bool operator<(const Data &ano) const {       return val > ano.val || (val == ano.val && isA < ano.isA);     }   };   priority_queue<Data> pq;   long long sum = 0;   int check(int t) {     while (!pq.empty()) pq.pop();     int cnt = 0;     sum = 0;     for (int i = 0; i < n; ++i) {       pq.push(Data(a[i] - t, true));       if (pq.top().val + b[i] < 0) {         cnt += pq.top().isA;         sum += pq.top().val + b[i];         pq.pop();         pq.push(Data(-b[i], false));       }     }     return cnt;   }   int main() {     n = readInt(), k = readInt();     for (int i = 0; i < n; ++i) a[i] = readInt();     for (int i = 0; i < n; ++i) b[i] = readInt();     int l = 0, r = 2e9 + 3;     while (r - l > 1) {       int mid = ((long long)l + r) / 2;       if (check(mid) <= k)         l = mid;       else         r = mid;     }     check(l);     printf( %I64d n , sum + (long long)k * l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5;   long long n, m, k, a[N], c, res;   struct stru {     long long col, x, l, r;   };   vector<stru> v;   vector<vector<long long>> mp(N), pr(N);   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < n - 1; ++i) {       if (a[i] == a[i + 1])         c++;       else {         v.push_back({a[i], c + 1, i - c, i});         c = 0;       }     }     v.push_back({a[n - 1], c + 1, n - 1 - c, n - 1});     for (long long i = 0; i < v.size(); ++i) {       long long col = v[i].col, l = 0, r = mp[col].size(), med, ni = v[i].l;       r--;       c = v[i].x;       while (r - l > 1) {         med = (r + l) / 2;         if (ni - mp[col][med] - 1 - pr[col].back() + pr[col][med] <= k)           r = med;         else           l = med;       }       if (!mp[col].empty() &&           ni - mp[col][l] - 1 - pr[col].back() + pr[col][l] <= k)         res = max(res, pr[col].back() - (l ? pr[col][l - 1] : 0) + c);       else if (!mp[col].empty() &&                ni - mp[col][r] - 1 - pr[col].back() + pr[col][r] <= k)         res = max(res, pr[col].back() - (r ? pr[col][r - 1] : 0) + c);       else         res = max(res, c);       mp[col].push_back(v[i].r);       if (!pr[col].empty())         pr[col].push_back(pr[col].back() + c);       else         pr[col].push_back(c);     }     cout << res;   }
#include <bits/stdc++.h>   const int N = 2e5 + 5;   using namespace std;   vector<int> G[N];   long long b[N];   int vis[N];   long long ans[N];   long long flag = 1;   void dfs(int x, int fa) {     long long minn = 0x3f3f3f3f;     if (b[x] == -1) {       for (int i = 0; i < G[x].size(); i++) {         int g = G[x][i];         if (!vis[g]) {           vis[g] = 1;           minn = min(minn, b[g]);           dfs(g, x);         }         if (minn != 0x3f3f3f3f)           b[x] = minn;         else           b[x] = b[fa];       }     } else {       for (int i = 0; i < G[x].size(); i++) {         int g = G[x][i];         if (!vis[g]) {           vis[g] = 1;           dfs(g, x);         }       }     }   }   void dfs2(int x, int fa) {     for (int i = 0; i < G[x].size(); i++) {       int g = G[x][i];       if (!vis[g]) {         vis[g] = 1;         ans[g] = b[g] - b[x];         if (ans[g] < 0) {           flag = 0;           return;         }         dfs2(g, x);       }     }   }   int main() {     int n;     cin >> n;     for (int i = 2; i <= n; i++) {       int u;       cin >> u;       G[i].push_back(u);       G[u].push_back(i);     }     for (int i = 1; i <= n; i++) cin >> b[i];     vis[1] = 1;     dfs(1, -1);     memset(vis, 0, sizeof vis);     vis[1] = 1;     ans[1] = b[1];     dfs2(1, -1);     if (flag) {       long long res = 0;       for (int i = 1; i <= n; i++)         if (ans[i] > 0) res += ans[i];       cout << res << endl;     } else       cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   int len(const T& a) {     return a.size();   }   using ll = long long;   constexpr long double EPS = 1e-7;   long double Check(const vector<long double>& a, long double x) {     vector<long double> new_a(a.size());     long double bestmin = 1e8, curmin = 0;     long double bestmax = -1e8, curmax = 0;     for (int i = 0; i < len(a); ++i) {       new_a[i] = (long double)a[i] - x;       curmax = max((long double)0, curmax + new_a[i]);       bestmax = max(bestmax, curmax);       curmin = min((long double)0, curmin + new_a[i]);       bestmin = min(bestmin, curmin);     }     return max(abs(bestmin), abs(bestmax));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(6);     int n;     cin >> n;     vector<long double> a(n);     for (auto& i : a) cin >> i;     long double l = -1e4 - 10, r = 1e4 + 10;     for (int step = 0; step < 200; ++step) {       long double m1 = l + (r - l) / 3.0;       long double m2 = r - (r - l) / 3.0;       if (Check(a, m1) - Check(a, m2) > EPS) {         l = m1;       } else {         r = m2;       }     }     cout << Check(a, l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, K, mp[1005][1005];   int main() {     memset(mp, 0, sizeof(mp));     n = read();     m = read();     K = read();     for (int i = 1; i <= K; i++) {       int x = read(), y = read();       mp[x][y] = 1;       if (mp[x + 1][y] && mp[x][y + 1] && mp[x + 1][y + 1]) {         cout << i << endl;         return 0;       }       if (mp[x + 1][y] && mp[x][y - 1] && mp[x + 1][y - 1]) {         cout << i << endl;         return 0;       }       if (mp[x - 1][y] && mp[x][y + 1] && mp[x - 1][y + 1]) {         cout << i << endl;         return 0;       }       if (mp[x - 1][y] && mp[x][y - 1] && mp[x - 1][y - 1]) {         cout << i << endl;         return 0;       }     }     cout << 0 << endl;     return 0;   }