malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   template <class T>   int gmax(T &a, T b) {     if (b > a) {       a = b;       return 1;     }     return 0;   }   template <class T>   int gmin(T &a, T b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int MAXN = 2e5 + 5;   const int MOD = 998244353;   int a[MAXN];   int b[MAXN];   int id[MAXN];   long long cnt[MAXN];   int cmp(int x, int y) { return cnt[x] > cnt[y]; }   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 0; i < n; ++i) scanf( %d , &a[i]);       for (int i = 0; i < n; ++i) scanf( %d , &b[i]);       sort(b, b + n);       for (int i = 0; i < n; ++i) {         id[i] = i;         cnt[i] = 1ll * (i + 1) * (n - i) * a[i];       }       sort(id, id + n, cmp);       long long result = 0;       for (int i = 0; i < n; ++i) {         result = (result + cnt[id[i]] % MOD * b[i] % MOD) % MOD;       }       printf( %lld n , result);     }     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int a[100][5], n, i, j, k = 0, min = 10000;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d%d%d , &a[i][0], &a[i][1], &a[i][2], &a[i][3]);       a[i][4] = i + 1;     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (a[j][0] > a[i][0] && a[j][1] > a[i][1] && a[j][2] > a[i][2]) {           a[i][3] = 10000;         }       }       if (a[i][3] < min) {         min = a[i][3];         k = a[i][4];       }     }     printf( %d , k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[2210], b[2210];   long long inf = 1e13;   int main() {     memset(a, 0, sizeof(a));     memset(b, 0, sizeof(b));     int n = 0, k = 0;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %I64d , &a[i]);     }     for (int i = 1; i <= n; ++i) {       scanf( %I64d , &b[i]);     }     long long l = 0, r = inf, res = 0;     while (l <= r) {       long long mid = (l + r) >> 1;       priority_queue<long long, vector<long long>, greater<long long>> qa;       priority_queue<long long> qb;       long long sz = 0, cur = 0;       for (int i = 1; i <= n; ++i) {         qa.push(a[i]);         long long tmp1 = qa.top() + b[i] - mid;         long long tmp2 = qb.empty() ? inf : (b[i] - qb.top());         if (tmp1 <= tmp2 && tmp1 <= 0) {           cur += tmp1;           ++sz;           qb.push(b[i]);           qa.pop();         } else if (tmp2 < tmp1 && tmp2 < 0) {           cur += tmp2;           qb.pop();           qb.push(b[i]);         }       }       if (sz >= k) {         res = cur + (long long)k * mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     printf( %I64d , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int iinf = INT_MAX;   const long long linf = 2e18;   const double dinf = 1e30;   const int MOD = 1000000007;   inline int read() {     int X = 0, w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();     return w ? -X : X;   }   void write(int x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   void print(int x) {     cout << x <<   n ;     exit(0);   }   void PRINT(string x) {     cout << x <<   n ;     exit(0);   }   void douout(double x) { printf( %lf n , x + 0.0000000001); }   long long ans = 1e18, a, b, mx = 1e18;   int main() {     cin >> a >> b;     for (long long i = 1; i * i <= (a + b); i++) {       if (a % i == 0) mx = min(mx, a / i);       if (b % i == 0) mx = min(mx, b / i);       if ((a + b) % i == 0 && (a + b) / i >= mx)         ans = min(ans, 2 * i + 2 * ((a + b) / i));     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, p;       cin >> n >> p;       int cnt = 0;       for (int i = 1; i < n; ++i) {         for (int j = i + 1; j <= n; ++j) {           if (cnt == 2 * n + p) break;           cout << i <<     << j <<   n ;           cnt++;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double getangle(pair<int, int> a, pair<int, int> b) {}   int main() {     int n;     cin >> n;     double arr[n + 1];     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       arr[i] = atan2(x, y);       if (arr[i] < 0) arr[i] += 2.0 * M_PI;       arr[i] *= 180.0 / M_PI;     }     sort(arr, arr + n);     double a = 0.0;     if (n <= 2)       a = min(360.0 - (arr[0] - arr[n - 1] + 360.0),               360.0 - (arr[n - 1] - arr[0]));     else {       a = 360.0 - (arr[0] - arr[n - 1] + 360.0);       for (int i = 0; i < n - 1; ++i) a = min(a, 360.0 - (arr[i + 1] - arr[i]));     }     printf( %.8lf n , a);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string aux;     cin >> aux;     int flag_Invalid_Input = 0;     int memo[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};     int counter = 0;     int len = aux.size();     int i, j;     for (i = 0; i < len; i++) {       if (aux[i] >  1 ) {         for (j = 0; j < len - i; j++) {           counter += memo[j];         }         break;       }       if (aux[i] ==  1 ) {         counter += memo[len - i - 1];       }     }     cout << counter;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 210010;   const int mod = 1e9 + 7;   int dp[110][maxn], sum[maxn];   int a, b, k, t;   int main() {     scanf( %d%d%d%d , &a, &b, &k, &t);     dp[0][0] = 1;     for (int i = 1; i <= t; i++) {       for (int j = 0; j < maxn; j++)         sum[j] = ((j > 0 ? sum[j - 1] : 0) + dp[i - 1][j]) % mod;       for (int j = 0; j < maxn; j++)         dp[i][j] =             (sum[j] - (j - 2 * k - 1 >= 0 ? sum[j - 2 * k - 1] : 0) + mod) % mod;     }     for (int i = 0; i < maxn; i++) {       sum[i] = ((i > 0 ? sum[i - 1] : 0) + dp[t][i]) % mod;     }     int ans = 0;     for (int i = 0; i <= 2 * k * t; i++) {       (ans += (1LL) * dp[t][i] * (i + a - b - 1 < 0 ? 0 : sum[i + a - b - 1]) %               mod) %= mod;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void dfs(long long n, long long i,            unordered_map<long long, vector<long long>> &adj, vector<bool> &vis,            vector<long long> &a1, vector<long long> &a2) {     if (vis[n]) return;     vis[n] = true;     if (i == 0)       a1.push_back(n);     else       a2.push_back(n);     for (auto &it : adj[n]) {       if (!vis[it]) dfs(it, i ^ 1, adj, vis, a1, a2);     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       unordered_map<long long, vector<long long>> adj;       vector<bool> vis(n + 1, false);       vector<long long> a1, a2;       for (long long i = 0; i < m; i++) {         long long x, y;         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       queue<pair<long long, long long>> q;       q.push({1, 0});       while (q.size() > 0) {         auto it = q.front();         q.pop();         long long x, y;         tie(x, y) = it;         if (vis[x]) continue;         vis[x] = true;         if (y == 0)           a1.push_back(x);         else           a2.push_back(x);         for (auto &it : adj[x]) {           if (!vis[it]) q.push({it, y ^ 1});         }       }       if (a1.size() <= a2.size()) {         cout << a1.size() <<   n ;         for (auto x : a1) cout << x <<    ;         cout << endl;         ;       } else {         cout << a2.size() <<   n ;         for (auto x : a2) cout << x <<    ;         cout << endl;         ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1);   struct Point {     long long x, y, r;     Point() {}     Point(long long a, long long b, long long c) {       x = a;       y = b;       r = c;     }   };   long double rad;   long double cor(long double angle) {     if (angle < 0) {       return angle + 2 * PI;     }     return angle;   }   pair<long double, long double> fnd(Point& p) {     long double kor = sqrt(p.x * p.x + p.y * p.y);     if (kor > rad + p.r) {       return {20, 20};     }     if (rad - p.r > kor) {       return {20, 20};     } else {       long double an1 =           acos((rad * rad + p.x * p.x + p.y * p.y - p.r * p.r) / (2 * rad * kor));       long double tmp = sqrt(p.x * p.x + p.y * p.y - p.r * p.r);       long double l = cor(atan2(p.y, p.x));       return {l - an1, l + an1};     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long double d;     long long n;     cin >> n;     cin >> d;     rad = 0;     vector<Point> sp(n);     long long x, y, r;     for (long long i = 0; i < n; ++i) {       cin >> x >> y >> r;       sp[i].x = x;       sp[i].y = y;       sp[i].r = r;     }     vector<pair<long double, long long> > al(0);     for (long long kol = 0; kol < 2850; ++kol) {       rad += d;       for (long long i = 0; i < n; ++i) {         pair<long double, long double> now = fnd(sp[i]);         if (now.first == 20) {           continue;         } else if (now.first == 30) {           continue;         } else if (now.first < 0 && now.second > 0) {           al.push_back({cor(now.first), 0});           al.push_back({2 * PI, 1});           al.push_back({0, 0});           al.push_back({now.second, 1});         } else if (now.second > 2 * PI) {           al.push_back({now.first, 0});           al.push_back({2 * PI, 1});           al.push_back({0, 0});           al.push_back({now.second - 2 * PI, 1});         } else {           al.push_back({now.first, 0});           al.push_back({now.second, 1});         }       }     }     sort(al.begin(), al.end());     long long now = 0;     long long mx = 0;     for (auto p : al) {       if (p.second == 0) {         ++now;       } else {         --now;       }       mx = max(mx, now);     }     cout << mx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int maxn = n * n - 1;     int c = 0;     for (int i = 0; i <= maxn; i++) {       if (i % 2 == 0) {         cout << i <<    ;         c++;       }       if (c == n) {         cout << endl;         c = 0;       }     }     for (int i = 0; i <= maxn; i++) {       if (i % 2 == 1) {         cout << i <<    ;         c++;       }       if (c == n) {         cout << endl;         c = 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, x, i, sum, j, r = 1, B[20][20];   char A[20][20];   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> x;       sum += x;     }     if (sum == 0)       cout << 0;     else {       if (abs(sum) <= m)         cout <<  1 ;       else         cout << (abs(sum) / m) + (abs(sum) % m != 0);     }     return 0;   }
#include <bits/stdc++.h>   template <class T>   int gmax(T &a, T b) {     if (b > a) {       a = b;       return 1;     }     return 0;   }   template <class T>   int gmin(T &a, T b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int MAXN = 2e5 + 5;   int X[MAXN];   int solve(int x, int y) {     if (x > y)       return y;     else if (x == y)       return 0;     else       return y - 1;   }   int has[MAXN];   int main() {     int n, m;     while (~scanf( %d %d , &n, &m)) {       memset(has, 0, sizeof(has));       map<int, long long> m1;       map<int, long long> m2;       map<int, int> m3;       long long tmp = 0;       for (int i = 0; i < m; ++i) {         scanf( %d , &X[i]);       }       for (int i = 1; i < m; ++i) {         if (X[i] == X[i - 1]) continue;         tmp += abs(X[i] - X[i - 1]);         m1[X[i]] += abs(X[i] - X[i - 1]);         m1[X[i - 1]] += abs(X[i] - X[i - 1]);         m2[X[i]] += solve(X[i], X[i - 1]);         m2[X[i - 1]] += solve(X[i - 1], X[i]);         m3[X[i]]++;         m3[X[i - 1]]++;         int t1 = X[i];         int t2 = X[i - 1];         if (t1 > t2) swap(t1, t2);         has[t1]++;         has[t2 + 1]--;       }       for (int i = 1; i <= n; ++i) has[i] += has[i - 1];       vector<long long> result;       result.push_back(tmp);       for (int i = 2; i <= n; ++i) {         long long tmp2 = tmp - m1[i];         result.push_back(tmp2 + m2[i] - (has[i] - m3[i]));       }       for (int i = 0; i < n; ++i) {         if (i) printf(   );         printf( %lld , result[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2005;   struct Point {     long long x, y;     Point() {}     Point(long long x, long long y) : x(x), y(y) {}     bool operator<(const Point& rhs) const {       if (y != rhs.y)         return y < rhs.y;       else         return x < rhs.x;     }   };   Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }   Point operator*(Point v, long long mul) { return Point(v.x * mul, v.y * mul); }   long long cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }   int n;   Point p[MAXN];   inline long long C(long long x) { return x * (x - 1) / 2; }   long long calc(Point o, vector<pair<Point, int> >& v) {     sort(v.begin(), v.end(),          [&o](const pair<Point, int>& a, const pair<Point, int>& b) -> bool {            return cross(a.first - o, b.first - o) < 0;          });     long long cnt[2] = {0}, ret = 0;     for (auto& i : v) cnt[i.second]++;     for (auto& i : v) {       cnt[i.second]--;       ret += C(cnt[0]) * C(cnt[1]);       cnt[i.second ^ 1]++;     }     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld%lld , &p[i].x, &p[i].y);     long long ans = 0;     for (int i = 0; i < n; i++) {       vector<pair<Point, int> > v;       for (int j = 0; j < n; j++)         if (j != i) {           if (p[i] < p[j])             v.emplace_back(p[j], 1);           else             v.emplace_back(p[i] * 2 - p[j], 0);         }       ans += calc(p[i], v);     }     ans /= 2;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using VI = vector<int>;   const int NN = 200011;   int a[NN], b[NN], arr[NN];   VI vec[NN], cyc[NN];   int nc;   int dp[NN], vst[NN];   int n, s;   void dfs(int u) {     while (not vec[u].empty()) {       int v = vec[u].back();       vec[u].pop_back();       dfs(a[v]);       cyc[nc].push_back(v);     }   }   int solve() {     cin >> n >> s;     for (int i = 1; i <= n; i++) scanf( %d , a + i), arr[i] = a[i], dp[i] = i;     sort(arr + 1, arr + n + 1);     int m = unique(arr + 1, arr + n + 1) - arr - 1;     for (int i = 1; i <= n; i++) {       b[i] = a[i] = lower_bound(arr + 1, arr + m + 1, a[i]) - arr;     }     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++)       if (a[i] ^ b[i]) {         vec[b[i]].push_back(i);       }     for (int i = 1; i <= m; i++) {       if (not vec[i].empty()) {         dfs(i);         int r = ((int)cyc[nc].size());         for (int j = 0; j < r; j++) {           dp[cyc[nc][(j + 1) % r]] = cyc[nc][j];           s--;         }         nc++;       }       if (s < 0) return puts( -1 );     }     s = min(s, nc);     if (s >= 2) {       cout << nc - s + 2 << endl;       cout << s << endl;       for (int i = 0; i < s; i++) printf( %d  , cyc[i][0]);       puts(  );       int tmp = dp[cyc[s - 1][0]];       for (int i = s; --i;) {         dp[cyc[i][0]] = dp[cyc[i - 1][0]];       }       dp[cyc[0][0]] = tmp;     } else       cout << nc << endl;     for (int i = 1; i <= n; i++) {       if (dp[i] == i or vst[i]) continue;       VI ans;       for (int u = i; not vst[u];) {         ans.push_back(u);         vst[u] = 1;         u = dp[u];       }       printf( %d n , ans.size());       for (int u : ans) printf( %d  , u);       puts(  );     }   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   long long int n, i, j, t, ans, arr[3009], crr[3009][3009];   int main() {     scanf( %lld , &t);     while (t--) {       scanf( %lld , &n);       ans = 0;       for (i = 1; i <= n; i++) scanf( %lld , &arr[i]);       for (i = n; i >= 1; i--) {         for (j = i - 1; j >= 1; j--) {           ans += crr[arr[i]][arr[j]];         }         for (j = i + 1; j <= n; j++) {           crr[arr[j]][arr[i]]++;         }       }       printf( %lld n , ans);       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) crr[i][j] = 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b, one, two;     string a;     one = 0;     two = 0;     cin >> n >> a;     for (b = 0; b < n; b++) {       if (a[b] ==  1 ) {         one++;       } else {         two++;       }     }     if (one > two) {       cout << one - two;     } else {       cout << two - one;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[2000000];   int dem;   int maxa;   int dp[10000001];   void mmax(int &a, int b) { a = max(a, b); }   bool ok(int len) {     for (int i = 0; i <= maxa; i++) dp[i] = 0;     dp[len] = 1;     for (int i = len + 1; i <= maxa; i++) {       mmax(dp[i], dp[i - 1]);       mmax(dp[i], dp[i >> 1] + dp[(i + 1) >> 1]);     }     long long sum = 0;     for (int i = 1; i <= n; i++) sum += dp[a[i]];     return sum >= k;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i], maxa = max(maxa, a[i]);     int d = 1, c = 10000000, g, fin = -1;     while (d <= c) {       g = (d + c) / 2;       if (ok(g)) {         fin = g;         d = g + 1;       } else         c = g - 1;     }     cout << fin;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long> mp1, mp2;   long long n, x, yy, c;   vector<pair<int, int>> v;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> yy;       v.push_back({x, yy});       mp1[x + yy]++;       mp2[x - yy]++;     }     for (int i = 0; i < n; i++) {       x = v[i].first;       yy = v[i].second;       c += mp1[x + yy];       c += mp2[x - yy];       c -= 2;     }     cout << c / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   int nowarn;   int n, m;   namespace Tree {   int head[MAXN], nxt[MAXN], to[MAXN], eidx;   void init() {     eidx = 0;     memset(head, -1, sizeof(head));   }   void adde(int u, int v) { to[eidx] = v, nxt[eidx] = head[u], head[u] = eidx++; }   }  // namespace Tree   namespace DFN {   int dfn[MAXN], dfn_cnt, son[MAXN], dep[MAXN], top[MAXN], size[MAXN], pa[MAXN];   void dfs1(int u, int fa, int d) {     using namespace Tree;     pa[u] = fa, dep[u] = d, son[u] = 0, size[u] = 1;     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       dfs1(v, u, d + 1);       size[u] += size[v];       if (size[v] > size[son[u]]) son[u] = v;     }   }   void dfs2(int u, int tp) {     using namespace Tree;     top[u] = tp, dfn[u] = ++dfn_cnt;     if (son[u]) dfs2(son[u], tp);     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       if (v == son[u]) continue;       dfs2(v, v);     }   }   void prelude() {     size[0] = dfn_cnt = 0;     dfs1(1, 0, 1);     dfs2(1, 1);   }   int lca(int u, int v) {     while (top[u] != top[v]) {       if (dep[top[u]] < dep[top[v]]) swap(u, v);       u = pa[top[u]];     }     return min(u, v);   }   }  // namespace DFN   int lowbit(int x) { return x & (-x); }   struct BIT {     long long c[MAXN];     void init() { memset(c, 0, sizeof(c)); }     void add(int p, long long v) {       for (; p <= n; p += lowbit(p)) c[p] += v;     }     long long sum(int p) const {       long long s = 0;       for (; p; p -= lowbit(p)) s += c[p];       return s;     }     long long sum(int l, int r) const { return sum(r) - sum(l - 1); }   };   struct Triple {     int first, second, val;     Triple() {}     Triple(int a, int b, int c) : first(a), second(b), val(c) {}   };   vector<Triple> chain[MAXN];   BIT sf, sg;   long long query(int u, int v, const BIT &bit) {     using namespace DFN;     long long s = 0;     while (top[u] != top[v]) {       s += bit.sum(dfn[top[v]], dfn[v]);       v = pa[top[v]];     }     s += bit.sum(dfn[u], dfn[v]);     return s;   }   long long f[MAXN], g[MAXN];   void dp(int u) {     using namespace Tree;     using namespace DFN;     g[u] = 0;     for (int i = head[u]; ~i; i = nxt[i]) dp(to[i]), g[u] += f[to[i]];     sg.add(dfn[u], g[u]);     f[u] = g[u];     for (int i = 0; i < (int)chain[u].size(); ++i) {       Triple tp = chain[u][i];       int s = tp.first, t = tp.second, w = tp.val;       if (t == u) swap(s, t);       if (s == u) {         f[u] = max(f[u], query(u, t, sg) - query(u, t, sf) + w);       } else {         f[u] = max(f[u], query(u, s, sg) + query(u, t, sg) - g[u] -                              query(u, s, sf) - query(u, t, sf) + w);       }     }     sf.add(dfn[u], f[u]);   }   int main() {     nowarn = scanf( %d%d , &n, &m);     Tree::init();     for (int i = 2; i <= n; ++i) {       int p;       nowarn = scanf( %d , &p);       Tree::adde(p, i);     }     DFN::prelude();     while (m--) {       int u, v, w;       nowarn = scanf( %d%d%d , &u, &v, &w);       int lca = DFN::lca(u, v);       chain[lca].push_back(Triple(u, v, w));     }     sf.init(), sg.init();     dp(1);     printf( %lld n , f[1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s = 1, i;     cin >> n;     int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == s) {         s++;       }     }     cout << s - 1 << endl;     s = 1;     for (i = 0; i < n; i++) {       if (a[i] == s) {         cout << i + 2001 <<    ;         s++;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     long long broj = 3;     int i;     for (i = 0; i < 3 * n - 1; i++) {       broj *= 3;       broj %= 1000000007;     }     long long broj1 = 7;     for (i = 0; i < n - 1; i++) {       broj1 *= 7;       broj1 %= 1000000007;     }     cout << (broj - broj1 + 1000000007) % 1000000007 <<   n ;     return 0;   }