#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
void compr (vi &a)
{
vi cur = a;
sort(ALL(cur));
cur.resize(unique(ALL(cur)) - cur.begin());
forn (i, sz(a))
a[i] = lower_bound(ALL(cur), a[i]) - cur.begin();
}
const int inf = (int)1e9;
struct segtree
{
int tsz;
vii vals;
segtree ()
{
tsz = -1;
}
segtree (int n)
{
tsz = 1;
while (tsz < n)
tsz *= 2;
vals.assign(2 * tsz, mp(0, 0));
}
void put (int pos, const pii &what)
{
vals[pos += tsz] = what;
for (pos >>= 1; pos > 0; pos >>= 1)
vals[pos] = max(vals[2 * pos], vals[2 * pos + 1]);
}
pii getseg (int l, int r)
{
pii ans(0, 0);
for (l += tsz, r += tsz; l < r; l >>= 1, r >>= 1)
{
if (l & 1)
ans = max(ans, vals[l++]);
if (r & 1)
ans = max(ans, vals[--r]);
}
return ans;
}
};
struct segtree2d
{
vector<segtree> vals;
vector<vii> who;
int tsz = 1;
segtree2d (const vi &a, const vi &b)
{
const int A = *max_element(ALL(a));
const int n = sz(a);
tsz = 1;
while (tsz <= A + 1)
tsz *= 2;
vals.resize(2 * tsz);
who.resize(2 * tsz);
forn (i, n)
who[a[i] + tsz].pb(mp(b[i], -i));
forn (i, A + 1)
sort(ALL(who[i + tsz]));
for (int i = tsz - 1; i >= 1; i--)
{
who[i].resize(sz(who[2 * i]) + sz(who[2 * i + 1]));
merge(ALL(who[2 * i]), ALL(who[2 * i + 1]), who[i].begin());
}
forn (i, 2 * tsz) if (i != 0)
vals[i] = segtree(sz(who[i]));
}
pii query (int pos, int d, int u)
{
int l = lower_bound(ALL(who[pos]), mp(d, -inf)) - who[pos].begin();
int r = lower_bound(ALL(who[pos]), mp(u, -inf)) - who[pos].begin();
return vals[pos].getseg(l, r);
}
pii rect (int l, int r, int d, int u)
{
pii ans(0, 0);
for (l += tsz, r += tsz; l < r; l >>= 1, r >>= 1)
{
if (l & 1)
ans = max(ans, query(l++, d, u));
if (r & 1)
ans = max(ans, query(--r, d, u));
}
return ans;
}
void put_node (int v, int b, int what, int nid)
{
int pos = lower_bound(ALL(who[v]), mp(b, -inf)) - who[v].begin();
assert(pos != sz(who[v]) && who[v][pos].fst == b);
vals[v].put(pos, mp(what, nid));
}
void put (int a, int b, int what, int nid)
{
put_node(a += tsz, b, what, nid);
for (a >>= 1; a > 0; a >>= 1)
put_node(a, b, what, nid);
}
};
void solve (int n)
{
vi a(n), b(n);
forn (i, n) cin >> a[i];
forn (i, n) cin >> b[i];
forn (i, n) a[i] = -a[i];
compr(a);
compr(b);
segtree2d data(a, b);
const int A = *max_element(ALL(a));
const int B = *max_element(ALL(b));
vi dp(n);
vi ptr(n, -1);
for (int i = n - 1; i >= 0; i--)
{
pii cur = data.rect(a[i], A + 1, b[i], B + 1);
dp[i] = cur.fst + 1;
ptr[i] = (cur.fst == 0 ? -1 : -cur.snd);
data.put(a[i], b[i], dp[i], -i);
}
vi who;
const int cpos = max_element(ALL(dp)) - dp.begin();
int pos = cpos;
while (pos != -1)
{
who.pb(pos);
assert(0 <= pos && pos < n);
pos = ptr[pos];
}
assert(dp[cpos] == sz(who));
cout << dp[cpos] << '\n';
forn (i, sz(who))
cout << who[i] + 1 << ' ';
cout << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
while (cin >> n)
solve(n);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgZnN0IGZpcnN0CiNkZWZpbmUgc25kIHNlY29uZAojZGVmaW5lIGZvcm4oaSwgbikg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NdID0gbWF4KHZhbHNbMiAqIHBvc10sIHZhbHNbMiAqIHBvcyArIDFdKTsKICAgIH0KCiAgICBwaWkgZ2V0c2VnIChpbnQgbCwgaW50IHIpCiAgICB7CiAgICAgICAgcGlpIGFucygwLCAwKTsKICAgICAgICBmb3IgKGwgKz0gdHN6LCByICs9IHRzejsgbCA8IHI7IGwgPj49IDEsIHIgPj49IDEpCiAgICAgICAgewogICAgICAgICAgICBpZiAobCAmIDEpCiAgICAgICAgICAgICAgICBhbnMgPSBtYXgoYW5zLCB2YWxzW2wrK10pOwogICAgICAgICAgICBpZiAociAmIDEpCiAgICAgICAgICAgICAgICBhbnMgPSBtYXgoYW5zLCB2YWxzWy0tcl0pOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYW5zOwogICAgfQp9OwoKc3RydWN0IHNlZ3RyZWUyZAp7CiAgICB2ZWN0b3I8c2VndHJlZT4gdmFsczsKICAgIHZlY3Rvcjx2aWk+IHdobzsKICAgIGludCB0c3ogPSAxOwoKICAgIHNlZ3RyZWUyZCAoY29uc3QgdmkgJmEsIGNvbnN0IHZpICZiKQogICAgewogICAgICAgIGNvbnN0IGludCBBID0gKm1heF9lbGVtZW50KEFMTChhKSk7CiAgICAgICAgY29uc3QgaW50IG4gPSBzeihhKTsKCiAgICAgICAgdHN6ID0gMTsKICAgICAgICB3aGlsZSAodHN6IDw9IEEgKyAxKQogICAgICAgICAgICB0c3ogKj0gMjsKCiAgICAgICAgdmFscy5yZXNpemUoMiAqIHRzeik7CiAgICAgICAgd2hvLnJlc2l6ZSgyICogdHN6KTsKICAgICAgICBmb3JuIChpLCBuKQogICAgICAgICAgICB3aG9bYVtpXSArIHRzel0ucGIobXAoYltpXSwgLWkpKTsKCiAgICAgICAgZm9ybiAoaSwgQSArIDEpCiAgICAgICAgICAgIHNvcnQoQUxMKHdob1tpICsgdHN6XSkpOwoKICAgICAgICBmb3IgKGludCBpID0gdHN6IC0gMTsgaSA+PSAxOyBpLS0pCiAgICAgICAgewogICAgICAgICAgICB3aG9baV0ucmVzaXplKHN6KHdob1syICogaV0pICsgc3ood2hvWzIgKiBpICsgMV0pKTsKICAgICAgICAgICAgbWVyZ2UoQUxMKHdob1syICogaV0pLCBBTEwod2hvWzIgKiBpICsgMV0pLCB3aG9baV0uYmVnaW4oKSk7CiAgICAgICAgfQoKICAgICAgICBmb3JuIChpLCAyICogdHN6KSBpZiAoaSAhPSAwKQogICAgICAgICAgICB2YWxzW2ldID0gc2VndHJlZShzeih3aG9baV0pKTsKICAgIH0KCiAgICBwaWkgcXVlcnkgKGludCBwb3MsIGludCBkLCBpbnQgdSkKICAgIHsKICAgICAgICBpbnQgbCA9IGxvd2VyX2JvdW5kKEFMTCh3aG9bcG9zXSksIG1wKGQsIC1pbmYpKSAtIHdob1twb3NdLmJlZ2luKCk7CiAgICAgICAgaW50IHIgPSBsb3dlcl9ib3VuZChBTEwod2hvW3Bvc10pLCBtcCh1LCAtaW5mKSkgLSB3aG9bcG9zXS5iZWdpbigpOwogICAgICAgIHJldHVybiB2YWxzW3Bvc10uZ2V0c2VnKGwsIHIpOwogICAgfQoKICAgIHBpaSByZWN0IChpbnQgbCwgaW50IHIsIGludCBkLCBpbnQgdSkKICAgIHsKICAgICAgICBwaWkgYW5zKDAsIDApOwogICAgICAgIGZvciAobCArPSB0c3osIHIgKz0gdHN6OyBsIDwgcjsgbCA+Pj0gMSwgciA+Pj0gMSkKICAgICAgICB7CiAgICAgICAgICAgIGlmIChsICYgMSkKICAgICAgICAgICAgICAgIGFucyA9IG1heChhbnMsIHF1ZXJ5KGwrKywgZCwgdSkpOwogICAgICAgICAgICBpZiAociAmIDEpCiAgICAgICAgICAgICAgICBhbnMgPSBtYXgoYW5zLCBxdWVyeSgtLXIsIGQsIHUpKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFuczsKICAgIH0KCiAgICB2b2lkIHB1dF9ub2RlIChpbnQgdiwgaW50IGIsIGludCB3aGF0LCBpbnQgbmlkKQogICAgewogICAgICAg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