===INPUT=== 5 5 300 1 100 2 200 2 200 1 200 3 1 2 1 3 2 4 3 4 3 5 ===OUTPUT=== 500 ===END===