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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <deque>
using namespace std;

typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define FT first
#define SD second
#define Y first
#define X second

vector<string>token(string a) {
	vector<string>w; a.push_back(' ');
	while (!a.empty()) { w.push_back(a.substr(0, a.find(" "))); a = a.substr(a.find(" ") + 1, a.size() - 1); }return w;
}

map<string, int> mapik;
vector<string> amapik;
int dodaj(string a) { if (mapik.count(a) == 0) { mapik[a] = mapik.size() - 1; amapik.PB(a); }return mapik[a]; }

const int INF = 1000000000;
const LL INFINF = 1000000000000000000LL;

PI moves4[4] = { MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1) };
PI move(PI st, PI m)
{
	return MP(st.first + m.first, st.second + m.second);
}

int rows, cols;
bool on_board(PI p)
{
	return p.first >= 0 && p.second >= 0 && p.first < rows && p.second < cols;
}

char tmp_str[1000000];
string scanf_string() {
	scanf("%s", tmp_str);
	return tmp_str;
}

inline bool get_bit(int w, int i) {
	return (w >> i) & 1;
}

#include "teatr.h"
#include "message.h"

// ==========================================================

const int V = 1000003;
const int N = 100000003;
const int M = 100;

LL po_ile[1000003];
int n;


const int baza = 16384; //1048576;
int tab[2 * baza + 1];

class Licznik
{
public:
	Licznik()
	{
		memset(tab, 0, 2 * baza * sizeof(int));
	}

	void wstaw(int x, int ile)
	{
		x += baza;
		while (x > 0)
		{
			tab[x] += ile;
			x >>= 1;
		}
	}

	int ile_mniejszych(int x)
	{
		int r = 0;
		x += baza;
		while (x > 1)
		{
			if (x & 1)
				r += tab[x - 1];
			x >>= 1;
		}
		return r;
	}
};


LL za_liczbe(int a, int b)
{
	LL res = 0;
	n = GetN();

	auto licznik = Licznik();
	int kazdy = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		auto val = GetElement(i) - a;
		if (val <= 0)
		{
			kazdy++;
		}
		else if (val <= b - a)
		{
			res += licznik.ile_mniejszych(val) + kazdy;
			licznik.wstaw(val, 1);
		}
	}
	return res;
}

int main() {
	int id = MyNodeId();
	LL res = 0;
	//for (id = 0; id < 100; id++)
	{
		int a = 10000 * id;
		int b = 10000 * (id + 1);
		//if (MyNodeId() == 0)
		{
			n = GetN();

			res += za_liczbe(a, b);

		}
	}

	if (id != 0)
	{
		PutLL(0, res);
		Send(0);
	}
	else {
		int ile = 0;
		int akt;
		while (akt = Receive(-1))
		{
			res += GetLL(akt);
			ile++;
			if (ile == 99)
				break;
		}

		printf("%lld\n", res);
	}


	return 0;
}