#include <fstream> using namespace std; ifstream fin("date.in"); ofstream fout("date.out"); int main() { int n,i,a[10000],s[10000]={0},maxx,im,jm; fin>>n; for(i=1;i<=n;i++) fin>>a[i]; maxx = a[1]; for(i=1;i<=n;i++) { s[i]=a[i]; if(s[i]<s[i-1]+a[i]) s[i]=s[i-1]+a[i]; if(s[i]>maxx) { maxx=s[i]; jm=i; } } fout<<maxx<<endl; im=jm; while(im>0 && s[im]>=0) im--; im++; for(i=im;i<=jm;i++) fout<<a[i]<<" "; return 0; }