malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long side[300001];   vector<long long> edges[300001];   bool vis[300001];   bool res = 1;   map<long long, long long> mp;   long long dfs(long long u, long long s) {     vis[u] = 1;     side[u] = s;     ++mp[s];     long long ret = 1;     for (long long i = 0; i < edges[u].size(); ++i) {       long long nxt = edges[u][i];       if (vis[nxt] && side[u] == side[nxt]) {         res = 0;       } else if (!vis[nxt]) {         ret += dfs(nxt, -s);       }     }     return ret;   }   int32_t main() {     cin >> n >> m;     for (long long i = 0; i < m; ++i) {       long long a, b;       cin >> a >> b;       edges[a].emplace_back(b);       edges[b].emplace_back(a);     }     long long big = 0;     long long cnt = 0;     for (long long i = 1; i <= n; ++i) {       if (vis[i]) continue;       long long x = dfs(i, i);       if (x == 2) ++cnt;       big = max(big, x);     }     if (big == 1) {       cout <<  3   << n * (n - 1) * (n - 2) / 6 <<   n ;     } else if (big == 2) {       cout <<  2   << cnt * (n - 2) <<   n ;     } else if (res == 1) {       long long ans = 0;       for (auto it = mp.begin(); it != mp.end(); ++it) {         long long x = (*it).second;         ans += x * (x - 1) / 2;       }       cout <<  1   << ans <<   n ;     } else {       cout <<  0 1 n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 112345;   long long l[MAXN], r[MAXN];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) scanf( %lld %lld , l + i, r + i);     sort(l, l + n);     sort(r, r + n);     long long ans = n;     for (int i = 0; i < n; ++i) ans += max(l[i], r[i]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMax = 5e3 + 5;   const int MMax = 1e3 + 5;   int N, M;   char input[NMax][MMax + 101];   short bit[NMax][MMax][2];   char solMin[MMax], solMax[MMax];   map<string, int> ID;   struct elem {     bool known;     int op1, op2;     char tor;   } v[NMax];   int compute(int, int, int);   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     cin >> N >> M;     cin.getline(input[0], MMax + 100);     for (int i = 1; i <= N; ++i) {       cin.getline(input[i] + 1, MMax + 100);       string name =   ;       int j = 1;       while ( a  <= input[i][j] && input[i][j] <=  z ) {         name += input[i][j++];       }       ID[name] = i;     }     for (int i = 1; i <= N; ++i) {       int j = 1;       while (input[i][j] !=  = ) {         ++j;       }       j += 2;       if (input[i][j] ==  0  || input[i][j] ==  1 ) {         v[i].known = true;         for (int k = 1; k <= M; ++k) {           bit[i][k][0] = bit[i][k][1] = input[i][j] -  0  + 1;           ++j;         }       } else {         string str;         if (input[i][j] ==  ? ) {           v[i].op1 = -1;           ++j;         } else {           str =   ;           while ( a  <= input[i][j] && input[i][j] <=  z ) {             str += input[i][j];             ++j;           }           v[i].op1 = ID[str];         }         ++j;         if (input[i][j] ==  A ) {           v[i].tor =  & ;           j += 3;         } else if (input[i][j] ==  O ) {           v[i].tor =  | ;           j += 2;         } else {           v[i].tor =  ^ ;           j += 3;         }         ++j;         if (input[i][j] ==  ? ) {           v[i].op2 = -1;         } else {           str =   ;           while ( a  <= input[i][j] && input[i][j] <=  z ) {             str += input[i][j];             ++j;           }           v[i].op2 = ID[str];         }       }     }     for (int b = 1; b <= M; ++b) {       int nr1By1 = 0, nr1By0 = 0;       for (int i = 1; i <= N; ++i) {         nr1By1 += compute(i, b, 1);         nr1By0 += compute(i, b, 0);       }       if (nr1By1 > nr1By0) {         solMax[b] =  1 ;       } else {         solMax[b] =  0 ;       }       if (nr1By1 < nr1By0) {         solMin[b] =  1 ;       } else {         solMin[b] =  0 ;       }     }     cout << (solMin + 1) <<   n  << (solMax + 1);     return 0;   }   int compute(int id, int b, int val) {     if (bit[id][b][val] != 0) {       return bit[id][b][val] - 1;     }     int f1, f2;     if (v[id].op1 == -1) {       f1 = val;     } else {       f1 = compute(v[id].op1, b, val);     }     if (v[id].op2 == -1) {       f2 = val;     } else {       f2 = compute(v[id].op2, b, val);     }     int res;     if (v[id].tor ==  & ) {       res = f1 & f2;     } else if (v[id].tor ==  | ) {       res = f1 | f2;     } else {       res = f1 ^ f2;     }     bit[id][b][val] = res + 1;     return res;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100005] = {0}, b[100005] = {0}, t, j, i, rn = 0, r[100005] = {0},          dis[100005] = {0};   vector<int> v;   vector<int> ht;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] == 1) ht.push_back(i);     }     for (i = 1; i <= n; i++) {       scanf( %d , &b[i]);       dis[b[i]]++;     }     for (i = 0; i < ht.size(); i++) {       v.clear();       v.push_back(ht[i]);       while (1) {         t = v.size();         if (b[v[t - 1]] == 0) {           break;         }         if (dis[b[v[t - 1]]] == 1)           v.push_back(b[v[t - 1]]);         else           break;       }       if (rn < v.size()) {         rn = v.size();         for (j = 0; j < rn; j++) r[j] = v[j];       }     }     printf( %d n , rn);     for (i = rn - 1; i >= 0; i--) printf( %d%c , r[i], i ?     :   n );     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int *mas = new int[n], m = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &mas[m++]);       while (m > 1 && mas[m - 1] == mas[m - 2]) {         mas[m - 2]++;         m--;       }     }     printf( %d n , m);     for (int i = 0; i < m; i++) printf( %d  , mas[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 101000;   const double eps = 1e-9, g = 9.8;   double V, angle, ca, sa, Y, K, x, y;   int i, j, k, l, m, n, o, p;   inline int sn(double x) { return x < -eps ? -1 : x > eps ? 1 : 0; }   inline double Sqr(double x) { return x * x; }   struct Point {     double x, y;     inline void read() { scanf( %lf%lf , &x, &y); }     bool operator<(const Point &t) const { return x < t.x; }   } wall[N], ans[N];   struct fire {     double a, b;     int i;     fire() {}     fire(double x, double y, int id) {       a = x;       b = y;       i = id;     }     inline void read(int id) {       scanf( %lf , &angle);       ca = cos(angle);       sa = sin(angle);       a = g / (2 * Sqr(V * ca));       b = sa / ca;       i = id;       ans[i].x = (b / a);       ans[i].y = 0;     }     bool operator<(const fire &t) const {       double b1 = b - K * a, b2 = t.b - K * t.a;       return (b1 < b2) || (!sn(b1 - b2) && (i < t.i));     }   } Tfire, P;   set<fire> F;   set<fire>::iterator pos;   int main() {     scanf( %d%lf , &n, &V);     K = (double)0.455555;     for (i = 1; i <= n; i++) {       Tfire.read(i);       F.insert(Tfire);     }     scanf( %d , &m);     for (i = 1; i <= m; i++) wall[i].read();     sort(wall + 1, wall + m + 1);     for (i = 1; i <= m; i++) {       K = wall[i].x;       Y = wall[i].y / wall[i].x;       while (1) {         pos = F.lower_bound(fire(0, Y + eps, N));         if (pos == F.begin()) break;         pos--;         P = (*pos);         j = P.i;         if (ans[j].x > wall[i].x) {           ans[j].x = wall[i].x;           ans[j].y = (-P.a) * Sqr(wall[i].x) + wall[i].x * P.b;         }         F.erase(pos);       }     }     for (i = 1; i <= n; i++) printf( %.9lf %.9lf n , ans[i].x, ans[i].y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s[500001];   char line[10];   int dp[30][30];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       memset(line, 0, sizeof(line));       scanf( %s , line);       s[i] = line;     }     memset(dp, 0, sizeof(dp));     for (int k = 0; k < n; ++k) {       int len = (int)s[k].size();       int start = s[k][0] -  a , end = s[k][len - 1] -  a ;       for (int i = 0; i < 26; ++i)         if (dp[i][start]) {           dp[i][end] = max(dp[i][end], dp[i][start] + len);         }       dp[start][end] = max(dp[start][end], len);     }     int ret = 0;     for (int i = 0; i < 26; ++i) ret = max(ret, dp[i][i]);     cout << ret << endl;     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--) {       int n;       cin >> n;       long long int a[n], b[n];       long long int sum = 0, suma = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         sum += a[i];       }       for (int i = 0; i < n; i++) {         cin >> b[i];         suma += b[i];       }       long long int mina = *min_element(a, a + n);       long long int mine = *min_element(b, b + n);       long long int ans = 0;       for (int i = 0; i < n; i++) {         ans += min(abs(a[i] - mina), abs(b[i] - mine));         int aoeu = a[i];         a[i] -= min(abs(a[i] - mina), abs(b[i] - mine));         b[i] -= min(abs(aoeu - mina), abs(b[i] - mine));         ans += abs(a[i] - mina);         ans += abs(b[i] - mine);       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int q[200010];   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int l = s.length();       if (l == 1) {         if (s[0] ==  L ) {           cout << 2 << endl;         } else {           cout << 1 << endl;         }         continue;       }       int flag = 0;       for (int i = 0; i < l; i++) {         if (s[i] ==  R ) {           flag = 1;           break;         }       }       if (flag == 0) {         cout << l + 1 << endl;         continue;       }       int k = 1;       q[0] = 0;       for (int i = 0; i < l; i++) {         if (s[i] ==  R ) {           q[k++] = i + 1;         }       }       q[k] = l + 1;       int maxn = 0;       for (int i = 1; i <= k; i++) {         int x = q[i] - q[i - 1];         maxn = max(maxn, x);       }       cout << maxn << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, j, i, l, t, k, x, y;   string s, a[10000001];   int main() {     cin >> n >> s;     for (i = 1; i < n; i++)       for (j = 0; j < n - i; j++) {         t++;         for (l = 0; l <= i; l++) {           a[t] += s[j + l];         }       }     for (i = 1; i <= t; i++) {       x = 0;       y = 0;       for (j = 0; j < a[i].size(); j++)         if (a[i][j] ==  U )           y++;         else if (a[i][j] ==  D )           y--;         else if (a[i][j] ==  L )           x--;         else if (a[i][j] ==  R )           x++;       if (x == 0 && y == 0) k++;     }     cout << k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   int gcd[N];   int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }   vector<int> primes;   void Calc() {     for (int i = 2; i * i <= 1000000000; i++) {       bool is_prime = true;       for (int p : primes) {         if (p * p > i) {           break;         }         is_prime &= i % p != 0;       }       if (is_prime) {         primes.push_back(i);       }     }   }   vector<int> Factorize(int a) {     vector<int> res;     for (int p : primes) {       if (p * p > a) {         break;       }       while (a % p == 0) {         res.push_back(p);         a /= p;       }     }     if (a != 1) {       res.push_back(a);     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     Calc();     int n;     int m;     cin >> n >> m;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     set<int> b;     for (int i = 0; i < m; i++) {       int p;       cin >> p;       b.insert(p);     }     gcd[0] = a[0];     for (int i = 1; i < n; i++) {       gcd[i] = GCD(gcd[i - 1], a[i]);     }     int res = 0;     int t = 1;     for (int i = n - 1; i >= 0; i--) {       auto factors = Factorize(gcd[i] / t);       int d = 0;       for (auto p : factors) {         d += b.count(p) ? 1 : -1;       }       if (d > 0) {         t = gcd[i];         res += d * (i + 1);       }     }     for (auto num : a) {       auto factors = Factorize(num);       int d = 0;       for (auto p : factors) {         d += b.count(p) ? -1 : 1;       }       res += d;     }     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void expand(int);   int main() {     int num;     cin >> num;     expand(num);     cout <<   n ;   }   void expand(int value) {     const char* const ones[20] = { zero ,     one ,        two ,       three ,                                    four ,     five ,       six ,       seven ,                                    eight ,    nine ,       ten ,       eleven ,                                    twelve ,   thirteen ,   fourteen ,  fifteen ,                                    sixteen ,  seventeen ,  eighteen ,  nineteen };     const char* const tens[10] = {  ,        ten ,    twenty ,  thirty ,                                    forty ,   fifty ,  sixty ,   seventy ,                                    eighty ,  ninety };     if (value < 0) {       cout <<  minus  ;       expand(-value);     } else if (value >= 20) {       cout << tens[value / 10];       if (value % 10) {         cout <<  - ;         expand(value % 10);       }     } else {       cout << ones[value];     }     return;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, a[N], ans[N], cnt, x, y;   bool Ok = 0;   int main() {     cin >> n;     for (int i = 0; i <= n; i++) {       cin >> a[i];       if (i) Ok |= (a[i] > 1 && a[i - 1] > 1);     }     if (!Ok) {       cout <<  perfect ;     } else {       cout <<  ambiguous  << endl;       cnt = 1;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= a[i]; j++) {           ans[cnt + j] = cnt;         }         if (a[i] > 1 && a[i - 1] > 1) {           x = cnt + a[i];           y = cnt - 1;         }         cnt += a[i];       }       for (int i = 1; i <= cnt; i++) {         cout << ans[i] <<    ;       }       cout << endl;       ans[x] = y;       for (int j = 1; j <= cnt; j++) {         cout << ans[j] <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int counter = 0;     for (int i = 0; i < n; i++) {       int j = 0;       for (j = i + 1; j < n; j++) {         if (s[j] == s[i])           counter++;         else {           break;         }       }       i = j - 1;     }     cout << counter;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[250];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int N = 250;       for (int j = 0; j < N; j++) scanf( %d , a + j);       double M = 0;       for (int j = 0; j < N; j++) M += a[j];       M /= N;       double v = 0;       for (int j = 0; j < N; j++) v += (a[j] - M) * (a[j] - M);       v /= N;       if (v < 3 * M)         puts( poisson );       else         puts( uniform );     }   }
#include <bits/stdc++.h>   using namespace std;   int bv[7][9] = {{},                   {4},                   {2, 6},                   {2, 4, 6},                   {0, 2, 6, 8},                   {0, 2, 4, 6, 8},                   {0, 2, 3, 5, 6, 8}};   int bh[7][9] = {{},                   {4},                   {0, 8},                   {0, 4, 8},                   {0, 2, 6, 8},                   {0, 2, 4, 6, 8},                   {0, 1, 2, 6, 7, 8}};   int cv[7] = {0};   int ch[7] = {0};   char s[2036][2036];   bool h[2036][2036];   bool v[2036][2036];   int MOD = 1000000007;   int f(int first, int second) {     int res = 0;     int sx = first * 4 + 1, sy = second * 4 + 1;     int pos = 0;     for (int i = (0); i < (int)(3); i++)       for (int j = (0); j < (int)(3); j++) {         if (s[sx + i][sy + j] ==  O ) {           res |= 1 << pos;         }         ++pos;       }     return res;   }   long long doub[536];   long long sing[536];   long long tmp[536];   int main() {     for (int k = (0); k < (int)(7); k++) {       for (int i = (0); i < (int)(k); i++) {         cv[k] |= 1 << bv[k][i];         ch[k] |= 1 << bh[k][i];       }     }     int n, m;     scanf( %d%d , &n, &m);     for (int i = (0); i < (int)(n * 4); i++) scanf( %s , s[i]);     memset(h, 0, sizeof(h));     memset(v, 0, sizeof(v));     for (int i = (0); i < (int)(n); i++)       for (int j = (0); j < (int)(m); j++) {         int cod = f(i, j);         for (int k = (0); k < (int)(7); k++) {           h[i][j] |= ch[k] == cod;           v[i][j] |= cv[k] == cod;         }       }     for (int j = (0); j < (int)(m); j++) {       sing[j] = n % 2 == 0;       for (int i = (0); i < (int)(n); i++) sing[j] &= v[i][j];     }     for (int j = (1); j < (int)(m); j++) {       memset(tmp, 0, sizeof(tmp));       for (int i = (0); i < (int)(n); i++) {         if (i >= 1) {           if (v[i][j - 1] && v[i][j] && v[i - 1][j - 1] && v[i - 1][j]) {             tmp[i] += (i - 2 == -1 ? 1 : tmp[i - 2]);           }         }         if (h[i][j - 1] && h[i][j]) {           tmp[i] += (i - 1 == -1 ? 1 : tmp[i - 1]);         }         tmp[i] %= MOD;       }       doub[j] = tmp[n - 1];       if (sing[j] && sing[j - 1]) {         doub[j] = (doub[j] + MOD - 1) % MOD;       }     }     memset(tmp, 0, sizeof(tmp));     for (int j = (0); j < (int)(m); j++) {       if (j >= 1) {         if (doub[j]) {           tmp[j] += doub[j] * (j == 1 ? 1 : tmp[j - 2]) % MOD;           tmp[j] %= MOD;         }       }       if (sing[j]) {         tmp[j] += sing[j] * (j == 0 ? 1 : tmp[j - 1]) % MOD;         tmp[j] %= MOD;       }     }     printf( %d n , (int)tmp[m - 1]);     return 0;   }
#include <bits/stdc++.h>   #define lo long long   #define KKH  1546C    #define fi first   #define se second   #define BIT(x,k) (((x)>>(k-1))&1)   #define rs(x,a) memset(x,(a),sizeof x)   #define off(x,k) ((x)^(1<<(k-1)))   using namespace std;   void START()   {       #ifdef toilagun2004       freopen(KKH .inp , r ,stdin);       freopen(KKH .out , w ,stdout);       #endif // toilagun2004       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);   }   const int gh=1e5+6;   int n,a[gh],g[gh],d[gh];   int main()   {    START();       int T;       cin>>T;       while(T--){           cin>>n;           rs(d,0);           rs(g,0);           for (int i=1;i<=n;i++)           {               cin>>a[i];               if (i&1) d[a[i]]++;               else g[a[i]]++;           }           sort(a+1,a+n+1);           for (int i=1;i<=n;i++)           {               if (i&1) d[a[i]]--;               else g[a[i]]--;           }           bool hung=true;           for(int e=1;e<=100000 && hung;e++)               if (d[e] || g[e]) hung=false;           if (hung) cout<< YES n ;           else cout<< NO n ;       }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000000000000LL;   long long ff(long long a, long long b, long long c) {     if ((a + b) % 2 != 0) return INF;     long long x = (a + b) / 2;     if (a < b) swap(a, b);     long long y = 0, z = (a - b) / 2;     return x + y + z;   }   int main() {     long long a, b, c;     scanf( %I64d%I64d%I64d , &a, &b, &c);     printf( %I64d n , min(min(ff(a, b, c), ff(b, c, a)), ff(c, a, b)));     return 0;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long int ll;         void solve()   {       ll n; cin>>n;       vector<ll> v;       for(int i=0;i<n;i++)       {           ll x; cin>>x;           v.push_back(x);       }       sort(v.begin(),v.end());       ll cost=0;       for(ll i=2; i<n; ++i)       {           ll j=lower_bound(v.begin(),v.end(),v[i]-2)-v.begin();           ll x=(i-j);           cost+=(x*(x-1))/2;       }cout<<cost<<  n ;   }                int main()       {   int t;   cin>>t;   while(t--)   {      solve();       }        }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long poww(long long num, long long p) {     long long ret = 1;     while (p != 0) {       if (p & 1) {         ret = (ret * num) % mod;       }       num = (num * num) % mod;       p = p >> 1;     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n, p;       cin >> n >> p;       long long a[n];       for (int i = 0; i < n; i++) cin >> a[i];       if (p == 1) {         if (n % 2 == 1)           cout <<  1 n ;         else           cout <<  0 n ;         continue;       }       sort(a, a + n);       stack<pair<long long, long long> > st;       for (int i = n - 1; i >= 0; i--) {         if (st.size() == 0) {           st.push(make_pair(a[i], 1));         } else {           long long t1 = a[i];           long long cnt = 1;           while (true) {             pair<long long, long long> t2 = st.top();             if (t2.first > t1) {               st.push(make_pair(t1, cnt));               break;             } else if (t2.first == t1) {               st.pop();               if (st.size() == 0)                 break;               else {                 cnt = t2.second + 1;                 if (cnt == p) {                   cnt = 1;                   t1++;                 } else {                   st.push(make_pair(t1, cnt));                   break;                 }               }             }           }         }       }       if (st.size() == 0) {         cout << 0 <<   n ;       } else {         long long ans = 0;         while (st.size() != 1) {           pair<long long, long long> temp = st.top();           st.pop();           ans = (ans + (temp.second * poww(p, temp.first)) % mod) % mod;         }         pair<long long, long long> temp = st.top();         st.pop();         long long res = poww(p, temp.first);         res = (res - ans + mod) % mod;         cout << res <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     long long a[1010000];     long long s[1010000];     memset(a, 0, sizeof(a));     for (int i = 0; i < n; i++) {       scanf( %lld , a + i);     }     vector<pair<long long, long long>> pll;     for (int i = 0; i < n; i++) {       long long sum = a[i];       long long sz = 1;       while (!pll.empty() &&              pll.back().first * 1.0 / pll.back().second > sum * 1.0 / sz) {         sum += pll.back().first;         sz += pll.back().second;         pll.pop_back();       }       pll.push_back(make_pair(sum, sz));     }     for (int i = 0; i < pll.size(); i++) {       for (int j = 0; j < pll[i].second; j++) {         if (!i && !j)           printf( %.9lf , pll[i].first * 1.0 / pll[i].second);         else           printf(  %.9lf , pll[i].first * 1.0 / pll[i].second);       }     }     return;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a1, t1, a2, t2, n1 = 0, n2 = 0;     cin >> n >> a1 >> a2 >> t1 >> t2;     n1 += t1 * 2;     n2 += t2 * 2;     n1 += a1 * n;     n2 += a2 * n;     if (n1 > n2) cout <<  Second ;     if (n2 > n1) cout <<  First ;     if (n1 == n2) cout <<  Friendship ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   long long DP[N];   int n;   int a[N];   int freq[N];   long long solve(int num) {     if (num < 1) return 0;     if (DP[num] != -1) return DP[num];     return DP[num] =                max((long long)num * freq[num] + solve(num - 2), solve(num - 1));   }   int main() {     memset(DP, -1, sizeof DP);     scanf( %d , &n);     int mx = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       ++freq[a[i]];       if (a[i] > mx) mx = a[i];     }     printf( %lld n , solve(mx));   }