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.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Random;
import java.util.StringTokenizer;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.RestoreAction;

public class Main implements Runnable {
	public static void main(String[] args) {
		(new Thread(new Main())).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			//in = new BufferedReader(new FileReader("input"));
			out = new PrintWriter(System.out);

			slv();
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	String nt() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int ni() throws NumberFormatException, IOException {
		return Integer.parseInt(nt());
	}

	HashMap<Integer, Integer> _hm = new HashMap<Integer, Integer>();
	int cnt = 0;

	int longToShort(int x) {
		if (!_hm.containsKey(x)) {
			_hm.put(x, cnt++);
		}

		return _hm.get(x);
	}

	void prnt(long[] a) {
		for (int i = 0; i < a.length; i++) {
			if (a[i] > 0) {
				out.print(i + "(" + a[i] + ") ");
			}
		}
		out.println();
	}

	void prnt2(long[] a) {
		for (int i = 0; i < a.length; i++) {
			out.print(a[i] + " ");
		}
		out.println();
	}

	void prnt(ArrayList[] a) {
		for (int i = 0; i < a.length; i++) {
			if (a[i].size() > 0) {
				out.print(i + " = > " + a[i]);
				out.println();
			}
		}
		out.println();
	}

	int maxn = (int) 2e5 + 500;

	class Max2 {
		public Max2() {
			Arrays.fill(sums[0], 0);
			Arrays.fill(sums[1], 0);
			Arrays.fill(cId[0], -1);
			Arrays.fill(cId[1], -1);
		}

		int getMaxId(int len, int curColor) {
			int sh = 0;
			if (cId[len][0] == curColor) {
				sh++;
			}
			return cId[len][sh];
		}

		long getMaxHigh(int len, int curColor) {
			int sh = 0;
			if (cId[len][0] == curColor) {
				sh++;
			}
			if (cId[len][sh] == -1)
				return Long.MIN_VALUE;
			return sums[len][sh];
		}

		void update(int len, int color, long heigh) {
			if (cId[len][0] == -1 || heigh > sums[len][0]) {
				cId[len][1] = cId[len][0];
				sums[len][1] = sums[len][0];
				//
				sums[len][0] = heigh;
				cId[len][0] = color;
				return;
			}
			if (cId[len][1] == -1 || heigh > sums[len][1]) {
				sums[len][1] = heigh;
				cId[len][1] = color;
				return;
			}
		}

		private long[][] sums = new long[maxn][2];
		private int[][] cId = new int[maxn][2];
	}

	class Rec implements Comparable<Rec> {
		int id;
		long heigh;

		@Override
		public int compareTo(Rec o) {
			if (o.heigh < heigh)
				return -1;
			else if (o.heigh > heigh)
				return 1;
			return 0;
		}

		@Override
		public String toString() {
			return heigh + "@" + id;
		}
	}

	void slv() throws Exception {
		if (false && true) {
			out = new PrintWriter("123");
			gen();
			return;
		}
		int n = ni();

		int tCnt[] = new int[maxn];
		long tLen[] = new long[maxn];

		ArrayList<Rec>[] colors = new ArrayList[maxn];
		for (int i = 0; i < maxn; i++) {
			colors[i] = new ArrayList<Rec>();
		}
		long mxV = -1;
		int mxId = -1;
		for (int i = 0; i < n; i++) {
			int color = longToShort(ni()), len = ni();
			Rec t = new Rec();
			t.id = i + 1;
			t.heigh = len;
			if (len > mxV) {
				mxV = len;
				mxId = i + 1;
			}
			colors[color].add(t);
			tCnt[color]++;
			tLen[color] += len;
		}

		Max2 mx = new Max2();

		for (int color = 0; color < maxn; color++) {
			Collections.sort(colors[color]);

			int N = colors[color].size();
			long sum = 0;
			for (int j = 0; j < N; j++) {
				sum += colors[color].get(j).heigh;
				// colors[color].get(j).heigh = sum;

				mx.update(j + 1, color, sum);
			}
		}
		//
		//prnt(colors);
		// prnt(sums);
		//

		long resTotal = -1;
		int ansC1 = -1, ansC2 = -1;

		for (int color = 0; color < maxn; color++) {
			int curLen = tCnt[color];
			if (curLen > 0) {
				for (int cLen = Math.max(0, curLen - 1); cLen <= curLen + 1; cLen++) {
					int mId = mx.getMaxId(cLen, color);
					if (mId != -1) {
						long tRes = tLen[color] + mx.getMaxHigh(cLen, color);
						if (mId != color && tRes > resTotal) {
							resTotal = tRes;
							ansC1 = color;
							ansC2 = mId;
						}
					}
				}
			}
		}
		if (resTotal > mxV) {
			out.println(resTotal);
			int len1 = colors[ansC1].size();
			int len2 = Math.min(colors[ansC2].size(), len1 + 1), tmpLen;
			out.println(len1 + len2);
			ArrayList<Rec> list1 = colors[ansC1];
			ArrayList<Rec> list2 = colors[ansC2], tmpList;

			if (len2 > len1) {
				tmpLen = len1;
				len1 = len2;
				len2 = tmpLen;
				//
				list1 = colors[ansC2];
				list2 = colors[ansC1];
			}

			for (int i = 0; i < len1; i++) {
				out.print(list1.get(i).id + " ");
				if (i < len2)
					out.print(list2.get(i).id + " ");
			}
			out.println();
		} else {
			out.println(mxV);
			out.println(1);
			out.println(mxId);
		}
	}

	void gen() {
		int n = (int) 1e5;
		out.println(n);
		Random r = new Random();
		for (int i = 0; i < n; i++) {
			// out.println((r.nextInt((int) 1e9) + 1) + " " + (int) 1e9);
			out.println((i % 2 + 1) + " " + (int) 1e9);
		}
	}

	private StringTokenizer st;
	private BufferedReader in;
	private PrintWriter out;
}