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.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeMap;


public class cf159e {
  public static void main(String[] args) {
    FastIO in = new FastIO(), out = in;
    int n = in.nextInt();
    Map<Long,Cluster<Pair<Long,Long>>> map = new HashMap<Long,Cluster<Pair<Long,Long>>>();
    long[] c = new long[n], s = new long[n];
    for(int i=0; i<n; i++) {
      c[i] = in.nextInt();
      s[i] = in.nextInt();
      if(!map.containsKey(c[i])) map.put(c[i],new Cluster<Pair<Long,Long>>());
      map.get(c[i]).add(new Pair<Long,Long>(-s[i],(long)i));
    }
    Map<Long,Pair<Long,Long>> sizes = new HashMap<Long,Pair<Long,Long>>();
    long ans = 0;
    long c1 = 0, c2 = 0;
    for(Cluster<Pair<Long,Long>> cl : map.values()) {
      long sum = 0;
      long count = 0;
      for(Pair<Long,Long> p : cl) {
        sum += -p.first;
        count++;
        if(sizes.containsKey(count-1)) {
          long tsum = sum + sizes.get(count-1).first;
          if(tsum > ans) {
            c1 = c[p.second.intValue()];
            c2 = sizes.get(count-1).second;
            ans = tsum;
          }
        }
        if(sizes.containsKey(count)) {
          long tsum = sum + sizes.get(count).first;
          if(tsum > ans) {
            c1 = c[p.second.intValue()];
            c2 = sizes.get(count).second;
            ans = tsum;
          }
        }
        if(sizes.containsKey(count+1)) {
          long tsum = sum + sizes.get(count+1).first;
          if(tsum > ans) {
            c2 = c[p.second.intValue()];
            c1 = sizes.get(count+1).second;
            ans = tsum;
          }
        }
      }
      sum = 0;
      count = 0;
      for(Pair<Long,Long> p : cl) {
        sum += -p.first;
        count++;
        if(!sizes.containsKey(count) || sum > sizes.get(count).first) {
          sizes.put(count, new Pair<Long,Long>(sum,c[p.second.intValue()]));
        }
      }
    }
    out.println(ans);
    Iterator<Pair<Long,Long>> i1 = map.get(c1).iterator();
    Iterator<Pair<Long,Long>> i2 = map.get(c2).iterator();
    int count = 0, total = 0;
    StringBuilder sb = new StringBuilder();
    while(true) {
      if(count % 2 == 0) {
        if(!i1.hasNext()) break;
        total++;
        sb.append((i1.next().second+1)+" ");
      }
      else {
        if(!i2.hasNext()) break;
        total++;
        sb.append((i2.next().second+1)+" ");        
      }
      count++;
    }
    out.println(total);
    out.println(sb.toString().trim());
    out.close();
  }
  static class Pair<T1 extends Comparable<? super T1>, T2 extends Comparable<? super T2>> implements Comparable<Pair<T1,T2>>{
    T1 first;
    T2 second;
    Pair(T1 _first, T2 _second) {
      first = _first;
      second = _second;
    }
    @Override
    public int compareTo(Pair<T1,T2> p) {
      int z = first.compareTo(p.first);
      if(z != 0) return z;
      return second.compareTo(p.second);
    }
    
    @Override
    public boolean equals(Object o) {
      if(!(o instanceof Pair<?,?>)) return false;
      @SuppressWarnings("unchecked")
      Pair<T1,T2> p = (Pair<T1,T2>)o;
      return first.equals(p.first) && second.equals(p.second); 
    }
    public String toString() {
      return first+":"+second;
    }
  }
  static class Cluster<T extends Comparable<? super T>> implements Iterable<T> {
    TreeMap<T,Long> map = new TreeMap<T,Long>();
    Cluster() {}
    void add(T t) {
      if(map.containsKey(t)) map.put(t, map.get(t)+1);
      else map.put(t, 1L);
    }
    @Override
    public Iterator<T> iterator() {
      return new ClusterIterator<T>(map);
    }
    public String toString() {
      return "["+map+"]";
    }
  }
  static class ClusterIterator<T extends Comparable<? super T>> implements Iterator<T> {
    Iterator<Entry<T,Long>> baseIterator;
    T element;
    long count = 0;
    public ClusterIterator(TreeMap<T, Long> map) {
      baseIterator = map.entrySet().iterator();
    }

    @Override
    public boolean hasNext() {
      if(count > 0) return true;
      return baseIterator.hasNext();
    }

    @Override
    public T next() {
      if(count == 0) {
        Entry<T,Long> curEntry = baseIterator.next();
        element = curEntry.getKey();
        count = curEntry.getValue();
        return next();
      }
      count--;
      return element;
    }

    @Override
    public void remove() {
      throw new UnsupportedOperationException();
    }
  }
  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;
    
    public FastIO() {
      this(System.in,System.out);
    }
    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }
    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch(Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }
    public int numTokens() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }
    public String next() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }
    public double nextDouble() {
      return Double.parseDouble(next());
    }
    public long nextLong() {
      return Long.parseLong(next());
    }
    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}
