Problem: Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if ti ≥ di, then i-th item cannot be saved.

Given the values pi for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in ta seconds, and the item b — in ta + tb seconds after fire started.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of items in Polycarp's house.

Each of the following n lines contains three integers ti, di, pi (1 ≤ ti ≤ 20, 1 ≤ di ≤ 2 000, 1 ≤ pi ≤ 20) — the time needed to save the item i, the time after which the item i will burn completely and the value of item i.

Output

In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m — the number of items in the desired set. In the third line print m distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them.

Examples

Input

3
3 7 4
2 6 5
3 7 6


Output

11
2
2 3 


Input

2
5 6 1
3 3 5


Output

1
1
1 

Note

In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11.

In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.Collection;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jialin Ouyang (Jialin.Ouyang@gmail.com)
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    QuickScanner in = new QuickScanner(inputStream);
    QuickWriter out = new QuickWriter(outputStream);
    TaskE solver = new TaskE();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskE {
    static int MAXT = 2000 + 1;
    int n;
    TaskE.Item[] items;
    int[][] maxPrice;
    boolean[][] used;
    IntArrayList solution;

    public void solve(int testNumber, QuickScanner in, QuickWriter out) {
      n = in.nextInt();
      items = new TaskE.Item[n];
      for (int i = 0; i < n; ++i) {
        items[i] = new TaskE.Item(in.nextInt(), in.nextInt(), in.nextInt(), i + 1);
      }
      Arrays.sort(items);
      int res = calc();
      out.println(res);
      out.println(calcSolution(IntArrayUtils.find(maxPrice[n], res)));
      out.println(solution);
    }

    int calc() {
      maxPrice = new int[n + 1][MAXT];
      used = new boolean[n + 1][MAXT];
      Arrays.fill(maxPrice[0], Integer.MIN_VALUE);
      maxPrice[0][0] = 0;
      for (int i = 0; i < n; ++i) {
        for (int t = 0; t < MAXT; ++t) {
          maxPrice[i + 1][t] = maxPrice[i][t];
          used[i + 1][t] = false;
        }
        TaskE.Item item = items[i];
        for (int t = item.burnT - 1 - item.saveT, st = item.burnT - 1; t >= 0; --t, --st) {
          if (maxPrice[i][t] < 0 || maxPrice[i + 1][st] >= maxPrice[i][t] + item.price) continue;
          maxPrice[i + 1][st] = maxPrice[i][t] + item.price;
          used[i + 1][st] = true;
        }
      }
      return IntArrayUtils.max(maxPrice[n]);
    }

    int calcSolution(int t) {
      solution = new IntArrayList(n);
      for (int i = n; i > 0; --i)
        if (used[i][t]) {
          TaskE.Item item = items[i - 1];
          solution.add(item.idx);
          t -= item.saveT;
        }
      solution.reverse();
      return solution.size;
    }

    static class Item implements Comparable<TaskE.Item> {
      final int saveT;
      final int burnT;
      final int price;
      final int idx;

      Item(int saveT, int burnT, int price, int idx) {
        this.saveT = saveT;
        this.burnT = burnT;
        this.price = price;
        this.idx = idx;
      }


      public int compareTo(TaskE.Item o) {
        return burnT - o.burnT;
      }

    }

  }

  static class QuickScanner {
    private static final int BUFFER_SIZE = 1024;
    private InputStream stream;
    private byte[] buffer;
    private int currentPosition;
    private int numberOfChars;

    public QuickScanner(InputStream stream) {
      this.stream = stream;
      this.buffer = new byte[BUFFER_SIZE];
      this.currentPosition = 0;
      this.numberOfChars = 0;
    }

    public int nextInt() {
      int c = nextNonSpaceChar();
      boolean positive = true;
      if (c == '-') {
        positive = false;
        c = nextChar();
      }
      int res = 0;
      do {
        if (c < '0' || '9' < c) throw new RuntimeException();
        res = res * 10 + c - '0';
        c = nextChar();
      } while (!isSpaceChar(c));
      return positive ? res : -res;
    }

    public int nextNonSpaceChar() {
      int res = nextChar();
      for (; isSpaceChar(res) || res < 0; res = nextChar()) ;
      return res;
    }

    public int nextChar() {
      if (numberOfChars == -1) {
        throw new RuntimeException();
      }
      if (currentPosition >= numberOfChars) {
        currentPosition = 0;
        try {
          numberOfChars = stream.read(buffer);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        if (numberOfChars <= 0) {
          return -1;
        }
      }
      return buffer[currentPosition++];
    }

    public boolean isSpaceChar(int c) {
      return c == ' ' || c == '\t' || isEndOfLineChar(c);
    }

    public boolean isEndOfLineChar(int c) {
      return c == '\n' || c == '\r' || c < 0;
    }

  }

  static class IntArrayUtils {
    public static int max(int[] values) {
      return max(values, 0, values.length);
    }

    public static int max(int[] values, int fromIdx, int toIdx) {
      int res = Integer.MIN_VALUE;
      for (int i = fromIdx; i < toIdx; ++i) {
        if (res < values[i]) res = values[i];
      }
      return res;
    }

    public static int find(int[] values, int value) {
      return find(values, 0, values.length, value);
    }

    public static int find(int[] values, int fromIdx, int toIdx, int value) {
      for (int i = fromIdx; i < toIdx; ++i) {
        if (values[i] == value) return i;
      }
      return -1;
    }

    public static void reverse(int[] values, int fromIdx, int toIdx) {
      for (int i = fromIdx, j = toIdx - 1; i < j; ++i, --j) {
        swap(values, i, j);
      }
    }

    public static void swap(int[] values, int uIdx, int vIdx) {
      if (uIdx == vIdx) return;
      values[uIdx] ^= values[vIdx];
      values[vIdx] ^= values[uIdx];
      values[uIdx] ^= values[vIdx];
    }

  }

  static interface IntCollection {
  }

  static class IntArrayList implements Displayable, IntCollection, Iterable<Integer> {
    private static final int[] EMPTY = {};
    public int[] values;
    public int size;

    public IntArrayList() {
      values = EMPTY;
      clear();
    }

    public IntArrayList(int capacity) {
      values = new int[IntUtils.nextPow2(capacity)];
      clear();
    }

    public IntArrayList(Collection<Integer> collection) {
      this(collection.size());
      addAll(collection);
    }


    public void clear() {
      size = 0;
    }


    public void add(int value) {
      ensureCapacity(size + 1);
      addInternal(value);
    }


    public void addAll(Collection<Integer> values) {
      ensureCapacity(size + values.size());
      for (int value : values) {
        addInternal(value);
      }
    }

    public void reverse() {
      IntArrayUtils.reverse(values, 0, size);
    }

    public void ensureCapacity(int capacity) {
      if (capacity <= values.length) return;
      int[] newValues = new int[IntUtils.nextPow2(capacity)];
      for (int i = 0; i < size; ++i) {
        newValues[i] = values[i];
      }
      values = newValues;
    }


    public Iterator<Integer> iterator() {
      return new Iterator<Integer>() {
        private int i = 0;


        public boolean hasNext() {
          return i < size;
        }


        public Integer next() {
          return values[i++];
        }
      };
    }

    private void addInternal(int value) {
      values[size++] = value;
    }

  }

  static class IntUtils {
    public static boolean isPow2(int n) {
      return n > 0 && (n & (n - 1)) == 0;
    }

    public static int nextPow2(int n) {
      if (n < 1) return 1;
      return isPow2(n) ? n : Integer.highestOneBit(n) << 1;
    }

  }

  static class QuickWriter {
    private final PrintWriter writer;

    public QuickWriter(OutputStream outputStream) {
      this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public QuickWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; ++i) {
        if (i > 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void println(Object... objects) {
      print(objects);
      writer.print('\n');
    }

    public void print(int[] objects, int fromIdx, int toIdx, char delimiter) {
      for (int i = fromIdx; i < toIdx; ++i) {
        if (i > fromIdx) writer.print(delimiter);
        writer.print(objects[i]);
      }
    }

    public void println(int[] objects, int fromIdx, int toIdx, char delimiter) {
      print(objects, fromIdx, toIdx, delimiter);
      writer.print('\n');
    }

    public void println(IntArrayList lst) {
      println(lst, ' ');
    }

    public void println(IntArrayList lst, char delimiter) {
      println(lst.values, 0, lst.size, delimiter);
    }

    public void close() {
      writer.close();
    }

  }

  static interface Displayable {
  }
}