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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
#include <cstdio>
#include <iostream>
#include <map>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <set>
#include <cassert>
#include <algorithm>
using namespace std;

typedef long long ll;

class RemovingNonExistingWeightException
{};

/*class SpratsDatabase
{
	typedef map<ll, ll> Sprats;
public:
	int GetMinimalNumberOfEatenSprats(ll currentCatfishWeight, ll targetCatfishWeight)
	{
		if (IsDone(currentCatfishWeight, targetCatfishWeight))
			return 0;
		if (IsSimplyImmpossible(currentCatfishWeight, targetCatfishWeight))
			return -1;

		int result = 0;
		while (currentCatfishWeight < targetCatfishWeight)
		{
			Sprats::iterator it = FindTheBiggestWeightLowerThanGiveWeight(currentCatfishWeight);
			if (it == spratWeightToQuantity.end())
				return -1;
			++result;
			currentCatfishWeight += it->first;
			RemoveExistingWeight(it);
		}

		return result;
	}

	void AddWeight(const ll& weight)
	{
		++spratWeightToQuantity[weight];
		sumOfAllWeights += weight;
	}

	void RemoveWeight(const ll& weight)
	{
		Sprats::iterator it = spratWeightToQuantity.find(weight);
		if (it == spratWeightToQuantity.end())
			throw RemovingNonExistingWeightException();

		RemoveExistingWeight(it);
	}
private:
	
	bool IsSimplyImmpossible(const ll& currentCatfishWeight, const ll& targetCatfishWeight)
	{
		return sumOfAllWeights < targetCatfishWeight - currentCatfishWeight
			|| spratWeightToQuantity.begin()->first >= currentCatfishWeight;
	}

	bool IsDone(const ll& currentCatfishWeight, const ll& targetCatfishWeight)
	{
		return targetCatfishWeight <= currentCatfishWeight;
	}

	void RemoveExistingWeight(Sprats::iterator it)
	{
		sumOfAllWeights -= it->first;
		--it->second;

		if (it->second == 0)
			spratWeightToQuantity.erase(it);
	}

	Sprats::iterator FindTheBiggestWeightLowerThanGiveWeight(ll weight)
	{
		if (spratWeightToQuantity.empty() || spratWeightToQuantity.begin()->first >= weight)
			return spratWeightToQuantity.end();

		Sprats::iterator result = spratWeightToQuantity.lower_bound(weight);
		if (result == spratWeightToQuantity.end())
		{
			if (spratWeightToQuantity.empty())
				return result;
			else
				--result;
		}
			
		if (result->first < weight)
			return result;

		return --result;
	}
	
	Sprats spratWeightToQuantity;
	ll sumOfAllWeights = 0;
};

class SmartSpratsDatabase
{
	typedef map<ll, ll> Sprats;
public:
	int GetMinimalNumberOfEatenSprats(ll currentCatfishWeight, ll targetCatfishWeight)
	{
		if (IsDone(currentCatfishWeight, targetCatfishWeight))
			return 0;
		if (IsSimplyImmpossible(currentCatfishWeight, targetCatfishWeight))
			return -1;

		int result = 0;
		while (currentCatfishWeight < targetCatfishWeight)
		{
			Sprats::iterator it = FindTheBiggestWeightLowerThanGiveWeight(currentCatfishWeight);
			if (it == spratWeightToQuantity.end())
			{
				RestoreRemovedWeights();
				return -1;
			}
			++result;
			currentCatfishWeight += it->first;
			RemoveExistingWeight(it, true);
		}

		RestoreRemovedWeights();
		return result;
	}

	void AddWeight(const ll& weight)
	{
		++spratWeightToQuantity[weight];
		sumOfAllWeights += weight;
	}

	void RemoveWeight(const ll& weight)
	{
		Sprats::iterator it = spratWeightToQuantity.find(weight);
		if (it == spratWeightToQuantity.end())
			throw RemovingNonExistingWeightException();

		RemoveExistingWeight(it, false);
	}
private:

	bool IsSimplyImmpossible(const ll& currentCatfishWeight, const ll& targetCatfishWeight)
	{
		return sumOfAllWeights < targetCatfishWeight - currentCatfishWeight
			|| spratWeightToQuantity.begin()->first >= currentCatfishWeight;
	}

	bool IsDone(const ll& currentCatfishWeight, const ll& targetCatfishWeight)
	{
		return targetCatfishWeight <= currentCatfishWeight;
	}

	void RemoveExistingWeight(Sprats::iterator it, bool shouldTrace)
	{
		if (shouldTrace)
			removedWeights.push_back(it->first);

		sumOfAllWeights -= it->first;
		--it->second;

		if (it->second == 0)
			spratWeightToQuantity.erase(it);
	}

	Sprats::iterator FindTheBiggestWeightLowerThanGiveWeight(ll weight)
	{
		if (spratWeightToQuantity.empty() || spratWeightToQuantity.begin()->first >= weight)
			return spratWeightToQuantity.end();

		Sprats::iterator result = spratWeightToQuantity.lower_bound(weight);
		if (result == spratWeightToQuantity.end())
		{
			if (spratWeightToQuantity.empty())
				return result;
			else
				--result;
		}

		if (result->first < weight)
			return result;

		return --result;
	}

	void RestoreRemovedWeights()
	{
		for (int i = 0; i < removedWeights.size(); ++i)
			AddWeight(removedWeights[i]);

		removedWeights.clear();
	}

	Sprats spratWeightToQuantity;
	ll sumOfAllWeights = 0;
	vector<ll> removedWeights;
};*/

