#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#pragma GCC optimize("O3")
typedef unsigned int uint;
typedef int ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define oset tree<pair<int,int>, null_type,less< pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace __gnu_pbds;
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n + 1), b(m + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    oset s;
    vector<ll> ans;
    
    
    
    for (int i = 1; i <= m; i++)
    {
        cin >> b[i];
        if (i < n)
        {
            s.insert({b[i], i});
            continue;
        }
         s.insert({b[i], i});
        if (i > n)
        {
            s.erase({b[i - n], i - n});
        }
        
        bool ok2 = 1;
        for(int j = 1;j <= 30;j++){
            
            ll el = (rand()%n);
            ll ind = s.find_by_order(el)->second; 
            if( a[el+1] != ind-(i-n)  ){
                ok2=0;
                break;
            }
        }
        
        
        
        if(!ok2)continue;
        
        bool ok = 1;
        ll cur = 0;
        for (auto g : s)
        {
            cur++;
            if (g.second != a[cur] + (i - n))
            {
                ok = 0;
                break;
            }
        }
        if (ok)
        {
            ans.push_back(i - n + 1);
        }
    }
    cout << ans.size() << endl;
    for (auto g : ans)
    {
        cout << g << ' ';
    }
}
signed main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |