func_code_string: #include <bits/stdc++.h>   using namespace std;   void upd(int& a, int b) { a = max(a, b); }   int main() {     int n, m;     cin >> n >> m;     vector<int> a(n), b(m);     for (int i = 0; i < (int)n; ++i) cin >> a[i];     for (int i = 0; i < (int)m; ++i) cin >> b[i];     sort(a.begin(), a.end());     sort(b.begin(), b.end());     vector<int> to_seg(n);     int seg = 0;     vector<int> start, end;     for (int i = 0; i < (int)a.size(); ++i) {       if (i == 0 || a[i] != a[i - 1] + 1) {         seg++;         if (i != 0) end.push_back(i - 1);         start.push_back(i);       }       to_seg[i] = seg - 1;     }     end.push_back(n - 1);     vector<int> z(start.size()), d(start.size());     for (int segment = 0; segment < (int)start.size(); ++segment) {       int first = -1;       int cnt = 0;       for (int i = 0; i < (int)m; ++i) {         if (b[i] < a[start[segment]])           first = i;         else if (b[i] <= a[end[segment]])           cnt++;       }       int cnt_orig = cnt;       upd(d[segment], cnt);       if (segment) upd(d[segment], cnt + z[segment - 1]);       if (first != -1) {         for (int i = first; i >= 0; --i) {           ++cnt;           int r = a[start[segment]];           int l = b[i];           if (start[segment] - (r - l) >= 0) {             int Q = 0;             int X = to_seg[start[segment] - (r - l)] - 1;             if (X >= 0) Q = z[X];             upd(d[segment], cnt + Q);           }         }       }       cnt = 0;       for (int i = first + cnt_orig + 1; i < m; ++i) {         ++cnt;         int l = a[end[segment]];         int r = b[i];         if (end[segment] + (r - l) < n) {           upd(z[to_seg[end[segment] + (r - l)]], d[segment] + cnt);         }       }       upd(z[segment], d[segment]);     }     cout << *max_element(z.begin(), z.end()) << endl;   }   