struct Query
{
	Query() {}
	Query(short t, ll fP, ll sP)
		: type(t), firstParam(fP), secondParam(sP)
	{}
	short type;
	ll firstParam, secondParam;
};

struct Input
{
	int numberOfSprats;
	vector<ll> spratsWeight;
	int numberOfqueries;
	vector<Query> queries;
};

class Hasher
{
public:
	Hasher(const Input& input)
	{
		vector<ll> sprats(input.spratsWeight.begin(), input.spratsWeight.end());
		for (int i = 0; i < input.queries.size(); ++i)
		{
			const Query& currentQuery = input.queries[i];
			if (currentQuery.type == 2)
				sprats.push_back(currentQuery.firstParam);
		}

		Initialize(sprats);
	}
	Hasher(vector<ll> numberToComputeHash)
	{
		Initialize(numberToComputeHash);
	}

	int GetHash(ll number)
	{
		return numberToHash[number];
	}

	ll GetNumber(int hash)
	{
		return hashToNumber[hash];
	}

	const set<ll>& GetAllNumberWithHashes()
	{
		return allNumberWithHashes;
	}

	const vector<ll>& GetAllNumberWithHashesVector()
	{
		return allNumberWithHashesVector;
	}
private:
	void Initialize(vector<ll> numberToComputeHash)
	{
		allNumberWithHashes = set<ll>(numberToComputeHash.begin(), numberToComputeHash.end());
		int hash = 1;
		for (set<ll>::reverse_iterator it = allNumberWithHashes.rbegin(); it != allNumberWithHashes.rend(); ++it)
		{
			numberToHash[*it] = hash;
			hashToNumber[hash++] = *it;
		}

		allNumberWithHashesVector = vector<ll>(allNumberWithHashes.begin(), allNumberWithHashes.end());
	}

	map<ll, int> numberToHash;
	map<int, ll> hashToNumber;
	set<ll> allNumberWithHashes;
	vector<ll> allNumberWithHashesVector;
};

class SumDatabase
{
public:
	SumDatabase(Hasher* hasher)
	{
		this->hasher = hasher;
		arraysSize = hasher->GetAllNumberWithHashes().size();
		sumOfNumberOfGivenHash = new ll[arraysSize + 1];
		numberOfNumbersOfGivenHash = new ll[arraysSize + 1];
		treeOfSum = new ll[arraysSize + 1];
		treeOfNumbers = new ll[arraysSize + 1];

		for (int i = 0; i <= arraysSize; ++i)
			sumOfNumberOfGivenHash[i] = numberOfNumbersOfGivenHash[i] = treeOfNumbers[i] = treeOfSum[i] = 0;
	}

