#p=[23,45,-31,-3,89,7,4,-2,4,56,-227,43]
p=[2,4,-5,8]
#p=[-3,-56,-38]
#p=[-2,-4,45,3,-7]
#p=[65,-2,-3,-4,-5,77]
n=range(len(p))
prof=0
buy=[]
for i in n:
#i runs from 0 to len(p)-1
  for j in n:
    block=0
    for k in n[i:j+1]:
    #the slice will run from n[i] to n[j]
      block=block+p[k]
    print n[i:j+1]
    print 'profit',block
    if block>prof:
      prof=block
      buy=n[i:j+1]
print prof
print buy       
