import java.io.*;
import java.util.*;

public class assault_pk_wa {

	void solve() throws IOException {
		int n = nextInt();
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = nextInt();
		}
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		long[] fenv = new long[100_000 + 2];
		Arrays.fill(fenv, Long.MIN_VALUE);
		set(fenv, 0, 0);
		long[] l = new long[n];
		long max = -1;
		for (int i = 0; i < n; i++) {
			long res = get(fenv, a[i]);
			l[i] = res + b[i];
			set(fenv, a[i], l[i]);
			max = Math.max(max, l[i]);
		}
		ArrayList<Integer> ans = new ArrayList<Integer>();
		int prev = 100_000 + 3;
		out.println(max);
		for (int i = n - 1; i >= 0; i--) {
			if (max != l[i] || a[i] > prev)
				continue;
			ans.add(i + 1);
			max -= b[i];
			prev = a[i];
		}
		Collections.reverse(ans);
		out.println(ans.size());
		for (int i = 0; i < ans.size(); i++) {
			out.print(ans.get(i) + " ");
		}
	}

	int f(int i) {
		return i - (i & (i - 1));
	}

	private long get(long[] fenv, int i) {
		i++;
		long ans = Long.MIN_VALUE;
		while (i > 0) {
			ans = Math.max(ans, fenv[i]);
			i -= f(i);
		}
		return ans;
	}

	private void set(long[] fenv, int i, long v) {
		i++;
		while (i < fenv.length) {
			fenv[i] = Math.max(fenv[i], v);
			i += f(i);
		}
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			br = new BufferedReader(new FileReader(new File("assault.in")));
			out = new PrintWriter("assault.out");
			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new assault_pk_wa().run();
	}

	String nextToken() throws IOException {
		while ((st == null) || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}
}
