from heapq import heappush, heappop

def solve():
    try:
        line = input().split()
        if not line:
            return
        n = int(line[0])
        
        tasks = []
        for _ in range(n):
            row = list(map(int, input().split()))
            if row:
                tasks.append(row)
    except EOFError:
        return

    # Sort by deadline (Earliest Deadline First)
    tasks.sort(key=lambda x: x[2])

    # Bound function: optimistic sum of priorities of all future tasks 
    # that could theoretically start at current_time and meet their deadline.
    def get_bound(idx, time, current_p):
        b = current_p
        for i in range(idx, n):
            if time + tasks[i][0] <= tasks[i][2]:
                b += tasks[i][1]
        return b

    # Priority Queue: (-bound, time, -priority, index)
    pq = []
    
    max_p = 0
    root_bound = get_bound(0, 0, 0)
    
    # Push root
    heappush(pq, (-root_bound, 0, 0, 0))

    while pq:
        bound, time, neg_p, idx = heappop(pq)
        bound = -bound
        p = -neg_p

        if bound <= max_p:
            continue
            
        if idx == n:
            if p > max_p:
                max_p = p
            continue
            
        # Branch 1: Include current interview
        dur, prio, dead = tasks[idx]
        if time + dur <= dead:
            new_time = time + dur
            new_p = p + prio
            
            if new_p > max_p:
                max_p = new_p
                
            new_bound = get_bound(idx + 1, new_time, new_p)
            if new_bound > max_p:
                heappush(pq, (-new_bound, new_time, -new_p, idx + 1))
        
        # Branch 2: Skip current interview
        exc_bound = get_bound(idx + 1, time, p)
        if exc_bound > max_p:
            heappush(pq, (-exc_bound, time, -p, idx + 1))

    print(f"Maximum Priority: {max_p}")

if __name__ == "__main__":
    solve()

# Sample Test Case
# ----------------
# Input:
# 4
# 2 10 5
# 2 20 3
# 1 30 4
# 3 15 10
#
# Output:
# Maximum Priority: 75
#
# Explanation:
# 4 Interviews. Format: Duration Priority Deadline
# Sorted by Deadline:
# 1. (2, 20, 3)
# 2. (1, 30, 4)
# 3. (2, 10, 5)
# 4. (3, 15, 10)
#
# Schedule:
# - Pick Item 1: Time becomes 2. Priority 20. (Valid: 2 <= 3)
# - Pick Item 2: Time becomes 3. Priority 20+30=50. (Valid: 3 <= 4)
# - Pick Item 3: Time becomes 5. Priority 50+10=60. (Valid: 5 <= 5)
# - Pick Item 4: Time becomes 8. Priority 60+15=75. (Valid: 8 <= 10)
# Total Priority = 75.