1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<iostream>
#include<algorithm>
#include<vector>
#define pb push_back
#define st first
#define nd second
#define mp make_pair
#define PII pair<int,int>
#define LL long long
#include "kanapka.h"
#include "message.h"
using namespace std;
//**atrapa
/*
int NN,smak[100],mojnum,nodes;
int NumberOfNodes(){
	return nodes;
}
int wpisz_test(){
	cin>>NN>>mojnum>>nodes;
	for(int i=0;i<NN;i++)cin>>smak[i];	
}
int GetN(){
	return NN;
}
int GetTaste(int x){
	return smak[x];	
}
int MyNodeId(){
	return mojnum;
}
void PutLL(int t,LL x){
	cout<<"send "<<t<<" "<<x<<"\n";	
}
LL GetLL(int t){
	cout<<"prosze o LL od "<<t<<"\n";
	LL x;
	cin>>x;
	return x;	
}
void Receive(int t){
	
}
void Send(int t){
		
}
*/
//**
vector<LL>v,wyn,pocz,kon;
LL MAX(LL a,LL b){
	if(a>b)return a;
	return b;	
}
void wczytaj_czesc(){
	int n=GetN(),p=NumberOfNodes(),nr=MyNodeId();
	if(p>n){
		p=n;
		if(nr>=p)return;	
	}
	LL sum=0,akt=0,res=0,mpref=0,msuf=0;
	PII prz=mp((n/p)*nr,(n/p)*(nr+1)-1);
	if(nr==p-1)prz.nd=n-1;
	for(int i=prz.st;i<=prz.nd;i++){
		int x=GetTaste(i);
		sum+=x;
		mpref=MAX(sum,mpref);
		akt-=x;
		if(akt<0)akt=0;
		res=MAX(res,akt);	
	}
	akt=0;
	for(int i=prz.nd;i>=prz.st;i--){
		int x=GetTaste(i);
		akt+=x;
		msuf=MAX(akt,msuf);
	}
	res=sum+res;
	PutLL(0,res);
	PutLL(0,sum);
	PutLL(0,mpref);
	PutLL(0,msuf);
	Send(0);
}
main(){
	//wpisz_test();
	wczytaj_czesc();
	if(MyNodeId()!=0)return 0;
	v.clear();
	LL res=0;
	int n=NumberOfNodes();
	if(n>GetN())n=GetN();
	for(int i=0;i<n;i++){
		Receive(i);
		wyn.pb(GetLL(i));
		v.pb(GetLL(i));
		pocz.pb(GetLL(i));
		kon.pb(GetLL(i));
		res+=v[i];
	}
	for(int i=0;i<n;i++){
		LL akt=0;
		akt+=wyn[i];
		for(int j=0;j<i;j++)akt+=v[j];
		for(int j=i+1;j<n;j++)akt+=v[j];
		res=MAX(res,akt);	
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			LL akt=pocz[i]+kon[j];
			for(int k=0;k<i;k++)akt+=v[k];
			for(int k=j+1;k<n;k++)akt+=v[k];
			res=MAX(res,akt);
		}
	}
	cout<<MAX(0,res)<<"\n";
}