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.util.*;
import java.math.*;
import java.io.*;
public class Main
	{
	public static void main(String args[])	throws IOException
		{
		BufferedReader c=new BufferedReader(new InputStreamReader(System.in));
		//Scanner c=new Scanner(System.in);
		int N=Integer.parseInt(c.readLine());
		
		LinkedList<box> L[]=(LinkedList<box>[])new LinkedList[N];		//for colors: <=N in number
		Comparator<box> comp= new Comparator<box>()
			{
			public int compare(box o1, box o2)
				{
				if(o1.size<o2.size)
					return 1;
				if(o1.size==o2.size)
					return 0;
				return -1;
				}
			};
			
		for(int i=0;i<N;i++) 
			L[i]=new LinkedList<box>();
		int used_color=0;
		HashMap<Integer,Integer> M=new HashMap<Integer, Integer>();
		for(int i=0;i<N;i++) 
			{
			StringTokenizer st=new StringTokenizer(c.readLine());
			int col=Integer.parseInt(st.nextToken());
			int size=Integer.parseInt(st.nextToken());
			if(M.containsKey(col))
				{
				int col_i=M.get(col);
				L[col_i].add(new box(i+1,size));
				}
			else
				{
				M.put(col, used_color);
				used_color++;
				int col_i=M.get(col);
				L[col_i].add(new box(i+1,size));
				}
			}
		//process the linked lists
		for(int i=0;i<N;i++) 
			{
			int m=L[i].size();
			box A[]=new box[m];
			for(int j=0;j<m;j++) 
				A[j]=L[i].remove();
			Arrays.sort(A,comp);
			for(int j=0;j<m;j++)
				L[i].add(A[j]);
			}
		
		
		height max[]=new height[N+1];			//if number of boxes is i, which color has the max height? what is this max_height
		height max_2[]=new height[N+1];		//if number of boxes is i, which color has the 2nd max height? what is this 2nd max_height
		for(int i=0;i<N+1;i++) 
			{
			max[i]=new height();
			max_2[i]=new height();
			}
		/*for(int i=0;i<N;i++) 
			{
			if(L[i].size()!=0)
				{
				System.out.println("Color "+i);
				for(int a:L[i])
					System.out.println("\t"+a);
				}
			}
		*/
		
		//create the arrays max[] and max_2[]
		for(int i=0;i<N;i++) 
			{
			int num=0;
			long my_height=0;
			for(box a:L[i])				//in decreasing order 
				{
				//System.out.println("checking height "+a+" of color "+i);
				num++;
				my_height+=a.size;
				//invariant: number of boxes (1 based)=num and height=my_height
				if(my_height>=max[num].height)
					{
					max_2[num].height=max[num].height;
					max_2[num].color=max[num].color;
					max[num].height=my_height;
					max[num].color=i;
					}
				else if(my_height>=max_2[num].height)
					{
					max_2[num].height=my_height;
					max_2[num].color=i;
					}
				}
			}
		
		/*for(int i=0;i<N;i++) 
			{
			System.out.println("MAX: number ="+i+" color: "+max[i].color+" height: "+max[i].height);
			System.out.println("MAX_2: number ="+i+" color: "+max_2[i].color+" height: "+max_2[i].height);
			}
		*/
		//done creating the arrays max[] and max_2[]
		
		//now compute the answer
		long ans=0;
		int col1=0;
		int col2=0;
		for(int i=0;i<N;i++) 
			{
			int num=0;
			long my_height=0;
			for(box a:L[i])				//in decreasing order 
				{
				num++;
				//num number of boxes of color i>=1
				my_height+=a.size;
				if(max[num-1].color==i)
					{
					if(my_height+max_2[num-1].height>ans&&max_2[num-1].height!=0)
						{
						ans=my_height+max_2[num-1].height;
						col1=i;
						col2=max_2[num-1].color;
						}
					}
				else
					{
					if(my_height+max[num-1].height>ans&&max[num-1].height!=0)
						{
						ans=my_height+max[num-1].height;
						col1=i;
						col2=max[num-1].color;
						}
					}
					
				if(max[num].color==i)
					{
					if(my_height+max_2[num].height>ans&&max_2[num].height!=0)
						{
						ans=my_height+max_2[num].height;
						col1=i;
						col2=max_2[num].color;
						}
					}
				else
					{
					if(my_height+max[num].height>ans&&max[num].height!=0)
						{
						ans=my_height+max[num].height;
						col1=i;
						col2=max[num].color;
						}
					}

				if(max[num+1].color==i)
					{
					if(my_height+max_2[num+1].height>ans&&max_2[num+1].height!=0)
						{
						ans=my_height+max_2[num+1].height;
						col1=i;
						col2=max_2[num+1].color;
						}
					}
				else
					{
					if(my_height+max[num+1].height>ans&&max[num+1].height!=0)
						{
						ans=my_height+max[num+1].height;
						col1=i;
						col2=max[num+1].color;
						}
					}
				}
			}
		System.out.println(ans);
		//System.out.println("col1= "+L[col1].size());
		//System.out.println("col2= "+L[col2].size());
		int MIN=Math.min(L[col1].size(),L[col2].size());
		int MAX=Math.max(L[col1].size(),L[col2].size());
		if(MAX==MIN)
			System.out.println(2*MIN);
		else
			System.out.println((2*MIN+1));
		if(L[col1].size()==L[col2].size())
			{
			for(int j=0;j<MIN;j++) 
				{
				System.out.print(L[col1].removeFirst().index+" ");
				System.out.print(L[col2].removeFirst().index+" ");
				}
			}
		else if(L[col1].size()<L[col2].size())
			{
			for(int j=0;j<MIN;j++) 
				{
				System.out.print(L[col2].removeFirst().index+" ");
				System.out.print(L[col1].removeFirst().index+" ");
				}
			System.out.print(L[col2].removeFirst().index+" ");
			}
			
		else if(L[col2].size()<L[col1].size())
			{
			for(int j=0;j<MIN;j++) 
				{
				System.out.print(L[col1].removeFirst().index+" ");
				System.out.print(L[col2].removeFirst().index+" ");
				}
			System.out.print(L[col1].removeFirst().index+" ");
			}

		//System.out.println("col1= "+col1+" col2= "+col2+" maxHeight= "+ans);
		}
	}

class height
	{
	int color;
	long height;
	}

class box
	{
	int index;
	int size;
	
	public box(int index, int size)
		{
		this.index =index;
		this.size=size;
		}
	}
//must declare new classes here