#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef long long LL;
const int maxn=1e4+5;
const LL INF=0x3f3f3f3f3f3f3f3f;
LL max(LL a,LL b)
{
return a>b?a:b;
}
int main()
{
PII p[maxn];
LL n,dp[maxn],a[maxn];
scanf("%lld",&n);
LL solve=-INF;
int l,r;
bool flag=true;
for(int i=0;i<n;i++)
{
LL x;
scanf("%lld",&x);
if(x>=0) flag=false;
a[i]=x;
if(i==0) {
dp[i]=x;
p[i].first=0;
p[i].second=0;
if(solve<dp[i]) {
l=p[i].first;
r=p[i].second;
solve=dp[i];
}
}
else {
if(x>dp[i-1]+x) {
p[i].first=i;
p[i].second=i;
p[i-1].second=i-1;
}
else {
p[i].first=p[i-1].first;
p[i].second=p[i-1].second+1;
}
dp[i]=max(x,dp[i-1]+x);
if(solve<dp[i]) {
l=p[i].first;
r=p[i].second;
solve=dp[i];
}
}
}
if(flag) {
cout<<"0"<<" "<<a[0]<<" "<<a[n-1]<<endl;
}
else cout<<solve<<" "<<a[l]<<" "<<a[r]<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
map<int,string>str;
int main()
{
str.clear();
int n;
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++)
{
string k,k1,k2,k3;
k.clear();
k1.clear();
k2.clear();
k3.clear();
getline(cin,k,'\n');
int len=k.length(),j=0;
for(;j<len;j++)
{
if(k[j]==' ') {
k1=k.substr(0,j);
break;
}
}
k2=k.substr(j+1,8);
k3=k.substr(j+10,8);
//cout<<k1<<endl<<k2<<endl<<k3<<endl;
int x1=0,x2=0;
x1+=((k2[0]-'0')*10+(k2[1]-'0'))*3600+((k2[3]-'0')*10+(k2[4]-'0'))*60+((k2[6]-'0')*10+(k2[7]-'0'));
x2+=((k3[0]-'0')*10+(k3[1]-'0'))*3600+((k3[3]-'0')*10+(k3[4]-'0'))*60+((k3[6]-'0')*10+(k3[7]-'0'));
str[x1]=k1;
str[x2]=k1;
}
map<int,string>::iterator it;
it=str.begin();
cout<<(*it).second<<" ";
string k;
k.clear();
k=(*it).second;
for(;it!=str.end();it++)
{
k=(*it).second;
}
cout<<k<<endl;
return 0;
}