#http://www.maths.nuigalway.ie/
#~gettrick/teach/cs102/
#p=[23,45,-31,-3,89,7,4,-2,4,56,-227,43]
#p=[2,4,-5,6]
#p=[-3,-56,-38]
#p=[-2,-4,45,3,-7]
p=[65,-2,-3,-4,-5,77]
n=range(len(p))
buy=[]
prof=0
for i in n:
#i is the LEFT MOST POINT of the block
  for j in n[i:]:
#j is the RIGHT MOST POINT
    m=n[i:j+1]
    block=0
    for k in m:
      block=block+p[k]
    print m
    print 'profit',block
    if block>prof:
      prof=block
      buy=m
print prof
print buy       
