malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   class graph {     int v;     list<int>* adj;       public:     graph(int x) {       this->v = x;       adj = new list<int>[v];     }     void add_edge(int a, int b) {       adj[a].push_back(b);       adj[b].push_back(a);     }     void count_colors(int a, int& n, int color[], int color_ar[]);   };   void graph::count_colors(int a, int& n, int color[], int color_ar[]) {     list<int>::iterator itr;     int x = 0;   }   int main() {     int n, m, c, x, y;     cin >> n >> m;     int color[100001] = {0}, Ar[100001] = {0}, g[100001] = {0};     for (int i = 0; i < n; i++) {       cin >> color[i];       g[color[i]] = 1;     }     map<pair<int, int>, int> mp;     for (int i = 0; i < m; i++) {       cin >> x >> y;       if (mp[make_pair(color[x - 1], color[y - 1])] == 0 &&           color[x - 1] != color[y - 1]) {         Ar[color[x - 1]]++;       }       if (mp[make_pair(color[y - 1], color[x - 1])] == 0 &&           color[x - 1] != color[y - 1]) {         Ar[color[y - 1]]++;       }       mp[make_pair(color[x - 1], color[y - 1])] = 1;       mp[make_pair(color[y - 1], color[x - 1])] = 1;     }     int max1 = INT_MIN, color1;     for (int i = 0; i < 100001; i++) {       if (g[i] == 1) {         if (Ar[i] > max1) {           max1 = Ar[i];           color1 = i;         }       }     }     cout << color1;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int M = 1e9 + 7;   int n;   double v, v2, a[N], b[N];   double x, y;   int id = 1;   int main() {     ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> v >> v2;     for (int i = 0; i < n; ++i) {       cin >> b[i];       a[i] = 1.0 * b[i] / v;     }     cin >> x >> y;     for (int i = 1; i < n; ++i) {       a[i] = a[i] + sqrt((b[i] - x) * (b[i] - x) + y * y) / v2;       if (a[i] <= a[id]) {         id = i;       }     }     cout << id + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, w;   };   long long MOD = 1000000007;   long long _MOD = 1000000009;   double EPS = 1e-10;   long long extgcd(long long a, long long b, long long& x, long long& y) {     if (b == 0) {       x = (a >= 0) ? 1 : -1;       y = 0;       return abs(a);     } else {       long long res = extgcd(b, a % b, y, x);       y -= (a / b) * x;       return res;     }   }   long long mod_inverse(long long a, long long m) {     long long x, y;     extgcd(a, m, x, y);     return (m + x % m) % m;   }   long long f(int l, int r, vector<long long>& h, vector<long long>& zi) {     long long x = (h[r] - h[l]) * zi[l] % MOD;     return (x + MOD) % MOD;   }   int main() {     int N, M;     cin >> N >> M;     vector<pair<long long, char> > a, b;     while (N--) {       int l;       char c;       scanf( %d-%c , &l, &c);       if (a.size() && a.back().second == c)         a.back().first += l;       else         a.push_back(pair<long long, char>(l, c));     }     while (M--) {       int l;       char c;       scanf( %d-%c , &l, &c);       if (b.size() && b.back().second == c)         b.back().first += l;       else         b.push_back(pair<long long, char>(l, c));     }     N = a.size();     M = b.size();     if (M == 1) {       long long ans = 0;       for (int i = 0; i < N; i++)         if (a[i].second == b[0].second)           ans += max(0LL, a[i].first - b[0].first + 1);       cout << ans << endl;       return 0;     }     vector<pair<long long, char> > v;     for (pair<long long, char> x : a) v.push_back(x);     for (pair<long long, char> x : b) v.push_back(x);     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     vector<int> A(N), B(M);     for (int i = 0; i < N; i++)       A[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;     for (int j = 0; j < M; j++)       B[j] = lower_bound(v.begin(), v.end(), b[j]) - v.begin() + 1;     vector<long long> z(200001), zi(200001);     z[0] = zi[0] = 1;     for (int i = 1; i <= 200000; i++) {       z[i] = z[i - 1] * 523541 % MOD;       zi[i] = mod_inverse(z[i], MOD);     }     vector<long long> ha(N + 1), hb(M + 1);     for (int i = 0; i < N; i++) ha[i + 1] = (ha[i] + A[i] * z[i]) % MOD;     for (int j = 0; j < M; j++) hb[j + 1] = (hb[j] + B[j] * z[j]) % MOD;     int cnt = 0;     for (int i = 0; i + M <= N; i++) {       if (!(a[i].second == b[0].second && a[i].first >= b[0].first)) continue;       if (!(a[i + M - 1].second == b[M - 1].second &&             a[i + M - 1].first >= b[M - 1].first))         continue;       if (f(i + 1, i + M - 1, ha, zi) != f(1, M - 1, hb, zi)) continue;       cnt++;     }     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   bool check(long long N, int pos) { return (bool)(N & (1LL << pos)); }   int k, n;   int ase[30];   string arr[2505];   vector<int> pos;   vector<int> adj[5005];   vector<string> vec;   int main() {     cin >> k >> n;     for (int i = 1; i <= k; i++) {       cin >> arr[i];     }     if (n == 1) {       cout << -1 << endl;       return 0;     }     if (n == 2) {       swap(arr[1][0], arr[1][1]);       string s1 = arr[1];       swap(arr[1][0], arr[1][1]);       for (int i = 1; i <= k; i++) {         if (arr[i] != arr[1]) {           cout << -1 << endl;           return 0;         }       }       cout << s1 << endl;       return 0;     }     if (k == 1) {       swap(arr[1][0], arr[1][1]);       cout << arr[1] << endl;       return 0;     }     bool hobe = true, first = true;     int nul = 0;     for (int i = 2; i <= k; i++) {       int cnt = 0;       for (int j = 0; j < n; j++) {         if (arr[1][j] != arr[i][j]) {           if (first) pos.push_back(j);           adj[i].push_back(j);           cnt++;         }       }       if (adj[i].size() == 0) nul++;       if (cnt == 1 || cnt > 4) hobe = false;       if (cnt > 0 && first) first = false;     }     if (nul == k - 1) {       swap(arr[1][0], arr[1][1]);       cout << arr[1] << endl;       return 0;     }     if (!hobe)       cout << -1 << endl;     else {       for (int i = 0; i < pos.size(); i++) {         for (int j = 0; j < n; j++) {           if (pos[i] == j) continue;           swap(arr[1][pos[i]], arr[1][j]);           vec.push_back(arr[1]);           swap(arr[1][pos[i]], arr[1][j]);         }       }       int mx = 0;       for (int i = 0; i < n; i++) {         ase[arr[1][i] -  a ]++;         mx = max(mx, ase[arr[1][i] -  a ]);       }       if (mx > 1) vec.push_back(arr[1]);       string ans =  -1 ;       for (int p = 0; p < vec.size(); p++) {         int cnt = 0;         for (int i = 2; i <= k; i++) {           int mis = 0;           char m1[5001], m2[5001];           for (int j = 0; j < n; j++) {             if (vec[p][j] != arr[i][j]) {               mis++;               m1[mis] = vec[p][j];               m2[mis] = arr[i][j];             }           }           if (mis == 2 && m1[1] == m2[2] && m1[2] == m2[1])             cnt++;           else if (mis == 0 && mx >= 2)             cnt++;           else             break;         }         if (cnt == k - 1) {           ans = vec[p];           break;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0}, mp[100005], b;   int cheak(int x, int y) {     if (abs(x - y) == m || abs(x - y) == 1)       return 1;     else       return 0;   }   void dfs(int x) {     if (x == n * m) {       b = 1;       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) printf( %d  , mp[i * m + j] + 1);         printf(  n );       }       return;     }     for (int i = x; i < n * m; i++) {       swap(mp[i], mp[x]);       if ((x / m == 0 || cheak(mp[x], mp[(x / m - 1) * m + x % m]) == 0) &&           (x % m == 0 || cheak(mp[x], mp[x / m * m + x % m - 1]) == 0)) {         dfs(x + 1);         if (b == 1) return;         swap(mp[i], mp[x]);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n * m; i++) mp[i] = i;     dfs(0);     if (b == 0) printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct coordinate {     float x;     float y;   };   float check1(coordinate c1, coordinate c2, coordinate c3, coordinate c4,                coordinate x1) {     float ans1 = (x1.y - c1.y) + (x1.x - c1.x);     float ans2 = (x1.y - c3.y) + (x1.x - c3.x);     if (ans1 == 0 || ans2 == 0)       return 0;     else {       float ans = ans1 / ans2;       return ans;     }   }   float check2(coordinate c1, coordinate c2, coordinate c3, coordinate c4,                coordinate x1) {     float m = (c3.y - c1.y) / (c3.x - c1.x);     float ans1 = (x1.y - c1.y) - m * (x1.x - c1.x);     float ans2 = (x1.y - c2.y) - m * (x1.x - c2.x);     if (ans1 == 0 || ans2 == 0)       return 0;     else {       float ans = ans1 / ans2;       return ans;     }   }   int main() {     float n, d;     cin >> n >> d;     coordinate c1, c2, c3, c4;     c1.x = d;     c1.y = 0;     c2.x = 0;     c2.y = d;     c3.x = n;     c3.y = n - d;     c4.x = n - d;     c4.y = n;     int t;     cin >> t;     while (t--) {       coordinate x1;       cin >> x1.x >> x1.y;       float ans1 = check1(c1, c2, c3, c4, x1);       float ans2 = check2(c1, c2, c3, c4, x1);       if (ans1 < 0 && ans2 < 0)         cout <<  YES  << endl;       else if (ans1 == 0 || ans2 == 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mul_mod(long long a, long long b, long long MOD) { return a * b; }   struct myhash {     long long chash[401000][2];     long long mult[401000][2];     long long b1, M1, b2, M2;     myhash(long long b1 = 1000000021, long long M1 = 1200000000000000013LL,            long long b2 = 1000000009, long long M2 = 1200000000000000011LL)         : b1(b1), M1(M1), b2(b2), M2(M2) {       calc();     }     void calc() {       mult[0][0] = mult[0][1] = 1;       for (long long i = 1; i < 401000; i++) {         mult[i][0] = mul_mod(mult[i - 1][0], b1, M1);         mult[i][1] = mul_mod(mult[i - 1][1], b2, M2);       }     }     void compute(vector<long long> &st) {       chash[0][0] = chash[0][1] = st[0] + 1;       for (int i = 1; i < (int)st.size(); i++) {         chash[i][0] = (mul_mod(chash[i - 1][0], b1, M1) + st[i] + 1);         chash[i][1] = (mul_mod(chash[i - 1][1], b2, M2) + st[i] + 1);       }     }     pair<long long, long long> substr(long long l, long long r) {       if (!l) return make_pair(chash[r][0], chash[r][1]);       long long p1 =           (chash[r][0] - mul_mod(chash[l - 1][0], mult[r - l + 1][0], M1));       long long p2 =           (chash[r][1] - mul_mod(chash[l - 1][1], mult[r - l + 1][1], M2));       return make_pair(p1, p2);     }   } h1, h2;   long long n, m, a[401000];   vector<long long> diff;   int main() {     scanf( %lld %lld , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       if (i) diff.push_back((a[i] - a[i - 1] + m) % m);     }     diff.push_back((a[0] - a[n - 1] + m) % m);     for (int i = 0, sz = diff.size(); i < sz; i++) diff.push_back(diff[i]);     h1.compute(diff);     reverse(diff.begin(), diff.end());     h2.compute(diff);     reverse(diff.begin(), diff.end());     long long acum = 0;     for (int i = 0; i < n; i++) acum += diff[i];     assert(acum % m == 0);     vector<long long> ans;     for (int i = n; i < diff.size(); i++) {       acum += diff[i];       if (h1.substr(0, i) == h2.substr(diff.size() - i - 1, diff.size() - 1)) {         ans.push_back((2LL * a[0] + acum) % m);       }     }     sort(ans.begin(), ans.end());     ans.resize(unique(ans.begin(), ans.end()) - ans.begin());     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %lld%c , ans[i], (i + 1 == ans.size()) ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   long long mpow(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n /= 2;     }     return res;   }   long long s2(long long n) {     n %= mod;     return n * (n - 1) % mod;   }   long long s3(long long n) {     n %= mod;     return n * (n - 1) % mod * (n - 2) % mod;   }   long long eval(vector<long long> p, long long t) {     long long res = 0;     for (int i = p.size() - 1; i >= 0; --i) {       res = (res * t + p[i]) % mod;     }     return res;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     long long n;     cin >> n;     vector<long long> p(4);     long long inv2 = mpow(2, mod - 2);     long long inv3 = mpow(3, mod - 2);     p[3] = (inv3) % mod;     p[2] = (-(n + 2) % mod * inv2) % mod;     p[1] = (-inv3 + (n + 2) % mod * inv2) % mod;     p[0] = (-s3(n + 2) * inv3 + (n + 2) % mod * inv2 % mod * s2(n + 1)) % mod;     long long s = eval(p, 1);     for (long long x = 1; x * x <= n; ++x) {       s = (s + 4 * eval(p, x * x % mod)) % mod;     }     vector<vector<long long> > pws(4, vector<long long>(1000003));     for (int i = 0; i < pws.size(); ++i) {       for (long long j = 1; j < pws[i].size(); ++j) {         long long j2 = j * j % mod;         long long add = 1;         for (int t = 0; t < i; ++t) add = add * j2 % mod;         pws[i][j] = (pws[i][j - 1] + add) % mod;       }     }     long long y = sqrt(n) + 2;     for (long long x = 1; x * x < n; ++x) {       while (x * x + y * y > n) --y;       long long x2 = x * x % mod;       long long s1 = 0;       s1 = (s1 + y * p[0]) % mod;       s1 = (s1 + (x2 * y % mod + pws[1][y]) * p[1]) % mod;       s1 =           (s1 + (x2 * x2 % mod * y % mod + 2 * x2 * pws[1][y] % mod + pws[2][y]) *                     p[2]) %           mod;       s1 = (s1 + (x2 * x2 % mod * x2 % mod * y % mod +                   3 * x2 * x2 % mod * pws[1][y] % mod + 3 * x2 * pws[2][y] % mod +                   pws[3][y]) *                      p[3]) %            mod;       s = (s + 4 * s1) % mod;     }     cout << (s % mod + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(int a, int b) {     if (a > b)       return true;     else       return false;   }   struct pack {     long long t, T, x, cost;   };   int main() {     long long ans = 0, n, m;     cin >> n >> m;     vector<pack> data;     for (int i = 0; i < (n); ++i) {       pack temp;       cin >> temp.t >> temp.T >> temp.x >> temp.cost;       data.push_back(temp);     }     for (int i = 0; i < (n); ++i) {       data[i].T = data[i].T - data[i].t;       if (data[i].T > 0) {         long long ans1;         if (m > data[i].T)           ans1 = data[i].cost + m * data[i].x;         else           ans1 = data[i].cost;         if (m > data[i].T) {           long long k = data[i].cost * ((m + data[i].T - 1) / data[i].T);           ans1 = min(ans1, k);         }         if (m > 2 * data[i].T) {           long long ans2 = m % data[i].T + data[i].T;           ans1 = min(ans1, data[i].cost * (1 + (m - ans2) / data[i].T) +                                ans2 * data[i].x);         }         ans += ans1;       } else {         ans += data[i].cost + m * data[i].x;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long infl = 0x3f3f3f3f3f3f3f3fLL;   template <class T>   void rd(T &a) {     char ch = getchar();     bool ng = 0;     a = 0;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) ng = 1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       a = (a << 1) + (a << 3) + (ch ^  0 );     if (ng) a = ~a + 1;   }   template <class T>   void wrt(T a) {     if (a < 0) {       putchar( - );       wrt(~a + 1);     } else {       if (a > 9) wrt(a / 10);       putchar(a % 10 ^  0 );     }   }   const int N = 5e5 + 5;   int n, q, nxt[N], a[N], ans[N];   map<int, int> pos;   vector<pair<int, int> > Q[N];   int fen[N];   void upd(int p, int x) {     for (; p <= n; p += p & (-p)) fen[p] = min(fen[p], x);   }   int get(int p) {     int res = inf;     for (; p; p -= p & (-p)) res = min(res, fen[p]);     return res;   }   int main() {     rd(n), rd(q);     for (int i = 1; i <= n; ++i) rd(a[i]);     for (int i = n; i; --i) {       if (pos.count(a[i]))         nxt[i] = pos[a[i]];       else         nxt[i] = -1;       pos[a[i]] = i;     }     for (int i = 1; i <= n; ++i) fen[i] = inf;     for (int i = 1; i <= q; ++i) {       int l, r;       rd(l), rd(r);       Q[l].push_back(pair<int, int>(r, i));     }     for (int i = n; i; --i) {       if (~nxt[i]) upd(nxt[i], nxt[i] - i);       for (int j = 0; j < (int)((Q[i]).size()); ++j) {         int r = Q[i][j].first, id = Q[i][j].second;         ans[id] = get(r);       }     }     for (int i = 1; i <= q; ++i) {       if (ans[i] >= inf)         puts( -1 );       else         wrt(ans[i]), puts(  );     }     return 0;   }
#include <bits/stdc++.h>   #define PI atan(1.0)*4   #define rp(i,s,t) for (register int i = (s); i <= (t); i++)   #define RP(i,t,s) for (register int i = (t); i >= (s); i--)   #define sc(x) scanf( %d ,&x)   #define scl(x) scanf( %lld ,&x)   #define ll long long   #define ull unsigned long long   #define mst(a,b) memset(a,b,sizeof(a))   #define lson l,m,rt<<1   #define rson m+1,r,rt<<1|1   #define pii pair<int,int>   #define pll pair<ll,ll>   #define pil pair<int,ll>   #define m_p make_pair   #define p_b push_back   #define ins insert   #define era erase   #define INF 0x3f3f3f3f   #define LINF 0x3f3f3f3f3f3f3f3f   #define dg if(debug)   #define outval(a) cout <<  Debuging...|  << #a <<  :   << a <<   n ;   using namespace std;   int debug = 0;   ll gcd(ll a,ll b){    return b?gcd(b,a%b):a;   }   ll lcm(ll a,ll b){    return a/gcd(a,b)*b;   }   inline int read(){    int s=0,f=1;    char ch=getchar();    while(ch< 0 ||ch> 9 ){     if(ch== - ) f=-1;     ch=getchar();    }    while(ch>= 0 &&ch<= 9 ){     s=s*10+ch- 0 ;     ch=getchar();    }    return s*f;   }   const int N = 1e6+7;   const double eps = 1e-7;   int a[N];   int f[N];   void solve(){    int n=read(),m=read();    rp(i,1,n) a[i]=read();    rp(i,1,n) f[i]=0;    RP(i,n,1){     if(a[i]!=i) break;     else f[i]=1;    }    int flag=1;    rp(i,1,n){     if(f[i]==0){      flag=0;     }    }    double ans=0.0;    double cur=1;    int ff=0;    rp(i,1,m){     int r;double p;     scanf( %d%lf ,&r,&p);     // printf( %d %lf n ,r,p);     if(r==n||f[r+1]){      ans+=cur*p;      cur*=(1.0-p);      if(fabs(p-1.0)<=eps) ff=1;     }    }    if(ff||flag){     printf( 1.000000 n );     return ;    }    printf( %.6f n ,ans);   }   int main(){    //ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);   #ifdef ONLINE_JUDGE   #else    freopen( in.txt ,  r , stdin);    //debug = 1;   #endif    time_t beg, end;    //if(debug) beg = clock();       int T=read();    while(T--) solve();       /*    if(debug) {     end = clock();     printf( time:%.2fs n , 1.0 * (end - beg) / CLOCKS_PER_SEC);    }    */    return 0;   }
#include <bits/stdc++.h>   const int N = 2e5 + 3;   int n, m, l[N + N + N], r[N + N + N], k;   char a[N + N + N], b[N];   int main() {     int p, q;     scanf( %d%d%s , &n, &m, a + 1);     for (int i = 1; i <= n; i++) a[i + n] = a[i + n + n] = a[i];     for (int i = 1; i <= n; i++) b[i] = a[i];     for (int i = 1; i <= n; i++)       if (a[i + n] == a[i + n - 1]) goto Brk;     for (int i = 1 + (m & 1); i <= n + (m & 1); i++) putchar(a[i]);     return 0;   Brk:;     k = 0;     for (int i = 1; i <= n * 3; i++)       if (a[i] == a[i - 1] && a[i] != a[i + 1]) r[++k] = i;     k = 0;     for (int i = 1; i <= n * 3; i++)       if (a[i] != a[i - 1] && a[i] == a[i + 1]) l[++k] = i;     for (int i = 1 + n; i <= n * 2; i++)       if (a[i] != a[i - 1] && a[i] != a[i + 1]) {         q = l[std::lower_bound(l + 1, l + 1 + k, i) - l];         p = r[std::lower_bound(r + 1, r + 1 + k, i) - r - 1];         if (q - i > m && i - p > m)           b[i - n] = a[i + (m & 1)];         else if (q - i < i - p)           b[i - n] = a[q];         else           b[i - n] = a[p];       }     for (int i = 1; i <= n; i++) putchar(b[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, k, x, d[200001] = {}, last_d = 1, last = 0, a;     long long sum = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> t;       if (1 == t) {         cin >> a >> x;         sum += a * x;         if (last_d == 0) {           last += x;         } else if (last_d == a) {           last += x;         } else {           d[a] -= x;         }       } else if (2 == t) {         cin >> k;         sum += k;         d[last_d++] = k - last;         last = k;       } else {         sum -= last;         last -= d[--last_d];       }       cout << setiosflags(ios::fixed) << setprecision(6)            << ((double)sum) / ((double)last_d) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     cin >> n >> d;     int t[n], sum = 0, rest = (n - 1) * 10;     for (int i = 0; i < n; i++) {       cin >> t[i];       sum = sum + t[i];     }     if ((rest + sum) > d) {       cout <<  -1 ;       return 0;     } else {       int bal = d - sum, max;       max = bal / 5;       cout << max;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:100000000 )   using namespace std;   const int N = 200;   char s[N][N];   int main() {     int C;     cin >> C;     int n = 3;     while (n * (n - 1) * (n - 2) / 6 <= C) ++n;     int m = --n;     C -= n * (n - 1) * (n - 2) / 6;     vector<int> add;     while (C > 0) {       ++n;       for (int i = 2; i <= m; i++) {         if (i * (i - 1) / 2 > C) {           --i;           add.push_back(i);           C -= i * (i - 1) / 2;           break;         }       }     }     assert(n <= 100);     memset(s,  0 , sizeof(s));     for (int(i) = 0; (i) < (m); (i)++)       for (int(j) = 0; (j) < (i); (j)++) s[i][j] = s[j][i] =  1 ;     for (int i = m; i < n; i++) {       for (int(j) = 0; (j) < (add[i - m]); (j)++) {         s[i][j] = s[j][i] =  1 ;       }     }     printf( %d n , n);     for (int(i) = 0; (i) < (n); (i)++) {       s[i][n] = 0;       puts(s[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int64_t INF = 0x7FFFFFFF;   const int MAX = 1;   unordered_map<int, int> maps;   unordered_map<int, int> cnt;   int main(int argc, char* args[]) {     int n;     scanf( %d , &n);     for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) {       int x;       scanf( %d , &x);       maps[x]++;     }     for (auto it : maps) {       int x = it.second;       for (int(i) = (1), _n = (x); (i) <= _n; (i)++) {         cnt[i]++;       }     }     int ans = 0;     for (auto it : cnt) {       ans += it.second - 1;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool lucky(char a) {     if (a ==  4  || a ==  7 )       return true;     else       return false;   }   int main() {     long long int a, b, c, d;     vector<bool> res;     cin >> a >> b >> c >> d;     if (abs(c - d) > 1 || min(a, b) < max(c, d)) {       puts( -1 );       return 0;     }     if (c > d) {       for (long long int i = 0; i < ((long long int)(a - d)); i++) cout << 4;       for (long long int i = 0; i < ((long long int)(d)); i++) cout << 74;       for (long long int i = 0; i < ((long long int)(b - d)); i++) cout << 7;     } else if (c < d) {       cout << 7;       for (long long int i = 0; i < ((long long int)(a - c)); i++) cout << 4;       for (long long int i = 0; i < ((long long int)(c - 1)); i++) cout << 74;       for (long long int i = 0; i < ((long long int)(b - c)); i++) cout << 7;       cout << 4;     } else {       if (a + b < c + d + 1) {         puts( -1 );         return 0;       }       for (long long int i = 0; i < ((long long int)(a - c)); i++) cout << 4;       if (a - c > 0) {         for (long long int i = 0; i < ((long long int)(c - 1)); i++) cout << 74;         for (long long int i = 0; i < ((long long int)(b - c + 1)); i++)           cout << 7;         cout << 4;       } else {         cout << 7;         for (long long int i = 0; i < ((long long int)(c)); i++) cout << 47;         for (long long int i = 0; i < ((long long int)(b - 1 - c)); i++)           cout << 7;       }     }     puts(  );     return 0;   }