malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const long long N = 200005;   long long hi, ls, n, X[N], t, A[N], bk[N];   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> t;     for (int i = 0; i < n; ++i) {       cin >> A[i];     }     for (int i = 0; i < n; ++i) {       cin >> X[i], --X[i];     }     for (int i = 0; i < n; ++i) {       if ((X[i] < i || (i < n - 1 && X[i] > X[i + 1])) ||           (X[i] != i &&            (X[X[i]] != X[i] || (X[i] + 1 < n && A[X[i] + 1] - 1 == A[X[i]])))) {         cout <<  No , std::exit(0);       }     }     for (int i = 0; i < n; ++i) {       if (X[i] > i) {         for (int j = max(hi, 1ll + i); j < X[i] + 1; ++j) {           bk[j] = 1;         }         hi = max(hi, X[i]);       }     }     cout <<  Yes n ;     for (int i = 0; i < n; ++i)       (i < n - 1 && bk[i + 1] ? hi = A[i + 1] + t : hi = A[i] + t),           (i > 0 && hi == ls ? cout << hi + 1 <<     : cout << hi <<    ),           ls = hi;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string a;   void convA() {     int c = 0, r = 0;     int i;     for (i = 1; a[i] !=  C ; i++) {       r *= 10;       r += a[i] -  0 ;     }     i++;     for (; i < a.size(); i++) {       c *= 10;       c += a[i] -  0 ;     }     vector<int> ans;     while (c != 0) {       if (c % 26 == 0) {         ans.push_back(26);         c--;       } else         ans.push_back(c % 26);       c /= 26;     }     for (int i = ans.size() - 1; i >= 0; i--) {       char ab = ans[i] + ( A  - 1);       cout << ab;     }     cout << r;     cout << endl;   }   void convB() {     vector<int> ans;     int i;     for (i = 0; a[i] >=  A  && a[i] <=  Z ; i++) {       if (a[i] ==  Z )         ans.push_back(26);       else         ans.push_back(a[i] -  A  + 1);     }     int c = 0, r;     for (int j = 0; j < ans.size(); j++) {       c += ans[j] * pow(26, ans.size() - j - 1);     }     cout <<  R ;     for (; i < a.size(); i++) cout << a[i];     cout <<  C  << c << endl;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       bool RC = false, k = false;       if (a.size() >= 4) {         if (a[0] ==  R  && !(a[1] >=  A  && a[1] <=  Z ))           RC = true;         else           RC = false;         for (int i = 2; RC && i < a.size(); i++) {           if (a[i] >=  A  && a[i] <=  Z  && k) {             RC = false;             break;           }           if (a[i] ==  C  && !k) k = true;         }         if (RC && k) convA();       }       if (!RC || !k) convB();     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   using namespace std;   const long long N = 1e6 + 5;   void pairsort(long long a[], long long b[], long long n) {     pair<long long, long long> pairt[n];     for (long long i = 0; i < n; i++) {       pairt[i].first = a[i];       pairt[i].second = b[i];     }     sort(pairt, pairt + n);     for (long long i = 0; i < n; i++) {       a[i] = pairt[i].first;       b[i] = pairt[i].second;     }   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long isPrime(long long n) {     if (n < 2) return 0;     if (n < 4) return 1;     if (n % 2 == 0 or n % 3 == 0) return 0;     for (long long i = 5; i * i <= n; i += 6)       if (n % i == 0 or n % (i + 2) == 0) return 0;     return 1;   }   long long C(long long n, long long r) {     if (r > n - r) r = n - r;     long long ans = 1;     for (long long i = 1; i <= r; i++) {       ans *= n - r + i;       ans /= i;     }     return ans;   }   long long mod = 1e9 + 7;   long long modexpo(long long x, long long p) {     long long res = 1;     x = x % mod;     while (p) {       if (p % 2) res = res * x;       p >>= 1;       x = x * x % mod;       res %= mod;     }     return res;   }   struct pair_hash {     template <class T1, class T2>     std::size_t operator()(std::pair<T1, T2> const &pair) const {       std::size_t h1 = std::hash<T1>()(pair.first);       std::size_t h2 = std::hash<T2>()(pair.second);       return h1 ^ h2;     }   };   long long n, x, y, f[N], vis[N], a[N], k;   set<pair<long long, long long>, greater<pair<long long, long long>>> s;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> x;     for (long long i = 1; i <= n; i++) {       cin >> y, a[i] = y;       if (x == y)         f[x]++;       else {         s.erase({f[y], y}), f[y]++, s.insert({f[y], y});         pair<long long, long long> p = *s.begin();         if (p.first >= f[x]) k = 1;       }     }     if (!k) return cout << -1, 0;     memset(f, 0, sizeof(f));     unordered_set<pair<long long, long long>, pair_hash> ss;     for (long long i = 1; i <= 1e6; i++)       if (x != i) ss.insert({0, i});     for (long long i = 1; i <= n; i++) {       if (x == a[i]) {         f[x]++;         vector<long long> vv;         for (auto it = ss.begin(); it != ss.end(); it++)           if ((*it).first < f[x])             vv.push_back({(*it).second}), vis[(*it).second] = 1;         for (long long i = 0; i < vv.size(); i++) ss.erase({f[vv[i]], vv[i]});       } else if (!vis[a[i]])         ss.erase({f[a[i]], a[i]}), f[a[i]]++, ss.insert({f[a[i]], a[i]});     }     vector<long long> vv;     for (auto it = ss.begin(); it != ss.end(); it++)       if (vis[(*it).second]) vv.push_back((*it).second);     for (long long i = 0; i < vv.size(); i++) ss.erase({f[vv[i]], vv[i]});     if (!ss.size()) return cout << -1, 0;     cout << (*ss.begin()).second;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m[367], f[367];   int main() {     memset(m, 0, sizeof(m));     memset(f, 0, sizeof(f));     int N;     cin >> N;     char ch;     int a, b;     for (int i = 0; i < N; ++i) {       cin >> ch >> a >> b;       if (ch ==  M )         for (int j = a; j <= b; ++j) ++m[j];       else         for (int j = a; j <= b; ++j) ++f[j];     }     int res = 0;     for (int i = 1; i <= 366; ++i) res = max(res, min(m[i], f[i]) * 2);     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char t;   int n, m;   char a[11][11];   bool used[11][11];   int kol = 0;   int maxleng = 0;   void dfs(int x, int y, bool ch, int leng = 0) {     if (x < 0 || y < 0 || x >= n || y >= m) return;     if (a[x][y] == 2) return;     if (used[x][y]) return;     used[x][y] = true;     if (ch) ++leng;     if (x - 1 >= 0 && y >= 0 && x - 1 < n && y < m && a[x][y] == !a[x - 1][y])       dfs(x - 1, y, !ch, leng);     if (x >= 0 && y - 1 >= 0 && x < n && y - 1 < m && a[x][y] == !a[x][y - 1])       dfs(x, y - 1, !ch, leng);     if (x >= 0 && y + 1 >= 0 && x < n && y + 1 < m && a[x][y] == !a[x][y + 1])       dfs(x, y + 1, !ch, leng);     if (x + 1 >= 0 && y >= 0 && x + 1 < n && y < m && a[x][y] == !a[x + 1][y])       dfs(x + 1, y, !ch, leng);     maxleng = max(maxleng, leng);   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         cin >> t;         if (t ==  . ) a[i][j] = 2;         if (t ==  P ) a[i][j] = 0;         if (t ==  W ) a[i][j] = 1;         used[i][j] = false;       }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (!used[i][j]) maxleng = 0, dfs(i, j, 0), kol += maxleng;     cout << kol;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)2e5 + 5;   int n, t;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     while (cin >> n) {       int ans = 0;       set<int> s;       for (int i = 1; i <= n && cin >> t; ++i) {         if (t) {           if (s.count(t))             ans++;           else             s.insert(t);         } else           ans++;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const int inf = 0x3f3f3f3f;   int main() {     int t;     t = 1;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       long long ans = 0;       for (int i = (a); i < (b + 1); i++) {         long long l = b - 1, r = c + 2;         while (l < r - 1) {           long long mid = l + r >> 1;           if (mid + i > c) {             r = mid;           } else {             l = mid;           }         }         if (r <= c && i + r > c) {           if (i + r <= d + 1) {             long long mx = min(i + c, d + 1);             ans += (i + r - c + mx - c) * (mx - (i + r) + 1) / 2;           }           if (i + c > d + 1) {             long long x = max(d + 2 - i, r);             ans += (d + 1 - c) * (c - x + 1);           }         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   double alto, ancho, altomesa, anchomesa, ancho1, alto1, x_1, x_2, y_1, y_2;   double abajo() {     if (altomesa <= y_1) return 0;     return altomesa - y_1;   }   double arriba() {     if (altomesa <= alto - y_2) return 0;     return altomesa - (alto - y_2);   }   double izquierda() {     if (anchomesa <= x_1) return 0;     return anchomesa - x_1;   }   double derecha() {     if (anchomesa <= ancho - x_2) return 0;     return anchomesa - (ancho - x_2);   }   void solve() {     cin >> ancho >> alto;     cin >> x_1 >> y_1 >> x_2 >> y_2;     cin >> anchomesa >> altomesa;     ancho1 = x_2 - x_1, alto1 = y_2 - y_1;     if (ancho1 + anchomesa > ancho && alto1 + altomesa > alto) {       cout << -1;       return;     }     double ans = 100000000;     if (ancho1 + anchomesa <= ancho) {       ans = min(ans, izquierda());       ans = min(ans, derecha());     }     if (alto1 + altomesa <= alto) {       ans = min(ans, arriba());       ans = min(ans, abajo());     }     printf( %.6f , ans);   }   int main() {     int T = 1;     cin >> T;     cout <<   n ;     while (T--) solve(), cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void run();   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(3);     srand(42);     run();   }   template <typename T1, typename T2>   bool mini(T1 &a, const T2 &b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T1, typename T2>   bool maxi(T1 &a, const T2 &b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const long long N = 52;   long long rcnt[N];   long long ccnt[N];   void run() {     long long n, m;     cin >> n >> m;     set<long long> masks;     for (long long i = 0; i < n; i++) {       long long kek = 0;       for (long long j = 0; j < m; j++) {         char c;         cin >> c;         if (c ==  # ) kek |= (1LL << j);       }       masks.insert(kek);     }     for (auto it1 = masks.begin(); it1 != masks.end(); it1++) {       auto it2 = it1;       it2++;       for (; it2 != masks.end(); it2++) {         if ((*it1) & (*(it2))) {           cout <<  No ;           return;         }       }     }     cout <<  Yes ;   }
#include <bits/stdc++.h>   using namespace std;   long long c[2000010];   long long sum[2000010];   int main() {     int n, x, y;     while (cin >> n >> x >> y) {       memset(c, 0, sizeof c);       memset(sum, 0, sizeof sum);       for (int i = 1; i <= n; i++) {         int w;         scanf( %d , &w);         c[w]++;         sum[w] += w;       }       for (int i = 0; i <= 2000000; i++) {         c[i] += c[i - 1];         sum[i] += sum[i - 1];       }       long long ans = 1LL * n * x;       for (int i = 2; i <= 1000000; i++) {         long long tmp = 0;         for (int j = i; j <= 1000000 + i && tmp < ans; j += i) {           int k = max(j - i, j - ((x - 1) / y + 1));           long long h = y * ((c[j] - c[k]) * j - (sum[j] - sum[k]));           h += (c[k] - c[j - i]) * x;           tmp += h;         }         ans = min(ans, tmp);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int T = 1, inf = 10000000000;   bool check(long long int n) {     long long int flag = 1;     while (n > 0) {       if (n % 10 != 4 && n % 10 != 7) {         flag = 0;         break;       }       n /= 10;     }     return flag;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     while (T--) {       long long int n, sz = 3, ans = 0, blag = 0, u, mn, ev = 0, mx, mini, i, v,                        q, p, j, k, w, h, l, m, x, y, od = 0, total = 0, cc = 0,                        pp = 0, flag = 0, klag = 0, sum = 0;       string s, s3, s1 =  YES , s2 =  NO ;       bool ok = 0;       cin >> n;       for (i = 4; i <= n; i += 1) {         if (n % i == 0) {           if (check(i)) {             cout << s1;             return 0;           }         }       }       cout << s2;       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 10;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int bit = 32;   const double pi = acos(-1.0);   int a[M];   int dfs(int k, int l, int r) {     if (l > r) return 0;     if (k < 0) return 1;     int mid = r;     int t = 1 << k;     for (int i = l; i <= r; i++) {       if (t & a[i]) {         mid = i - 1;         break;       }     }     int x = dfs(k - 1, l, mid), y = dfs(k - 1, mid + 1, r);     return max(x + min(r - mid, 1), y + min(mid - l + 1, 1));   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     printf( %d n , n - dfs(30, 1, n));     return 0;   }
#include <bits/stdc++.h>   template <class T>   inline void read(T &x) {     x = 0;     int ne = 0;     char c;     while (!isdigit(c = getchar())) ne = c ==  - ;     x = c - 48;     while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48;     x = ne ? -x : x;     return;   }   const int maxn = 1005;   const int inf = 0x7fffffff;   int g[maxn][maxn];   int okx[maxn][maxn], oky[maxn][maxn];   int sum[maxn][maxn];   bool flag[maxn][maxn];   char s[maxn];   int n, m;   struct Star {     int x, y, size;     Star(int a, int b, int c) { x = a, y = b, size = c; }     Star() { ; }   } st[1000005];   int tot = 0;   int len;   inline bool solve(int i, int j) {     int p = 1, k = 0;     len = 0;     while (p != 0) {       int x = p + k;       if (j - x >= 1 && j + x <= m && i + x <= n && i - x >= 1 &&           (sum[i][j] - sum[i][j - 1] - sum[i - x - 1][j] +                sum[i - x - 1][j - 1] >=            (x + 1)) &&           (sum[i + x][j] - sum[i + x][j - 1] - sum[i - 1][j] +                sum[i - 1][j - 1] >=            (x + 1))) {         if ((sum[i][j] - sum[i][j - x - 1] - sum[i - 1][j] +                  sum[i - 1][j - x - 1] >=              (x + 1)) &&             (sum[i][j + x] - sum[i - 1][j + x] - sum[i][j - 1] +                  sum[i - 1][j - 1] >=              (x + 1))) {           k += p, p = p << 1;           x = p + k;         } else           p = p / 2;       } else         p = p / 2;       x = p + k;       while (j - x < 1 || j + x > m || i + x > n || i - x < 1 && p) {         p = p >> 1;         x = p + k;       }     }     len = k;     if (!len) return 0;     okx[i][j - len]++, okx[i][j + len + 1]--;     oky[j][i - len]++, oky[j][i + len + 1]--;     return 1;   }   int main() {     read(n), read(m);     for (register int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (register int j = 1; j <= m; j++) {         if (s[j] ==  * )           g[i][j] = 1;         else           g[i][j] = 0;         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + g[i][j];       }     }     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) {         if (g[i][j]) {           if (solve(i, j)) {             st[++tot] = Star(i, j, len);           }         }       }     }     for (register int i = 1; i <= n; i++) {       int tmp = 0;       for (register int j = 1; j <= m; j++) {         tmp += okx[i][j];         if (tmp) flag[i][j] = 1;       }     }     for (register int i = 1; i <= m; i++) {       int tmp = 0;       for (register int j = 1; j <= n; j++) {         tmp += oky[i][j];         if (tmp) flag[j][i] = 1;         if (g[j][i] && !flag[j][i]) {           puts( -1 );           return 0;         }       }     }     printf( %d n , tot);     for (register int i = 1; i <= tot; i++) {       printf( %d %d %d n , st[i].x, st[i].y, st[i].size);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   clock_t time_p = clock();   void rtime() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << fixed << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   bool isPrime(long long n) {     for (long long i = 2; i * i <= n; ++i) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long factorial(long long n) {     return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);   }   long long power(long long x, long long y) {     long long res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y >> 1;       x = (x * x) % mod;     }     return res % mod;   }   long long ncr(long long n, long long r) {     long long res = 1;     if (r > n) return 0;     if (r > n - r) r = n - r;     for (long long i = 0; i < r; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }   long long max(long long a, long long b) {     long long ans = a > b ? a : b;     return ans;   }   long long min(long long a, long long b) {     long long ans = a < b ? a : b;     return ans;   }   bool cmp(long long x, long long y) { return x > y; }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       if (n == 2)         cout <<  2 n ;       else if (n % 2 == 0)         cout <<  0 n ;       else         cout <<  1 n ;     }     rtime();   }
#include <bits/stdc++.h>   using namespace std;   int read(int &x) { return scanf( %d , &x); }   int read(int &x, int &y) { return scanf( %d%d , &x, &y); }   int read(int &x, int &y, int &z) { return scanf( %d%d%d , &x, &y, &z); }   int read(long long &x) { return scanf( %lld , &x); }   int read(long long &x, long long &y) { return scanf( %lld%lld , &x, &y); }   int read(double &x) { return scanf( %lf , &x); }   char buff[2000010];   int read(string &s) {     int r = scanf( %s , buff);     s = buff;     return r;   }   int main() {     vector<int> PHI(1000002);     for (int i = 1; i < PHI.size(); ++i) {       PHI[i] = i;     }     for (int i = 2; i < PHI.size(); ++i) {       if (PHI[i] == i) {         for (int j = i; j < PHI.size(); j += i) {           PHI[j] = PHI[j] / i * (i - 1);         }       }     }     int N, K;     read(N, K);     if (K == 1) {       cout << 3 << endl;       return 0;     }     sort(PHI.begin() + 3, PHI.begin() + N + 1);     cout << accumulate(PHI.begin() + 3, PHI.begin() + 3 + K, 2LL) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     string s;     long long p = 0, q = 0;     cin >> s;     for (int i = s.size() - 1; i > -1; i--) {       if (s[i] ==  a ) {         p += q;         p = p % 1000000007;         q = (2 * q) % 1000000007;       } else {         q = (q + 1) % 1000000007;       }     }     cout << p;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char w[1555][1555];   int nm[1555][1555];   int n, m;   struct cell {     int x, y;   };   void mark(int x, int y, int c) {     queue<cell> q;     cell T;     T.x = x;     T.y = y;     q.push(T);     while (!q.empty()) {       T = q.front();       q.pop();       if (T.x < 0 || T.x >= n || T.y < 0 || T.y >= m || w[T.x][T.y] ==  #  ||           nm[T.x][T.y] != 0)         continue;       nm[T.x][T.y] = c;       cell W;       W.x = T.x;       W.y = T.y - 1;       q.push(W);       W.x = T.x;       W.y = T.y + 1;       q.push(W);       W.x = T.x + 1;       W.y = T.y;       q.push(W);       W.x = T.x - 1;       W.y = T.y;       q.push(W);     }   }   int kn;   int Sn;   const int M = 1555 * 20;   int fir[1555 * 1555], tov[M], nxt[M], dx[M], dy[M];   int ke;   void add(int x, int y, int Dx, int Dy) {     nxt[++ke] = fir[x];     tov[ke] = y;     fir[x] = ke;     dx[ke] = Dx;     dy[ke] = Dy;     if (ke & 1) add(y, x, -Dx, -Dy);   }   bool u[1555 * 1555];   int vx[1555 * 1555], vy[1555 * 1555];   bool cool = false;   void dfs(int c, int x, int y) {     if (u[c]) {       if (vx[c] != x || vy[c] != y) {         cool = true;       }       return;     }     u[c] = true;     vx[c] = x;     vy[c] = y;     for (int t = fir[c]; t; t = nxt[t]) {       dfs(tov[t], x + dx[t], y + dy[t]);     }   }   int main() {     scanf( %d%d , &n, &m);     cin.ignore();     for (int i = 0; i < n; ++i) {       gets(w[i]);     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         if (w[i][j] !=  #  && nm[i][j] == 0) {           mark(i, j, ++kn);         }         if (w[i][j] ==  S ) {           Sn = nm[i][j];         }       }     for (int i = 0; i < n; ++i) {       if (w[i][0] !=  #  && w[i][m - 1] !=  # ) {         add(nm[i][0], nm[i][m - 1], -1, 0);       }     }     for (int i = 0; i < m; ++i) {       if (w[0][i] !=  #  && w[n - 1][i] !=  # ) {         add(nm[0][i], nm[n - 1][i], 0, -1);       }     }     dfs(Sn, 0, 0);     if (cool)       puts( Yes );     else       puts( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int sz = 1e5 + 50;   map<int, int> prime, mark;   void init() {     prime[2] = 1;     int limit = sqrt(sz) + 1;     for (int i = 3; i <= sz; i += 2) {       if (!mark[i]) {         prime[i] = 1;         if (i <= limit) {           for (int j = i * i; j <= sz; j += i * 2) mark[j] = 1;         }       }     }   }   int main() {     init();     int n, a;     scanf( %d , &n);     int o = 0, t = 0;     while (n--) {       scanf( %d , &a);       a == 1 ? o++ : t++;     }     int sum = 0;     vector<int> v;     while (t || o) {       if (o > 0 && prime[sum + 1]) {         o--;         sum += 1;         v.push_back(1);       } else if (t > 0 && prime[sum + 2]) {         t--;         sum += 2;         v.push_back(2);       } else {         if (t)           sum += 2, t--, v.push_back(2);         else           sum++, o--, v.push_back(1);       }     }     for (auto i : v) printf( %d  , i);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 7;   const int M = 59;   const int mid = M / 2;   const int mod = 1e9 + 9;   const int inf = 1e6 + 3;   const long long linf = 1ll * inf * inf;   const double pi = acos(-1);   const double eps = 1e-7;   const double ep = 1e-5;   const int maxn = 1e5 + 7;   const double PI = acos(-1);   int C, W, H;   int dp[2][107];   struct matrix {     long long a[N][N];     int n, m;     matrix(int _n, int _m) {       n = _n;       m = _m;       memset(a, 0, sizeof(a));     }     matrix(int _n, int _m, bool itype) {       n = _n;       m = _m;       if (itype) {         for (int i = (1); i < (n + 1); i++) a[i][i] = 1;       }     }     matrix operator*(matrix u) {       matrix c(n, u.m);       for (int i = 1; i <= c.n; i++) {         for (int j = 1; j <= c.m; j++) {           long long tmp = 0;           for (int t = 1; t <= m; t++)             tmp = (tmp + (long long)a[i][t] * u.a[t][j]) % inf;           c.a[i][j] = tmp;         }       }       return c;     }     void print() {       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) printf( %lld  , a[i][j]);         printf(  n );       }     }   };   void solve() {     cin >> C >> W >> H;     matrix b(W + 1, W + 1);     for (int i = (2); i < (W + 2); i++) {       b.a[i - 1][i] = H;     }     for (int i = (1); i < (W + 2); i++) b.a[i][1] = 1;     matrix I(W + 1, W + 1, true);     while (C > 0) {       if (C & 1) {         I = I * b;       }       b = b * b;       C >>= 1;     }     matrix res(1, W + 1);     res.a[1][1] = 1;     res = res * I;     int ans = 0;     for (int i = (1); i < (res.m + 1); i++) ans = (ans + res.a[1][i]) % inf;     cout << ans;   }   int main() {     int T = 1;     for (int i = (1); i < (T + 1); i++) {       solve();     }   }