	void AddNumber(ll number)
	{
		int hash = hasher->GetHash(number);
		sumOfNumberOfGivenHash[hash] += number;
		addSumToTree(treeOfSum, hash, number);
		++numberOfNumbersOfGivenHash[hash];
		addSumToTree(treeOfNumbers, hash, 1);
	}

	void RemoveNumber(ll number)
	{
		int hash = hasher->GetHash(number);
		sumOfNumberOfGivenHash[hash] -= number;
		addSumToTree(treeOfSum, hash, -number);
		--numberOfNumbersOfGivenHash[hash];
		addSumToTree(treeOfNumbers, hash, -1);
	}

	ll GetSumOfAllNumberOfHashNotGreaterThan(int hash)
	{
		return getSum(treeOfSum, hash);
	}

	ll GetNumberOfNumberOfHashNotGreaterThan(int hash)
	{
		return getSum(treeOfNumbers, hash);
	}

	void DumpDatabase()
	{
		const set<ll>& allNumberWithHash = hasher->GetAllNumberWithHashes();
		for (set<ll>::const_iterator it = allNumberWithHash.begin(); it != allNumberWithHash.end(); ++it)
		{
			int hash = hasher->GetHash(*it);
			printf("number: %lld, hash: %d\n", *it, hash);
			printf("GetSumOfAllNumberOfHashNotGreaterThan: %lld\n", GetSumOfAllNumberOfHashNotGreaterThan(hash));
			printf("GetNumberOfNumberOfHashNotGreaterThan: %lld\n", GetNumberOfNumberOfHashNotGreaterThan(hash));
		}
	}
	~SumDatabase()
	{
		delete sumOfNumberOfGivenHash;
		delete numberOfNumbersOfGivenHash;
		delete treeOfSum;
		delete treeOfNumbers;
	}
private:

	void addSumToTree(ll* targetTree, int index, ll delta)
	{
		const int numberOfElements = arraysSize;
		while (index <= numberOfElements)
		{
			targetTree[index] += delta;
			index += index & (-index);
		}
	}

	ll getSum(ll* targetTree, int index)
	{
		ll sum = 0;
		while (index > 0)
		{
			sum += targetTree[index];
			index -= index & (-index);
		}

		return sum;
	}
	Hasher* hasher;
	int arraysSize;
	ll* sumOfNumberOfGivenHash;
	ll* numberOfNumbersOfGivenHash;
	ll* treeOfSum;
	ll* treeOfNumbers;

};

class SmartSpratsDatabase2
{
	typedef map<ll, ll> Sprats;
public:
	SmartSpratsDatabase2(Hasher* hasher):
		sumDatabase(new SumDatabase(hasher))
	{
		this->hasher = hasher;
	}
	int GetMinimalNumberOfEatenSprats(ll currentCatfishWeight, ll targetCatfishWeight)
	{
		//sumDatabase->DumpDatabase();

		if (IsDone(currentCatfishWeight, targetCatfishWeight))
			return 0;
		if (IsSimplyImmpossible(currentCatfishWeight, targetCatfishWeight))
			return -1;

		int result = 0;
		while (currentCatfishWeight < targetCatfishWeight)
		{
			Sprats::iterator it = FindTheBiggestWeightLowerThanGiveWeight(currentCatfishWeight);
			if (it == spratWeightToQuantity.end())
			{
				RestoreRemovedWeights();
				return -1;
			}
			// je�li it wskazuje na szprotk� o najwi�kszej masie i masa szczupaka jest od niej wi�ksza,
			// to znaczy, �e mo�na zjada� wszystkie szprotki poczynaj�c od najwi�kszych
			else if (it->first == spratWeightToQuantity.rbegin()->first && currentCatfishWeight > it->first)
			{
				//sumDatabase->DumpDatabase();
				//result = ComputeResulutAssumingThatCatfishCanEatAnySprat(currentCatfishWeight, targetCatfishWeight, result);
				result = ComputeResulutAssumingThatCatfishCanEatAnySprat2(currentCatfishWeight, targetCatfishWeight, result);
				RestoreRemovedWeights();
				return result;
			}
			else
			{
				++result;
				currentCatfishWeight += it->first;
				RemoveExistingWeight(it, true);
			}
		}

		RestoreRemovedWeights();
		return result;
	}

