#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX = 10005;
typedef pair <int, int> PT;
int N;

int main()
{
	int k;
	int t = 0;
	vector <int> a;
	vector <pair <PT, int> > v;

	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &k);
		t += k;
	}

	for (int i = 0; i < t; i++)
	{
		scanf("%d", &k);
		a.push_back(k);
	}

	for (int i = 0; i < t; i++)
	{
		scanf("%d", &k);
		v.push_back(make_pair(PT(a[i], -k), i + 1));
	}

	sort(v.begin(), v.end());

	int ans = 0;
	t = 0;

	for (int i = 0; i < v.size(); i++)
	{
		pair <PT, int> p = v[i];
		t += p.first.first;
		ans += -p.first.second * t;
	}

	printf("%d\n", ans);

	for (int i = 0; i < v.size(); i++)
	{
		printf("%d ", v[i].second);
	}

	puts("");

	return 0;
}
