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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;

public class Main {
	static class Assert {
		static void check(boolean e) {
			if (!e) {
				throw new Error();
			}
		}
	}

	class Stack {
		int len;
		int[] val;

		Stack() {
			int[] val = new int[100001];
			len = 0;
		}

		int pop() {
			return val[len--];
		}

		int add(int v) {
			return val[++len] = v;
		}
	}

	class Scanner {

		StreamTokenizer in;

		Scanner(InputStream is) {
			in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
			in.resetSyntax();
			in.whitespaceChars(0, 32);
			in.wordChars(33, 255);
		}

		String next() {
			try {
				in.nextToken();
				Assert.check(in.ttype == in.TT_WORD);
				return in.sval;
			} catch (IOException e) {
				throw new Error(e);
			}
		}

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

	public static void main(String[] argv) {
		new Main().run();
	}

	void run() {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		try {
			solve();
		} finally {
			out.close();
		}
	}

	PrintWriter out;
	Scanner in;

	class Box {
		int color;
		int cost;

		Box() {
			color = in.nextInt();
			cost = in.nextInt();
		}

		@Override
		public String toString() {
			return color + " " + cost;
		}

		@Override
		public int hashCode() {
			return cost + 31 * color;
		}

		@Override
		public boolean equals(Object o) {
			Box b = (Box) o;
			return b.cost == cost && b.color == color;
		}
	}

	class Pack {
		long cost;
		int len;
		int color;

		Pack(long cost, int len, int color) {
			this.color = color;
			this.cost = cost;
			this.len = len;
		}

		@Override
		public String toString() {
			return color + " " + cost + " " + len;
		}
	}

	class PackList extends ArrayList<Pack> {
		PackList() {
			super();
		}

		PackList(PackList a) {
			super(a);
		}
	}

	class BoxList extends ArrayList<Box> {
		BoxList(BoxList a) {
			super(a);
		}

		BoxList() {
			super();
		}
	}

	void outAnswer(Pack p1, Pack p2, Box[] a, Box[] sort) {
		int col1 = p1.color;
		int col2 = p2.color;
		int len1 = p1.len;
		int len2 = p2.len;
		HashMap<Box, Integer> map = new HashMap<Box, Integer>();
		for (int i = 0; i < sort.length; i++) {
			if (sort[i].color == col1 && len1 > 0) {
				if (!map.containsKey(sort[i])) {
					map.put(sort[i], 1);
				} else {
					map.put(sort[i], map.get(sort[i]) + 1);
				}
				len1--;
			}
			if (sort[i].color == col2 && len2 > 0) {
				if (!map.containsKey(sort[i])) {
					map.put(sort[i], 1);
				} else {
					map.put(sort[i], map.get(sort[i]) + 1);
				}
				len2--;
			}
		}
		out.println(p1.cost + p2.cost);
		out.println(p1.len + p2.len);
		ArrayList<Integer> index1 = new ArrayList<Integer>();
		ArrayList<Integer> index2 = new ArrayList<Integer>();
		for (int i = 0; i < a.length; i++) {
			if (map.containsKey(a[i])) {
				if (col1 == a[i].color) {
					index1.add(i + 1);
				} else {
					index2.add(i + 1);
				}
				int cnt = map.get(a[i]) - 1;
				if (cnt == 0) {
					map.remove(a[i]);
				} else {
					map.put(a[i], cnt);
				}
			}
		}
		int min = Math.min(index1.size(), index2.size());
		for (int i = 0; i < min; i++) {
			out.print(index1.get(i) + " " + index2.get(i) + " ");
		}
		if (index1.size() > min) {
			out.print(index1.get(index1.size() - 1));
		}

		if (index2.size() > min) {
			out.print(index2.get(index2.size() - 1));
		}

	}

	void solve() {
		int n = in.nextInt();
		Box[] a = new Box[n];
		for (int i = 0; i < n; i++) {
			a[i] = new Box();
		}
		Box[] b = a.clone();
		Arrays.sort(a, new Comparator<Box>() {
			@Override
			public int compare(Box b1, Box b2) {
				if (b1.color == b2.color) {
					return b2.cost - b1.cost;
				}
				return b1.color - b2.color;
			}
		});
		int color = a[0].color;
		long curSum = a[0].cost;
		Pack[] packs = new Pack[n];
		int len = 1;
		packs[0] = new Pack(curSum, len, color);
		for (int i = 1; i < n; i++) {
			if (color == a[i].color) {
				curSum += a[i].cost;
				len++;
				packs[i] = new Pack(curSum, len, color);
			} else {
				color = a[i].color;
				curSum = a[i].cost;
				len = 1;
				packs[i] = new Pack(curSum, len, color);
			}
		}
		Arrays.sort(packs, new Comparator<Pack>() {
			@Override
			public int compare(Pack p1, Pack p2) {
				if (p1.len == p2.len) {
					if (p2.cost == p1.cost) {
						return 0;
					}
					return p2.cost - p1.cost > 0 ? 1 : -1;
				}
				return p1.len - p2.len;
			}
		});
		ArrayList<Pack> res = new ArrayList<Pack>();
		HashMap<Integer, PackList> map = new HashMap<Integer, PackList>();
		// for (int i = 0; i < n; i++) {
		// out.println(packs[i]);
		// }
		int lastLen = 1;
		int count = 1;
		res.add(packs[0]);
		for (int i = 1; i < n; i++) {
			// out.println(lastLen == packs[i].len);
			if (lastLen == packs[i].len && count > 0) {
				res.add(packs[i]);
				count--;
			} else if (lastLen != packs[i].len) {
				lastLen = packs[i].len;
				count = 1;
				res.add(packs[i]);
			}
		}
		// out.println("-----------------------------");
		// for (int i = 0; i < res.size(); i++) {
		// out.println(res.get(i));
		// }
		PackList buf = new PackList();
		for (int i = 0; i < res.size();) {
			buf.clear();
			if (i < res.size() - 1 && res.get(i).len == res.get(i + 1).len) {
				// out.println("x2 add");
				buf.add(res.get(i));
				buf.add(res.get(i + 1));
				map.put(res.get(i).len, new PackList(buf));
				i += 2;
			} else {
				buf.add(res.get(i));
				map.put(res.get(i).len, new PackList(buf));
				i++;
			}
		}
		// now we have array of blocks in map with key as len
		// for-each 1->max len; find max size
		len = res.get(res.size() - 1).len;
		long max = Long.MIN_VALUE;
		Pack part1 = null;
		Pack part2 = null;
		if (map.get(1).size() == 2) {
			max = map.get(1).get(0).cost + map.get(1).get(1).cost;
			part1 = map.get(1).get(0);
			part2 = map.get(1).get(1);
		}
		// for (Integer i : map.keySet()) {
		// out.println(map.get(i));
		// }
		for (int l = 2; l <= len; l++) {
			if (map.get(l).size() == 2) {
				Pack f = map.get(l).get(0);
				Pack s = map.get(l).get(1);
				if (max < f.cost + s.cost) {
					max = f.cost + s.cost;
					// out.println("update");
					part1 = f;
					part2 = s;
				}
			}
			for (Pack p1 : map.get(l)) {
				for (Pack p2 : map.get(l - 1)) {
					if (p1.color != p2.color && max < p1.cost + p2.cost) {
						max = p1.cost + p2.cost;
						part1 = p1;
						part2 = p2;
					}
				}
			}
		}
		outAnswer(part1, part2, b, a);

	}
}