malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int main() {     string s;     cin >> s;     int i, l = 0, can = 0, can_too = 0;     for (i = 0; i < s.length(); i++) {       if (s[i] ==  @  && can == 0) {         can = 1;         a.push_back(i);       } else if (s[i] ==  .  && can && !can_too) {         a.push_back(i);       } else if (s[i] ==  /  && can) {         can_too = 1;         a.push_back(i);       }     }     for (i = 0; i < a.size(); i++) {       int ta, tb;       if (i == 0) {         ta = -1;         tb = a[i];       } else {         ta = a[i - 1];         tb = a[i];       }       if (abs(ta - tb) == 1) {         cout <<  NO  << endl;         return 0;       }       for (int j = ta + 1, l = 0; j < tb; j++) {         l++;         if ((s[j] <  a  || s[j] >  z ) && (s[j] <  A  || s[j] >  Z ) &&             (s[j] <  0  || s[j] >  9 ) && s[j] !=  _ ) {           cout <<  NO  << endl;           return 0;         } else if (l > 16) {           cout <<  NO  << endl;           return 0;         }       }       if (i == a.size() - 1) {         ta = a[i];         tb = s.length();         if (abs(ta - tb) == 0) {           cout <<  NO  << endl;           return 0;         }         for (int j = ta + 1, l = 0; j < tb; j++) {           l++;           if ((s[j] <  a  || s[j] >  z ) && (s[j] <  A  || s[j] >  Z ) &&               (s[j] <  0  || s[j] >  9 ) && s[j] !=  _ ) {             cout <<  NO  << endl;             return 0;           } else if (l > 16) {             cout <<  NO  << endl;             return 0;           }         }       }     }     int px = 0, py = 0;     for (i = 0; i < a.size(); i++) {       if (s[a[i]] ==  @ ) {         px = a[i];         break;       }     }     for (i = 0; i < a.size(); i++) {       if (s[a[i]] ==  / ) {         py = a[i];         break;       }     }     if (abs(py - px - 1) > 32 && px && py) {       cout <<  NO  << endl;       return 0;     }     if (a.size() == 0) {       cout <<  NO  << endl;       return 0;     }     if (a.size() == 1 && a[0] == s.length() - 1) {       cout <<  NO  << endl;       return 0;     }     for (i = 0; i < a.size(); i++) {       if (a[i] + 1 == s.length()) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     int n;     int k;     cin >> n >> k;     auto dp = vector<int>(n);     auto mas = vector<int>(n);     for (int i = 0; i < n; ++i) cin >> mas[i];     if (k == n || k == n - 1) {       for (int i = 0; i < n; ++i) cout << n <<    ;       return 0;     }     dp[0] = 1 + k;     for (int i = 1; i < n; ++i)       if (mas[i] == 0)         dp[i] = 1 + min(i - 0, k) + min(n - 1 - i, k);       else if (i - mas[i] >= 2 * k)         dp[i] = 1 + k + min(n - 1 - i, k) + dp[mas[i] - 1];       else {         if (i <= k)           dp[i] = 1 + min(i - 0, k) + min(n - 1 - i, k);         else if (n - mas[i] <= k)           dp[i] = dp[mas[i] - 1];         else           dp[i] = 1 + k + min(n - 1 - i, k) + dp[mas[i] - 1] -                   ((mas[i] - 1 + k) - (i - k) + 1);       }     for (int i = 0; i < n; ++i) cout << dp[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[1000000 + 342];   set<int> ans;   bool incl[1000000 + 342];   bool isleader[1000000 + 342];   map<pair<int, int>, bool> egd;   int main() {     ios::sync_with_stdio(false);     int n, m, x, y;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> x >> y;       if (egd[make_pair(x, y)] == false) {         adj[x].push_back(y);         egd[make_pair(x, y)] = true;       }     }     for (int i = 1; i <= n; i++) {       if (incl[i] == false) {         for (auto next : adj[i]) {           if (next > i)             if (incl[next] == false) {               incl[next] = true;             }         }       }     }     for (int i = n; i >= 1; i--) {       if (incl[i] == false) {         ans.insert(i);         for (auto next : adj[i]) {           incl[next] = true;         }       }     }     cout << ans.size() <<   n ;     for (auto bc : ans) cout << bc <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, les, m, f[5010], g[5010];   char s[5010];   template <class Aqua>   inline void read(Aqua &s) {     s = 0;     Aqua f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) s = s * 10 + c -  0 , c = getchar();     s *= f;   }   int main() {     scanf( %s , s + 1);     m = n = strlen(s + 1);     for (les = 1; n; n >>= 1, les <<= 1)       ;     (les >>= 1)--;     for (int i = 0; i <= les; i++) f[i] = 1;     for (int i = 1; i <= m - les; i++) {       char mn =  z  + 1;       for (int j = 0; j <= les; j++)         if (f[j]) mn = min(mn, s[i + j]);       putchar(mn);       for (int j = 0; j <= les; j++) {         if (f[j] && s[i + j] == mn)           g[j] = 1;         else {           g[j] = 0;           for (int k = 0; (1 << k) <= j; k++)             if ((j >> k) & 1) g[j] |= g[j ^ (1 << k)];         }       }       memcpy(f, g, sizeof(g));     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, l[1010], ch, h = 0, kol = 0;   int main() {     cin >> n;     memset(l, 0, sizeof l);     for (int i = 0; i < n; ++i) {       cin >> ch;       ++l[ch];     }     for (int i = 0; i <= 1000; ++i) {       if (l[i]) ++kol;       h = max(h, l[i]);     }     cout << h <<     << kol;     return 0;   }
#include <bits/stdc++.h>   const size_t N = 2 * 100002;   int main(void) {     long long n, k, res = 0;     std::cin >> n >> k;     int arr[N];     for (long long i = 0; i < n; ++i) std::cin >> arr[i];     int next[N];     next[n - 1] = n;     for (long long i = n - 2; i >= 0; --i)       next[i] = arr[i + 1] != 1 ? i + 1 : next[i + 1];     for (long long left = 0; left < n; ++left) {       long long right = left;       long long mult = arr[left];       long long sum = arr[left];       if (mult == sum * k) res += 1;       while (next[right] != n) {         if (LLONG_MAX / mult < arr[next[right]]) break;         mult *= arr[next[right]];         sum += next[right] - right - 1 + arr[next[right]];         right = next[right];         int k_mult = 0;         if (mult % k == 0) k_mult = mult / k;         if (sum <= k_mult && k_mult <= sum + next[right] - right - 1) res += 1;       }     }     std::cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int SIZE = 1e6 + 10;   char A[SIZE];   long long d[SIZE];   int len;   vector<long long> D;   long long dp[2][4000][2][2];   void ADD(long long &x, long long v) { x = (x + v) % MOD; }   long long CC(long long x) { return x * (x - 1) / 2 % MOD; }   long long con(long long x, long long y) {     if (x > y) return 0;     return (x + y) * (y - x + 1) / 2 % MOD;   }   int main() {     int p, a;     scanf( %d%d , &p, &a);     scanf( %s , (A));     len = strlen(A);     for (int i = 0; i < (len); ++i) {       d[len - 1 - i] = A[i] -  0 ;     }     int top = len - 1;     while (top >= 0) {       long long r = 0;       for (int i = top; i >= 0; i--) {         r *= 10;         d[i] += r;         r = d[i] % p;         d[i] /= p;       }       D.push_back(r);       while (top >= 0 && d[top] == 0) top--;     }     if (a >= ((int)(D).size())) return 0 * puts( 0 );     int now = 0, nxt = 1;     dp[now][0][1][0] = 1;     for (int i = ((int)(D).size()) - 1; i >= 0; i--) {       memset((dp[nxt]), 0, sizeof((dp[nxt])));       for (int j = 0; j < (a + 1); ++j) {         ADD(dp[nxt][j][1][0], dp[now][j][1][1] * (p - 1 - D[i]));         ADD(dp[nxt][min(j + 1, a)][1][1], dp[now][j][1][1] * (p - D[i]));         ADD(dp[nxt][j][0][0], dp[now][j][1][1] * con(p - D[i], p - 1));         ADD(dp[nxt][min(j + 1, a)][0][1],             dp[now][j][1][1] * con(p - D[i] + 1, p));         ADD(dp[nxt][j][1][0], dp[now][j][1][0] * (D[i] + 1));         ADD(dp[nxt][min(j + 1, a)][1][1], dp[now][j][1][0] * D[i]);         ADD(dp[nxt][j][0][0], dp[now][j][1][0] * con(1, D[i]));         ADD(dp[nxt][min(j + 1, a)][0][1], dp[now][j][1][0] * con(1, D[i] - 1));         ADD(dp[nxt][j][0][0], dp[now][j][0][1] * con(1, p - 1));         ADD(dp[nxt][min(j + 1, a)][0][1], dp[now][j][0][1] * con(1, p));         ADD(dp[nxt][j][0][0], dp[now][j][0][0] * con(1, p));         ADD(dp[nxt][min(j + 1, a)][0][1], dp[now][j][0][0] * con(1, p - 1));       }       swap(now, nxt);     }     long long an = 0;     for (int j = 0; j < (2); ++j) ADD(an, dp[now][a][j][0]);     cout << an;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void dbs(string str, T t) {     cerr << str <<   :   << t <<   n ;   }   template <class T, class... S>   void dbs(string str, T t, S... s) {     int idx = str.find( , );     cerr << str.substr(0, idx) <<   :   << t <<  , ;     dbs(str.substr(idx + 1), s...);   }   template <class S, class T>   ostream& operator<<(ostream& os, const pair<S, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& os, const map<S, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   void prc(T a, T b) {     cerr <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cerr <<  ,  ;       cerr << *i;     }     cerr <<  ] n ;   }   const int N = 100010;   const int LOG = 18;   string s;   int n;   int p[LOG][N];   pair<pair<int, int>, int> vec[N];   pair<int, int> suff[N];   int save[N];   int lcp(int a, int b) {     int temp = a;     for (int i = LOG - 1; i >= 0 and max(a, b) < n; i--) {       if (p[i][a] == p[i][b]) {         a += (1 << i), b += (1 << i);       }     }     return a - temp;   }   int main() {     cin >> s;     n = int(s.size());     for (int i = (int)(0); i <= (int)(n - 1); i++) {       p[0][i] = s[i];     }     for (int i = (int)(1); i <= (int)(LOG - 1); i++) {       for (int j = (int)(0); j <= (int)(n - 1); j++) {         if (j + (1 << (i - 1)) >= n) {           vec[j] = make_pair(make_pair(p[i - 1][j], -1), j);         } else {           vec[j] =               make_pair(make_pair(p[i - 1][j], p[i - 1][j + (1 << (i - 1))]), j);         }       }       sort(vec, vec + n);       for (int j = (int)(1); j <= (int)(n - 1); j++) {         if (vec[j].first == vec[j - 1].first) {           p[i][vec[j].second] = p[i][vec[j - 1].second];         } else {           p[i][vec[j].second] = j;         }       }     }     for (int i = (int)(0); i <= (int)(n - 1); i++) {       suff[i] = make_pair(p[LOG - 1][i], i);     }     sort(suff, suff + n);     for (int i = (int)(0); i <= (int)(n - 2); i++) {       save[i] = lcp(suff[i].second, suff[i + 1].second);     }     long long answer1 = 0;     stack<pair<long long, long long>> s1;     s1.push(make_pair(save[0], 1));     long long currSum = save[0];     for (int i = (int)(1); i <= (int)(n - 1); i++) {       answer1 += currSum;       long long x = save[i], cnt = 1;       if (i == n - 1) break;       while (!s1.empty() and s1.top().first > x) {         currSum -= s1.top().first * s1.top().second;         cnt += s1.top().second;         s1.pop();       }       s1.push(make_pair(save[i], cnt));       currSum += x * cnt;     }     cout << answer1 + (n * 1LL * (n + 1)) / 2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   int inp() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int sum = 0;     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum;   }   int n, x[200010];   long long ans[200010], sum[200010];   void solve(int a, int b) {     if (a == b) return;     if (a > b) std::swap(a, b);     sum[1] += b - a;     sum[a] -= b - a;     sum[b + 1] += b - a;     sum[a + 1] += (b - a - 1);     sum[b] -= (b - a - 1);     ans[a] += b - 1;     ans[b] += a;   }   int main() {     n = inp();     int m = inp();     for (int i = 1; i <= m; i++) x[i] = inp();     for (int i = 1; i < m; i++) solve(x[i], x[i + 1]);     long long tot = 0;     for (int i = 1; i <= n; i++) {       tot += sum[i];       printf( %lld  , tot + ans[i]);     }     putchar(  n );   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long maxn = 1e5 + 7;   const long long maxe = 1e6 + 7;   const long long INF = 1e9 + 7;   const double PI = acos(-1);   int dx[4] = {0, 0, 1, -1};   int dy[4] = {-1, 1, 0, 0};   inline void Max(int &a, int b) {     if (b > a) a = b;   }   inline void Min(int &a, int b) {     if (a == -1 || b < a) a = b;   }   int n, t, p, L;   pair<int, int> dp[maxn];   int l[maxn], r[maxn];   void update(int k, pair<int, int> t) {     if (dp[k].first < t.first)       dp[k] = t;     else if (dp[k].first == t.first)       dp[k].second = min(dp[k].second, t.second);   }   int main() {     cin >> L >> n >> p >> t;     for (int i = 1; i <= n; i++) scanf( %d%d , &l[i], &r[i]);     dp[0] = make_pair(0, -INF);     for (int i = 1, j = 0; i <= n; i++) {       if (j) j--;       for (; j < i && dp[j].second + t <= r[i]; j++) {         int pos = max(dp[j].second + t, l[i]);         int num = (r[i] - pos) / p;         update(i, make_pair(num + dp[j].first, pos + num * p));       }       update(i, dp[i - 1]);     }     cout << dp[n].first << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 0, 1, -1}, dy[] = {-1, 1, 0, 0};   const int dxx[] = {0, 0, 1, -1, -1, -1, 1, 1},             dyy[] = {-1, 1, 0, 0, 1, -1, 1, -1};   ifstream f(  );   ofstream g(  );   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long n, m, prv = 0, prvmax = -1;     cin >> n >> m;     vector<int> v(0);     for (int a; n; n--) cin >> a, v.push_back(a);     vector<pair<long long, long long> > w(0);     for (int a, b; m; m--) cin >> a >> b, w.push_back({a, b});     sort(w.begin(), w.end());     for (int i = 0; i <= w.size() - 1; i++) {       w[i].first = max(w[i].first, prvmax);       prvmax = w[i].first;       w[i].second += prv;       prv = w[i].second;     }     for (auto i : v)       if (i < w.front().first)         cout <<  0  ;       else if (i >= w.back().first)         cout << w.back().second <<    ;       else {         int st = 0, dr = w.size() - 1, rz;         while (st <= dr) {           int m = (st + dr) / 2;           if (w[m].first <= i)             st = m + 1, rz = m;           else             dr = m - 1;         }         cout << w[rz].second <<    ;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s, a, b;   int to[27], k, T;   bool vis[27];   bool up(int dir) {     if (dir == s.size()) return 1;     if (to[s[dir] -  a ] != -1) {       int t = to[s[dir] -  a ];       if (t > a[dir] -  a ) return 1;       if (t < a[dir] -  a ) return 0;       return up(dir + 1);     }     for (int i = a[dir] -  a  + 1; i < k; ++i)       if (!vis[i]) return vis[to[s[dir] -  a ] = i] = 1;     if (!vis[a[dir] -  a ]) {       vis[a[dir] -  a ] = 1;       to[s[dir] -  a ] = a[dir] -  a ;       if (up(dir + 1)) return 1;       to[s[dir] -  a ] = -1;       vis[a[dir] -  a ] = 0;     }     return 0;   }   bool down(int dir) {     if (dir == s.size()) return 1;     if (to[s[dir] -  a ] != -1) {       int t = to[s[dir] -  a ];       if (t > b[dir] -  a ) return 0;       if (t < b[dir] -  a ) return 1;       return down(dir + 1);     }     for (int i = 0; i < b[dir] -  a ; ++i)       if (!vis[i]) return vis[to[s[dir] -  a ] = i] = 1;     if (!vis[b[dir] -  a ]) {       vis[b[dir] -  a ] = 1;       to[s[dir] -  a ] = b[dir] -  a ;       if (down(dir + 1)) return 1;       to[s[dir] -  a ] = -1;       vis[b[dir] -  a ] = 0;     }     return 0;   }   bool dfs(int dir) {     if (dir == s.size()) return 1;     if (to[s[dir] -  a ] != -1) {       int t = to[s[dir] -  a ];       if (t > a[dir] -  a  && t < b[dir] -  a ) return 1;       if (t < a[dir] -  a  || t > b[dir] -  a ) return 0;       if (t == a[dir] -  a  && t == b[dir] -  a ) return dfs(dir + 1);       if (t == a[dir] -  a ) return up(dir + 1);       if (t == b[dir] -  a ) return down(dir + 1);     }     for (int i = a[dir] -  a  + 1; i < b[dir] -  a ; ++i)       if (!vis[i]) return vis[to[s[dir] -  a ] = i] = 1;     if (!vis[a[dir] -  a ]) {       vis[a[dir] -  a ] = 1;       to[s[dir] -  a ] = a[dir] -  a ;       if (a[dir] -  a  == b[dir] -  a ) return dfs(dir + 1);       if (up(dir + 1)) return 1;       vis[a[dir] -  a ] = 0;       to[s[dir] -  a ] = 0;     }     if (!vis[b[dir] -  a ]) {       vis[b[dir] -  a ] = 1;       to[s[dir] -  a ] = b[dir] -  a ;       if (down(dir + 1)) return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     for (cin >> T; T; --T) {       cin >> k >> s >> a >> b;       memset(to, -1, sizeof(to));       memset(vis, 0, sizeof(vis));       if (dfs(0)) {         cout <<  YES  <<   n ;         for (int i = 0; i < k; ++i)           if (to[i] == -1) {             for (int j = 0; j < k; ++j)               if (!vis[j]) {                 vis[j] = 1;                 cout << (char)( a  + j);                 break;               }           } else             cout << (char)( a  + to[i]);         cout <<   n ;       } else         cout <<  NO  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<int, int> container_1;     map<int, int> container_2;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int a, b;       cin >> a >> b;       container_1[a] = b;       container_2[a] = 0;     }     int k;     cin >> k;     for (int i = 0; i < k; ++i) {       int a, b;       cin >> a >> b;       container_2[a] = b;       if (container_1.find(a) == container_1.end()) {         container_1[a] = 0;       }     }     long long sum = 0;     for (auto it : container_1) {       if (it.second > container_2[it.first]) {         sum += it.second;       } else {         sum += container_2[it.first];       }     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int MAX = 1000005;   vector<int> dp[MAX];   int a[MAX];   void add(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   int main() {     int n, k;     long long l;     scanf( %d %I64d %d , &n, &l, &k);     for (int i = 0; i < n; i++) dp[i].resize(k + 1);     vector<int> vals;     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       vals.push_back(a[i]);     }     sort(vals.begin(), vals.end());     vals.resize(unique(vals.begin(), vals.end()) - vals.begin());     for (int i = 0; i < n; i++) {       a[i] = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin();       dp[i][1] = 1;     }     vector<int> cnt;     cnt.resize(vals.size());     for (int j = 2; j <= k; j++) {       for (int i = 0; i < (int)cnt.size(); i++) cnt[i] = 0;       for (int i = 0; i < n; i++) add(cnt[a[i]], dp[i][j - 1]);       for (int i = 1; i < (int)cnt.size(); i++) add(cnt[i], cnt[i - 1]);       for (int i = 0; i < n; i++) dp[i][j] = cnt[a[i]];     }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 1; j <= k; j++) {         long long b = l / n;         if (i < l % n) b++;         b = b - j + 1;         if (b > 0) ans = (ans + (b % MOD) * dp[i][j]) % MOD;       }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     char str[1000][1000], str1[] =  bcdfghjklmpqrstvwxyz ;     int i, j, k, c = 0, s = 0;     scanf( %s , str[0]);     for (i = 0; i < strlen(str[0]); i++) {       for (j = 0; j < strlen(str1); j++) {         if (str[0][i] == str1[j]) {           s = s + 1;           if (str[0][i + 1] ==  a  || str[0][i + 1] ==  e  ||               str[0][i + 1] ==  i  || str[0][i + 1] ==  o  ||               str[0][i + 1] ==  u ) {             c = c + 1;           }         }       }     }     if (s == c) {       printf( YES );     } else {       printf( NO );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, j, x, y, b, a, temp;     cin >> n >> b >> a;     temp = a;     long long int c[n];     for (i = 0; i < n; i++) cin >> c[i];     for (i = 0; i < n; i++) {       if (c[i] == 0 && a != 0)         a--;       else {         if (b > 0 && c[i] == 1) {           if (a < temp) {             a++;             b--;           } else {             a--;           }         } else {           if (b > 0 && c[i] == 0)             b--;           else {             if (b == 0) a--;           }         }       }       if (b == 0 && a == 0) break;     }     if (i == n)       cout << i;     else       cout << i + 1;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       bool gt = true;       long long mn = m, mx = m;       long long curt = 0;       for (long long i = 0; i < n; i++) {         long long t, l, h;         cin >> t >> l >> h;         long long ti = t - curt;         mn -= ti;         mx += ti;         if (l > mx || h < mn) gt = false;         mn = max(mn, l);         mx = min(mx, h);         curt = t;       }       if (gt)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int G[16][110];   bool B[110][2];   int main() {     memset(G, -1, sizeof(G));     for (int i = 0; i < 16; i++) {       G[i][0] = 0;     }     for (int j = 1; j <= 105; j++) {       for (int i = 0; i < 16; i++) {         if ((i & 5) == 5 || (i & 10) == 10) {           continue;         }         vector<int> gs;         for (int k = (i & 4 ? 1 : 0); k + (i & 8 ? 1 : 0) < j; k++) {           gs.push_back(G[(i & 5) | 2][max(0, k)] ^                        G[(i & 10) | 1][max(0, j - k - 1)]);         }         for (int k = (i & 1 ? 1 : 0); k + (i & 2 ? 1 : 0) < j; k++) {           gs.push_back(G[(i & 5) | 8][max(0, k)] ^                        G[(i & 10) | 4][max(0, j - k - 1)]);         }         sort(gs.begin(), gs.end());         gs.resize(unique(gs.begin(), gs.end()) - gs.begin());         G[i][j] = 0;         assert(gs.empty() || gs[0] >= 0);         for (int& g = G[i][j]; g < gs.size() && gs[g] == g; g++)           ;       }     }     int R, N;     cin >> R >> N;     for (int i = 0; i < N; i++) {       int r, c;       cin >> r >> c;       r--;       c--;       B[r][c] = true;       B[r][1 - c] = true;       if (r > 0) B[r - 1][1 - c] = true;       if (r + 1 < R) B[r + 1][1 - c] = true;     }     int gg = 0;     for (int i = 0;;) {       while (i < R && B[i][0] && B[i][1]) i++;       if (i == R) break;       int sz = 0;       int lf = 0;       int rh = 0;       while (i + sz < R && !(B[i + sz][0] && B[i + sz][1])) {         if (B[i + sz][0]) {           lf++;         } else if (B[i + sz][1]) {           rh++;         }         sz++;       }       if (lf == 0 && rh == 0) {         gg ^= G[0][sz];       } else if (lf + rh == 1) {         gg ^= G[1][sz];       } else if (lf == 2 || rh == 2) {         gg ^= G[3][sz];       } else if (lf == 1 && rh == 1) {         gg ^= G[9][sz];       } else {         assert(0);       }       i += sz;     }     if (gg) {       cout <<  WIN  << endl;     } else {       cout <<  LOSE  << endl;     }     return 0;   }