import java.io.*;
public class Main {
static int n;
static int[][][] dp;
static int[] w;
static int[][] num;
static int[][] cost;
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
n = Integer.parseInt(in.readLine());
dp = new int[n + 2][n + 2][3];
num = new int[n + 1][n + 1];
cost = new int[n + 1][n + 1];
w = new int[n + 1];
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
num[i][j] = j - i + 1;
for (int c = 0; c < 3; c++) {
dp[i][j][c] = Integer.MAX_VALUE;// 初始化为无效
}
}
}
String[] str = in.readLine().split(" ");
for (int i = 1; i <= n; i++) {
w[i] = Integer.parseInt(str[i - 1]);
w[i] += w[i - 1];
}
str = in.readLine().split(" ");
for (int i = 1; i <= n; i++) {
int color = Integer.parseInt(str[i - 1]);
dp[i][i][color] = 0;// 有效
}
for (int len = 2; len <= n; len++) {
for (int l = 1; l + len - 1 <= n; l++) {
int r = l + len - 1;
for (int c = 0; c < 3; c++) {
int cur = Integer.MAX_VALUE;
for (int k = l; k < r; k++) {
if (dp[l][k][c] != Integer.MAX_VALUE && dp[k + 1][r][c] != Integer.MAX_VALUE) {
cur = Math.min(dp[l][k][c] + dp[k + 1][r][c] + w[r] - w[l - 1], cur);
}
}
if (cur == Integer.MAX_VALUE)
continue;// 无效数据
dp[l][r][(c + 1) % 3] = cur;
num[l][r] = 1;
cost[l][r] = Math.min(dp[l][r][0], Math.min(dp[l][r][1], dp[l][r][2]));
}
}
}
for (int len = 2; len <= n; len++) {
for (int l = 1; l + len - 1 <= n; l++) {
int r = l + len - 1;
for (int k = l; k < r; k++) {
if (num[l][r] > num[l][k] + num[k + 1][r]) {
num[l][r] = num[l][k] + num[k + 1][r];
cost[l][r] = cost[l][k] + cost[k + 1][r];
} else if (num[l][r] == num[l][k] + num[k + 1][r]) {
cost[l][r] = Math.min(cost[l][k] + cost[k + 1][r], cost[l][r]);
}
}
}
}
out.write(num[1][n] + " " +cost[1][n]);
out.flush();
out.close();
in.close();
}
}