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.*;
import java.lang.Math;
import java.util.*;

public class Main
{	
	public BufferedReader in;
	public PrintStream out;
	
	public boolean log_enabled = true;
	
	public int longCmp(long a, long b)
	{
		if (a==b)
		{
			return 0;
		}
		
		if (a<b)
		{
			return -1;
		}
		else
		{
			return 1;
		}
	}
	
	private class Cube implements Comparable
	{
		int number, color;
		long size;
		
		Cube (int n, int c, long s)
		{
			number = n;
			size = s;
			color = c;
		}
		
		public int compareTo(Object o)
		{
			Cube c = (Cube)o;
		
			if (c.color == color)
			{
				return longCmp(c.size,size);
			}
			else
			{
				return color - c.color;
			}
		}
	}
	
	
	
	private class Color implements Comparable
	{
		int number, count;
		long[] size;
		long total_size;
		
		Color(int n, int c)
		{
			number =n;
			count =c;
			//size= new long[s+1];
		}
		
		public int compareTo(Object o)
		{
			Color c = (Color)o;
		
			if (c.count==count)
			{	
				return longCmp(c.total_size,total_size);
			}
			else
			{
				return (count - c.count);
			}
			
		}
		
		public void next_size(long s)
		{
			size[++count] = size[count-1] + s;
		}
	}
	
	public void test()
	{
		int i, n = readInt();
		Cube[] cubs = new Cube[n];
		
		for (i=0; i<n; i++)
		{
			cubs[i] = new Cube(i+1, readInt(), readInt());
		}
		
		Arrays.sort(cubs);
		
		int c_last = -1;
		int c_count = -1;
		
		Color[] colors = new Color[n];
		
		for (i=0; i<n; i++)
		{
			if (cubs[i].color != c_last)
			{
				c_last = cubs[i].color;
				colors[++c_count] = new Color(c_count, 1);
				colors[c_count].total_size = cubs[i].size;
			}
			else
			{
				colors[c_count].total_size += cubs[i].size;
				colors[c_count].count++;
			}
			
			cubs[i].color = c_count;
		}
		
		for (i=0; i<=c_count; i++)
		{
			//logWrite("c %d: %d \n", i, colors[i].count);
		
			colors[i].size = new long[colors[i].count+1];
			colors[i].count = 0;
			colors[i].size[0] = 0;
		}
		
		for (i=0; i<n; i++)
		{
			//logWrite("c: %d\n", cubs[i].color);
			colors[cubs[i].color].next_size(cubs[i].size);
		}
		
		Arrays.sort(colors, 0, c_count+1);
		
		long m, max = 0;
		
		int max_col1= 0;
		int max_col2 = 0;
		
		int max_n = 0;
		
		int j;
		
		c_last = -1;
		
		for (i=0; i<c_count; i++)
		{
			//logWrite(" %d: %d / %d \n", c_new[i].number, c_new[i].count, c_new[i].size[c_new[i].count]);
			
			if (c_last == colors[i].count)
			{
				continue;
			}
			
			c_last = colors[i].count;
		
			for (j=i+1; j<=c_count; j++)
			{
				m = colors[i].size[colors[i].count] + colors[j].size[ colors[j].count>colors[i].count ? colors[i].count + 1 : colors[i].count ];
				
				if (m>max)
				{
					max = m;
					
					max_col1= colors[i].number;
					max_col2 = colors[j].number;
					
					max_n = 2*colors[i].count + (colors[j].count>colors[i].count ? 1 : 0);
				}
			}
		}
		
		
		out.println(max);
		out.println(max_n);
		
		int c1=-1, c2=-1;
		for (i=0; i<n; i++)
		{
			if ((cubs[i].color == max_col1)&&(c1<0))
			{
				c1 = i;
			}
			if ((cubs[i].color == max_col2)&&(c2<0))
			{
				c2 = i;
			}
		}
		
		if (max_n % 2 == 1)
		{
			out.printf("%d ", cubs[c2++].number);
		}
		
		for (i=0; i<max_n/2; i++)
		{
			if (i>0)
			{
				out.print(" ");
			}
			
			out.printf("%d %d", cubs[c1++].number, cubs[c2++].number);
		}
	}
    
	public void run()
	{
		try
		{
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;
			
			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));
			
			
		}
		catch (Exception e)
		{
			return;
		}
		
		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)					
			{
				test();
			}
		}
	}
	
	public static void main(String args[])
	{
		new Main().run();
	}
	
	private StringTokenizer tokenizer = null;
	
	public int readInt() 
	{
        return Integer.parseInt(readToken());
    }
   
    public long readLong() 
	{
        return Long.parseLong(readToken());
    }
   
    public double readDouble() 
	{
        return Double.parseDouble(readToken());
    }
   
	public String readLn()
	{	
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}
	
    public String readToken() 
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens()) 
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }
	
	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}
	
	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}
	
	public void logWrite(String format, Object... args)
	{
		if (!log_enabled)
		{
			return;
		}
		
		out.printf(format, args);
	}
}