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.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class A {



	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextint();


		TreeMap<Integer, ArrayList<Point>> map = new TreeMap<>();
		TreeSet<Integer> colors = new TreeSet<>();
		TreeMap<Integer, Long> size = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			int c = sc.nextint();
			int s = sc.nextInt();

			ArrayList<Point> set = map.getOrDefault(c, new ArrayList<>());
			long sz = size.getOrDefault(c, 0l);
			size.put(c, sz + s);
			set.add(new Point(i, s));
			map.put(c, set);

			colors.add(c);
		}

		for(Entry<Integer, ArrayList<Point>> e : map.entrySet())
			Collections.sort(e.getValue(), new Comparator<Point>() {

				@Override
				public int compare(Point o1, Point o2) {
					return o2.y - o1.y;
				}

			});


		ArrayList<Integer> sorted = new ArrayList<>();

		for(int c: colors)
			sorted.add(c);

		Collections.sort(sorted, new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				return map.get(o2).size() - map.get(o1).size();
			}
		});

		long ans = 0;
		int fst = 0;
		int snd = 0;


		ArrayList<Integer> cnt = new ArrayList<>();

		NiceMap nicM = new NiceMap();
		nicM.add(0, size.get(sorted.get(0)));
		
		for (int i = 0; i < sorted.size(); i++) {
			cnt.add(map.get(sorted.get(i)).size());
		}

		for (int i = 1; i < sorted.size(); i++) {
			for (int j = 0; j < i; j++) {
				if(cnt.get(j) <= cnt.get(i) + 1)
					break;
				else while(cnt.get(j) > cnt.get(i) + 1) {
					nicM.remove(j, size.get(sorted.get(j)));
					size.put(sorted.get(j), size.get(sorted.get(j)) - map.get(sorted.get(j)).get(cnt.get(j) - 1).y);
					nicM.add(j, size.get(sorted.get(j)));
					cnt.set(j, cnt.get(j) - 1);

					

				}
			}

			if(size.get(sorted.get(i)) + size.get(sorted.get(nicM.getMaxIndex())) > ans) {
				ans = size.get(sorted.get(i)) + size.get(sorted.get(nicM.getMaxIndex()));
				fst = nicM.getMaxIndex();
				snd = i;
			}
			nicM.add(i, size.get(sorted.get(i)));

		}


		ArrayList<Integer> indexes = new ArrayList<>();
		long total = 0;
		ArrayList<Point> first = map.get(sorted.get(fst));
		ArrayList<Point> second = map.get(sorted.get(snd));
		for (int i = 0; i < first.size(); i++) {
			indexes.add(first.get(i).x);
			total += first.get(i).y;
			if(i < second.size()) {
				indexes.add(second.get(i).x);
				total += second.get(i).y;
			}else
				break;
		}

		out.println(total);
		out.println(indexes.size());
		for(int x: indexes)
			out.print(x + 1 + " ");
		out.println();




		out.close();

	}


	static class NiceMap {
		TreeMap<Long, Integer> map = new TreeMap<Long, Integer>();
		TreeMap<Long, TreeSet<Integer>> set = new TreeMap<>();
		
		void add(int i, long x) {
			int f = map.getOrDefault(x, 0);
			map.put(x, f + 1);
			
			TreeSet<Integer> arr = set.computeIfAbsent(x, k -> new TreeSet<>());
			arr.add(i);
		}
		
		void remove(int i, long x) {
			int f = map.get(x);
			if(f == 1)
				map.remove(x);
			else
				map.put(x, f - 1);
			
			TreeSet<Integer> arr = set.get(x);
			arr.remove(i);
		}
		
		int getMaxIndex() {
			return set.get(map.lastKey()).first();
		}
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s)
		{
			br = new BufferedReader(new InputStreamReader(s));
		}

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

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

		public int nextint() throws IOException
		{
			return Integer.parseInt(next());
		}

		public String nextLine() throws IOException
		{
			return br.readLine();
		}

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

		public boolean ready() throws IOException
		{
			return br.ready();
		}
	}
}