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.*;
import java.util.*;

public class main
{
	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
	private static long mod = 1000000000 + 7;
	private static long mod1 = 1000000000 + 9;
	private static int block;
	static LinkedList<Integer>[] l;
	static int[] c;
	static int[] ans;
	static int k;
	static HashMap<Long,Integer> arr;
	static int[] arr1;
	private static void soln()
	{
		int n=nextInt();
		Pair[] arr=new Pair[n];
		int max=0;
		for(int i=0;i<n;i++) {
			int ti=nextInt();
			int di=nextInt();
			int pi=nextInt();
			max=Math.max(max, di);
			arr[i]=new Pair(ti,di,pi,i+1);
		}
		Arrays.sort(arr);
		ArrayList<Integer>[][] dp1=new ArrayList[n+1][max+1];
		int[][] dp=new int[n+1][max+1];
		for(int i=0;i<=n;i++)
			for(int d=0;d<=max;d++)
				dp1[i][d]=new ArrayList<>();
		for(int i=0;i<n;i++) {
			for(int d=arr[i].ti;d<arr[i].di;d++) {
				dp[i+1][d]=dp[i][d-arr[i].ti]+arr[i].pi;
				for(int x:dp1[i][d-arr[i].ti]) {
					dp1[i+1][d].add(x);
				}
				dp1[i+1][d].add(arr[i].ind);
			}
			for(int d=0;d<=max;d++) {
				if(dp[i+1][d]<dp[i][d]) {
					dp[i+1][d]=Math.max(dp[i+1][d], dp[i][d]);
					dp1[i+1][d].clear();
					for(int x:dp1[i][d])
						dp1[i+1][d].add(x);
				}
			//	System.out.print(dp[i+1][d]+" ");
			}
			//System.out.println();
		}
		int ans=0;
		ArrayList<Integer> tmp=null;
		for(int d=0;d<=max;d++) {
			if(ans<=dp[n][d])
				tmp=dp1[n][d];
			ans=Math.max(ans, dp[n][d]);
		}
		pw.println(ans);
		pw.println(tmp.size());
		for(int x:tmp)
			pw.print(x+" ");
	}
	private static class Pair implements Comparable<Pair>{
		int ti,di,pi,ind;
		public Pair(int t,int d,int p,int i){
			ti=t;
			pi=p;
			di=d;
			ind=i;
		}
		public int compareTo(Pair an) {
			return this.di-an.di;
		}
	}
	private static void dfs(int cur,int prev) {
		Iterator<Integer> it=l[cur].listIterator();
		//System.out.println(cur);
		int co=c[cur];
		long tmp=((long)co << 20) + (long)(arr1[co]);
		if(arr1[co]-k < 0)
			ans[cur]=-2;
		else {
			ans[cur]=arr.get(tmp-k);
		}
		arr.put(tmp,arr1[co]);
		arr1[co]++;
		while(it.hasNext()) {
			int x=it.next();
			if(x!=prev) {
				dfs(x,cur);
			}
		}
		arr.remove(tmp);
		arr1[co]--;
	}
	private static class Node{
		int val;
		Node left;
		Node right;
		public Node(int v) {
			val=v;
		}
	}
	public static class Segment {
		private int[] tree;
		private int[] base;
		private int size;
		private int n;
		private class node{
			private int a;
			private int b;
			private int c;
			public node(int x,int y,int z){
				a=x;
				b=y;
				c=z;
			}
		}
		public Segment(int n,int[] arr){
			//this.base=arr;
			int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
	        size = 2 * (int) Math.pow(2, x) - 1;
			tree=new int[size];
			base=arr;
			this.n=n;
			build(0,0,n-1);
		}
		public void build(int id,int l,int r) {
			if(l==r) {
				tree[id]=base[l];
				return;
			}
			int mid=l+((r-l)>>1);
			build((id<<1)+1,l,mid);
			build((id<<1)+2,mid+1,r);
			tree[id]=Math.max(tree[(id<<1)+1],tree[(id<<1)+2]);
		}
		public int query(int l,int r){
			return queryUtil(l,r,0,0,n-1);
		}
		private int queryUtil(int x,int y,int id,int l,int r){
			if(l>y || x>r) 
				return 0;
			if(x <= l && r<=y)
				return tree[id];
			int mid=l+((r-l)>>1);
			return Math.max(queryUtil(x,y,(id<<1)+1,l,mid),queryUtil(x,y,(id<<1)+2,mid+1,r));
		}
		public void update(int x,int colour,int id,int l,int r){
			//System.out.println(l+" "+r+" "+x);
			if(x>r || x<l)
				return;
			if(l==r){
				tree[id]+=colour;
				return;
			}
			int mid=l+(r-l)/2;
			update(x,colour,2*id+1,l,mid);
			update(x,colour,2*id+2,mid+1,r);
			tree[id]=tree[2*id+1]+tree[2*id+2];
		}
	}

