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.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class E436Div2
{
    public static void main(String[] args)
    {
        new E436Div2(System.in, System.out);
    }

    private static class Solver implements Runnable
    {
        int n, maxValue;
        Item[] items;
        int[][] dp;
        List<Integer> list;
        // BufferedReader in;
        InputReader in;
        PrintWriter out;

        void solve() throws IOException
        {
            n = in.nextInt();
            items = new Item[n];

            for (int i = 0; i < n; i++)
                items[i] = new Item(i, in.nextInt(), in.nextInt(), in.nextInt());

            Arrays.sort(items, new Comparator<Item>()
            {
                @Override
                public int compare(Item one, Item two)
                {
                    if (one.expiry == two.expiry)
                        return Integer.compare(two.val, one.val);

                    return Integer.compare(one.expiry, two.expiry);
                }
            });


            dp = new int[n + 1][2001];

            // dp[i][j] = max value possible using items up to i, with total time taken until now = j.
            for (int i = 0; i < n; i++)
            {
//                System.out.println("i : " + i + ", items[i] : " + items[i]);
                for (int j = 1; j < 2001; j++)
                {
//                    System.out.println("i : " + i + ", j : " + j + ", items[i] : " + items[i]);
                    if (i == 0)
                        dp[i][j] = (items[i].expiry > j && j >= items[i].time) ? items[i].val : 0;
                    else
                    {
//                        dp[i][j] = items[i].expiry > j + items[i - 1].
                        if (items[i].expiry > j)
                        {
                            if (j - items[i].time >= 0)
                                dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - items[i].time] + items[i].val);
                            else
                                dp[i][j] = dp[i - 1][j];
                        }
                        else
                        	dp[i][j] = dp[i - 1][j];
//                            dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                    }
                }
            }

/*            System.out.println("dp[n - 1] :");

            for (int i = 0; i < n; i++, System.out.println())
                for (int j = 0; j < 107; j++)
                    System.out.print(dp[i][j] + " ");*/

			int maxAt = -1;

			for (int i = 0; i < 2001; i++)
			{
				if (dp[n - 1][i] > maxValue)
				{
					maxValue = dp[n - 1][i];
					maxAt = i;
				}
			}

//            maxValue = dp[n - 1][2000];
//            System.out.println("maxValue : " + maxValue);

            List<Integer> list = new ArrayList<>();
            int curr = maxValue;
            int i = n - 1;
            int j = maxAt;

            while (i >= 0 && curr > 0)
            {
//                System.out.println("i : " + i + ", j : " + j + ", curr : " + curr + ", item[i] : " + items[i]);
                if (i > 0)
                {
/*                	if (i == 4)
					{
						System.out.println("*********** i = 4, j : " + j + ", item[4] : " + items[i]);
						System.out.println("j : " + j + ", dp[i - 1][j - items[i].time] : " + dp[i - 1][j - items[i]
								.time]);
					}*/

					if (j - items[i].time >= 0 && dp[i - 1][j - items[i].time] + items[i].val == curr)
                    {
                        list.add(i);
                        curr -= items[i].val;
                        j -= items[i].time;
                        i--;
                    }
                    else
                    {
                        i--;
                    }
                }
                else
                {
                    if (j - items[i].time >= 0 && items[i].val == curr)
                    {
                        list.add(i);
                        curr = 0;
//                        i--;
//                        j -= items[i].time;
                    }

                    i--;
                }
            }

            Collections.reverse(list);
            out.println(maxValue);
            out.println(list.size());

            for (int x : list)
                out.print(items[x].ind + 1 + " ");

/*            dp = new int[n + 1][2001];
            list = new ArrayList<>();

            for (int i = 0; i <= n; i++)
                Arrays.fill(dp[i], -1);

            maxValue = find(0, 0);

            System.out.println("maxValue : " + maxValue);
            System.out.println("size : " + list.size());
            Collections.reverse(list);
            System.out.println("items : " + list);*/
        }

        // dp[curr][timeTaken] = max value possible using items up to curr, with total time taken until now = timeTaken.
        int find(int curr, int timeTaken)
        {
            if (curr == n)
                return 0;

            if (dp[curr][timeTaken] != -1)
                return dp[curr][timeTaken];

            int max = -1;

            if (items[curr].expiry > timeTaken + items[curr].time)
                max = find(curr + 1, timeTaken + items[curr].time) + items[curr].val;

            max = Math.max(max, find(curr + 1, timeTaken));

            if (max > maxValue)
            {
                maxValue = max;
                list = new ArrayList<>();
                list.add(items[curr].ind);
            }

            return dp[curr][timeTaken] = max;
        }

        static class Item
        {
            int ind, time, expiry, val;

            Item(int ind, int time, int expiry, int val)
            {
                this.ind = ind;
                this.time = time;
                this.expiry = expiry;
                this.val = val;
            }

            @Override
            public String toString()
            {
                return "time : " + time + ", exp : " + expiry + ", val : " + val;
            }

        }

        // uncomment below line to change to BufferedReader
        // public Solver(BufferedReader in, PrintWriter out)
        Solver(InputReader in, PrintWriter out)
        {
            this.in = in;
            this.out = out;
        }

        @Override
        public void run()
        {
            try
            {
                solve();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }

    }

    private static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        int nextInt()
        {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c & 15;

                c = read();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        boolean isSpaceChar(int c)
        {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        void close()
        {
            try
            {
                stream.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }

        InputReader(InputStream stream)
        {
            this.stream = stream;
        }

    }

    private E436Div2(InputStream inputStream, OutputStream outputStream)
    {
        // uncomment below line to change to BufferedReader
        // BufferedReader in = new BufferedReader(new
        // InputStreamReader(inputStream));
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Thread thread = new Thread(null, new Solver(in, out), "Solver", 1 << 29);

        try
        {
            thread.start();
            thread.join();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }

        in.close();
        out.flush();
        out.close();
    }

}