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.math.*;
import java.io.*;
import java.awt.*;
import java.util.*;
public class Solution{
    static Helper hp;
    final static int MAXN = 1000_006;
    final static long MOD = (long) 1000000007;
    final static long MOD1 = (long) 998244353;
    public static void debug(Object s)throws Exception{
        if(hp.debugger)System.out.println(s.toString());
    }
    public static void debug(int a[])throws Exception{
        if(hp.debugger)System.out.println(Arrays.toString(a));
    }
    public static void main(String []args)throws Exception
    {
        hp=new Helper(MOD,MAXN);
        //hp.initIO("input.txt","output.txt");
        hp.initIO(System.in,System.out);
        solve();
    }
    static int n;
    static Item items[];
    static void solve()throws Exception{
        boolean testCases = false;
        int tc=testCases?hp.nextInt():1;
        for (int tce = 1; tce <= tc; tce++) {
            n=hp.nextInt();
            items=new Item[n];
            for(int i=0;i<n;i++)
            {
                items[i]=new Item(i+1,hp.nextInt(),hp.nextInt(),hp.nextInt());
            }
            Arrays.sort(items);
            map=new HashMap<>();
            ArrayList<Integer> ans=solve(0,0);
            hp.println(value(ans));
            hp.println(ans.size());
            for(int x:ans)hp.printsp(items[x].index);


        }
        hp.flush();
    }
    public static int value(ArrayList<Integer> taken)
    {
        int sum=0;
        for(int x:taken)
            sum+=items[x].p;
        return sum;
    }
    static HashMap<Point,ArrayList<Integer>> map;
    public static ArrayList<Integer> solve(int time_used,int curr_index)
    {
        if(map.get(new Point(time_used,curr_index))!=null)
        {
            ArrayList<Integer> temp=map.get(new Point(time_used,curr_index));
            ArrayList<Integer> temp1=new ArrayList<>();
            for(int x:temp)
                if(x>=curr_index)
                    temp1.add(x);
            return temp1;
        }
        if(curr_index==n)
            return new ArrayList<Integer>();;
        ArrayList<Integer> one;
        if(time_used+items[curr_index].t>=items[curr_index].d)
            one=new ArrayList<>();
        else
        {
            one=solve(time_used+items[curr_index].t,curr_index+1);
            one.add(0,curr_index);
        }
        ArrayList<Integer> zero=solve(time_used,curr_index+1);
        if(value(one)>value(zero))
        {
            map.put(new Point(time_used,curr_index),one);
            return one;
        }
        else
        {
            map.put(new Point(time_used,curr_index),zero);
            return zero;
        }
    }
}
class Item implements Comparable<Item>
{
    int index,t,d,p;
    Item(int i,int a,int b,int c)
    {   
        index=i;
        t=a;
        d=b;
        p=c;
    }
    public int compareTo(Item o)
    {
        if(d-o.d!=0)
            return d-o.d;
        return o.p-p;
    }

}
class Helper {
    final long MOD;
    final int MAXN;
    final Random rnd;
    boolean debugger;
    public Helper(long mod, int maxn) {
        MOD = mod;
        MAXN = maxn;
        rnd = new Random();
    }


    public static int[] sieve;
    public static ArrayList<Integer> primes;

    public void setSieve() {
        primes = new ArrayList<>();
        sieve = new int[MAXN];
        int i, j;
        for(i=0;i<MAXN;i++) sieve[i]=i;
        for (i = 2; i*i< MAXN; ++i)
        {
            if (sieve[i] == i) {
                for (j = i*i;j < MAXN; j += i) {
                    if(sieve[j]==j)
                    sieve[j] = i;
                }
            }
        }
        for(i=2;i<MAXN;i++)if(sieve[i]==i)primes.add(i);
    }

    public static long[] factorial;

    public void setFactorial() {
        factorial = new long[MAXN];
        factorial[0] = 1;
        for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
    }

