package mypackage;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.util.Scanner; 
public class a {

    public static int max(int a[],int n) //判断大小
    {
        int x=a[0];
        for(int i=0;i<=n;i++)    
        {
            if(a[i]>x) {x=a[i];}                
        }
        return x;
    }
    
    public static int add(int a[],int n) //加和
    {
        int x=0,i,j,k,g=0;
        int[] b=new int [1000];
        int[] c=new int [1000];
        for(i=0;i<=n-1;i++,g++)
        {
            int f=0;
            for(j=n-1;j>=i;j--,f++)
            {
                int y=0;                
                for(k=j;k>=i;k--)
                {
                    y=a[k]+y;                    
                }
                b[f]=y;
            }
            c[g]=max(b,f);
        }
        x=max(c,g);
        return x;
    }
    public static void main(String[] args) throws IOException {
            File writename = new File("C:\\\\\\\\\\\\\\\\Users\\\\\\\\\\\\\\\\xxoo\\\\\\\\\\\\\\\\Desktop\\\\\\\\\\\\\\\\新建文本文档.txt");  
            writename.createNewFile(); // 创建新文件      
            BufferedWriter out = new BufferedWriter(new FileWriter(writename));
            int n=(int)(1+Math.random()*(1000-1+1)),m,x,y;
            for(m=1;m<=n;m++)
            {        
                x=(int)(1+Math.random()*(10000000-1+1));
                y=(int)(1+Math.random()*(2-1+1));
                if(y==1) {x=x*(-1);}
                out.write(x+" ");
                out.flush(); 
            }
            out.close();//随机输入
            
            Reader r = new BufferedReader(new FileReader("C:\\\\\\\\Users\\\\\\\\xxoo\\\\\\\\Desktop\\\\\\\\新建文本文档.txt"));
            StreamTokenizer stok = new StreamTokenizer(r);
            stok.parseNumbers();
            int[] sum=new int [1000];
            int i=-1;
            stok.nextToken();
            while (stok.ttype != StreamTokenizer.TT_EOF) {
              if (stok.ttype == StreamTokenizer.TT_NUMBER)
              {  
                  i++;
                sum[i] = (int) stok.nval;
              }
              else
                System.out.println("Nonnumber: " + stok.sval);
              stok.nextToken();
            }//读取

        System.out.println(add(sum,i));
    }

}