===INPUT=== 10 30 1 3 2 1 3 2 3 1 2 1 ===OUTPUT=== 5884 ===END===