    public long getFactorial(int n) {
        if (factorial == null) setFactorial();
        return factorial[n];
    }

    public long ncr(int n, int r) {
        if (r > n) return 0;
        if (factorial == null) setFactorial();
        long numerator = factorial[n];
        long denominator = factorial[r] * factorial[n - r] % MOD;
        return numerator * pow(denominator, MOD - 2, MOD) % MOD;
    }


    public Long[] getLongArray(int size) throws Exception {
        Long[] ar = new Long[size];
        for (int i = 0; i < size; ++i) ar[i] = new Long(nextLong());
        return ar;
    }

    public Integer[] getIntArray(int size) throws Exception {
        Integer[] ar = new Integer[size];
        for (int i = 0; i < size; ++i) ar[i] = new Integer(nextInt());
        return ar;
    }

    public String[] getStringArray(int size) throws Exception {
        String[] ar = new String[size];
        for (int i = 0; i < size; ++i) ar[i] = next();
        return ar;
    }

    public String joinElements(long... ar) {
        StringBuilder sb = new StringBuilder();
        for (long itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }


    public String joinElements(int... ar) {
        StringBuilder sb = new StringBuilder();
        for (int itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(String... ar) {
        StringBuilder sb = new StringBuilder();
        for (String itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(Object... ar) {
        StringBuilder sb = new StringBuilder();
        for (Object itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }


    public long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }
    public int max(int ... ar)
    {
        int max=ar[0];
        for(int itr:ar)
            max=Math.max(max,itr);
        return max;
    }
    public long max(long ... ar){
        long max=ar[0];
        for(long itr:ar)max=Math.max(max,itr);
        return max;
    }
    public <T extends Comparable<T>> T max(T ... ar)
    {
        T max=ar[0];
        for(T itr:ar) max=itr.compareTo(max)>0?itr:max;
        return max;
    }
    public <T extends Comparable<T>> T min(T ... ar)
    {
        T min=ar[0];
        for(T itr:ar) min=itr.compareTo(min)<0?itr:min;
        return min; 
    }
    public Long sum(Long... arr)
    {
        Long sum=new Long(0);
        for(Long itr:arr)sum+=itr;
        return sum;
    }
    public Long sum(Integer ... arr)
    {
        Long sum=new Long(0);
        for(Integer itr:arr)sum+=itr;
        return sum;
    }
    public long sum(long... ar) {
        long sum = 0;
        for (long itr : ar) sum += itr;
        return sum;
    }

    public long sum(int... ar) {
        long sum = 0;
        for (int itr : ar) sum += itr;
        return sum;
    }

    public long pow(long base, long exp, long MOD) {
        base %= MOD;
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) ret = ret * base % MOD;
            base = base * base % MOD;
            exp >>= 1;
        }
        return ret;
    }


    static final int BUFSIZE = 1 << 20;
    static byte[] buf;
    static int index, total;
    static InputStream in;
    static BufferedWriter bw;


    public void initIO(InputStream is, OutputStream os) {
        try {
            debugger=false;
            in = is;
            bw = new BufferedWriter(new OutputStreamWriter(os));
            buf = new byte[BUFSIZE];
        } catch (Exception e) {
        }
    }

    public void initIO(String inputFile, String outputFile) {
        try {
            debugger=true;
            in = new FileInputStream(inputFile);
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile)));
            buf = new byte[BUFSIZE];
        } catch (Exception e) {
        }
    }

    private int scan() throws Exception {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public String next() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public int nextInt() throws Exception {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public long nextLong() throws Exception {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public void print(Object a) throws Exception {
        bw.write(a.toString());
    }

    public void printsp(Object a) throws Exception {
        print(a);
        print(" ");
    }

    public void println() throws Exception {
        bw.write("\n");
    }

    public void println(Object a) throws Exception {
        print(a);
        println();
    }

    public void flush() throws Exception {
        bw.flush();
    }
}