#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long LL;

struct job {
	LL T, W;
	int id;
	vector<job> parts;
	
	job() {
		T = W = id = 0;
	}
	
	bool operator < (const job& other) const {
		return T * other.W < W * other.T;
	}
};

void solve() {
	int N;
	cin >> N;
	vector<int> K(N);
	for (int i = 0; i < N; ++i)
		cin >> K[i];

	vector<job> jobs(N);
	
	int ID = 0;
	for (int i = 0; i < N; ++i) {
		jobs[i].parts.resize(K[i]);
		for (int j = 0; j < K[i]; ++j) {
			cin >> jobs[i].parts[j].T;
			jobs[i].parts[j].id = ++ID;
			jobs[i].T += jobs[i].parts[j].T;
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < K[i]; ++j) {
			cin >> jobs[i].parts[j].W;
			jobs[i].W += jobs[i].parts[j].W;
		}
		
		sort(jobs[i].parts.begin(), jobs[i].parts.end());
	}
	sort(jobs.begin(), jobs.end());
	
	long long cost = 0;
	long long TIME = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < jobs[i].parts.size(); ++j) {
			TIME += jobs[i].parts[j].T;
			cost += TIME * jobs[i].parts[j].W;
		}
	}
	
	cout << cost << endl;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < jobs[i].parts.size(); ++j) {
			if (i+j) cout << ' ';
			cout << jobs[i].parts[j].id;
		}
	}
	cout << endl;
}

int main() {
	solve();
	
	return 0;
}
