malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, T, cnt, top;   char s[5100][5100];   struct poi {     int x, y;     poi() {}     poi(int x, int y) : x(x), y(y) {}     void trs() {       swap(x, y);       x--;       y = n - y;     }     friend bool operator<(const poi &r1, const poi &r2) {       if (r1.x == r2.x) return r1.y < r2.y;       return r1.x < r2.x;     }     friend int operator^(const poi &r1, const poi &r2) {       return r1.x * r2.y - r2.x * r1.y;     };     friend poi operator-(const poi &r1, const poi &r2) {       return poi(r1.x - r2.x, r1.y - r2.y);     };   } a[5100 << 5], st[5100 << 5];   int onleft(poi p1, poi p2, poi p3) { return ((p1 - p2) ^ (p3 - p2)) >= 0; }   int main() {     while (scanf( %d , &n) != EOF && n) {       top = 0;       cnt = 0;       for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (s[i][j] >  0  && s[i][j + 1] >  0  && s[i + 1][j] >  0  &&               s[i + 1][j + 1] >  0  &&               (s[i][j] ==  1  || s[i][j + 1] ==  1  || s[i + 1][j] ==  1  ||                s[i + 1][j + 1] ==  1 ))             a[++cnt] = poi(i, j + 1);       for (int i = 1; i <= cnt; i++) a[i].trs();       sort(a + 1, a + 1 + cnt);       for (int i = 1; i <= cnt; i++) {         while (top >= 2 && onleft(st[top], st[top - 1], a[i])) top--;         st[++top] = a[i];       }       int t = top;       for (int i = cnt - 1; i >= 1; i--) {         while (top > t && onleft(st[top], st[top - 1], a[i])) top--;         st[++top] = a[i];       }       printf( %d n , top - 1);       for (int i = 1; i < top; i++) printf( %d %d n , st[i].x, st[i].y);     }     return 0;   }
#pragma GCC optimize(3, Ofast , inline )   #include <cstdio>   #include <iostream>   #include <cstring>   #include <algorithm>   #include <cmath>   #include <set>   #include <map>   #include <vector>   #include <stack>   #include <queue>   using namespace std;   typedef long long ll;      typedef pair<int, int> pii;   const int maxn = 1e6 + 10;   const ll mod = 1e9 + 7;   const double pi = acos(-1.0);   const double eps = 1e-8;      int t;   int n, k;   string s1, s2;   int cnt[27];      void solve()   {     int f = 0;     memset(cnt, 0, sizeof(cnt));     sort(s1.begin(), s1.end());     sort(s2.begin(), s2.end());     if(s1 == s2)  puts( Yes );     else{       for(int i = 0; i < n; i ++) cnt[s1[i] -  a ] ++;       for(int i = 0; i < n; i ++) cnt[s2[i] -  a ] --;       for(int i = 0; i < 26; i ++){         if(cnt[i] < 0 || cnt[i] % k){             f = 1;             break;           }         cnt[i + 1] += cnt[i];       }       puts(!f ?  Yes  :  No );     }   }      int main(){     std::ios::sync_with_stdio(false);     cin >> t;     while(t --){       cin >> n >> k;       cin >> s1 >> s2;       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, a, s;   vector<pair<int, long long> > v, u;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> a;       if (x < 0)         v.push_back(make_pair(-x, a));       else         u.push_back(make_pair(x, a));       s += a;     }     sort(v.begin(), v.end());     sort(u.begin(), u.end());     if ((int)v.size() - (int)u.size() <= 1 &&         (int)u.size() - (int)v.size() <= 1) {       cout << s << endl;       return 0;     }     if (v.size() > u.size()) {       for (int i = u.size() + 1; i < v.size(); i++) s -= v[i].second;       cout << s << endl;       return 0;     }     for (int i = v.size() + 1; i < u.size(); i++) s -= u[i].second;     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[101][101];   void rec(int x, int y) {     if (x - 1 > 0 && a[x][y] > a[x - 1][y]) {       a[x - 1][y] = a[x][y] - 1;       rec(x - 1, y);     }     if (a[x][y] > a[x + 1][y]) {       a[x + 1][y] = a[x][y] - 1;       rec(x + 1, y);     }     if (y - 1 > 0 && a[x][y] > a[x][y - 1]) {       a[x][y - 1] = a[x][y] - 1;       rec(x, y - 1);     }     if (a[x][y + 1] < a[x][y]) {       a[x][y + 1] = a[x][y] - 1;       rec(x, y + 1);     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n * 2 + 1; i++) {       for (int j = 1; j <= n * 2 + 1; j++) {         a[i][j] = 0;       }     }     a[n + 1][n + 1] = n;     rec(n + 1, n + 1);     for (int i = 1; i <= n * 2 + 1; i++) {       bool ok = 0;       for (int j = 1; j <= n * 2 + 1; j++) {         if ((i == 1 || i == 2 * n + 1) && j == n + 1) {           if (j != 1) {             cout <<    ;           }           cout << 0;           break;         }         if (a[i][j] == 0 && (a[i][j + 1] <= 0 && a[i][j - 1] <= 0)) {           a[i][j] = -1;         }         if (a[i][j] == -1) {           if (ok == 1) {             break;           }           if (j != 1) {             cout <<    ;           }           cout <<    ;         } else {           if (j != 1) {             cout <<    ;           }           cout << a[i][j];           ok = 1;         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string i_str(int n) {     char buff[10];     sprintf(buff,  %d , n);     return string(buff);   }   int main() {     int a, b;     cin >> a >> b;     if (a < b) {       cout << b;       return 0;     }     string sa, sb, t, r =   , si =   ;     sb = i_str(b);     for (int j = a + 1; j <= 1000000; j++) {       r =   ;       si = i_str(j);       int ni = si.length();       for (int i = 0; i < ni; i++) {         if (si[i] ==  4 ) r = r + si[i];         if (si[i] ==  7 ) r = r + si[i];       };       if (r == sb) {         cout << j;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const long long mod = 1e9 + 7;   long long powr(long long a, long long b) {     long long x = 1 % mod;     a %= mod;     while (b) {       if (b & 1) x = (x * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return x;   }   long long inv(long long a) { return powr(a, mod - 2); }   map<int, int> mymap, mymap2;   int par[maxn];   int val[maxn];   int main() {     int n;     cin >> n;     int x;     map<int, int>::iterator it1, it2;     int mx = 0, mn = 1e9 + 10;     int maxi = 1, mini = 1;     for (int i = 1; i <= n; i++) {       cin >> x;       if (i == 1) mx = mn = x;       val[i] = x;       if (i > 1) {         if (x > mx) {           par[i] = maxi;           maxi = i;           mx = x;         } else if (x < mn) {           par[i] = mini;           mini = i;           mn = x;         } else {           it2 = mymap.upper_bound(x);           int x = it2->second;           it2--;           int y = it2->second;           par[i] = max(x, y);         }         cout << val[par[i]] <<    ;       }       mymap[x] = i;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t, n;     string s;     cin >> t;     while (t--) {       cin >> n >> s;       vector<int> szs;       char prev = s.front();       int sz = 0;       for (char c : s) {         if (c != prev) {           szs.push_back(sz);           sz = 1;         } else           sz++;         prev = c;       }       szs.push_back(sz);       int cnt = 0, id = 1;       for (int i : szs) {         if (i > 1) cnt += min(i - 1, id - cnt);         id++;       }       cout << cnt + (szs.size() - cnt + 1) / 2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 3e5 + 10;   template <typename value_t>   class fenwick {    public:     fenwick(int n) {       memset(c, 0, sizeof c);       this->n = n;     }     void add(int i, value_t x) {       while (i <= n) {         c[i] += x;         i += Lowbit(i);       }     }     value_t sum(int x) {       value_t sum = 0;       while (x > 0) {         sum += c[x];         x -= Lowbit(x);       }       return sum;     }     value_t sum(int x1, int x2) { return sum(x2) - sum(x1 - 1); }       private:     value_t c[MAXN];     int n;     inline int Lowbit(int x) { return x & (-x); }   };   class lfs {    public:     lfs(int N) {       memset(head, -1, sizeof head);       ecnt = 0;       n = N;     }     void adde(int from, int to, int w) {       e[ecnt].to = to;       e[ecnt].w = w;       e[ecnt].next = head[from];       head[from] = ecnt++;     }     void addde(int a, int b, int w) {       adde(a, b, w);       adde(b, a, w);     }     void solve() {       memset(ans, 0, sizeof ans);       arr = new fenwick<long long>(n);       dfs(1, 0, 1);     }     vector<pair<int, int>> opr[MAXN];     long long ans[MAXN];       protected:     struct Edge {       int to, next, w;     } e[MAXN * 2];     int head[MAXN];     int ecnt;     int n;     fenwick<long long>* arr;     void dfs(int u, int fa, int dep) {       for (auto& i : opr[u]) {         arr->add(dep, i.second);         arr->add(dep + i.first + 1, -i.second);       }       ans[u] = arr->sum(dep);       for (int i = head[u]; i != -1; i = e[i].next) {         int v = e[i].to;         if (v != fa) dfs(v, u, dep + 1);       }       for (auto& i : opr[u]) {         arr->add(dep, -i.second);         arr->add(dep + i.first + 1, i.second);       }     }   };   template <typename T = int>   inline T read() {     T X = 0, w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) {       X = (X << 3) + (X << 1) + (ch ^ 48);       ch = getchar();     }     return w ? -X : X;   }   int main() {     int n = read();     lfs* tree = new lfs(n);     for (int i = 1; i < n; i++) {       tree->addde(read(), read(), 1);     }     int m = read();     for (int i = 1; i <= m; i++) {       int u = read();       int d = read();       int x = read();       tree->opr[u].push_back(make_pair(d, x));     }     tree->solve();     for (int i = 1; i <= n; i++) {       cout << tree->ans[i] <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using ld = long double;   using pii = pair<int, int>;   ll val(ll solve, ll whole) {     if (2 * solve > whole) return 500;     if (4 * solve > whole) return 1000;     if (8 * solve > whole) return 1500;     if (16 * solve > whole) return 2000;     if (32 * solve > whole) return 2500;     return 3000;   }   ll score(vi &t, vector<ll> &cnt, ll whole) {     ll ans = 0;     for (int i = 0; i < t.size(); i++)       if (t[i] != -1) ans += val(cnt[i], whole) * (250 - t[i]);     return ans;   }   bool go(vector<vi> &a, ll k, int mask) {     vector<ll> cnt(a[0].size());     for (int i = 0; i < a.size(); i++)       for (int j = 0; j < a[i].size(); j++)         if (a[i][j] != -1) cnt[j]++;     for (int i = 0; i < 5; i++)       if ((mask & (1 << i)) && a[0][i] != -1) cnt[i] += k;     ll whole = a.size() + (mask == 0 ? 0 : k);     return score(a[0], cnt, whole) > score(a[1], cnt, whole);   }   void solve() {     int n;     cin >> n;     vector<vi> a(n, vi(5));     for (int i = 0; i < n; i++)       for (int j = 0; j < 5; j++) cin >> a[i][j];     for (int k = 0; k < 32 * n; k++)       for (int mask = 1; mask < 1 << 5; mask++)         if (go(a, k, mask)) {           cout << k <<   n ;           return;         }     cout << -1 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     string s;     cin >> s;     if ((int)s[0] >= 97 && (int)s[0] <= 122) {       s[0] = (char)((int)s[0] - 32);     }     for (i = 0; i < s.size(); i++) {       cout << s[i];     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 101000;   int a[maxn], x, y, z, cnt, curr, ans, n, m;   vector<int> v;   int bs(int x) {     int l = 0, r = m;     while (l < r - 1) {       int mid2 = (l + r) / 2;       if (v[mid2] < x) {         l = mid2;       } else {         r = mid2;       }     }     if (v[l] >= x) {       return -1;     }     return l;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int j = 0; j < m; ++j) {       cin >> x >> y >> z;       if (x == 1) {         v.push_back(y);         if (y == 1000000000) {           ++cnt;         }       }     }     sort(a, a + n);     sort(v.begin(), v.end());     ans = cnt + n;     if (!v.size()) {       cout << 0 << endl;       return 0;     }     v.push_back(1000001000);     m = v.size();     for (int i = 0; i < n; ++i) {       curr = i;       int val = bs(a[i]);       curr += m - val - 2;       ans = min(ans, curr);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   long long int mod = 1000000007;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, k;     cin >> n >> k;     long long int p = k / n;     if (k % n != 0) {       p += 1;     }     cout << p;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, z = 1, x, c, zx;   map<string, long long> m;   string a[1001], s;   int main() {     while (getline(cin, s)) {       a[n++] = s;       zx = max(zx, (long long)s.size());     }     for (int i = -2; i < zx; i++) cout <<  * ;     cout <<   n ;     for (int i = 0; i < n; i++) {       int k = zx - (long long)a[i].size();       cout <<  * ;       for (int j = 0; j < (k + x) / 2; j++) cout <<    ;       cout << a[i].c_str();       for (int j = (k + x) / 2; j < k; j++) cout <<    ;       cout <<  *             <<   n ;       if (k & 1) x = 1 - x;     }     for (int i = -2; i < zx; i++) cout <<  * ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int samples, len, temp, sz;     cin >> samples >> len;     deque<int> q;     set<int> s;     sz = s.size();     for (; samples--;) {       cin >> temp;       s.insert(temp);       if (s.size() > sz) {         q.push_front(temp);         if (q.size() > len) {           s.erase(q[q.size() - 1]);           q.pop_back();         }       }       sz = s.size();     }     printf( %d n , q.size());     for (auto x : q) printf( %d  , x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct inter {     int l, r, id;     inter() { l = r = id = -1; }     inter(int _l, int _r, int _id) { l = _l, r = _r, id = _id; }     bool operator<(const inter &r) const { return l < r.l; }   };   int N, L, R;   int A[100005], C[100005];   int B[100005];   map<int, inter> S;   int main() {     while (scanf( %d%d%d , &N, &L, &R) == 3) {       for (int i = 0; i < N; i++) scanf( %d , A + i);       for (int i = 0; i < N; i++)         scanf( %d , C + i), S[C[i]] = inter(L - A[i], R - A[i], i);       int nowL = -2147483646;       int found = 1;       for (map<int, inter>::iterator it = S.begin(); it != S.end(); it++) {         nowL = max(nowL, it->second.l);         if (nowL > it->second.r) {           found = -1;           break;         }         B[it->second.id] = nowL++;       }       if (found == -1) {         printf( -1 );       } else {         for (int i = 0; i < N; i++) {           if (i) printf(   );           printf( %d , B[i] + A[i]);         }       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, c;   int a[1005];   bool check() {     bool good = a[0] > 0;     for (int i = 1; i < n; i++) good &= (a[i] > 0) && (a[i] >= a[i - 1]);     return good;   }   int main() {     cin >> n >> m >> c;     for (int i = 0; i < n; i++) a[i] = 0;     while (m--) {       if (check()) return 0;       int p;       cin >> p;       if (p <= c / 2) {         for (int i = 0; i < n; i++) {           if (a[i] == 0) {             a[i] = p;             cout << i + 1;             break;           }           if (a[i] > p) {             a[i] = p;             cout << i + 1;             break;           }         }       } else {         for (int i = n - 1; i >= 0; i--) {           if (a[i] == 0) {             a[i] = p;             cout << i + 1;             break;           }           if (a[i] < p) {             a[i] = p;             cout << i + 1;             break;           }         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1 << 19;   long long n, k;   long long ans[maxn], mx[maxn], mn[maxn];   bool occ[maxn];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (long long i = 0; i < (long long)(1 << k); ++i)       mx[i] = -1e9, mn[i] = 1e9, ans[i] = 2e9;     for (long long i = 0; i < (long long)(n); ++i) {       long long u;       cin >> u;       occ[u] = 1, mx[u] = u, mn[u] = u;     }     for (long long i = 0; i < k; ++i) {       for (long long j = 0; j < (1 << k); j += (1 << i + 1)) {         for (long long t = 0; t < (long long)(1 << i); ++t) {           ans[j + t] = ans[j + t + (1 << i)] =               min(ans[j + t], ans[j + t + (1 << i)]);           ans[j + t] = min(ans[j + t], mn[j + t + (1 << i)] - mx[j + t]);           ans[j + t + (1 << i)] =               min(ans[j + t + (1 << i)],                   mn[j + t] - mx[j + t + (1 << i)] + (1 << i + 1));         }       }       for (long long j = 0; j < (1 << k); j += (1 << i + 1)) {         for (long long t = 0; t < (long long)(1 << i); ++t) {           long long upmn0 = min(mn[j + t], mn[j + t + (1 << i)]);           long long upmn1 =               min(mn[j + t + (1 << i)] - (1 << i), mn[j + t] + (1 << i));           long long upmx0 = max(mx[j + t], mx[j + t + (1 << i)]);           long long upmx1 =               max(mx[j + t + (1 << i)] - (1 << i), mx[j + t] + (1 << i));           mn[j + t] = upmn0, mn[j + t + (1 << i)] = upmn1;           mx[j + t] = upmx0, mx[j + t + (1 << i)] = upmx1;         }       }     }     for (long long i = 0; i < (long long)(1 << k); ++i) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int d[2005];   vector<int> E[2005];   bool h[2005];   const int INF = 1e9 + 7;   void add(int u, int v) { E[u].push_back(v); }   void bfs() {     queue<int> q;     d[0] = 0;     q.push(0);     while (q.size()) {       int t = q.front();       q.pop();       for (int i = 0; i < E[t].size(); i++) {         if (d[E[t][i]] == INF) {           d[E[t][i]] = d[t] + 1;           q.push(E[t][i]);           if (E[t][i] == 1001) {             return;           }         }       }     }     return;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i <= 2001; i++) d[i] = INF;     for (int i = 1; i <= k; i++) {       int x;       scanf( %d , &x);       x -= n;       if (!h[x + 1001]) {         add(0, x + 1001);         h[x + 1001] = 1;       }     }     for (int i = 1; i <= 2001; i++) {       for (int j = 1; j <= 2001; j++) {         if (h[j] && (0 <= i + j - 1001 && i + j - 1001 <= 2001)) {           add(i, i + j - 1001);         }       }     }     bfs();     if (d[1001] != INF)       printf( %d n , d[1001]);     else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ncr(int n, int r) {     int ret = 1;     for (int i = 1; i <= n - r; i++) {       ret = (ret * (n - r + i)) / i;     }     return ret;   }   int main() {     int n;     cin >> n;     int x;     long long pos = 0;     long long neg = 0;     long long prod = 1;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       if (x < 0) {         prod = (prod + 1) & 1;       }       if (prod) {         pos++;       } else {         neg++;       }     }     cout << neg * pos + neg <<    ;     cout << (neg * (neg - 1)) / 2 + (pos * (pos - 1)) / 2 + pos << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int a[maxn];   struct node {     int l, r, Max, Min, pa, pi;   } T[maxn << 2];   void pushup(int o) {     T[o].Min = min(T[o << 1].Min, T[o << 1 | 1].Min);     T[o].Max = max(T[o << 1].Max, T[o << 1 | 1].Max);     if (T[o].Min == T[o << 1].Min)       T[o].pi = T[o << 1].pi;     else       T[o].pi = T[o << 1 | 1].pi;     if (T[o].Max == T[o << 1].Max)       T[o].pa = T[o << 1].pa;     else       T[o].pa = T[o << 1 | 1].pa;   }   void build(int o, int l, int r) {     T[o].l = l;     T[o].r = r;     if (l == r) {       T[o].Max = T[o].Min = a[l];       T[o].pa = T[o].pi = l;       return;     }     int mid = (l + r) >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);     pushup(o);   }   int query(int o, int l, int r, int op) {     if (T[o].l == l && T[o].r == r) {       if (op == 1)         return T[o].Max;       else if (op == 2)         return T[o].Min;       else if (op == 3)         return T[o].pa;       else         return T[o].pi;     }     int mid = (T[o].l + T[o].r) >> 1;     if (r <= mid)       return query(o << 1, l, r, op);     else if (l > mid)       return query(o << 1 | 1, l, r, op);     else {       if (op == 1)         return max(query(o << 1, l, mid, 1), query(o << 1 | 1, mid + 1, r, 1));       else if (op == 2)         return min(query(o << 1, l, mid, 2), query(o << 1 | 1, mid + 1, r, 2));       else if (op == 3) {         int ans1 = query(o << 1, l, mid, 1),             ans2 = query(o << 1 | 1, mid + 1, r, 1);         int ans = max(ans1, ans2);         if (ans == ans1)           return query(o << 1, l, mid, 3);         else           return query(o << 1 | 1, mid + 1, r, 3);       } else {         int ans1 = query(o << 1, l, mid, 2),             ans2 = query(o << 1 | 1, mid + 1, r, 2);         int ans = min(ans1, ans2);         if (ans == ans1)           return query(o << 1, l, mid, 4);         else           return query(o << 1 | 1, mid + 1, r, 4);       }     }   }   int main() {     int n, m;     while (~scanf( %d%d , &n, &m)) {       for (int i = 1; i <= n; i++) scanf( %d , a + i);       build(1, 1, n);       int l, r, x, Max, Min, pa, pi;       while (m--) {         scanf( %d%d%d , &l, &r, &x);         Max = query(1, l, r, 1);         Min = query(1, l, r, 2);         pa = query(1, l, r, 3);         pi = query(1, l, r, 4);         int ans;         if (Max == Min && Max == x)           ans = -1;         else if (Min != x)           ans = pi;         else if (Max != x)           ans = pa;         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   typedef struct pair {     int x, y;   } pair;   int const N = 1e4 + 5;   int n = 8;   pair sMatrix[N], sac[N];   char matrix[N][N], mariaMove[10][10][100];   pair anna, maria;   int i, j, k, s, m, h, t;   int kontrol(int x, int y) {     int i, j;     for (i = 0; i < s; i++) {       if (sMatrix[i].x == x && sMatrix[i].y == y) return 0;     }     return 1;   }   void sDown(int add) {     int i;     for (i = 0; i < s; i++) {       sMatrix[i].x += add;     }   }   void wrtS() {     int i;     for (i = 0; i < s; i++) {       printf( %d-SS-%d , sMatrix[i].x, sMatrix[i].y), puts(  );     }   }   void dfs(int x, int y, int t) {     int i, j, k;     if (x == anna.x && y == anna.y) {       printf( WIN ), puts(  );       exit(0);     }     if (!(!mariaMove[x][y][t] && x >= 0 && x < n && y >= 0 && y < n) ||         !kontrol(x, y))       return;     sDown(1);     if (!kontrol(x, y)) {       sDown(-1);       return;     }     mariaMove[x][y][t] = 1;     for (i = -1, k = 0; i <= 1; i++) {       for (j = -1; j <= 1; j++, k++) {         dfs(x + i, y + j, k);       }     }     sDown(-1);   }   void clearMariaMove() {     int i, j, k;     for (i = 0; i < 10; i++) {       for (j = 0; j < 10; j++) {         for (k = 0; k < 100; k++) {           mariaMove[i][j][k] = 0;         }       }     }   }   void clear_sMatrix() {     int i;     for (i = 0; i < s; i++) {       sMatrix[i].x = sac[i].x;       sMatrix[i].y = sac[i].y;     }   }   int main() {     for (i = 0; i < n; i++) {       scanf( %s , matrix[i]);       for (j = 0; j < n; j++) {         if (matrix[i][j] ==  S ) {           sMatrix[s].x = i, sMatrix[s].y = j;           sac[s].x = i, sac[s].y = j;           s++;         }       }     }     maria.x = 7, maria.y = 0;     anna.x = 0, anna.y = 7;     for (i = -1; i <= 0; i++) {       for (j = 0; j <= 1; j++) {         dfs(maria.x + i, maria.y + j, 0);         clearMariaMove();         clear_sMatrix();       }     }     puts( LOSE );     return 0;   }