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 t_{i} seconds to save i-th item. In addition, for each item, he estimated the value of d_{i} — the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if t_{i} ≥ d_{i}, then i-th item cannot be saved.

Given the values p_{i} 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 t_{a} seconds, and the item b — in t_{a} + t_{b} 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 t_{i}, d_{i}, p_{i} (1 ≤ t_{i} ≤ 20, 1 ≤ d_{i} ≤ 2 000, 1 ≤ p_{i} ≤ 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.

Difficulty: interview

Starter code:

Solutions:

n = int(input())

items = []
max_time = 0

for i in range(1,n+1):
    t,d,p = list(map(int,input().split()))
    max_time = max(max_time, d)
    items.append((t,d,p,i))

items.sort(key=lambda x: x[1])

dp = [[(0,[]) for _ in range(n+1)] for _ in range(max_time+1)]

for time in range(1, max_time+1):
    for it in range(1, n+1):
        
        if time < items[it-1][0] or time >= items[it-1][1]:
            dp[time][it] = max(dp[time][it-1], dp[time-1][it])
        else:
            
            pick = dp[time-items[it-1][0]][it-1][0] + items[it-1][2]
            if dp[time][it-1][0] > pick : 
                dp[time][it] = max(dp[time][it-1], dp[time-1][it])
            else:
                
                dp[time][it] = (dp[time-items[it-1][0]][it-1][0] + items[it-1][2], list(dp[time-items[it-1][0]][it-1][1]))
                dp[time][it][1].append(items[it-1][3])

#print(dp)

res = max(dp[max_time])

print(res[0])
print(len(res[1]))
print(*res[1])             


P = [0] * 2001
S = [[] for i in range(2001)]

q = [list(map(int, input().split())) + [str(i + 1)] for i in range(int(input()))]
q.sort(key=lambda q: q[1])

for t, d, p, i in q:
    for x in range(t, d)[::-1]:
        if P[x] < P[x - t] + p:
            P[x] = P[x - t] + p
            S[x] = S[x - t] + [i]

k = P.index(max(P))
print('\n'.join([str(P[k]), str(len(S[k])), ' '.join(S[k])]))

from functools import lru_cache


def readints():
    return [int(obj) for obj in input().strip().split()]


class Solver:
    def main(self):
        n = readints()[0]
        self.t, self.d, self.p = [], [], []
        for i in range(n):
            t1, d1, p1 = readints()
            self.t.append(t1)
            self.d.append(d1)
            self.p.append(p1)

        self.backtrack = []
        sd = max(self.d) + 1
        for i in range(n+1):
            self.backtrack.append([])
            for j in range(sd):
                self.backtrack[i].append(0)

        triples = list(zip(self.t, self.d, self.p, list(range(1, n+1))))
        triples = sorted(triples, key=lambda x: x[1])
        self.t, self.d, self.p, self.indexes = [0], [0], [0], []
        for i in range(n):
            self.t.append(triples[i][0])
            self.d.append(triples[i][1])
            self.p.append(triples[i][2])
            self.indexes.append(triples[i][3])

        self.f = []
        for i in range(n+1):
            self.f.append([])
            for j in range(sd):
                self.f[i].append(0)

        for i in range(1, n+1):
            for d in range(sd):
                if d - self.t[i] >= 0 and d < self.d[i] and self.t[i] < self.d[i]:
                    data = self.f[i - 1][d - self.t[i]]
                    if data + self.p[i] > self.f[i][d]:
                        self.f[i][d] = data + self.p[i]
                        self.backtrack[i][d] = i

                data = self.f[i - 1][d]
                if data > self.f[i][d]:
                    self.f[i][d] = data
                    self.backtrack[i][d] = 0

        ans = 0
        res = []
        best = None
        for i in range(sd):
            data = self.f[n][i]
            if data > ans:
                ans = data
                best = (n, i)

        if best is None:
            print('0\n0\n')
            return

        i = best[0]
        s = best[1]
        while i > 0:
            if self.backtrack[i][s] != 0:
                res.append(self.backtrack[i][s])
                s -= self.t[self.backtrack[i][s]]
            i -= 1

        print(ans)
        print(len(res))
        print(' '.join(str(self.indexes[item - 1]) for item in reversed(res)))


Solver().main()


# -*- coding: utf-8 -*-

import math
import collections
import bisect
import heapq
import time
import random

"""
created by shhuan at 2017/10/4 21:10

"""

N = int(input())
M = []
for i in range(N):
    M.append([int(x) for x in input().split()])

# N = 9
# M = [[13, 18, 14],
#      [8, 59, 20],
#      [9, 51, 2],
#      [18, 32, 15],
#      [1, 70, 18],
#      [14, 81, 14],
#      [10, 88, 16],
#      [18, 52, 3],
#      [1, 50, 6]]

MA = []
for i, row in enumerate(M):
    t, d, p = row
    MA.append((d, p, t, i+1))
M = sorted(MA)

# for row in M:
#     print(row)

T = [0] + [x[2] for x in M]
D = [0] + [x[0] for x in M]
P = [0] + [x[1] for x in M]
I = [0] + [x[3] for x in M]

dmax = max(D)

# dp[t][i]即时间t内能够拯救的前i个物品的最大物品价值
dp = [[0 for _ in range(N+1)] for _ in range(dmax)]
track = [[0 for _ in range(N+1)] for _ in range(dmax)]
for t in range(dmax):
    for i in range(1, N+1):
        ti = t-T[i]
        if T[i] <= t < D[i] and ti >= 0:
            dp[t][i] = max(dp[t][i-1], dp[ti][i-1] + P[i])
            if dp[t][i-1] > dp[ti][i-1]+P[i]:
                track[t][i] = (t, i-1, -1)
            else:
                track[t][i] = (ti, i-1, i)
        else:
            dp[t][i] = dp[t][i-1]
            track[t][i] = (t, i-1, -1)

# for row in dp:
#     print(row)

saved = 0
t, i, j = 0, N, -1
for j in range(dmax):
    if dp[j][N] > saved:
        saved = dp[j][N]
        t = j

print(saved)
# print(I)
res = []
while t > 0 and i > 0:
    t, i, j = track[t][i]
    if j > 0:
        res.append(I[j])

print(len(res))
print(' '.join([str(x) for x in reversed(res)]))






import os
import sys
import re
from collections import OrderedDict

if 'PYCHARM' in os.environ:
    sys.stdin = open('in', 'r')

n = int(input())
things = []
for i in range(n):
    t, d, p = list(map(int, input().split()))
    things.append((d, t, p, i + 1))

things.sort()
D = 2001
f = [[0] * D]
w = [[False] * D]

for i in range(n):
    thing = things[i]
    w.append([False] * D)
    f.append(list(f[i]))
    for j in range(D):
        ni = j + thing[1]
        nv = f[i][j] + thing[2]
        if ni < thing[0]:
            if f[i + 1][ni] < nv:
                f[i + 1][ni] = nv
                w[i + 1][ni] = True

ind = 0
for i in range(D):
    if f[n][i] > f[n][ind]:
        ind = i

print(f[n][ind])
ans = []
for i in range(n, 0, -1):
    if w[i][ind]:
        ind -= things[i - 1][1]
        ans.append(things[i - 1][3])

print(len(ans))
print(*reversed(ans))





n = int(input())
a = []
for i in range(n):
    t,d,p = list(map(int,input().split()))
    a.append([t,d,p,i+1])
a.sort(key = lambda x: x[1])
d = {0: [0,[]]}
for i in a:
    e = {}
    for j in d:
        if d[j][0] + i[0] < i[1]:
            if j + i[2] in d:
                if d[j][0]+i[0] < d[j+i[2]][0]:
                    e[j+i[2]] = [d[j][0]+i[0],d[j][1]+[i[3]]]
            else:
                e[j+i[2]] = [d[j][0]+i[0],d[j][1]+[i[3]]]
    d.update(e)
t = max(d)                
print(t)
k = d[t][1]
print(len(k))
k = list(map(str,k))
print(' '.join(k))


from sys import stdin
input = stdin.readline
n = int(input())
T = 2001
t, d, p, idx = [], [], [], []
ans = []
arr = []
for i in range(n):
    a, b, c = map(int, input().split())
    arr.append([a, b, c, i])
arr.sort(key=lambda x: x[1])
for i in arr:
    t.append(i[0]); d.append(i[1]); p.append(i[2]); idx.append(i[3])
dp = [[0 for j in range(n)] for i in range(T)]
for time in range(1, T):
    for i in range(n):
        #dp[time][i] = max(dp[time - 1][i], dp[time][i - 1])
        dp[time][i] = dp[time][i - 1]
        if d[i] > time >= t[i]:
            if i:
                dp[time][i] = max(dp[time][i], p[i] + dp[time - t[i]][i - 1])
            else:
                dp[time][i] = p[i]
b = [0, [0 ,0]]
for i in range(T):
    for j in range(n):
        if b[0] < dp[i][j]:
            b = [dp[i][j], [i, j]]
print(b[0])
b = b[1]
while dp[b[0]][b[1]] and b[0] > -1:
    if b[1] and dp[b[0]][b[1]] != dp[b[0]][b[1] - 1]:
        ans.append(b[1])
        b[0] -= t[b[1]]
    elif b[1] == 0:
        if dp[b[0]][b[1]]:
            ans.append(b[1])
        break
    b[1] -= 1
print(len(ans))
for i in ans[::-1]:
    print(idx[i] + 1, end=' ')

import copy
n = int(input()) 
arr = []
m = 0
for er in range(n):
    temp = list(map(int,input().split(" ")))
    temp.append(er+1)
    if(temp[0]<temp[1]):
        arr.append(temp)
        if(temp[1]>m):
            m = temp[1]
    else:
        n-=1
arr.sort(key = lambda x:x[1])
#print(arr)
temp=[]
for i in range(n):
    temp.append([0])
com = []
com.append(temp)
total = [0,0]
for i in range(1,m+1):
    temp = []
    for j in range(n+1):
        if(j==0):
            temp.append([0])
        else:
            p=arr[j-1]
            if(p[0]>i or p[1]<=i):
                temp.append(temp[j-1])
            else:
                te = i - p[0]
                ty = copy.deepcopy(com[te][j-1])
                ty[0]+=p[2]
                ty.append(j)
                if(total[0]<ty[0]):
                    total = ty
                if(temp[j-1][0]<ty[0]):
                    temp.append(ty)
                else:
                    temp.append(temp[j-1])
    #print(temp , " temp")
    com.append(temp)
#print(com)
print(total[0])
if(total[0]>0):
    print(len(total)-1)
    for i in range(1,len(total)):
        print(arr[total[i]-1][3] , end = " ")
else:
    print("0")

from sys import stdin

n = int(stdin.readline())

items = []

for i in range(n):
  t,d,p = [int(x) for x in stdin.readline().split()]
  items.append((d,t,p,i))

items.sort()

mem = [{} for x in range(n)]
mem2 = [{} for x in range(n)]

def best(time,x):
  time += items[x][1]
  if time in mem[x]:
    return mem[x][time]

  if time >= items[x][0]:
    mem[x][time] = 0
    mem2[x][time] = -1
    return 0
  
  top = 0
  top2 = -1

  for i in range(x+1,n):
    temp = best(time,i)
    if temp > top:
      top = temp
      top2 = i

  mem[x][time] = top+items[x][2]
  mem2[x][time] = top2
  return mem[x][time]

top = -1
l = []

for x in range(n):
  b = best(0,x)
  if b > top:
    top = b
    #print('new',x,top)
    l = []
    c = x
    time = 0
    while c != -1:
      time += items[c][1]
      l.append(items[c][3])
      if time in mem2[c]:
        c = mem2[c][time]
      else:
        c = -1

print(top)
if top != 0:
  print(len(l))
  print(' '.join([str(x+1) for x in l]))
else:
  print(0)
  print()