malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int n, m;   char a[10000];   char b[10000];   int main() {     scanf( %s %s , a, b);     n = strlen(a);     m = strlen(b);     int minn = 10000000;     for (int i = -m + 1; i < n; i++) {       int count = 0;       for (int j = 0; j < m; j++) {         if (i + j < 0 || i + j >= n) {           count++;         } else if (a[i + j] != b[j])           count++;       }       if (count < minn) minn = count;     }     printf( %d n , minn);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   long long mod = 1000000007LL;   long long mod2 = 998244353LL;   int t, n;   int a[200005];   int dp[200005][2];   int main() {     cin >> t;     for (int cas = 1; cas <= t; ++cas) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);       }       for (int i = 0; i <= n; ++i) {         for (int j = 0; j < 2; ++j) {           dp[i][j] = inf;         }       }       dp[0][0] = 0;       for (int i = 0; i < n; ++i) {         if (dp[i][0] < inf) {           if (a[i + 1]) {             dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + 1);           } else {             dp[i + 1][1] = min(dp[i + 1][1], dp[i][0]);           }           if (i + 2 <= n) {             int cnt = a[i + 1] + a[i + 2];             dp[i + 2][1] = min(dp[i + 2][1], dp[i][0] + cnt);           }         }         if (dp[i][1] < inf) {           dp[i + 1][0] = min(dp[i + 1][0], dp[i][1]);           if (i + 2 <= n) {             dp[i + 2][0] = min(dp[i + 2][0], dp[i][1]);           }         }       }       int res = min(dp[n][0], dp[n][1]);       printf( %d n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int inf = 2147483647;   const long double pi = acos(-1);   inline unsigned long long read() {     unsigned long long data = 0, w = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (ch <=  9  && ch >=  0 ) data = data * 10 + ch - 48, ch = getchar();     return data * w;   }   inline void file() {     freopen(          a           .in ,          r , stdin);     freopen(          a           .out ,          w , stdout);   }   int n;   inline int check(unsigned long long x) {     int mx = 1;     for (int i = 2; 1ll * i * i <= x; i++)       if (x % i == 0)         mx = max((unsigned long long)mx, max((unsigned long long)i, x / i));     return mx;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       unsigned long long x = read(), r = x;       int cnt = 0;       while (r) {         cnt++;         r >>= 1;       }       if (x == (1ll << cnt) - 1)         printf( %d n , check(x));       else         printf( %I64d n , (1ll << cnt) - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, max_len = 0, tmpl, tmpr;     pair<int, int> fmaxl, fminr, smaxl(-1, -1), sminr(-1, -1);     cin >> n >> tmpl >> tmpr;     fmaxl = make_pair(tmpl, tmpr);     fminr = make_pair(tmpl, tmpr);     for (int i = 1; i < n; i++) {       cin >> tmpl >> tmpr;       if (tmpl >= fmaxl.first) {         smaxl = fmaxl;         fmaxl = make_pair(tmpl, tmpr);       }       if (tmpr <= fminr.second) {         sminr = fminr;         fminr = make_pair(tmpl, tmpr);       }       if (smaxl.first == -1 || (tmpl < fmaxl.first && tmpl > smaxl.first))         smaxl = make_pair(tmpl, tmpr);       if (sminr.first == -1 || (tmpr > fminr.second && tmpr < sminr.second))         sminr = make_pair(tmpl, tmpr);     }     if (fmaxl == fminr && smaxl == sminr)       cout << sminr.second - sminr.first;     else if (fmaxl == fminr)       cout << max((sminr.second - smaxl.first), (sminr.second - smaxl.first));     else {       max_len = max((fminr.second - smaxl.first), (sminr.second - fmaxl.first));       max_len < 0 ? cout << 0 : cout << max_len;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int i, j, k, l, m, n, t, r, cnt;     int flag = 0;     long long ans = 0, an = 0;     t = 1;     while (t--) {       cin >> n >> m;       cout << min(n, m) + 1 << endl;       int x, y;       x = 0;       y = m;       while (x <= n && y >= 0) {         cout << x <<     << y << endl;         x++;         y--;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, diff = 0;     bool flag = 1;     scanf( %d , &n);     int a[n];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (i == 1) diff = a[i] - a[i - 1];     }     for (int i = 1; i < n; i++) {       if (a[i] - a[i - 1] != diff) {         flag = 0;         break;       }     }     if (flag)       printf( %d n , a[0] + n * diff);     else       printf( %d n , a[n - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long sqr(long long x) { return x * x; }   mt19937 Random((int)time(0));   inline long long rnd(long long x) { return Random() % x; }   const long long INF = (long long)1e9 + 2018;   const long long MOD = (long long)1e9 + 7;   const long double PI = acos(-1.0);   pair<int, int> cnt(int n) {     if (n & 1) {       return {sqr(n / 2 + 1) + sqr(n / 2), n * n - sqr(n / 2 + 1) - sqr(n / 2)};     } else {       return {n * n / 2, n * n / 2};     }   }   void $main() {     int n;     cin >> n;     int a = 0, b = 0;     for (int i = 0; i < n; i++) {       string s;       cin >> s >> s;       a += s ==  hard ;       b += s ==  soft ;     }     for (int i = 1;; i++) {       pair<int, int> res = cnt(i);       if ((res.first >= a && res.second >= b) ||           (res.second >= a && res.first >= b)) {         cout << i;         return;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.setf(ios_base::fixed, ios_base::floatfield);     cout.precision(10);     $main();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 7;   int T, n, vis[N], can[N];   map<char, int> mp, ha = {{ ? , 0}, { V , 1}, { K , 2}};   char s[N];   bool check(int l) {     static int vis[N];     for (int i = 0; i < l; ++i) {       int who = ha[s[i]], now = i + l;       while (now < n) {         if (who && s[now] !=  ?  && who != ha[s[now]]) return false;         if (s[now] !=  ? ) who = ha[s[now]];         now += l;       }     }     return true;   }   int main() {     cin >> T;     while (T--) {       scanf( %d , &n);       scanf( %s , s);       memset(vis, 0, sizeof(int) * (n + 1));       memset(can, 0, sizeof(int) * (n + 1));       mp.clear();       for (int i = 0; i < n; ++i) mp[s[i]] = 1;       if (mp[ V ] + mp[ K ] <= 1) {         printf( %d n , n);         for (int i = 1; i <= n; ++i) printf( %d%c , i, i == n ?   n  :    );         continue;       }       for (int i = 2; i <= n; ++i) {         if (!vis[i]) {           if (check(i)) {             for (int j = i; j <= n; j += i) can[j] = true, vis[j] = 0;             can[i] = true;           }         }       }       int ans = 0, first = 1;       for (int i = 2; i <= n; ++i) ans += can[i];       printf( %d n , ans);       for (int i = 2; i <= n; ++i) {         if (can[i]) {           if (first)             first = false;           else             putchar(   );           printf( %d , i);         }       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, res;   int mat[405][405];   int cnt[405][405][4];   bool valid(int x1, int y1, int x2, int y2) {     int num = 2;     if (x1 == x2) num = 1;     if (y1 == y2) num = 0;     if (x1 + y1 == x2 + y2) num = 3;     return cnt[x1][y1][num] == cnt[x2][y2][num];   }   void check(int x1, int y1, int x2, int y2, int x3, int y3) {     if (x1 < 1 || y1 < 1 || x2 < 1 || y2 < 1 || x3 < 1 || y3 < 1) return;     if (x1 > n || y1 > m || x2 > n || y2 > m || x3 > n || y3 > m) return;     if (mat[x1][y1] || mat[x2][y2] || mat[x3][y3]) return;     if (!valid(x1, y1, x2, y2)) return;     if (!valid(x2, y2, x3, y3)) return;     if (!valid(x1, y1, x3, y3)) return;     res++;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         char c;         cin >> c;         mat[i][j] = (c -  0 );         cnt[i][j][0] = cnt[i - 1][j][0] + mat[i][j];         cnt[i][j][1] = cnt[i][j - 1][1] + mat[i][j];         cnt[i][j][2] = cnt[i - 1][j - 1][2] + mat[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = m; j >= 1; j--) {         cnt[i][j][3] = cnt[i - 1][j + 1][3] + mat[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int k = 1; k <= min(n, m); k++) {           check(i, j, i + k, j, i, j + k);           check(i, j, i - k, j, i, j + k);           check(i, j, i + k, j, i, j - k);           check(i, j, i - k, j, i, j - k);           check(i - k, j, i, j + k, i, j - k);           check(i + k, j, i, j + k, i, j - k);           check(i + k, j, i - k, j, i, j - k);           check(i + k, j, i - k, j, i, j + k);         }       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool upmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool upmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const long double eps = 1e-11;   const long double pi = acos(-1);   const int oo = 1 << 30;   const long long loo = 1ll << 62;   const int MAXN = 5005;   const int mods = 998244353;   const int INF = 0x3f3f3f3f;   inline int read() {     int f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   int f[MAXN][MAXN][2], g[MAXN][2], cnt[MAXN], num = 0, n;   vector<int> e[MAXN];   void tree_dp(int x, int father) {     int flag = 0;     for (auto v : e[x])       if (v != father) flag = 1, tree_dp(v, x);     if (!flag)       f[x][0][0] = f[x][1][1] = 0, cnt[x] = 1;     else       f[x][0][0] = f[x][0][1] = cnt[x] = 0;     for (auto v : e[x])       if (v != father) {         cnt[x] += cnt[v];         for (int i = cnt[x]; i >= 0; i--) {           g[i][0] = INF, g[i][1] = INF;           for (int j = min(cnt[v], i); j >= 0; j--) {             upmin(g[i][0], min(f[x][i - j][0] + f[v][j][0],                                f[x][i - j][0] + f[v][j][1] + 1));             upmin(g[i][1], min(f[x][i - j][1] + f[v][j][0] + 1,                                f[x][i - j][1] + f[v][j][1]));           }           f[x][i][0] = g[i][0], f[x][i][1] = g[i][1];         }       }   }   signed main() {     n = read();     for (int i = 1, u, v; i < n; i++)       u = read(), v = read(), e[u].push_back(v), e[v].push_back(u);     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) f[i][j][0] = f[i][j][1] = INF;     for (int i = 1; i <= n; i++)       if (e[i].size() > 1) {         tree_dp(i, 0);         printf( %d n , min(f[i][cnt[i] / 2][0], f[i][cnt[i] / 2][1]));         return 0;       }     puts( 1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   int t;   int dp[52][1005][1005];   int dp2[52][1005];   int c[1501][60];   long long f[100];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     dp[0][0][1] = 1;     f[0] = 1;     for (long long i = 1; i <= 50; ++i) f[i] = (f[i - 1] * i) % md;     for (int i = 0; i <= 50; ++i) {       for (int j = 0; j <= 1001; ++j) {         long long sum = 0;         for (int k = 0; k <= 1001; ++k) {           sum = sum + dp[i][j][k];           if (sum > md) sum -= md;           if (j + k <= 1000) {             dp[i + 1][j + k][k + 1] = dp[i + 1][j + k][k + 1] + sum;             if (dp[i + 1][j + k][k + 1] > md) dp[i + 1][j + k][k + 1] -= md;           }         }         for (int k = 1; k <= 1001; ++k) {           dp2[i][j] = (dp2[i][j] + dp[i][j][k]);           if (dp2[i][j] > md) dp2[i][j] -= md;         }         dp2[i][j] = (dp2[i][j] * f[i]) % md;       }     }     c[0][0] = 1;     for (int i = 1; i <= 1500; ++i)       for (int j = 0; j <= min(55, i); ++j) {         c[i][j] = c[i - 1][j];         if (j) c[i][j] += c[i - 1][j - 1];         if (c[i][j] >= md) c[i][j] -= md;       }     for (int i = 1; i <= t; ++i) {       int x, y;       cin >> x >> y;       long long res = 0;       if (y > 50) {         cout <<  0  <<   n ;         continue;       }       for (int i = 0; i <= x; ++i)         res = (res +                (long long)((long long)dp2[y][i] * (long long)c[x - i + y][y]) %                    md) %               md;       cout << res <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n + 1];     int i, m, k, l, x, y;     for (i = 1; i <= n; i++) cin >> a[i];     cin >> m;     for (i = 0; i < m; i++) {       cin >> x >> y;       a[x - 1] += y - 1;       a[x + 1] += (a[x] - y);       a[x] = 0;     }     for (i = 1; i <= n; i++) cout << a[i] << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, m, x, y;       cin >> n >> m >> x >> y;       if (2 * x < y) y = 2 * x;       vector<vector<long long>> grid(n, vector<long long>(m));       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           char c;           cin >> c;           if (c ==  . )             grid[i][j] = 0;           else             grid[i][j] = 1;         }       }       long long sum = 0;       for (long long i = 0; i < n; i++) {         vector<pair<long long, long long>> all;         all.push_back({grid[i][0], 1});         for (long long j = 1; j < m; j++) {           if (grid[i][j] == all.back().first)             all.back().second++;           else             all.push_back({grid[i][j], 1});         }         for (auto it : all) {           if (it.first == 0) {             long long a = it.second / 2, b = it.second % 2;             sum += a * y;             sum += b * x;           }         }       }       cout << sum <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int jou[n + 1];     vector<bool> u(n + 1, false);     int k = 1;     for (int i = 1; i < n + 1; i++) {       cin >> jou[i];       if (u[jou[i]] == false) {         u[jou[i]] = true;       } else         k++;     }     cout << k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long rdtsc() {     long long tmp;     asm( rdtsc  :  =A (tmp));     return tmp;   }   inline int myrand() { return abs((rand() << 15) ^ rand()); }   inline int rnd(int x) { return myrand() % x; }   const int INF = (int)1.01e9;   const long double EPS = 1e-9;   void precalc() {}   long long x;   bool read() {     if (scanf( %lld , &x) < 1) {       return 0;     }     return 1;   }   void solve() {     vector<pair<long long, long long> > ans;     for (long long t = 1;; ++t) {       long long a = t * (t + 1) / 2;       long long b = a * (2 * t + 1) / 3;       if (b > x) {         break;       }       long long left = x - b;       if (left % a) {         continue;       }       left /= a;       ans.push_back(make_pair(t, t + left));       if (left) {         ans.push_back(make_pair(t + left, t));       }     }     printf( %d n , ((int)(ans).size()));     sort(ans.begin(), ans.end());     for (int i = 0; i < ((int)(ans).size()); ++i) {       printf(            %lld                           %lld              n ,           ans[i].first, ans[i].second);     }   }   int main() {     srand(rdtsc());     precalc();     while (1) {       if (!read()) {         break;       }       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Mod = 1e9 + 7;   int n, inv;   long long m;   long long A[30];   inline int Qpow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = (long long)ans * a % Mod;       b >>= 1;       a = (long long)a * a % Mod;     }     return ans;   }   inline int C(long long a) {     if (a < (n - 1)) return 0;     long long res = 1;     for (int i = 0; i < n - 1; i++) res = res * ((a - i) % Mod) % Mod;     return res * inv % Mod;   }   inline void Init() {     cin >> n >> m;     inv = 1;     for (int i = 2; i < n; i++) inv = (long long)inv * i % Mod;     inv = Qpow(inv, Mod - 2);     for (int i = 1; i <= n; i++) cin >> A[i];   }   inline void Work() {     int res = 0;     for (int i = 0; i < (1 << n); i++) {       long long a = n + m - 1;       int flag = 1;       for (int j = 0; j < n; j++) {         if ((i >> j) & 1) {           flag *= -1;           a -= A[j + 1] + 1;         }       }       res = ((long long)res + (long long)flag * C(a) % Mod) % Mod;     }     cout << (res + Mod) % Mod << endl;   }   int main() {     Init();     Work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   const int inf = 1e9;   vector<int> getArray(int *a, int n, int k) {     vector<int> ret;     for (int i = 0; i < n * k; i++) {       if (i < n)         ret.push_back(a[i]);       else         ret.push_back(a[i % n]);     }     return ret;   }   vector<int> myLIS(vector<int> a, int n) {     vector<int> dp, ret;     dp.resize(n + 1);     dp[0] = -inf;     for (int i = 1; i <= n; i++) dp[i] = 1000;     for (int i = 0; i < n; i++) {       int tmp = upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin();       ret.push_back(tmp);       dp[tmp] = a[i];     }     return ret;   }   int main() {     int n, T, a[maxn];     scanf( %d%d , &n, &T);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int ret = 0;     if (T <= 1000) {       vector<int> prefix = myLIS(getArray(a, n, T), n * T);       for (int i = 0; i < n * T; i++) {         ret = max(ret, prefix[i]);       }     } else {       vector<int> newA = getArray(a, n, n);       vector<int> prefix = myLIS(newA, n * n);       for (int i = 0; i < newA.size(); i++) {         newA[i] = -newA[i];       }       reverse(newA.begin(), newA.end());       vector<int> suffix = myLIS(newA, n * n);       for (int i = 0; i < n; i++) {         int cnt = 0;         for (int j = 0; j < n; j++)           if (a[i] == a[j]) cnt++;         for (int j = 0; j < n; j++) {           if (a[j] < a[i]) continue;           ret = max(ret, prefix[(n - 1) * n + i] + cnt * (T - 2 * n) +                              suffix[n * n - j - 1]);         }       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     set<int> st;     for (int i = 0; i < n; i++) {       cin >> a[i];       st.insert(a[i]);     }     set<int>::iterator it = st.begin();     it++;     if (it == st.end())       cout <<  NO ;     else       cout << (*it);     return 0;   }
#include <bits/stdc++.h>   int main() {     long a, b, c;     scanf( %ld%ld%ld , &a, &b, &c);     if (b == a) {       printf( YES n );     } else if (c > 0) {       if (b < a) {         printf( NO n );       } else if (((b - a) % c) == 0) {         printf( YES n );       } else {         printf( NO n );       }     } else if (c < 0) {       if (b > a) {         printf( NO n );       } else if (((a - b) % c) == 0) {         printf( YES n );       } else {         printf( NO n );       }     } else {       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 100;   const long long inf = 0x3f3f3f3f3f;   int n;   int a[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       if (i != n) {         int q;         cout <<  ?               <<   1               <<     << i + 1 << endl;         cin >> q;         a[i + 1] = q;       } else {         int q;         cout <<  ?               <<                  <<  2               <<     << 3 << endl;         cin >> q;         a[1] = (a[2] + a[3] - q) / 2;       }     }     cout <<  !  ;     for (int i = 1; i <= n; i++) {       if (i == 1)         cout << a[1] <<    ;       else         cout << a[i] - a[1] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int mob[2000005], vis[2000005], p[1000005];   long long cnt[2000005], cnt2[2000005], pnum;   bool prime[1000005];   long long mod = 1e9 + 7;   int read() {     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       ;     int x = c - 48;     for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c - 48;     return x;   }   void Mobius() {     int i, j;     pnum = 0;     memset(prime, true, sizeof(prime));     mob[1] = 1;     for (i = 2; i < 1000005; i++) {       if (prime[i]) {         p[pnum++] = i;         mob[i] = -1;       }       for (j = 0; j < pnum && (long long)i * p[j] < 1000005; j++) {         prime[i * p[j]] = false;         if (i % p[j] == 0) {           mob[i * p[j]] = 0;           break;         }         mob[i * p[j]] = -mob[i];       }     }   }   int main(void) {     int n, m, x, T, MAX, ca = 1;     long long ans, temp, k, kk, nnn, res, i, j;     Mobius();     n = read();     k = read();     kk = read();     nnn = k / kk;     memset(cnt, 0, sizeof(cnt));     memset(cnt2, 0, sizeof(cnt2));     MAX = 1;     for (i = 1; i <= n; i++) {       x = read();       cnt[x]++;       cnt2[x] += x;       MAX = max(MAX, x);     }     for (int i = 1; i <= 2000000; i++) {       cnt[i] += cnt[i - 1];       cnt2[i] += cnt2[i - 1];     }     ans = -1;     T = 0;     for (i = p[T]; T < pnum; i = p[T]) {       T++;       res = 0;       for (j = i; j <= 1000000 + i; j += i) {         if (nnn >= i) {           res += (((cnt[j - 1] - cnt[j - i]) * j) - (cnt2[j - 1] - cnt2[j - i])) *                  kk;         } else {           res += (cnt[j - nnn - 1] - cnt[j - i]) * k;           res += (((cnt[j - 1] - cnt[j - nnn - 1]) * j) -                   (cnt2[j - 1] - cnt2[j - nnn - 1])) *                  kk;         }       }       if (ans == -1) ans = res;       ans = min(ans, res);     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   set<vector<int> > DP[10001];   bool R[4];   int main() {     cin >> n;     cin >> s;     for (int i = 0; i < s.size(); i++)       if (s[i] ==  G )         s[i] =  0 ;       else if (s[i] ==  S )         s[i] =  1 ;       else if (s[i] ==  H )         s[i] =  2 ;       else if (s[i] ==  R )         s[i] =  3 ;     vector<int> E(4, 0);     DP[0].insert(E);     for (int i = 0; i < n; i++) {       set<vector<int> >::iterator it;       for (it = DP[i].begin(); it != DP[i].end(); it++) {         vector<int> T;         T = *it;         int q = min(T[0], min(T[1], min(T[2], T[3])));         for (int j = 0; j < 4; j++) {           if ((s[i] !=  ?  && (j == (s[i] -  0 )) ||                (s[i] ==  ?  && T[j] == q))) {             vector<int> N;             N = T;             N[j]++;             int p = min(N[0], min(N[1], min(N[2], N[3])));             for (int l = 0; l < 4; l++) N[l] -= p;             DP[i + 1].insert(N);           }         }       }     }     set<vector<int> >::iterator it;     for (it = DP[n].begin(); it != DP[n].end(); it++) {       vector<int> T;       T = *it;       int q = min(T[0], min(T[1], min(T[2], T[3])));       for (int j = 0; j < 4; j++)         if (T[j] == q) R[j] = true;     }     if (R[0]) cout <<  Gryffindor  << endl;     if (R[2]) cout <<  Hufflepuff  << endl;     if (R[3]) cout <<  Ravenclaw  << endl;     if (R[1]) cout <<  Slytherin  << endl;     cin >> n;     return 0;   }