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.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;





public class Main {
	long maxHeight = -1;
	long color1 = -1;
	long color2 = -1;
	int count1 = -1;
	int count2 = -1;
	public MaxPair[] pairs ;
	public MaxPair getPair(int count) {
		MaxPair pair = pairs[count - 1];
		if (pair == null) {
			pair = new MaxPair();
			pairs[count - 1] = pair;
		}
		return pair;
	}
	static class Kub {
		public Kub(long num, long color, long size) {
			this.num = num;
			this.color = color;
			this.size = size;
		}
		@Override
		public String toString() {
			return "Kub [num=" + num + ", color=" + color + ", size=" + size
					+ "]";
		}
		long num;
		long color;
		long size;
	}
	static class MaxPair {
		
		
		long firstColor = -1;
		long firstValue = -Long.MIN_VALUE;
		
		long secondColor = -1;
		long secondValue = -Long.MIN_VALUE;
		public void propose(long color, long value) {
			if (firstValue < value) {
				secondColor = firstColor;
				secondValue = firstValue;
				
				firstColor = color;
				firstValue = value;
			} else if ( secondValue < value) {
				secondColor = color;
				secondValue = value;
			}
		}
		public long getMaxValue(long color) {
			return firstColor == color ? secondValue : firstValue;
		}
		public long getMaxColor(long color) {
			return firstColor == color ? secondColor : firstColor;
		}
	}
	int size = 0;
	
	BufferedReader reader;
	List<Kub> list;
	Map<Long, List<Kub>> map = new TreeMap<Long, List<Kub>>();
	
	public Main(InputStream in) throws IOException {
		reader = new BufferedReader(new InputStreamReader(in));
		readParams();
	}
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		Main m = new Main(System.in);
		System.out.print(m.solve());
	}
	
	public String solve() {
		Collections.sort(list, new Comparator<Kub>() {
			@Override
			public int compare(Kub o1, Kub o2) {
				if (o1.size == o2.size) return 0;
				return o1.size > o2.size ? -1 : 1;
			}
		});
		for(Kub kub:list) {
			List<Kub> l = getList(kub.color);
			Kub k;
			if (l.size() == 0) {
				k = kub;
				l.add(0, kub);
			} else {
				k = new Kub(kub.num, kub.color, kub.size + l.get(l.size() - 1).size);
				l.add(l.size(), k);
			}
			getPair(l.size()).propose(k.color, k.size);
		}
		
		for (Map.Entry<Long, List<Kub>> kubs: map.entrySet()) {
			 List<Kub> l = kubs.getValue();
			 int currCount = l.size();
			 Kub currKub = l.get(currCount - 1);
			 long currSize = currKub.size;
			 long currColor = currKub.color;
			
			 if (currCount > 1) {
				 long val1  =  getPair(currCount - 1).getMaxValue(currColor);
				 propose(val1 + currSize, currColor, getPair(currCount - 1).getMaxColor(currColor), currCount, currCount - 1);
			 }
			 if (currCount < size) {
				 long val2  =  getPair(currCount + 1).getMaxValue(currColor);
				 propose(val2 + currSize, getPair(currCount + 1).getMaxColor(currColor), currColor, currCount + 1, currCount);
			 }
			 long val3  =  getPair(currCount).getMaxValue(currColor);
			 propose(val3 + currSize, getPair(currCount).getMaxColor(currColor), currColor, currCount, currCount);
		}
		
		StringBuffer buf = new StringBuffer();
		buf.append(maxHeight + "\r\n");
		buf.append((count1 + count2) + "\r\n");
		Kub[] lColor1 = getList(color1).toArray(new Kub[0]);
		Kub[] lColor2 = getList(color2).toArray(new Kub[0]);
		for (int i = 0; i < count2; i++){
			buf.append(lColor1[i].num + " " + lColor2[i].num + " ");
		}
		if (count1 > count2) {
			buf.append(lColor1[count1 - 1].num + " ");
		}
		return buf.toString();
	}
	void propose(long sum, long color1, long color2, int currCount1, int currCount2){
		if(sum > maxHeight) {
			maxHeight = sum;
			this.color1 = color1;
			this.color2 = color2;
			this.count1 = currCount1;
			this.count2 = currCount2;
		}
	}
	private List<Kub> getList(long color) {
		List<Kub> l = map.get(color);
		if (l == null) {
			l = new LinkedList<Kub>();
			map.put(color, l);
		}
		return l;
		
	}
	public void readParams() throws IOException {
		
		size = readInt();
		list = new ArrayList<Kub>(size);
		pairs = new MaxPair[size];
		for(int i = 0; i < size; i++) {
			Integer[] params = readInt(2);
			list.add(new Kub(i + 1, params[0], params[1]));
		}
	}
	
	public Integer readInt() throws NumberFormatException, IOException {
		return Integer.parseInt(reader.readLine());
	}
	
	public Integer[] readInt(int size) throws IOException {
		Integer[] result = new Integer[size];
		String[] params =  reader.readLine().split(" ");
		for(int i = 0; i < size; i++) {
			result[i] = Integer.parseInt(params[i]);
		}
		return result;
	}
	
	public String readStr() throws IOException {
		return reader.readLine().trim();
	}

}