<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> class Solution ( object ) : <EOL> def solve ( self , cipher ) : <EOL> """<STR_LIT>""" <EOL> N , A = cipher <EOL> f = [ <NUM_LIT:0> for _ in A ] <EOL> f [ N - <NUM_LIT:1> ] = A [ N - <NUM_LIT:1> ] <EOL> for i in xrange ( N - <NUM_LIT:2> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> f [ i ] = max ( A [ i ] , f [ i + <NUM_LIT:1> ] ) <EOL> profit = <NUM_LIT:0> <EOL> for i in xrange ( N - <NUM_LIT:1> ) : <EOL> profit += max ( <NUM_LIT:0> , f [ i + <NUM_LIT:1> ] - A [ i ] ) <EOL> return profit <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import sys <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:r>" ) <EOL> solution = Solution ( ) <EOL> testcases = int ( f . readline ( ) . strip ( ) ) <EOL> for t in xrange ( testcases ) : <EOL> N = int ( f . readline ( ) . strip ( ) ) <EOL> A = map ( int , f . readline ( ) . strip ( ) . split ( '<STR_LIT:U+0020>' ) ) <EOL> cipher = N , A <EOL> s = "<STR_LIT>" % ( solution . solve ( cipher ) ) <EOL> print s , </s>
