import java.io.*;
import java.util.*;

public class missions_pk_wa_fail {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	public String nextToken() throws IOException {
		while ((st == null) || (!st.hasMoreTokens()))
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	class mission {
		int[] d;
		int num;

		public mission(int a, int b, int c, int n) {
			d = new int[3];
			d[0] = a;
			d[1] = b;
			d[2] = c;
			num = n;
		}
		
		@Override
		public String toString() {
			return num + " " + d[0] + " " + d[1] + " " + d[2];
		}
	}

	public void solve() throws IOException {
		int n = nextInt();
		ArrayList<mission> m = new ArrayList<missions_pk_wa_fail.mission>();
		for (int i = 0; i < n; i++) {
			m.add(new mission(nextInt(), nextInt(), nextInt(), i));
		}

		mission[][] max = new mission[3][3];
		for (mission x : m) {
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					if (i == j)
						continue;
					if (max[i][j] == null)
						max[i][j] = x;
					if (max[i][j].d[i] > x.d[i])
						continue;
					if (max[i][j].d[i] < x.d[i] || max[i][j].d[j] < x.d[j]) {
						max[i][j] = x;
						continue;
					}
				}
			}
		}

		System.err.println(Arrays.deepToString(max));
		
		ArrayList<mission> fin = new ArrayList<missions_pk_wa_fail.mission>();
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (max[i][j] != null && !fin.contains(max[i][j]))
					fin.add(max[i][j]);
			}
		}

		long min = Long.MAX_VALUE;
		ArrayList<mission> ans = new ArrayList<mission>();
		for (int z = 0; z < 10000; z++) {
			Collections.shuffle(fin);
			long sum = 0;
			for (int i = 0; i < fin.size(); i++) {
				for (int t = 0; t < 3; t++) {
					long add = fin.get(i).d[t];
					for (int j = 0; j < i; j++) {
						if (fin.get(j).d[t] >= add) {
							add = 0;
						}
					}
					sum += add;
				}
			}
			if (sum < min) {
				min = sum;
				ans = (ArrayList<mission>) fin.clone();
			}

		}

		out.println(min);
		for (mission x : ans) {
			out.print(x.num + 1 + " ");
		}

		for (int i = 0; i < n; i++) {
			boolean fl = false;
			for (mission x : ans) {
				if (x.num == i)
					fl = true;
			}
			if (!fl) {
				out.print(i + 1 + " ");
			}
		}
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			br = new BufferedReader(new FileReader("missions.in"));
			out = new PrintWriter("missions.out");

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new missions_pk_wa_fail().run();
	}
}