malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (a != 0 && b != 0) {       if (a > b)         a %= b;       else         b = b % a;     }     return a + b;   }   int main() {     int k, l, m, n, d;     cin >> k >> l >> m >> n >> d;     int ans = 0;     for (int i = (1); i < (d + 1); i++)       if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) ans++;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   const int INF = INT_MAX;   const double EXP = 0.0001;   void files() { freopen( output.txt ,  w , stdout); }   long long pow3(long long x) { return x * x * x; }   pair<int, long long> answer;   void solution(long long m, int step, long long cur) {     if (m == 0) {       answer = max(answer, make_pair(step, cur));       return;     }     long long x = 1;     while (pow3(x) <= m) x++;     x--;     solution(m - pow3(x), step + 1, cur + pow3(x));     if (x > 0) solution(pow3(x) - 1 - pow3(x - 1), step + 1, cur + pow3(x - 1));   }   int main() {     ios_base::sync_with_stdio(false);     long long m;     cin >> m;     solution(m, 0, 0);     cout << answer.first <<     << answer.second;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void ret(string s) {     cout << s;     exit(0);   }   int main() {     int n, m;     cin >> n >> m;     bool ok;     string s[100];     int xn = 200, xm = 0, yn = 200, ym = 0;     for (int i = 0; i < n; i++) {       cin >> s[i];       for (int j = 0; j < s[i].length(); j++)         if (s[i][j] ==  * ) {           xn = min(xn, j);           xm = max(xm, j);           yn = min(yn, i);           ym = max(yn, i);         }     }     for (int i = yn; i <= ym; i++) {       for (int j = xn; j <= xm; j++) cout << s[i][j];       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 2, M = 1e9 + 7, OO = 0x3f3f3f3f;   int n, m, u, v;   int ic[N];   int fc[N];   int adj[N][N];   pair<int, int> p[N];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> ic[i];     for (int i = 0; i < m; i++) {       cin >> u >> v;       u--;       v--;       fc[u] += ic[v];       fc[v] += ic[u];       adj[u][v] = 1;       adj[v][u] = 1;     }     for (int i = 0; i < n; ++i) p[i] = {ic[i], i};     sort(p, p + n);     int ans = 0;     int t;     int r = n;     while (r--) {       t = p[r].second;       ans += fc[t];       for (int i = 0; i < n; ++i) {         if (adj[t][i]) {           fc[i] -= ic[t];           adj[i][t] = 0;           adj[t][i] = 0;         }       }       fc[t] = OO;       sort(p, p + n);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   template <typename T>   void MACRO_VAR_Scan(T& t) {     std::cin >> t;   }   template <typename First, typename... Rest>   void MACRO_VAR_Scan(First& first, Rest&... rest) {     std::cin >> first;     MACRO_VAR_Scan(rest...);   }   template <typename T>   void MACRO_VEC_ROW_Init(int n, T& t) {     t.resize(n);   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {     first.resize(n);     MACRO_VEC_ROW_Init(n, rest...);   }   template <typename T>   void MACRO_VEC_ROW_Scan(int p, T& t) {     std::cin >> t[p];   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {     std::cin >> first[p];     MACRO_VEC_ROW_Scan(p, rest...);   }   template <class T>   inline T CHMAX(T& a, const T b) {     return a = (a < b) ? b : a;   }   template <class T>   inline T CHMIN(T& a, const T b) {     return a = (a > b) ? b : a;   }   template <class T>   using V = std::vector<T>;   template <class T>   using VV = V<V<T>>;   template <typename S, typename T>   std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using PAIR = std::pair<ll, ll>;   using PAIRLL = std::pair<ll, ll>;   constexpr ll INFINT = 1 << 30;   constexpr ll INFINT_LIM = (1LL << 31) - 1;   constexpr ll INFLL = 1LL << 60;   constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);   constexpr double EPS = 1e-6;   constexpr ll MOD = 1000000007;   constexpr double PI = 3.141592653589793238462643383279;   template <class T, size_t N>   void FILL(T (&a)[N], const T& val) {     for (auto& x : a) x = val;   }   template <class ARY, size_t N, size_t M, class T>   void FILL(ARY (&a)[N][M], const T& val) {     for (auto& b : a) FILL(b, val);   }   template <class T>   void FILL(std::vector<T>& a, const T& val) {     for (auto& x : a) x = val;   }   template <class ARY, class T>   void FILL(std::vector<std::vector<ARY>>& a, const T& val) {     for (auto& b : a) FILL(b, val);   }   signed main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     ;     ll n, m;     MACRO_VAR_Scan(n, m);     ;     std::vector<ll> a, b;     MACRO_VEC_ROW_Init(m, a, b);     for (ll w_ = 0; w_ < m; ++w_) {       MACRO_VEC_ROW_Scan(w_, a, b);     };     std::vector<std::vector<ll>> g(n);     for (ll i = 0; i < ll(m); ++i) {       --a[i];       --b[i];       g[a[i]].emplace_back(b[i]);     }     std::vector<ll> min(n, INFLL);     for (ll i = 0; i < ll(n); ++i) {       for (ll x : g[i]) {         ll cost = x - i;         if (cost <= 0) cost += n;         CHMIN(min[i], cost);       }     }     for (ll i = 0; i < ll(n); ++i) {       ll ans = 0;       for (ll j = 0; j < ll(n); ++j) {         ll J = (i + j) % n;         if (g[J].empty()) continue;         ll len = g[J].size();         ll sum = (len - 1) * n + j + min[J];         CHMAX(ans, sum);       }       std::cout << (ans);       std::cout << (i + 1 == n ?   n  :    );       ;     }     return 0;   }
#pragma GCC optimize( Ofast,unroll-loops )   #pragma GCC target( avx,avx2,sse,sse2,ssse3,sse4,mmx,popcnt )   #include <bits/stdc++.h>   #define ar array      using namespace std;   using ll = long long;      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      const int mxN = 2e5, mxM = 60;   int n, m, p;   vector<int> a[mxN];   using S = bitset<mxN>;   S a_inv[mxM];      ll ans = 0;      void solve(int start) {     int k = (int)a[start].size();        int best = 0;     int best_cnt = __builtin_popcountll(ans);        for (int s = 1; s < 1<<k; ++s) {       if (__builtin_popcount(s) <= best_cnt) continue;       S agree; agree.set();       for (int kk = 0; kk < k; ++kk) {         if (!(s & (1<<kk))) continue;         agree &= a_inv[a[start][kk]];       }       if ((int)agree.count()*2 >= n) best = s, best_cnt = __builtin_popcount(s);     }        if (best_cnt > __builtin_popcountll(ans)) {       ans = 0;       for (int kk = 0; kk < k; ++kk) {         if (!(best & (1<<kk))) continue;         ans |= (1LL<<a[start][kk]);       }     }   }      int main() {     cin.tie(0)->sync_with_stdio(0);        // since 50% need to agree, any random guy has at least 50% chance of being in the set     // need to only select a few people        cin >> n >> m >> p;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         char c; cin >> c;         if (c ==  1 ) a[i].push_back(j);       }     }        for (int i = 0; i < n; ++i)       for (int j : a[i])         a_inv[j].set(i);        uniform_int_distribution<int> random_i(0, n-1);        for (int rep = 0; rep < 10; ++rep) {       int i = random_i(rng);       solve(i);     }        for (int i = 0; i < m; ++i) {       cout << (ans&1);       ans /= 2;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double eps = 1e-8;   const int mod = 1000000007;   const double pi = acos(-1.0);   inline void gn(long long& x) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (sg = -1, x = 0) : (x = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= sg;   }   inline void gn(int& x) {     long long t;     gn(t);     x = t;   }   inline void gn(unsigned long long& x) {     long long t;     gn(t);     x = t;   }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   long long powmod(long long a, long long x, long long mod) {     long long t = 1ll;     while (x) {       if (x & 1) t = t * a % mod;       a = a * a % mod;       x >>= 1;     }     return t;   }   const int maxn = 222222;   pair<int, int> pp[maxn];   map<int, int> need;   int fix[maxn];   map<int, vector<int> > hasid;   map<int, int> has;   int val[maxn];   int main() {     int n, m;     int totmatch = 0, totfix = 0;     memset((fix), 0, sizeof(fix));     gn(n);     gn(m);     for (int i = (1); i <= (n); i++) {       int x;       gn(x);       need[x]++;       val[i] = x;     }     for (int i = (1); i <= (m); i++) {       int vv;       gn(vv);       pp[i].first = vv;       pp[i].second = i;     }     sort(pp + 1, pp + 1 + m);     for (int i = (1); i <= (m); i++) {       int p = pp[i].first;       p = p * 2;       int tmp = -1;       while (true) {         if (p == 1) break;         p = (p + 1) / 2;         tmp++;         if (need.count(p) && has[p] < need[p]) break;       }       if (need.count(p) && has[p] < need[p]) {         totfix += tmp;         fix[pp[i].second] = tmp;         hasid[p].push_back(pp[i].second);         totmatch++;         has[p]++;       }     }     printf( %d %d n , totmatch, totfix);     for (int i = (1); i <= (m); i++) printf( %d  , fix[i]);     puts(  );     for (int i = (1); i <= (n); i++) {       if (!need.count(val[i]))         printf( 0  );       else {         if (hasid[val[i]].size() > 0) {           printf( %d  , hasid[val[i]].back());           hasid[val[i]].pop_back();         } else {           printf( %d  , 0);         }       }     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int h1, a1, c, h2, a2, h;     cin >> h1 >> a1 >> c >> h2 >> a2;     vector<string> v;     h = h1;     while (h2 > 0) {       if ((a1 >= h2) || h1 > a2) {         v.push_back( STRIKE );         h2 -= a1;       } else {         v.push_back( HEAL );         h1 += c;       }       h1 -= a2;     }     cout << v.size() << endl;     for (string s : v) cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( -Ofast,unroll-loops )   #pragma GCC target( avx2 )   std::mt19937 rnd(237);   using namespace std;   const int N = 2e5, mod = 1e9 + 7;   int n, m, type[N], cmp[N], cmp_p = 0;   vector<array<int, 2>> g1[N], g2[N];   long long dfs(int v) {     cmp[cmp_p++] = v;     long long ans = (type[v] ? 0 : 1);     for (auto &[u, c] : g1[v]) {       if (~type[u]) {         if (type[v] && type[u] != c) return -2e9;         if (!type[v] && type[u] == c) return -2e9;       } else {         type[u] = (type[v] ? c : 1 - c);         ans += dfs(u);       }     }     for (auto &[u, c] : g2[v]) {       if (~type[u]) {         if (type[u] == 1 && type[v] != c) return -2e9;         if (type[u] == 0 && type[v] == c) return -2e9;       } else {         type[u] = (type[v] == c ? 1 : 0);         ans += dfs(u);       }     }     return ans;   }   void solve() {     cin >> n >> m;     fill(type, type + n, -1);     cmp_p = 0;     for (int i = 0; i < n; ++i) {       g1[i].clear();       g2[i].clear();     }     for (int i = 0; i < m; ++i) {       int u, v;       string s;       cin >> u >> v >> s;       --u, --v;       if (s ==  crewmate ) {         g1[u].push_back({v, 1});         g2[v].push_back({u, 1});       } else {         g1[u].push_back({v, 0});         g2[v].push_back({u, 0});       }     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (type[i] == -1) {         long long mx = -2e9;         type[i] = 1;         cmp_p = 0;         mx = max(mx, dfs(i));         for (int j = 0; j < cmp_p; ++j) {           type[cmp[j]] = -1;         }         type[i] = 0;         cmp_p = 0;         mx = max(mx, dfs(i));         ans += mx;       }     }     cout << (ans < 0 ? -1 : ans);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt = 1;     cin >> tt;     while (tt--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   int check(int num1, int num2);   using namespace std;   int main() {     int k, l, m, n, d;     cin >> k;     cin >> l;     cin >> m;     cin >> n;     cin >> d;     int total = 0;     for (int i = 1; i < d + 1; i++) {       if (check(i, k) || check(i, l) || check(i, m) || check(i, n)) {         total++;       }     }     cout << total << endl;     return 0;   }   int check(int num1, int num2) {     if (num1 % num2 == 0) {       return 1;     } else {       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   char c[10005];   int main() {     int i, a, b, l1, l2;     a = b = l1 = l2 = 0;     scanf( %d , &n);     scanf( %s , &c[1]);     for (i = 1; i <= n; i++) {       if (c[i] ==  L ) a++;       if (c[i] ==  R ) b++;     }     if (a == 0 && b == 0)       l1 = l2 = 1;     else if (a == 0) {       for (i = 1; i <= n; i++) {         if (c[i] ==  R ) {           if (l1 == 0) l1 = i;           l2 = i + 1;         }       }     } else if (b == 0) {       for (i = 1; i <= n; i++) {         if (c[i] ==  L ) {           if (l2 == 0) l2 = i - 1;           l1 = i;         }       }     } else {       for (i = 1; i <= n; i++) {         if (c[i] ==  R ) {           if (l1 == 0) l1 = i;           l2 = i;         }       }     }     printf( %d %d , l1, l2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5050;   int n, b, c[MAXN], d[MAXN], fa[MAXN], sum[MAXN], f[MAXN][MAXN], g[MAXN][MAXN];   int buff[MAXN], bufg[MAXN];   int main() {     memset(f, 63, sizeof(f));     memset(g, 63, sizeof(g));     scanf( %d%d , &n, &b);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &c[i], &d[i]);       if (i > 1) scanf( %d , &fa[i]);       sum[i] = 1;       f[i][1] = c[i] - d[i];       g[i][0] = 0;       g[i][1] = c[i];       if (f[i][1] > b && g[i][1] > b) sum[i] = 0;     }     for (int i = n; i >= 2; i--) {       memcpy(buff, f[fa[i]], sizeof(buff));       memcpy(bufg, g[fa[i]], sizeof(bufg));       for (int j = 0; j <= sum[i]; j++)         for (int k = 0; k <= sum[fa[i]]; k++) {           f[fa[i]][j + k] = min(f[fa[i]][j + k], min(f[i][j], g[i][j]) + buff[k]);           g[fa[i]][j + k] = min(g[fa[i]][j + k], g[i][j] + bufg[k]);         }       sum[fa[i]] += sum[i];     }     for (int i = n; i; --i) {       if (f[1][i] <= b || g[1][i] <= b) {         printf( %d , i);         return 0;       }     }     printf( 0 );     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, q;     std::cin >> n >> q;     std::vector<std::pair<int, int>> a(q);     std::vector<int> cnt(n), k1(q), pr(n, -1);     std::vector<std::vector<int>> k2(q, std::vector<int>(q));     for (auto &i : a) {       std::cin >> i.first >> i.second;       --i.first;       --i.second;     }     for (auto i : a) {       for (int j = i.first; j <= i.second; ++j) {         ++cnt[j];       }     }     for (int i = 0; i < q; ++i) {       for (int j = a[i].first; j <= a[i].second; ++j) {         if (cnt[j] == 1) {           ++k1[i];         }       }     }     for (int i = 0; i < q; ++i) {       for (int j = a[i].first; j <= a[i].second; ++j) {         if (cnt[j] == 2) {           if (pr[j] == -1) {             pr[j] = i;           } else {             ++k2[pr[j]][i];           }         }       }     }     int max = 0, sum = 0;     for (int i = 0; i < n; ++i) {       if (cnt[i] > 0) ++sum;     }     for (int i = 0; i < q; ++i) {       for (int j = i + 1; j < q; ++j) {         max = std::max(max, sum - k1[i] - k1[j] - k2[i][j]);       }     }     std::cout << max;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6;     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4 >> x5 >> y5 >> x6 >> y6;     long long a1 = (x2 - x1) * (y2 - y1);     x3 = max(x3, x1);     x4 = min(x4, x2);     x5 = max(x5, x1);     x6 = min(x6, x2);     y3 = max(y3, y1);     y5 = max(y5, y1);     y6 = min(y2, y6);     y4 = min(y4, y2);     long long a2 = (x4 - x3) * (y4 - y3);     long long a3 = (x6 - x5) * (y6 - y5);     if (a2 < 0) a2 = 0;     if (a3 < 0) a3 = 0;     if (a1 == a2 || a1 == a3) {       cout <<  NO ;       return 0;     }     a1 -= a2 + a3;     if (a1 > 0) {       cout <<  YES  << endl;       return 0;     }     if (x4 > x5 && x3 <= x5) {       long long y7 = min(y4, y6);       long long y8 = max(y3, y5);       x4 = min(x4, x6);       long long val = (x4 - x5) * (y7 - y8);       if (val > 0) a1 += val;     } else if (x6 > x3 && x5 <= x3) {       long long y7 = min(y4, y6);       long long y8 = max(y3, y5);       x6 = min(x6, x4);       long long val = (x6 - x3) * (y7 - y8);       if (val > 0) a1 += val;     }     if (a1 == 0) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 500 * 1000 + 10;   int n, h[Maxn], ans;   vector<int> adj[Maxn], vec;   bool mark[Maxn];   void dfs(int v) {     mark[v] = true;     if ((int)adj[v].size() == 1) vec.push_back(h[v]);     for (int i = 0; i < (int)adj[v].size(); i++)       if (!mark[adj[v][i]]) {         h[adj[v][i]] = h[v] + 1;         dfs(adj[v][i]);       }     return;   }   int main() {     scanf( %d , &n);     int u, v;     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &u, &v);       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     mark[0] = true;     for (int i = 0; i < (int)adj[0].size(); i++) {       dfs(adj[0][i]);       sort(vec.begin(), vec.end());       reverse(vec.begin(), vec.end());       int cnt = 1;       for (int j = 0; j < (int)vec.size(); j++) {         if (vec[j] + cnt > ans) ans = vec[j] + cnt;         cnt++;       }       vec.clear();     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   void solve() {     string p, h;     cin >> p >> h;     swap(p, h);     sort(h.begin(), h.end());     for (long long i = 0; i + h.size() - 1 < p.size(); ++i) {       string temp = p.substr(i, h.size());       sort(temp.begin(), temp.end());       if (temp == h) {         cout <<  YES n ;         return;       }     }     cout <<  NO n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   enum { UP, DOWN, LEFT, RIGHT };   const int MaxN = 1005;   const int MaxM = MaxN * MaxN;   const int oo = 0x3F3F3F3F;   char mp[MaxN][MaxN];   int dir[MaxM][4];   int d[MaxM][4];   int id[MaxN][MaxN], K;   int R, C, s, t;   struct Node {     int u, dir, d;     Node() {}     Node(int u, int dir, int d) : u(u), dir(dir), d(d) {}   };   void BFS() {     deque<Node> q;     Node u, v;     memset(d, 0x3F, sizeof(d));     q.push_back(Node(s, RIGHT, 0));     d[s][RIGHT] = 0;     while (!q.empty()) {       u = q.front();       q.pop_front();       if (d[u.u][u.dir] != u.d) continue;       for (int i = 0; i < 4; i++) {         if (dir[u.u][i]) {           v.u = dir[u.u][i];           v.dir = i;           v.d = u.d + (i != u.dir);           if (d[v.u][v.dir] > v.d) {             d[v.u][v.dir] = v.d;             if (i != u.dir)               q.push_back(v);             else               q.push_front(v);           }         }       }     }   }   int main() {     while (scanf( %d%d , &R, &C) == 2) {       for (int i = 0; i < R; i++) {         scanf( %s , mp[i]);         for (int j = 0; j < C; j++) {           if (mp[i][j] ==  # ) {             id[i][j] = ++K;           } else {             id[i][j] = 0;           }         }       }       s = ++K;       t = ++K;       fill(dir[s], dir[s] + 4, 0);       fill(dir[t], dir[t] + 4, 0);       for (int i = 0; i < R; i++) {         int last = i == 0 ? s : 0;         for (int j = 0; j < C; j++) {           if (mp[i][j] ==  # ) {             if (i == 0 && dir[s][RIGHT] == 0) dir[s][RIGHT] = id[i][j];             dir[id[i][j]][LEFT] = last;             last = id[i][j];           }         }         last = i == R - 1 ? t : 0;         for (int j = C - 1; j >= 0; j--) {           if (mp[i][j] ==  # ) {             if (i == R - 1 && dir[t][LEFT] == 0) dir[t][LEFT] = id[i][j];             dir[id[i][j]][RIGHT] = last;             last = id[i][j];           }         }       }       for (int j = 0; j < C; j++) {         int last = 0;         for (int i = 0; i < R; i++) {           if (mp[i][j] ==  # ) {             dir[id[i][j]][UP] = last;             last = id[i][j];           }         }         last = 0;         for (int i = R - 1; i >= 0; i--) {           if (mp[i][j] ==  # ) {             dir[id[i][j]][DOWN] = last;             last = id[i][j];           }         }       }       BFS();       if (d[t][RIGHT] == oo)         puts( -1 );       else         printf( %d n , d[t][RIGHT]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void PLAY() {     cout << fixed << setprecision(10);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     deque<long long> x;     map<long long, long long> h;     for (int i = 0; i < n; i++) {       long long f;       cin >> f;       if (h[f] == 0) {         h[f] = 1;         x.push_back(f);         long long l = x.size();         if (l == k + 1) {           h[x.front()] = 0;           x.pop_front();         }       }     }     cout << x.size() << endl;     reverse(x.begin(), x.end());     long long l = x.size();     for (auto it : x) {       cout << it <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T;     cin >> T;     while (T--) {       int N;       cin >> N;       for (int i = 0; i < N; i++) cout <<  1  ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long n, m, ans = 0;   long long d[N], h[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (long long i = 1; i <= m; i++) cin >> d[i] >> h[i];     for (long long i = 2; i <= m; i++) {       long long maxdiff = abs(d[i] - d[i - 1]);       if (abs(h[i] - h[i - 1]) > maxdiff) {         cout <<  IMPOSSIBLE ;         return 0;       }     }     ans = max(h[1] + abs(d[1] - 1), h[m] + abs(n - d[m]));     for (long long i = 1; i <= m - 1; i++) {       long long extradays = d[i + 1] - d[i] - abs(h[i + 1] - h[i]);       long long maxh = max(h[i], h[i + 1]);       ans = max(ans, maxh + extradays / 2);     }     cout << ans;     return 0;   }