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
#include <bits/stdc++.h>
#include "message.h"
#include "skup.h"

using namespace std;
/*
int MyNodeId(){
	return 0;
}

int NumberOfNodes(){
	return 1;
}

int NumberOfCompanies(){
	return 1;
}

int GetShareCost(int a){
	return a + 1;
}

void PutInt(int a, int b){
	a += b;
}

void Send(int a){
	a += a;
}

int Receive(int a){
	return a;
}

int GetInt(int a){
	return a + 1;
}
*/
const int N = 1007;

int n;
int dp[N][N];

int main(){
	n = NumberOfNodes();
	int m = NumberOfCompanies();
	for(int i = 0; i < m; ++i)
		dp[MyNodeId()][i] = GetShareCost(i);
	
	for(int i = 1; i < n; ++i){
		for(int j = 0; j < n; ++j)
			if(j != MyNodeId()){
				for(int ii = 0; ii < n; ++ii)
					for(int jj = 0; jj < 1000; ++jj)
						PutInt(j, dp[ii][jj]);
				Send(j);
			}
		
		for(int j = 0; j < n; ++j){
			if(j == MyNodeId())	continue;

			int id = Receive(j);
			for(int ii = 0; ii < n; ++ii)
				for(int jj = 0; jj < 1000; ++jj)
					dp[ii][jj] = max(dp[ii][jj], GetInt(id));
		}
	}
	
	bool was = true;
	for(int i = 0; i < n; ++i)
		was &= dp[i][0] > 0;
	
	int mini = was ? MyNodeId() + 1: n + 1;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j)
			if(j != MyNodeId()){
				PutInt(j, mini);
				Send(j);
			}
		
		for(int j = 0; j < n; ++j){
			if(j == MyNodeId())	continue;
			int id = Receive(j); int cur = GetInt(id);
			if(cur > 0)	mini = min(mini, cur);
		}
	}
	
	if(mini - 1 != MyNodeId())
		return 0;
	
	vector <int> cur;
	long long int res = 0LL;

	for(int i = 0; i < n; ++i)
		for(int j = 0; j < 1000; ++j)
			if(dp[i][j] > 0)
				cur.push_back(-dp[i][j]);
	sort(cur.begin(), cur.end());
	
	int cnt = 0;
	for(int v: cur)
		res -= 1LL * (++cnt) * v;
	printf("%lld\n", res);
	return 0;
}