import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Main3_1 {
public static void main(String[] args) {
List list = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int [] arrWeigth = new int[n];
int [] arrNumber = new int[n];
for (int i = 0; i < n; i++) {
arrWeigth[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
arrNumber[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < arrNumber[i]; j++) {
list.add(arrWeigth[i]);
}
}
List<List> subList = getSubList(list);
// System.out.println(subList);
Set set = new HashSet<>();
for (int i = 0; i < subList.size(); i++) {
int sum = 0;
for (Integer s : subList.get(i)) {
sum += s;
}
if (!set.contains(sum)) {
set.add(sum);
}
}
System.out.println(set);
System.out.println(set.size()+1);
}
/*主方法*/
public static List<List<Integer>> getSubList(List<Integer> list){
List<Integer> tempList;
List<List<Integer>> resList = new ArrayList<>();
for (int i = list.size(); i >= 0; i--) {
tempList = new ArrayList<>();
for (int j = 0; j < i; j++) {
tempList.add(list.get(j));
}
for (int j = 0; j < tempList.size(); j++) {
List<Integer> subList = new ArrayList<>();
for (int k = j; k < tempList.size(); k++) {
subList.add(tempList.get(k));
}
if (!resList.contains(subList)) {
resList.add(subList);
}
}
}
return resList;
}
}