#include<stdio.h>
#include<string.h>
int k,num[10024],add[10024],pri[10024],pos;
void cal( )
{
int m = 0;
for( int i = 1; i <= k; ++i )
{
if( (add[i-1] + num[i]) > 0 && add[i-1] > 0 )
{
add[i] = add[i-1] + num[i];
pri[i] = pri[i-1];
}
else
{
if( num[i] > 0 )
add[i] = num[i];
else
add[i] = 0;
}
if( add[i] > add[pos] )
pos = i;
}
if( add[pos] == 0 )
pos = k,pri[k] = 1;
if( add[pos] == 0 )
for( int i = 1; i <= k; ++i )
if( num[i] == 0 )
pos = i;
}
int main( )
{
while( scanf( "%d",&k ),k )
{
memset( add,0,sizeof( add ) );
memset( num,0,sizeof( num ) );
pos = pri[0] = 0;
for( int i = 1; i <= k ; ++i )
scanf( "%d",&num[i] ),pri[i] = i;
cal();
printf( "%d %d %d\n",add[pos],num[pri[pos]],num[pos] );
}
return 0;
}