malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3007;   const int w = 31;   int n, m, q, d[maxn][maxn >> 4], o[maxn][maxn >> 4], sm[maxn];   set<pair<int, int> > s;   set<pair<int, int> > valid;   vector<int> val[maxn];   int gd(int n) {     int ans = 0;     while (n) {       ans += n & 1;       n >>= 1;     }     return ans;   }   int get_ans(int l, int r) {     int ans = ((1 << r - l + 1) - 1) << l;     return ans;   }   int get_sum(int u) {     int ans = 0;     for (int i = 0; i <= m / w; ++i) {       ans += o[u][i];     }     return ans;   }   bool ck(int i, int j) {     for (int k = 0; k <= m / w; ++k) {       if ((d[i][k] & d[j][k]) != d[i][k]) return 1;     }     return 0;   }   int get_dig(int i, int j) {     for (int k = 0; k <= m / w; ++k) {       if ((d[i][k] & d[j][k]) != d[i][k]) {         int t1 = d[i][k], t2 = d[j][k];         for (int u = 0; u < w; ++u) {           if ((t1 & 1) && !(t2 & 1)) {             return u + k * w + 1;           }           t1 >>= 1, t2 >>= 1;         }       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; ++i) {       s.insert({0, i});     }     while (q--) {       int i, l, r;       scanf( %d%d%d , &i, &l, &r);       l--, r--;       int lb = l / w, rb = r / w;       if (lb < rb) {         d[i][lb] = d[i][lb] ^ get_ans(l % w, w - 1);         o[i][lb] = gd(d[i][lb]);         d[i][rb] = d[i][rb] ^ get_ans(0, r % w);         o[i][rb] = gd(d[i][rb]);         for (int j = lb + 1; j < rb; ++j) {           d[i][j] = d[i][j] ^ get_ans(0, w - 1);           o[i][j] = w - o[i][j];         }       } else {         d[i][lb] = d[i][lb] ^ get_ans(l % w, r % w);         o[i][lb] = gd(d[i][lb]);       }       auto p = s.find({sm[i], i});       int u = prev(p)->second, v = next(p)->second;       if (u && v && ck(u, v)) {         val[u].push_back(v);         val[v].push_back(u);         valid.insert({u, v});         valid.insert({v, u});       }       s.erase(p);       for (int j = 0; j < val[i].size(); ++j) {         valid.erase({i, val[i][j]});         valid.erase({val[i][j], i});       }       val[i].clear();       sm[i] = get_sum(i);       s.insert({sm[i], i});       p = s.find({sm[i], i});       u = prev(p)->second, v = next(p)->second;       if (u && ck(u, i)) {         val[i].push_back(u);         val[u].push_back(i);         valid.insert({i, u});         valid.insert({u, i});       }       if (v && ck(i, v)) {         val[i].push_back(v);         val[v].push_back(i);         valid.insert({i, v});         valid.insert({v, i});       }       if (valid.empty()) {         cout << -1 << endl;       } else {         auto p = valid.begin();         int u = next(p)->first, v = next(p)->second;         int au = get_dig(u, v), av = get_dig(v, u);         if (u > v) swap(u, v);         if (au > av) swap(au, av);         printf( %d %d %d %d n , u, au, v, av);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dx[8] = {-1, 1, 0, 0, 1, -1, 1, -1};   long long dy[8] = {0, 0, -1, 1, 1, -1, -1, 1};   void solve() {     long long n, m;     cin >> n >> m;     char a[n][m];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) cin >> a[i][j];     }     bool f = 1;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (a[i][j] ==  . ) {           for (long long k = 0; k < 8; k++) {             long long x = i + dx[k];             long long y = j + dy[k];             if (x < 0 || x >= n || y < 0 || y >= m) continue;             if (a[x][y] ==  * ) {               cout <<  NO ;               return;             }           }         } else if (a[i][j] >=  1  && a[i][j] <=  8 ) {           long long cnt = 0;           for (long long k = 0; k < 8; k++) {             long long x = i + dx[k];             long long y = j + dy[k];             if (x < 0 || x >= n || y < 0 || y >= m) continue;             if (a[x][y] ==  * ) cnt++;           }           if (cnt != a[i][j] -  0 ) {             cout <<  NO ;             return;           }         }       }     }     cout <<  YES ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> moebius(int n) {     map<int, int> res;     vector<int> primes;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         primes.push_back(i);         while (n % i == 0) n /= i;       }     }     if (n != 1) primes.push_back(n);     int m = primes.size();     for (int i = 0; i < (1 << m); i++) {       int mu = 1;       int d = 1;       for (int j = 0; j < m; j++) {         if (i >> j & 1) {           mu *= -1;           d *= primes[j];         }       }       res[d] = mu;     }     return res;   }   int digCnt(long long n) {     int cnt = 0;     while (n) {       cnt++;       n /= 2;     }     return cnt;   }   int isPrime(int a) {     if (a <= 1) return false;     for (int i = 2; i * i <= a; i++)       if (a % i == 0) return false;     return true;   }   const int mu[] = {0, 1,  -1, -1, 0, -1, 1,  -1, 0, 0,  1,  -1, 0, -1, 1,  1,                     0, -1, 0,  -1, 0, 1,  1,  -1, 0, 0,  1,  0,  0, -1, -1, -1,                     0, 1,  1,  1,  0, -1, 1,  1,  0, -1, -1, -1, 0, 0,  1,  -1,                     0, 0,  0,  1,  0, -1, 0,  1,  0, 1,  1,  -1, 0, -1, 1,  0,                     0, 1,  -1, -1, 0, 1,  -1, -1, 0, -1, 1,  0,  0, 1};   long long getNum(long long n) {     long long res = 0;     if (n <= 0) return res;     int digs = digCnt(n);     vector<int> v;     long long tmp = n;     while (tmp) {       v.push_back(tmp % 2);       tmp /= 2;     }     reverse(v.begin(), v.end());     for (int i = 2; i < digs; i++) {       map<int, int> m = moebius(i);       for (int k = 1; k < i; k++)         if (i % k == 0) {           res -= (1LL << (k - 1)) * (long long)m[i / k];         }     }     map<int, int> m = moebius(digs);     for (int k = 1; k < digs; k++) {       if (digs % k == 0) {         long long cand = 0;         for (int i = 0; i < k; i++) {           if (i != 0 && v[i]) {             cand += (1LL << (k - i - 1));           }         }         long long num = 0;         for (int i = 0; i < k; i++) {           if (v[i]) {             for (int j = i; j < digs; j += k) num |= (1LL << (digs - 1 - j));           }         }         if (num <= n) cand++;         res -= m[digs / k] * cand;       }     }     return res;   }   int main() {     long long l, r;     while (cin >> l >> r) {       cout << getNum(r) - getNum(l - 1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string grid[60];   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     int t;     cin >> t;     int r, c;     while (t--) {       cin >> r >> c;       for (int i = 0; i < r; i++) cin >> grid[i];       bool quina = false, borda = false, meio = false, all = true, tdb1 = true,            tdb2 = true, tdb3 = true, tdb4 = true, tdm1 = false, tdm2 = false;       for (int i = 0; i < r; i++) {         bool at = true;         for (int j = 0; j < c; j++) {           if (grid[i][j] ==  A ) {             if ((i == 0 && j == 0) || (i == 0 && j == c - 1) ||                 (i == r - 1 && j == 0) || (i == r - 1 && j == c - 1))               quina = true;             else if (i == 0 || j == c - 1 || i == r - 1 || j == 0)               borda = true;             else               meio = true;           } else {             all = false;             at = false;           }         }         tdm1 = tdm1 || at;       }       for (int i = 0; i < c; i++) {         bool at = true;         for (int j = 0; j < r; j++) {           if (grid[j][i] ==  P ) {             at = false;           }         }         tdm2 = tdm2 || at;       }       for (int i = 0; i < r; i++) {         if (grid[i][0] ==  P ) tdb1 = false;       }       for (int i = 0; i < r; i++) {         if (grid[i][c - 1] ==  P ) tdb2 = false;       }       for (int i = 0; i < c; i++) {         if (grid[0][i] ==  P ) tdb3 = false;       }       for (int i = 0; i < c; i++) {         if (grid[r - 1][i] ==  P ) tdb4 = false;       }       if (all)         cout << 0 << endl;       else if (tdb1 || tdb2 || tdb3 || tdb4)         cout << 1 << endl;       else if (quina || tdm1 || tdm2)         cout << 2 << endl;       else if (borda)         cout << 3 << endl;       else if (meio)         cout << 4 << endl;       else         cout <<  MORTAL  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int s, x1, x2, t1, t2, p, d;     cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d;     int cnt = 0, initial_position = p;     while (initial_position != x1) {       if (initial_position == s) d = -1;       if (initial_position == 0) d = 1;       initial_position += d;       cnt++;     }     while (initial_position != x2) {       if (initial_position == s) d = -1;       if (initial_position == 0) d = 1;       initial_position += d;       cnt++;     }     int ans = min(abs(x1 - x2) * t2, cnt * t1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool even(long long int x) { return (x % 2 == 0); }   bool odd(long long int x) { return (x % 2 != 0); }   vector<int> sieve(int n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     vector<int> v;     for (int p = 2; p <= n; p++)       if (prime[p]) v.push_back(p);     return v;   }   long long gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool isprime(long long n) {     if (n == 1) return false;     if (n == 2 || n == 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6) {       if (n % i == 0 || n % (i + 2) == 0) return false;     }     return true;   }   long long lcm(int a, int b) { return (a / gcd(a, b)) * b; }   bool compare(pair<int, int> p1, pair<int, int> p2) {     if (p1.first == p2.first)       return p1.second <= p2.second;     else       return p1.first > p2.first;   }   vector<int> presum(vector<long long int> v) {     vector<int> res(v.size());     res[0] = v[0];     for (int i = 1; i < v.size(); i++) {       res[i] = res[i - 1] + v[i];     }     return res;   }   void precision(int a) { cout << setprecision(a) << fixed; }   int main() {     int t;     cin >> t;     while (t--) {       int f = 0;       int n;       cin >> n;       string s;       cin >> s;       int l = 0, r = 0;       for (int i = 0; i < n; i++) {         int a = 0, b = 0;         for (int j = i; j < n; j++) {           if (s[j] ==  a ) a++;           if (s[j] ==  b ) b++;           if (a == b && (a != 0 && b != 0)) {             l = i;             r = j;             f = 1;             break;           }         }         if (f == 1) break;       }       if (f == 1)         cout << l + 1 <<     << r + 1 << endl;       else         cout <<  -1 -1  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   int main() {     int r, g, h, t;     cin >> r >> g;     t = r + g;     h = sqrt(t * 2);     if ((h * (h + 1)) / 2 > t) {       h--;     }     int dp[2][r + 1];     for (int j = 0; j <= r; j++) {       dp[0][j] = 0;       dp[1][j] = 0;     }     dp[0][0] = 1;     int x = 0;     for (int i = 1; i <= h; i++) {       x += i;       for (int j = 0; j <= r; j++) {         if (x - j <= g) {           dp[1][j] += dp[0][j];         }         if (j - i >= 0) {           dp[1][j] += dp[0][j - i];         }         dp[1][j] = dp[1][j] % mod;       }       for (int j = 0; j <= r; j++) {         dp[0][j] = dp[1][j];         dp[1][j] = 0;       }     }     int out = 0;     for (int i = 0; i <= r; i++) {       out = (out + dp[0][i]) % mod;     }     cout << out << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long f = 1, x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -f;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + (s -  0 );       s = getchar();     }     return f * x;   }   int n, m, i, j, s, o, k;   int U[200005], V[200005];   vector<int> g[200005];   int fa[200005], ds[200005], siz[200005];   int findd(int x) {     if (x == fa[x]) return 0;     return findd(fa[x]) ^ ds[x];   }   int findf(int x) { return x == fa[x] ? x : findf(fa[x]); }   vector<int> st;   bool unionSet(int a, int b) {     int u = findf(a), v = findf(b);     if (siz[u] > siz[v]) swap(u, v), swap(a, b);     int d1 = findd(a), d2 = findd(b);     if (u == v) {       return d1 ^ d2;     }     if (d1 == d2)       ds[u] = 1;     else       ds[u] = 0;     siz[v] += siz[u];     fa[u] = v;     st.push_back(u);     return 1;   }   void POP() {     int u = st.back();     st.pop_back();     int v = fa[u];     ds[u] = 0;     siz[v] -= siz[u];     fa[u] = u;     return;   }   int maxl[200005];   int li[200005], ri[200005];   void solve(int l, int r, int l2, int r2) {     if (l > r || l2 > r2) return;     if (l2 == r2) {       for (int i = l; i <= r; i++) maxl[i] = l2;       return;     }     int mid = (l + r) >> 1, le = (int)st.size(), rr = max(l2, mid - 1);     int flag = 0;     for (int i = l; i <= mid; i++)       if (i) flag |= 1 ^ unionSet(U[i], V[i]);     int le2 = (int)st.size();     if (flag) rr = r2;     for (int i = min(r2, m); i > mid && i >= l2 && i > rr; i--) {       flag |= 1 ^ unionSet(U[i], V[i]);       if (flag) {         rr = i;         break;       }     }     maxl[mid] = rr;     while ((int)st.size() > le2) POP();     solve(mid + 1, r, rr, r2);     while ((int)st.size() > le) POP();     for (int i = min(r2, m); i >= rr; i--) unionSet(U[i], V[i]);     solve(l, mid - 1, l2, rr);     while ((int)st.size() > le) POP();     return;   }   int main() {     n = read();     m = read();     int Q = read();     for (int i = 1; i <= m; i++) {       s = read();       o = read();       g[s].push_back(o);       g[o].push_back(s);       U[i] = s;       V[i] = o;     }     int rr = 0;     for (int i = 1; i <= Q; i++)       li[i] = read(), ri[i] = read(), rr = max(li[i], rr);     for (int i = 1; i <= n; i++) fa[i] = i, ds[i] = 0, siz[i] = 1;     solve(0, m, 0, m + 1);     for (int i = 1; i <= Q; i++) {       s = li[i];       o = ri[i];       if (maxl[s - 1] > o)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 123456, Mod = 1000000000;   long long a[MaxN], f[MaxN];   int main(void) {     int i, j, n, m;     f[0] = f[1] = 1;     for (i = 2; i < MaxN; i++) f[i] = (f[i - 1] + f[i - 2]) % Mod;     while (scanf( %d %d , &n, &m) != EOF) {       int i, t, l, r;       for (i = 0; i < n; i++) scanf( %I64d , &a[i]);       for (j = 0; j < m; j++) {         scanf( %d %d %d , &t, &l, &r);         if (t == 1)           a[l - 1] = r;         else {           long long s = 0;           for (i = 0; i <= r - l; i++) s = (s + a[i + l - 1] * f[i]) % Mod;           printf( %d n , (int)s);         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, y;   long int v[1001];   long int ans;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       scanf( %ld , &v[i]);     }     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       if (v[x] > v[y])         ans += v[y];       else         ans += v[x];     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   string itos(int x) {     stringstream ss;     ss << x;     return ss.str();   }   int n, k, a[400010], nxt[400010], pt[400010], res;   struct Comp {     bool operator()(int l, int r) const { return pt[l] > pt[r]; }   };   set<int, Comp> s1;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     iota(pt, pt + 400010, n);     for (int i = n - 1; i >= 0; i--) {       nxt[i] = pt[a[i]];       pt[a[i]] = i;     }     for (int i = 0; i < n; i++) {       if (s1.count(a[i])) {         s1.erase(a[i]);         pt[a[i]] = nxt[i];         s1.insert(a[i]);       } else         pt[a[i]] = nxt[i];       if (s1.count(a[i])) continue;       if (s1.size() == k) s1.erase(s1.begin());       s1.insert(a[i]);       res++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<long long> p(n);     vector<int> a(n), b(n);     for (int i = 0; i < n; ++i) cin >> p[i];     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     vector<pair<long long, int>> one, two, three;     for (int i = 0; i < n; ++i) {       if (a[i] == 1 || b[i] == 1) one.push_back({p[i], i});       if (a[i] == 2 || b[i] == 2) two.push_back({p[i], i});       if (a[i] == 3 || b[i] == 3) three.push_back({p[i], i});     }     sort(one.begin(), one.end());     sort(two.begin(), two.end());     sort(three.begin(), three.end());     vector<bool> vis(n, false);     int p1 = 0, p2 = 0, p3 = 0;     int si1 = one.size(), si2 = two.size(), si3 = three.size();     int m, c;     cin >> m;     for (int i = 0; i < m; ++i) {       cin >> c;       if (c == 1) {         bool fl = false;         for (int start = p1; start < si1; start++) {           if (vis[one[start].second] == false) {             cout << one[start].first <<    ;             vis[one[start].second] = true;             fl = true;             p1 = start + 1;             break;           }         }         if (!fl) cout <<  -1  ;       } else if (c == 2) {         bool fl = false;         for (int start = p2; start < si2; start++) {           if (vis[two[start].second] == false) {             cout << two[start].first <<    ;             vis[two[start].second] = true;             fl = true;             p2 = start + 1;             break;           }         }         if (!fl) cout <<  -1  ;       } else {         bool fl = false;         for (int start = p3; start < si3; start++) {           if (vis[three[start].second] == false) {             cout << three[start].first <<    ;             vis[three[start].second] = true;             fl = true;             p3 = start + 1;             break;           }         }         if (!fl) cout <<  -1  ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; ++i) cin >> arr[i];     vector<bool> used(n, false);     int count = 0;     int marked = 0;     while (marked < n) {       int min = 101;       for (int i = 0; i < n; ++i) {         if (arr[i] < min && !used[i]) min = arr[i];       }       for (int i = 0; i < n; ++i)         if (arr[i] % min == 0) {           if (!used[i]) ++marked;           used[i] = true;         }       ++count;     }     cout << count;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     long long S;     cin >> n >> k >> S;     int a[30];     for (int i = 0; i < n; i++) cin >> a[i];     long long fac[50];     fac[0] = 1;     for (int i = 1; i < 50; i++) {       fac[i] = i * fac[i - 1];       if (fac[i] > 10000000000000000ll) fac[i] = 10000000000000001ll;     }     int bit = n / 2;     bit++;     map<pair<long long, int>, long long> mp;     int lim = pow(3ll, (long long)bit);     for (int i = 0; i < lim; i++) {       int rem = i;       int cnt = 0;       long long sm = 0;       for (int j = 0; j < bit; j++) {         if (rem % 3 == 2) {           cnt++;           sm += fac[min(49, a[j])];         } else if (rem % 3 == 1)           sm += a[j];         rem /= 3;       }       if (cnt > k || sm > S) continue;       pair<long long, int> p = make_pair(sm, cnt);       mp[p]++;     }     long long r = 0;     int bit2 = n - bit;     lim = pow(3ll, (long long)bit2);     for (int i = 0; i < lim; i++) {       int rem = i;       int cnt = 0;       long long sm = 0;       for (int j = 0; j < bit2; j++) {         if (rem % 3 == 2) {           cnt++;           sm += fac[min(49, a[j + bit])];         } else if (rem % 3 == 1)           sm += a[j + bit];         rem /= 3;       }       if (sm > S) continue;       for (int K = cnt; K <= k; K++) {         pair<long long, int> p = make_pair(S - sm, k - K);         r += mp[p];       }     }     cout << r << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   int B[100000 + 5];   int S[100000 + 5];   int main() {     int k, n;     cin >> n >> k;     for (int i = 0; i < n; i++) {       char c;       int a, b;       cin >> c >> a >> b;       if (c ==  B ) {         B[a] += b;       } else {         S[a] += b;       }     }     int t = k;     stack<int> SS, SSS;     for (int i = 0; i <= 100000 + 4 && t; i++) {       if (S[i]) SS.push(i), SSS.push(S[i]), t--;     }     while (!SS.empty()) {       int a = SS.top(), b = SSS.top();       SS.pop();       SSS.pop();       printf( S %d %d n , a, b);     }     t = k;     for (int i = 100000 + 4; i >= 0 && t; i--) {       if (B[i]) printf( B %d %d n , i, B[i]), t--;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, f[2][200];   int main() {     f[0][0] = f[1][1] = 1;     int t = 1;     cin >> n;     for (int i = 2; i <= n; ++i) {       t = i & 1;       for (int j = 1; j <= i; ++j) f[t][j] = (f[t][j] + f[t ^ 1][j - 1]) & 1;     }     printf( %d n , n);     for (int i = 0; i <= n; ++i) printf( %d  , f[t][i]);     printf(  n%d n , n - 1);     for (int i = 0; i < n; ++i) printf( %d  , f[t ^ 1][i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int N, M;   int A[5002], B[5002];   int D[5002], E[5002], F[5002];   int result;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int getDif(int x) {     int resnow = 0;     for (int i = 1; i <= M; ++i)       while (x % B[i] == 0) {         --resnow;         x /= B[i];       }     for (int i = 2; i * i <= x; ++i)       while (x % i == 0) {         ++resnow;         x /= i;       }     if (x != 1) ++resnow;     return resnow;   }   int main() {     cin.sync_with_stdio(false);     cin >> N >> M;     for (int i = 1; i <= N; ++i) cin >> A[i];     for (int i = 1; i <= M; ++i) cin >> B[i];     E[0] = 0;     for (int i = 1; i <= N; ++i) {       E[i] = gcd(E[i - 1], A[i]);       F[i] = getDif(E[i]);     }     int base = 0;     for (int i = 1; i <= N; ++i) base += getDif(A[i]);     result = base;     for (int i = N; i >= 1; --i) {       D[i] = F[i] * i;       for (int j = i + 1; j <= N; ++j) D[i] = min(D[i], D[j] + (F[i] - F[j]) * i);       result = max(result, base - D[i]);     }     cout << result <<   n ;   }
#include <bits/stdc++.h>   int mn(int a, int b) { return a < b ? a : b; }   int main() {     int a, b;     scanf( %d%d , &a, &b);     int x = mn(a, b);     int ans = 1;     for (int i = 2; i <= x; i++) {       ans *= i;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int ara[3];     int a, b, c, sum, d, sum1;     int m;     for (int wq = 0; wq < t; wq++) {       cin >> ara[0] >> ara[1] >> ara[2];       sort(ara, ara + 3);       m = ara[2];       sum = ara[0] + ara[1] + ara[2];       sum1 = ara[0] + ara[1];       if (m > sum1) {         d = sum1;       } else {         d = sum / 2;       }       cout << d << endl;     }     return 0;   }