	void AddWeight(const ll& weight)
	{
		++spratWeightToQuantity[weight];
		sumOfAllWeights += weight;
		sumDatabase->AddNumber(weight);
	}

	void RemoveWeight(const ll& weight)
	{
		Sprats::iterator it = spratWeightToQuantity.find(weight);
		if (it == spratWeightToQuantity.end())
			throw RemovingNonExistingWeightException();

		RemoveExistingWeight(it, false);
	}

	~SmartSpratsDatabase2()
	{
		delete sumDatabase;
	}

private:

	bool IsSimplyImmpossible(const ll& currentCatfishWeight, const ll& targetCatfishWeight)
	{
		return sumOfAllWeights < targetCatfishWeight - currentCatfishWeight
			|| spratWeightToQuantity.begin()->first >= currentCatfishWeight;
	}

	bool IsDone(const ll& currentCatfishWeight, const ll& targetCatfishWeight)
	{
		return targetCatfishWeight <= currentCatfishWeight;
	}

	void RemoveExistingWeight(Sprats::iterator it, bool shouldTrace)
	{
		if (shouldTrace)
			removedWeights.push_back(it->first);

		sumOfAllWeights -= it->first;
		--it->second;
		sumDatabase->RemoveNumber(it->first);

		if (it->second == 0)
			spratWeightToQuantity.erase(it);
	}

	Sprats::iterator FindTheBiggestWeightLowerThanGiveWeight(ll weight)
	{
		if (spratWeightToQuantity.empty() || spratWeightToQuantity.begin()->first >= weight)
			return spratWeightToQuantity.end();

		Sprats::iterator result = spratWeightToQuantity.lower_bound(weight);
		if (result == spratWeightToQuantity.end())
		{
			if (spratWeightToQuantity.empty())
				return result;
			else
				--result;
		}

		if (result->first < weight)
			return result;

		return --result;
	}

	void RestoreRemovedWeights()
	{
		for (int i = 0; i < removedWeights.size(); ++i)
		{
			AddWeight(removedWeights[i]);
			//sumDatabase->AddNumber(removedWeights[i]);
			//sumDatabase->DumpDatabase();
		}

		removedWeights.clear();
	}

	int ComputeResulutAssumingThatCatfishCanEatAnySprat(ll currentCatfishWeight, ll targetCatfishWeight, int alreadyEatenSprats)
	{
		if (targetCatfishWeight <= currentCatfishWeight)
			return alreadyEatenSprats;
		if (currentCatfishWeight <= spratWeightToQuantity.rbegin()->first)
			throw string("currentCatfishWeight <= spratWeightToQuantity.rbegin()->first");

		int result = alreadyEatenSprats;
		for (Sprats::reverse_iterator it = spratWeightToQuantity.rbegin(); it != spratWeightToQuantity.rend(); ++it)
		{
			const ll potentialWeight = currentCatfishWeight + it->second * it->first;
			if (potentialWeight >= targetCatfishWeight)
			{
				const int missingWeight = targetCatfishWeight - currentCatfishWeight;
				return result + missingWeight / it->first
					+ (missingWeight % it->first == 0 ? 0 : 1);
			}
			else
			{
				currentCatfishWeight = potentialWeight;
				result += it->second;
			}
		}

		return -1;
	}

