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
#include "message.h"
#include "teatr.h"
#include <iostream>
#include <cstdio>

#define LLI long long int
using namespace std;

int n, m, nod, k;
LLI wyn, tab[10];
//***************************************************************************************************
int main()
{
    n = GetN(); m = NumberOfNodes(); nod = MyNodeId();
    int pac = n / m;
    if (nod == m - 1) k = n;
    else k = nod * pac + pac;
    for(int i = nod * pac; i < k; i++) {
        int u = GetElement(i);
        tab[u]++;
        for(int j = 5; j > u; j--) wyn += tab[j];
    }

    if(nod != 0) {
        PutLL(0, wyn);
        for(int i = 1; i <= 5; i++) PutLL(0, tab[i]);
        Send(0);
    }
    else {
        for(int i = 1; i < m; i++) {
            wyn += Receive(i);
            for(int j = 1; j <= 5; j++) {
                LLI u = Receive(i), wn = 0;
                for(int o = 5; o > j; o--) wn += tab[o];
                wyn += wn * u;
                tab[j] += u;
            }
        }
        printf("%lld", wyn);
    }
}