===INPUT=== 8 25 3 2 2 2 1 1 3 1 ===OUTPUT=== 1137 ===END===