malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct query {     long long t, fi, si;   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long a[n];     map<long long, long long> f;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       a[i] = x;       f[x]++;     }     long long maxn, maxf = -1;     for (auto i : f) {       if (i.second > maxf) {         maxf = i.second;         maxn = i.first;       }     }     vector<long long> index;     for (long long i = 0; i < n; i++) {       if (a[i] == maxn) index.push_back(i);     }     vector<query> ans;     for (auto i : index) {       long long j = i - 1;       while (a[j] != maxn && j >= 0) {         if (a[j] > a[j + 1]) {           ans.push_back({2, j + 1, j + 2});           a[j] = maxn;         } else if (a[j] < a[j + 1]) {           ans.push_back({1, j + 1, j + 2});           a[j] = maxn;         }         j--;       }     }     long long j = index.back() + 1;     while (j < n) {       if (a[j] > a[j - 1]) {         ans.push_back({2, j + 1, j});         a[j] = maxn;       } else if (a[j] < a[j - 1]) {         ans.push_back({1, j + 1, j});         a[j] = maxn;       }       j++;     }     cout << ans.size() <<   n ;     for (auto i : ans) cout << i.t <<     << i.fi <<     << i.si <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     const int N = 1e2 + 10;     int n, m;     int v[N][2 * N];     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 2 * m; j++) {         cin >> v[i][j];       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 2 * m; j += 2) {         if (v[i][j] == 1 or v[i][j + 1] == 1) ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[105][105][2], a[105];   int n;   void printdp() {     int cnt = 0;     for (int i = 0; i < n + 1; i++) {       for (int j = 0; j < n + 1; j++) {         for (int k = 0; k < 2; k++) {           cnt++;           cout <<  index    << i <<     << j <<     << k <<     << dp[i][j][k]                <<    ;         }         cout << endl;       }       cout << endl;     }     cout << endl << cnt << endl;   }   int main() {     cin >> n;     for (int i = 0; i < n + 1; i++) {       for (int j = 0; j < n + 1; j++) {         for (int k = 0; k < 2; k++) {           dp[i][j][k] = n + 1;         }       }     }     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     dp[0][0][0] = dp[0][0][1] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= i; j++) {         if (a[i] % 2 || a[i] == 0) {           dp[i][j][1] = min(dp[i - 1][j][0] + 1, dp[i - 1][j][1]);         }         if (a[i] % 2 == 0 && j > 0) {           dp[i][j][0] = min(dp[i - 1][j - 1][0], dp[i - 1][j - 1][1] + 1);         }       }     }     cout << min(dp[n][n / 2][0], dp[n][n / 2][1]) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, s;     cin >> n >> s;     long long int min = INT_MAX;     unsigned long long int sum = 0;     long long int i;     long long int arr[n];     for (i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];       if (arr[i] < min) min = arr[i];     }     if (sum < s) {       cout <<  -1 ;       return 0;     }     if (sum == s) {       cout <<  0 ;       return 0;     }     long long int count = 0;     for (i = 0; i < n; i++) {       if (arr[i] > min) count++;     }     for (i = 0; i < n; i++) {       if (count <= 0) break;       if (arr[i] > min) {         count -= 1;         if (s - (arr[i] - min) <= 0) {           cout << min;           return 0;         }         s = s - (arr[i] - min);         arr[i] = min;       }     }     while (s != 0 && min >= 0) {       if (s - (n) <= 0) {         cout << (min - 1);         return 0;       } else {         min--;         s = s - n;       }     }     cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100030;   const long long MODD = 1000000009;   void do_case() {     int a, b, c, d, x, y;     cin >> x >> y >> a >> b >> c >> d;     if (x > y) swap(x, y);     pair<int, int> T[4] = {{a + c, max(b, d)},                            {a + d, max(b, c)},                            {b + c, max(a, d)},                            {b + d, max(a, c)}};     for (auto p : T) {       int X, Y;       tie(X, Y) = minmax(p.first, p.second);       if (X <= x && Y <= y) {         cout <<  YES  << endl;         return;       }     }     cout <<  NO  << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     do_case();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 500;   int a[maxn];   int main(void) {     int n, m;     cin >> n >> m;     int ans = 0;     for (int i = 1; i <= m; i++) {       int num;       scanf( %d , &num);       int x, temp;       int flag = 0;       scanf( %d , &x);       temp = x;       if (x == 1) flag = 1;       for (int j = 2; j <= num; j++) {         scanf( %d , &x);         if (flag == 1 && x == temp + 1) {           temp = x;           continue;         }         if (x == 1) {           temp = x;           flag = 1;         } else {           flag = 0;           ans++;         }       }     }     ans = ans + ans + m - 1;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   int n, m;   int dp[45][1 << 7][1 << 7];   int cnt[1 << 7];   void init() {     for (int i = 0; i < (1 << m); i++) {       for (int x = i; x; x >>= 1)         if ((x & 1)) cnt[i]++;       cnt[i] = m - cnt[i];     }   }   bool ok(int j, int k, int l) {     int state = k | (k << 1) | (k >> 1) | j | l;     return (state & ((1 << m) - 1)) == ((1 << m) - 1);   }   int main() {     n = read(), m = read();     if (n < m) swap(n, m);     init();     memset(dp, -0x3f3f3f3f, sizeof dp);     for (int i = 0; i < (1 << m); i++) dp[0][0][i] = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < (1 << m); j++)         for (int k = 0; k < (1 << m); k++)           if (dp[i][j][k] >= 0)             for (int l = 0; l < (1 << m); l++)               if (ok(j, k, l))                 dp[i + 1][k][l] = max(dp[i + 1][k][l], dp[i][j][k] + cnt[k]);     int ans = 0;     for (int i = 0; i < (1 << m); i++) ans = max(ans, dp[n][i][0]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   bool des(int i, int j) { return i > j; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     if (n == 5)       cout << 1;     else       cout << n % 3 + 1;   }
#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 X[210] = {};      int N, M; cin >> N >> M;      for(int i = 0; i < N; i++){      for(int j = 0; j < M; j++){       int a; cin >> a;        X[i+j] ^= a;       }     }     bool ok = true;      for(int i = 0; i < N+M-1; i++){      if(X[i]) ok = false;      }     cout << (ok ?  Jeel n  :  Ashish n );     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void chkmax(T &x, T y) {     if (x < y) x = y;   }   template <class T>   inline void chkmin(T &x, T y) {     if (x > y) x = y;   }   int t, n, m, k, cnt[26];   bool vis[200020];   char s[200020];   int solve() {     int ans = 1000000007;     for (int i = 0; i < n; i++) vis[i] = 0;     vis[0] = 1;     for (int i = 0; i < 26; i++) {       for (int j = n - 1; j >= 0; j--) {         if (vis[j]) {           if (j + cnt[i] >= n) {             if (j + cnt[i] + m <= k) return 0;             chkmin(ans, (n - j) * (j + cnt[i] + m - k));           } else             vis[j + cnt[i]] = 1;         }       }     }     for (int i = 0; i < m; i++) vis[i] = 0;     vis[0] = 1;     for (int i = 0; i < 26; i++) {       for (int j = m - 1; j >= 0; j--) {         if (vis[j]) {           if (j + cnt[i] >= m) {             if (j + cnt[i] + n <= k) return 0;             chkmin(ans, (m - j) * (j + cnt[i] + n - k));           } else             vis[j + cnt[i]] = 1;         }       }     }     return ans;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d %d %d , &n, &m, &k);       scanf( %s , s);       memset(cnt, 0, sizeof cnt);       for (int i = 0; i < k; i++) cnt[s[i] -  A ]++;       sort(cnt, cnt + 26, greater<int>());       printf( %d n , solve());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<pair<int, int>, int> a[100010];   vector<pair<long long, int> > pre[100010];   long long maxx = 0;   int maxi, maxj;   int c = 0;   long long s = 0;   long long val1, val2;   void eval(int i, int j, int k, bool f) {     val2 = pre[j][k].first;     if (val1 + val2 > maxx) {       maxx = val1 + val2;       maxi = pre[i][pre[i].size() - 1].second;       maxj = pre[j][k].second;       if (f) swap(maxi, maxj);     }   }   vector<int> out;   int main() {     int n, i;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf( %d , &a[i].first.first);       scanf( %d , &a[i].first.second);       a[i].first.second = -a[i].first.second;       a[i].second = i;     }     sort(a, a + n);     s = -a[0].first.second;     c++;     pre[c].push_back(make_pair(s, 0));     for (i = 1; i < n; ++i) {       if (a[i].first.first == a[i - 1].first.first) {         s -= a[i].first.second;         c++;       } else {         s = -a[i].first.second;         c = 1;       }       pre[c].push_back(make_pair(s, i));     }     for (i = 1; i < 100010; ++i) {       if (pre[i].size() == 0) break;       sort(pre[i].begin(), pre[i].end());     }     for (i = 1; i < 100010; ++i) {       if (pre[i].size() == 0) break;       val1 = pre[i][pre[i].size() - 1].first;       if (i > 1) {         if (pre[i - 1].size()) {           if (a[pre[i - 1][pre[i - 1].size() - 1].second].first.first !=               a[pre[i][pre[i].size() - 1].second].first.first)             eval(i, i - 1, pre[i - 1].size() - 1, 0);           else if (pre[i - 1].size() > 1)             eval(i, i - 1, pre[i - 1].size() - 2, 0);         }       }       if (pre[i].size() > 1) eval(i, i, pre[i].size() - 2, 0);       if (pre[i + 1].size()) {         if (a[pre[i + 1][pre[i + 1].size() - 1].second].first.first !=             a[pre[i][pre[i].size() - 1].second].first.first)           eval(i, i + 1, pre[i + 1].size() - 1, 1);         else if (pre[i + 1].size() > 1)           eval(i, i + 1, pre[i + 1].size() - 2, 1);       }     }     while (maxj) {       if (a[maxj - 1].first.first != a[maxj].first.first) break;       out.push_back(a[maxi].second + 1);       out.push_back(a[maxj].second + 1);       --maxi;       --maxj;     }     out.push_back(a[maxi].second + 1);     out.push_back(a[maxj].second + 1);     if (maxi) {       if (a[maxi - 1].first.first == a[maxi].first.first)         out.push_back(a[maxi - 1].second + 1);     }     printf( %lld n%d n , maxx, (int)out.size());     for (i = 0; i < out.size(); ++i) printf( %d  , out[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long dp[100001];   bool seen[100001];   int n, q;   vector<int> v, c;   long long cal() {     long long a, b;     cin >> a >> b;     for (int i = 0; i < 100001; i++) seen[i] = false;     int c1, c2;     c1 = c2 = -1;     for (int i = 0; i < n; i++) {       long long maxV = b * v[i];       if (seen[c[i]]) {         maxV =             (((dp[c[i]] + a * v[i]) > (maxV)) ? (dp[c[i]] + a * v[i]) : (maxV));       }       if (c1 >= 0 && c1 != c[i]) {         maxV = (((dp[c1] + b * v[i]) > (maxV)) ? (dp[c1] + b * v[i]) : (maxV));       }       if (c2 >= 0 && c2 != c[i]) {         maxV = (((dp[c2] + b * v[i]) > (maxV)) ? (dp[c2] + b * v[i]) : (maxV));       }       if (!seen[c[i]]) dp[c[i]] = maxV;       seen[c[i]] = true;       dp[c[i]] = (((maxV) > (dp[c[i]])) ? (maxV) : (dp[c[i]]));       if (c1 < 0 || maxV > dp[c1]) {         c2 = c1;         c1 = c[i];       } else if (c2 < 0 || maxV > dp[c2] && c[i] != c1) {         c2 = c[i];       }     }     if (c1 >= 0) return (((dp[c1]) > (0LL)) ? (dp[c1]) : (0LL));     return 0LL;   }   int main() {     cin >> n >> q;     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       v.push_back(tmp);     }     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       c.push_back(tmp);     }     for (int i = 0; i < q; i++) cout << cal() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef const int &ci;   inline int read() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while ( 0  <= c && c <=  9 ) x = 10 * x + c -  0 , c = getchar();     return x;   }   inline void Max(int &x, ci y) {     if (x < y) x = y;   }   const int N = 2003;   int n, m, k, Ans, ans[N];   int px[N], py[N];   char c[N][N];   int f[N][N];   int u[N][N], d[N][N];   int h1, t1, q1[N];   int h2, t2, q2[N];   inline void Calc(int *a, int *b) {     q1[h1 = t1 = 1] = 1, q2[h2 = t2 = 1] = 1;     for (int l = 1, r = 1; r <= m; l++) {       while (h1 <= t1 && q1[h1] < l) h1++;       while (h2 <= t2 && q2[h2] < l) h2++;       while (r < l || r - l + 1 <= a[q1[h1]] + b[q2[h2]] - 1) {         Max(Ans, r - l + 1), r++;         while (h1 <= t1 && a[q1[t1]] >= a[r]) t1--;         q1[++t1] = r;         while (h2 <= t2 && b[q2[t2]] >= b[r]) t2--;         q2[++t2] = r;       }       Max(Ans, a[q1[h1]] + b[q2[h2]] - 1);     }   }   int main() {     n = read(), m = read(), k = read();     for (int i = 1; i <= n; i++) scanf( %s , c[i] + 1);     for (int i = 1; i <= k; i++) {       px[i] = read(), py[i] = read();       c[px[i]][py[i]] =  # ;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (c[i][j] ==  . ) {           f[i][j] = min(f[i - 1][j - 1], min(f[i - 1][j], f[i][j - 1])) + 1;           Max(Ans, f[i][j]);           u[i][j] = u[i - 1][j] + 1;         }     for (int i = n; i >= 1; i--)       for (int j = m; j >= 1; j--)         if (c[i][j] ==  . ) d[i][j] = d[i + 1][j] + 1;     for (int Cas = k, x, y; Cas >= 1; Cas--) {       ans[Cas] = Ans, c[x = px[Cas]][y = py[Cas]] =  . ;       for (int i = x; i <= n; i++)         if (c[i][y] ==  . ) u[i][y] = u[i - 1][y] + 1;       for (int i = x; i >= 1; i--)         if (c[i][y] ==  . ) d[i][y] = d[i + 1][y] + 1;       Calc(u[x], d[x]);     }     for (int i = 1; i <= k; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long sum;   struct myS {     int index;     long long v;     myS(){};     myS(int index, long long v) : index(index), v(v){};     bool operator<(const myS& right) const { return v < right.v; }   } a[200001];   bool dd[1000001];   vector<int> res;   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     cout.tie(0);     ;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].v;       sum += a[i].v;       a[i].index = i;     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       long long le = sum - a[i].v;       if (le % 2 == 1) continue;       long long need = (le >> 1);       auto it = lower_bound(a + 1, a + n + 1, myS(0, need));       if ((*it).v == need && (*it).index != a[i].index)         res.push_back(a[i].index);       else if ((*it).v == need && (*it).index == a[i].index) {         auto it2 = upper_bound(a + 1, a + n + 1, myS(0, need));         while (it != it2) {           if ((*it).index != a[i].index) {             res.push_back(a[i].index);             break;           } else             it++;         }       }     }     cout << res.size() << endl;     for (auto i : res) cout << i <<    ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   int main() {     long long n, m, x, y, sum = 0, total;     vector<long> v, v1, v2;     set<int> s, s1, s2;     map<long long, bool> Mymap;     scanf( %I64d %I64d , &n, &m);     for (long long int i = 1; i <= n; i++) {       cin >> x;       Mymap[x]++;     }     for (long long int j = 1; j <= m; j++) {       if (Mymap[j] != true) {         m -= j;         v.push_back(j);       }     }     cout << v.size() << endl;     for (auto it : v) {       cout << it <<    ;     }     cout << endl;     v.clear();     Mymap.clear();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long len[1000006];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, q, t, x, s, m, p, d, l;     cin >> n >> m >> l;     for (int i = 0; i < n; i++) {       cin >> len[i];     }     long long co = 0;     long long pre;     if (n == 1) {       if (len[0] > l) co++;       for (int i = 0; i < m; i++) {         cin >> x;         if (x == 1) {           cin >> p >> d;           pre = len[p - 1];           len[p - 1] += d;           if (len[p - 1] > l && pre <= l) {             co++;           }         } else           cout << co <<   n ;       }       return 0;     }     for (int i = 0; i < n; i++) {       if (len[i] > l) {         co++;         int j = i;         while (j < n && len[j] > l) {           j++;         }         if (j > i) i = j;       }     }     long long prev;     for (int i = 0; i < m; i++) {       cin >> x;       if (x == 1) {         cin >> p >> d;         p--;         prev = len[p];         len[p] += d;         if (prev <= l) {           if (len[p] > l) {             if (p == 0) {               if (len[p + 1] > l)                 continue;               else {                 co++;                 continue;               }             } else if (p == n - 1) {               if (len[p - 1] > l)                 continue;               else                 co++;             } else {               if (len[p - 1] > l && len[p + 1] > l)                 co--;               else if (len[p - 1] <= l && len[p + 1] <= l)                 co++;             }           }         }       } else {         cout << max(1ll * 0, co) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int www = 9;   const int Size = 10000;   char buffer[Size];   int dr[] = {-1, 0, 1, 0};   int dc[] = {0, 1, 0, -1};   const int inf = 0x0fffffff;   const int size = 52;   long long dp[size][10];   int ar[size];   struct Point {     int x, y, z;     Point(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}   };   Point operator-(const Point &a, const Point &b) {     return Point(a.x - b.x, a.y - b.y, a.z - b.z);   }   double dist(const Point &a) {     return sqrt((double)a.x * a.x + (double)a.y * a.y + (double)a.z * a.z);   }   int solution(int nTest) {     int n;     scanf( %d , &n);     vector<Point> v;     for (int i = 0; i < n; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       v.push_back(Point(x, y, z));     }     double m = 10e8;     Point cent = v[0];     for (int i = 1; i < n; i++) {       for (int j = i + 1; j < n; j++) {         Point a = v[i], b = v[j];         double x = dist(a - cent);         double y = dist(b - cent);         double d = dist(a - b);         double time = (x + d - y) / 2 + y;         m = min(m, time);       }     }     printf( %.7lf n , m);     return 0;   }   int main() {     int i = 0, n = 9999;     while (i < n && solution(i)) {       i++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6 + 1e3, mod = 1e9 + 7, inf = 1e9;   long long n, m, x1, d, z, t, sum, x, y, maxi, mini, a[MAXN], dp[4][MAXN],       b[MAXN], ans;   string s[MAXN];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) {       for (int j = 1; j < 4; j++) {         dp[j][i] = inf;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] >=  a  && s[i][j] <=  z ) {           dp[1][i] = j;           break;         }       }       for (int j = 0; j < m; j++) {         if (s[i][j] >=  0  && s[i][j] <=  9 ) {           dp[2][i] = j;           break;         }       }       for (int j = 0; j < m; j++) {         if (s[i][j] ==  *  || s[i][j] ==  #  || s[i][j] ==  & ) {           dp[3][i] = j;           break;         }       }       for (int j = m - 1; j >= 0; j--) {         if (s[i][j] >=  a  && s[i][j] <=  z ) {           dp[1][i] = min(dp[1][i], (m - j));           break;         }       }       for (int j = m - 1; j >= 0; j--) {         if (s[i][j] >=  0  && s[i][j] <=  9 ) {           dp[2][i] = min(dp[2][i], (m - j));           break;         }       }       for (int j = m - 1; j >= 0; j--) {         if (s[i][j] ==  *  || s[i][j] ==  #  || s[i][j] ==  & ) {           dp[3][i] = min(dp[3][i], (m - j));           break;         }       }     }     ans = inf;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         for (int k = 0; k < n; k++) {           if (i != j && i != k && j != k) {             ans = min(ans, dp[1][i] + dp[2][j] + dp[3][k]);           }         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if (n == k) {       cout << -1;       return 0;     }     int q = n - k;     int a[n];     for (int i = 0; i < n; i++) a[i] = i + 1;     if (!(q % 2)) {       swap(a[0], a[n - 1]);       q--;     }     for (int i = 1; i < q; i += 2) {       swap(a[i], a[i + 1]);     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   struct AA {     int p, s;   } c[110];   int st[110];   bool cmp1(AA a, AA b) {     if (a.p == b.p) return a.s < b.s;     return a.p < b.p;   }   bool vis[110];   int work1() {     int ret = 0;     sort(c, c + n, cmp1);     sort(st, st + m);     for (int i = 0; i < n; i++) {       if (i == m) break;       if (c[i].p == 1) break;       if (c[i].s > st[m - 1 - i]) break;       ret += st[m - 1 - i] - c[i].s;     }     return ret;   }   int work2() {     int ret = 0;     sort(c, c + n, cmp1);     sort(st, st + m);     memset(vis, 0, sizeof(vis));     for (int i = 0; i < n; i++)       if (c[i].p == 1) {         bool fg = true;         for (int j = 0; j < m; j++)           if (!vis[j] && st[j] > c[i].s) {             vis[j] = true;             fg = false;             break;           }         if (fg) return 0;       }     for (int i = 0; i < n; i++)       if (c[i].p == 0) {         bool fg = true;         for (int j = 0; j < m; j++)           if (!vis[j] && st[j] >= c[i].s) {             vis[j] = true;             ret += st[j] - c[i].s;             fg = false;             break;           }         if (fg) return 0;       }     for (int j = 0; j < m; j++)       if (!vis[j]) ret += st[j];     return ret;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       char s[10];       scanf( %s , s);       if (s[0] ==  A )         c[i].p = 0;       else         c[i].p = 1;       scanf( %d , &c[i].s);     }     for (int i = 0; i < m; i++) scanf( %d , &st[i]);     cout << max(work1(), work2());   }