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.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.lang.Long;
import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * Problem statement: http://codeforces.com/problemset/problem/431/D
 * 
 * @author thepham
 * 
 */

public class E_VK2012_Round2 {
	static long Mod = 1000000007;
	static int[][][] dp;
	static int max = 100000;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		HashMap<Integer, ArrayList<Box>> map = new HashMap();
		int l = 0;
		for (int i = 0; i < n; i++) {
			int c = in.nextInt();
			long s = in.nextLong();
			if (map.containsKey(c)) {
				map.get(c).add(new Box(i, c, s));
			} else {
				map.put(c, new ArrayList());
				map.get(c).add(new Box(i, c, s));
			}
			l = Math.max(l, map.get(c).size());
		}
		for (int c : map.keySet()) {
			Collections.sort(map.get(c));
		}

		int[][] data = new int[l][2];
		long[][] cur = new long[l][2];
		for (int[] a : data) {
			Arrays.fill(a, -1);
		}
		for (int c : map.keySet()) {

			long[] re = new long[map.get(c).size()];
			for (int i = 0; i < re.length; i++) {
				re[i] = map.get(c).get(re.length - i - 1).size;
				if (i > 0) {
					re[i] += re[i - 1];

				}
				if (data[i][0] == -1) {
					data[i][0] = c;
					cur[i][0] = re[i];
				} else if (cur[i][0] < re[i]) {
					data[i][1] = data[i][0];
					cur[i][1] = cur[i][0];
					data[i][0] = c;
					cur[i][0] = re[i];
				} else if (data[i][1] == -1 || cur[i][1] < re[i]) {
					data[i][1] = c;
					cur[i][1] = re[i];
				}
			}

		}
		long max = 0;
		long total = 0;
		int[] re = new int[2];
		for (int i = 0; i < l; i++) {
			if (data[i][1] != -1) {
				long tmp = cur[i][0] + cur[i][1];
				if (tmp > max) {
					max = tmp;
					total = 2 * i;
					re[0] = data[i][0];
					re[1] = data[i][1];
				}
			}
			if (i > 0) {
				if (data[i][0] != data[i - 1][0]) {
					long tmp = cur[i][0] + cur[i - 1][0];
					if (tmp > max) {
						max = tmp;
						total = 2 * i - 1;
						re[0] = data[i][0];
						re[1] = data[i - 1][0];
					}
				} else {
					if (data[i - 1][1] != -1) {
						long tmp = cur[i][0] + cur[i - 1][1];
						if (tmp > max) {
							max = tmp;
							total = 2 * i - 1;
							re[0] = data[i][0];
							re[1] = data[i - 1][1];
						}
					}
					if (data[i][1] != -1 && data[i][1] != data[i - 1][0]) {
						long tmp = cur[i][1] + cur[i - 1][0];
						if (tmp > max) {
							max = tmp;
							total = 2 * i - 1;
							re[0] = data[i][1];
							re[1] = data[i - 1][0];
						}
					}
				}
			}
		}
		out.println(max);
		out.println((total + 2));
		int start = 0;
		int[] size = new int[2];
		int[] count = new int[2];
		size[0] = map.get(re[0]).size();
		size[1] = map.get(re[1]).size();
		for (int i = 0; i < total + 2; i++) {
			out.print((map.get(re[start]).get(size[start] - count[start] - 1).index + 1)
					+ " ");
			count[start]++;
			start = 1 - start;
		}

		out.close();
	}

	static class Box implements Comparable<Box> {

		int index, c;
		long size;

		public Box(int index, int c, long size) {
			super();
			this.index = index;
			this.c = c;
			this.size = size;
		}

		@Override
		public int compareTo(Box o) {
			// TODO Auto-generated method stub
			return Long.compare(size, o.size);
		}

	}

	static long min(long a, long b) {
		if (a > b) {
			return b;
		}
		return a;
	}

	public static int[] buildKMP(String val) {
		int[] data = new int[val.length() + 1];
		int i = 0;
		int j = -1;
		data[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(i) != val.charAt(j)) {
				j = data[j];
			}
			i++;
			j++;

			data[i] = j;
			// System.out.println(val + " " + i + " " + data[i]);
		}
		return data;
	}

	static int find(int index, int[] u) {
		if (u[index] != index) {
			return u[index] = find(u[index], u);
		}
		return index;
	}

	static int crossProduct(Point a, Point b) {
		return a.x * b.y + a.y * b.x;
	}

	static long squareDist(Point a) {
		long x = a.x;
		long y = a.y;
		return x * x + y * y;
	}

	static Point minus(Point a, Point b) {
		return new Point(a.x - b.x, a.y - b.y);
	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	static class Point {
		int x, y;

		public Point(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return "{" + x + " " + y + "}";
		}

	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static class FT {

		int[] data;

		FT(int n) {
			data = new int[n];
		}

		public void update(int index, int value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public int get(int index) {
			int result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(
			// new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}

}