	int ComputeResulutAssumingThatCatfishCanEatAnySprat2(ll currentCatfishWeight, ll targetCatfishWeight, int alreadyEatenSprats)
	{
		if (currentCatfishWeight <= spratWeightToQuantity.rbegin()->first)
			throw string("currentCatfishWeight <= spratWeightToQuantity.rbegin()->first");

		int result = alreadyEatenSprats;
		const vector<ll>& allNumberWithHashes = hasher->GetAllNumberWithHashesVector();
		int pocz = 0, kon = allNumberWithHashes.size() - 1;
		ll elem, midSum;
		while (pocz <= kon)
		{
			int mid = pocz + (kon - pocz) / 2;
			elem = hasher->GetHash(allNumberWithHashes[mid]);
			ll sumToFind = targetCatfishWeight - currentCatfishWeight;
			ll midSum = sumDatabase->GetSumOfAllNumberOfHashNotGreaterThan(elem);

			if (midSum < sumToFind)
				kon = mid - 1;
			else
			{
				if (midSum > sumToFind)
					pocz = mid + 1;
				else
					return result + sumDatabase->GetNumberOfNumberOfHashNotGreaterThan(elem);
			}

		}
		/*kon = min(kon + 10, (int)allNumberWithHashes.size() - 1);
		elem = hasher->GetHash(allNumberWithHashes[kon]);
		midSum = sumDatabase->GetSumOfAllNumberOfHashNotGreaterThan(elem);
		return ComputeResulutAssumingThatCatfishCanEatAnySprat(currentCatfishWeight + midSum, targetCatfishWeight, alreadyEatenSprats
			+ sumDatabase->GetNumberOfNumberOfHashNotGreaterThan(elem));*/
		elem = hasher->GetHash(allNumberWithHashes[0]);
		if (sumDatabase->GetSumOfAllNumberOfHashNotGreaterThan(elem) < targetCatfishWeight - currentCatfishWeight)
			return -1;

		kon = min(kon + 10, (int)allNumberWithHashes.size() - 1);
		elem = hasher->GetHash(allNumberWithHashes[kon]);
		midSum = sumDatabase->GetSumOfAllNumberOfHashNotGreaterThan(elem);
		while (kon >= 0)
		{
			elem = hasher->GetHash(allNumberWithHashes[kon]);
			midSum = sumDatabase->GetSumOfAllNumberOfHashNotGreaterThan(elem);
			if (currentCatfishWeight + midSum >= targetCatfishWeight)
			{
				if (currentCatfishWeight + midSum == targetCatfishWeight)
					return sumDatabase->GetNumberOfNumberOfHashNotGreaterThan(elem);
				else
				{
					const ll currentWeight = allNumberWithHashes[kon];
					const ll maxFishes = spratWeightToQuantity[allNumberWithHashes[kon]];
					const ll alreadyEaten = sumDatabase->GetNumberOfNumberOfHashNotGreaterThan(elem);
					for (int i = 0; i <= maxFishes; ++i)
					{
						if (midSum - maxFishes * currentWeight + currentCatfishWeight + i * currentWeight >= targetCatfishWeight)
							return alreadyEatenSprats + alreadyEaten - maxFishes + i;
					}
				}
			}
			--kon;
		}
		return -1;
		/*for (Sprats::reverse_iterator it = spratWeightToQuantity.rbegin(); it != spratWeightToQuantity.rend(); ++it)
		{
			const ll potentialWeight = currentCatfishWeight + it->second * it->first;
			if (potentialWeight >= targetCatfishWeight)
			{
				const int missingWeight = targetCatfishWeight - currentCatfishWeight;
				return result + missingWeight / it->first
					+ (missingWeight % it->first == 0 ? 0 : 1);
			}
			else
			{
				currentCatfishWeight = potentialWeight;
				result += it->second;
			}
		}*/
	}

	Sprats spratWeightToQuantity;
	ll sumOfAllWeights = 0;
	vector<ll> removedWeights;
	Hasher* hasher;
	SumDatabase* sumDatabase;
};

