malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   using ll = long long;   map<ll, int> dd;   map<pair<int, int>, int> f;   int n, pre[3][N];   ll a[3][N];   int dfs(int n, int m) {     if (pre[1][n] == -1 && pre[2][m] == -1 && pre[0][min(n, m)] == -1) return 0;     pair<int, int> p{n, m};     if (f.count(p)) return f[p];     int ans = 0;     if (pre[1][n] > pre[2][m])       ans = max(ans, dfs(pre[1][n], m) + 1);     else if (pre[2][m] != -1)       ans = max(ans, dfs(n, pre[2][m]) + 1);     if (pre[0][min(n, m)] != -1)       ans = max(ans, dfs(pre[0][min(n, m)], pre[0][min(n, m)]) + 1);     return f[p] = ans;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int j = 1; j <= 2; j++)       for (int i = 1; i <= n; i++) cin >> a[j][i], a[0][i] += a[j][i];     for (int i = 0; i <= 2; i++)       for (int j = 1; j <= n; j++) a[i][j] += a[i][j - 1];     for (int i = 0; i <= 2; i++) {       dd.clear();       dd[0] = 0;       pre[i][0] = -1;       for (int j = 1; j <= n; j++) {         pre[i][j] = max(pre[i][j - 1], dd.count(a[i][j]) ? dd[a[i][j]] : -1);         dd[a[i][j]] = j;       }     }     cout << dfs(n, n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   long long c[1010][1010];   const int mod = 1e9 + 7;   void pre() {     for (int i = 0; i <= 1005; i++) {       c[i][0] = c[i][i] = 1;     }     for (int i = 1; i <= 1005; i++) {       for (int j = 0; j <= i; j++) {         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;         ;       }     }   }   int main(int argc, char const *argv[]) {     scanf( %d%d%d , &n, &m, &k);     pre();     if (2 * k > n - 1 || 2 * k > m - 1) {       printf( 0 );     } else {       printf( %lld n , c[n - 1][k * 2] * c[m - 1][k * 2] % mod);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr long long MOD = 1e9 + 7;   long long cnt[710][710];   int a[500100];   int main() {     int n;     scanf( %d , &n);     for (int ii = 0; ii < n; ++ii) {       int t, x, y;       scanf( %d%d%d , &t, &x, &y);       if (t == 1) {         a[x] += y;         for (int i = 1; i <= 700; ++i) {           cnt[i][x % i] += y;         }       } else {         long long ans = 0;         if (x > 700) {           for (int i = y % x; i <= 500000; i += x) {             ans += a[i];           }         } else {           ans = cnt[x][y % x];         }         printf( %I64lld n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int MAXN = 3e5 + 5;   constexpr int MAXW = 1e4 + 5;   constexpr int MOD = 998244353;   constexpr long long INF = 2e10;   constexpr int LOG = 11;   string s;   vector<int> ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     reverse(s.begin(), s.end());     while (!s.empty()) {       if (s.back() ==  . ) {         ans.push_back(0);         s.pop_back();       } else {         s.pop_back();         if (s.back() ==  - ) {           ans.push_back(2);         } else {           ans.push_back(1);         }         s.pop_back();       }     }     for (auto p : ans) {       cout << p;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());   const ld pi = acos(0) * 2;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   template <typename CT, typename T>   inline void reset_container(CT &c, int sz, T v) {     c.resize(sz);     for (auto &x : c) x = v;   }   int n, k;   int a[101];   void solve() {     read(n);     read(k);     for (int i = (1); i <= (n); i++) read(a[i]);     sort(a + 1, a + n + 1);     if (a[n] - k > a[1] + k)       puts( -1 );     else       writeln(a[1] + k);   }   int main() {     int q;     read(q);     while (q--) solve();   }
#include <bits/stdc++.h>   using namespace std;   vector<bool> trust;   vector<int> massive(int** mas, int num) {     vector<int> mase;     int nume = num;     int nume1;     while (nume != 0) {       nume1 = nume;       nume = mas[nume - 1][0];     }     mase.push_back(0);     while (nume1 != 0) {       mase.push_back(nume1);       trust[nume1 - 1] = true;       nume1 = mas[nume1 - 1][1];     }     mase.push_back(0);     return mase;   }   int main() {     int n;     cin >> n;     int** mas = new int*[n];     for (int i = 0; i < n; i++) {       mas[i] = new int[2];       trust.push_back(false);       cin >> mas[i][0] >> mas[i][1];     }     vector<vector<int>> comp;     for (int i = 0; i < n; i++) {       vector<int> vect2;       if (!trust[i]) {         vect2 = massive(mas, i + 1);         comp.push_back(vect2);       }     }     vector<int> ansver;     ansver.push_back(0);     for (auto i : comp) {       for (auto j : i) {         if (j != 0) {           ansver.push_back(j);         }       }     }     ansver.push_back(0);     for (int i = 1; i < n + 1; i++) {       for (int j = 0; j < ansver.size(); j++) {         if (i == ansver[j]) {           cout << ansver[j - 1] <<     << ansver[j + 1];         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j;     cin >> n >> m;     for (i = 1; i <= n; i++) {       for (j = 0; j < m; j++) {         if (i % 4 == 0) {           if (j == 0)             cout <<  # ;           else             cout <<  . ;         } else if (i % 4 == 2) {           if (j == m - 1)             cout <<  # ;           else             cout <<  . ;         } else           cout <<  # ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 5;   long long n, m, i, t, j, k, l, x, y, z, s, e, p, q;   long long dg(long long s, long long e) {     if (e % 2) return 1 - s % 2;     if (s > e / 2) return s % 2;     if (s > e / 4) return 1;     return dg(s, e / 4);   }   int main() {     scanf( %lld , &n);     p = 0;     q = 1;     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &s, &e);       x = dg(s, e);       if (s > e / 2)         y = 1;       else         y = dg(s, e / 2);       if (p + q != 1)         continue;       else if (p)         p = 1 - x, q = 1 - y;       else         p = x, q = y;     }     printf( %lld %lld n , p, q);   }
#include <bits/stdc++.h>   using namespace std;   char s[5005];   int n, dp[5005][5];   const int inf = 1e7 + 5;   int go(int id, int need) {     if (id == n) return 0;     if (dp[id][need] != -1) return dp[id][need];     int ans = 0;     if (need == 1) {       if (s[id] ==  a )         ans = max(1 + go(id + 1, 1), 1 + go(id + 1, 2));       else         ans = max(go(id, 2), go(id + 1, 1));     } else if (need == 2) {       if (s[id] ==  a )         ans = max(go(id, 3), go(id + 1, 2));       else         ans = max(1 + go(id + 1, 2), 1 + go(id + 1, 3));     } else {       if (s[id] ==  a )         ans = 1 + go(id + 1, 3);       else         ans = go(id + 1, 3);     }     return dp[id][need] = ans;   }   int main() {     scanf(  %s , s);     n = strlen(s);     memset(dp, -1, sizeof(dp));     printf( %d n , go(0, 1));   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200;   typedef long long matrix[N][N];   const long long MOD = 1000000007;   const double EPS = 1e-8;   const double PI = 2 * acos(0);   const int maxn = 1e6 + 6;   int main() {     cin.sync_with_stdio(false);     int n, ans = 0, a[100100], p[100100];     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i] >> p[i];     int i = 1;     while (i <= n) {       ans += a[i] * p[i];       for (int j = i + 1; j <= n; j++) {         if (p[j] < p[i]) {           i = j - 1;           break;         }         ans += a[j] * p[i];         if (j == n) i = n;       }       i++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long n, m;   vector<string> pref;   long mov[500][500];   string temp;   string inp[500];   long er, td;   long bst[2000];   string tst;   long dp[4][500][500];   long nend, t, ncvrd, answ;   void ad(long &a, long b) {     a += b;     if (a >= 1000000009) a -= 1000000009;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> inp[i];       for (int j = 0; j < inp[i].size(); j++) inp[i][j] = inp[i][j] -  A  +  a ;     }     pref.push_back(  );     for (int i = 1; i <= m; i++) {       temp =   ;       for (int j = 0; j < inp[i].size(); j++) {         temp += inp[i][j];         pref.push_back(temp);       }     }     for (int i = 0; i < pref.size(); i++) {       bst[i] = -1;       for (int j = 1; j <= m; j++) {         if (inp[j].size() > pref[i].size()) continue;         er = 0;         if (bst[i] >= 0 && inp[j].size() <= inp[bst[i]].size()) continue;         td = pref[i].size() - inp[j].size();         for (int q = 0; q < inp[j].size(); q++)           if (pref[i][q + td] != inp[j][q]) {             er = 1;             break;           }         if (er == 0) bst[i] = j;       }     }     for (int i = 0; i < pref.size(); i++)       for (int ad = 0; ad < 26; ad++) {         mov[i][ad] = -1;         tst = pref[i];         tst += char( a  + ad);         for (int j = 0; j < pref.size(); j++) {           if (pref[j].size() > tst.size()) continue;           er = 0;           td = tst.size() - pref[j].size();           if (mov[i][ad] != -1 && pref[mov[i][ad]].size() > pref[j].size())             continue;           for (int q = 0; q < pref[j].size(); q++)             if (pref[j][q] != tst[td + q]) {               er = 1;               break;             }           if (er == 0) mov[i][ad] = j;         }       }     dp[0][0][0] = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= pref.size(); j++)         for (int q = 0; q <= i; q++) dp[1 - i % 2][j][q] = 0;       for (int end = 0; end < pref.size(); end++)         for (int cvrd = 0; cvrd <= i; cvrd++)           if (cvrd >= i - 25)             if (dp[i % 2][end][cvrd])               for (int achar = 0; achar < 26; achar++) {                 nend = mov[end][achar];                 t = bst[nend];                 if (t > -1 && inp[t].size() + cvrd > i)                   ncvrd = i + 1;                 else                   ncvrd = cvrd;                 ad(dp[1 - i % 2][nend][ncvrd], dp[i % 2][end][cvrd]);               }     }     answ = 0;     for (int end = 0; end < pref.size(); end++) ad(answ, dp[n % 2][end][n]);     cout << answ << endl;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a, b;     for (int i = 0; i < n / 2; ++i) {       a.push_back(i);     }     for (int i = 0; i < n - n / 2; ++i) {       b.push_back(i + n / 2);     }     cout << a.size() * b.size() << endl;     for (int i = 0; i < a.size(); ++i) {       for (int j = 0; j < b.size(); ++j) {         cout << a[i] + 1 <<     << b[j] + 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s1[100005], s2[100005];   int main() {     int l1, l2, i;     char tmp;     while (~scanf( %s , s1)) {       l1 = strlen(s1);       for (i = l1 - 1, l2 = 0, tmp = 0; i >= 0; i--) {         if (s1[i] >= tmp) {           tmp = s1[i];           s2[l2++] = s1[i];         }       }       for (i = l2 - 1; i >= 0; i--) {         printf( %c , s2[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 2010;   int n, m;   long long f[N][N], g[N][N], h[N][N], o[N][N], p[N][N], ans;   int main() {     cin >> n >> m;     memset(f, 0, sizeof(f));     memset(g, 0, sizeof(g));     memset(h, 0, sizeof(h));     memset(o, 0, sizeof(o));     for (int i = 1; i <= n; ++i) {       for (int j = 2; j <= m; ++j) {         (f[i][j] += 1 + g[i - 1][j] * j % mod + h[i - 1][j]) %= mod;         o[i][j] = (f[i][j] - f[i - 1][j]) % mod;       }       for (int j = 2; j <= m; ++j) {         g[i][j] = (g[i][j - 1] + f[i][j]) % mod;         h[i][j] = (h[i][j - 1] + f[i][j] * (1 - j) % mod) % mod;       }     }     memset(p, 0, sizeof(p));     for (int i = 1; i <= n; ++i)       for (int j = 2; j <= m; ++j) p[i][j] = (p[i - 1][j] + o[i][j]) % mod;     ans = 0;     for (int i = 1; i <= n; ++i)       for (int j = 2; j <= m; ++j) {         (ans += (m - j + 1) * o[i][j] % mod * p[n - i + 1][j] % mod) %= mod;       }     cout << (ans + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 35;   const long long N = 1e7 + 35;   const long long mod = 3e18;   const double eps = 1e-6;   string a[MAX];   map<string, int> mm;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       for (int j = 1; j <= 9; j++) {         for (int k = 0; k + j < 10; k++) {           string s = a[i].substr(k, j);           if (mm[s] == 0)             mm[s] = i + 1;           else if (mm[s] != i + 1)             mm[s] = -1;         }       }     }     string s;     for (int i = 0; i < n; i++) {       bool ok = 0;       for (int j = 1; j <= 9; j++) {         for (int k = 0; k + j < 10; k++) {           s = a[i].substr(k, j);           if (mm[s] != -1) {             ok = 1;             break;           }         }         if (ok) break;       }       cout << s <<   n ;     }   }
#include <bits/stdc++.h>   const int kMaxN = 1e7 + 5;   int N;   int phi[kMaxN];   long long prime[kMaxN], primeList[kMaxN], count[kMaxN];   int k = 0;   void ComputePhi() {     for (int i = 1; i <= N; i++) {       phi[i] = i;     }     for (int i = 2; i <= N; i++) {       if (phi[i] == i) {         for (int j = i; j <= N; j += i) {           phi[j] = phi[j] / i * (i - 1);         }       }     }   }   void ComputePrimes() {     for (int i = 2; i <= N; i++) {       if (prime[i] != 0) {         count[prime[i]]++;         continue;       }       for (int j = i; j <= N; j += i) {         if (!prime[j]) {           prime[j] = i;         }       }       count[prime[i]]++;     }     for (int i = 2; i <= N; i++) {       while (count[i] > 0) {         primeList[++k] = i;         count[i]--;       }     }   }   int main() {     scanf( %d , &N);     ComputePhi();     ComputePrimes();     long long sol = 0;     for (int i = 2; i <= N; i++) {       sol += i - 1 - phi[i];     }     sol *= -1;     int cursor = k;     for (int i = 1; i <= k; i++) {       while (cursor >= i && primeList[i] * primeList[cursor] > N) {         cursor--;       }       if (cursor >= i) {         sol += 2LL * (cursor - i);       }     }     cursor = k;     for (int i = 1; i <= k; i++) {       while (cursor > 0 && primeList[i] * primeList[cursor] > N) {         cursor--;       }       cursor++;       if (2 * primeList[i] <= N && cursor < i &&           primeList[i] * primeList[cursor] > N) {         sol += 3LL * (i - cursor);       }     }     printf( %lld n , sol);     return 0;   }
#include <cassert>   #include <climits>   #include <cstdio>   #include <cstdlib>   #include <cstring>   #include <cmath>   #include <cctype>   #include <vector>   #include <string>   #include <queue>   #include <deque>   #include <stack>   #include <set>   #include <map>   #include <utility>   #include <algorithm>   #include <iostream>   #include <sstream>   #include <numeric>   using namespace std;      #define SIZE(x) int((x).size())   #define REP(i,c) for(auto &i : c)   #define pb push_back   #define eb emplace_back   typedef long long i64;   typedef unsigned long long u64;   const double EPS = 1e-12;   const int INF = 999999999;   typedef vector<int> VI;   typedef vector<string> VS;   typedef pair<int,int> PII;   typedef vector<PII> VPII;      const int MAXN=1500;      int n,m;   int a[MAXN][MAXN];   int f[MAXN][MAXN];       // colors in square (i,j) ... (i+f[i]][j]-1, j+f[i][j-1]), order max(x-i,y-i)   VPII sq[2][MAXN];   int cur;      bool seen[MAXN*MAXN+1];      int ans[MAXN+1];      void Solve() {       scanf( %d%d ,&n,&m);       for(int i=0;i<n;i++)           for(int j=0;j<n;j++) {               scanf( %d ,&a[i][j]);           }          fill(ans+1,ans+(n+1),0);       cur=0;       for(int i=n-1;i>=0;i--) {           int pre=cur;           cur=cur^1;           for(int j=n-1;j>=0;j--) {               sq[cur][j]={{0,a[i][j]}};               if(i==n-1 || j==n-1) {                   f[i][j]=1;                   ans[f[i][j]]++;                   continue;               }                  seen[a[i][j]]=1;               VI ps={0,0,0};               vector<const VPII*> vs={&sq[cur][j+1],&sq[pre][j],&sq[pre][j+1]};               while(SIZE(sq[cur][j])<=m) {                   int md=INF;                   int mi=-1;                   for(int i=0;i<3;i++) {                       const VPII& v=*vs[i];                       if(ps[i]==SIZE(v)) continue;                       if(v[ps[i]].first<md) {                           md=v[ps[i]].first;                           mi=i;                       }                   }                   if(mi<0) break;                   const PII &u=(*vs[mi])[ps[mi]++];                   if(!seen[u.second]) {                       seen[u.second]=1;                       sq[cur][j].eb(u.first+1,u.second);                   }               }               REP(p,sq[cur][j]) seen[p.second]=0;                  f[i][j]=min(n-i,n-j);               if(SIZE(sq[cur][j])>m) f[i][j]=min(f[i][j],sq[cur][j][m].first);               ans[f[i][j]]++;           }       }          for(int i=n-1;i>=1;i--) ans[i]+=ans[i+1];       for(int i=1;i<=n;i++) printf( %d n ,ans[i]);      }      int main() {       Solve();          return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool flag;   const double eps = 1e-12;   double sqr(double x) { return x * x; }   void read(complex<double> &A) {     double x, y;     cin >> x >> y;     A = complex<double>(x, y);   }   bool tri(complex<double> A, double ra, complex<double> B, double rb) {     double a[] = {abs(A - B), ra, rb};     sort(a, a + 3);     return (a[0] + a[1] + eps > a[2]);   }   bool ok(complex<double> A, double ra, complex<double> B, double rb,           complex<double> C, double rc) {     if (abs(A - C) < ra + eps && abs(B - C) < rb + eps) return true;     if (!tri(A, ra, B, rb)) return false;     double d = abs(A - B);     double t = (sqr(ra) + sqr(d) - sqr(rb)) / 2.0 / sqr(d);     double h = sqrt(max(sqr(ra) - sqr(t * d), 0.0));     double mx = A.real() + t * (B.real() - A.real()),            my = A.imag() + t * (B.imag() - A.imag());     double dx, dy;     if (abs(A.imag() - my) < eps) {       dy = h * (A.real() - mx) / sqrt(sqr(A.real() - mx) + sqr(A.imag() - my)),       dx = dy * (my - A.imag()) / (A.real() - mx);     } else {       dx = h * (A.imag() - my) / sqrt(sqr(A.real() - mx) + sqr(A.imag() - my)),       dy = dx * (mx - A.real()) / (A.imag() - my);     }     complex<double> tmp;     tmp = complex<double>(mx + dx, my + dy);     if (abs(tmp - C) < rc + eps) return true;     tmp = complex<double>(mx - dx, my - dy);     if (abs(tmp - C) < rc + eps) return true;     return false;   }   bool check(complex<double> A, double ra, complex<double> B, double rb,              complex<double> C, double rc) {     if (ok(A, ra, B, rb, C, rc)) return true;     if (ok(A, ra, C, rc, B, rb)) return true;     if (ok(B, rb, C, rc, A, ra)) return true;     return false;   }   int main() {     double t1, t2;     complex<double> A, B, C;     cin >> t1 >> t2;     read(A);     read(B);     read(C);     if (abs(A - C) + abs(B - C) < abs(A - B) + t2 + eps) {       double ans = min(abs(A - C) + abs(B - C) + t1, abs(A - B) + t2);       printf( %.9lf , ans);       return 0;     }     double low = 0, high = min(abs(A - C) + t1, abs(A - B) + t2), mid;     int k = 100;     while (k--) {       mid = (low + high) / 2.0;       if (check(A, mid, B, abs(A - B) + t2 - mid, C, abs(A - C) + t1 - mid))         low = mid;       else         high = mid;     }     printf( %.9lf , mid);   }
#include <bits/stdc++.h>   using namespace std;   double PI = acos(-1);   double EPS = 1e-7;   int INF = 1000000000;   int MOD = 1000000007;   int MAXINT = 2147483647;   long long INFLL = 1000000000000000000LL;   long long MAXLL = 9223372036854775807LL;   int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};   int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};   int rem[1000005];   int lol[1000005];   int pos[1000005];   int nx[1000005][20];   int bit[1000005];   int n, m;   void build() {     memset(bit, 0, sizeof(bit));     for (int(a) = (1); (a) <= (n); (a)++) {       pos[lol[a]] = a;       nx[a][0] = lol[a];       if (rem[lol[a]]) nx[a][0] = INF;     }     for (int(k) = (1); (k) <= (19); (k)++) {       for (int(a) = (1); (a) <= (n - (1 << k) + 1); (a)++) {         nx[a][k] = min(nx[a][k - 1], nx[a + (1 << (k - 1))][k - 1]);       }     }   }   int query(int pos, int lim) {     int ret = 0;     for (int(a) = (19); (a) >= (0); (a)--) {       if (pos + (1 << a) - 1 <= n && nx[pos][a] > lim) {         pos += (1 << a);         ret += (1 << a);       }     }     return ret;   }   void update(int bit[], int x, int v) {     for (int i = x; i <= n; i += (i & -i)) {       bit[i] += v;     }   }   int query(int bit[], int x) {     int res = 0;     for (int i = x; i >= 1; i -= (i & -i)) {       res += bit[i];     }     return res;   }   int query(int bit[], int l, int r) { return query(bit, r) - query(bit, l - 1); }   long long calc() {     build();     long long ans = 0;     for (int(v) = (1); (v) <= (n); (v)++) {       int a = pos[v];       if (rem[v] == 1) {         int tmp = query(a + 1, lol[a]);         ans += tmp;         ans -= query(bit, a + 1, a + tmp);         update(bit, a, 1);       }     }     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int(a) = (1); (a) <= (n); (a)++) {       scanf( %d , &lol[a]);       rem[a] = 1;     }     for (int(a) = (1); (a) <= (m); (a)++) {       int k;       scanf( %d , &k);       rem[k] = 0;     }     long long ans = n - m;     ans += calc();     reverse(lol + 1, lol + n + 1);     ans += calc();     printf( %I64d n , ans);   }