malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18 + 239;   vector<long long> used;   vector<vector<pair<long long, long long> > > gr;   long long ans = -inf;   vector<long long> dp;   long long n;   void dfs(long long p1) {     used[p1] = 1;     if (gr[p1].size() == 1 && p1 != 0) {       ans = max(ans, dp[p1]);       return;     }     vector<long long> neib;     for (long long i = 0; i < gr[p1].size(); i++) {       long long p2 = gr[p1][i].first;       if (used[p2] == 1) continue;       dfs(p2);       neib.push_back(dp[p2] - gr[p1][i].second);     }     sort(neib.rbegin(), neib.rend());     if (neib.size() > 1) {       ans = max(ans, dp[p1] + neib[0] + neib[1]);     }     dp[p1] = max(dp[p1], dp[p1] + neib[0]);     ans = max(ans, dp[p1]);   }   signed main() {     cin >> n;     vector<long long> val(n, 0);     for (long long i = 0; i < n; i++) cin >> val[i];     long long mx = -1;     for (long long i = 0; i < n; i++) mx = max(mx, val[i]);     long long cnt = 0, ana = 1;     for (long long i = 0; i < n; i++) {       if (val[i] == mx)         ++cnt;       else         cnt = 0;       ana = max(ana, cnt);     }     cout << ana << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e9;   const int SIZE = 2e5 + 5;   const int MOD = 1e9 + 7;   void solve(int CASE) {     long long x;     cin >> x;     vector<long long> res;     for (long long i = 1; i <= x; i *= 2LL) {       res.push_back(i);       x -= i;     }     if (x) res.push_back(x);     sort(res.begin(), res.end());     cout << res.size() - 1 << endl;     for (int i = 1; i < res.size(); i++) cout << res[i] - res[i - 1] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int IT;     cin >> IT;     for (int i = 1; i <= IT; i++) {       solve(i);     };     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x, y;     double f, s;     cin >> x >> y;     f = y * (log10(x));     s = x * (log10(y));     if (abs(f - s) < pow(10, -8))       cout <<  = ;     else if (f < s)       cout <<  < ;     else if (f > s)       cout <<  > ;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 10005;   const int Maxb = 31;   struct linker {     int x, y, id;     linker(int x = 0, int y = 0, int id = 0) : x(x), y(y), id(id) {}     bool operator<(const linker &b) const {       if (y != b.y) return y > b.y;       if (x != b.x) return x > b.x;       return id < b.id;     }   };   int n;   linker L[Maxn];   int xbas[Maxb];   int rval[Maxb], masktaken[Maxn];   vector<pair<int, int> > res;   int getBit(int x) {     if (x == 0) return -1;     for (int i = Maxb - 1; i >= 0; i--)       if (x & 1 << i) return i;   }   void Swap(int a, int b) {     if (a == b) return;     res.push_back(pair<int, int>(L[a].id, L[b].id));     res.push_back(pair<int, int>(L[b].id, L[a].id));     res.push_back(pair<int, int>(L[a].id, L[b].id));     swap(L[a].x, L[b].x);     int ab = getBit(L[a].x), bb = getBit(L[b].x);     if (ab != -1) xbas[ab] = a;     if (bb != -1) xbas[bb] = b;   }   void writeMask(int x) {     for (int i = 0; i < Maxb; i++)       if (masktaken[L[x].id] & 1 << i)         res.push_back(pair<int, int>(L[x].id, rval[i]));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &L[i].x);       L[i].id = i;       for (int b = Maxb - 1; b >= 0; b--)         if (L[i].x & 1 << b)           if (xbas[b]) {             res.push_back(pair<int, int>(i, xbas[b]));             L[i].x ^= L[xbas[b]].x;           } else {             xbas[b] = i;             break;           }     }     for (int i = 1; i <= n; i++) {       scanf( %d , &L[i].y);       int num = L[i].y;       L[i].y = 0;       for (int b = Maxb - 1; b >= 0; b--)         if (num & 1 << b)           if (xbas[b]) {             num ^= L[xbas[b]].x;             L[i].y |= 1 << b;           } else {             printf( -1 n );             return 0;           }     }     int cur = 1;     while (true) {       sort(L + cur, L + n + 1);       for (int i = cur; i <= n; i++) {         int b = getBit(L[i].x);         if (b != -1) xbas[b] = i;       }       int b = getBit(L[cur].y);       if (b == -1) {         for (int i = cur; i <= n; i++) {           if (L[i].x) res.push_back(pair<int, int>(L[i].id, L[i].id));           writeMask(i);         }         break;       } else {         Swap(cur, xbas[b]);         writeMask(cur);         for (int i = b - 1; i >= 0; i--)           if (L[cur].y & 1 << i)             res.push_back(pair<int, int>(L[cur].id, L[xbas[i]].id));         rval[b] = L[cur].id;         masktaken[L[cur].id] ^= 1 << b;         for (int i = cur + 1; i <= n; i++)           if (L[i].y & 1 << b) {             L[i].y ^= L[cur].y;             masktaken[L[i].id] ^= masktaken[L[cur].id];           }       }       cur++;     }     printf( %d n , res.size());     for (int i = 0; i < res.size(); i++)       printf( %d %d n , res[i].first, res[i].second);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n, k, i, c = 1, p;       cin >> n >> k;       long long int a[n];       set<long long int> s;       for (i = 0; i < n; i++) {         cin >> a[i];         s.insert(a[i]);       }       if (s.size() <= k) {         cout << 1;       } else {         if (k == 1)           cout << -1;         else {           p = s.size();           p -= k;           if (p % (k - 1) != 0) c++;           c += p / (k - 1);           cout << c;         }       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int TC;     cin >> TC;     while (TC--) {       int N;       cin >> N;       string s;       cin >> s;       int ans = 0;       int cnt = 0;       for (int i = N - 1; i >= 0; i--) {         if (s[i] ==  P )           cnt++;         else {           ans = max(ans, cnt);           cnt = 0;         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0) {       cout << -1;     } else {       for (int i = 0; i < n; i++) {         cout << (2 * i) % n <<    ;       }       cout << endl;       cout << 0 <<    ;       for (int i = n - 1; i > 0; i--) {         cout << i <<    ;       }       cout << endl;       for (int i = 0; i < n; i++) {         cout << i <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a;     cin >> n >> m;     a = n % m;     for (int i = 1; i <= m; i++) {       if (a > 0) {         cout << n / m + 1 <<    ;         a--;       } else {         cout << n / m <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int nax = 1e5 + 10;   vector<int> tree(4 * nax);   long long i, j, x, y, k;   bool sortbysec(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.second < b.second);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, cnt = 0;     cin >> n;     vector<vector<long long>> a(n + 1);     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       a[x].push_back(y);       a[y].push_back(x);     }     for (i = 1; i <= n; i++) {       if (a[i].size() == 1) cnt++;     }     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   double max(double a, double b) { return a > b ? a : b; }   double min(double a, double b) { return a > b ? b : a; }   double x[10101], y[10101], z[10101], A, B;   int n, m, k;   void slv() {     double minx = -1;     sort(x + 1, x + n + 1);     sort(y + 1, y + m + 1);     sort(z + 1, z + k + 1);     double tmp = sqrt(x[n] * x[n] / (1 + ((A * z[1]) / (B * y[m]))));     printf( %lf n , tmp);   }   int main() {     while (cin >> n) {       for (int i = 1; i <= n; i++) {         cin >> x[i];       }       cin >> m;       for (int i = 1; i <= m; i++) {         cin >> y[i];       }       cin >> k;       for (int i = 1; i <= k; i++) {         cin >> z[i];       }       cin >> A >> B;       slv();     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   int n;   long long area, cnt;   double fac[200], ans, calc;   struct Point {     long long x, y;     Point() {}     Point(long long x, long long y) : x(x), y(y) {}     Point operator-(const Point& tmp) const {       return Point(x - tmp.x, y - tmp.y);     }   } p[maxn];   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   long long cross(Point A, Point B) { return A.x * B.y - A.y * B.x; }   int main() {     if (fopen( D.in ,  r ) != NULL) {       freopen( D.in ,  r , stdin);       freopen( D.out ,  w , stdout);     }     n = read();     for (int i = 0; i < n; i++) p[i].x = read(), p[i].y = read();     fac[0] = 1;     for (int i = 1; i <= 100; i++) fac[i] = fac[i - 1] * 2;     if (n <= 100) calc = fac[n] - 1 - n - n * (n - 1) / 2;     for (int i = 0; i < n; i++)       cnt += gcd(abs(p[i].x - p[(i + 1) % n].x), abs(p[i].y - p[(i + 1) % n].y));     for (int i = 1; i < n - 1; i++) area += cross(p[i] - p[0], p[i + 1] - p[0]);     ans = (area - cnt) / 2 + 1;     for (int i = 0; i < n; i++) {       area = 0,       cnt =           gcd(abs(p[i].x - p[(i + 1) % n].x), abs(p[i].y - p[(i + 1) % n].y)) + 1;       for (int k = 2, j; k <= 60; k++) {         j = (i + k) % n;         if ((j + 1) % n == i) break;         cnt += gcd(abs(p[j].x - p[(j - 1 + n) % n].x),                    abs(p[j].y - p[(j - 1 + n) % n].y));         area += cross(p[(j + n - 1) % n] - p[i], p[j] - p[i]);         long long tmp = gcd(abs(p[j].x - p[i].x), abs(p[j].y - p[i].y)) - 1;         long long s = (area - (cnt + tmp)) / 2 + 1;         if (n <= 100)           ans -= (double)(tmp + s) * (fac[n - k - 1] - 1) / calc;         else           ans -= (double)(tmp + s) * (1.0 / fac[k + 1]);       }     }     printf( %.12lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y;     cin >> x >> y;     int length = x.length();     for (int i = 0; i < length; i++) {       int c = x[i];       if (islower(c)) x[i] = toupper(c);     }     int length1 = y.length();     for (int i = 0; i < length1; i++) {       int c = y[i];       if (islower(c)) y[i] = toupper(c);     }     int xx = 0, yy = 0;     for (int i = 0; i < length; i++) {       int r = int(x[i]);       xx += r;       int d = int(y[i]);       yy += d;     }     cout << x.compare(y);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int dp[N], x[N];   int main() {     int k, n, b, t;     scanf( %d%d%d%d , &k, &n, &b, &t);     int lim = min(t, min(n, b)) * n;     while (k--) {       for (int i = 0; i < n; i++) scanf( %d , &x[i]);       memset(dp, 0, sizeof dp);       for (int i = 0; i < lim; i++) {         int v = x[i % n];         for (int j = v; j <= b && dp[j] == dp[v - 1]; j++) dp[j]++;       }       printf( %d n , dp[b]);     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q;     cin >> t;     while (t--) {       cin >> n;       f = 0;       v.clear();       for (i = 2; f < 2 && i <= sqrt(n) + 1; i++) {         if (n % i == 0) {           v.push_back(i);           n /= i;           f++;         }       }       if (v.size() < 2 || n == 1 || n == v[0] || n == v[1]) {         cout <<  NO n ;       } else {         cout <<  YES n  << v[0] <<     << v[1] <<     << n <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 105;   const long long MOD = 1e9 + 7;   long long n, m, k;   long long cache[N][N * N], cache2[N][N];   long long fact[N], invfact[N];   long long pow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   long long modinv(long long k) { return pow(k, MOD - 2, MOD); }   void precompute() {     fact[0] = fact[1] = 1;     for (long long i = 2; i < N; i++) {       fact[i] = fact[i - 1] * i;       fact[i] %= MOD;     }     invfact[N - 1] = modinv(fact[N - 1]);     for (long long i = N - 2; i >= 0; i--) {       invfact[i] = invfact[i + 1] * (i + 1);       invfact[i] %= MOD;     }   }   long long nCr(long long x, long long y) {     if (y > x) return 0;     long long num = fact[x];     num *= invfact[y];     num %= MOD;     num *= invfact[x - y];     num %= MOD;     return num;   }   long long get(long long idx, long long cur) {     long long &ans = cache2[idx][cur];     if (ans != -1) return ans;     long long ways = nCr(n, cur);     long long have = m / n;     if (m % n >= (idx)) have++;     ways = pow(ways, have, MOD);     return ans = ways;   }   long long dp(long long idx, long long rem) {     if (idx == n + 1) return (rem == 0);     long long &ans = cache[idx][rem];     if (ans != -1) return ans;     ans = 0;     for (long long cur = 0; cur <= min(n, rem); cur++) {       long long ways = get(idx, cur);       ans += ways * dp(idx + 1, rem - cur);       ans %= MOD;     }     return ans;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     precompute();     memset(cache, -1, sizeof(cache));     memset(cache2, -1, sizeof(cache2));     cin >> n >> m >> k;     cout << dp(1, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 7;   const long long INF = (long long)1e9 + 7;   char st[N];   map<long long, long long> s[200];   long long c[N];   int main() {     int n;     long long t, ans = 0, x = 0;     for (char i =  a ; i <=  z ; i++) cin >> c[i];     gets(st);     gets(st);     n = strlen(st);     for (int i = 0; i < n; i++) {       x += c[st[i]];       ans += s[st[i]][x - c[st[i]]];       s[st[i]][x]++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[1000011];   int main() {     while (~scanf( %s , a)) {       int t = strlen(a);       if (t % 2 != 0)         printf( Impossible n );       else {         stack<char> sta;         int ans = 0, p = 0;         for (int i = 0; i < t; i++) {           if (a[i] ==  {  || a[i] ==  [  || a[i] ==  (  || a[i] ==  < ) {             sta.push(a[i]);             ans++;           } else {             if (sta.empty()) {               p++;               printf( Impossible n );               break;             } else {               char s = sta.top();               if ((s ==  {  && a[i] ==  } ) || (s ==  (  && a[i] ==  ) ) ||                   (s ==  [  && a[i] ==  ] ) || (s ==  <  && a[i] ==  > )) {                 ans--;               }               sta.pop();             }           }         }         if (p == 0) {           if (sta.empty()) {             if (ans < 0)               printf( Impossible n );             else               printf( %d n , ans);           } else             printf( Impossible n );         }       }       memset(a, 0, sizeof(a));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef long long lli;   #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);     #define pb push_back    #define int long long      int dp[201][20001];      int numSubseq(int n , vector<int>& a, int s , int pos1 = -2 , int pos2 = -2 )   {    if( n == pos1 || n == pos2 )      return numSubseq( n - 1 , a , s ) ;       if(n==-1)       {           if(s==0) return 1;           return 0;       }       if(s<0) return 0;       if(s==0) return 1;       if(dp[n][s]!=-1) return dp[n][s];       return dp[n][s] = numSubseq(n-1,a,s-a[n]) || numSubseq(n-1,a,s);   }      signed main()   {         memset(dp,-1,sizeof(dp));    int n , sum = 0 ;    cin >> n ;     vector<int> a(n) ;    for( auto &it : a )     cin >> it , sum += it ;        if( sum % 2 )     {     cout << 0 ;     return 0 ;    }     if( !numSubseq( n -1 , a , sum / 2 ) )    {     cout << 0;     return 0 ;    }       for( int i = 0 ; i< n ; i++ )     {     int target = sum - a[i] ;     if( target % 2 )      {      cout << 1 << endl;       cout << i + 1;       return 0 ;      }      if( !numSubseq(n-1,  a , target / 2 , i ) )     {      cout <<  1 << endl ;      cout << i + 1 << endl ;       return 0 ;     }    }          for( int i = 0 ; i < n; i++ )    {     for( int j = 0 ; j < n ; j++ )     {      if( i == j ) continue ;      int target = sum - a[i] - a[j] ;       if( target % 2 )       {       cout << 2 << endl ;       cout << i +1 <<     << j + 1 << endl ;       return 0 ;       }      if( !numSubseq(n-1, a , target / 2 , i , j ) )       {       cout << 2 << endl ;       cout << i + 1 <<     << j + 1 <<endl ;       return 0 ;      }     }    }   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, m, ta, tb, k;     cin >> n >> m >> ta >> tb >> k;     long long int a[n], b[m];     for (int i = 0; i < n; i++) cin >> a[i], a[i] += ta;     for (int i = 0; i < m; i++) cin >> b[i];     if (k >= n || k >= m) {       cout << -1 <<   n ;       return 0;     }     long long int d = 0;     for (int i = 0, index; i < n && k >= 0; i++, k--) {       index = lower_bound(b, b + m, a[i]) - b + k;       if (index >= m) {         cout << -1 <<   n ;         return 0;       }       d = max(d, b[index] + tb);     }     cout << d <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     if (n == 12) {       string hour =   ;       hour += s[0];       hour += s[1];       string min =   ;       min += s[3];       min += s[4];       if (hour ==  00 ) s[0] =  1 ;       if (stoi(hour) > 12) {         if (s[1] ==  0 )           s[0] =  1 ;         else if (s[1] ==  2  || s[1] ==  1 )           s[0] =  1 ;         else {           s[0] =  0 ;         }       }       if (stoi(min) > 59) {         s[3] =  0 ;       }     } else {       string hour =   ;       hour += s[0];       hour += s[1];       string min =   ;       min += s[3];       min += s[4];       if (stoi(hour) > 23) {         s[0] =  0 ;       }       if (stoi(min) > 59) s[3] =  0 ;     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 100;   vector<int> adj[N];   int n, sz[N];   int get(int cur, int fr) {     sz[cur] = 1;     int ret = 0;     for (auto v : adj[cur]) {       if (v == fr) continue;       ret |= get(v, cur);       sz[cur] += sz[v];     }     if (!ret && sz[cur] > n / 2) ret = cur;     return ret;   }   void dfs(int cur, int fr) {     sz[cur] = 1;     for (auto v : adj[cur]) {       if (v == fr) continue;       dfs(v, cur);       sz[cur] += sz[v];     }   }   bool can[N];   void solve(int cur, int fr, int mx) {     if (n - sz[cur] - mx <= n / 2) can[cur] = 1;     vector<int> pre(1, 0), suf(1, 0);     for (auto v : adj[cur])       if (v != fr) pre.push_back(max(pre.back(), sz[v]));     for (int i = int(adj[cur].size()) - 1; i >= 0; i--) {       int v = adj[cur][i];       if (v != fr) suf.push_back(max(suf.back(), sz[v]));     }     reverse(suf.begin(), suf.end());     int j = 0;     for (int i = 0; i < adj[cur].size(); ++i) {       int v = adj[cur][i];       if (v == fr) continue;       int nmx = max(pre[j], suf[j + 1]);       nmx = max(nmx, mx);       if (n - sz[v] <= n / 2) nmx = max(nmx, n - sz[v]);       solve(v, cur, nmx);       j++;     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; ++i) {       int u, v;       scanf( %d , &u), scanf( %d , &v);       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     int root = get(0, 0);     dfs(root, root);     solve(root, root, 0);     for (int i = 0; i < n; ++i)       if (can[i])         printf( 1  );       else         printf( 0  );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int g[4];     int i = 0;     for (i = 0; i < 4; i++) {       cin >> g[i];     }     sort(g, g + 4);     long long a = 0, b = 0, c = 0, k = 0;     k = g[3];     a = g[0];     b = g[1];     c = g[2];     cout << (a + c) - k <<     << (a + b) - k <<     << (b + c) - k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = 2000000000;   const long double eps = 0.0000001;   const long double pi = acos(-1.0);   const long long int MOD = 998244353;   const long long int N = 1e5 + 5;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     long long int a[n];     for (long long int i = 0; i < n; ++i) {       cin >> a[i];     }     long long int ans = 1, mn = inf;     for (long long int t = 1; t <= 100; t++) {       long long int s = 0;       for (long long int i = 0; i < n; ++i) {         if (a[i] > t + 1)           s += a[i] - t - 1;         else if (a[i] < t - 1)           s += t - a[i] - 1;       }       if (s < mn) {         mn = s;         ans = t;       }     }     cout << ans <<     << mn;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mem[1000];   int k;   map<long long int, long long int> first;   long long int f(long long int x) {     if (first.find(x) != first.end()) return first[x];     if (x % 2 == 0)       return f(x / 2);     else       return f(x / 2) + 1;   }   int main() {     first[0] = 0;     first[1] = 1;     map<long long int, long long int> q;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long int x;       cin >> x;       long long int fx = f(x);       q[fx]++;     }     long long int ans = 0;     map<long long int, long long int>::iterator it;     for (it = q.begin(); it != q.end(); it++) {       ans += ((it->second) * (it->second - 1)) / 2;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n), g(256, -1);     for (int &e : a) cin >> e;     for (int i = 0; i < n; i++) {       if (g[a[i]] != -1)         a[i] = g[a[i]];       else {         int temp = max(0, a[i] - k + 1);         for (int j = a[i] - 1; j >= temp; j--)           if (g[j] != -1) {             if (g[j] >= temp) {               for (int k = g[j]; k <= a[i]; k++) g[k] = g[j];               a[i] = g[j];               break;             }             for (int k = j + 1; k <= a[i]; k++) g[k] = j + 1;             a[i] = j + 1;             break;           } else if (j == temp) {             for (int k = temp; k <= a[i]; k++) g[k] = temp;             a[i] = temp;           }       }     }     for (int &e : a) cout << e <<    ;     cin >> n;   }