/*Grigory Shovkoplyas in the house*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<cstdlib>
#include<ctime>
using namespace std;

int x, n;
vector<int> a, b;
vector<pair<long long, int> > t;

int step(int n)
{
  int i = 1;
  while(i < n)
    i <<= 1;
  return i;
}

void update(int v, pair<long long, int> k)
{
  int i = v + x;
  t[i] = k;
  while (i > 1)
  {
    i /= 2;
    t[i] = max(t[2 * i], t[2 * i + 1]);
  }
} 

pair<long long, int> get_max(int v, int l, int r, int a, int b)
{
  if(r < a || l > b)
    return make_pair(0, 0);
  if(a <= l && b >= r)
    return t[v];
  int m = (l + r) / 2;
  return max(get_max(2 * v, l, m, a, b), get_max(2 * v + 1, m + 1, r, a, b));
}

int main()
{
  freopen("assault.in", "r", stdin);
  freopen("assault.out", "w", stdout);
  cin >> n;
  a.resize(n); 
  b.resize(n);
  for(int i = 0; i < n; i++)
    cin >> a[i];
  for(int i = 0; i < n; i++)
    cin >> b[i];
  x = step((int)2e5);
  t.assign(2 * x, make_pair(0, -1));
  vector<int> prev(n);
  for (int i = 0; i < n; i++)
  {
    pair<long long, int> maxx = get_max(1, 0, x, 0, b[i]);
    if(maxx.first == 0)
    {
      if(a[i] > t[b[i] + x].first)  {
        prev[i] = -1;
        update(b[i], make_pair(a[i], i));
      }
      continue;
    }
    if(maxx.first + a[i] > t[b[i] + x].first)
    {  
      prev[i] = maxx.second;
      update(b[i], make_pair(maxx.first + a[i], i));
    }
  }
  pair<long long, int> maxx = get_max(1, 0, x - 1, 0, x - 1);
  long long ans = maxx.first;
  int ansi = maxx.second;
  cout << ans << endl;
  vector<int> p(1, ansi);
  while(prev[ansi] != -1)
    ansi = prev[ansi], p.push_back(ansi);
  cout << p.size() << endl;
  reverse(p.begin(), p.end());
  for(int i = 0; i < (int)p.size(); i++)
    cout << p[i] + 1 << ' ';
  cout << endl;     

  return 0;
}