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

public class E1 implements Runnable {

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

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

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

	String nextStr() throws IOException {
		return nextToken();
	}

	char nextChar() throws IOException {
		return nextToken().charAt(0);
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	public class Cubik implements Comparable<Cubik>{
		public Cubik(long height, int number) {
			this.height = height;
			this.number = number;
		}
		long height;
		int number;
		@Override
		public int compareTo(Cubik o) {
			return Long.compare(height, o.height);
		}
	}
	
	public class CubSum implements Comparable<CubSum>{
		public CubSum(int color, long sum) {
			this.color = color;
			this.sum = sum;
		}
		int color;
		long sum;
		@Override
		public int compareTo(CubSum o) {
			return Long.compare(sum, o.sum);
		}
	}
	
	public class CurrentResult implements Comparable<CurrentResult>{
		public CurrentResult(int color1, int color2, long sum, int size) {
			this.color1 = color1;
			this.color2 = color2;
			this.sum = sum;
			this.size = size;
		}
		int color1, color2;
		int size;
		long sum;
		@Override
		public int compareTo(CurrentResult o) {
			return Long.compare(sum, o.sum);
		}
	}
	
	CurrentResult getResult( ArrayList<CubSum> mas, ArrayList<CubSum> oldMas, int size ) {
		if ( mas.size() < 1 || oldMas.size() < 1 ) {
			return new CurrentResult(0, 0, 0, 0);
		}
		CubSum max = Collections.max(mas);
		CubSum oldMax = getMax( oldMas );
		if ( oldMax.color == max.color) {
			if ( oldMas.size() > 1 ) {
				CubSum preOldMax = getPreMax(oldMas);
				return new CurrentResult(max.color, preOldMax.color, max.sum + preOldMax.sum, size);
			}else {
				return new CurrentResult(0, 0, 0, 0);
			}
		}
		return new CurrentResult(max.color, oldMax.color, max.sum + oldMax.sum, size);
	}
	
	CurrentResult getResult( ArrayList<CubSum> mas, int size ) {
		if ( mas.size() <= 1 ) {
			return new CurrentResult(0, 0, 0, 0);
		}
		CubSum max = Collections.max(mas);
		CubSum preMax = new CubSum(0, -1);
		for ( CubSum cb : mas ) {
			if ( cb != max && cb.compareTo(preMax) > 0 ) {
				preMax = cb;
			}
		}
		return new CurrentResult(max.color, preMax.color, max.sum + preMax.sum, size);
	}
	
	CubSum getMax( ArrayList<CubSum> mas ) {
		return Collections.max(mas);
	}
	
	CubSum getPreMax( ArrayList<CubSum> mas ) {
		CubSum max = Collections.max(mas);
		CubSum preMax = new CubSum(0, -1);
		for ( CubSum cb : mas ) {
			if ( cb != max && cb.compareTo(preMax) > 0 ) {
				preMax = cb;
			}
		}
		return preMax;
	}

	public void solve() throws IOException {
		int n = nextInt();
		
		HashMap<Integer, ArrayList<Cubik> > hash = new  HashMap<Integer, ArrayList<Cubik> >();
		HashMap<Integer, Long > currentSize = new  HashMap<Integer, Long> ();
		for ( int i=0; i<n; ++i ) {
			int color = nextInt();
			int size = nextInt();
			if ( !hash.containsKey(color) ) {
				hash.put(color, new ArrayList<Cubik>());
			}
			hash.get(color).add(new Cubik(size, i+1));
		}
		
		Set<Integer> colors = hash.keySet();
		Set<Integer> sizes = new TreeSet<Integer>();
		int firstColor = -1;
		int secondColor = -1;
		for ( int color : colors ) {
			if ( firstColor == -1 ) {
				firstColor = color;
			}else if ( secondColor == -1 ) {
				secondColor = color;
			}
			Collections.sort( hash.get(color) );
			sizes.add(hash.get(color).size());
			sizes.add(hash.get(color).size() + 1);
			currentSize.put(color, (long) 0);
		}
		
		int prevSize = 0;
		CurrentResult cr = new CurrentResult(firstColor, secondColor, 0, 0);
		ArrayList<CubSum> oldSums = new ArrayList<CubSum>();
		for ( int size : sizes ) {
			
			ArrayList<CubSum> newSums = new ArrayList<CubSum>();
			
			for ( int color : colors ) {
				ArrayList<Cubik> mas = hash.get(color); 
				if ( size <= mas.size() ) {
					long sum = 0;
					for ( int i=prevSize; i<size; ++i ) {
						sum += mas.get(mas.size() - i - 1).height;
					}
					currentSize.put(color, sum + currentSize.get(color));
					newSums.add(new CubSum( color, currentSize.get(color)));
				}
			}
			
			CurrentResult tmp = getResult(newSums, size);
			if ( tmp.compareTo(cr) > 0 ) {
				cr = tmp;
			}
			tmp = getResult(newSums, oldSums, size);
			if ( tmp.compareTo(cr) > 0 ) {
				cr = tmp;
			}
			
			oldSums = newSums;
			prevSize = size;
		}
		
		out.println(cr.sum);
		int n1 = Math.min( hash.get(cr.color1).size(), cr.size);
		int n2 = Math.min( hash.get(cr.color2).size(), cr.size);
		out.println( n1 + n2 );
		
		ArrayList<Cubik> big;
		ArrayList<Cubik> small;
		if ( n1 > n2 ) {
			big = hash.get(cr.color1);
			small = hash.get(cr.color2);
		}else {
			big = hash.get(cr.color2);
			small = hash.get(cr.color1);
		}
		for ( int i=0; i<Math.min(n1, n2); ++i ) {
			out.print( big.get(big.size() - 1 - i).number + " " + small.get(small.size() - 1 - i).number + " ");
		}
		if ( n1 != n2 ) {
			out.println( big.get(big.size() - Math.max(n1, n2)).number );
		}
		
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			st = new StringTokenizer("");
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new Thread(new E1()).start();
	}
}