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:
/**
 p * @author prakhar28
 *
 */
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.text.*;
import java.math.*;
import java.util.regex.*;


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main{
	
	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
 
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public String readLine() throws IOException
        {
            byte[] buf = new byte[200005]; // line length+1
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n' || c==' ') {
                	//buf[cnt++]=(byte)c;
                    break;
                }
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }
 
        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');
 
            if (neg)
                return -ret;
            return ret;
        }
 
        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }
 
        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
 
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
 
            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }
 
            if (neg)
                return -ret;
            return ret;
        }
 
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
 
        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
 
        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
	
	static class FastScanner {

	    private final BufferedReader bufferedReader;
	    private StringTokenizer stringTokenizer;

	    public FastScanner() {
	        bufferedReader = new BufferedReader(new InputStreamReader(System.in));
	    }

	    public String next() {
	        while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
	            try {
	                stringTokenizer = new StringTokenizer(bufferedReader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException("Can't read next value", e);
	            }
	        }
	        return stringTokenizer.nextToken();
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public double nextDouble() {
	        return Double.parseDouble(next());
	    }

	    public String nextLine(){
	        String str = "";
	        try {
	            str = bufferedReader.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	    }
	}
	
	static void closeall() throws IOException{
		printWriter.close();
		sc.close();
		in.close();
	}
	static Scanner sc = new Scanner(System.in);
	static Reader in = new Reader();
	static FastScanner fastScanner = new FastScanner();
	static PrintWriter printWriter = new PrintWriter(new BufferedOutputStream(System.out));
	static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
	static long INF = (long)(1e18);

	
	int V,E;
	ArrayList<Integer> adj[];
	Main(int v){
		V=v;
		adj=new ArrayList[v];
		for(int i=0;i<v;i++)
			adj[i] = new ArrayList<>();
	}
	void addEdge(int u,int v){
		adj[u].add(v);
		//adj[v].add(u);
	}
	
	
	static long power(long a,long k)
	{
		long m = 1000000007;
	    long ans=1;
	    long tmp=a%m;
	    while(k>0)
	    {
	        if(k%2==1)
	        	ans=ans*tmp%m;
	        tmp=tmp*tmp%m;
	        k>>=1;
	    }
	    return ans;
	}
	
	static class Pair implements Comparable<Pair>{
		int a,b;
		Pair(int a,int b){
			this.a=a;
			this.b=b;
		}
		public int compareTo(Pair ob){
			return this.b-ob.b;
		}
		
	}
	static int gcd(int a,int b) {
		if(a<b) {
			int t = a;
			a = b;
			b = t;
		}
		int r = a%b;
		if(r==0)
			return b;
		return gcd(b,r);
	}
	
	static int lower_bound(int[] a,int low,int high,int val) {
		while(low!=high) {
			int mid = (low+high)/2;
			if(a[mid]<val)
				low=mid+1;
			else
				high=mid;
		}
		return low;
	}
	
	static int max(int a,int b) {
		return (int)Math.max(a, b);
	}
	static long max(long a,long b) {
		return (long)Math.max(a, b);
	}
	static long min(long a,long b) {
		return (long)Math.min(a, b);
	}
	static int min(int a,int b) {
		if(a<b)
			return a;
		return b;
	}
	static long m = 1000000007;
	
	static class items implements Comparable<items>{
		int t,d,p,i;
		items(int t,int d,int p,int i){
			this.t = t;
			this.d = d;
			this.p = p;
			this.i = i;
		}
		@Override
		public int compareTo(items o) {
			return this.d-o.d;
		}
	}
	
	public static void main(String args[])throws IOException{
		int n = in.nextInt();
		items a[] = new items[n];
		int x,y,z;
		for(int i=0;i<n;i++) {
			x = in.nextInt();
			y = in.nextInt();
			z = in.nextInt();
			a[i] = new items(x,y,z,i+1);
		}
		Arrays.sort(a);
		int dp[][] = new int[n+1][2005];
		int row[][] = new int[n+1][2005];
		int col[][] = new int[n+1][2005];
		int itm[][] = new int[n+1][2005];
		for(int i=0;i<n;i++) {
			for(int j=0;j<2005;j++) {
				if(dp[i][j]>dp[i+1][j]) {
					dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
					row[i+1][j] = row[i][j];
					col[i+1][j] = col[i][j];
					itm[i+1][j] = itm[i][j];
				}
				if(a[i].t+j>=a[i].d)
					continue;
				if(dp[i+1][a[i].t+j]<dp[i][j]+a[i].p) {
					dp[i+1][a[i].t+j] = max(dp[i+1][a[i].t+j],dp[i][j]+a[i].p);
					row[i+1][a[i].t+j] = i;
					col[i+1][a[i].t+j] = j;
					itm[i+1][a[i].t+j] = a[i].i;
				}
			}
		}
		int max = 0;
		int idx = 0;
		for(int i=0;i<2005;i++) {
			if(dp[n][i]>max) {
				max = dp[n][i];
				idx = i;
			}
		}
		printWriter.println(max);
		int cnt = 0;
		int r = n;
		ArrayList<Integer> arli = new ArrayList<>();
		while(dp[r][idx]>0) {
			arli.add(itm[r][idx]);
			int tmp = r;
			r = row[r][idx];
			idx = col[tmp][idx];
			cnt++;
		}
		printWriter.println(cnt);
		for(int i=arli.size()-1;i>=0;i--)
			printWriter.print(arli.get(i)+" ");
		closeall();
	}
}