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.InputStreamReader;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Collections;
import java.util.Iterator;


public class E {
	
	
	static class cube implements Comparable<cube>
	{
		int color,size,n;
		public cube(int c,int s,int a)
		{
			color=c;
			size=s;
			n=a;
		}
		public int compareTo(cube arg0) {
			return arg0.size - this.size;
		}
	}
	
	static class Scanner
	{
		BufferedReader rd;
		StringTokenizer tk;
		public Scanner() throws IOException
		{
			rd=new BufferedReader(new InputStreamReader(System.in));
			tk=new StringTokenizer(rd.readLine());
		}
		public String next() throws IOException
		{
			if (!tk.hasMoreTokens())
			{
				tk=new StringTokenizer(rd.readLine());
				return tk.nextToken();
			}
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException
		{
			return Integer.valueOf(this.next());
		}
	}
	
	
	static int N;
	
	public static void main(String args[]) throws IOException
	{
		Scanner sc=new Scanner();
		N=sc.nextInt();
		TreeMap<Integer,Integer> index_of=new TreeMap<Integer,Integer>();
		LinkedList<cube>[] array=(LinkedList<cube>[]) new LinkedList[100010];
		long[][] sum=new long[100010][];
		int index=0;
		for(int i=1;i<=N;i++)
		{
			int c=sc.nextInt();
			int s=sc.nextInt();
			if (index_of.containsKey(c))
				array[index_of.get(c)].add(new cube(c,s,i));
			else
			{
				index_of.put(c, index);
				array[index]=new LinkedList<cube>();
				array[index].add(new cube(c,s,i));
				index++;
			}
		}
		for(int i=0;i<index;i++)
		{
			Collections.sort(array[i]);
			sum[i]=new long[array[i].size()];
			int counter=0;
			long suma=0;
			for(cube r: array[i])
			{
				sum[i][counter]=r.size + suma;
				suma=sum[i][counter];
				counter++;
			}
		}
		
		long[] MAX_TOWER=new long[100010];
		int[] index_MAX=new int[100010];
		for(int u=0;u<10010;u++)
		{
			MAX_TOWER[u]=0;
			index_MAX[u]=-1;
		}
		for(int i=0;i<sum[0].length;i++)
		{
			MAX_TOWER[i]=sum[0][i];
			index_MAX[i]=0;
		}
		
		/*
		for(int i=0;i<index;i++)
		{
			for(int j=0;j<sum[i].length;j++)
				System.out.print(sum[i][j]+ " ");
			System.out.println();
		}*/
		
		long BEST=0;
		int indexx=-1;
		int index2=-1;
		for(int i=1;i<index;i++)
		{
			//int tam=sum[i].length;
			for(int tam=0;tam<sum[i].length;tam++)
			{
				//tam--;
				if (tam-1>=0 && MAX_TOWER[tam-1]!=0)
				{
					if (sum[i][tam] + MAX_TOWER[tam-1] > BEST)
					{
						BEST=sum[i][tam] + MAX_TOWER[tam-1];
						indexx=i;
						index2=index_MAX[tam-1];
					}
				}
				if(MAX_TOWER[tam]!=0)
				{
					if (sum[i][tam] + MAX_TOWER[tam] > BEST)
					{
						BEST=sum[i][tam] + MAX_TOWER[tam];
						indexx=i;
						index2=index_MAX[tam];
					}
				}
				if (MAX_TOWER[tam+1]!=0)
				{
					if (sum[i][tam] + MAX_TOWER[tam+1] > BEST)
					{
						BEST=sum[i][tam] + MAX_TOWER[tam+1];
						indexx=i;
						index2=index_MAX[tam+1];
					}
				}
			}
			
			for(int j=0;j<sum[i].length;j++)
			{
				if (sum[i][j]>MAX_TOWER[j])
				{
					MAX_TOWER[j]=sum[i][j];
					index_MAX[j]=i;
				}
			}
		}
		/*
		System.out.println(indexx +" "+ index2);
		*/
		int cuadros;
		if (sum[indexx].length == sum[index2].length)
			cuadros=sum[index2].length*2;
		else if (sum[indexx].length > sum[index2].length)
			cuadros=sum[index2].length*2 + 1;
		else
			cuadros=sum[indexx].length*2 + 1;
		
		System.out.println(BEST);
		System.out.println(cuadros);
		
		
		int first,second;
		if (sum[indexx].length>sum[index2].length)
		{
			first=indexx;second=index2;
		}
		else
		{
			first=index2;second=indexx;
		}
		
		
		Iterator p = array[first].iterator();
		Iterator q = array[second].iterator();
		cube a;
		int count=0;
		while(true)
		{
			a=(cube)p.next();
			System.out.print(a.n);
			count++;
			if (count==cuadros)
				break;
			a=(cube)q.next();
			System.out.print(" "+a.n);
			count++;
			if (count==cuadros)
				break;
			System.out.print(" ");
		}
		
		
		
		
	}

}