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

public class dragons_pk {

	PrintWriter out;
	BufferedReader br;
	StringTokenizer st;

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

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

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

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

	public void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			int t = nextInt() - 1;
			a[t] = i;
			b[i] = t;
		}
		int k = nextInt();
		TreeSet<Integer> available = new TreeSet<Integer>();
		for (int i = 0; i < k ; i++) {
			available.add(a[nextInt() - 1]);
		}
		
		int cur = 0;
		long ans = 0;
		ArrayList<Integer> res = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int go = available.first();
			if (available.higher(cur - 1) != null) {
				go = available.higher(cur - 1);
			}
			
			ans = ans + ((go - cur + n) % n);
			available.remove(go);
			if (i < n - k) {
				available.add(a[nextInt() - 1]);
			}
			res.add(b[go] + 1);
			cur = go;
		}
		out.println(ans + 60 + n);
		for (int i = 0; i < n; i++) {
			out.print(res.get(i));
			if (i < n - 1)
				out.print(' ');
		}
		out.println();
	}

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

			br = new BufferedReader(new FileReader("dragons.in"));
			out = new PrintWriter("dragons.out");

			solve();

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

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