Input ReadInput()
{
	Input result;
	scanf("%d", &result.numberOfSprats);

	ll currentWeight, targetWeight;
	for (int i = 0; i < result.numberOfSprats; ++i)
	{
		scanf("%lld", &currentWeight);
		result.spratsWeight.push_back(currentWeight);
	}

	scanf("%d", &result.numberOfqueries);
	for (int queryNumber = 0; queryNumber < result.numberOfqueries; ++queryNumber)
	{
		Query query;
		scanf("%d", &query.type);
		switch (query.type)
		{
		case 1:
			scanf("%lld %lld", &currentWeight, &targetWeight);
			query.firstParam = currentWeight;
			query.secondParam = targetWeight;
			break;
		case 2:
			scanf("%lld", &currentWeight);
			query.firstParam = currentWeight;
			break;
		case 3:
			scanf("%lld", &currentWeight);
			query.firstParam = currentWeight;
			break;
		}

		result.queries.push_back(query);
	}

	return result;
}

void WriteOutput(const Input& input, SmartSpratsDatabase2& spratDatabase)
{
	for (int i = 0; i < input.spratsWeight.size(); ++i)
		spratDatabase.AddWeight(input.spratsWeight[i]);

	for (int query = 0; query < input.numberOfqueries; ++query)
	{
		const Query& currentQuery = input.queries[query];
		switch (currentQuery.type)
		{
		case 1:
			printf("%d\n", spratDatabase.GetMinimalNumberOfEatenSprats(currentQuery.firstParam, currentQuery.secondParam));
			break;
		case 2:
			spratDatabase.AddWeight(currentQuery.firstParam);
			break;
		case 3:
			spratDatabase.RemoveWeight(currentQuery.firstParam);
			break;
		}
	}
}

void Debug()
{
	vector<ll> numberToHash;
	for (int i = 1; i <= 10; ++i) numberToHash.push_back(i);
	Hasher hasher(numberToHash);
	SumDatabase sumDatabase(&hasher);
	for (int i = 0; i < numberToHash.size(); ++i)
	{
		assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(hasher.GetHash(numberToHash[i])) == 0);
		assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(hasher.GetHash(numberToHash[i])) == 0);
	}

	for (int iterationNumber = 1; iterationNumber < 10; ++iterationNumber)
	{
		sumDatabase.AddNumber(1);
		assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(hasher.GetHash(1)) == iterationNumber);
		assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(hasher.GetHash(1)) == iterationNumber);
		for (int i = 1; i < numberToHash.size(); ++i)
		{
			assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(hasher.GetHash(numberToHash[i])) == 0);
			assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(hasher.GetHash(numberToHash[i])) == 0);
		}
	}

	for (int iterationNumber = 1; iterationNumber < 10; ++iterationNumber)
	{
		sumDatabase.AddNumber(2);
		assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(hasher.GetHash(1)) == iterationNumber + 9);
		assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(hasher.GetHash(1)) == 9 + 2 * iterationNumber);
		for (int i = 2; i < numberToHash.size(); ++i)
		{
			assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(hasher.GetHash(numberToHash[i])) == 0);
			assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(hasher.GetHash(numberToHash[i])) == 0);
		}
	}

	sumDatabase.AddNumber(10);
	sumDatabase.AddNumber(10);

	for (int hash = 1; hash <= 8; ++hash)
	{
		assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(hash) == 2);
		assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(hash) == 20);
	}

	assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(9) == 2 + 9);
	assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(9) == 2 * 10 + 9 * 2);

	assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(10) == 2 + 9 + 9);
	assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(10) == 2 * 10 + 9 * 2 + 9);

	sumDatabase.RemoveNumber(10);

	for (int hash = 1; hash <= 8; ++hash)
	{
		assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(hash) == 1);
		assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(hash) == 10);
	}

	assert(sumDatabase.GetNumberOfNumberOfHashNotGreaterThan(9) == 1 + 9);
	assert(sumDatabase.GetSumOfAllNumberOfHashNotGreaterThan(9) == 1 * 10 + 9 * 2);
}

int main()
{
	//Debug();
	Input input = ReadInput();
	Hasher hasher(input);
	SmartSpratsDatabase2 spratDatabase(&hasher);
	WriteOutput(input, spratDatabase);

	return 0;
}