malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   inline int Read() {     int x = 0, f = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   struct EDGE {     int from, to, w, next;   } E[400005];   int n, m;   int HEAD[200005];   int dep[200005], CENT;   int pa[200005][50], maxx[200005][50];   void ADD(int from, int to, int w) {     E[CENT].from = from;     E[CENT].to = to;     E[CENT].w = w;     E[CENT].next = HEAD[from];     HEAD[from] = CENT++;   }   void DFS(int u, int f) {     pa[u][0] = f;     for (int i = HEAD[u]; i != -1; i = E[i].next) {       int to = E[i].to;       if (to != f) {         dep[to] = dep[u] + 1;         maxx[to][0] = E[i].w;         DFS(to, u);       }     }   }   int maxh;   void deal() {     int j;     for (j = 1; (1 << j) < n; j++)       for (int i = 1; i <= n; i++) {         int t = pa[i][j - 1];         pa[i][j] = pa[pa[i][j - 1]][j - 1];         maxx[i][j] = max(maxx[i][j - 1], maxx[t][j - 1]);       }     maxh = j - 1;   }   int swim(int x, int k, int &ma) {     ma = 0;     for (int i = 0; i <= maxh; i++) {       if (k >> i & 1) {         ma = max(ma, maxx[x][i]);         x = pa[x][i];       }     }     return x;   }   int LCA(int x, int y) {     if (dep[x] > dep[y]) swap(x, y);     int ans = 0;     y = swim(y, dep[y] - dep[x], ans);     if (x == y) return ans;     for (int i = maxh; i >= 0; i--) {       if (pa[x][i] != pa[y][i]) {         ans = max(ans, max(maxx[x][i], maxx[y][i]));         x = pa[x][i], y = pa[y][i];       }     }     return max(ans, max(maxx[x][0], maxx[y][0]));   }   const int N = 200005;   struct edge {     int from, to, w, next;     int ty;     bool operator<(const edge a) const { return w < a.w; }   };   int pre[N], head[N];   int cnt;   edge e[200005 + 5];   void add(int from, int to, int w) {     e[cnt].from = from;     e[cnt].to = to;     e[cnt].w = w;     e[cnt].next = head[from];     e[cnt].ty = 0;     head[from] = cnt++;   }   int find(int x) {     if (x == pre[x]) return x;     return pre[x] = find(pre[x]);   }   void Kruskal() {     for (int i = 1; i <= n; ++i) pre[i] = i;     sort(e, e + cnt);     for (int i = 0; i < cnt; ++i) {       int u = find(e[i].from);       int v = find(e[i].to);       if (u != v) {         pre[u] = v;         ADD(e[i].from, e[i].to, e[i].w);         ADD(e[i].to, e[i].from, e[i].w);         e[i].ty = 1;       }     }   }   int main() {     while (scanf( %d %d , &n, &m) != EOF) {       CENT = cnt = 0;       for (int i = 1; i <= n; i++) head[i] = HEAD[i] = -1;       for (int i = 1; i <= m; i++) {         int u = Read(), v = Read(), w = Read();         add(u, v, w);       }       Kruskal();       DFS(1, -1);       deal();       int ans = 0;       for (int i = 0; i < cnt; i++) {         if (!e[i].ty) {           int u = e[i].from, v = e[i].to;           int minn = LCA(u, v);           if (minn == e[i].w) ans++;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> a[200005];   signed main() {     long long n, j;     cin >> n >> j;     j %= 2 * n;     long long x0, y0;     cin >> x0 >> y0;     for (long long i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;     }     for (long long i = 1; i <= j; i++) {       x0 = 2 * a[(i - 1) % n].first - x0;       y0 = 2 * a[(i - 1) % n].second - y0;     }     cout << x0 <<     << y0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       long long x, y;       cin >> x >> y;       if (y % x == 0LL) {         cout << x <<   n ;       } else if (x > y) {         cout << x + y <<   n ;       } else {         cout << (y / x) * x + (y - (y / x) * x) / 2 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn=1e5+10;      int a[maxn];   int f[maxn];   int n,m,gcnt,ans;      int main()   {    scanf( %d ,&n);    for (int i=1;i<=n;i++) scanf( %d ,&a[i]),f[i]=n+1;    gcnt=1;    for (int i=2,prevmin=0;i<=n;i++)    {     if (a[i-1]!=a[i]) gcnt++;     f[a[i-1]]=min(f[a[i]]-1+(a[i-1]==a[i]),prevmin);     prevmin=min(prevmin,f[a[i-1]]);    }    ans=n;    for (int i=0;i<=n;i++) ans=min(ans,f[i]+gcnt);    printf( %d n ,ans);   }
#include <bits/stdc++.h>   using namespace std;   char s[2005];   const int mod = 1e9 + 7;   int n, k, t[2005];   int a[2005][2005], b[2005][2005];   int mp(const int &a, const int &b) { return (int)(1ll * a * b % mod); }   int add(const int &a, const int &b) { return (a + b) % mod; }   int main() {     scanf( %d %d %s , &n, &k, s);     int i, j, u, v, d, e;     for (i = 0; i < n; i++) t[i + 1] = s[i] -  a ;     for (i = 0; i <= n + 1; i++) a[i][0] = 1;     for (i = n; i > 0; i--) {       v = n - i;       for (j = 0; j <= k; j++) {         b[i][j] = add(b[i + 1][j], mp(t[i], a[i + 1][j]));         a[i][j] = add(a[i][j], b[i][j]);         for (u = 0; u <= v / 2; u++) {           e = j - (v - u + 1) * (u + 1);           if (e < 0) break;           if (2 * u == v)             a[i][j] = add(mp(25 - t[i + u], a[i + u + 1][e]), a[i][j]);           else {             a[i][j] = add(mp(25 - t[i + u], a[i + u + 1][e]), a[i][j]);             a[i][j] = add(mp(25 - t[i + v - u], a[i + v - u + 1][e]), a[i][j]);           }         }       }     }     printf( %d n , a[1][k]);   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   int nextPrime(int N) {     if (N <= 1) return 2;     int prime = N;     bool found = false;     while (!found) {       prime++;       if (isPrime(prime)) found = true;     }     return prime;   }   long long int powerexp(long long int x, long long int n) {     long long int result = 1;     while (n) {       if (n & 1) result = result * x % 1000000007;       n = n / 2;       x = x * x % 1000000007;     }     return result;   }   int gcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     if (a == b) return a;     if (a > b) return gcd(a - b, b);     return gcd(a, b - a);   }   int largest_divisor(long long int n) {     long long int i;     for (i = n / 2; i >= 1; i--) {       if (n % i == 0) {         return i;       }     }     return 0;   }   bool checkPalindrome(string str) {     int n = str.length();     int count = 0;     for (int i = 0; i < n / 2; ++i)       if (str[i] != str[n - i - 1]) ++count;     return (count <= 1);   }   bool countDivisors(long long int n) {     int cnt = 0;     for (int i = 3; i <= sqrt(n); i = i + 2) {       if (n % i == 0) {         return true;       }     }     return false;   }   long long int factorial(long long int n) {     if (n == 0) return 0;     return n * factorial(n - 1);   }   long long int lcm(long long int a, long long int b) {     return (a / gcd(a, b)) * b;   }   void fastIO() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     long long int t = 1;     while (t--) {       long long int n;       cin >> n;       long long int a[n];       long long int z = 0, p = 0, neg = 0;       long long int res = 0;       for (long long int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] == 0) {           res++;           z++;         } else if (a[i] > 0) {           res = res + (a[i] - 1);           p++;         } else {           res = res + (-1 - a[i]);           neg++;         }       }       if (neg % 2 == 1 && z == 0) {         res += 2;       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2e9;   int main() {     int k, n, m, q;     cin >> k >> n >> m >> q;     map<string, map<string, int>> rec;     vector<string> art(n);     map<int, map<string, int>> b;     for (int(i) = (int)(0); (i) < (int)n; ++(i)) cin >> art[i];     sort(art.begin(), art.end());     string s;     getline(cin, s);     for (int(i) = (int)(0); (i) < (int)m; ++(i)) {       getline(cin, s);       int p = s.find( : );       string ar = s.substr(0, p);       s = s.substr(p + 2, s.size());       s +=  ,  ;       while (s !=   ) {         p = s.find(   );         string t = s.substr(0, p);         s = s.substr(p + 1, s.size());         p = s.find( , );         string t2 = s.substr(0, p);         s = s.substr(p + 2, s.size());         int col = atoi(t2.c_str());         rec[ar][t] = col;       }     }     for (int(i) = (int)(0); (i) < (int)q; ++(i)) {       int t;       cin >> t;       string st;       cin >> st;       b[t][st]++;       for (map<string, map<string, int>>::iterator it1 = rec.begin();            it1 != rec.end(); ++it1) {         bool ok = true;         for (map<string, int>::iterator it2 = it1->second.begin();              it2 != it1->second.end(); ++it2) {           if (b[t].find(it2->first) == b[t].end() ||               b[t][it2->first] < it2->second) {             ok = false;             break;           }         }         if (ok) {           for (map<string, int>::iterator it2 = it1->second.begin();                it2 != it1->second.end(); ++it2) {             b[t][it2->first] -= it2->second;             if (b[t][it2->first] == 0) b[t].erase(it2->first);           }           b[t][it1->first]++;           break;         }       }     }     for (int(i) = (int)(1); (i) < (int)k + 1; ++(i)) {       cout << b[i].size() <<   n ;       for (map<string, int>::iterator it = b[i].begin(); it != b[i].end(); ++it)         if (it->second) cout << it->first <<     << it->second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 3005;   const int N = 100005;   int n, a[mx][mx], b[mx][mx], ans[N];   pair<int, int> t[N];   inline int check(int lx, int rx, int ly, int ry) {     int cnt = b[rx][ry];     if (lx) cnt -= b[lx - 1][ry];     if (ly) cnt -= b[rx][ly - 1];     if (lx && ly) cnt += b[lx - 1][ly - 1];     int need = (rx - lx + 1) * (ry - ly + 1);     if (cnt != need) return -1;     if (ly)       if (a[rx][ly] == a[rx][ly - 1]) return -1;     if (lx)       if (a[lx][ry] == a[lx - 1][ry]) return -1;     for (int i = lx; i <= rx; i++)       if (a[i][ry] == a[i][ry + 1]) return false;     for (int i = ly; i <= ry; i++)       if (a[rx][i] == a[rx + 1][i]) return false;     return true;   }   int main() {     int n;     scanf( %d , &n);     for (int q = (0); q <= ((n)-1); q++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       for (int i = x1; i < x2; i++)         for (int j = y1; j < y2; j++) a[i][j] = q + 1, b[i][j] = 1;       t[q] = make_pair(x1, y1);     }     for (int i = (0); i <= ((mx)-1); i++)       for (int j = (0); j <= ((mx)-1); j++) {         if (i - 1 >= 0) b[i][j] += b[i - 1][j];         if (j - 1 >= 0) b[i][j] += b[i][j - 1];         if (i - 1 >= 0 && j - 1 >= 0) b[i][j] -= b[i - 1][j - 1];       }     random_shuffle(t, t + n);     for (int q = (0); q <= ((n)-1); q++) {       int si = t[q].first, sj = t[q].second;       int ei = si, ej = sj;       while (ei < mx && ej < mx) {         int ch = check(si, ei, sj, ej);         if (ch == -1) break;         if (ch == 1) {           for (int i = si; i <= ei; i++)             for (int j = sj; j <= ej; j++) ans[a[i][j]] = 1;           vector<int> res;           for (int i = 0; i < N; i++)             if (ans[i]) res.push_back(i);           printf( YES %d n , (int)((res).end() - (res).begin()));           for (int i = (0); i <= (((int)((res).end() - (res).begin())) - 1);                i++) {             if (i) printf(   );             printf( %d , res[i]);           }           puts(  );           exit(0);         }         ei++;         ej++;       }     }     puts( NO );     return 0;   }
#include<bits/stdc++.h>   using namespace std;      #ifndef ONLINE_JUDGE     #include  Mohit.h    #endif      typedef long long ll;   typedef long double ld;   #define endl   n    #define rep(i,n)  for(ll i = 0; i < (n); ++i)   #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)   #define repD(i, a, n)  for(ll i = a; i >= (n); --i)   #define trav(a, x) for(auto& a : x)   #define all(x) x.begin(), x.end()   #define ff first   #define ss second   #define pb push_back   typedef vector<ll> vll;   typedef vector<pair<ll,ll>> vpl;   const ld PI = 4*atan((ld)1);   const ll INF = 1e18;   const ll mod = 1e9+7;      int main()   {       ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);       ll tt=1;           cin >> tt;       repA(qq,1,tt){           ll n; cin >> n;           vll a(n);           rep(i,n){               cin >> a[i];           }              ll ans = INF;           ll s1=a[0],s2=0,c1=1,c2=0;           ll m1=a[0],m2=INF;              repA(i,1,n-1){               if(i&1){                   m2 = min(m2,a[i]); s2 += a[i];                   ll t1 = (s2-m2)+(n-(c2))*m2;                   ll t2 = (s1-m1)+(n-(c1-1))*m1;                   ans = min(ans,t1+t2);                   c2++;               }else{                   m1 = min(m1,a[i]); s1 += a[i];                   ll t1 = (s1-m1)+(n-(c1))*m1;                   ll t2 = (s2-m2)+(n-(c2-1))*m2;                   ans = min(ans,t1+t2);                   c1++;               }           }              cout << ans << endl;       }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, z = 0;     cin >> n;     long long a[n], b[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       cin >> b[i];     }     vector<long long> neg, pos;     for (long long i = 0; i < n; i++) {       if (a[i] == b[i]) z++;       if ((a[i] - b[i]) >= 0)         pos.push_back(a[i] - b[i]);       else         neg.push_back(b[i] - a[i]);     }     if (!pos.empty()) sort(pos.begin(), pos.end());     if (!neg.empty()) sort(neg.begin(), neg.end());     long long ans = 0, cnt = 0, j = (long long)neg.size() - 1,               k = (long long)pos.size() - 1;     ans += (k * (k + 1)) / 2;     ans -= (z * (z - 1)) / 2;     while (j >= 0 && !pos.empty()) {       if (k >= 0 && neg[j] < pos[k]) {         cnt++;         k--;       } else {         ans += cnt;         j--;       }     }     cout << ans << endl;     return;   }   int main() {     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int a[MAXN];   bool mark[MAXN];   void add(int v, int u) {     while (mark[u] == false) {       cout << v <<     << u << endl;       mark[u] = true;       v = a[v];       u = a[u];     }   }   int dfs(int x) {     int ret = 1;     mark[x] = true;     if (mark[a[x]] == false) ret += dfs(a[x]);     return ret;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++)       if (a[i] == i) {         cout <<  YES  << endl;         for (int j = 1; j <= n; j++)           if (j != i) cout << i <<     << j << endl;         return 0;       }     int p = -1;     for (int i = 1; i <= n; i++)       if (mark[i] == false) {         int x = dfs(i);         if (x % 2) {           cout <<  NO  << endl;           return 0;         } else if (x == 2)           p = i;       }     if (p == -1) {       cout <<  NO  << endl;       return 0;     }     fill(mark, mark + MAXN, false);     cout <<  YES  << endl;     cout << p <<     << a[p] << endl;     mark[p] = mark[a[p]] = true;     for (int i = 1; i <= n; i++)       if (!mark[i]) add(p, i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void task();   int main() {     srand(time(0));     task();     return 0;   }   const int INF = 0x3f3f3f3f;   const int N = 1e6 + 10;   const int M = 1e7 + 100;   const int OLOLO = 0xFFFFFFFF;   int n, k;   long long int cnt[N];   set<int> vals;   long long int ans;   vector<int> masks;   void task() {     cin >> n >> k;     for (int i = 0; i < n; ++i) {       int a;       cin >> a;       ++cnt[a];       vals.insert(a);     }     for (int i = 0; i < (1 << 14); ++i) {       if (__builtin_popcount(i) == k) {         masks.push_back(i);       }     }     for (int val : vals) {       for (int mask : masks) {         int result = val & (mask ^ OLOLO);         result |= (val ^ OLOLO) & mask;         if (result < N) {           if (val == result) {             ans += cnt[val] * (cnt[val] - 1);           } else {             ans += cnt[val] * cnt[result];           }         }       }     }     cout << ans / 2;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   long long ln, lk, lm;   int x[105], y[105], r[105];   string vs[2];   void add(int id, int i, int x) {     string str =  (((1-abs((t- ;     str += to_string(i);     str +=  )))+abs((abs((t- ;     str += to_string(i);     str +=  ))-1)))* ;     str += to_string(x);     str +=  ) ;     if (vs[id] ==   )       vs[id] = str;     else {       vs[id] =  (  + vs[id] +  +  + str +  ) ;     }   }   void fmain() {     scanf( %d , &n);     for (int(i) = 0; (i) < (int)(2); (i)++) vs[i] =   ;     for (int(i) = 0; (i) < (int)(n); (i)++) {       scanf( %d%d%d , x + i, y + i, r + i);       add(0, i + 1, x[i] / 2);       add(1, i + 1, y[i] / 2);     }     for (int(i) = 0; (i) < (int)(2); (i)++) cout << vs[i] << endl;   }   int main() {     fmain();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int bit(int x, int i) { return (x >> i) & 1; }   inline int two(int x) { return 1 << x; }   int n, s[110], m, team[110], dp[20][1 << 20];   char op[110];   bool vis[20][1 << 20];   int go(int mi, int ban) {     if (mi == m) return 0;     int &ret = dp[mi][ban];     if (vis[mi][ban]) return ret;     vis[mi][ban] = 1;     ret = -514514514;     for (int i = 0; i < (int)(n); i++)       if (!bit(ban, i)) {         int now = go(mi + 1, ban | two(i));         int str = (op[mi] ==  p  ? s[i] : 0);         if (mi + 1 < m && team[mi + 1] != team[mi])           now = str - now;         else           now = str + now;         ret = max(ret, now);       }     return ret;   }   int main() {     scanf( %d , &(n));     for (int i = 0; i < (int)(n); i++) scanf( %d , &(s[i]));     scanf( %d , &(m));     for (int i = 0; i < (int)(m); i++) scanf(  %c %d , op + i, team + i);     sort(s, s + n, greater<int>());     n = m;     int ans = go(0, 0);     if (team[0] == 2) ans *= -1;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, numero;     cin >> n;     if (n < 10)       cout << n;     else {       n -= 9;       if (n < 181) {         if (n % 2 == 0) {           n /= 2;           n -= 1;           n %= 10;           cout << n;         } else {           n = (n + 1) / 2;           cout << ((n - 1) / 10) + 1;         }       } else {         n -= 180;         numero = ((n - 1) / 3) + 1;         numero += 99;         n = n % 3;         switch (n) {           case 0:             cout << numero % 10;             break;           case 1:             cout << numero / 100;             break;           default:             cout << (numero % 100) / 10;             break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p[3000], k, m = 0, c;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) {       k = p[i];       c = 1;       while (k > 0) {         c++;         k = p[k];       }       m = max(c, m);     }     cout << m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     char st[200010];     cin >> n >> st;     queue<int> d, r;     for (int i = 0; i < n; i++) {       if (st[i] ==  D )         d.push(i);       else         r.push(i);     }     while (!r.empty() && !d.empty()) {       int R = r.front(), D = d.front();       if (R < D) {         r.pop();         d.pop();         r.push(n + R);       } else {         d.pop();         r.pop();         d.push(n + D);       }     }     if (!r.empty())       cout <<  R  << endl;     else       cout <<  D  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long w, h;     cin >> w >> h;     long long res = 0;     if (w == 1 || h == 1) {       cout <<  0  << endl;       return 0;     }     for (long long i = 1; i < h; i++) {       for (long long j = 1; j < w; j++) res += min(i, h - i) * min(j, w - j);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long n, k;     cin >> n >> k;     priority_queue<long long, vector<long long>, greater<long long>> priq;     long long cur = 0, co = 0;     map<long long, long long> ma;     while (n > 0) {       if (n % 2) {         ma[cur]++;         co++;       }       n /= 2;       cur++;     }     if (co > k) {       cout <<  No  << endl;       return 0;     }     for (long long i = 63; i >= -63; i--) {       long long temp = ma[i] + co;       if (temp <= k) {         co += ma[i];         ma[i - 1] += (2 * ma[i]);         ma[i] = 0;       } else {         break;       }     }     for (long long i = 63; i >= -63; i--)       for (long long j = 0; j < ma[i]; j++) {         priq.push(i);       }     while (priq.size() < k) {       long long x = priq.top();       priq.pop();       priq.push(x - 1);       priq.push(x - 1);     }     vector<long long> ans;     cout <<  Yes  << endl;     while (!priq.empty()) {       long long x = priq.top();       ans.push_back(x);       priq.pop();     }     sort(ans.begin(), ans.end(), greater<long long>());     for (long long i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int dist[10010], DD[30][30];   int s[10010];   vector<int> all;   vector<int> a;   queue<int> q;   int dp[1 << 20];   int n;   void calc(int x) {     memset(dist, -1, sizeof(dist));     q.push(x), dist[x] = 0;     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < all.size(); i++) {         int del = all[i];         if (x - del > 0 && dist[x - del] == -1) {           dist[x - del] = dist[x] + 1;           q.push(x - del);         }         if (x + del <= n + 1 && dist[x + del] == -1) {           dist[x + del] = dist[x] + 1;           q.push(x + del);         }       }     }   }   void chmin(int &x, int y) { x = min(x, y); }   int main() {     int k, l;     scanf( %d%d%d , &n, &k, &l);     for (int i = 0; i < k; i++) {       int x;       scanf( %d , &x);       s[x] = 1;     }     while (l--) {       int x;       scanf( %d , &x);       all.push_back(x);     }     for (int i = n + 1; i >= 1; i--) {       s[i] ^= s[i - 1];     }     for (int i = 1; i <= n + 1; i++) {       if (s[i]) a.push_back(i);     }     for (int i = 0; i < a.size(); i++) {       int x = a[i];       calc(x);       for (int j = 0; j < a.size(); j++) {         DD[i][j] = dist[a[j]];       }     }     int N = a.size();     memset(dp, 0x3f, sizeof(dp));     dp[0] = 0;     for (int mask = 0; mask < (1 << N) - 1; mask++) {       if (dp[mask] == INF) continue;       int x = 0;       while (mask >> x & 1) x++;       for (int y = x + 1; y < N; y++) {         if (mask >> y & 1) continue;         if (DD[x][y] == -1) continue;         chmin(dp[mask | 1 << x | 1 << y], dp[mask] + DD[x][y]);       }     }     printf( %d n , dp[(1 << N) - 1] == INF ? -1 : dp[(1 << N) - 1]);     return 0;   }