Make More Money

Limits 1s, 512 MB

You, the great businessman of TEUB, arrived at ESC land which consists of NNN cities numbered from 1 to NNN. You are currently at city 1. For each city iii, you arrive at (including your current city) in ESC land, you do some business and make profit aia_iai​. The profit can be negative which means you have lost ∣ai∣|a_i|∣ai​∣ amount of money in your business.But there is a special rule for travelling ESC land:

This is a companion discussion topic for the original entry at