malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10;   int mod = 1e9 + 7;   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   long long INV(long long a) { return power(a, mod - 2); }   mt19937 Rand(123456);   int Range(int l, int r) { return l + Rand() % (r - l + 1); }   map<long long, long long> mp;   void work(int l, int r, int k) {     if (k == 1 || l == r) {       ++mp[r - l + 1];       return;     }     int mid = (l + r) / 2;     work(l, mid, k - 1);     work(mid + 1, r, k - 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k >> mod;     vector<long long> inv(2 * n), inv_sum;     for (int i = 0; i <= 2 * n - 1; i++) inv[i] = INV(i);     inv_sum = inv;     for (int i = 1; i <= 2 * n - 1; i++) inv_sum[i] += inv_sum[i - 1];     for (auto& I : inv_sum) I %= mod;     auto merge = [&](int l, int r, const vector<long long>& inv_sum) {       long long res = (long long)l * r % mod * INV(2) % mod;       for (int i = 1; i <= l; i++) res -= inv_sum[i + r] - inv_sum[i];       res %= mod;       res += mod;       return res % mod;     };     work(1, n, k);     long long res = 0;     for (auto I : mp)       res += (I.first * (I.first - 1) % mod * INV(4) % mod) * I.second % mod,           res += I.second * (I.second - 1) % mod * INV(2) % mod *                  merge(I.first, I.first, inv_sum) % mod;     for (auto I : mp)       for (auto J : mp)         if (I.first < J.first)           res +=               merge(I.first, J.first, inv_sum) * I.second % mod * J.second % mod;     res %= mod;     res += mod;     res %= mod;     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double t, y, j, n;     cin >> t;     while (t--) {       cin >> n;       j = n * n;       j = j - 4 * n;       if (j >= 0) {         double x = sqrt(j);         if ((-n - x) > 0)           cout <<  N ;         else {           x = (n - x) / 2;           if (x != 0)             y = n / x;           else             y = 0;           std::cout << std::fixed <<  Y                      <<     << std::setprecision(9) << x <<     << y;         }       } else         cout <<  N ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   constexpr long long INF = 2e18;   constexpr long long MOD = 1e9 + 7;   constexpr long long MAXN = 2e5 + 3;   void solve() {     long long n;     cin >> n;     map<long long, long long> m;     long long ans = 0;     for (long long i = 1; i <= n; ++i) {       long long x;       cin >> x;       m[x - i] += x;       ans = max(ans, m[x - i]);     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   float S, a, b, c;   int main() {     ios ::sync_with_stdio(false);     cin >> S >> a >> b >> c;     float sum = a + b + c;     if (sum == 0)       cout <<  0 0 0 ;     else       printf( %.12f %.12f %.12f , a * S / sum, b * S / sum, c * S / sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MM = 120000;   vector<int> G[MM], T[MM];   int P[MM], L[MM];   void dfs(int u, int par) {     P[u] = par;     if (par != -1) L[u] = L[par] + 1;     for (auto v : G[u]) {       if (v != par) {         dfs(v, u);       }     }   }   int N, K;   bool rip = 0;   void dfs2(int u, int par, int lev) {     int kek = 0;     for (auto v : G[u]) {       if (v != par) {         kek++;         dfs2(v, u, lev + 1);       }     }     if (kek < 3 && kek != 0) {       rip = 1;     }     if (kek == 0 && lev != K) {       rip = 1;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N >> K;     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       G[u - 1].push_back(v - 1);       G[v - 1].push_back(u - 1);     }     dfs(0, -1);     int mx = 0;     int el = -1;     for (int i = 0; i < N; i++) {       mx = max(mx, L[i]);       if (mx == L[i]) {         el = i;       }     }     if (mx >= K) {       mx = K;       while (mx--) el = P[el];       int rt = el;       dfs2(rt, -1, 0);       if (rip) {         cout <<  No ;       } else {         cout <<  Yes ;       }     } else {       cout <<  No ;       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int get(int x) {     int cnt = 0;     while (x >= 10) {       int sum = 0;       while (x) {         sum += x % 10;         x /= 10;       }       cnt++;       x = sum;     }     return cnt;   }   int main() {     string s;     cin >> s;     if (s.size() == 1)       cout << 0 << endl;     else {       int n = 0;       for (int i = 0; i < s.size(); i++) n += s[i] -  0 ;       cout << get(n) + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void ga(int N, int *A) {     for (int i(0); i < N; i++) scanf( %d , A + i);   }   long long pw(long long n, long long k, long long MOD) {     long long r(1);     while (k) {       if (k & 1) r = r * n >= MOD ? r * n % MOD + MOD : r * n;       n = n * n >= MOD ? n * n % MOD + MOD : n * n;       k >>= 1;     }     return r;   }   long long P[(1 << 17) >> 1] = {2}, L(1), cn[1 + ((1 << 17) >> 6)];   void gen() {     (cn[0 >> 6] |= 1ULL << ((0 & 63))), (cn[1 >> 6] |= 1ULL << ((1 & 63)));     int Q(1 + sqrt((1 << 17)));     for (long long i(4); i < (1 << 17); i += 2)       (cn[i >> 6] |= 1ULL << ((i & 63)));     for (int k(3); k <= Q; k += 2)       if (!((cn[k >> 6] >> (k & 63)) & 1))         for (long long h(k << 1), j(k * k); j < (1 << 17); j += h)           (cn[j >> 6] |= 1ULL << ((j & 63)));     for (int i(3); i < (1 << 17); i += 2)       if (!((cn[i >> 6] >> (i & 63)) & 1)) P[L++] = i;   }   int fc(int N, int *f, int *c) {     int L(0);     for (int i(0), h(0); N >= P[i] * P[i]; ++i, h = 0) {       while (!(N % P[i])) ++h, N /= P[i];       if (h) f[L] = P[i], c[L++] = h;     }     if (N > 1) f[L] = N, c[L++] = 1;     return L;   }   int phi(int N) {     static int f[64], c[64];     int L(fc(N, f, c)), P(1);     for (int i(0); i < L; i++)       P *= pow(f[i], c[i]) - pow(f[i], c[i] - 1) + (1e-10);     return P;   }   int N, M, G[(1 << 17)], I, A[(1 << 17)], a, b, S;   int main(void) {     gen(), scanf( %d%d , &N, &M), *G = M, ga(N, A);     while (G[I] ^ 1) ++I, G[I] = phi(G[I - 1]);     int _;     scanf( %d , &_);     for (int i(0); i < _; i++) {       scanf( %d%d , &a, &b), --a, --b, S = 1;       for (int i = min(b - a, I); ~i; --i) S = pw(A[a + i], S, G[i]);       printf( %d n , S % M);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, k;     cin >> n >> k;     long long int ans = k / n;     long long int t1 = ans * n;     if (t1 < k) ans++;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.push_back(move(x));     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   n ;     err(++it, args...);   }   int N, M;   int X[5013];   pair<long long, int> H[5013];   long long dp[5013][5013];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M;     for (int i = 0; i < N; i++) {       cin >> X[i];     }     long long housing = 0;     for (int i = 1; i <= M; i++) {       cin >> H[i].first >> H[i].second;       housing += H[i].second;     }     if (N > housing) {       cout << -1 << endl;       return 0;     }     sort(X, X + N);     sort(H + 1, H + M + 1);     for (int i = 0; i < N; i++) {       dp[0][i] = 1123456789123456789LL;     }     for (int i = 1; i <= M; i++) {       long long allin = 0;       deque<pair<long long, int> > mpq;       mpq.push_back({0, -1});       for (int j = 0; j < N; j++) {         allin += abs(X[j] - H[i].first);         long long diff = dp[i - 1][j] - allin;         while (mpq.size() && diff <= mpq.back().first) {           mpq.pop_back();         }         mpq.push_back({diff, j});         while (j - mpq.front().second > H[i].second) {           mpq.pop_front();         }         dp[i][j] = allin + mpq.front().first;       }     }     cout << dp[M][N - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000005], dp[1000005];   int main() {     int n, i, j;     while (~scanf( %d , &n)) {       memset(dp, 0, sizeof(dp));       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);       }       for (i = 0; i < n; i++) {         dp[a[i]] = max(dp[a[i]], 1);         for (j = a[i] + a[i]; j <= a[n - 1]; j += a[i])           dp[j] = max(dp[j], dp[a[i]] + 1);       }       int ans = 1;       for (i = 0; i < n; i++) ans = max(ans, dp[a[i]]);       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     int n;     long long m;     cin >> n >> m;     m -= 1;     vector<int> xs;     for (int i = 0; i < n; i++) {       xs.push_back(-1);     }     int i = 0;     int u = 0;     int v = n - 1;     while (u <= v) {       long long h = (1LL << (n - i - 2));       if (m >= h) {         xs[v] = i;         v -= 1;         m -= h;       } else {         xs[u] = i;         u += 1;       }       i += 1;     }     for (int i = 0; i < n; i++) printf( %d  , xs[i] + 1);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p[222222];   long long sum[222222];   long long max1[222222];   long long max2[222222];   long long get(long long l, long long r) {     long long t = sum[r];     if (l >= 1) {       t -= sum[l - 1];     }     return t;   }   int main() {     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n; i++) {       cin >> p[i];       if (i) {         sum[i] = sum[i - 1] + p[i];       } else {         sum[i] = p[i];       }     }     for (long long i = 0; i < n; i++) {       if (i < k - 1) {         max1[i] = 0;       } else {         max1[i] = max(max1[i - 1], get(i + 1 - k, i));       }     }     long long b = -1;     for (long long i = 0; i < n; i++) {       if (i < 2 * k - 1) {         max2[i] = 0;       } else {         max2[i] = max(max2[i - 1], get(i + 1 - k, i) + max1[i - k]);         ;       }     }     long long i = n - 1;     while (i >= 0) {       if (max2[i - 1] >= get(i + 1 - k, i) + max1[i - k]) {         i--;       } else {         b = i + 1 - k;         break;       }     }     long long se = max2[n - 1] - get(b, b + k - 1);     for (long long i = 0; i < n; i++) {       if (get(i, i + k - 1) == se) {         cout << i + 1 <<    ;         cout << b + 1 <<   n ;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 9223000000000000000;   struct DATA {     long long v;     long long c;     long double p;   };   long long n, l;   DATA data[31];   bool cmp(DATA x, DATA y) { return x.p < y.p; }   void init() {     scanf( %lld%lld , &n, &l);     for (int i = 1; i <= n; i++) {       scanf( %lld , &data[i].c);       data[i].v = pow(2, i - 1);       data[i].p = (long double)data[i].c / data[i].v;     }     sort(data + 1, data + n + 1, cmp);   }   long long process(long long left) {     long long ans = maxn;     if (left == 0) return 0;     for (int i = 1; i <= n; i++) {       if (data[i].v >= left) ans = min(ans, data[i].c);     }     int id = -1;     for (int i = 1; i <= n; i++)       if (data[i].v < left) {         id = i;         break;       }     if (id != -1) {       long long sum = 0;       long long k = left / data[id].v;       sum = k * data[id].c + process(left - k * data[id].v);       ans = min(ans, sum);     }     return ans;   }   int main() {     init();     printf( %lld , process(l));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &item) {     out <<  (  << item.first <<  ,   << item.second <<  ) ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (const auto &item : v) out << item <<    ;     return out;   }   int x[2][2], y[2][2];   void mul(int a[2][2], int b[2][2], int c[2][2], int mod) {     for (int i = 0; i < 2; ++i)       for (int j = 0; j < 2; ++j)         c[i][j] = (1LL * a[i][0] * b[0][j] + 1LL * a[i][1] * b[1][j]) % mod;   }   void pw(ll exp, int mod) {     int aux[2][2];     y[0][0] = y[1][1] = 1 % mod;     y[0][1] = y[1][0] = 0;     for (; exp; exp >>= 1) {       if (exp & 1) {         mul(x, y, aux, mod);         memcpy(y, aux, sizeof aux);       }       mul(x, x, aux, mod);       memcpy(x, aux, sizeof aux);     }   }   int fib(ll n, int mod) {     if (n <= 2) return 1 % mod;     x[0][0] = 0;     x[0][1] = x[1][0] = x[1][1] = 1 % mod;     pw(n - 1, mod);     return (y[0][0] + y[1][0]) % mod;   }   ll l, r, k;   ll collect(ll n) {     if (n == 0) return 0;     ll kk, res = 0;     for (ll x = 1; x * x <= n; ++x) {       if (r / x - (l - 1) / x >= k) res = max(res, x);       kk = n / x;     }     for (; kk; --kk) {       ll x = n / kk;       if (r / x - (l - 1) / x >= k) res = max(res, x);     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     ll mod;     cin >> mod >> l >> r >> k;     ll ans = collect(l - 1);     ans = max(ans, collect(r));     cout << fib(ans, mod) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       long long a[100001];       long long y = 0;       long long thissum = 0, maxsum = 0;       int count = 1;       for (int i = 0; i < n; i++) {         scanf( %lld , &a[i]);         y += a[i];       }       thissum = a[0];       maxsum = a[0];       int temp = 1;       for (int i = 1; i < n; i++) {         if (thissum > 0) {           thissum += a[i];           temp++;         } else {           thissum = a[i];           temp = 1;         }         if (thissum > maxsum) {           maxsum = thissum;           count = temp;         }       }       int flag;       if (y > maxsum) {         flag = 1;       } else {         if (y == maxsum && count == n) {           maxsum = maxsum - min(a[0], a[n - 1]);           if (y > maxsum) {             flag = 1;           } else {             flag = 0;           }         } else {           flag = 0;         }       }       if (flag == 1) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       long long x, y;       cin >> x >> y;       if (x == y + 1) {         cout <<  NO n ;       } else {         cout <<  YES n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int recpow(long long int base, long long int exp) {     long long int result = 1;     while (exp > 0) {       if (exp & 1) result = ((long long int)result * base) % 1000000007;       base =           ((long long int)(base % 1000000007) * (base % 1000000007)) % 1000000007;       exp >>= 1;     }     return (result % 1000000007);   }   bool comp(const pair<long long int, long long int>& a,             const pair<long long int, long long int>& b) {     return ((a.first == b.first and a.second > b.second) or a.first < b.first);   }   bool chk(long long int p, vector<pair<long long int, long long int>>& v) {     int n = v.size();     long long int i = 0;     while (i < n) {       if (p < v[i].first) return 0;       p += v[i].second;       i++;     }     return 1;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int tc = 1;     while (tc--) {       long long int n, m;       cin >> n >> m;       vector<long long int> dp(n + 1, 0), pref(n + 1, 0);       dp[1] = 1, pref[1] = 1;       for (long long int i = 2; i < n + 1; i++) {         dp[i] = (dp[i] + pref[i - 1]) % m;         for (long long int j = 1; j * j <= i; ++j) {           long long int tmp = i / j - i / (j + 1);           dp[i] = (dp[i] + (tmp * dp[j]) % m) % m;         }         for (long long int j = 2; j * j <= i; ++j) {           long long int tmp = i / j;           if (tmp * tmp > i) {             dp[i] = (dp[i] + dp[tmp]) % m;           }         }         pref[i] = (pref[i - 1] + dp[i]) % m;       }       cout << dp[n] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int N;   vector<int> adj[MAXN];   map<int, int> dp[MAXN];   int cid;   map<vector<int>, int> idmp;   int getid(vector<int> v) {     if (idmp.count(v)) {       return idmp[v];     }     return idmp[v] = cid++;   }   int dfs(int x, int p);   vector<int> getv(int x, int p) {     vector<int> v;     for (int y : adj[x]) {       if (y == p) {         continue;       }       v.push_back(dfs(y, x));     }     sort((v).begin(), (v).end());     return v;   }   int dfs(int x, int p) {     if (dp[x].count(p)) {       return dp[x][p];     }     return dp[x][p] = getid(getv(x, p));   }   int main() {     idmp[vector<int>()] = cid++;     scanf( %d , &N);     for (int i = 1; i < N; i++) {       int a, b;       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 1; i <= N; i++) {       for (int j : adj[i]) {         dfs(j, i);       }     }     set<vector<int>> st;     for (int i = 1; i <= N; i++) {       if (adj[i].size() < 4) {         st.insert(getv(i, -1));       }     }     printf( %lu n , st.size());   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int t = 1;     while (t--) {       int n;       cin >> n;       map<int, vector<int>> m;       vector<int> v(n);       for (int i = 0; i < n; i++) {         cin >> v[i];         m[v[i]].push_back(i);       }       vector<pair<int, int>> res;       for (auto p : m) {         vector<int> tmp = p.second;         if (tmp.size() == 1) {           res.push_back(make_pair(p.first, 0));           continue;         }         int d = tmp[1] - tmp[0];         int flag = 0;         for (int i = 1; i < tmp.size() - 1; i++) {           int curr = tmp[i + 1] - tmp[i];           if (curr != d) {             flag = 1;             break;           }         }         if (flag == 1) {           continue;         }         res.push_back(make_pair(p.first, d));       }       sort((res).begin(), (res).end());       cout << res.size() << endl;       for (auto p : res) {         cout << p.first <<     << p.second << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t0 = 0, t1 = 0, a[200009], h = 100000, mx = 0;   string s;   void f(char x) {     if (x ==  0 )       t0++;     else       t1++;   }   int main() {     cin >> n >> s;     for (int i = 0; i < n; i++) {       f(s[i]);       a[100000 + t1 - t0] = i;       if (t0 == t1) mx = i + 1;     }     for (int i = 1; i < n; i++) {       if (s[i - 1] ==  0 )         h--;       else         h++;       if (a[h] != 0) mx = max(mx, a[h] - i + 1);     }     cout << mx;   }
#include <bits/stdc++.h>   using namespace std;   namespace Flandre_Scarlet {   long long mod;   class Matrix {    private:     long long a[5][5];       public:     long long n;     Matrix() {       memset(a, 0, sizeof(a));       n = 0;     }     Matrix(long long _n) {       memset(a, 0, sizeof(a));       n = _n;     }     Matrix(long long _n, long long _x) {       _x %= mod;       n = _n;       for (long long i = 0; i < 5; ++i) {         for (long long j = 0; j < 5; ++j) {           a[i][j] = _x;         }       }     }     long long* operator[](long long i) { return *(a + i); }     void Set(long long x) {       x %= mod;       for (long long i = 0; i < 5; ++i) {         for (long long j = 0; j < 5; ++j) {           a[i][j] = x;         }       }     }     void Identity() {       memset(a, 0, sizeof(a));       for (long long i = 0; i < 5; ++i) {         a[i][i] = 1;       }     }   };   Matrix operator*(Matrix x, Matrix y) {     Matrix ans(x.n, 0);     long long n = ans.n;     for (long long i = 1; i <= n; ++i) {       for (long long j = 1; j <= n; ++j) {         for (long long k = 1; k <= n; ++k) {           ans[i][j] += x[i][k] * y[k][j];           ans[i][j] %= mod;         }       }     }     return ans;   }   Matrix operator^(Matrix x, long long p) {     Matrix ans(x.n, 1);     ans.Identity();     while (p) {       if (p & 1) ans = ans * x;       x = x * x, p >>= 1;     }     return ans;   }   long long Fib(long long x) {     Matrix Init(2, 0);     Init[1][1] = 0, Init[1][2] = 1;     Matrix Trans(2, 1);     Trans[1][1] = 0;     Matrix Ans = Init * (Trans ^ x);     return Ans[1][1];   }   long long l, r, k;   void R1(long long& x) {     x = 0;     char c = getchar();     long long f = 1;     while (c <  0  or c >  9 ) f = (c ==  - ) ? -1 : 1, c = getchar();     while (c >=  0  and c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     x = (f == 1) ? x : -x;   }   void Input() {     R1(mod);     R1(l), R1(r), R1(k);   }   bool cxk(long long x) { return (r / x - (l - 1) / x) >= k; }   void Soviet() {     long long ans = -0x3f3f3f3f;     for (long long i = 1; i * i <= r; ++i) {       if (cxk(i)) ans = max(ans, i);       if (cxk(r / i)) ans = max(ans, r / i);     }     printf( %lld n , Fib(ans));   }   void IsMyWife() {     Input();     Soviet();   }   }  // namespace Flandre_Scarlet   int main() {     Flandre_Scarlet::IsMyWife();     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int grid[201][201]{0};   int main() {     string s;     cin >> s;     int x = 100;     int y = 100;     grid[x][y] = true;     for (auto& it : s) {       switch (it) {         case  L :           x--;           break;         case  R :           x++;           break;         case  U :           y--;           break;         case  D :           y++;       }       if (grid[x][y] || (it !=  L  && grid[x + 1][y]) ||           (it !=  R  && grid[x - 1][y]) || (it !=  U  && grid[x][y + 1]) ||           (it !=  D  && grid[x][y - 1])) {         cout <<  BUG  << endl;         return 0;       }       grid[x][y] = true;     }     cout <<  OK  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, _m, ans = 0;   map<string, int> m;   string s[1010], u[1010], v[1010];   int main() {     cin >> n >> _m;     for (int i = 1; i <= n; i++) cin >> s[i];     sort(s + 1, s + n + 1);     for (int i = 1; i <= n; i++) m[s[i]] = i - 1;     for (int i = 1; i <= _m; i++) cin >> u[i] >> v[i];     for (int i = 1; i <= (1 << n); i++) {       bool flag = 1;       for (int j = 1; j <= _m; j++)         if (((i - 1) & (1 << m[u[j]])) && ((i - 1) & (1 << m[v[j]]))) flag = 0;       if (flag && __builtin_popcount(ans) < __builtin_popcount(i - 1))         ans = i - 1;     }     cout << __builtin_popcount(ans) <<   n ;     for (int i = 1; i <= n; i++)       if (ans & (1 << (i - 1))) cout << s[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int N = 1e5 + 1;   vector<int> co[N];   long long ans = 0;   void dfs(int x, int p) {     ans += (int)co[x].size() * ((int)co[x].size() - 1) / 2;     for (auto y : co[x]) {       if (y == p) continue;       dfs(y, x);     }   }   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       co[a].push_back(b);       co[b].push_back(a);     }     dfs(1, 0);     cout << ans;   }