	static void multiply(long[][] a, long[][] b, long m)
	{
		int n = a.length;
		long[][] mul = new long[n][n];
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				mul[i][j] = 0;
				for (int k = 0; k < n; k++)
					mul[i][j] = (mul[i][j] + (a[i][k] * b[k][j]) % m) % m;
			}
		}
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				a[i][j] = mul[i][j];
	}
	private static class DSU{
		int[] parent;
		int[] rank;
		int[][] lr;
		public DSU(int n){
			parent=new int[n];
			rank=new int[n];
			lr=new int[n][2];
			//cnt=new int[n];
			for(int i=0;i<n;i++){
				parent[i]=i;
				rank[i]=1;
				lr[i][0]=lr[i][1]=i;
				//cnt[i]=1;
			}
		}
		int find(int i){
	        while(parent[i] !=i){
	        	parent[i]=parent[parent[i]];
	        	i=parent[i];
	        }
	        return i;
	    }
		int Union(int x, int y){
	        int xset = find(x);
	        int yset = find(y);
	        if(xset==yset)
	        	return 0;
	        	parent[yset]=xset;
	        	rank[xset]+=rank[yset];
	        	rank[yset]=0;
	        	lr[xset][1]=lr[yset][1];
	        	lr[yset][0]=lr[xset][0];
	        	//cnt[xset]+=cnt[yset];
	        	//cnt[yset]=0;
	        	return xset;
	    }
	}

	private static long pow(long a, long b, long c)
	{
		if (b == 0)
			return 1;
		long p = pow(a, b / 2, c);
		p = (p * p) % c;
		return (b % 2 == 0) ? p : (a * p) % c;
	}
	private static class Mo implements Comparable<Mo>
	{
		int l;
		int r;
		int i;

		public Mo(int a, int b, int ind)
		{
			l = a;
			r = b;
			i = ind;
		}

		@Override
		public int compareTo(Mo arg0)
		{
			int b1 = this.l / block;
			int b2 = arg0.l / block;
			return (b1 != b2) ? (b1 - b2) : (this.r - arg0.r);
		}
	}

	private static long gcd(long n, long l)
	{
		if (l == 0)
			return n;
		return gcd(l, n % l);
	}
	public static void main(String[] args) throws Exception
	{
		new Thread(null, new Runnable()
		{
			@Override
			public void run()
			{
				/*try { 
					InputReader(new FileInputStream("C:\\Users\\hardik\\Desktop\\B-large-practice.in")); 
				} catch (FileNotFoundException e) { // TODO Auto-generated catch block
					e.printStackTrace(); 
				} */
				InputReader(System.in);
				pw = new PrintWriter(System.out);
				/*try { 
					pw=new PrintWriter(new FileOutputStream("C:\\Users\\hardik\\Desktop\\out.txt")); 
				} catch (FileNotFoundException e) { // TODO Auto-generated catch block
					e.printStackTrace();
				}*/
				soln();
				pw.close();
			}
		}, "1", 1 << 26).start();
	}

	public static void InputReader(InputStream stream1)
	{
		stream = stream1;
	}

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

	private static boolean isEndOfLine(int c)
	{
		return c == '\n' || c == '\r' || c == -1;
	}

	private static 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++];
	}

	private static 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 - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-')
		{
			sgn = -1;
			c = read();
		}
		long res = 0;
		do
		{
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do
		{
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do
		{
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n)
	{
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n)
	{
		long[] arr = new long[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr)
	{
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr)
	{
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c)
	{
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private static char nextChar()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		char c1 = (char) c;
		while (!isSpaceChar(c))
			c = read();
		return c1;
	}

	private interface SpaceCharFilter
	{
		public boolean isSpaceChar(int ch);
	}
}