malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int M = 1e5 + 50;   map<int, int> vis, cnt;   int main() {     int n;     long long ans = 0;     scanf( %lld , &n);     for (int i = 0; i < n; i++) {       int ch, tmp;       scanf( %d , &ch);       if (!vis[ch]) {         vis[ch] = 1;         cnt[ch] = vis.size() - 1;         tmp = vis.size() - 1;       } else {         tmp = vis.size() - cnt[ch];         cnt[ch] = vis.size();       }       ans += 1ll * tmp;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a = 0, b, c, d, i, j;     char s[116][116];     cin >> n >> m;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         cin >> s[i][j];       }     }     for (i = 1; i <= n && a == 0; i++) {       for (j = 1; j <= m; j++) {         if (s[i][j] ==  B ) {           a = i;           break;         }       }     }     for (i = a, j = 1; j <= m; j++) {       if (s[i][j] ==  B ) {         b = j;         break;       }     }     for (i = a, j = m; j > 0; j--) {       if (s[i][j] ==  B ) {         c = j;         break;       }     }     d = (c - b) / 2;     cout << a + d <<     << c - d;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5010;   int f[MAXN];   string s;   int l;   int ans[MAXN];   int help[MAXN];   int nim[MAXN];   int start[MAXN];   void init() {     f[0] = 0;     f[1] = 1;     for (int i = 2; i <= l; ++i) {       memset(nim, 0, sizeof(nim));       nim[f[i - 2] ^ f[0]] = 1;       for (int j = 2; j <= i - 1; ++j) nim[f[i - j - 1] ^ f[j - 2]] = 1;       for (int j = 0;; ++j)         if (nim[j] == 0) {           f[i] = j;           break;         }     }   }   int main() {     cin >> s;     l = s.size();     init();     int top = 0;     for (int i = 1; i < l - 1; ++i)       if (s[i - 1] == s[i + 1]) ans[++top] = i;     int cnt = 0;     if (top >= 1) {       help[1] = 1;       start[1] = ans[1];       cnt = 1;     }     for (int i = 2; i <= top; ++i)       if (ans[i] == ans[i - 1] + 1)         help[cnt]++;       else {         cnt++;         help[cnt] = 1;         start[cnt] = ans[i];       }     int out = 0;     for (int i = 1; i <= cnt; ++i) out = out ^ f[help[i]];     if (!out)       cout <<  Second  << endl;     else {       cout <<  First  << endl;       for (int j = 1; j <= cnt; ++j) {         if (help[j] == 1) {           if (!out ^ f[help[j]]) {             cout << start[j] + 1 << endl;             return 0;           }         }         if (!(out ^ f[help[j]] ^ f[help[j] - 2])) {           cout << start[j] + 1 << endl;           return 0;         }         for (int k = 2; k <= help[j] - 1; ++k)           if (!(out ^ f[help[j]] ^ f[help[j] - k - 1] ^ f[k - 2])) {             cout << start[j] + k << endl;             return 0;           }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int skip_classes[501][501], dp[501][501], N, M, K;   vector<int> timings[501];   vector<string> grid(501);   void preprocess() {     for (long long int i = 1; i <= N; i++) {       int total_classes_on_day_i = timings[i].size();       for (int skip = 0; skip <= K; skip++) {         skip_classes[i][skip] = INT_MAX;         int to_attend = total_classes_on_day_i - skip;         if (to_attend <= 0)           skip_classes[i][skip] = 0;         else           for (int j = to_attend - 1; j < timings[i].size(); j++) {             skip_classes[i][skip] =                 (skip_classes[i][skip] <=                          timings[i][j] - timings[i][j - to_attend + 1] + 1                      ? skip_classes[i][skip]                      : timings[i][j] - timings[i][j - to_attend + 1] + 1);           }       }     }     return;   }   long long int solve_for(long long int day, long long int can_skip) {     if (can_skip < 0) return INT_MAX;     if (day == 0) return 0;     if (dp[day][can_skip] != -1) return dp[day][can_skip];     long long int ans = INT_MAX, current_ans;     for (long long int i = 0; i <= can_skip; i++) {       current_ans = solve_for(day - 1, can_skip - i) + skip_classes[day][i];       ans = (ans <= current_ans ? ans : current_ans);     }     return dp[day][can_skip] = ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof dp);     cin >> N >> M >> K;     for (long long int i = 1; i <= N; i++) {       cin >> grid[i];       for (int j = 0; j < grid[i].size(); j++) {         if (grid[i][j] ==  1 ) timings[i].push_back(j + 1);       }     }     preprocess();     long long int ans = solve_for(N, K);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> years;     int curr = 1;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       if (x == curr) {         ++curr;         years.push_back(2000 + i);       }     }     cout << years.size() << endl;     for (int year : years) {       cout << year <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, a[100005];   bool pos(int len) {     set<pair<int, int> > ms;     for (int i = 1; i <= n; i++) {       ms.insert(make_pair(a[i], i));       if (i >= len) {         auto it = ms.begin();         int mn = (*it).first;         it = ms.end();         it--;         int mx = (*it).first;         if (mx - mn <= k) return 1;         ms.erase(make_pair(a[i - len + 1], i - len + 1));       }     }     return 0;   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     int hi = n, lo = 1;     while (hi > lo) {       int mid = (hi + lo + 1) / 2;       if (pos(mid))         lo = mid;       else         hi = mid - 1;     }     int len = hi;     vector<int> ans;     set<pair<int, int> > ms;     for (int i = 1; i <= n; i++) {       ms.insert(make_pair(a[i], i));       if (i >= len) {         auto it = ms.begin();         int mn = (*it).first;         it = ms.end();         it--;         int mx = (*it).first;         if (mx - mn <= k) ans.push_back(i - len + 1), ans.push_back(i);         ms.erase(make_pair(a[i - len + 1], i - len + 1));       }     }     printf( %d %d n , hi, (int)ans.size() / 2);     for (int i = 0; i < ans.size(); i += 2) printf( %d %d n , ans[i], ans[i + 1]);   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int cnt[10];   int ans[5], id[5];   int main() {     int n, s;     scanf( %d%d , &n, &s);     int a;     for (int i = 0; i < n; i++) {       scanf( %d , &a);       cnt[a]++;     }     int A, B, C, mx = 0x3f3f3f3f;     for (int i = s / n; i >= 0; i--) {       id[0] = i;       A = cnt[3] * id[0];       for (int j = (s - A) / (cnt[4] + cnt[5]); j >= i; j--) {         id[1] = j;         B = cnt[4] * id[1];         C = s - A - B;         id[2] = C / cnt[5];         if (C % cnt[5]) continue;         int tmp = abs(A - B) + abs(B - C);         if (tmp >= mx && B <= C) break;         if (tmp < mx) {           ans[0] = id[0];           ans[1] = id[1];           ans[2] = id[2];           mx = tmp;         }       }     }     if (mx == 0x3f3f3f3f)       puts( -1 );     else       printf( %d %d %d n , ans[0], ans[1], ans[2]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, ans = 0;     cin >> n;     string x;     cin >> x;     for (long long int i = 0; i < x.length(); i++) {       if (x[i] ==  0  || x[i] ==  2  || x[i] ==  4  || x[i] ==  6  ||           x[i] ==  8 ) {         ans += (i + 1);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int r, c, d[1020][1020], used[1020][1020];   string s[1020];   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   long long ans = 0;   bool ok(int x, int y) {     return x >= 0 && x < r && y >= 0 && y < c && s[x][y] !=  T ;   }   void bfs(int x, int y) {     used[x][y] = 1;     queue<pair<int, int> > q;     q.push(make_pair(x, y));     d[x][y] = 0;     while (q.empty() == false) {       int xk = q.front().first, yk = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         int xx = xk + dx[i];         int yy = yk + dy[i];         if (ok(xx, yy) == true && used[xx][yy] == 0) {           used[xx][yy] = 1;           d[xx][yy] = d[xk][yk] + 1;           q.push(make_pair(xx, yy));         }       }     }   }   int main() {     scanf( %d %d , &r, &c);     int sx, sy, ex, ey;     for (int i = 0; i < r; i++) {       cin >> s[i];       for (int j = 0; j < c; j++) {         if (s[i][j] ==  S ) {           sx = i;           sy = j;           s[i][j] =  0 ;         } else if (s[i][j] ==  E ) {           ex = i;           ey = j;           s[i][j] =  0 ;         }       }     }     bfs(ex, ey);     int need = d[sx][sy];     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (s[i][j] ==  T  && i == sx && j == sy) continue;         int add = (int)(s[i][j] -  0 );         if (d[i][j] <= need && d[i][j] != 0) {           ans += add;         }       }     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, mp[5][1000050];   int sta[20], cnt[20], tot;   char s[1000050];   int f[1000050][20], ans;   void init() {     for (int i = 0; i < (1 << n); i++) {       sta[++tot] = i;       int u = i;       while (u) {         cnt[tot] += ((u % 2) ^ 0);         u >>= 1;       }     }   }   int change(int id, int y) {     int ans = 0, status = sta[id];     for (int i = n; i >= 1; i--, status >>= 1) ans += ((status % 2) ^ mp[i][y]);     return ans;   }   void dp() {     init();     memset(f, 0x3f, sizeof f);     for (int i = 1; i <= tot; i++) f[1][i] = change(i, 1);     for (int i = 2; i <= m; i++)       for (int j = 1; j <= tot; j++)         for (int k = 1; k <= tot; k++) {           int a = sta[j], b = sta[k];           int last = a % 2 + b % 2, now, flag = 1;           a >>= 1;           b >>= 1;           for (int l = n - 1; l >= 1; l--) {             now = a % 2 + b % 2;             a >>= 1;             b >>= 1;             if ((last + now) % 2 == 0) flag = 0;             last = now;           }           if (flag) f[i][j] = min(f[i][j], f[i - 1][k] + change(j, i));         }   }   int main() {     scanf( %d%d , &n, &m);     if (min(n, m) >= 4) {       printf( -1 );       return 0;     }     if (n == 1) {       printf( 0 );       return 0;     }     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= m; j++) mp[i][j] = s[j] -  0 ;     }     dp();     ans = n * m;     for (int i = 1; i <= tot; i++) ans = min(ans, f[m][i]);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long INF = 1e9;   const int MX = 2e5 + 10;   const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0};   template <class T>   using V = vector<T>;   template <class T>   bool ckmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   long long cdiv(long long a, long long b) {     return a / b + ((a ^ b) > 0 && a % b);   }   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   long long random(long long a, long long b) { return a + rng() % (b - a + 1); }   void IO() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     IO();     int N;     cin >> N;     vector<int> a(N);     for (int i = (0); i < (N); ++i) cin >> a[i];     int cnt[101];     fill(cnt, cnt + 101, 0);     int mx = 0, D;     for (auto x : a) {       cnt[x]++;       if (ckmax(mx, cnt[x])) D = x;     }     int ans = 0;     for (int V = (1); V < (101); ++V)       if (V != D) {         vector<int> v(N);         for (int i = (0); i < (N); ++i) {           if (a[i] == D)             v[i] = 1;           else if (a[i] == V)             v[i] = -1;           else             v[i] = 0;         }         unordered_map<int, int> pre;         int s = 0;         for (int i = (0); i < (N); ++i) {           s += v[i];           pre[s] = INF;         }         pre[0] = -1;         for (int i = (0); i < (N); ++i) {           if (i) v[i] += v[i - 1];           ckmax(ans, i - pre[v[i]]);           if (pre[v[i]] == INF) pre[v[i]] = i;         }       }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, m;   int a[100010];   long long f[110][100010], n;   long long dfs(int n, long long m) {     if (!n) return m;     if (m < 100010 && f[n][m] >= 0) return f[n][m];     long long A = dfs(n - 1, m) - dfs(n - 1, m / a[n]);     if (m < 100010) f[n][m] = A;     return A;   }   int main() {     scanf( %I64d%d , &n, &m);     for (i = 1; i <= m; i++) scanf( %d , &a[i]);     sort(a + 1, a + m + 1);     memset(f, 255, sizeof(f));     printf( %I64d n , dfs(m, n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s, t;     cin >> s >> t;     int sum1 = 0, sum2 = 0, sum3 = 0;     for (int i = 0; i < 2 * n; i++) {       if (s[i] ==  1  && t[i] ==  1 ) {         sum3++;         continue;       }       sum1 += (s[i] ==  1 );       sum2 += (t[i] ==  1 );     }     if (sum3 % 2) {       if (sum1 + 1 == sum2 || sum1 + 2 == sum2) {         cout <<  Draw n ;       } else {         cout << ((sum1 >= sum2) ?  First  :  Second ) <<   n ;       }     } else {       if (sum1 == sum2 || sum1 + 1 == sum2) {         cout <<  Draw n ;       } else {         cout << ((sum1 > sum2) ?  First  :  Second ) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ni() {     int a;     scanf( %d , &a);     return a;   }   double nf() {     double a;     scanf( %lf , &a);     return a;   }   char sbuf[100005];   string ns() {     scanf( %s , sbuf);     return sbuf;   }   long long nll() {     long long a;     scanf( %lld , &a);     return a;   }   template <class T>   void out(T a, T b) {     bool first = true;     for (T i = a; i != b; ++i) {       if (!first) printf(   );       first = false;       cout << *i;     }     printf(  n );   }   template <class T>   void outl(T a, T b) {     for (T i = a; i != b; ++i) {       cout << *i <<   n ;     }   }   int n, m;   int ans[100005];   int main() {     int i, j, k;     vector<pair<pair<int, int>, int> > v;     n = ni();     for (i = (0); i < (((n))); ++i) {       int a = ni();       int b = ni();       v.push_back(make_pair(make_pair(a, b), i));     }     sort((v).begin(), (v).end());     reverse((v).begin(), (v).end());     vector<pair<int, int> > s;     vector<int> sa;     for (i = (0); i < (((v.size()))); ++i) {       pair<int, int> last = make_pair(-1, -1);       pair<int, int> vv = v[i].first;       int aa = 1;       while (s.size()) {         if (s.back().first >= vv.first + vv.second)           break;         else {           if (last.second == -1 || last.first + last.second <= s.back().first)             aa += sa.back();           if (vv.first + vv.second >= s.back().first + s.back().second) {             last = s.back();             s.pop_back();             sa.pop_back();           } else             break;         }       }       s.push_back(vv);       sa.push_back(aa);       ans[v[i].second] = aa;     }     out(ans, ans + n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 0x3f3f3f3f;   const double EPS = 1e-6;   const double PI = acos(-1.0);   string second;   int ch = 0;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> second;     for (int i = 0; second[i]; i++) {       while (ch != second[i] + 1) {         ch--;         cout <<  ... n.X. n... n ;         if (ch < 0) ch = 255;       }       cout <<  .X. n.X. n... n ;       ch--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, a[N];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     if (a[n] >= a[n - 1] + a[n - 2])       cout <<  NO ;     else {       cout <<  YES n ;       cout << a[n] <<    ;       for (int i = n - 2; i >= 1; i--) cout << a[i] <<    ;       cout << a[n - 1];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, result = 0;     {       cin >> n;       float init = sqrt(n);       if (init == floor(init))         cout << init * 4 << endl;       else {         int init2 = floor(init);         n = n - init2 * init2;         result = init2 * 4;         if (n > init2) {           int temp1 = n / 2;           result = result + (temp1 + 1) * 2 - temp1 * 2;           int temp2 = n - n / 2;           result = result + (temp2 + 1) * 2 - temp2 * 2;         } else           result = result + (n + 1) * 2 - n * 2;         cout << result << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long FASTIO = []() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     return 0;   }();   long long n;   vector<vector<long long>> ans;   long long ask(long long x1, long long y1, long long x2, long long y2) {     cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 <<   n ;     cout.flush();     long long c;     cin >> c;     if (c == -1) {       while (1) {       }     }     return c;   }   void bfs(long long x, long long y) {     vector<vector<long long>> used(n + 5, vector<long long>(n + 5, true));     vector<long long> v1 = {2, 1, 0, 0, -1, -2};     vector<long long> v2 = {0, 1, 2, -2, -1, 0};     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         used[i][j] = false;       }     }     queue<pair<long long, long long>> q;     q.push({x, y});     used[x][y] = true;     while (!q.empty()) {       long long X = q.front().first;       long long Y = q.front().second;       q.pop();       for (long long i = 0; i < 6; i++) {         if (X + v1[i] > 0 && Y + v2[i] > 0 && !used[X + v1[i]][Y + v2[i]]) {           pair<long long, long long> a = {X, Y}, b = {X + v1[i], Y + v2[i]};           if (v1[i] < 0 || v2[i] < 0) {             swap(a, b);           }           if (b != pair<long long, long long>{n, n}) {             bool t = ask(a.first, a.second, b.first, b.second);             if (t) {               ans[X + v1[i]][Y + v2[i]] = ans[X][Y];             } else {               ans[X + v1[i]][Y + v2[i]] = !ans[X][Y];             }           }           used[X + v1[i]][Y + v2[i]] = true;           q.push({X + v1[i], Y + v2[i]});         }       }     }   }   signed main() {     cin >> n;     ans.resize(n + 10, vector<long long>(n + 10, -1));     ans[1][1] = 1;     ans[n][n] = 0;     bfs(1, 1);     long long p = 1;     while (ans[p][p] == ans[p + 2][p + 2]) {       ++p;     }     if (ask(p, p, p + 2, p + 1)) {       ans[p + 2][p + 1] = ans[p][p];       bfs(p + 2, p + 1);     } else if (ask(p + 1, p, p + 2, p + 2)) {       ans[p + 1][p] = ans[p + 2][p + 2];       bfs(p + 1, p);     } else {       if (ans[p + 2][p] == 1) {         ans[p + 2][p + 1] = 0;         bfs(p + 2, p + 1);       } else {         ans[p + 1][p] = 1;         bfs(p + 1, p);       }     }     cout <<  ! n ;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         cout << ans[i][j];       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l[2005], r[2005], t, k;     cin >> t;     while (t) {       int q = 0, next = 0;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> l[i] >> r[i];         if (i == 0) {           next = l[i] + 1;           cout << l[i] <<    ;           continue;         }         if (r[i] < next) {           cout << 0 <<    ;         } else if (l[i] <= next) {           cout << next <<    ;           next++;         } else {           cout << l[i] <<    ;           next = l[i] + 1;         }       }       cout << endl;       t--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[500005], b[500005];   char s[500005];   int res = 1e9, xx, yy;   int calc2(int x, int y) {     if (x == 0 && y == 0) return 1000000000;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (x <= a[i] && y <= b[i])         ans = max(ans, max(a[i] - x, b[i] - y));       else if (x <= a[i] || y <= b[i])         ans = max(ans, abs(a[i] - x) + abs(b[i] - y));       else         ans = max(ans, max(x - a[i], y - b[i]));     }     if (ans < res) {       res = ans;       xx = x, yy = y;     }     return ans;   }   int calc1(int x) {     int l = 0, r = 500000;     if (x == 0) l = 1;     while (l <= r) {       int mid = (l + r) >> 1;       if (calc2(x, mid) < calc2(x, mid + 1))         r = mid - 1;       else         l = mid + 1;     }     return min(calc2(x, l), calc2(x, r));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       int x = (int)strlen(s + 1);       for (int j = 1; j <= x; j++) {         if (s[j] ==  N )           a[i]++;         else           b[i]++;       }     }     int l = 0, r = 500000;     while (l <= r) {       int mid = (l + r) >> 1;       int v1 = calc1(mid), v2 = calc1(mid + 1);       if (v1 < v2)         r = mid - 1;       else if (v1 > v2)         l = mid + 1;       else {         int v3 = calc1(mid + 2);         if (v1 < v3)           r = mid - 1;         else if (v1 > v3)           l = mid + 1;         else           break;       }     }     printf( %d n , res);     for (int i = 1; i <= xx; i++) putchar( N );     for (int i = 1; i <= yy; i++) putchar( B );     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, num, l, r;     string str, res;     cin >> n;     l = 1e9;     l = l * (-2);     r = 1e9;     r = r * (2);     while (n--) {       cin >> str >> num >> res;       if (str ==  > ) {         if (res ==  Y )           l = max(l, num + 1);         else           r = min(r, num);       } else if (str ==  >= ) {         if (res ==  Y )           l = max(l, num);         else           r = min(r, num - 1);       } else if (str ==  < ) {         if (res ==  Y )           r = min(r, num - 1);         else           l = max(l, num);       } else {         if (res ==  Y )           r = min(r, num);         else           l = max(l, num + 1);       }     }     if (l > r)       cout <<  Impossible ;     else       cout << l;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<1005> b[1005];   int n, m;   bool ok2(int r, int c) {     if (r + 2 > n || c + 2 > n) return false;     for (int i = r; i < r + 3; i++)       for (int j = c; j < c + 3; j++) {         if (!b[i].test(j)) return false;       }     return true;   }   bool ok(int r, int c) {     if (n < 3) return false;     for (int i = r - 2; i <= r; i++) {       if (i <= 0) continue;       for (int j = c - 2; j <= c; j++) {         if (j <= 0) continue;         if (ok2(i, j)) return true;       }     }     return false;   }   int main() {     int r, c;     bool bOK = false;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &r, &c);       b[r].set(c);       if (ok(r, c)) {         bOK = true;         printf( %d n , i);         break;       }     }     if (!bOK) printf( -1 n );     return 0;   }