malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct inf {     long long v;     long long b;   };   bool cmp(struct inf a, struct inf c) { return a.b > c.b; }   int main() {     struct inf a[300005];     long long n, k, i, j, sum = 0, ans = -1, temp;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> a[i].v >> a[i].b;     }     sort(a, a + n, cmp);     priority_queue<long long, vector<long long>, greater<long long>> q;     for (i = 0; i < n; i++) {       if (i < k) {         sum += a[i].v;         q.push(a[i].v);         ans = max(ans, sum * a[i].b);       } else {         temp = q.top();         if (temp < a[i].v) {           sum -= temp;           q.pop();           q.push(a[i].v);           sum += a[i].v;           ans = max(ans, sum * a[i].b);         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void count() {}   int ans[1000001], h = 0;   int main() {     count();     int n;     cin >> n;     int a[301], b[301];     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       cin >> b[i];     }     for (int i = 1; i <= n; ++i) {       if (a[i] != b[i]) {         int id;         for (int j = i + 1; j <= n; ++j) {           if (b[j] == a[i]) {             id = j;             break;           }         }         for (int j = id; j > i; --j) {           ans[h++] = j;           swap(b[j], b[j - 1]);         }       }     }     cout << h << endl;     for (int i = 0; i < h; ++i) {       cout << ans[i] - 1 <<     << ans[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int count = 1;     bool res = false;     for (int i = 0; i < s.length() - 1; i++) {       if (s.at(i) == s.at(i + 1)) {         count++;         if (count > 6) {           res = true;           break;         }       } else {         count = 1;       }     }     if (res) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, y;     long long white, black;     cin >> n;     cin >> x >> y;     white = (x - 1) + (y - 1);     black = (n - x) + (n - y);     if (white == black) {       cout <<  White ;     } else {       white > black ? cout <<  Black  : cout <<  White ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 15;   int prime[maxn];   bool visit[maxn] = {false};   vector<int> prim;   vector<int> nu;   void init() {     int pos = 0;     for (int i = 2; i < maxn; i++) {       if (visit[i] == false) {         prime[pos++] = i;       }       for (int j = 0; j < pos && prime[j] * i < maxn; j++) {         visit[prime[j] * i] = true;         if (i % prime[j] == 0) {           break;         }       }     }   }   bool isprime(long long test) {     for (int i = 2; i <= sqrt(test); i++) {       if (test / 2 == 0) {         return false;       }     }     return true;   }   void find(long long test) {     for (int i = 0; prime[i] <= sqrt(test); i++) {       int num = 0;       while (test % prime[i] == 0) {         num++;         test /= prime[i];       }       if (num != 0) {         prim.push_back(prime[i]);         nu.push_back(num);       }     }     if (isprime(test) && test > 1) {       prim.push_back(test);       nu.push_back(1);     }   }   int main() {     int t;     init();     cin >> t;     long long p, q;     while (t--) {       cin >> p >> q;       prim.clear();       nu.clear();       find(q);       if (p % q != 0) {         cout << p << endl;       } else {         long long maxans = -100;         for (int i = 0; i < prim.size(); i++) {           int tmpnum = 0;           long long test = p;           long long ans = p;           while (test % prim[i] == 0) {             test /= prim[i];             tmpnum++;           }           int reducenum = tmpnum - nu[i] + 1;           ans = ans / pow(prim[i], reducenum);           maxans = max(ans, maxans);         }         cout << maxans << endl;       }     }   }
#include <bits/stdc++.h>   int n;   int a[100001];   typedef struct {     int len;   } segment;   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     if (n <= 2) {       printf( %d , n);       return 0;     }     segment max;     max.len = 2;     segment temp;     temp.len = 2;     for (int i = 2; i < n; ++i) {       if (a[i] == a[i - 1] + a[i - 2])         temp.len++;       else {         if (max.len < temp.len) max.len = temp.len;         temp.len = 2;       }     }     if (temp.len > max.len) max.len = temp.len;     printf( %d , max.len);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int lowbit(int a) { return a & (-a); }   int getans(char c, int l, int r, string &s) {     if (l == r) {       return s[l] != c;     }     int len = r - l + 1;     int cnt = 0;     for (int i = l; i < l + len / 2; i++) {       if (s[i] != c) cnt++;     }     int ans = cnt + getans(c + 1, l + len / 2, r, s);     cnt = 0;     for (int i = l + len / 2; i <= r; i++) {       if (s[i] != c) cnt++;     }     ans = min(ans, cnt + getans(c + 1, l, l + len / 2 - 1, s));     return ans;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       cout << getans( a , 0, n - 1, s) <<   n ;     }   }
#include <cstdio>   #include <algorithm>   #include <vector>      typedef long long LL;   const int Inf = 0x3f3f3f3f;   const int Mod = 998244353;   const int MN = 405;      int N, M;   std::vector<int> G[MN];   int Dis[MN][MN];      int Calc(int x, int y) {    for (int i = 2; i <= N; ++i)     if ((Dis[x][i] ^ Dis[y][i] ^ Dis[x][1] ^ Dis[y][1]) & 1)      return 0;    int cnt = 0;    for (int i = 1; i <= N; ++i)     if (Dis[x][i] + Dis[y][i] == Dis[x][y])      ++cnt;    if (cnt != Dis[x][y] + 1) return 0;    int Ans = 1;    for (int i = 1; i <= N; ++i) {     if (Dis[x][i] + Dis[y][i] == Dis[x][y]) continue;     int c = 0;     for (int v : G[i]) {      if (Dis[x][v] != Dis[x][i] - 1) continue;      if (Dis[y][v] != Dis[y][i] - 1) continue;      ++c;     }     if (!c) return 0;     Ans = (LL)Ans * c % Mod;    }    return Ans;   }      int main() {    scanf( %d%d , &N, &M);    for (int i = 1; i <= N; ++i)     for (int j = 1; j <= N; ++j)      Dis[i][j] = i == j ? 0 : Inf;    for (int i = 1; i <= M; ++i) {     int u, v;     scanf( %d%d , &u, &v);     G[u].push_back(v);     G[v].push_back(u);     Dis[u][v] = 1;     Dis[v][u] = 1;    }    for (int k = 1; k <= N; ++k)     for (int i = 1; i <= N; ++i)      for (int j = 1; j <= N; ++j)       Dis[i][j] = std::min(Dis[i][j], Dis[i][k] + Dis[k][j]);   // for (int i = 1; i <= N; ++i)   //  for (int j = 1; j <= N; ++j)   //   printf( %d%s , Dis[i][j], j == N ?   n  :  ,  );    for (int i = 1; i <= N; ++i)     for (int j = 1; j <= N; ++j)      printf( %d%c , Calc(i, j),    n [j == N]);    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 7;   long long modPow(long long n, long long k) {     long long res = 1;     for (n %= mod; k; k >>= 1) {       if (k & 1) res = res * n % mod;       n = n * n % mod;     }     return res;   }   long long modInv(const long long x) { return modPow(x, mod - 2); }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     int n;     cin >> n;     vector<int> l(n + 1, 0), r(n + 1, 0);     for (int i = 1; i <= n; ++i) cin >> l[i];     for (int i = 1; i <= n; ++i) cin >> r[i];     const auto sz = [&](const int i) {       assert(l[i] <= r[i]);       return r[i] - l[i] + 1LL;     };     long long ans = 0;     vector<long long> dp(n);     for (int i = 0; i < n; ++i) {       const long long c = max(0, min(r[i], r[i + 1]) - max(l[i], l[i + 1]) + 1);       dp[i] = 1 - c * modInv(sz(i)) % mod * modInv(sz(i + 1)) % mod;       (ans += dp[i]) %= mod;     }     for (int i = 0; i + 1 < n; ++i) {       const int L = max(l[i], max(l[i + 1], l[i + 2]));       const int R = min(r[i], min(r[i + 1], r[i + 2]));       const long long c = max(0, R - L + 1);       const long long temp =           1 - (1 - dp[i]) - (1 - dp[i + 1]) +           c * modInv(sz(i) * sz(i + 1) % mod * sz(i + 2) % mod);       (ans += 2 * temp) %= mod;     }     long long sum = 0;     for (int i = 2; i < n; ++i) {       (sum += dp[i - 2]) %= mod;       (ans += 2 * dp[i] * sum) %= mod;     }     cout << (ans % mod + mod) % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct segnode {     int l, r, mid, s, h;     segnode *ls, *rs;     segnode(void) { l = r = mid = s = h = 0; }     segnode(int x, int y) { l = x, r = y, mid = (l + r) >> 1, s = h = 0; }     void build(void) {       if (l == r) return;       ls = new segnode(l, mid);       rs = new segnode(mid + 1, r);       ls->build();       rs->build();     }     void upd(int x, int y) {       if (l == r) {         s = y > 0, h = y;         return;       }       if (x <= mid)         ls->upd(x, y);       else         rs->upd(x, y);       s = ls->s + rs->s;     }     int findx(int x, int &dh) {       if (l == r) {         dh = h;         return l;       }       if (x <= ls->s)         return ls->findx(x, dh);       else         return rs->findx(x - ls->s, dh);     }     int findy(int x) {       if (l == r) return h;       if (x <= mid)         return ls->findy(x);       else         return rs->findy(x);     }     void mupd(int x, int y) {       if (l == r) {         s = y;         return;       }       if (x <= mid)         ls->mupd(x, y);       else         rs->mupd(x, y);       s = max(ls->s, rs->s);     }     int mget(int x, int y) {       if (x <= l && r <= y) return s;       int t = 0;       if (x <= mid) t = ls->mget(x, y);       if (y > mid) t = max(rs->mget(x, y), t);       return t;     }     void print(void) {       printf( [%d,%d %d %d] n , l, r, mid, s);       if (l == r) return;       ls->print();       rs->print();     }   };   segnode sy, sx;   segnode ty, tx;   int n, m, mm;   void init(void) {     mm = m + 11;     sy = segnode(0, mm);     sx = segnode(0, n);     ty = segnode(0, mm);     tx = segnode(0, n);     sy.build();     sx.build();     ty.build();     tx.build();   }   void msort(int *x, int *y, int n) {     pair<int, int> a[20];     for (int i = 1; i <= n; i++) a[i].first = x[i], a[i].second = y[i];     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) x[i] = a[i].first, y[i] = a[i].second;   }   int main(void) {     scanf( %d%d , &n, &m);     init();     for (int t = 1, x, y, z; t <= m; t++) {       scanf( %d%d , &x, &y);       static int ti[20], hi[20];       if (x == 1) {         scanf( %d , &z);         int dz = z;         z = z - t + m;         tx.upd(y, z), ty.upd(z, y);         int dt = 0;         for (int i = 1; i <= dz; i++) {           int id = i - t + m;           ti[++dt] = ty.findy(id), hi[dt] = id;           if (!ti[dt])             dt--;           else             sy.mupd(id, 0), sx.mupd(ti[dt], 0);         }         msort(hi, ti, dt);         for (int i = dt; i >= 1; i--) {           int s = sx.mget(ti[i] + 1, n) + 1;           sy.mupd(hi[i], s), sx.mupd(ti[i], s);         }       } else {         for (int i = 1; i <= y; i++) {           int h, id = tx.findx(i, h);           ti[i] = id, hi[i] = h;           sy.mupd(h, 0), sx.mupd(id, 0);           if (i == y) tx.upd(id, 0), ty.upd(h, 0);         }         for (int i = y - 1; i >= 1; i--) {           int s = sy.mget(hi[i] + 1, mm) + 1;           sy.mupd(hi[i], s), sx.mupd(ti[i], s);         }       }       printf( %d n , sy.mget(0, mm));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct node {     int a, k;     bool operator<(const node& e) const { return k < e.k; }   } a[300100];   int main() {     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++) scanf( %d %d , &a[i].k, &a[i].a);       sort(a, a + n);       int ans = a[0].a;       for (int i = 1; i < n; i++) {         int u = 0;         while (ans != 1 && u + a[i - 1].k < a[i].k) {           u++;           ans = (ans + 3) / 4;         }         ans = max(ans, a[i].a);       }       if (ans == 1)         printf( %d n , a[n - 1].k + 1);       else {         int p = a[n - 1].k;         while (ans != 1) {           p++;           ans = (ans + 3) / 4;         }         printf( %d n , p);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int MAXN = 1e18 + 7;   const long long int MAXNN = 300005;   long long int int_pow(long long int base, long long int exp) {     long long int result = 1;     while (exp) {       if (exp & 1) result *= base;       exp /= 2;       base *= base;     }     return result;   }   vector<long long int> g[MAXNN];   vector<long long int> w[MAXNN];   set<pair<long long int, long long int> > st;   long long int dist[MAXNN];   long long int par[MAXNN];   bool mark[MAXNN];   map<pair<long long int, long long int>, long long int> mpw;   map<pair<long long int, long long int>, long long int> mpn;   void diekstra(long long int n, long long int s) {     fill_n(dist, MAXNN, MAXN);     dist[s] = 0;     for (long long int i = 1; i <= n; i++) st.insert({dist[i], i});     while (!st.empty()) {       set<pair<long long int, long long int> >::iterator it = st.begin();       long long int x = it->second;       mark[x] = 1;       st.erase(it);       for (long long int i = 0; i < (long long int)g[x].size(); i++) {         long long int y = g[x][i];         if (!mark[y]) {           st.erase({dist[y], y});           if (dist[y] >= dist[x] + w[x][i]) {             par[y] = x;           }           dist[y] = min(dist[y], dist[x] + w[x][i]);           st.insert({dist[y], y});         }       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(par, -1, sizeof par);     long long int n, m, u, v, z, stpoint = 0, ans = 0;     cin >> n >> m;     for (long long int i = 0; i < m; i++) {       cin >> u >> v >> z;       if (u > v) swap(u, v);       mpn[{u, v}] = i + 1;       mpw[{u, v}] = z;       g[u].push_back(v);       g[v].push_back(u);       w[u].push_back(z);       w[v].push_back(z);     }     cin >> stpoint;     diekstra(n, stpoint);     for (long long int i = 1; i <= n; i++) {       if (i == stpoint) continue;       u = i, v = par[i];       if (u > v) swap(u, v);       ans += mpw[{u, v}];     }     cout << ans <<   n ;     for (long long int i = 1; i <= n; i++) {       if (i == stpoint) continue;       u = i, v = par[i];       if (u > v) swap(u, v);       cout << mpn[{u, v}] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[10000000];   int main() {     long long n, i, j, m, l, r, cnt = 0;     string s, s2, s3 =   , s4 =   , s5 =   ;     cin >> s >> s2;     n = s.size();     for (i = 0; i < n - 1; i++) {       if (s[i] == s2[i])         s3 += s[i];       else         break;     }     for (i = n - 1; i > 0; i--) {       if (s[i] == s2[i - 1])         s4 += s[i];       else         break;     }     l = s3.size();     r = s4.size();     if (l + 1 < n - r)       cout <<  0  << endl;     else {       s5 = s5 + s[l];       cnt = 0;       for (i = l; i >= 0; i--) {         if (s5[0] == s[i]) {           a[cnt] = i + 1;           ++cnt;         } else           break;       }       for (i = l + 1; i < n; i++) {         if (s5[0] == s[i]) {           a[cnt] = i + 1;           ++cnt;         } else           break;       }       sort(a, a + cnt);       cout << cnt << endl;       for (i = 0; i < cnt; i++) {         cout << a[i] <<    ;       }     }   }
#include <bits/stdc++.h>      using namespace std;      long long dp[2][300000];      long long dfs(int previous,bool previousMax,int N, vector<vector<int> > & adj, vector<pair<long long,long long> > &vals) {    if(dp[previousMax][N]!=-1) return dp[previousMax][N];    long long res1 = 0;    long long res2 = 0;    if(previous != -1) {     res1 = abs((previousMax?vals[previous].second:vals[previous].first)-vals[N].first);     res2 = abs((previousMax?vals[previous].second:vals[previous].first)-vals[N].second);    }       for(auto &z:adj[N]) {     if(z != previous) {      res1 += dfs(N,false,z,adj,vals);      res2 += dfs(N,true,z,adj,vals);     }    }    dp[previousMax][N] = max(res1,res2);    return max(res1,res2);   }      int main() {    ios_base::sync_with_stdio(false);    cin.tie(0);    int T;    cin>>T;        while(T--) {     int N;     cin>>N;     vector<pair<long long int,long long int> > vals(N);     for(int c=0;c<N;c++) cin>>vals[c].first>>vals[c].second;        vector<vector<int> > adj(N);        for(int c=0;c<2;c++) for(int c2=0;c2<N;c2++) dp[c][c2] = -1;        for(int c=1;c<N;c++) {      int f,t;      cin>>f>>t;      f--;      t--;      adj[f].push_back(t);      adj[t].push_back(f);     }        cout<<max(dfs(-1,false,0,adj,vals),dfs(-1,false,0,adj,vals))<<  n ;    }   }
#include <bits/stdc++.h>   using namespace std;   int n;   char a[1000];   int mp[105][150];   int jishu[105][5];   int flag;   int main() {     scanf( %d , &n);     memset(mp, 0, sizeof(mp));     getchar();     for (int i = 1; i <= n; i++) {       memset(a, 0, sizeof(a));       gets(a);       flag = 0;       for (unsigned int j = 0; j < strlen(a); j++) {         if (mp[i][a[j]] == 0) {           jishu[i][flag] = a[j];           flag++;         }         mp[i][a[j]]++;         if (flag > 2) {           memset(mp[i], 0, sizeof(mp[i]));           memset(jishu[i], 0, sizeof(jishu[i]));           break;         }       }     }     int re = 0;     int linshi = 0;     for (int j =  a ; j <=  z ; j++)       for (int k =  a ; k <=  z ; k++) {         linshi = 0;         for (int l = 1; l <= n; l++) {           if ((jishu[l][0] == j && jishu[l][1] == k) ||               (jishu[l][0] == k && jishu[l][1] == j)) {             linshi += (mp[l][j] + mp[l][k]);           } else {             if (jishu[l][1] < 97 || jishu[l][1] > 123) {               if (jishu[l][0] == j) {                 linshi += mp[l][j];               }               if (jishu[l][0] == k && j != k) {                 linshi += mp[l][k];               }             }           }         }         re = max(re, linshi);       }     cout << re << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int main(void) {     int t;     long long n, k, o;     cin >> t;     while (t--) {       cin >> n >> k;       for (o = 0; n;) {         if (n % k) {           o += n % k;           n -= n % k;         } else {           o++;           n /= k;         }       }       cout << o << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;      // Template {{{   #define MOD     1000000007   #define MAX     1e9   #define MIN                 -1e9   #define PI     acos(-1.0)   #define mid(s,e)   (s+(e-s)/2)   #define clz(n)    __builtin_clzll(n)   #define all(x)              (x).begin(), (x).end()   #define pb                  push_back      using ll = long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vll = vector<ll>;   using vvll = vector<vll>;   using vb = vector<bool>;   using vd = vector<double>;   using vs = vector<string>;       using pii = pair<int, int>;   using pll = pair<ll, ll>;   using pdd = pair<double, double>;       using vpii = vector<pii>;   using vpll = vector<pll>;   using vpdd = vector<pdd>;      void __print(int x) {cerr << x;}   void __print(long x) {cerr << x;}   void __print(long long x) {cerr << x;}   void __print(unsigned x) {cerr << x;}   void __print(unsigned long x) {cerr << x;}   void __print(unsigned long long x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}      template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}   template<typename T>   void printVec(const T &v, char sep=   ) {for (auto &i: v) cout << i << sep;}   template<typename T>   void printVecPair(const T &v, char sep=   ) {for (auto &i: v) cout << i.first <<    << i.second<< sep;}         #ifndef ONLINE_JUDGE   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif   // }}}      void solve() {       int n;       cin>>n;       vll c(n), a(n), b(n);       for(ll& i: c) cin>>i;       for(ll& i: a) cin>>i;       for(ll& i: b) cin>>i;       ll ans = 0; ll tot = c[n-1]-1;       for(int i=n-2;i>=0;i--) {           if(a[i+1] > b[i+1]) swap(a[i+1],b[i+1]);           if(a[i+1] == b[i+1]) {               ans = max(tot+2,ans);               tot = c[i] - 1;               continue;           }           if(a[i+1] == -1 || b[i+1] == -1) {               ans = max(tot+2,ans);               tot = 0;               continue;           }           tot += 2;           ll c1 = c[i] - (a[i+1] - 1) - (c[i] - b[i+1]) - 1;            ll c2 = (a[i+1] - 1) + (c[i] - b[i+1]);           ans = max(tot+c1,ans);                      tot+=c2;           if(c[i] > tot) tot = c[i] - 1;             }                 cout<<ans<<endl;                }      int main() {       int t;       cin>>t;       while(t--) solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 4e6;   const long double SADAT = 7.84e-17;   const long long INF = 1e9;   const long long mod = 1e9 + 7;   const long double PI = 4 * atan((long double)1);   long long pw(long long a, long long b) {     return (!b ? 1                : (b & 1 ? a * pw(a * a % mod, b / 2) % mod                         : pw(a * a % mod, b / 2) % mod));   }   long long c, d, n, m, k;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> c >> d >> n >> m >> k;     long long w = n * m - k;     long long mn = 1e9;     for (long long i = 0; i < 10005; i++) {       mn = min(mn, c * i + max(w - n * i, (long long)0) * d);     }     cout << mn;     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   struct info {     int x, y, z;   };   vector<info> ans;   int dep[N], n, m, fa[N];   vector<int> g[N], edge[N];   void dfs(int x) {     dep[x] = dep[fa[x]] + 1;     for (int v : g[x]) {       if (!dep[v]) {         fa[v] = x;         dfs(v);       } else if (v != fa[x] && dep[v] < dep[x]) {         edge[v].push_back(x);       }     }   }   int solve(int x) {     for (int i = 0; i < edge[x].size() >> 1; i++) {       ans.push_back((info){edge[x][i << 1], x, edge[x][i << 1 | 1]});     }     int res = 0;     if (edge[x].size() & 1) {       res = edge[x].back();     }     edge[x].clear();     if (res) {       edge[x].push_back(res);     }     for (int v : g[x]) {       if (fa[v] == x) {         int t = solve(v);         if (t) {           ans.push_back((info){x, v, t});         } else {           edge[x].push_back(v);         }       }     }     for (int i = 0; i < edge[x].size() >> 1; i++) {       ans.push_back((info){edge[x][i << 1], x, edge[x][i << 1 | 1]});     }     return (edge[x].size() & 1) ? edge[x].back() : 0;   }   int main(void) {     scanf( %d%d , &n, &m);     for (int i = 1, u, v; i <= m; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       if (!dep[i]) {         dfs(i);         solve(i);       }     }     printf( %d n , ans.size());     for (info cur : ans) {       printf( %d %d %d n , cur.x, cur.y, cur.z);     }     return 0;   }