malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, i, j;       cin >> n;       vector<int> icons(n);       for (i = 0; i < n; i++) {         cin >> icons[i];       }       vector<int> num;       sort(icons.begin(), icons.end());       int cnt = 1;       for (i = 1; i < icons.size(); i++) {         if (icons[i] == icons[i - 1]) {           cnt++;         } else {           num.push_back(cnt);           cnt = 1;         }       }       num.push_back(cnt);       int x = num[0] + 1;       int minNum = 1e9 + 7;       for (i = 1; i <= x; i++) {         int sum = 0;         for (j = 0; j < num.size(); j++) {           int q = ceil((float)num[j] / i);           if ((i - 1) * q > num[j]) {             sum = 1e9 + 7;             break;           }           sum += q;         }         if (sum < minNum) minNum = sum;       }       cout << minNum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void print() {     int n;     cin >> n;     int arr[n], mx = 0, sum = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];       mx = max(mx, arr[i]);     }     if (mx * 2 > sum || (sum & 1))       cout <<  T  << endl;     else       cout <<  HL  << endl;   }   int main() {     int t;     cin >> t;     while (t) {       --t;       print();     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   std::ostream &operator<<(std::ostream &out, vector<T> &v) {     for (typename vector<T>::size_type i = 0; i < v.size(); ++i)       out << v[i] <<    ;     out <<   n ;     return out;   }   template <typename T>   std::ostream &operator<<(std::ostream &out, set<T> &s) {     for (auto e : s) out << e <<    ;     out <<   n ;     return out;   }   template <typename T, typename N>   std::ostream &operator<<(std::ostream &out, pair<T, N> &p) {     out <<  (  << p.first <<  ,   << p.second <<  )  ;     return out;   }   template <typename T, typename N>   std::ostream &operator<<(std::ostream &out, vector<pair<T, N> > &v) {     for (size_t i = 0; i < v.size(); ++i) cout << v[i];     out <<   n ;     return out;   }   template <typename T>   std::ostream &operator<<(std::ostream &out, vector<vector<T> > &v) {     for (size_t i = 0; i < v.size(); ++i) {       for (size_t j = 0; j < v[i].size(); ++j) {         out << v[i][j] <<    ;       }       out <<   n ;     }     return out;   }   template <typename T>   std::ostream &operator<<(std::ostream &out, vector<set<T> > &v) {     for (size_t i = 0; i < v.size(); ++i) {       out << v[i];     }     out <<   n ;     return out;   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     int total = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       total += a[i];     }     int diff = 0;     for (int i = n - 1; i >= 0; --i) {       diff = abs(diff - a[i]);     }     cout << (total - diff) / 2 <<     << (total + diff) / 2 <<   n ;     return;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   int dx[] = {+0, +0, -1, +1, +1, +1, -1, -1};   int dy[] = {+1, -1, +0, +0, +1, -1, +1, -1};   using namespace std;   int n, mod = 1000000000 + 7;   long long res;   bool f1[20], f2[20];   int r[8] = {1, 18, 1800, 670320, 734832000, 890786230, 695720788, 150347555};   void attempt(int i) {     if (i == n + 1) {       res++;       return;     }     for (int j = int(1); j <= int(n); j++)       if (f1[j]) {         int k = (n - i + 1 + j - 2) % n + 1;         if (f2[k]) {           f1[j] = f2[k] = false;           attempt(i + 1);           f1[j] = f2[k] = true;         }       }   }   int main() {     cin >> n;     if (n % 2 == 0)       cout << 0 << endl;     else       cout << r[n / 2] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[100001];   int dist[100001];   int n, m;   void bfs(int x) {     queue<int> q;     int cur, i;     memset(dist, -1, sizeof(dist));     dist[x] = 0;     q.push(x);     while (!q.empty()) {       cur = q.front();       q.pop();       for (i = 0; i < (int)g[cur].size(); i++) {         if (dist[g[cur][i]] == -1) {           dist[g[cur][i]] = dist[cur] + 1;           q.push(g[cur][i]);         }       }     }   }   int main() {     int i, a, b, x, res;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     bfs(1);     res = 0;     x = 1;     for (i = 1; i <= n; i++) {       if (dist[i] > res) {         res = dist[i];         x = i;       }     }     bfs(x);     res = 0;     for (i = 1; i <= n; i++) {       res = max(res, dist[i]);     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     char board[9][9];     char trash;     for (long r = 0; r < 3; ++r) {       for (long x = 0; x < 3; ++x) {         for (long c = 0; c < 3; ++c) {           for (long y = 0; y < 3; ++y) cin >> board[3 * r + x][3 * c + y];           if (c == 5) cin >> trash;         }       }     }     long x, y;     cin >> x >> y;     --x, --y;     x %= 3;     y %= 3;     bool empty = false;     for (long i = 0; i < 3; ++i)       for (long j = 0; j < 3; ++j)         if (board[3 * x + i][3 * y + j] ==  . ) empty = true;     if (empty) {       for (long i = 0; i < 3; ++i)         for (long j = 0; j < 3; ++j)           if (board[3 * x + i][3 * y + j] ==  . )             board[3 * x + i][3 * y + j] =  ! ;     } else {       for (long i = 0; i < 9; ++i)         for (long j = 0; j < 9; ++j)           if (board[i][j] ==  . ) board[i][j] =  ! ;     }     for (long r = 0; r < 3; ++r) {       for (long x = 0; x < 3; ++x) {         for (long c = 0; c < 3; ++c) {           for (long y = 0; y < 3; ++y) cout << board[3 * r + x][3 * c + y];           if (c < 2) cout <<    ;         }         cout <<   n ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, p;   int main() {     map<int, int> mp;     cin >> n;     for (int i = 1; i <= 2 * n + 1; i++) {       if (p % n == 0) {         mp[n]++;       }       mp[p % n]++;       p += i - 1;     }     for (int i = 1; i <= n; i++) {       if (mp[i] == 0) {         cout <<  NO ;         return 0;       }     }     cout <<  YES           <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e2 + 5;   int N, T;   int pref[MAXN];   int ask(int l, int r) {     printf( ? %d %d n , l, r);     fflush(stdout);     int res;     scanf( %d , &res);     if (res == -1) exit(0);     return res;   }   int main() {     scanf( %d%d , &N, &T);     if (N == 1) {       printf( ! %d n , T);       fflush(stdout);       return 0;     }     int k = N % 2, curr = T;     for (int i = 1; i <= N - k; i++) {       int lft = 0, rig = 0;       bool ok = false;       while (!ok || lft || rig) {         int nxt = ask(i, i + k);         if ((curr + nxt) % 2 == (i + k) % 2) {           lft ^= 1;           if (lft && !rig) {             pref[i + k] = (i + k - nxt + T) / 2;             ok = true;           }         } else           rig ^= 1;         curr = nxt;       }     }     if (k) {       int it = 0;       while (1) {         int nxt = ask(2, N);         if (!((curr + nxt) % 2)) {           pref[1] = it ? (T - nxt + 1) / 2 : (nxt + T - N + 1) / 2;           break;         }         curr = nxt;         it ^= 1;       }     }     printf( !  );     for (int i = 1; i <= N; i++) printf( %d , pref[i] - pref[i - 1]);     puts(  );     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1 << 13;   const int N = 13;   long long dp[M][N][2][2];   bool used[M][N][2][2];   vector<int> digits_hour, digits_minuts;   long long solve(int mask, int pos, bool flag1, bool flag2) {     int h = digits_hour.size();     int min = digits_minuts.size();     if (pos == h + min) {       return 1LL;     }     long long &ans = dp[mask][pos][flag1][flag2];     if (used[mask][pos][flag1][flag2]) {       return ans;     }     used[mask][pos][flag1][flag2] = true;     if (pos >= h) {       for (int t = 0; t < 7; t++) {         int el = 1 << t;         if ((mask & el) == 0) {           if (flag2 || digits_minuts[pos - h] >= t) {             ans += solve(mask | el, pos + 1, flag1,                          flag2 || (digits_minuts[pos - h] > t));           }         }       }     } else {       for (int t = 0; t < 7; t++) {         int el = 1 << t;         if ((mask & el) == 0) {           if (flag1 || digits_hour[pos] >= t) {             ans +=                 solve(mask | el, pos + 1, flag1 || (digits_hour[pos] > t), flag2);           }         }       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     scanf( %d %d , &n, &m);     n--, m--;     if (n == 0) {       digits_hour.push_back(0);     }     if (m == 0) {       digits_minuts.push_back(0);     }     while (n) {       digits_hour.push_back(n % 7);       n /= 7;     }     reverse(digits_hour.begin(), digits_hour.end());     while (m) {       digits_minuts.push_back(m % 7);       m /= 7;     }     reverse(digits_minuts.begin(), digits_minuts.end());     printf( %lld n , solve(0, 0, false, false));     return 0;   }
#include <bits/stdc++.h>   using std::map;   long long n;   long long p2[100005 * 2] = {1};   long long fa[100005 * 2], size[100005 * 2], p[100005 * 2];   long long vis[100005 * 2];   map<long long, long long> mx, my;   long long cnt;   long long ans = 1;   long long getfa(long long x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }   int main() {     scanf( %I64d , &n);     for (long long i = 1; i <= n * 2; i++) {       fa[i] = i;       size[i] = 1;       p2[i] = (p2[i - 1] * 2) % ((int)1e9 + 7);     }     long long x, y, px, py, fx, fy;     for (long long i = 1; i <= n; i++) {       scanf( %I64d %I64d , &x, &y);       if (mx.find(x) == mx.end()) {         mx[x] = ++cnt;       }       if (my.find(y) == my.end()) {         my[y] = ++cnt;       }       px = mx[x];       py = my[y];       fx = getfa(px);       fy = getfa(py);       if (fx == fy) {         p[fx] = 1;       } else {         fa[fx] = fy;         size[fy] += size[fx];         p[fy] |= p[fx];       }       getfa(px);     }     for (long long i = 1; i <= cnt; i++) {       long long fi = getfa(i);       if (vis[fi]) continue;       vis[fi] = 1;       if (p[fi]) {         ans *= p2[size[fi]];       } else {         ans *= (p2[size[fi]] - 1);       }       ans %= ((int)1e9 + 7);     }     printf( %I64d n , ans);   }
//愿你和你重要的人能够重逢！   #include<bits/stdc++.h>   using namespace std;   template<typename T>inline void read(T &x)   {    x=0;char c=getchar(),f=0;    for(;c<48||c>57;c=getchar()) if(!(c^45)) f=1;    for(;c>=48&&c<=57;c=getchar()) x=(x<<1)+(x<<3)+(c^48);    f?x=-x:0;   }   long long l,r,st,t,x,y;set<long long>s;   int main()   {    read(st),read(l),read(r),read(t),read(x),read(y);    if(x>y)    {     if((x-y<2e18/t&&st-l>=t*(x-y))&&st+y<=r) puts( Yes );     else if(x-y<2e18/t&&st-l>=t*x-(t-1)*y) puts( Yes );     else puts( No );     return 0;    }    long long qwq=st,tp;qwq=l+(qwq-l)%x,t-=(st-qwq)/x;    if(t<=0) return puts( Yes ),0;else if(qwq+y>r) return puts( No ),0;    while(t>0)    {     qwq+=y;if(qwq>r) return puts( No ),0;else tp=qwq,qwq=l+(qwq-l)%x,t-=(tp-qwq)/x;     if(t<=0) return puts( Yes ),0;else if(s.count(qwq)) return puts( Yes ),0;else s.insert(qwq);    }    return puts( Yes ),0;   }
#include <bits/stdc++.h>   using namespace std;   int n, w[200200], h[200200], W, a[200200], maxH, maxH2, id;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &w[i], &h[i]);       if (h[i] > maxH) {         maxH = h[i];         id = i;       }       W += w[i];     }     for (int i = 1; i <= n; ++i) {       if (i != id) maxH2 = max(maxH2, h[i]);     }     for (int i = 1; i <= n; ++i) {       if (h[i] == maxH)         printf( %d  , maxH2 * (W - w[i]));       else         printf( %d  , maxH * (W - w[i]));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     string s;     cin >> n >> k >> s;     for (int i = 0; i < s.size(); i++) {       if (!k) break;       if (i + 2 < s.size() && s[i] ==  4  && s[i + 1] ==  7  && s[i + 2] ==  7  &&           i % 2 == 0) {         if (k % 2) s[i + 1] =  4 ;         break;       }       if (i + 2 < s.size() && s[i] ==  4  && s[i + 1] ==  4  && s[i + 2] ==  7  &&           i % 2 == 0) {         if (k % 2) s[i + 1] =  7 ;         break;       }       if (i + 1 < s.size() && s[i] ==  4  && s[i + 1] ==  7  && i % 2 == 0) {         s[i + 1] =  4 ;         k--;       }       if (i + 1 < s.size() && s[i] ==  4  && s[i + 1] ==  7  && i % 2 != 0) {         s[i] =  7 ;         k--;       }     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[4], i, j, min = 1000, x, y;     for (i = 0; i < 4; i++) {       cin >> a[i];       if (min > a[i]) min = a[i];     }     cin >> x >> y;     if (x >= min) {       cout << 0;       return 0;     } else if (y < min) {       cout << y - x + 1;     } else {       cout << min - x;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     long long int one = 1;     if (!y)       return one;     else if (y == 1)       return x;     else {       long long int y1 = power(x, y >> 1);       long long int y2 = y1 * y1;       if (y & 1)         return x * y2;       else         return y2;     }   }   bool comp(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first)       return a.first < b.first;     else       return a.second > b.second;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, mx;     cin >> n >> mx;     long long int a[n];     map<long long int, long long int> occ;     for (int i = 0; i < n; i++) cin >> a[i], occ[a[i]]++;     long long int allow = 8 * mx;     allow /= n;     if (allow > 20) {       cout << 0;       return 0;     }     long long int dis = power(2, allow);     vector<pair<int, int> > give;     for (auto v : occ) give.push_back(make_pair(v.first, v.second));     long long int n1 = give.size();     sort(give.begin(), give.end(), comp);     long long int ans = INT_MAX;     long long int presum[n1];     presum[0] = give[0].second;     for (int i = 1; i < n1; i++) presum[i] = presum[i - 1] + give[i].second;     if (n1 <= dis) {       cout << 0;       return 0;     }     for (int i = 0; i <= n1 - dis; i++) {       int rem = 0;       if (i == 0)         rem = presum[i + dis - 1];       else         rem = presum[i + dis - 1] - presum[i - 1];       if (n - rem < ans) ans = n - rem;     }     cout << ans;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int MAX = 2e5 + 5;   const long long MAX2 = 11;   const long long MOD = 998244353;   const long long MOD2 = 1000000006;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 316;   int n, q, push_front[MAX], le[MAX], ri[MAX], l[MAX], r[MAX], cl[MAX], jlh[MAX],       cnt, a, b, len, id, ls;   long long hs[MAX], x[MAX], key, tmp, pj, t2;   bool z[MAX], st;   char c;   pair<long long, int> res;   inline pair<long long, int> f(int a, int b) {     if (a > b) return {0, 0};     int len = b - a + 1;     return {x[b] - x[a - 1] * hs[len], len};   }   inline pair<long long, int> comp(int a, int b) {     tmp = pj = st = 0;     if (z[a]) {       if (ri[a] - a + 1 & 1) ++pj;       a = ri[a] + 1;     }     if (z[b]) {       if (b - le[b] + 1 & 1) st = 1;       b = le[b] - 1;     }     if (cl[a] == cl[b]) {       tmp = l[a] + r[b] - jlh[cl[a]];       if (st) tmp *= key;       return {tmp, 1 + pj + st};     }     res = f(cl[a] + 1, cl[b] - 1);     tmp = (l[a] * hs[res.second] + res.first) * key + r[b];     if (st) tmp *= key;     return {tmp, cl[b] - cl[a] + 1 + pj + st};   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     key = 2000003153;     cin >> n;     hs[0] = 1;     for (int i = 1; i <= n; ++i) {       cin >> c, z[i] = (c ==  1 ), push_front[i] = push_front[i - 1] + z[i],                 hs[i] = hs[i - 1] * key;       if (z[i]) {         st ^= 1;         if (le[i - 1])           le[i] = le[i - 1];         else           le[i] = i;       } else {         if (st) {           jlh[id] = cnt;           x[id] = x[id - 1] * key + cnt;           st = cnt = 0;         }         if (cnt == 0) ++id;         ++cnt, r[i] = cnt;         cl[i] = id;       }     }     if (cnt) x[id] = x[id - 1] * key + cnt, jlh[id] = cnt;     ls = id;     cnt = 0;     for (int i = n; i >= 1; --i) {       if (z[i]) {         if (ri[i + 1])           ri[i] = ri[i + 1];         else           ri[i] = i;       } else {         if (cl[i] != ls) cnt = 0, ls = cl[i];         l[i] = ++cnt;       }     }     cin >> q;     while (q--) {       cin >> a >> b >> len;       if (push_front[a + len - 1] - push_front[a - 1] !=           push_front[b + len - 1] - push_front[b - 1]) {         cout <<  No n ;         continue;       }       if (push_front[a + len - 1] - push_front[a - 1] == 0 ||           push_front[a + len - 1] - push_front[a - 1] == len) {         cout <<  Yes n ;         continue;       }       if (comp(a, a + len - 1) == comp(b, b + len - 1))         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }
#include <iostream>   #include <cmath>   using namespace std;   int t, n, a[105];   int main(){    cin>>t;    while(t--){     cin>>n;     int suc = 0;     for(int i=0; i<n; i++)      cin>>a[i];     for(int i=0; i<n; i++){      int k = (int)sqrt((double)a[i]);      if(k*k != a[i]){       suc = 1;       break;      }     }     if(suc)      cout<< YES <<endl;     else      cout<< NO <<endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2600, MAXL = 10000 * 5 + 10, MAXALP = 26;   int n, f[MAXN][MAXN], cnt[MAXALP], p[MAXN][MAXN];   char str[MAXL];   pair<int, int> Tohka;   string Houki;   void Print(const pair<int, int> &a, int res) {     if (res <= 0) return;     if (p[a.first][a.second] == -1)       Print(make_pair(a.first - 1, a.second), res);     else if (p[a.first][a.second] == 1)       Print(make_pair(a.first, a.second + 1), res);     else {       Print(make_pair(a.first - 1, a.second + 1),             res - 2 + (a.first == a.second));       if (res <= 100) Houki += str[a.first];     }   }   int main() {     scanf( %s , str + 1);     n = strlen(str + 1);     if (n >= 2600) {       for (int i = 1; i <= n; ++i) ++cnt[str[i] -  a ];       for (int i = 0; i < MAXALP; ++i)         if (cnt[i] >= 100) {           for (int j = 0; j < 100; ++j) printf( %c ,  a  + i);           exit(0);         }     }     for (int i = 1; i <= n; ++i)       for (int j = n; j >= i; --j) {         f[i][j] = f[i - 1][j], p[i][j] = -1;         if (f[i][j] < f[i][j + 1]) f[i][j] = f[i][j + 1], p[i][j] = 1;         if (str[i] == str[j] && f[i][j] < f[i - 1][j + 1] + 1)           f[i][j] = f[i - 1][j + 1] + 1, p[i][j] = 0;         if (f[i][j] * 2 - (i == j) >             f[Tohka.first][Tohka.second] * 2 - (Tohka.first == Tohka.second))           Tohka = make_pair(i, j);       }     Print(Tohka,           f[Tohka.first][Tohka.second] * 2 - (Tohka.first == Tohka.second));     string rev =         Houki.substr(0, Houki.size() - (Tohka.first == Tohka.second &&                                         f[Tohka.first][Tohka.second] * 2 -                                                 (Tohka.first == Tohka.second) <=                                             100));     reverse(rev.begin(), rev.end());     Houki += rev;     cout << Houki << endl;     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int ls[N << 2], rs[N << 2], rt[N << 2], sum[N << 2];   int rcnt;   void update(int &rt, int l, int r, int pos) {     if (rt == 0) rt = ++rcnt;     if (l == r) {       sum[rt]++;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid) {       update(ls[rt], l, mid, pos);     } else {       update(rs[rt], mid + 1, r, pos);     }     sum[rt] = sum[ls[rt]] + sum[rs[rt]];   }   int query(int &rt, int l, int r, int ql, int qr) {     if (rt == 0) return 0;     if (ql <= l && qr >= r) return sum[rt];     int mid = (l + r) >> 1, res = 0;     if (ql <= mid) res += query(ls[rt], l, mid, ql, qr);     if (qr > mid) res += query(rs[rt], mid + 1, r, ql, qr);     return res;   }   int n, k;   struct node {     int x, r, f;     bool operator<(const node &z) const { return r > z.r; }   } a[N];   const int low = 1000000000;   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d %d %d , &a[i].x, &a[i].r, &a[i].f);     }     sort(a + 1, a + n + 1);     long long ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = a[i].f - k; j <= a[i].f + k; ++j) {         if (j < 1 || j > 10000) continue;         ans += query(rt[j], 1, low, max(1, a[i].x - a[i].r),                      min(low, a[i].x + a[i].r));       }       update(rt[a[i].f], 1, low, a[i].x);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   int main() {     int num = 0;     int a[100];     int i = 0;     int m = 0;     int yushu;     char hex[16] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,                      8 ,  9 ,  A ,  B ,  C ,  D ,  E ,  F };     scanf( %d , &num);     if (num == 0) {       printf( 1 n );       return 0;     }     while (num > 0) {       yushu = num % 16;       a[i++] = yushu;       num = num / 16;     }     int output = 0;     for (i = i - 1; i >= 0; i--) {       m = a[i];       if (hex[m] ==  0 ) output++;       if (hex[m] ==  4 ) output++;       if (hex[m] ==  6 ) output++;       if (hex[m] ==  8 ) output += 2;       if (hex[m] ==  9 ) output++;       if (hex[m] ==  A ) output++;       if (hex[m] ==  B ) output += 2;       if (hex[m] ==  D ) output++;     }     printf( %d n , output);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const int mod = inf + 7;   const double eps = 1e-9;   const double pi = acos(-1.0);   int n, ind = -1;   int a[100100], b[100100];   pair<int, int> c[100100];   int v[100100], pos[100100];   vector<pair<int, int> > ans;   bool is_happy(int x) {     if (x == 0) return true;     int c = x % 10;     if (c != 4 && c != 7) return false;     return is_happy(x / 10);   }   void sw(int x, int y) {     if (x == y) return;     ans.push_back(make_pair(x, y));     swap(a[x], a[y]);     pos[a[x]] = x;     pos[a[y]] = y;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       b[i] = a[i];       c[i] = make_pair(a[i], i);       if (is_happy(a[i])) ind = i;     }     sort(b, b + n);     bool ok = 1;     for (int i = 0; i < n; i++) ok &= (a[i] == b[i]);     if (ok) {       printf( 0 n );       return 0;     }     if (ind == -1) {       if (ok)         printf( 0 n );       else         printf( -1 n );       return 0;     }     sort(c, c + n);     for (int i = 0; i < n; i++) a[c[i].second] = i;     for (int i = 0; i < n; i++) pos[a[i]] = i;     int x = a[ind];     for (int i = 0; i < n; i++) {       if (i == x) continue;       if (a[i] == i) continue;       int target = pos[i];       sw(ind, i);       ind = i;       sw(ind, target);       ind = target;     }     printf( %d n , (int)ans.size());     for (__typeof(ans.begin()) it = ans.begin(); it != ans.end(); it++) {       printf( %d %d n , it->first + 1, it->second + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100010], b[100010], ja[100010];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ja[a[i]] = i;     }     for (int i = 2; i <= n; i++) {       if (ja[i] > ja[i - 1])         b[i] = 1;       else         b[i] = 0;     }     int ad = 0;     for (int i = 1; i <= n; i++) {       int j = i;       while (b[j] == 1) j++;       ad = max(ad, j - i + 1);       i = j;     }     cout << n - ad << endl;   }