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

#define taskname "assault"

int main()
{
  freopen(taskname".in", "r", stdin);
  freopen(taskname".out", "w", stdout);
  int n;
  cin >> n;
  assert(n <= 1000);
  vector<int> a(n), t(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> t[i];
  vector<long long> dp(n);
  vector<int> prev(n);
  for (int i = 0; i < n; i++)
  {
    int maxi = -1;
    for (int j = 0; j < i; j++)
      if (t[j] < t[i] && (maxi < 0 || dp[j] > dp[maxi]))
        maxi = j;
    prev[i] = maxi;
    dp[i] = a[i];
    if(maxi != -1)
      dp[i] += dp[maxi];    
  }
  long long ans = 0;
  int ansi = 0;
  for (int i = 0; i < n; i++)
  {
    if(ans < dp[i])
      ans = dp[i], ansi = i;
  }
  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;
}