Problem: Little Janet likes playing with cubes. Actually, she likes to play with anything whatsoever, cubes or tesseracts, as long as they are multicolored. Each cube is described by two parameters — color ci and size si. A Zebra Tower is a tower that consists of cubes of exactly two colors. Besides, the colors of the cubes in the tower must alternate (colors of adjacent cubes must differ). The Zebra Tower should have at least two cubes. There are no other limitations. The figure below shows an example of a Zebra Tower.

<image>

A Zebra Tower's height is the sum of sizes of all cubes that form the tower. Help little Janet build the Zebra Tower of the maximum possible height, using the available cubes.

Input

The first line contains an integer n (2 ≤ n ≤ 105) — the number of cubes. Next n lines contain the descriptions of the cubes, one description per line. A cube description consists of two space-separated integers ci and si (1 ≤ ci, si ≤ 109) — the i-th cube's color and size, correspondingly. It is guaranteed that there are at least two cubes of different colors.

Output

Print the description of the Zebra Tower of the maximum height in the following form. In the first line print the tower's height, in the second line print the number of cubes that form the tower, and in the third line print the space-separated indices of cubes in the order in which they follow in the tower from the bottom to the top. Assume that the cubes are numbered from 1 to n in the order in which they were given in the input.

If there are several existing Zebra Towers with maximum heights, it is allowed to print any of them. 

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Examples

Input

4
1 2
1 3
2 4
3 3


Output

9
3
2 3 1 


Input

2
1 1
2 1


Output

2
2
2 1 

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

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

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;
	Random rand = new Random(12345);

	private void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

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

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

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

	class Cube implements Comparable<Cube> {
		public Cube(int c2, long s2, int n2) {
			c = c2;
			s = s2;
			n = n2;
		}

		long s;
		int c;
		int n;

		@Override
		public int compareTo(Cube o) {
			return s > o.s ? -1 : 1;
		}
	}

	private void solve() throws IOException {
		int n = nextInt();
		HashMap<Integer, ArrayList<Cube>> hm = new HashMap<Integer, ArrayList<Cube>>();
		for (int i = 0; i < n; i++) {
			Cube c = new Cube(nextInt(), nextInt(), i);
			if (!hm.containsKey(c.c)) {
				hm.put(c.c, new ArrayList<Cube>());
			}
			hm.get(c.c).add(c);
		}
		for (ArrayList<Cube> al : hm.values()) {
			Collections.sort(al);
		}
		Cube[] m1 = new Cube[n + 1];
		Cube[] m2 = new Cube[n + 1];
		for (int i = 0; i < m1.length; i++) {
			m1[i] = new Cube(-1, Long.MIN_VALUE / 4, i);
		}
		for (int i = 0; i < m2.length; i++) {
			m2[i] = new Cube(-1, Long.MIN_VALUE / 4, i);
		}
		for (int c : hm.keySet()) {
			ArrayList<Cube> al = hm.get(c);
			long sum = 0;
			for (int i = 0; i < al.size(); i++) {
				sum += al.get(i).s;
				if (m1[i + 1].s < sum) {
					m2[i + 1].s = m1[i + 1].s;
					m2[i + 1].c = m1[i + 1].c;
					m1[i + 1].s = sum;
					m1[i + 1].c = c;
				} else if (m2[i + 1].s < sum) {
					m2[i + 1].s = sum;
					m2[i + 1].c = c;
				}
			}
		}
		Cube best1 = null;
		Cube best2 = null;
		long ans = -1;
		for (int i = 1; i < m1.length; i++) {
			if (m2[i].c < 0) {
				continue;
			}
			if (ans < m1[i].s + m2[i].s) {
				ans = m1[i].s + m2[i].s;
				best1 = m1[i];
				best2 = m2[i];
			}
		}
		for (int i = 1; i + 1 < m1.length; i++) {
			if (m1[i].c < 0) {
				continue;
			}
			if (m1[i + 1].c != m1[i].c) {
				if (ans < m1[i].s + m1[i + 1].s) {
					ans = m1[i].s + m1[i + 1].s;
					best1 = m1[i + 1];
					best2 = m1[i];
				}
			} else if (m2[i + 1].c >= 0) {
				if (ans < m1[i].s + m2[i + 1].s) {
					ans = m1[i].s + m2[i + 1].s;
					best1 = m2[i + 1];
					best2 = m1[i];
				}
			}
			if (m2[i].c >= 0 && m1[i + 1].c >= 0 && m2[i].c != m1[i + 1].c) {
				if (ans < m2[i].s + m1[i + 1].s) {
					ans = m2[i].s + m1[i + 1].s;
					best1 = m1[i + 1];
					best2 = m2[i];
				}
			}
		}
		out.println(ans);
		out.println(best1.n + best2.n);
		ArrayList<Cube> al1 = hm.get(best1.c);
		ArrayList<Cube> al2 = hm.get(best2.c);
		while (best1.n > 0) {
			best1.n--;
			out.print(al1.get(best1.n).n + 1 + " ");
			best2.n--;
			if (best2.n >= 0) {
				out.print(al2.get(best2.n).n + 1 + " ");
			}
		}
	}

}