import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] pro = new int[n]; int[] name = new int[n]; for(int i = 0; i < n; i++){ pro[i] = sc.nextInt(); } for(int i = 0; i < n; i++){ name[i] = sc.nextInt(); } int[] point = new int[101]; for(int i = 0; i < 101; i++){ point[i] = 0; } for(int i = 0; i < 101; i++){ for(int j = 0; j < n; j++){ if(name[j] == i){ point[i] = point[i] + pro[j]; } } } int ans = point[0]; for(int i = 1; i < 101; i++){ if(ans