malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};   using namespace std;   template <class T>   T sq(T n) {     return n * n;   }   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   template <class T>   bool inside(T a, T b, T c) {     return a <= b && b <= c;   }   template <class T>   void setmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void setmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   pair<int, int> in[110];   int main() {     int n, T, t = 1, m, i, j, k;     while (scanf( %d , &n) == 1) {       scanf( %d , &k);       double ans = 0;       for (i = 0; i < n; i++) {         scanf( %d , &in[i].first);         scanf( %d , &in[i].second);       }       for (i = 1; i < n; i++) {         ans += sqrt((double)((             ((in[i].first - in[i - 1].first) * (in[i].first - in[i - 1].first)) +             ((in[i].second - in[i - 1].second) *              (in[i].second - in[i - 1].second)))));       }       ans /= (double)50.0;       printf( %.15lf n , ans * (double)k);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double m1 = 200.0, m2 = 0.0, DV;   int card, n, k, Q, getcard;   int a[110], vs[110], b[110], len = 0;   int sum = 0, tmp;   int main() {     memset(vs, 0, sizeof(vs));     scanf( %d%d , &n, &k);     card = (int)(n / k);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     scanf( %d , &Q);     for (int i = 1; i <= Q; ++i) {       sum = 0;       for (int j = 1; j <= card; ++j) {         scanf( %d , &tmp);         sum += a[tmp];         vs[tmp] = 1;       }       DV = double(sum) / double(card);       if (DV < m1) m1 = DV;       if (DV > m2) m2 = DV;     }     for (int i = 1; i <= n; ++i)       if (!vs[i]) b[++len] = a[i];     getcard = (n - len) / card;     if (len >= card && getcard < k) {       sort(b + 1, b + len + 1);       sum = 0;       for (int i = 1; i <= card; ++i) sum += b[i];       DV = double(sum) / double(card);       if (DV < m1) m1 = DV;       if (DV > m2) m2 = DV;       sum = 0;       for (int i = len - card + 1; i <= len; ++i) sum += b[i];       DV = double(sum) / double(card);       if (DV < m1) m1 = DV;       if (DV > m2) m2 = DV;     }     printf( %.10lf %.10lf n , m1, m2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     if (a == 1) {       cout << 1 <<     << 1 << endl << 1 << endl;     } else {       cout << 2 * (a - 1) <<     << 2 << endl << 1 <<     << 2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a = 0, b = 0, r = 0;     while (true) {       a = (int)n / 36;       r = n % 36;       b = (int)r / 3;       if (r % 3 == 2) b += 1;       if (b >= 12)         n = b * 3 + a * 36;       else         break;     }     cout << a <<     << b << endl;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = (int)1e9;   const double inf1 = 1e-9;   const int ss = (int)1e6 + 3;   int main() {     string s;     getline(cin, s);     int sz = s.find( . );     int z1 = 0;     if (sz == -1) {       sz = s.size();       z1 = -1;     }     string res;     int z = 0;     if (s[0] ==  - ) {       res =  ( ;       z = 1;     }     res +=  $ ;     for (int i = z; i < (sz - z) % 3 + z; ++i) res += s[i];     if ((sz - z) % 3 != 0) res +=  , ;     string tmp;     for (int i = (sz - z) % 3 + z; i < sz; i += 3) {       res += s[i];       res += s[i + 1];       res += s[i + 2];       res +=  , ;     }     res.erase(res.size() - 1, 1);     res +=  . ;     s +=  00 ;     res += s[sz + 1 + z1];     res += s[sz + 2 + z1];     if (s[0] ==  - ) {       res +=  ) ;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long ans1, ans2;       long long n, m;       cin >> n >> m;       ans1 = n * m / 2;       ans2 = ans1;       if (n * m % 2) ans1++;       long long x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       long long white1 = (x2 - x1 + 1) * (y2 - y1 + 1) / 2;       long long black1 = white1;       if ((x2 - x1 + 1) * (y2 - y1 + 1) % 2) {         if (abs(x2 - y2) % 2)           black1++;         else           white1++;       }       long long x3, y3, x4, y4;       cin >> x3 >> y3 >> x4 >> y4;       long long white2 = (x4 - x3 + 1) * (y4 - y3 + 1) / 2;       long long black2 = white2;       if ((x4 - x3 + 1) * (y4 - y3 + 1) % 2) {         if (abs(x4 - y3) % 2)           black2++;         else           white2++;       }       long long x5 = max(x1, x3), y5 = max(y1, y3), x6 = min(x2, x4),                 y6 = min(y2, y4);       long long white = 0, black = 0;       if (x5 <= x6 && y5 <= y6) {         long long gapx = x6 - x5 + 1;         long long gapy = y6 - y5 + 1;         white = gapx * gapy / 2;         black = white;         if (gapx * gapy % 2) {           if (abs(x5 - y5) % 2)             black++;           else             white++;         }       }       ans1 -= white;       ans2 -= black;       white1 -= white;       black1 -= black;       white2 -= white;       black2 -= black;       ans1 += black1;       ans2 -= black1;       ans2 += white2;       ans1 -= white2;       ans2 += white + black;       cout << ans1 <<     << ans2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int inf = numeric_limits<int>::max() >> 1;   constexpr int N = 100001;   constexpr int mod = 1000000007;   int h[N], tin[N], tout[N], ap[N], n, root, a[N], T;   int mx[N * 4], mn[N * 4], ml[N * 4];   vector<int> g[N];   void dfs(int u, int p) {     tin[u] = ++T;     ap[T] = u;     h[u] = h[p] + 1;     for (int v : g[u])       if (v != p) dfs(v, u);     tout[u] = T;   }   void build(int id, int l, int r) {     if (l == r) {       mx[id] = h[ap[l]];       mn[id] = a[ap[l]];       ml[id] = h[ap[l]];       return;     }     build((id << 1), l, (l + r) / 2);     build(((id << 1) + 1), (l + r) / 2 + 1, r);     mx[id] = max(mx[(id << 1)], mx[((id << 1) + 1)]);     mn[id] = min(mn[(id << 1)], mn[((id << 1) + 1)]);     ml[id] = min(ml[(id << 1)], ml[((id << 1) + 1)]);     return;   }   int query(int id, int l, int r, int L, int R, int dep) {     if (R < l || r < L) return inf;     if (ml[id] > dep) return inf;     if (L <= l && r <= R && mx[id] <= dep) return mn[id];     return min(query((id << 1), l, (l + r) / 2, L, R, dep),                query(((id << 1) + 1), (l + r) / 2 + 1, r, L, R, dep));   }   void solution() {     cin >> n >> root;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(root, 0);     build(1, 1, n);     int m;     cin >> m;     int last = 0;     while (m--) {       int p, q;       cin >> p >> q;       p = 1 + ((p + last) % n);       q = (q + last) % n;       last = query(1, 1, n, tin[p], tout[p], h[p] + q);       cout << last <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tc = 1;     while (tc--) {       solution();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 1;   int vis[M], vis2[M];   int main() {     string t, s;     cin >> s >> t;     int a = 0, b = 0;     for (char c : t) vis[c]++;     int i = 0;     for (char c : s) {       if (vis[c]) {         vis[c]--;         a++;         vis2[i] = 1;       }       i++;     }     for (i = 0; i < s.size(); i++) {       if (vis2[i]) continue;       char c = s[i];       if (islower(c))         c = toupper(c);       else         c = tolower(c);       if (vis[c]) b++, vis[c]--;     }     cout << a <<     << b;   }
#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7;   int add(int a, int b) {     if ((a += b) >= P) a -= P;     return a;   }   int sub(int a, int b) {     if ((a -= b) < 0) a += P;     return a;   }   int mul(int a, int b) { return 1ll * a * b % P; }   int kpow(int a, int b) {     int r = 1;     for (; b; b >>= 1, a = mul(a, a)) {       if (b & 1) r = mul(r, a);     }     return r;   }   const int N = 205;   int a, b, c, w, n, m, p1, p2;   char ans[N][N];   bool vis[200];   bool solve(int n, int m) {     if (n * m % 2 == 1) return 0;     if (n % 2 == 1) {       if (m / 2 > a) return 0;       a -= m / 2;       for (int i = 1; i <= m; i += 2)         ans[n][i] = ans[n][i + 1] = (i / 2 % 2 == 0 ?  a  :  b );       n--;     }     if (m % 2 == 1) {       if (n / 2 > b) return 0;       b -= n / 2;       for (int i = 1; i <= n; i += 2)         ans[i][m] = ans[i + 1][m] = (i / 2 % 2 == 0 ?  a  :  b );       m--;     }     if (a & 1) a--;     if (b & 1) b--;     if (n * m > a * 2 + b * 2 + c * 4) return 0;     for (int i = 1; i <= n; i += 2)       for (int j = 1; j <= m; j += 2) {         for (int k = ( a ); k < ( z  + 1); k++) vis[k] = 0;         vis[ans[i - 1][j]] = 1;         vis[ans[i - 1][j + 1]] = 1;         vis[ans[i][j - 1]] = 1;         vis[ans[i + 1][j - 1]] = 1;         for (int k = ( c ); k < ( z  + 1); k++)           if (!vis[k]) {             p1 = k;             vis[p1] = 1;             break;           }         for (int k = ( c ); k < ( z  + 1); k++)           if (!vis[k]) {             p2 = k;             vis[p2] = 1;             break;           }         if (a > 0) {           a -= 2;           ans[i][j] = ans[i][j + 1] = p1;           ans[i + 1][j] = ans[i + 1][j + 1] = p2;         } else if (b > 0) {           b -= 2;           ans[i][j] = ans[i + 1][j] = p1;           ans[i][j + 1] = ans[i + 1][j + 1] = p2;         } else {           c--;           ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 1] = p1;         }       }     return 1;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     cin >> n >> m >> a >> b >> c;     bool ok = solve(n, m);     if (!ok)       cout <<  IMPOSSIBLE             <<   n ;     else {       for (int i = (1); i < (n + 1); i++) {         for (int j = (1); j < (m + 1); j++) cout << ans[i][j];         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const long long MOD = 998244353;   vector<vector<pair<long long, long long> > > adj;   int c[2];   int colour[700005];   bool ok;   int n;   void dfs(int idx) {     c[colour[idx]] += (idx <= n);     for (auto x : adj[idx]) {       if (colour[x.first] == -1) {         colour[x.first] = colour[idx] ^ x.second;         dfs(x.first);       } else if (colour[x.first] != (colour[idx] ^ x.second)) {         ok = false;       }     }   }   int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int m;       cin >> n >> m;       adj.assign(n + m + 5, vector<pair<long long, long long> >());       for (int i = 0; i < n + m + 5; i++) {         colour[i] = -1;       }       int fake = n + 1;       for (int i = 0; i < m; i++) {         int a, b;         string c;         cin >> a >> b >> c;         if (c ==  crewmate ) {           adj[a].push_back(pair<long long, long long>(fake, 1));           adj[fake].push_back(pair<long long, long long>(a, 1));           adj[fake].push_back(pair<long long, long long>(b, 1));           adj[b].push_back(pair<long long, long long>(fake, 1));           fake++;         } else {           adj[a].push_back(pair<long long, long long>(b, 1));           adj[b].push_back(pair<long long, long long>(a, 1));         }       }       int ans = 0;       ok = true;       for (int i = 1; i < n + 1; i++) {         if (colour[i] == -1) {           colour[i] = 0;           c[0] = c[1] = 0;           dfs(i);           ans += max(c[0], c[1]);         }       }       if (!ok) {         ans = -1;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   int a[1005];   void Init() {     int i;     a[0] = 1;     a[1] = 1;     for (i = 2; i <= 1000; i++) {       a[i] = a[i - 1] * 3 % 1000003;     }   }   int main() {     int i, n;     Init();     scanf( %d , &n);     printf( %d n , a[n]);     return 0;   }
#include <bits/stdc++.h>   int m, n, a[10][10] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0},                          {2, 0, 1}, {0, 2, 1}, {0, 1, 2}};   int main() {     scanf( %d %d , &n, &m);     n %= 6;     printf( %d , a[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b[100], c, xd = 0, lol;     cin >> a;     for (int i = 0; i < a; i++) {       cin >> b[i];     }     sort(b, b + a);     for (int i = 0; i < a; i++) {       if (i == a - 1) {         c = b[i];       }     }     for (int i = 0; i < a; i++) {       if (b[i] <= c) {         xd = xd + (c - b[i]);       }     }     cout << xd;   }
#include <bits/stdc++.h>   using namespace std;   using UL = unsigned long int;   using UI = unsigned int;   using ULL = unsigned long long int;   using LI = long int;   using LL = long long;   using LF = double;   using LLF = long double;   const int mod1 = 1000000007;   const int mod2 = 998244353;   const double PI = acos(-1);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int ntc = 1, tc, i, j;     int n, k;     for (tc = 1; tc <= ntc; tc++) {       cin >> n >> k;       string s;       cin >> s;       int cnt1[26] = {0}, cnt2[26] = {0};       string ans =   ;       for (auto ch : s) {         cnt1[ch -  a ]++;       }       for (i = 0; i < 26 && k > 0; i++) {         cnt2[i] += min(k, cnt1[i]);         k -= min(k, cnt1[i]);       }       for (auto ch : s) {         if (cnt2[ch -  a ] > 0) {           cnt2[ch -  a ]--;           continue;         }         cout << ch;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1004;   int n, p, q, f[N][54][54], vc = 1000000000, ns[N][30], nt[N][30];   char c[N], s[N], t[N];   bool check1(int i, char x, int j) {     if (i + 1 < j) return false;     for (int k = 1; k < j; k++) {       if (s[i + k - j + 1] != s[k]) return false;     }     if (x != s[j]) return false;     return true;   }   bool check2(int i, char x, int j) {     if (i + 1 < j) return false;     for (int k = 1; k < j; k++) {       if (t[i + k - j + 1] != t[k]) return false;     }     if (x != t[j]) return false;     return true;   }   void build() {     for (int i = 0; i <= p; i++) {       for (char x =  a ; x <=  z ; x++) {         for (int j = p; j >= 1; j--) {           if (check1(i, x, j)) {             ns[i][x -  a  + 1] = j;             break;           }         }       }     }     for (int i = 0; i <= q; i++) {       for (char x =  a ; x <=  z ; x++) {         for (int j = q; j >= 1; j--) {           if (check2(i, x, j)) {             nt[i][x -  a  + 1] = j;             break;           }         }       }     }   }   int cal(int i, int x, int y) {     if (i == n) return 0;     if (f[i][x][y] != -vc) return f[i][x][y];     f[i][x][y] = -vc + 1;     if (c[i + 1] ==  * ) {       for (char b =  a ; b <=  z ; b++) {         int cost = 0;         int nx1 = ns[x][b -  a  + 1];         if (nx1 == p) cost++;         int nx2 = nt[y][b -  a  + 1];         if (nx2 == q) cost--;         f[i][x][y] = max(f[i][x][y], cal(i + 1, nx1, nx2) + cost);       }     } else {       int cost = 0;       char b = c[i + 1];       int nx1 = ns[x][b -  a  + 1];       if (nx1 == p) cost++;       int nx2 = nt[y][b -  a  + 1];       if (nx2 == q) cost--;       f[i][x][y] = max(f[i][x][y], cal(i + 1, nx1, nx2) + cost);     }     return f[i][x][y];   }   int main() {     scanf( %s%s%s , c + 1, s + 1, t + 1);     p = strlen(s + 1);     q = strlen(t + 1);     n = strlen(c + 1);     build();     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= p; j++) {         for (int z = 0; z <= q; z++) f[i][j][z] = -vc;       }     }     cout << cal(0, 0, 0);   }
#include <bits/stdc++.h>   using namespace std;   string S;   set<string> answer;   void izomorphism1(string &s) {     swap(s[0], s[3]);     swap(s[1], s[3]);     swap(s[2], s[3]);   }   void izomorphism2(string &s) {     swap(s[1], s[4]);     swap(s[3], s[5]);     swap(s[4], s[5]);   }   void izomorphism3(string &s) {     swap(s[4], s[2]);     swap(s[0], s[5]);     swap(s[4], s[5]);   }   int main() {     cin >> S;     sort(S.begin(), S.end());     do {       string cur_S, min_string;       cur_S = S;       min_string = S;       for (int i = 1; i <= 4; i++, izomorphism1(cur_S))         for (int j = 1; j <= 4; j++, izomorphism2(cur_S))           for (int z = 1; z <= 4; z++, izomorphism3(cur_S)) {             min_string = min(min_string, cur_S);           }       answer.insert(min_string);     } while (next_permutation(S.begin(), S.end()));     cout << answer.size() << endl;     return 0;   }
#include <bits/stdc++.h>   const unsigned long long maxn = 70;   unsigned long long n, flg, KKK, ans;   unsigned long long f[maxn], mul10[maxn], cycle[maxn], a[maxn];   struct matrix {     unsigned long long len, wid;     unsigned long long mt[3][3];   } pre[14][45];   inline unsigned long long min(unsigned long long a, unsigned long long b) {     return a < b ? a : b;   }   unsigned long long modmul(unsigned long long a, unsigned long long b,                             unsigned long long mod) {     unsigned long long res = 0;     while (b) {       if (b & 1) {         res += a;         if (res > mod) res -= mod;       }       a += a;       if (a > mod) a -= mod;       b >>= 1;     }     return res;   }   matrix mul(matrix a, matrix b, unsigned long long mod) {     matrix res;     res.len = a.len, res.wid = b.wid;     for (unsigned long long u = 1; u <= a.len; u++)       for (unsigned long long v = 1; v <= b.wid; v++) res.mt[u][v] = 0;     for (unsigned long long u = 1; u <= a.len; u++)       for (unsigned long long v = 1; v <= b.wid; v++)         for (unsigned long long w = 1; w <= a.wid; w++)           res.mt[u][v] =               (res.mt[u][v] + modmul(a.mt[u][w], b.mt[w][v], mod)) % mod;     return res;   }   unsigned long long calc(unsigned long long b, unsigned long long kk,                           unsigned long long mod) {     matrix a, res;     res.len = 1, res.wid = 2, res.mt[1][1] = 0, res.mt[1][2] = 1;     for (unsigned long long i = 0; i <= 44; i++)       if ((b >> i) & 1) res = mul(res, pre[kk][i], mod);     return res.mt[1][1];   }   void dfs(unsigned long long len, unsigned long long now) {     if (now > ans) return;     if (len == n + 1) {       flg = 1, ans = min(ans, now);       return;     }     for (unsigned long long i = 0; i < 10; i++) {       unsigned long long k =           (modmul(i, cycle[len], cycle[len + 1]) + now) % cycle[len + 1];       if (calc(k, len, mul10[len]) == a[len]) dfs(len + 1, k);     }   }   signed main() {     f[0] = 0, f[1] = 1;     for (unsigned long long i = 2; i <= 60; i++) f[i] = f[i - 1] + f[i - 2];     cycle[0] = 6, mul10[0] = 1;     for (unsigned long long i = 1; i <= 19; i++)       cycle[i] = 10ll * cycle[i - 1], mul10[i] = 10ll * mul10[i - 1];     for (unsigned long long i = 1; i <= 13; i++) {       pre[i][0].len = pre[i][0].wid = 2, pre[i][0].mt[1][1] = 0,       pre[i][0].mt[1][2] = pre[i][0].mt[2][1] = pre[i][0].mt[2][2] = 1;       for (unsigned long long j = 1; j <= 44; j++)         pre[i][j] = mul(pre[i][j - 1], pre[i][j - 1], mul10[i]);     }     scanf( %llu , &KKK);     n = 13, ans = 10000000000000000;     for (unsigned long long i = 1; i <= n; i++)       a[i] = a[i - 1] + KKK % 10 * mul10[i - 1], KKK /= 10;     for (unsigned long long i = 0; i < 60; i++)       if (f[i] % 10 == a[1]) dfs(1, i);     if (flg == 0)       puts( -1 );     else       printf( %llu n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int main() {     int n, m;     cin >> n >> m;     int now1 = 0;     for (int i = 0; i < n; i++) {       int c, t;       cin >> c >> t;       now1 += c * t;       mp[now1] = 1;     }     map<int, int>::iterator it = mp.begin();     int now = 0;     for (int i = 0; i < m; i++) {       int v;       cin >> v;       while (v > it->first) {         it++;         now++;       }       cout << now + 1 << endl;     }   }
#include <bits/stdc++.h>   struct node {     int x, y;     int dir, len;   } arr[1100 * 1100], st[1100];   int n, m, tot, vis[1100][1100], cnt;   int srow[1100][1100], scol[1100][1100];   int dir[4] = {1, -1, -1, 1};   char mmap[1100][1100];   void Initial() {     int i, j, k;     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j) srow[i][j] = srow[i][j - 1] + vis[i][j];     for (j = 1; j <= m; ++j)       for (i = 1; i <= n; ++i) scol[i][j] = scol[i - 1][j] + vis[i][j];   }   int GetDir(char c) {     if (c ==  N ) return 0;     if (c ==  S ) return 1;     if (c ==  W ) return 2;     if (c ==  E ) return 3;   }   int Isok(int in) {     int i, j, k, x, y;     x = st[in].x, y = st[in].y;     for (i = 1; i <= tot; ++i) {       int td = arr[i].dir, tl = arr[i].len;       if (td == 0) {         if (x - tl <= 0) return 0;         if (scol[x][y] - scol[x - tl - 1][y] > 0) return 0;         x -= tl;       } else if (td == 1) {         if (x + tl >= n + 1) return 0;         if (scol[x + tl][y] - scol[x - 1][y] > 0) return 0;         x += tl;       } else if (td == 2) {         if (y - tl <= 0) return 0;         if (srow[x][y] - srow[x][y - tl - 1] > 0) return 0;         y -= tl;       } else {         if (y + tl >= m + 1) return 0;         if (srow[x][y + tl] - srow[x][y - 1] > 0) return 0;         y += tl;       }     }     cnt++;     return 1;   }   int main() {     int i, j, k;     while (scanf( %d%d , &n, &m) != EOF) {       for (i = 0; i < 26; ++i) st[i].x = -1;       for (i = 1; i <= n; ++i) {         scanf( %s , mmap[i] + 1);         for (j = 1; j <= m; ++j) {           if (mmap[i][j] >=  A  && mmap[i][j] <=  Z )             st[mmap[i][j] -  A ].x = i, st[mmap[i][j] -  A ].y = j;           vis[i][j] = mmap[i][j] ==  #  ? 1 : 0;         }       }       Initial();       scanf( %d , &tot);       for (i = 1; i <= tot; ++i) {         char str[20];         scanf( %s %d , str, &arr[i].len);         arr[i].dir = GetDir(str[0]);       }       cnt = 0;       for (i = 0; i < 26; ++i)         if (st[i].x != -1 && Isok(i)) printf( %c , i +  A );       if (cnt == 0) printf( no solution n );       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000 + 5;   int a[N], b[N];   bool mark[N];   vector<int> ch;   int main() {     int n, m, mn, ans = 0;     cin >> n >> m;     mn = n / m;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] <= m && !mark[a[i]]) {         b[a[i]]++;         if (b[a[i]] == mn) mark[a[i]] = true;       } else         ch.push_back(i);     }     for (int i = 1; i <= m; i++)       while (!mark[i]) {         ans++;         a[ch.back()] = i;         ch.pop_back();         b[i]++;         if (b[i] == mn) mark[i] = true;       }     cout << mn <<     << ans <<   n ;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;     return 0;   }