malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     reverse(a, a + n);     stack<pair<int, int>> st;     for (int i = 0; i < n; i++) {       pair<int, int> p = make_pair(a[i], 0);       while (!st.empty()) {         pair<int, int> q = st.top();         if (q.first < p.first) {           st.pop();           p.second = max(p.second + 1, q.second);         } else           break;       }       st.push(p);     }     int pas = 0;     while (!st.empty()) {       pas = max(pas, st.top().second);       st.pop();     }     cout << pas;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   istream &operator>>(istream &in, pair<T1, T2> &P) {     in >> P.first >> P.second;     return in;   }   template <class T1, class T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &P) {     out <<  (  << P.first <<  ,   << P.second <<  ) ;     return out;   }   template <class T>   istream &operator>>(istream &in, vector<T> &arr) {     for (auto &x : arr) in >> x;     return in;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &arr) {     for (auto &x : arr) out << x <<    ;     cout <<   n ;     return out;   }   template <class T>   istream &operator>>(istream &in, deque<T> &arr) {     for (auto &x : arr) in >> x;     return in;   }   template <class T>   ostream &operator<<(ostream &out, const deque<T> &arr) {     for (auto &x : arr) out << x <<    ;     cout <<   n ;     return out;   }   long long n, m, q, k, v[1000050], l, pref[1000050];   pair<long long, long long> TT, w[1000050];   string second;   long long dp[1000050];   long long prox[1000050];   long long resolve(long long cost) {     memset(dp, 0, sizeof dp);     for (long long i = n; i >= 1; i--) {       long long A =           dp[min(n + 1, i + l)] + (pref[min(n, i + l - 1)] - pref[i - 1]) - cost;       long long B = dp[i + 1];       if (A > B)         prox[i] = 0;       else         prox[i] = 1;       dp[i] = max(A, B);     }     long long j = 1, usados = 0;     while (j <= n) {       if (!prox[j])         usados++, j = j + l;       else         j = j + 1;     }     return usados;   }   long long solve(long long a, long long b) {     long long ini = 0, fim = 200000000000000000, mid, best = -1;     while (fim >= ini) {       mid = (ini + fim) / 2;       long long us = resolve(mid);       if (us <= k)         best = mid, fim = mid - 1;       else         ini = mid + 1;     }     if (best == -1) return 0;     long long us = resolve(best);     return dp[1] + k * best;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k >> l;     cin >> second;     for (long long i = 1; i <= n; i++) {       if ( a  <= second[i - 1] and second[i - 1] <=  z )         v[i] = 0;       else         v[i] = 1;     }     for (long long i = 1; i <= n; i++) pref[i] = pref[i - 1] + v[i];     long long A = pref[n] - solve(1, k);     for (long long i = 1; i <= n; i++) {       v[i] ^= 1;       pref[i] = pref[i - 1] + v[i];     }     long long B = pref[n] - solve(1, k);     cout << min(A, B) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2000 + 10;   int n, k, a[MAX_N], dp[MAX_N];   bool check(int x) {     for (int i = 0; i < n; i++) {       dp[i] = 1;       for (int j = i - 1; ~j; j--)         if (abs(a[i] - a[j]) <= 1LL * (i - j) * x) dp[i] = max(dp[i], dp[j] + 1);       if (n - dp[i] <= k) return true;     }     return false;   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     int L = -1, R = 2e9 + 10;     while (L + 1 < R) {       int mid = (1LL * L + R) >> 1;       check(mid) ? R = mid : L = mid;     }     cout << R << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans;   struct aa {     int l, r;     int v;   };   bool operator<(aa a, aa b) { return a.r < b.r; }   inline aa qwq(int l, int r, int v) {     aa a;     a.l = l;     a.r = r;     a.v = v;     return a;   }   set<aa> s;   int read() {     register int x = 0, ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   void wt() {     for (set<aa>::iterator i = s.begin(); i != s.end(); i++) {       cout << i->l <<     << i->r <<     << i->v <<   n ;     }     cout <<  ------ n ;   }   void spliT(set<aa>::iterator i, int x) {     int l = i->l;     int r = i->r;     int v = i->v;     if (x >= r) return;     if (x < l) return;     s.erase(i);     s.insert(qwq(l, x, v));     s.insert(qwq(x + 1, r, v));     if (v == 1) ans++;   }   void mergE(set<aa>::iterator i) {     int l = i->l, r = i->r, v = i->v;     set<aa>::iterator j = i, k = i;     if (l != 1) {       j--;       if (j->v == v) {         l = j->l;         s.erase(j);         if (v == 1) ans--;       }     }     if (r != n) {       k++;       if (k->v == v) {         r = k->r;         s.erase(k);         if (v == 1) ans--;       }     }     s.erase(i);     s.insert(qwq(l, r, v));   }   void Ass(int l, int r) {     set<aa>::iterator x = s.lower_bound((aa){0, l - 1, 0});     if (l != 1) spliT(x, l - 1);     set<aa>::iterator y = s.lower_bound((aa){0, r, 0});     spliT(y, r);     x = s.lower_bound((aa){0, l, 0});     y = s.lower_bound((aa){0, r + 1, 0});     for (set<aa>::iterator i = x; i != y; i++) {       if (i->v == 1) ans--;     }     s.erase(x, y);     s.insert(qwq(l, r, 1));     ans++;     x = s.lower_bound((aa){0, l, 0});     mergE(x);   }   signed main() {     n = 1000000005;     cin >> m;     s.insert(qwq(1, n, 0));     for (int i = 1; i <= m; i++) {       int l, r;       l = read();       r = read();       r--;       Ass(l, r);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long MAXN = 1e5 + 7;   const long long MAXM = 1e5 + 7;   const long long MOD = 1e9 + 7;   const double eps = 1e-6;   const double pi = acos(-1.0);   long long a[200005];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     sort(a + 1, a + 1 + n);     long long ans = 0x3f3f3f3f;     for (int i = 1; i <= n / 2; i++) ans = min(ans, a[i + n / 2] - a[i]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     map<pair<int, int>, int> mp;     map<int, int> mp1;     vector<pair<int, int>> v;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       mp1[x]++;       mp1[y]++;       mp[{x, y}]++;       mp[{y, x}]++;     }     bool f = 0;     for (int i = 1; i <= n; i++) {       v.push_back({mp1[i], i});     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       if (f) break;       for (int j = i - 1; j > -1 && v[i].first + v[j].first >= m; j--) {         int x = v[i].second, y = v[j].second;         int ans = 0;         ans += mp1[x];         ans += mp1[y];         ans -= mp[{x, y}];         if (ans >= m) {           f = 1;           break;         }       }     }     if (f)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p;   char a[20000];   int b[20000];   int main() {     cin >> n >> p;     scanf( %s , a);     memset(b, -1, sizeof(b));     for (int i = 0; i < n; ++i) {       if (a[i] ==  . ) {         if (i - p >= 0 && b[i - p] != -1) {           b[i] = b[i - p] ^ 1;         }       } else {         b[i] = a[i] -  0 ;         ;         if (i - p >= 0 && b[i - p] == -1) {           b[i - p] = b[i] ^ 1;         }       }     }     for (int i = 0; i < n; ++i) {       if (b[i] == -1) {         if (i - p >= 0)           b[i] = b[i - p] ^ 1;         else           b[i] = 0;       }     }     int fg = 0;     for (int i = 0; i < n; ++i) {       if (i + p >= n) continue;       if (b[i] != b[i + p]) fg = 1;     }     if (fg == 0)       puts( No );     else {       for (int i = 0; i < n; ++i) {         printf( %d , b[i]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char com[200];     char *p;     int man = 0;     int sum = 0;     int i;     int word;     while (scanf( %c , com) == 1) {       i = 1;       while ((com[i] = getchar()) !=   n ) i++;       com[i] =   0 ;       word = 0;       if (com[0] ==  + ) {         man++;         continue;       }       if (com[0] ==  - ) {         man--;         continue;       }       p = strchr(com,  : );       p += 1;       while (*(p++) !=   0 ) {         word++;       }       sum += word * man;     }     printf( %d , sum);   }
#include<bits/stdc++.h>   #define ll long long   #define F first   #define S second   #define endl   n    using namespace std;   const ll mod=1e9+7;   const int N=5+3e5;   const int INF=1e9;   ll a[3][N],s[3],n[3];   int x[3]= {0,1,2};   int main()   {   #ifdef LOCAL       freopen( input.in ,  r , stdin);   #endif       ll m1,m2,ans=-1e18;       cin>>n[0]>>n[1]>>n[2];       for(int i=0; i<n[0]; ++i)       {           cin>>a[0][i];           s[0]+=a[0][i];       }       for(int i=0; i<n[1]; ++i)       {           cin>>a[1][i];           s[1]+=a[1][i];       }       for(int i=0; i<n[2]; ++i)       {           cin>>a[2][i];           s[2]+=a[2][i];       }          sort(a[0],a[0]+n[0]);       sort(a[1],a[1]+n[1]);       sort(a[2],a[2]+n[2]);          do       {           m1=a[x[1]][0]-(s[x[0]]-a[x[0]][n[x[0]]-1]+s[x[2]]-a[x[2]][0]);           m2=a[x[2]][0]-(s[x[1]]-a[x[1]][0]);           if(m1>m2)               swap(m1,m2);           if(m2>=0)               ans=max(ans,a[x[0]][n[x[0]]-1]-(m1-m2));           else               ans=max(ans,a[x[0]][n[x[0]]-1]-m1-m2);       }       while(next_permutation(x,x+3));       cout<<ans<<  n ;                           }
#include <bits/stdc++.h>   const long long INF = (long long)1e18 + 2;   using namespace std;   void solve();   void fastIO() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int main() {     fastIO();     solve();   }   void solve() {     int n, m;     cin >> n >> m;     char a[n][m];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     int rs = 200, re = -1, cs = 200, ce = -1;     bool flag = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  B ) {           if (i < rs) rs = i;           if (i > re) re = i;           if (j < cs) cs = j;           if (j > ce) ce = j;           flag = false;         }       }     }     if (flag) {       cout << 1;       return;     }     int x = re - rs + 1;     int y = ce - cs + 1;     int mx = max(x, y);     if (n < mx || m < mx) {       cout << -1;       return;     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  B ) ans++;       }     }     cout << (mx * mx - ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     if (b % a) {       cout << -1 <<   n ;     } else {       int x = b / a;       int ans = 0;       while (x % 2 == 0) {         ans++;         x /= 2;       }       while (x % 3 == 0) {         ans++;         x /= 3;       }       if (x != 1) {         cout << -1 << endl;       } else {         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, nn = 0, nm = 0, dr[5069], dh[10069], pd[5069], pr[5069], fq[10069],                sbt[10069], sm = 0, z = 1e18;   vector<pair<long long, long long>> fz[5069], al[10069];   pair<long long, long long> sk[5069];   vector<long long> pst[5069];   bitset<10069> vtd;   void ae(long long x, long long y, long long w) {     al[x].push_back({y, w});     al[y].push_back({x, w});   }   void bd(long long x) {     long long i, sz = al[x].size(), l;     vtd[x] = 1;     sbt[x] = fq[x];     for (i = 0; i < sz; i++) {       l = al[x][i].first;       if (!vtd[l]) {         bd(l);         sbt[x] += sbt[l];       }     }   }   void dfs(long long x) {     long long i, sz = al[x].size(), l, w;     vtd[x] = 1;     z = min(z, sm);     for (i = 0; i < sz; i++) {       l = al[x][i].first;       w = al[x][i].second;       if (!vtd[l]) {         nn += sbt[x] - sbt[l];         sm += w * (nn - (n - nn));         dfs(l);         sm -= w * (nn - (n - nn));         nn -= sbt[x] - sbt[l];       }     }   }   int main() {     long long i, j, k, l, w, ll, c, p = 0, sz, bg, lca;     for (i = 2; i <= 5000; i++) {       if (fz[i].empty()) {         p++;         for (j = i; j <= 5000; j += i) {           for (c = 0, k = j; k % i == 0; k /= i, c++)             ;           fz[j].push_back({p, c});           dr[j] += c;         }       }     }     nm = 5000;     for (i = 1; i <= 5000; i++) {       sz = fz[i].size();       lca = dh[i - 1];       if (sz) {         bg = fz[i][sz - 1].first;         for (j = 1; j < bg; j++) {           lca -= pd[j];         }       }       for (j = 0; j < sz; j++) {         l = fz[i][j].first;         w = fz[i][j].second;         pd[l] += w;       }       dh[i] = dh[i - 1] + dr[i];       l = 0;       for (; nn && sk[nn].second >= lca; nn--) {         l = sk[nn].first;       }       if (l) {         nn++;         sk[nn] = {l, lca};         sz = pst[l].size();         if (lca < dh[pst[l][sz - 1]]) {           nm++;           dh[nm] = lca;           pst[l].push_back(nm);           sz++;         }         pr[i] = pst[l][sz - 1];       }       nn++;       sk[nn] = {i, dh[i]};       pst[i].push_back(i);     }     for (i = 1; i <= 5000; i++) {       sz = pst[i].size();       for (j = 0; j < sz; j++) {         l = pst[i][j];         if (j) {           ae(ll, l, dh[ll] - dh[l]);         }         ll = l;       }       if (pr[i]) {         ae(pst[i][sz - 1], pr[i], dh[pst[i][sz - 1]] - dh[pr[i]]);       }     }     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &k);       k += !k;       fq[k]++;       sm += dh[k];     }     bd(1);     vtd.reset();     nn = 0;     dfs(1);     printf( %lld n , z);   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], in[100005];   int main() {     int n, m;     scanf( %d , &n);     int i, j;     for (i = 0; i < n; i++) {       scanf( %d , &in[i]);       in[i] = ++a[in[i]];     }     for (i = 2; i <= 100000; i++)       if (a[i] > a[i - 1]) break;     if (i <= 100000)       printf( -1 n );     else {       printf( %d n , a[1]);       for (i = 0; i < n; i++) printf( %d%c , in[i],    n [i == n - 1]);     }   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> arr(5, vector<int>(200005));   int main() {     int t, n, i, ans, a, b, c, d, e, m, j, s, curr;     string s1;     cin >> t;     while (t--) {       cin >> n;       for (i = 0; i < n; i++) {         cin >> s1;         a = 0;         b = 0;         c = 0;         d = 0;         e = 0;         m = s1.size();         for (j = 0; j < m; j++) {           if (s1[j] ==  a )             a++;           else if (s1[j] ==  b )             b++;           else if (s1[j] ==  c )             c++;           else if (s1[j] ==  d )             d++;           else if (s1[j] ==  e )             e++;         }         arr[0][i] = a - (m - a);         arr[1][i] = b - (m - b);         arr[2][i] = c - (m - c);         arr[3][i] = d - (m - d);         arr[4][i] = e - (m - e);       }       for (i = 0; i < 5; i++)         sort(arr[i].begin(), arr[i].begin() + n, greater<int>());       ans = 0;       for (i = 0; i < 5; i++) {         curr = 0;         j = 0;         s = 0;         while (j < n && arr[i][j] > 0) {           s += arr[i][j];           curr++;           j++;         }         while (j < n && (s + arr[i][j]) > 0) {           s += arr[i][j];           curr++;           j++;         }         ans = max(ans, curr);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   int c2i(char c) {     if (c <=  9 ) return c -  0 ;     return c -  A  + 10;   }   long long conv(string num, int base) {     long long res = 0;     for (int i = 0; i < (int)num.length(); i++) {       if (c2i(num[i]) >= base) return INF;       res = res * base + c2i(num[i]);     }     return res;   }   int main() {     string inp, h, m;     cin >> inp;     for (int i = 0; i < (int)inp.length(); i++)       if (inp[i] ==  : ) inp[i] =    ;     istringstream sin(inp);     sin >> h >> m;     vector<int> res;     for (int base = 2; base <= 100; base++)       if (conv(h, base) < 24 && conv(m, base) < 60) res.push_back(base);     if (res.empty())       cout << 0 << endl;     else if (res.back() == 100)       cout << -1 << endl;     else {       for (int i = 0; i < (int)res.size(); i++) cout << res[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int n;   int m;   int a, b;   long long fast_mod_pow(long long a, long long b) {     long long res = 1;     a %= mod;     while (b) {       if (b & 1) {         res = (res * a) % mod;       }       a = (a * a) % mod;       b >>= 1;     }     return res;   }   const int MAXN = 1000005;   long long fac[MAXN];   long long invfact[MAXN];   int main() {     cin >> n >> m >> a >> b;     long long ans = 0;     fac[0] = 1;     fac[1] = 1;     for (int i = 2; i < MAXN; i++) {       fac[i] = fac[i - 1] * i;       fac[i] %= mod;     }     invfact[MAXN - 1] = fast_mod_pow(fac[MAXN - 1], mod - 2);     for (int i = MAXN - 2; i >= 0; i--) {       invfact[i] = (invfact[i + 1] * (i + 1)) % mod;     }     for (int i = 1; i <= m; i++) {       if (i > n - 1) break;       long long temp = 1;       temp *= fac[m - 1];       temp %= mod;       temp *= invfact[m - i];       temp %= mod;       temp *= invfact[i - 1];       temp %= mod;       temp *= fac[n - 2];       temp %= mod;       temp *= invfact[n - i - 1];       temp %= mod;       if ((n - i - 1) == 0) {         ans += temp;         ans %= mod;         continue;       }       temp *= fast_mod_pow((long long)m, (long long)(n - i - 1));       temp %= mod;       temp *= (i + 1);       temp %= mod;       temp *= fast_mod_pow((long long)n, (long long)(n - i - 2));       temp %= mod;       ans += temp;       ans %= mod;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(pair<float, int> a, pair<float, int> b) {     if (a.first > b.first)       return true;     else if (a.first == b.first)       return a.second < b.second;     else       return false;   }   inline istream& skip_endl(istream& is) {     return is.ignore(numeric_limits<streamsize>::max(),   n );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     long double t1, t2, k, a, b, h1, h2;     cin >> n >> t1 >> t2 >> k;     vector<pair<long double, int>> heights;     for (int i = 1; i <= n; i++) {       cin >> a >> b;       h1 = (a * t1) - (a * t1 * (k / 100.0)) + (b * t2);       h2 = (b * t1) - (b * t1 * (k / 100.0)) + (a * t2);       heights.push_back(make_pair(max(h1, h2), i));     }     sort(heights.begin(), heights.end(), comp);     for (auto h : heights) {       cout << fixed << setprecision(2) << h.second;       cout <<     << h.first <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937_64 rd(787);   int a[500010];   int cnt[500010];   unsigned long long has[500010];   unsigned long long val[500010];   list<int> vec[500010];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     auto t = clock();     auto now_time = [&] { return (clock() - t) / (double)CLOCKS_PER_SEC; };     int n;     cin >> n;     unsigned long long anss = 1e18;     for (int i = 1; i <= n; i++) cin >> a[i];     while (now_time() < 4) {       for (int i = 1; i <= n; i++) val[i] = rd(), vec[i].clear();       unsigned long long ans = 0;       map<unsigned long long, int> mp;       mp[0]++;       int pre = 0;       for (int i = 1; i <= n; i++) {         int tmp = a[i];         has[i] = has[i - 1] + val[tmp], cnt[tmp]++, vec[tmp].push_back(i);         if (cnt[tmp] % 3 == 0) {           has[i] -= 3 * val[tmp];         }         mp[has[i]]++;         if (vec[tmp].size() > 3) {           int now = vec[tmp].front();           vec[tmp].pop_front();           for (; pre < now; pre++) {             mp[has[pre]]--;           }         }         ans += mp[has[i]] - 1;       }       anss = min(ans, anss);       break;     }     cout << anss << endl;   }
#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> V;   bool solve(int n);   int main() {     ios_base::sync_with_stdio(false);     int i, st, dr, mid;     cin >> N;     V.resize(N);     for (i = 0; i < N; ++i) {       cin >> V[i];     }     sort(V.begin(), V.end());     st = 1;     dr = N;     while (st < dr) {       mid = (st + dr) / 2;       if (solve(mid)) {         dr = mid;       } else {         st = mid + 1;       }     }     cout << dr <<   n ;     return 0;   }   bool solve(int n) {     int i, j, nr;     vector<int> piles;     piles.resize(n, 101);     j = 0;     for (i = N - 1; i >= 0; --i) {       nr = 0;       while (piles[j] == 0) {         ++j;         ++nr;         if (j == n) j = 0;         if (nr == n + 1) break;       }       if (nr == n + 1) break;       piles[j] = min(piles[j] - 1, V[i]);       ++j;       if (j == n) j = 0;     }     if (i == -1) {       return true;     }     return false;   }
#include <bits/stdc++.h>   using namespace std;   string s, t;   int l = 0, r = 0;   int main() {     cin >> s >> t;     while (s[l] !=  | ) l++;     r = s.size() - l - 1;     int dif;     if (l > r)       dif = t.size() - (l - r);     else       dif = t.size() - (r - l);     if (dif < 0 || dif & 1) {       cout <<  Impossible  << endl;       return 0;     }     if (l < r) {       reverse(s.begin(), s.end());       int i = 0;       while (l < r) {         s += t[i];         i++;         l++;       }       while (i < t.size()) {         s += t[i];         i++;         s = t[i] + s;         i++;       }       reverse(s.begin(), s.end());       cout << s << endl;       return 0;     }     int i = 0;     while (r < l) {       s += t[i];       i++;       r++;     }     while (i < t.size()) {       s += t[i];       i++;       s = t[i] + s;       i++;     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fib[100];   void init() {     fib[0] = 1, fib[1] = 2;     for (int i = 2; i <= 85; i++) fib[i] = fib[i - 1] + fib[i - 2];   }   int w[100];   int dp[100][2];   void solve(long long x) {     memset(w, 0, sizeof(w));     memset(dp, 0, sizeof(dp));     int num = 0;     for (int i = 85; i >= 0; i--) {       if (x >= fib[i]) {         x -= fib[i];         w[num++] = i;       }     }     num--;     dp[0][1] = 1;     dp[0][0] = w[num] >> 1;     int i = 0;     while (num > 0) {       num--;       dp[i + 1][0] = dp[i][0] * ((w[num] - w[num + 1]) >> 1) +                      dp[i][1] * ((w[num] - w[num + 1] - 1) >> 1);       dp[i + 1][1] = dp[i][0] + dp[i][1];       i++;     }     cout << dp[i][0] + dp[i][1] << endl;   }   int main() {     ios::sync_with_stdio(false);     init();     int t;     cin >> t;     while (t--) {       long long x;       cin >> x;       solve(x);     }     return 0;   }