malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c *x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct deb {     template <class c>     deb &operator<<(const c &) {       return *this;     }   };   template <class T>   T &chmin(T &a, const T &b) {     return a = min(a, b);   }   template <class T>   T &chmax(T &a, const T &b) {     return a = max(a, b);   }   const long long dx[8] = {0, 1, -1, 0, 1, 1, -1, -1};   const long long dy[8] = {1, 0, 0, -1, 1, -1, -1, 1};   const long long mod = 1e9 + 7;   inline long long add(long long a, long long b) {     return ((a % mod) + (b % mod)) % mod;   }   inline long long sub(long long a, long long b) {     return ((a % mod) - (b % mod) + mod) % mod;   }   inline long long mul(long long a, long long b) {     return ((a % mod) * (b % mod)) % mod;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &vec) {     for (auto &v : vec) is >> v;     return is;   }   const double PI = acos(-1.0);   const long long inf = 1e18;   const long long maxn = 1e3 + 5;   void solve() {     long long n;     cin >> n;     vector<long long> arr(2 * n);     cin >> arr;     cin >> arr;     sort(arr.begin(), arr.end());     long long s1 = 0;     long long s2 = 0;     for (long long i = 0; i < n; i++) s1 += arr[i];     for (long long i = n; i < 2 * n; i++) s2 += arr[i];     if (s1 != s2) {       for (long long i = 0; i < 2 * n; i++) {         cout << arr[i] <<    ;       }       cout <<   n ;     } else {       cout << -1 <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     for (long long tt = 1; tt <= t; tt++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long &a) {     a %= 1000000007;     (a < 0) && (a += 1000000007);   }   inline long long modMul(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a * b) % 1000000007;   }   inline long long modAdd(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a + b) % 1000000007;   }   inline long long modSub(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInverse(b));   }   inline long long power(long long bs, long long k) {     long long x = 1LL, y = bs;     if (k == 0) return 1LL;     while (k > 0) {       if (k % 2) x *= y;       y *= y;       k /= 2;     }     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout.unsetf(ios::floatfield);     cout.precision(10);     cout.setf(ios::fixed, ios::floatfield);     ;     long long n;     cin >> n;     if (n % 2)       cout <<  black ;     else {       cout <<  white  <<   n ;       cout <<  1 2 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1e3 + 20;   long long inf = (long long)1e15;   long long mod = (long long)1e9 + 7;   long long n, cntr[MAX], cntc[MAX], l[MAX][MAX], used[MAX];   void swpr(long long ind1, long long ind2) {     swap(cntr[ind1], cntr[ind2]);     for (int i = 1; i <= n; i++) swap(l[ind1][i], l[ind2][i]);   }   void swpc(long long ind1, long long ind2) {     swap(cntc[ind1], cntc[ind2]);     for (int i = 1; i <= n; i++) swap(l[i][ind1], l[i][ind2]);   }   void solve() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       long long x, y;       cin >> x >> y;       l[x][y] = 1;       cntr[x]++;       cntc[y]++;     }     vector<pair<long long, pair<long long, long long>>> ans;     long long need = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (cntr[j] == need && !used[j]) {           used[i] = 1;           need = 0;           if (i != j) {             swpr(i, j);             ans.push_back({1, {i, j}});           }           break;         }       }       need++;     }     for (int i = 2; i <= n; i++) {       long long start = (i - 1) - cntr[i] + 1;       long long bord = start;       while (bord <= n) {         if (l[i][bord] == 1) {           if (bord != start) {             swpc(start, bord);             ans.push_back({2, {start, bord}});           }           start++;         }         bord++;       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i].first <<     << ans[i].second.first <<                << ans[i].second.second <<   n ;     }   }   int main() {     mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());     ios::sync_with_stdio(0);     long long q;     q = 1;     while (q--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     size_t pos1 = s.find( AB ), pos2 = s.find( BA );     string tmp = s;     s.erase(0, pos1 + 2);     tmp.erase(0, pos2 + 2);     bool check = false;     if (pos1 == string::npos || pos2 == string::npos) {       cout <<  NO ;     } else {       if (s.find( BA ) != string::npos || tmp.find( AB ) != string::npos)         check = true;       if (check)         cout <<  YES ;       else         cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string mask(int a) {     string ans;     int x = a;     while (x) {       if (x % 10 == 4 || x % 10 == 7) ans.insert(ans.begin(), x % 10 +  0 );       x /= 10;     }     return ans;   }   int main() {     string b;     int a;     cin >> a >> b;     a++;     while (mask(a) != b) a++;     cout << a;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f, mn1, mn2, res, ans1, ans2;     cin >> a >> b >> c >> d >> e >> f;     res = d;     mn2 = min(b, min(c, d));     d = abs(mn2 - d);     mn1 = min(a, d);     ans1 = (mn2 * f) + (mn1 * e);     mn1 = min(a, res);     res = abs(mn1 - res);     mn2 = min(b, min(c, res));     ans2 = (mn2 * f) + (mn1 * e);     cout << max(ans1, ans2) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int node[4][11][11][maxn];   int h[110];   char s[maxn], e[11];   int lowbit(int x) { return x & (-x); }   void add(int ty, int pos, int x, int d) {     for (; x < maxn; x += lowbit(x)) {       for (int k = 1; k <= 10; k++) {         node[ty][k][pos % k][x] += d;       }     }   }   int sum(int ty, int len, int pos, int x) {     int ans = 0;     for (; x > 0; x -= lowbit(x)) {       ans += node[ty][len][pos][x];     }     return ans;   }   int query(int l, int r, int ty, int len, int pos) {     return sum(ty, len, pos, r) - sum(ty, len, pos, l - 1);   }   int main() {     int n;     h[ A ] = 0;     h[ T ] = 1;     h[ C ] = 2;     h[ G ] = 3;     scanf( %s%d , s, &n);     int len = strlen(s);     for (int i = 0; i < len; i++) {       add(h[s[i]], i, i + 1, 1);     }     while (n--) {       int a, b, c;       scanf( %d , &a);       if (a == 1) {         scanf( %d%s , &b, e);         add(h[s[b - 1]], b - 1, b, -1);         add(h[e[0]], b - 1, b, 1);         s[b - 1] = e[0];       } else {         scanf( %d%d%s , &b, &c, e);         len = strlen(e);         int ans = 0;         for (int i = 0; i < len; i++) {           ans += query(b, c, h[e[i]], len, (i + b - 1) % len);         }         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p[1000100], h[1000100], g[1000100], ans;   int main() {     int m, n, x, y;     cin >> n >> m;     for (int i = 0; i <= n; i++) p[i] = (i ? p[i - 1] * 9 : 1);     while (m--) {       scanf( %d%d , &x, &y);       h[x] += p[y];       h[y] += p[x];     }     for (int i = 1; i <= n; i++) g[i] = h[i] + p[i];     sort(h + 1, h + n + 1);     for (int i = 1, cnt = 0; i <= n; i++)       if (h[i] == h[i - 1])         ans += cnt++;       else         cnt = 1;     sort(g + 1, g + n + 1);     for (int i = 1, cnt = 0; i <= n; i++)       if (g[i] == g[i - 1])         ans += cnt++;       else         cnt = 1;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   void die(string S) {     puts(S.c_str());     exit(0);   }   int number[333][333];   int cnt[100100];   vector<int> V[100100];   int grid[333][333];   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<int> v;       for (int i = 0; i < n * m; i++) {         int x;         cin >> x;         v.push_back(x);         number[i / m][i % m] = x;         cnt[i] = 0;         V[i].clear();       }       sort((v).begin(), (v).end());       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           number[i][j] =               lower_bound((v).begin(), (v).end(), number[i][j]) - v.begin();           cnt[number[i][j]]++;           V[number[i][j]].push_back(i * m + j);         }       int pos = 0;       for (int i = 0; i < n * m; i++)         if (cnt[i]) {           int endp = (pos + cnt[i] - 1);           if (endp / m == pos / m) {             sort((V[i]).rbegin(), (V[i]).rend());             for (int j = 0; j < cnt[i]; j++)               grid[(pos + j) / m][(pos + j) % m] = V[i][j];           } else {             sort((V[i]).begin(), (V[i]).end());             int x = m - pos % m;             for (int j = x - 1; j >= 0; j--)               grid[(pos + x - j - 1) / m][(pos + x - j - 1) % m] = V[i][j];             x = endp % m + 1;             for (int j = cnt[i] - 1; j >= cnt[i] - x; j--)               grid[(endp / m * m + cnt[i] - j - 1) / m]                   [(endp / m * m + cnt[i] - j - 1) % m] = V[i][j];             for (int j = m - pos % m; j < cnt[i] - x; j++)               grid[(pos + j) / m][(pos + j) % m] = V[i][j];             for (int j = pos / m + 1; j < endp / m; j++)               reverse(grid[j], grid[j] + m);           }           pos += cnt[i];         }       int ans = 0;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           for (int k = j + 1; k < m; k++)             if (grid[i][j] < grid[i][k]) ans++;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 10 + 5;   char a[maxN][maxN][maxN];   int mark[maxN][maxN][maxN];   int k, n, m;   int dx[] = {-1, 1, 0, 0, 0, 0};   int dy[] = {0, 0, -1, 1, 0, 0};   int dz[] = {0, 0, 0, 0, -1, 1};   int cnt;   void dfs(int x, int y, int z) {     mark[x][y][z] = 1;     cnt++;     for (int i = 0; i < 6; i++) {       int r = x + dx[i], c = y + dy[i], t = z + dz[i];       if (r < 0 || c < 0 || t < 0) continue;       if (r >= k || c >= n || t >= m) continue;       if (!mark[r][c][t] && a[r][c][t] ==  . ) dfs(r, c, t);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> k >> n >> m;     for (int i = 0; i < k; i++)       for (int j = 0; j < n; j++)         for (int t = 0; t < m; t++) cin >> a[i][j][t];     int x, y;     cin >> x >> y;     x--;     y--;     dfs(0, x, y);     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int n = s.size();     int cz = 0;     int co = 0;     int ct = 0;     for (int i = 0; i < n; i++) {       co += (s[i] ==  1 );       ct += (s[i] ==  2 );       cz += (s[i] ==  0 );     }     if (cz == 0 || ct == 0) {       sort(s.begin(), s.end());       cout << s <<   n ;       return 0;     }     if (co == 0) {       cout << s <<   n ;       return 0;     }     string aux =   ;     int idx = -1;     for (int i = 0; i < n; i++) {       if (s[i] !=  1 ) aux += s[i];     }     string res =   ;     int occ = -1;     for (int i = 0; i < aux.size(); i++) {       if (aux[i] ==  2  && occ == -1) {         while (co--) {           res +=  1 ;         }         res += aux[i];         occ = 1;       } else {         res += aux[i];       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = (int)2e5 + 5;   int n, c[mx], ans[mx];   char a[mx], b[mx];   void solve() {     int cnt = 0, temp = 0;     for (int i = n - 1; i >= 0; i--) {       c[cnt++] = (a[i] + b[i] - 2 *  a  + temp) % 26;       temp = (a[i] + b[i] - 2 *  a  + temp) / 26;     }     c[cnt++] = temp;     temp = 0;     for (int i = cnt - 1; i >= 0; i--) {       temp *= 26;       ans[i] = (c[i] + temp) / 2;       temp = (c[i] + temp) % 2;     }     for (int i = n - 1; i >= 0; i--) {       printf( %c , ans[i] +  a );     }     cout << endl;   }   int main() {     cin >> n;     scanf( %s%s , a, b);     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     int c = 0;     cin >> a >> b;     while (a > 0 && b > 0) {       if (a > b) {         a -= 2;         b -= 1;       } else {         a -= 1;         b -= 2;       }       if (a > -1 && b > -1) c++;     }     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, MAX = 100003, INF = 1 << 30;   long long rui(long long a, long long b) {     if (b == 1)       return a % mod;     else if (b == 0)       return 1;     else if (b % 2 == 0)       return (rui(a, b / 2) * rui(a, b / 2)) % mod;     else       return (rui(a, b - 1) * a) % mod;   }   int main() {     int Q;     cin >> Q;     for (int q = 0; q < Q; q++) {       int N, M;       cin >> N >> M;       vector<int> S[N], color(N, 0);       for (int i = 0; i < M; i++) {         int a, b;         cin >> a >> b;         a--;         b--;         S[a].push_back(b);         S[b].push_back(a);       }       long long ans = 1;       for (int i = 0; i < N; i++) {         if (color[i]) continue;         int odd = 1, even = 0;         color[i] = 1;         queue<int> Q;         Q.push(i);         while (!Q.empty()) {           int a = Q.front();           Q.pop();           for (int j = 0; j < S[a].size(); j++) {             int b = S[a][j];             if (color[b] == 0) {               color[b] = 3 - color[a];               if (color[b] % 2)                 odd++;               else                 even++;               Q.push(b);             } else if (color[a] == color[b]) {               ans = 0;             }           }         }         ans *= (rui(2, odd) + rui(2, even)) % mod;         ans %= mod;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int lenA, lenB;   int A[1000004];   int B[1000004];   int idxB[1000004];   int lenP = 0, idxP = 0;   long long P[1000004 * 2];   int main() {     scanf( %d %d , &lenA, &lenB);     for (int i = 0, _n = (lenA); i < _n; ++i) scanf( %d , A + i);     memset(idxB, -1, sizeof(idxB));     for (int j = 0, _n = (lenB); j < _n; ++j) {       scanf( %d , B + j);       idxB[B[j]] = j;     }     long long offset = 0;     int res = 0;     for (int k = 0, _n = (lenA * 2); k < _n; ++k) {       long long p = idxB[A[k % lenA]];       if (p < 0) {         lenP = 0;         idxP = 0;         continue;       }       p += offset;       if (lenP > 0 && P[lenP - 1] >= p) {         p += lenB;         offset += lenB;       }       P[lenP++] = p;       idxP = lower_bound(P + idxP, P + lenP, p - lenB + 1) - P;       int len = lenP - idxP;       res = max(res, len);     }     printf( %d n , res);     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 t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long d = (k / (n - 1)), r = (k % (n - 1));       if (r != 0) {         cout << (d * n) + r << endl;       } else {         cout << (d * n) - 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   int n, m;   int main() {     long long ans;     int b, c, A, B, C, l;     scanf( %d%d , &n, &m);     n++;     m++;     ans = 0;     for (c = m; c <= n - m; c++) {       C = 2 * (n * n - n * c + c * c);       for (b = n - m; b >= m; b--) {         A = 2 * n - b - c;         B = b * (n + c);         l = (C - B) / A;         if (m > l) l = m - 1;         if (l >= n - m) break;         ans += n - m - l;       }     }     printf( %I64d n , ans * 3);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   struct node {     int c, f, l, i;   } a[maxn], b[maxn];   bool cmp1(node a, node b) { return a.f < b.f; }   bool cmp2(node a, node b) { return a.c > b.c; }   int main() {     int n, d, s;     scanf( %d%d%d , &n, &d, &s);     int nn = n;     int m = 0;     int ss = s;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &a[i].c, &a[i].f, &a[i].l);       a[i].i = i;       b[i] = a[i];       if (a[i].c != 0 && a[i].l >= d) {         if (m == 0 || a[m].f > a[i].f) m = i;       }     }     int ansf = 0;     int ansc = 0;     if (m != 0 && a[m].f <= s) {       s = s - a[m].f;       sort(a + 1, a + 1 + n, cmp2);       int sumc = a[1].c;       int sum = 1;       for (int i = 2; i <= n; i++) {         sum++;         sumc = sumc - 1 + a[i].c;         if (sumc == 0) break;       }       int j = 0;       for (int i = 1; i <= n; i++)         if (a[i].l >= d && a[i].i != m) {           a[++j] = a[i];         }       n = j;       sort(a + 1, a + 1 + n, cmp1);       for (int i = 1; i <= n; i++) {         if (sum == nn) break;         if (s >= a[i].f) {           sum++;           s -= a[i].f;         } else           break;       }       ansf = ss - s;       ansc = sum;     }     n = nn;     for (int i = 1; i <= n; i++) a[i] = b[i];     s = ss;     int sumc = 0;     int j = 0;     for (int i = 1; i <= n; i++)       if (a[i].c == 0 && a[i].l >= d) {         a[++j] = a[i];       }     n = j;     sort(a + 1, a + 1 + n, cmp1);     for (int i = 1; i <= n; i++) {       if (s >= a[i].f) {         sumc++;         s -= a[i].f;       } else         break;     }     if (ansc < sumc) {       ansf = ss - s;       ansc = sumc;     } else if (ansc == sumc && ansf > ss - s) {       ansf = ss - s;       ansc = sumc;     }     printf( %d %d n , ansc, ansf);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool flag;   int vis[(1 << 17)];   int n, m, k;   vector<pair<int, int> > vt[(1 << 17)];   void dfs(int u) {     for (int i = 0; i < vt[u].size(); i++) {       int v = vt[u][i].first;       int c = vt[u][i].second;       if (vis[v] == -1) {         if (c == 1)           vis[v] = vis[u];         else           vis[v] = !vis[u];         dfs(v);       }       if (c == 1 && (vis[v] != vis[u])) flag = true;       if (c == 0 && (vis[v] == vis[u])) flag = true;     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v, c;       scanf( %d%d%d , &u, &v, &c);       vt[u].push_back(make_pair(v, c));       vt[v].push_back(make_pair(u, c));     }     memset(vis, -1, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (vis[i] == -1) {         vis[i] = 0;         dfs(i);         k++;       }     }     long long ans = 1;     if (flag) {       puts( 0 );       return 0;     }     for (int i = 2; i <= k; i++) ans = ans * 2 % 1000000007;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, w[210], d[210][30010], f[30010], x[210][30010], u[30010], p;   vector<int> a[30010], b[30010];   inline void GG() {     printf( -1 n );     exit(0);   }   inline void line(int i, int j) {     a[i].push_back(j);     a[j].push_back(i);   }   inline void dfs(int i, int j, int k, int l) {     if (d[k][i] != l) GG();     int u;     for (u = 0; u < a[i].size(); u++)       if (a[i][u] != j) dfs(a[i][u], i, k, l + 1);   }   inline void check() {     int i;     for (i = 1; i <= m; i++) dfs(w[i], 0, i, 0);   }   inline bool cmp(int i, int j) { return d[1][i] < d[1][j]; }   int main() {     int i, j, k, l, r;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       for (j = 1; j <= n; j++) {         scanf( %d , &d[i][j]);         if (d[i][j] == 0)           if (w[i])             GG();           else             w[i] = j;       }       if (!w[i]) GG();       for (j = 1; j < i; j++)         if (w[i] == w[j]) GG();     }     for (i = 2; i <= m; i++) {       for (j = 1; j <= n; j++)         if (d[i][j] + d[1][j] == d[i][w[1]]) x[i][d[i][j]] = j;       for (j = 0; j <= d[i][w[1]]; j++)         if (!x[i][j]) GG();       for (j = 0; j < d[i][w[1]]; j++)         if (f[x[i][j]] && f[x[i][j]] != x[i][j + 1])           GG();         else           f[x[i][j]] = x[i][j + 1];     }     for (i = 1; i <= n; i++)       if (f[i]) line(i, f[i]);     check();     for (i = 1; i <= n; i++)       if (!f[i] && i != w[1])         u[++p] = i;       else         b[i].push_back(i);     if (p) {       sort(u + 1, u + p + 1, cmp);       for (i = 1; i <= p; i++) {         for (j = 2, k = w[1]; j <= m; j++) {           l = d[1][u[i]] + d[j][u[i]] - d[1][w[j]];           if ((l & 1) || l == 0) GG();           r = d[j][u[i]] - l / 2;           r = x[j][r];           if (d[1][r] > d[1][k]) k = r;         }         j = d[1][u[i]] - d[1][k];         if (b[k].size() >= j) {           line(b[k][j - 1], u[i]);           if (b[k].size() == j) b[k].push_back(u[i]);         } else           GG();       }       check();     }     for (i = 1; i <= n; i++)       for (j = 0; j < a[i].size(); j++)         if (a[i][j] > i) printf( %d %d n , i, a[i][j]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     pair<long long, long long> s, e;     long long t;     cin >> t;     cin >> s.first >> s.second >> e.first >> e.second;     map<char, int> mp;     string str;     cin >> str;     for (int i = 0; i < t; ++i) {       mp[str[i]]++;     }     char dir[] = { NSWE };     map<char, long long> nd;     for (int j = 0; j < 4; ++j) {       nd[dir[j]] = 0;     }     long long xdiff = abs(s.first - e.first);     if (s.first < e.first) {       nd[ E ] = xdiff;     } else if (s.first > e.first) {       nd[ W ] = xdiff;     }     long long ydiff = abs(s.second - e.second);     if (s.second < e.second) {       nd[ N ] = ydiff;     } else if (s.second > e.second) {       nd[ S ] = ydiff;     }     for (int i = 0; i < (int)str.size(); ++i) {       if (nd[str[i]] > 0) {         nd[str[i]]--;       }       int chck = 0;       for (int j = 0; j < 4; ++j) chck += nd[dir[j]] == 0;       if (chck == 4) {         cout << i + 1 << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }