The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;
const int ok=500;
int n,k,a[ok];
double sum,cnt;
int av;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	int n1=n;
	cnt=sum*1.0/n;
	av=round(cnt);
	while(av!=k)
	{
		sum+=k;
		n++;
		cnt=sum*1.0/n;
		av=round(cnt);
	}
	printf("%d",n-n1);
	return 0;
}

NoteConsider the first example testcase.Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.

Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.

Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.To graduate with «A» certificate, Noora has to have mark k.Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.

Input:
2 10
8 9

Output: 4

Input:
3 5
4 4 4

Output: 3

Input:
3 10
10 8 9

Output: 3

Input:
2 23
21 23

Output: 2

Input:
5 10
5 10 10 9 10

Output: 7

Input:
12 50
18 10 26 22 22 23 14 21 27 18 25 12

Output: 712

Input:
38 12
2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6

Output: 482

Input:
63 86
32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28

Output: 6469

Input:
100 38
30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31

Output: 1340

Input:
33 69
60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61

Output: 329

Input:
39 92
19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16

Output: 5753

Input:
68 29
29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29

Output: 0

Input:
75 30
22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25

Output: 851

Input:
78 43
2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4

Output: 5884

Input:
82 88
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1

Output: 14170

Input:
84 77
28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30

Output: 6650

Input:
94 80
21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20

Output: 11786

Input:
96 41
13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28

Output: 3182

Input:
1 26
26

Output: 0

Input:
99 39
25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26

Output: 1807

Input:
100 12
7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4

Output: 946

Input:
100 18
1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2

Output: 3164

Input:
100 27
16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16

Output: 1262

Input:
100 29
20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18

Output: 2024

Input:
100 30
16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15

Output: 1984

Input:
100 59
56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55

Output: 740

Input:
100 81
6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4

Output: 14888

Input:
100 100
30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40

Output: 13118

Input:
100 100
71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76

Output: 3030

Input:
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 19700

Input:
100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
100 100
1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 19696

Input:
100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99

Output: 0

Input:
100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100

Output: 0

Input:
100 100
95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100

Output: 2

Input:
100 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 0

Input:
100 2
2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1

Output: 16

Input:
3 5
5 5 5

Output: 0

Input:
7 7
1 1 1 1 1 1 1

Output: 77

Input:
1 1
1

Output: 0

Input:
4 10
10 10 10 10

Output: 0

Input:
1 10
10

Output: 0

Input:
10 1
1 1 1 1 1 1 1 1 1 1

Output: 0

Input:
3 10
10 10 10

Output: 0

Input:
2 4
3 4

Output: 0

Input:
1 2
2

Output: 0

Input:
3 4
4 4 4

Output: 0

Input:
3 2
2 2 1

Output: 0

Input:
5 5
5 5 5 5 5

Output: 0

Input:
3 3
3 3 3

Output: 0

Input:
2 9
8 9

Output: 0

Input:
3 10
9 10 10

Output: 0

Input:
1 3
3

Output: 0

Input:
2 2
1 2

Output: 0

Input:
2 10
10 10

Output: 0

Input:
23 14
7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14

Output: 0

Input:
2 10
9 10

Output: 0

Input:
2 2
2 2

Output: 0

Input:
10 5
5 5 5 5 5 5 5 5 5 4

Output: 0

Input:
3 5
4 5 5

Output: 0

Input:
5 4
4 4 4 4 4

Output: 0

Input:
2 10
10 9

Output: 0

Input:
4 5
3 5 5 5

Output: 0

Input:
10 5
5 5 5 5 5 5 5 5 5 5

Output: 0

Input:
3 10
10 10 9

Output: 0

Input:
5 1
1 1 1 1 1

Output: 0

Input:
2 1
1 1

Output: 0

Input:
4 10
9 10 10 10

Output: 0

Input:
5 2
2 2 2 2 2

Output: 0

Input:
2 5
4 5

Output: 0

Input:
5 10
10 10 10 10 10

Output: 0

Input:
2 6
6 6

Output: 0

Input:
2 9
9 9

Output: 0

Input:
3 10
10 9 10

Output: 0

Input:
4 40
39 40 40 40

Output: 0

Input:
3 4
3 4 4

Output: 0

Input:
9 9
9 9 9 9 9 9 9 9 9

Output: 0

Input:
1 4
4

Output: 0

Input:
4 7
1 1 1 1

Output: 44

Input:
1 5
5

Output: 0

Input:
3 1
1 1 1

Output: 0

Input:
1 100
100

Output: 0

Input:
2 7
3 5

Output: 10

Input:
3 6
6 6 6

Output: 0

Input:
4 2
1 2 2 2

Output: 0

Input:
4 5
4 5 5 5

Output: 0

Input:
5 5
1 1 1 1 1

Output: 35

Input:
66 2
1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1

Output: 0

Input:
2 2
2 1

Output: 0

Input:
5 5
5 5 5 4 5

Output: 0

Input:
3 7
1 1 1

Output: 33

Input:
2 5
5 5

Output: 0

Input:
1 7
1

Output: 11

Input:
6 7
1 1 1 1 1 1

Output: 66

Input:
99 97
15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64

Output: 10077

Input:
8 7
1 1 1 1 1 1 1 1

Output: 88

Input:
3 2
2 2 2

Output: 0

Input:
6 5
5 5 5 5 5 5

Output: 0

Input:
10 5
5 5 5 5 5 5 5 4 1 1

Output: 8

Input:
1 5
1

Output: 7

Input:
10 10
10 10 10 10 10 10 10 10 10 10

Output: 0

Input:
2 3
2 3

Output: 0

Input:
1 9
9

Output: 0

Input:
74 2
2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2

Output: 0

Input:
5 5
5 5 5 5 4

Output: 0


The first line contains nonempty sequence consisting of digits from 0 to 9 — Masha's phone number. The sequence length does not exceed 50.

    #include <bits/stdc++.h>
    using namespace std;
    #define  MX (int)1e6+1
    #define pb push_back
    #define ip pair<int,int>
    #define  ll long long
    #define  INF 70
    const ll mod = 1e9 + 7;
    #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);
    ll dp[55][10][10],n;
    string input;

    ll solver(int pos,int fav,int last){
        if(pos==n)return 1;

        ll &ret=dp[pos][fav][last];
        if(~ret)return ret;
        ret=0;
        if(pos==0){
            for(int i=0;i<=9;i++){
                ret+=solver(pos+1,i,i);
            }
            return ret;
        }

    int choice1=(input[pos]-'0'+last)/2;
    int choice2=(input[pos]-'0'+last+1)/2;
    ret+=solver(pos+1,fav,choice1);
    if(choice2!=choice1)ret+=solver(pos+1,fav,choice2);
        return ret;
    }

    int main()
    {fastIO
        memset(dp,-1, sizeof(dp));
    cin>>input;
    n=input.length();
    ll ans=solver(0,0,0);
    for(int i=1;i<n;i++){
        if(abs(input[i]-input[i-1])>1)return cout<<ans,0;
    }
    cout<<ans-1;

        return 0;}

Output the single number — the number of phone numbers Masha will dial.

Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy. The phone number is divined like that. First one needs to write down one's own phone numbers. For example, let's suppose that Masha's phone number is 12345. After that one should write her favorite digit from 0 to 9 under the first digit of her number. That will be the first digit of the needed number. For example, Masha's favorite digit is 9. The second digit is determined as a half sum of the second digit of Masha's number and the already written down first digit from her beloved one's number. In this case the arithmetic average equals to (2 + 9) / 2 = 5.5. Masha can round the number up or down, depending on her wishes. For example, she chooses the digit 5. Having written down the resulting digit under the second digit of her number, Masha moves to finding the third digit in the same way, i.e. finding the half sum the the third digit of her number and the second digit of the new number. The result is (5 + 3) / 2 = 4. In this case the answer is unique. Thus, every i-th digit is determined as an arithmetic average of the i-th digit of Masha's number and the i - 1-th digit of her true love's number. If needed, the digit can be rounded up or down. For example, Masha can get: 12345 95444 Unfortunately, when Masha tried dialing the number, she got disappointed: as it turned out, the number was unavailable or outside the coverage area. But Masha won't give up. Perhaps, she rounded to a wrong digit or chose the first digit badly. That's why she keeps finding more and more new numbers and calling them. Count the number of numbers Masha calls. Masha calls all the possible numbers that can be found by the described means of arithmancy, except for, perhaps, her own one.


The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 100\,000$$$) — the number of fast food restaurants on the circle and the distance between the neighboring restaurants, respectively. The second line contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le \frac{k}{2}$$$) — the distances to the nearest fast food restaurants from the initial city and from the city Sergey made the first stop at, respectively.

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define N 100005
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define print(x) cout << #x << "=" << x << "\t";

ll n;
ll k;
ll a;
ll b;
ll ma = -1e18;
ll mi = 1e18;

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> k >> a >> b;

    for(ll i=0;i<=n;i++) {
        ll l = i * k + b + a;
        if (l <= 0)
            continue;
        ll g = __gcd(n * k, l);
        ll lcm = n * k / g;
        ma = max(ma, lcm);
        mi = min(mi, lcm);
    }

    for(ll i=0;i<=n;i++) {
        ll l = (i + 1) * k - b + a;
        ll g = __gcd(n * k, l);
        ll lcm = n * k / g;
        ma = max(ma, lcm);
        mi = min(mi, lcm);
    }

    for(ll i=0;i<=n;i++) {
        ll l = (i + 1) * k - a + b;
        ll g = __gcd(n * k, l);
        ll lcm = n * k / g;
        ma = max(ma, lcm);
        mi = min(mi, lcm);
    }

    for(ll i=0;i<=n;i++) {
        ll l = (i + 2) * k - a - b;
        ll g = __gcd(n * k, l);
        ll lcm = n * k / g;
        ma = max(ma, lcm);
        mi = min(mi, lcm);
    }

    cout << mi << " " << ma;
    return 0;
}

NoteIn the first example the restaurants are located in the cities $$$1$$$ and $$$4$$$, the initial city $$$s$$$ could be $$$2$$$, $$$3$$$, $$$5$$$, or $$$6$$$. The next city Sergey stopped at could also be at cities $$$2, 3, 5, 6$$$. Let's loop through all possible combinations of these cities. If both $$$s$$$ and the city of the first stop are at the city $$$2$$$ (for example, $$$l = 6$$$), then Sergey is at $$$s$$$ after the first stop already, so $$$x = 1$$$. In other pairs Sergey needs $$$1, 2, 3$$$, or $$$6$$$ stops to return to $$$s$$$, so $$$y = 6$$$.In the second example Sergey was at cities with fast food restaurant both initially and after the first stop, so $$$l$$$ is $$$2$$$, $$$4$$$, or $$$6$$$. Thus $$$x = 1$$$, $$$y = 3$$$.In the third example there is only one restaurant, so the possible locations of $$$s$$$ and the first stop are: $$$(6, 8)$$$ and $$$(6, 4)$$$. For the first option $$$l = 2$$$, for the second $$$l = 8$$$. In both cases Sergey needs $$$x=y=5$$$ stops to go to $$$s$$$.

Print the two integers $$$x$$$ and $$$y$$$.

Recently a Golden Circle of Beetlovers was found in Byteland. It is a circle route going through $$$n \cdot k$$$ cities. The cities are numerated from $$$1$$$ to $$$n \cdot k$$$, the distance between the neighboring cities is exactly $$$1$$$ km.Sergey does not like beetles, he loves burgers. Fortunately for him, there are $$$n$$$ fast food restaurants on the circle, they are located in the $$$1$$$-st, the $$$(k + 1)$$$-st, the $$$(2k + 1)$$$-st, and so on, the $$$((n-1)k + 1)$$$-st cities, i.e. the distance between the neighboring cities with fast food restaurants is $$$k$$$ km.Sergey began his journey at some city $$$s$$$ and traveled along the circle, making stops at cities each $$$l$$$ km ($$$l > 0$$$), until he stopped in $$$s$$$ once again. Sergey then forgot numbers $$$s$$$ and $$$l$$$, but he remembers that the distance from the city $$$s$$$ to the nearest fast food restaurant was $$$a$$$ km, and the distance from the city he stopped at after traveling the first $$$l$$$ km from $$$s$$$ to the nearest fast food restaurant was $$$b$$$ km. Sergey always traveled in the same direction along the circle, but when he calculated distances to the restaurants, he considered both directions.Now Sergey is interested in two integers. The first integer $$$x$$$ is the minimum number of stops (excluding the first) Sergey could have done before returning to $$$s$$$. The second integer $$$y$$$ is the maximum number of stops (excluding the first) Sergey could have done before returning to $$$s$$$.

Input:
2 3
1 1

Output: 1 6

Input:
3 2
0 0

Output: 1 3

Input:
1 10
5 3

Output: 5 5

Input:
3 3
1 0

Output: 9 9

Input:
4 3
1 1

Output: 1 12

Input:
5 5
2 2

Output: 1 25

Input:
6 3
1 1

Output: 1 18

Input:
3 10
1 3

Output: 5 15

Input:
2 1
0 0

Output: 1 2

Input:
1 100
0 0

Output: 1 1

Input:
39 17
8 5

Output: 17 663

Input:
147 149
74 33

Output: 149 21903

Input:
100000 100
21 29

Output: 64 2500000

Input:
100000 100000
50000 50000

Output: 1 100000

Input:
16127 18181
6581 2408

Output: 18181 293204987

Input:
96557 28657
2964 7036

Output: 28657 2767033949

Input:
96557 4
0 2

Output: 2 193114

Input:
2 98763
10021 19979

Output: 32921 197526

Input:
10 99990
3 7

Output: 9999 499950

Input:
99999 23782
0 0

Output: 1 99999

Input:
14621 29242
7 13

Output: 213773641 213773641

Input:
23981 21841
10376 10637

Output: 21841 523769021

Input:
21013 45013
693 307

Output: 45013 945858169

Input:
36739 36739
18369 18369

Output: 1 1349754121

Input:
65536 32768
6427 13573

Output: 67108864 1073741824

Input:
99871 99877
5273 34727

Output: 99877 9974815867

Input:
99871 99873
2979 17955

Output: 11097 1108268487

Input:
99873 99876
24862 13862

Output: 1189 2493728937

Input:
99079 99053
49479 49521

Output: 99053 9814072187

Input:
95911 95917
47946 47954

Output: 95917 9199495387

Input:
89527 91159
44571 44990

Output: 91159 8161191793

Input:
98752 97209
41218 39020

Output: 21427641 3199861056

Input:
100000 100000
10 1

Output: 10000000000 10000000000

Input:
100000 100000
0 1

Output: 10000000000 10000000000

Input:
97979 85648
41517 20663

Output: 21412 4195852696

Input:
100000 99737
34242 43667

Output: 99737 9973700000

Input:
806 654
118 76

Output: 109 263562


The first line contains six integers n, m, x, y, a, b (1 ≤ n, m ≤ 109, 0 ≤ x ≤ n, 0 ≤ y ≤ m, 1 ≤ a ≤ n, 1 ≤ b ≤ m).

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <set>
using namespace std;
#define ll long long
int n,m,x,y,a,b;
int main()
{
   // freopen("in.txt","r",stdin);
    cin>>n>>m>>x>>y>>a>>b;
    ll t=__gcd(a,b);
    a/=t;
    b/=t;
    ll lx,ly;
    lx=n/a*a;
    ly=m/b*b;
    if(lx*b>a*ly)
    {
        lx=ly/b*a;
    }else  ly=lx/a*b;
//    cout<<a<<endl;
//    cout<<b<<endl;
//    cout<<lx<<endl;
//    cout<<ly<<endl;
    ll x2=x+(lx>>1);
    ll y2=y+(ly>>1);
    ll x1=x2-lx;
    ll y1=y2-ly;
    ll mx=x1<0?-x1:x2>n?n-x2:0;
    ll my=y1<0?-y1:y2>m?m-y2:0;
     printf("%lld %lld %lld %lld\n",x1+mx,y1+my,x2+mx,y2+my);
//    mx=my=0;
//    prllf("%d %d %d %d\n",x1+mx,y1+my,x2+mx,y2+my);

    return 0;
}

Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2).

You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m).Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≤ x1 ≤ x ≤ x2 ≤ n, 0 ≤ y1 ≤ y ≤ y2 ≤ m, .The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers.  If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one.

Input: 9 9 5 5 2 1

Output: 1 3 9 7

Input: 100 100 52 50 46 56

Output: 17 8 86 92

Input: 100 100 16 60 42 75

Output: 0 0 56 100

Input: 100 100 28 22 47 50

Output: 0 0 94 100

Input: 100 100 44 36 96 21

Output: 0 25 96 46

Input: 100 100 56 46 1 47

Output: 55 0 57 94

Input: 100 100 20 53 6 22

Output: 6 1 33 100

Input: 100 100 32 63 2 41

Output: 30 18 34 100

Input: 100 100 48 73 63 16

Output: 16 65 79 81

Input: 100 100 13 59 14 20

Output: 0 0 70 100

Input: 36830763 28058366 30827357 20792295 11047103 20670351

Output: 25303805 7388015 36350908 28058366

Input: 87453374 60940601 74141787 32143714 78082907 33553425

Output: 9370467 15367001 87453374 48920426

Input: 71265727 62692710 12444778 3479306 21442685 5463351

Output: 0 0 64328055 16390053

Input: 48445042 43730155 14655564 6244917 43454856 2866363

Output: 0 4811735 43454856 7678098

Input: 85759276 82316701 8242517 1957176 10225118 547026

Output: 0 0 81800944 4376208

Input: 64748258 21983760 9107246 2437546 11247507 8924750

Output: 0 0 22495014 17849500

Input: 6561833 24532010 2773123 457562 6225818 23724637

Output: 0 0 6225818 23724637

Input: 33417574 19362112 17938303 4013355 10231192 2596692

Output: 166200 0 33417574 8439249

Input: 98540143 28776614 12080542 1456439 96484500 3125739

Output: 0 0 96484500 3125739

Input: 75549175 99860242 42423626 6574859 73199290 26030615

Output: 2349885 0 75549175 26030615

Input: 4309493 76088457 2523467 46484812 909115 53662610

Output: 1887086 960803 3159847 76088457

Input: 99373741 10548319 82293354 9865357 58059929 5328757

Output: 41313812 5219562 99373741 10548319

Input: 81460 7041354 53032 1297536 41496 5748697

Output: 27916 0 78148 6958949

Input: 5664399 63519726 1914884 13554302 2435218 44439020

Output: 697275 0 3132493 44439020

Input: 19213492 76256257 10302871 19808004 19174729 55280126

Output: 38763 0 19213492 55280126

Input: 61430678 95017800 11901852 27772249 25202227 87778634

Output: 0 0 25202227 87778634

Input: 1063740 2675928 277215 2022291 204933 298547

Output: 0 1183193 1024665 2675928

Input: 71580569 68590917 4383746 13851161 9868376 8579752

Output: 0 0 71545726 62203202

Input: 17818532 82586436 8482338 54895799 12444902 11112345

Output: 2259887 49339626 14704789 60451971

Input: 63651025 50179036 16141802 24793214 28944209 13993078

Output: 0 10800136 57888418 38786292

Input: 11996821 42550832 8901163 19214381 3510233 20406511

Output: 4976355 0 11996821 40813022

Input: 27048166 72584165 4785744 2001800 24615554 27645416

Output: 0 0 24615554 27645416

Input: 47001271 53942737 7275347 1652337 33989593 48660013

Output: 0 0 33989593 48660013

Input: 51396415 50182729 20810973 38206844 17823753 2905275

Output: 0 34333144 47530008 42080544

Input: 27087649 52123970 20327636 19640608 8481031 14569965

Output: 1644556 0 27087649 43709895

Input: 41635044 16614992 36335190 11150551 30440245 13728274

Output: 11194799 2886718 41635044 16614992

Input: 97253692 35192249 21833856 26094161 41611668 32149284

Output: 0 363858 45079307 35192249

Input: 60300478 3471217 11842517 3192374 27980820 507119

Output: 0 2456979 55961640 3471217

Input: 69914272 30947694 58532705 25740028 30431847 27728130

Output: 39482425 3219564 69914272 30947694

Input: 83973381 91192149 19059738 26429459 49573749 78006738

Output: 0 0 49573749 78006738

Input: 1000000000 1000000000 286536427 579261823 230782719 575570138

Output: 171145067 291476754 401927786 867046892

Input: 1000000000 1000000000 42362139 725664533 91213476 617352813

Output: 0 176862916 121617968 1000000000

Input: 1000000000 1000000000 503220555 167034539 244352073 511651840

Output: 276322201 0 730118908 950210560

Input: 1000000000 1000000000 259046267 313437250 252266478 848401810

Output: 132913028 0 385179506 848401810

Input: 1000000000 1000000000 867388331 312356312 405405075 887925029

Output: 594594925 0 1000000000 887925029

Input: 1000000000 1000000000 623214043 753726318 970868535 929707704

Output: 29131465 70292296 1000000000 1000000000

Input: 1000000000 1000000000 84072459 754904836 124007132 824006731

Output: 22068893 175993269 146076025 1000000000

Input: 1000000000 1000000000 839898171 196274842 131921537 865789406

Output: 773937402 0 905858939 865789406

Input: 1000000000 1000000000 448240235 342677552 992352294 907572080

Output: 0 0 992352294 907572080

Input: 1000000000 1000000000 837887296 643696230 478881476 45404539

Output: 42237048 598291691 1000000000 689100769

Input: 1000000000 500 1000 400 11 122

Output: 978 12 1022 500

Input: 1000000000 1000000000 1000000000 1000000000 1 1

Output: 0 0 1000000000 1000000000

Input: 1000000000 1000000000 1000000000 1000000000 1000000000 1

Output: 0 999999999 1000000000 1000000000

Input: 1000000000 999999999 1000 1000 1000000000 999999999

Output: 0 0 1000000000 999999999

Input: 70 10 20 5 5 3

Output: 12 0 27 9

Input: 1000000000 1000000000 500000000 500000000 500000000 500000001

Output: 250000000 249999999 750000000 750000000


A single line contains three space-separated integers a, b, k (1 ≤ a, b, k ≤ 106; a ≤ b).

In a single line print a single integer — the required minimum l. If there's no solution, print -1.

You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.Consider positive integers a, a + 1, ..., b (a ≤ b). You want to find the minimum integer l (1 ≤ l ≤ b - a + 1) such that for any integer x (a ≤ x ≤ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers. Find and print the required minimum l. If no value l meets the described limitations, print -1.

Input: 2 4 2

Output: 3

Input: 6 13 1

Output: 4

Input: 1 4 3

Output: -1

Input: 5 8 2

Output: 4

Input: 8 10 3

Output: -1

Input: 1 5 2

Output: 3

Input: 6 8 3

Output: -1

Input: 21 29 2

Output: 9

Input: 17 27 3

Output: 11

Input: 1 1000000 10000

Output: 137970

Input: 690059 708971 10000

Output: -1

Input: 12357 534133 2

Output: 138

Input: 838069 936843 3

Output: 142

Input: 339554 696485 4

Output: 168

Input: 225912 522197 5

Output: 190

Input: 404430 864261 6

Output: 236

Input: 689973 807140 7

Output: 236

Input: 177146 548389 8

Output: 240

Input: 579857 857749 9

Output: 300

Input: 35648 527231 10

Output: 280

Input: 2 1000000 10000

Output: 137970

Input: 1 999999 9999

Output: 137958

Input: 5 5 10

Output: -1

Input: 11 11 6

Output: -1

Input: 4 4 95

Output: -1

Input: 1 1000000 1000000

Output: -1

Input: 1 1000000 78498

Output: 999999

Input: 1 1000000 78499

Output: -1

Input: 3459 94738 1

Output: 72

Input: 1 1000000 1

Output: 114

Input: 1 1000000 78497

Output: 999998

Input: 1 1000000 78490

Output: 999978

Input: 1000 10000 13

Output: 168

Input: 100000 1000000 7821

Output: 108426

Input: 20 1000000 40000

Output: 539580

Input: 1000 900000 50000

Output: 659334

Input: 10000 1000000 60000

Output: 793662

Input: 9999 99999 8000

Output: 86572

Input: 50 150 20

Output: 100

Input: 999953 999953 1

Output: 1

Input: 999953 999953 2

Output: -1

Input: 999931 999953 2

Output: 23

Input: 999906 999984 4

Output: 52

Input: 999940 999983 3

Output: 26

Input: 1 1 1

Output: -1

Input: 1 1 1000000

Output: -1

Input: 1 2 1

Output: 2

Input: 1 3 1

Output: 2

Input: 1 3 2

Output: 3

Input: 1 4 2

Output: 3

Input: 1 5 3

Output: 5

Input: 2 5 2

Output: 3

Input: 3 5 1

Output: 2


The single line of the input contains three integers n, d and mod (1 ≤ n ≤ 1000, 2 ≤ d ≤ 10, 108 ≤ mod ≤ 109)  — the number of vertices in the tree, the degree of internal vertices and the prime modulo.

#include <bits/stdc++.h>
using namespace std;
const int maxn=1005;
const int maxd=11;
long long n,d,mod,dp[maxn][maxd],pd[maxn][maxd],f,t[maxd];
inline long long ksm(long long x,long long n) {
    long long ret=1;
    while (n) {
        if (n&1)
            ret=ret*x%mod;
        n>>=1;
        x=x*x%mod;
    }
    return ret;
}
inline long long solve() {
    dp[1][0]=1;
    for (int i=1;i<=n/2;++i) {//if (i%(d-1)==0) {
        f=(i==1)?1:dp[i][d-1];
        for (int j=1;j<=n;++j)
            for (int k=0;k<=d;++k)
                pd[j][k]=0;
        t[0]=1;
        for (int j=1;j<=d;++j)
            t[j]=t[j-1]*(f+j-1)%mod*ksm(j,mod-2)%mod;
        for (int j=0;j<=d;++j)
            for (int k=0;k<=d;++k)  if (j+k<=d)
                for (int l=1;l<=n;++l) if (l+i*k<=n)
                    pd[l+i*k][j+k]=(pd[l+i*k][j+k]+dp[l][j]*t[k])%mod;
        for (int j=0;j<=n;++j)
            for (int k=0;k<=d;++k)
                //if (pd[j][k])
                    dp[j][k]=pd[j][k];
    }
    long long ret=dp[n][d];
    if (n%2==0)
        ret=((ret-dp[n/2][d-1]*(dp[n/2][d-1]-1)/2)%mod+mod)%mod;
    return ret;
}
int main()
{
    scanf("%I64d%I64d%I64d",&n,&d,&mod);
    if (n<=2)
        puts("1");
    else
        printf("%I64d\n",solve());
    return 0;
}

Print the number of trees over the modulo mod.

A tree is a connected graph without cycles.Two trees, consisting of n vertices each, are called isomorphic if there exists a permutation p: {1, ..., n} → {1, ..., n} such that the edge (u, v) is present in the first tree if and only if the edge (pu, pv) is present in the second tree.Vertex of the tree is called internal if its degree is greater than or equal to two.Count the number of different non-isomorphic trees, consisting of n vertices, such that the degree of each internal vertex is exactly d. Print the answer over the given prime modulo mod.

Input: 5 2 433416647

Output: 1

Input: 10 3 409693891

Output: 2

Input: 65 4 177545087

Output: 910726

Input: 2 2 434448163

Output: 1

Input: 2 3 434448163

Output: 1

Input: 2 4 434448163

Output: 1

Input: 2 5 434448163

Output: 1

Input: 180 3 434448163

Output: 106622108

Input: 104 7 434448163

Output: 47207

Input: 106 9 434448163

Output: 1296

Input: 1 4 904448911

Output: 1

Input: 2 6 904448911

Output: 1

Input: 2 7 904448911

Output: 1

Input: 2 8 904448911

Output: 1

Input: 102 4 904448911

Output: 0

Input: 2 9 904448911

Output: 1

Input: 2 10 904448911

Output: 1

Input: 100 2 944036243

Output: 1

Input: 101 4 944036243

Output: 467334192

Input: 102 5 944036243

Output: 74266477

Input: 102 6 944036243

Output: 748711

Input: 100 8 944036243

Output: 3128

Input: 101 10 944036243

Output: 235

Input: 1 2 727733989

Output: 1

Input: 1 3 727733989

Output: 1

Input: 1 5 727733989

Output: 1

Input: 1 6 727733989

Output: 1

Input: 1 7 727733989

Output: 1

Input: 1 8 727733989

Output: 1

Input: 1 9 837744727

Output: 1

Input: 1 10 837744727

Output: 1

Input: 999 3 837744727

Output: 0

Input: 1000 5 970400047

Output: 0

Input: 1000 6 970400047

Output: 0

Input: 1000 7 970400047

Output: 0

Input: 1000 8 750160753

Output: 0

Input: 1000 9 750160753

Output: 0

Input: 1000 10 750160753

Output: 0

Input: 1000 2 750160753

Output: 1

Input: 1000 3 750160753

Output: 16572167

Input: 998 4 817408561

Output: 443073705

Input: 998 5 680633279

Output: 233182629

Input: 997 6 680633279

Output: 148277591

Input: 998 7 930423869

Output: 167343048

Input: 996 8 990767311

Output: 350615945

Input: 994 9 390528763

Output: 211625777

Input: 992 10 762763321

Output: 571064998

Input: 983 10 762763321

Output: 663665406

Input: 989 8 990767311

Output: 976760285

Input: 992 6 680633279

Output: 451750559

Input: 995 4 817408561

Output: 36421881

Input: 999 2 750160753

Output: 1


The only line of the input contains two integers $$$n$$$ and $$$S$$$ ($$$1 \le n \le 100\,000$$$, $$$1 \le S \le 10^9$$$)

#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rep(i,x,y) for(register int i=x;i<=y;++i)
#define drp(i,x,y) for(register int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
int n,s;
int main(){//sjn AK IOI
	cin>>n>>s;
	int ans=s/n;
	if(s%n) ++ans;
	cout<<ans;
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

NoteIn the first example, some of the possible ways to get sum $$$11$$$ with $$$3$$$ coins are:   $$$(3, 4, 4)$$$ $$$(2, 4, 5)$$$ $$$(1, 5, 5)$$$ $$$(3, 3, 5)$$$ It is impossible to get sum $$$11$$$ with less than $$$3$$$ coins.In the second example, some of the possible ways to get sum $$$16$$$ with $$$3$$$ coins are:   $$$(5, 5, 6)$$$ $$$(4, 6, 6)$$$ It is impossible to get sum $$$16$$$ with less than $$$3$$$ coins.

Print exactly one integer — the minimum number of coins required to obtain sum $$$S$$$.

You have unlimited number of coins with values $$$1, 2, \ldots, n$$$. You want to select some set of coins having the total value of $$$S$$$. It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum $$$S$$$?

Input: 5 11

Output: 3

Input: 6 16

Output: 3

Input: 14 28

Output: 2

Input: 5 29

Output: 6

Input: 10 24

Output: 3

Input: 1 30

Output: 30

Input: 14969 66991573

Output: 4476

Input: 1 1000000000

Output: 1000000000

Input: 100000 1

Output: 1

Input: 10 46

Output: 5

Input: 11 35

Output: 4

Input: 12 45

Output: 4

Input: 15 34

Output: 3

Input: 31859 629091638

Output: 19747

Input: 15666 689919612

Output: 44040

Input: 90681 254480989

Output: 2807

Input: 69018 523197828

Output: 7581

Input: 1352 434805201

Output: 321602

Input: 73439 384841883

Output: 5241

Input: 42482 352232377

Output: 8292

Input: 57862 374476819

Output: 6472

Input: 41711 440229650

Output: 10555

Input: 46602 894472145

Output: 19194

Input: 47832 942980453

Output: 19715

Input: 22951 747845288

Output: 32585

Input: 76998 722886555

Output: 9389

Input: 68666 512525633

Output: 7465

Input: 66269 356663481

Output: 5383

Input: 56624 922065652

Output: 16285

Input: 31618 26008350

Output: 823

Input: 90952 904040054

Output: 9940

Input: 49630 947487392

Output: 19092

Input: 45084 431878651

Output: 9580

Input: 7156 806580442

Output: 112714

Input: 2 193379347

Output: 96689674

Input: 6 823813339

Output: 137302224

Input: 5 939845324

Output: 187969065

Input: 7 236413222

Output: 33773318

Input: 10 695784696

Output: 69578470

Input: 3 877026418

Output: 292342140

Input: 8 550991517

Output: 68873940

Input: 6 899779610

Output: 149963269

Input: 12 394018478

Output: 32834874

Input: 66 63576176

Output: 963276

Input: 66 982670621

Output: 14888949

Input: 8 750191967

Output: 93773996

Input: 10 349992600

Output: 34999260

Input: 65 281828001

Output: 4335816

Input: 53 468285594

Output: 8835578

Input: 83 361125900

Output: 4350915

Input: 15 191203328

Output: 12746889

Input: 100000 1000000000

Output: 10000

Input: 2 999999999

Output: 500000000

Input: 2 1000000000

Output: 500000000

Input: 4821 917142246

Output: 190240


The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <string>
#define sqr(x) (x)*(x)
#define fi first
#define se second
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=int(1e9+7);
int n,m;
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif //ONLINE_JUDGE
    scanf("%d%d",&n,&m);

    for (int i=0; ; i++){
        if (i/2>=n && i/3>=m && i/2+i/3-i/6>=n+m){
            printf("%d",i);
            break;
        }
    }

    #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    #endif // ONLINE_JUDGE
    return 0;
}

NoteIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.

Print a single integer, denoting the minimum possible height of the tallest tower.

Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

Input: 1 3

Output: 9

Input: 3 2

Output: 8

Input: 5 0

Output: 10

Input: 4 2

Output: 9

Input: 0 1000000

Output: 3000000

Input: 1000000 1

Output: 2000000

Input: 1083 724

Output: 2710

Input: 1184 868

Output: 3078

Input: 1285 877

Output: 3243

Input: 820189 548173

Output: 2052543

Input: 968867 651952

Output: 2431228

Input: 817544 553980

Output: 2057286

Input: 813242 543613

Output: 2035282

Input: 961920 647392

Output: 2413968

Input: 825496 807050

Output: 2448819

Input: 974174 827926

Output: 2703150

Input: 969872 899794

Output: 2804499

Input: 818549 720669

Output: 2308827

Input: 967227 894524

Output: 2792626

Input: 185253 152723

Output: 506964

Input: 195173 150801

Output: 518961

Input: 129439 98443

Output: 341823

Input: 163706 157895

Output: 482402

Input: 197973 140806

Output: 508168

Input: 1000000 1000000

Output: 3000000

Input: 1000000 999999

Output: 2999998

Input: 999999 1000000

Output: 3000000

Input: 500000 500100

Output: 1500300

Input: 500000 166000

Output: 1000000

Input: 500000 499000

Output: 1498500

Input: 500000 167000

Output: 1000500

Input: 1 1000000

Output: 3000000

Input: 2 999123

Output: 2997369

Input: 10 988723

Output: 2966169

Input: 234 298374

Output: 895122

Input: 2365 981235

Output: 2943705

Input: 12345 981732

Output: 2945196

Input: 108752 129872

Output: 389616

Input: 984327 24352

Output: 1968654

Input: 928375 1253

Output: 1856750

Input: 918273 219

Output: 1836546

Input: 987521 53

Output: 1975042

Input: 123456 1

Output: 246912

Input: 789123 0

Output: 1578246

Input: 143568 628524

Output: 1885572

Input: 175983 870607

Output: 2611821

Input: 6 4

Output: 15

Input: 6 3

Output: 14

Input: 7 3

Output: 15

Input: 5 4

Output: 14

Input: 5 3

Output: 12

Input: 8 5

Output: 20

Input: 1 0

Output: 2

Input: 19170 15725

Output: 52342

Input: 3000 2000

Output: 7500

Input: 7 4

Output: 16

Input: 50 30

Output: 120

Input: 300 200

Output: 750

Input: 9 4

Output: 20

Input: 4 3

Output: 10

Input: 1 1

Output: 3

Input: 8 6

Output: 21

Input: 10 6

Output: 24

Input: 65 56

Output: 182

Input: 13 10

Output: 34

Input: 14 42

Output: 126

Input: 651 420

Output: 1606

Input: 8 9

Output: 27

Input: 15 10

Output: 38

Input: 999999 888888

Output: 2833330

Input: 192056 131545

Output: 485402

Input: 32 16

Output: 72

Input: 18 12

Output: 45

Input: 1000000 666667

Output: 2500000

Input: 0 1

Output: 3

Input: 9 5

Output: 21

Input: 1515 1415

Output: 4395

Input: 300000 200000

Output: 750000


The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the prediction on the number of people who will buy the game.

#include<bits/stdc++.h>
using namespace std ;
long long n, ans ;

int main()
{
    cin >> n ;
    if(2520 > n) cout << 0 << endl;
    else
    {
        cout << n / 2520 << endl;
    }
}

Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.

IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.


The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).

#include <bits/stdc++.h>

using namespace std ;
typedef long long ll;

ll a, b, ans;

int main () {
    cin >> a >> b;
    if(a == b) {
        cout << 1;
        return 0;
    }
    long long x = b - a;
    //cout << x << '\n';
    if (x >= 5){
        cout << 0;
        return 0;
    }
    if (x == 1){
        cout << b % 10;
        return 0;
    }
    ans = 1;
    for (long long i = a + 1; i <= b; ++i){
        ans *= i;
        ans %= 10;
    }
    cout << ans % 10;
    return 0;
}
/*
998244355 998244359
*/

NoteIn the first example, the last digit of  is 2;In the second example, the last digit of  is 0;In the third example, the last digit of  is 2.

Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.

Even if the world is full of counterfeits, I still regard it as wonderful.Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, . Note that when b ≥ a this value is always integer.As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.

Input: 2 4

Output: 2

Input: 0 10

Output: 0

Input: 107 109

Output: 2

Input: 10 13

Output: 6

Input: 998244355 998244359

Output: 4

Input: 999999999000000000 1000000000000000000

Output: 0

Input: 2 3

Output: 3

Input: 3 15

Output: 0

Input: 24 26

Output: 0

Input: 14 60

Output: 0

Input: 11 79

Output: 0

Input: 1230 1232

Output: 2

Input: 2633 2634

Output: 4

Input: 535 536

Output: 6

Input: 344319135 396746843

Output: 0

Input: 696667767 696667767

Output: 1

Input: 419530302 610096911

Output: 0

Input: 238965115 821731161

Output: 0

Input: 414626436 728903812

Output: 0

Input: 274410639 293308324

Output: 0

Input: 650636673091305697 650636673091305702

Output: 0

Input: 651240548333620923 651240548333620924

Output: 4

Input: 500000000000000000 1000000000000000000

Output: 0

Input: 999999999999999999 1000000000000000000

Output: 0

Input: 1000000000000000000 1000000000000000000

Output: 1

Input: 0 4

Output: 4

Input: 50000000062000007 50000000062000011

Output: 0

Input: 0 0

Output: 1

Input: 1 1

Output: 1

Input: 0 2

Output: 2

Input: 10000000000012 10000000000015

Output: 0

Input: 5 5

Output: 1

Input: 12 23

Output: 0

Input: 0 11

Output: 0

Input: 11111234567890 11111234567898

Output: 0

Input: 0 3

Output: 6

Input: 1 2

Output: 2

Input: 999999999999999997 999999999999999999

Output: 2

Input: 4 5

Output: 5

Input: 0 1

Output: 1

Input: 101 1002

Output: 0

Input: 0 100000000000000001

Output: 0

Input: 99999999999999997 99999999999999999

Output: 2

Input: 14 15

Output: 5

Input: 8 19

Output: 0

Input: 12 22

Output: 0

Input: 999999999999996 999999999999999

Output: 4

Input: 1 3

Output: 6

Input: 124 125

Output: 5

Input: 11 32

Output: 0

Input: 0 5

Output: 0

Input: 0 999999

Output: 0

Input: 151151151515 151151151526

Output: 0

Input: 6 107

Output: 0

Input: 5 16

Output: 0

Input: 7 16

Output: 0

Input: 6 19

Output: 0

Input: 11113111111111 13111111111111

Output: 0

Input: 1 1000

Output: 0

Input: 24 25

Output: 5

Input: 0 100000000000

Output: 0

Input: 1 22

Output: 0

Input: 999999999999999996 999999999999999999

Output: 4


The single line of the input contains integers n, w and b (3 ≤ n ≤ 4000, 2 ≤ w ≤ 4000, 1 ≤ b ≤ 4000) — the number of days, the number of good events and the number of not-so-good events. It is guaranteed that w + b ≥ n.

#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define N 4010
#define mo 1000000009
#define int64 long long
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
int i,j,k,n,m,w,b;
int64 f1[N],f2[N],an;
inline int64 C(int n,int m) {
    if (m>n) return 0;
    if (!m) return 1;
    return f1[n]*f2[m]%mo*f2[n-m]%mo;
}
int main() {
    f1[0]=1;
    For(i,1,N-1) f1[i]=f1[i-1]*i%mo;
    f2[0]=f2[1]=1;
    For(i,2,N-1) f2[i]=(-f2[mo%i]*(mo/i)%mo+mo)%mo;
    For(i,2,N-1) f2[i]=f2[i]*f2[i-1]%mo;
    scanf("%d%d%d",&n,&w,&b);
    For(i,1,n-2) an=(an+f1[w]*f1[b]%mo*C(b-1,i-1)%mo*C(w-1,n-i-1)%mo*(n-i-1))%mo;
    printf("%I64d",an);  return 0;
}

NoteWe'll represent the good events by numbers starting from 1 and the not-so-good events — by letters starting from 'a'. Vertical lines separate days.In the first sample the possible ways are: "1|a|2" and "2|a|1". In the second sample the possible ways are: "1|a|b|2", "2|a|b|1", "1|b|a|2" and "2|b|a|1". In the third sample the possible ways are: "1|ab|2", "2|ab|1", "1|ba|2" and "2|ba|1".

Print the required number of ways modulo 1000000009 (109 + 9).

Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to take place during each day. As each day is unequivocally characterizes as a part of a white or a black stripe, then each day is going to have events of the same type only (ether good or not-so-good).What is the number of distinct ways this scenario can develop over the next n days if Polycarpus is in for a white stripe (a stripe that has good events only, the stripe's length is at least 1 day), the a black stripe (a stripe that has not-so-good events only, the stripe's length is at least 1 day) and a white stripe again (a stripe that has good events only, the stripe's length is at least 1 day). Each of n days will belong to one of the three stripes only.Note that even the events of the same type are distinct from each other. Even if some events occur on the same day, they go in some order (there are no simultaneous events).Write a code that prints the number of possible configurations to sort the events into days. See the samples for clarifications on which scenarios should be considered distinct. Print the answer modulo 1000000009 (109 + 9).

Input: 3 2 1

Output: 2

Input: 4 2 2

Output: 4

Input: 3 2 2

Output: 4

Input: 3 3 1

Output: 12

Input: 3 3 3

Output: 72

Input: 4 2 3

Output: 24

Input: 4 3 2

Output: 48

Input: 10 10 10

Output: 318389383

Input: 10 7 5

Output: 130636800

Input: 10 4 9

Output: 135283173

Input: 100 200 300

Output: 316471646

Input: 200 100 300

Output: 949581532

Input: 239 300 231

Output: 774612666

Input: 300 300 300

Output: 375912430

Input: 300 2 300

Output: 775907030

Input: 300 300 1

Output: 775907030

Input: 3 300 300

Output: 496527918

Input: 3 2 300

Output: 196174631

Input: 3 300 1

Output: 828107078

Input: 4000 1000 3000

Output: 876839920

Input: 4000 2000 2000

Output: 310481606

Input: 4000 100 3900

Output: 221262673

Input: 4000 2 3998

Output: 686088712

Input: 3 2 4000

Output: 938379934

Input: 3 4000 4000

Output: 680114446

Input: 4000 4000 1

Output: 63263244

Input: 4000 3998 2

Output: 296557186

Input: 4000 4000 4000

Output: 997463324

Input: 4000 4000 100

Output: 994443885

Input: 4000 100 4000

Output: 908339579


The first line contains an integer $$$n$$$ — the number of cards with digits that you have ($$$1 \leq n \leq 100$$$). The second line contains a string of $$$n$$$ digits (characters "0", "1", ..., "9") $$$s_1, s_2, \ldots, s_n$$$. The string will not contain any other characters, such as leading or trailing spaces.

#include<bits/stdc++.h>
using namespace std;
int num=0,n;
char ch;
int main() {
    scanf("%d\n",&n);
    for (int i=1;i<=n;i++) {
        scanf("%c",&ch);
        if (ch=='8') num++;
    }
    if (num==0) printf("0");
    else {
        if (num*11<=n) printf("%d",num);
        else printf("%d",n/11);
    }
    return 0;
}

NoteIn the first example, one phone number, "8000000000", can be made from these cards.In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".In the third example you can't make any phone number from the given cards.

If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.

Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.You have $$$n$$$ cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.

Input:
11
00000000008

Output: 1

Input:
22
0011223344556677889988

Output: 2

Input:
11
31415926535

Output: 0

Input:
99
097167815527663544905782574817314139311067328533970663873718450545467450059059869618211361469505108

Output: 9

Input:
100
8820286285185244938452488887088871457098945874486988698468788381417332842888928188688887641132194956

Output: 9

Input:
99
509170332523502565755650047942914747120102240396245453406790272793996913905060450414255616791704320

Output: 0

Input:
100
1976473621569903172721407763737179639055561746310369779167351419713916160700096173622427077757986026

Output: 1

Input:
100
8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

Output: 9

Input:
10
8888888888

Output: 0

Input:
20
88888888888888888888

Output: 1

Input:
30
888888888888888888888888888888

Output: 2

Input:
40
8888888888888888888888888888888888888888

Output: 3

Input:
50
88888888888888888888888888888888888888888888888888

Output: 4

Input:
60
888888888888888888888888888888888888888888888888888888888888

Output: 5

Input:
70
8888888888888888888888888888888888888888888888888888888888888888888888

Output: 6

Input:
80
88888888888888888888888888888888888888888888888888888888888888888888888888888888

Output: 7

Input:
90
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

Output: 8

Input:
11
24572366390

Output: 0

Input:
21
582586788289484878588

Output: 1

Input:
31
0868889888343881888987888838808

Output: 2

Input:
41
78888884888874788841882882888088888588888

Output: 3

Input:
51
882889888888689888850888388887688788888888888858888

Output: 4

Input:
61
8880888836888988888988888887388888888888868898887888818888888

Output: 5

Input:
71
88888888888888888888888188888805848888788088888883888883187888838888888

Output: 6

Input:
81
808888883488887888888808888888888888188888888388888888888888868688888488888882888

Output: 7

Input:
91
8828880888888884883888488888888888888881888888888884888888848588888808888888888888888880888

Output: 8

Input:
100
8888888888828188888888888888888808888888888888888888891888888768888888888288888885886888838888888888

Output: 9

Input:
22
4215079217017196952791

Output: 0

Input:
32
88257478884887437239023185588797

Output: 2

Input:
42
885887846290886288816884858898812858495482

Output: 3

Input:
52
8878588869084488848898838898788838337877898817818888

Output: 4

Input:
62
18888883884288488882387888486858887882838885288886472818688888

Output: 5

Input:
72
888488888888823288848804883838888888887888888888228888218488897809784868

Output: 6

Input:
82
8889809888888888485881851986857288588888888881988888868888836888887858888888888878

Output: 7

Input:
92
86888880558884738878888381088888888895888881888888888368878888888884888768881888888888808888

Output: 8

Input:
100
8881888389882878867888888888888888888886388888888870888884878888089888883898887888808688888487888888

Output: 9

Input:
33
270375004567749549929235905225024

Output: 0

Input:
43
7404899846883344886153727489084158470112581

Output: 3

Input:
53
85838985300863473289888099788588319484149888886832906

Output: 4

Input:
63
728385948188688801288285888788852829888898565895847689806684688

Output: 5

Input:
73
2185806538483837898808836883483888818818988881880688028788888081888907898

Output: 6

Input:
83
88584458884288808888588388818938838468960248387898182887888867888888888886088895788

Output: 7

Input:
93
888088898748888038885888818882806848806887888888882087481868888888177809288888889648468888188

Output: 8

Input:
100
8088888818885808888888848829886788884187188858898888888788988688884828586988888888288078638898728181

Output: 9

Input:
44
15920309219313427633220119270900111650391207

Output: 0

Input:
54
438283821340622774637957966575424773837418828888614203

Output: 4

Input:
64
8885984815868480968883818886281846682409262501034555933863969284

Output: 5

Input:
74
70988894874867688968816582886488688881063425288316858438189808828755218508

Output: 6

Input:
84
181288888282608548858058871581888853888486785801381108858832882809848798828837386086

Output: 7

Input:
94
8188948828818938226378510887848897889883818858778688882933888883888898198978868888808082461388

Output: 8

Input:
100
2867878187889776883889958480848802884888888878218089281860321588888888987288888884288488988628618888

Output: 9

Input:
55
7271714707719515303911625619272900050990324951111943573

Output: 0

Input:
65
44542121362830719677175203560438858260878894083124543850593761845

Output: 5

Input:
75
878909759892888846183608689257806813376950958863798487856148633095072259838

Output: 6

Input:
85
6888887655188885918863889822590788834182048952565514598298586848861396753319582883848

Output: 7

Input:
95
29488352815808808845913584782288724288898869488882098428839370889284838688458247785878848884289

Output: 8

Input:
100
2833898888858387469888804083887280788584887487186899808436848018181838884988432785338497585788803883

Output: 9

Input:
66
747099435917145962031075767196746707764157706291155762576312312094

Output: 0

Input:
76
7900795570936733366353829649382870728119825830883973668601071678041634916557

Output: 6

Input:
86
84065885114540280210185082984888812185222886689129308815942798404861082196041321701260

Output: 7

Input:
96
812087553199958040928832802441581868680188987878748641868838838835609806814288472573117388803351

Output: 8

Input:
77
11233392925013001334679215120076714945221576003953746107506364475115045309091

Output: 0

Input:
87
311753415808202195240425076966761033489788093280714672959929008324554784724650182457298

Output: 7

Input:
97
4088468966684435599488804806521288358953088399738904557539253573051442198885776802972628197705081

Output: 8

Input:
100
6451941807833681891890004306065158148809856572066617888008875119881621810329816763604830895480467878

Output: 9

Input:
88
2694079127792970410465292300936220976260790323517221561516591792566791677970332966660472

Output: 0

Input:
98
87247250157776241281197787785951754485531639139778166755966603305697265958800376912432893847612736

Output: 8

Input:
100
1835563855281170226095294644116563180561156535623048783710060508361834822227075869575873675232708159

Output: 9

Input:
11
55814018693

Output: 1

Input:
22
6188156585823394680191

Output: 2

Input:
33
429980628264468835720540136177288

Output: 3

Input:
44
30153452341853403190257244993442815171970194

Output: 2

Input:
55
3982037603326093160114589190899881252765957832414122484

Output: 5

Input:
66
157941266854773786962397310504192100434183957442977444078457168272

Output: 5

Input:
1
0

Output: 0

Input:
11
80000000000

Output: 1

Input:
27
888000000000000000000000000

Output: 2

Input:
10
8000000000

Output: 0

Input:
1
8

Output: 0

Input:
50
88000000000000000000000000000000000000000000000000

Output: 2

Input:
11
81234567090

Output: 1

Input:
32
88000000000000000000000000000000

Output: 2

Input:
57
888888888888888888888888888888888888888888888888888888888

Output: 5

Input:
22
8899999999999999999999

Output: 2

Input:
21
881234567900123456790

Output: 1

Input:
21
888888555555555555555

Output: 1

Input:
21
888000000000000000000

Output: 1

Input:
100
8800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Output: 2

Input:
21
888888888888000000000

Output: 1

Input:
8
12345678

Output: 0

Input:
21
880000000000000000000

Output: 1

Input:
11
81234567123

Output: 1

Input:
11
88888888888

Output: 1

Input:
32
88888888888888888888888888888888

Output: 2

Input:
33
888800000000000000000000000000000

Output: 3

Input:
100
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008

Output: 1

Input:
21
888111111111111111111

Output: 1

Input:
77
11111111111111111111111111111111111111111111111111111111111111111111111111111

Output: 0


//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
#include <time.h>

//using    namespace __gnu_pbds;
using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define scln1(a) scanf("%lld",&a)
#define scln2(a,b) scanf("%lld %lld",&a,&b)
#define scln3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

/*** Output ***/
#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pfln1(a) printf("%lld\n",a)
#define pfln2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin>>arr[i];
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) cin>>arr[i];
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/

#define    ff              first
#define    ss              second
#define    re              return
#define    MP              make_pair
#define    pb              push_back
#define    SZ(x)           ((int) (x).size())

#define    EPS             10E-10
#define    mxx             100005
#define    MOD             1000000007
#define    iseq(a,b)       (fabs(a-b)<EPS)
#define    PI              3.141592653589793238462643

#define    gcd(a, b)       __gcd(a,b)
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    lcm(a, b)       ((a)*(b)/gcd(a,b))
#define    min4(a,b,c,d)   min(d,min(a,min(b,c)))
#define    max4(a,b,c,d)   max(d,max(a,max(b,c)))
#define    input           freopen("input.txt","rt", stdin)
#define    output          freopen("output.txt","wt", stdout)

#define    all(v)          v.begin(),v.end()
#define    mem(nam,val)    memset(nam, val, sizeof(nam))
#define    Unique(X)       (X).resize(unique(all(X))-(X).begin())
#define    get_pos(c,x)    (lower_bound(c.begin(),c.end(),x)-c.begin())
#define    IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef stack <ll> stll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** BitWise Operations
///int Set(int N,int pos){return N=N | (1<<pos);}
///int reset(int N,int pos){return N= N & ~(1<<pos);}
///bool check(int N,int pos){return (bool)(N & (1<<pos));}
***/

/*** Grids
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
***/

/*** Functions
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///ll toint(string s){ll n=0,k=1;for(int i=s.size()-1; i>=0; i--){n += ((s[i]-'0')*k);k*=10;}return n;}
///string tostring(ll x){string s="";while(x){s += (x%10)+'0';x/=10;}reverse(s.begin(),s.end());return s;}
///bool sortinrev(const pair<ll,ll> &a,const pair<ll,ll> &b)return (a.first > b.first);
///priority_queue< pll ,vector<pll>,greater<pll> >p;
///cout<<*X.find_by_order(0)<<endl;
///cout<<X.order_of_key(-5)<<endl;
***/

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'

ll A[1000005];
ll B[1000005];
ll fac[1000005];

void fact(ll m)
{
    fac[0]=1;
    for(ll i=1;i<=250005;i++)
    {
        fac[i]=(i*fac[i-1])%m;
    }
}

int main()
{
    IOS;
    ll tst=1;
   // cin>>tst;
    for(ll tt=1;tt<=tst;tt++)
    {
        //code
        ll n,m;
        cin>>n>>m;
        fact(m);
        ll res=(fac[n]*n)%m;
        for(ll i=1;i<n;i++)
        {
            ll dif=i+1;
            dif=fac[dif];
            dif=(dif*(n-i))%m;
            ll val=(dif*fac[n-i])%m;
           // val=(val*fac[n-i]);
            res=(res+val)%m;
        }
        cout<<res<<endl;

    }

    return 0;
}

NoteFor sample input $$$n=3$$$, let's consider all permutations of length $$$3$$$:  $$$[1, 2, 3]$$$, all subsegments are framed segment. Happiness is $$$6$$$.  $$$[1, 3, 2]$$$, all subsegments except $$$[1, 2]$$$ are framed segment. Happiness is $$$5$$$.  $$$[2, 1, 3]$$$, all subsegments except $$$[2, 3]$$$ are framed segment. Happiness is $$$5$$$.  $$$[2, 3, 1]$$$, all subsegments except $$$[2, 3]$$$ are framed segment. Happiness is $$$5$$$.  $$$[3, 1, 2]$$$, all subsegments except $$$[1, 2]$$$ are framed segment. Happiness is $$$5$$$.  $$$[3, 2, 1]$$$, all subsegments are framed segment. Happiness is $$$6$$$. Thus, the sum of happiness is $$$6+5+5+5+5+6 = 32$$$.

Print $$$r$$$ ($$$0 \le r < m$$$), the sum of happiness for all permutations of length $$$n$$$, modulo a prime number $$$m$$$.

Recall that the permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).A sequence $$$a$$$ is a subsegment of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. We will denote the subsegments as $$$[l, r]$$$, where $$$l, r$$$ are two integers with $$$1 \le l \le r \le n$$$. This indicates the subsegment where $$$l-1$$$ elements from the beginning and $$$n-r$$$ elements from the end are deleted from the sequence.For a permutation $$$p_1, p_2, \ldots, p_n$$$, we define a framed segment as a subsegment $$$[l,r]$$$ where $$$\max\{p_l, p_{l+1}, \dots, p_r\} - \min\{p_l, p_{l+1}, \dots, p_r\} = r - l$$$. For example, for the permutation $$$(6, 7, 1, 8, 5, 3, 2, 4)$$$ some of its framed segments are: $$$[1, 2], [5, 8], [6, 7], [3, 3], [8, 8]$$$. In particular, a subsegment $$$[i,i]$$$ is always a framed segments for any $$$i$$$ between $$$1$$$ and $$$n$$$, inclusive.We define the happiness of a permutation $$$p$$$ as the number of pairs $$$(l, r)$$$ such that $$$1 \le l \le r \le n$$$, and $$$[l, r]$$$ is a framed segment. For example, the permutation $$$[3, 1, 2]$$$ has happiness $$$5$$$: all segments except $$$[1, 2]$$$ are framed segments.Given integers $$$n$$$ and $$$m$$$, Jongwon wants to compute the sum of happiness for all permutations of length $$$n$$$, modulo the prime number $$$m$$$. Note that there exist $$$n!$$$ (factorial of $$$n$$$) different permutations of length $$$n$$$.

Input: 1 993244853

Output: 1

Input: 2 993244853

Output: 6

Input: 3 993244853

Output: 32

Input: 2019 993244853

Output: 923958830

Input: 2020 437122297

Output: 265955509

Input: 250000 993244853

Output: 872048421

Input: 244435 994838543

Output: 634651929

Input: 234324 994631069

Output: 720229385

Input: 249996 997202249

Output: 633673455

Input: 32433 992864681

Output: 302084847

Input: 4 389349601

Output: 180

Input: 5 141602633

Output: 1116

Input: 6 223676287

Output: 7728

Input: 7 110998807

Output: 59904

Input: 8 848339069

Output: 518400

Input: 9 298827211

Output: 4982400

Input: 10 876938317

Output: 52842240

Input: 11 739198003

Output: 614200320

Input: 12 273157301

Output: 122791732

Input: 13 797912417

Output: 234147739

Input: 14 353847517

Output: 42904792

Input: 249997 996061721

Output: 69046617

Input: 249998 990040613

Output: 108188702

Input: 249999 992509109

Output: 854585866

Input: 250000 996140731

Output: 227969454

Input: 2341 994476991

Output: 121932216

Input: 1000 100000651

Output: 92079298

Input: 100000 100000921

Output: 51605491

Input: 20422 956269049

Output: 895579878

Input: 40424 285650803

Output: 114646354

Input: 60426 547574749

Output: 323978028

Input: 80428 410667659

Output: 284512223

Input: 100432 858603079

Output: 763015781

Input: 120424 735211237

Output: 78258285

Input: 140426 454141843

Output: 451934478

Input: 160428 434183023

Output: 156691255

Input: 180420 266525887

Output: 239713633

Input: 200422 984828937

Output: 556345906

Input: 220424 428927617

Output: 43877713

Input: 240422 623039447

Output: 291729074


The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.

#include<bits/stdc++.h>
using namespace std;
int a[5];
int u[4];
bool f[5],falg;
void dfs(int dep)
{
    if(dep==4)
    {
        if(u[1]+u[2]>u[3]&&u[1]+u[3]>u[2]&&u[2]+u[3]>u[1])
        {
            printf("TRIANGLE");
            exit(0);
        }
        if(u[1]+u[2]>=u[3]&&u[1]+u[3]>=u[2]&&u[2]+u[3]>=u[1])falg=true;
        return;
    }
    for(int i=1;i<=4;i++)
    if(f[i]==false)
    {
        f[i]=true;
        u[dep]=a[i];
        dep++;
        dfs(dep);
        dep--;
        u[dep]=0;
        f[i]=false;
    }
}
int main()
{
    scanf("%d%d%d%d",a+1,a+2,a+3,a+4);
    dfs(1);
    if(falg==true)printf("SEGMENT");
    else printf("IMPOSSIBLE");
return 0;
}

Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.

Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.

Input: 4 2 1 3

Output: TRIANGLE

Input: 7 2 2 4

Output: SEGMENT

Input: 3 5 9 1

Output: IMPOSSIBLE

Input: 3 1 5 1

Output: IMPOSSIBLE

Input: 10 10 10 10

Output: TRIANGLE

Input: 11 5 6 11

Output: TRIANGLE

Input: 1 1 1 1

Output: TRIANGLE

Input: 10 20 30 40

Output: TRIANGLE

Input: 45 25 5 15

Output: IMPOSSIBLE

Input: 20 5 8 13

Output: TRIANGLE

Input: 10 30 7 20

Output: SEGMENT

Input: 3 2 3 2

Output: TRIANGLE

Input: 70 10 100 30

Output: SEGMENT

Input: 4 8 16 2

Output: IMPOSSIBLE

Input: 3 3 3 10

Output: TRIANGLE

Input: 1 5 5 5

Output: TRIANGLE

Input: 13 25 12 1

Output: SEGMENT

Input: 10 100 7 3

Output: SEGMENT

Input: 50 1 50 100

Output: TRIANGLE

Input: 50 1 100 49

Output: SEGMENT

Input: 49 51 100 1

Output: SEGMENT

Input: 5 11 2 25

Output: IMPOSSIBLE

Input: 91 50 9 40

Output: IMPOSSIBLE

Input: 27 53 7 97

Output: IMPOSSIBLE

Input: 51 90 24 8

Output: IMPOSSIBLE

Input: 3 5 1 1

Output: IMPOSSIBLE

Input: 13 49 69 15

Output: IMPOSSIBLE

Input: 16 99 9 35

Output: IMPOSSIBLE

Input: 27 6 18 53

Output: IMPOSSIBLE

Input: 57 88 17 8

Output: IMPOSSIBLE

Input: 95 20 21 43

Output: IMPOSSIBLE

Input: 6 19 32 61

Output: IMPOSSIBLE

Input: 100 21 30 65

Output: IMPOSSIBLE

Input: 85 16 61 9

Output: IMPOSSIBLE

Input: 5 6 19 82

Output: IMPOSSIBLE

Input: 1 5 1 3

Output: IMPOSSIBLE

Input: 65 10 36 17

Output: IMPOSSIBLE

Input: 81 64 9 7

Output: IMPOSSIBLE

Input: 11 30 79 43

Output: IMPOSSIBLE

Input: 1 1 5 3

Output: IMPOSSIBLE

Input: 21 94 61 31

Output: IMPOSSIBLE

Input: 49 24 9 74

Output: IMPOSSIBLE

Input: 11 19 5 77

Output: IMPOSSIBLE

Input: 52 10 19 71

Output: SEGMENT

Input: 2 3 7 10

Output: SEGMENT

Input: 1 2 6 3

Output: SEGMENT

Input: 2 6 1 8

Output: SEGMENT

Input: 1 2 4 1

Output: SEGMENT

Input: 4 10 6 2

Output: SEGMENT

Input: 2 10 7 3

Output: SEGMENT

Input: 5 2 3 9

Output: SEGMENT

Input: 6 1 4 10

Output: SEGMENT

Input: 10 6 4 1

Output: SEGMENT

Input: 3 2 9 1

Output: SEGMENT

Input: 22 80 29 7

Output: SEGMENT

Input: 2 6 3 9

Output: SEGMENT

Input: 3 1 2 1

Output: SEGMENT

Input: 3 4 7 1

Output: SEGMENT

Input: 8 4 3 1

Output: SEGMENT

Input: 2 8 3 5

Output: SEGMENT

Input: 4 1 2 1

Output: SEGMENT

Input: 8 1 3 2

Output: SEGMENT

Input: 6 2 1 8

Output: SEGMENT

Input: 3 3 3 6

Output: TRIANGLE

Input: 3 6 3 3

Output: TRIANGLE

Input: 4 10 4 4

Output: TRIANGLE

Input: 1 1 2 1

Output: TRIANGLE

Input: 3 3 3 6

Output: TRIANGLE

Input: 5 4 5 5

Output: TRIANGLE

Input: 8 7 8 8

Output: TRIANGLE

Input: 3 3 3 1

Output: TRIANGLE

Input: 1 1 6 6

Output: TRIANGLE

Input: 1 9 1 9

Output: TRIANGLE

Input: 7 2 2 7

Output: TRIANGLE

Input: 7 2 3 2

Output: TRIANGLE

Input: 4 4 10 10

Output: TRIANGLE

Input: 7 7 10 7

Output: TRIANGLE

Input: 4 4 4 5

Output: TRIANGLE

Input: 1 10 9 2

Output: TRIANGLE

Input: 1 8 2 7

Output: TRIANGLE

Input: 4 3 2 8

Output: TRIANGLE

Input: 5 9 5 3

Output: TRIANGLE

Input: 4 10 3 5

Output: TRIANGLE


The single line contains space-separated integers l and r (1 ≤ l ≤ r ≤ 1018). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

#define F first
#define S second
#define eps 1e-8
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define INF 2000000000

typedef long long ll;

using namespace std;
ll l, r, ans;
int q, Q, p;
bool w[99], W[99];
int main()
{
	ios::sync_with_stdio(0);
	cin >> l >> r;
	while(l){
		w[q++] = l % 2;
		l >>= 1;
	}
	while(r){
		W[Q++] = r % 2;
		r >>= 1;
	}
	for(int i = Q; i >= 0; i--)
		if(w[i] != W[i]){
			p = i + 1;
			break;
		}
	ans = (1ll << p) - 1ll;
	cout << ans;

	return 0;
}

In a single line print a single integer — the maximum value of  for all pairs of integers a, b (l ≤ a ≤ b ≤ r).

A little girl loves problems on bitwise operations very much. Here's one of them.You are given two integers l and r. Let's consider the values of  for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value among all considered ones.Expression  means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal — as "xor".

Input: 1 2

Output: 3

Input: 8 16

Output: 31

Input: 1 1

Output: 0

Input: 506 677

Output: 1023

Input: 33 910

Output: 1023

Input: 36 94

Output: 127

Input: 10000000000 20000000000

Output: 34359738367

Input: 79242383109441603 533369389165030783

Output: 576460752303423487

Input: 797162752288318119 908416915938410706

Output: 576460752303423487

Input: 230148668013473494 573330407369354716

Output: 576460752303423487

Input: 668869743157683834 805679503731305624

Output: 288230376151711743

Input: 32473107276976561 588384394540535099

Output: 1152921504606846975

Input: 632668612680440378 864824360766754908

Output: 576460752303423487

Input: 658472316271074503 728242833853270665

Output: 288230376151711743

Input: 289218059048863941 314351197831808685

Output: 36028797018963967

Input: 54248140375568203 718189790306910368

Output: 1152921504606846975

Input: 330134158459714054 457118108955760856

Output: 288230376151711743

Input: 190442232278841373 980738846929096255

Output: 1152921504606846975

Input: 203359308073091683 455893840817516371

Output: 576460752303423487

Input: 200851182089362664 449305852839820160

Output: 576460752303423487

Input: 731792654005832175 789527173439457653

Output: 72057594037927935

Input: 231465750142682282 276038074124518614

Output: 72057594037927935

Input: 462451489958473150 957447393463701191

Output: 1152921504606846975

Input: 68666076639301243 247574109010873331

Output: 288230376151711743

Input: 491113582000560303 858928223424873439

Output: 1152921504606846975

Input: 454452550141901489 843034681327343036

Output: 1152921504606846975

Input: 43543567767276698 769776048133345296

Output: 1152921504606846975

Input: 214985598536531449 956713939905291713

Output: 1152921504606846975

Input: 56445001476501414 706930175458589379

Output: 1152921504606846975

Input: 666033930784103123 883523065811761270

Output: 576460752303423487

Input: 501827377176522663 590153819613032662

Output: 1152921504606846975

Input: 140216419613864821 362678730465999561

Output: 576460752303423487

Input: 23811264031960242 520940113721281721

Output: 576460752303423487

Input: 43249439481689805 431488136320817289

Output: 576460752303423487

Input: 198909890748296613 528950282310167050

Output: 576460752303423487

Input: 190620774979376809 899159649449168622

Output: 1152921504606846975

Input: 18565852953382418 697862904569985066

Output: 1152921504606846975

Input: 277046860122752192 828379515775613732

Output: 1152921504606846975

Input: 25785331761502790 119852560236585580

Output: 144115188075855871

Input: 363313173638414449 500957528623228245

Output: 288230376151711743

Input: 549330032897152846 715374717344043295

Output: 1152921504606846975

Input: 47456305370335136 388462406071482688

Output: 576460752303423487

Input: 125051194948742221 235911208585118006

Output: 288230376151711743

Input: 780993382943360354 889872865454335075

Output: 576460752303423487

Input: 815449097320007662 942453891178865528

Output: 576460752303423487

Input: 765369978472937483 796958953973862258

Output: 144115188075855871

Input: 259703440079833303 857510033561081530

Output: 1152921504606846975

Input: 181513087965617551 301910258955864271

Output: 576460752303423487

Input: 28591024119784617 732203343197854927

Output: 1152921504606846975

Input: 215365547805299155 861595308221385098

Output: 1152921504606846975

Input: 1 1000000000000000000

Output: 1152921504606846975

Input: 1000000000000 999999999999999999

Output: 1152921504606846975

Input: 1 1

Output: 0

Input: 9999999999998 9999999999999

Output: 1

Input: 9999999999900 9999999999901

Output: 1

Input: 9999999999900 9999999999902

Output: 3

Input: 9999999999900 9999999999903

Output: 3

Input: 1 3

Output: 3

Input: 5000000 5900000

Output: 2097151

Input: 8589934592 8989934592

Output: 536870911


The first and only line contains three integers: n, m and k (1 ≤ n, m, k ≤ 2000).

#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
long long ans=1,n,m,k;
int main()
{
	cin >> n >> m >> k;
	if (k == 1 || k>n){
		for (int i = 1; i <= n; i++){ ans = (ans*m) % 1000000007; }
		cout << ans;
	}
	else if (k == n){
		for (int i = 1; i <= int((n + 1) / 2); i++){
			ans = (ans*m) % 1000000007;
		}
		cout << ans;
	}
	else if (k % 2 == 1){
		cout << m*m;
	}
	else{
		cout << m;
	}
	return 0;
}

NoteIn the first sample only one string is valid: "a" (let's denote the only letter of our alphabet as "a").In the second sample (if we denote the alphabet letters as "a" and "b") the following strings are valid: "aaaaa" and "bbbbb".

Print a single integer — the number of strings of the described type modulo 1000000007 (109 + 7).

Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal to k is a palindrome. How many such strings exist? Your task is to find their quantity modulo 1000000007 (109 + 7). Be careful and don't miss a string or two!Let us remind you that a string is a palindrome if it can be read the same way in either direction, from the left to the right and from the right to the left.

Input: 1 1 1

Output: 1

Input: 5 2 4

Output: 2

Input: 7 4 20

Output: 16384

Input: 8 13 9

Output: 815730721

Input: 10 23 9

Output: 529

Input: 10 25 8

Output: 25

Input: 997 1752 1000

Output: 184834849

Input: 784 1 1999

Output: 1

Input: 341 9 342

Output: 320920086

Input: 777 1 777

Output: 1

Input: 542 13 542

Output: 490685740

Input: 1501 893 1501

Output: 889854713

Input: 1321 95 2

Output: 95

Input: 2000 1000 3

Output: 1000000

Input: 1769 849 1000

Output: 849

Input: 1000 2 1

Output: 688423210

Input: 345 1777 1

Output: 756253754

Input: 1999 2000 2000

Output: 675798323

Input: 1984 1847 1992

Output: 345702953

Input: 2000 2000 2000

Output: 321179016

Input: 1451 239 1451

Output: 968856942

Input: 2000 2000 1

Output: 596636543

Input: 1230 987 1

Output: 890209975

Input: 1764 305 843

Output: 93025

Input: 1999 98 132

Output: 98

Input: 2000 2 10

Output: 2

Input: 2000 1999 1999

Output: 3996001

Input: 1678 1999 1234

Output: 1999

Input: 7 10 7

Output: 10000

Input: 15 1 15

Output: 1

Input: 2000 2000 1000

Output: 2000

Input: 1 2000 2000

Output: 2000

Input: 10 10 90

Output: 999999937

Input: 100 100 1

Output: 424090053

Input: 6 6 6

Output: 216

Input: 10 10 1

Output: 999999937

Input: 100 10 100

Output: 319300014

Input: 5 4 5

Output: 64

Input: 5 2 5

Output: 8

Input: 1000 1000 1000

Output: 850431726

Input: 5 5 1

Output: 3125

Input: 1000 1000 1

Output: 524700271

Input: 4 256 1

Output: 294967268

Input: 5 5 5

Output: 125

Input: 10 10 10

Output: 100000

Input: 100 100 100

Output: 226732710

Input: 5 2 1

Output: 32

Input: 4 4 4

Output: 16

Input: 15 5 1

Output: 517577915

Input: 1000 2 1001

Output: 688423210

Input: 100 7 3

Output: 49

Input: 8 2 8

Output: 16

Input: 200 200 200

Output: 104842676

Input: 4 4 1

Output: 256

Input: 1999 1999 1999

Output: 21610777

Input: 17 5 1

Output: 939447791

Input: 100 5 1

Output: 146981449

Input: 10 5 1

Output: 9765625

Input: 11 2 11

Output: 64

Input: 100 1000 1

Output: 327648028

Input: 3 1000 3

Output: 1000000

Input: 3 3 3

Output: 9

Input: 3 5 3

Output: 25

Input: 20 3 3

Output: 9

Input: 10 2 1

Output: 1024

Input: 7 2 7

Output: 16

Input: 13 9 1

Output: 865810542

Input: 11 2 5

Output: 4

Input: 13 13 13

Output: 62748517

Input: 239 123 239

Output: 221051222


The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100\,000$$$), the number of rows and the number of columns of the field.

NoteThe picture below shows all possible random pictures of size $$$2$$$ by $$$3$$$.

Print one integer, the number of random pictures modulo $$$10^9 + 7$$$.

Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $$$n$$$ rows and $$$m$$$ columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo $$$10^9 + 7$$$.

Input: 2 3

Output: 8

Input: 1 2

Output: 4

Input: 1 1

Output: 2

Input: 2 1

Output: 4

Input: 1 3

Output: 6

Input: 3 1

Output: 6

Input: 2 5

Output: 18

Input: 3 6

Output: 30

Input: 2 2

Output: 6

Input: 1 100000

Output: 935236457

Input: 100000 1

Output: 935236457

Input: 91697 91697

Output: 999949469

Input: 86821 24538

Output: 1000000005

Input: 100000 100000

Output: 870472905

Input: 99999 1

Output: 822870997

Input: 1 99999

Output: 822870997

Input: 1 99998

Output: 112365460

Input: 99998 1

Output: 112365460

Input: 1 88588

Output: 153641669

Input: 68869 1

Output: 840775285

Input: 91248 82914

Output: 542035391

Input: 99999 100000

Output: 758107445

Input: 100000 99999

Output: 758107445

Input: 99999 99999

Output: 645741985

Input: 13771 94814

Output: 581579207

Input: 99411 90913

Output: 189215541

Input: 52702 64157

Output: 1000000005

Input: 24538 86821

Output: 1000000005


The first line of input contains K (1 ≤ K ≤ 25), the number of onsite finalists you know. The second line of input contains r1, r2, ..., rK (1 ≤ ri ≤ 106), the qualifying ranks of the finalists you know. All these ranks are distinct.

#include<iostream>
#include<algorithm>
using namespace std;
int n;
int ans;
const int maxn=1e6+10;
int sum[maxn];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>sum[i];
	}
	sort(sum+1,sum+1+n);
	if(sum[n]<=25)
	{
		cout<<"0"<<endl;
		return 0;
	}
	else
	{
		ans=sum[n]-25;
	}
	cout<<ans<<endl;
	return 0;
}

NoteIn the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.

Print the minimum possible number of contestants that declined the invitation to compete onsite.

This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.After the qualifying round completes, you know K of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round.

Input:
25
2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28

Output: 3

Input:
5
16 23 8 15 4

Output: 0

Input:
3
14 15 92

Output: 67

Input:
1
1000000

Output: 999975

Input:
25
1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976

Output: 999975

Input:
25
13 15 24 2 21 18 9 4 16 6 10 25 20 11 23 17 8 3 1 12 5 19 22 14 7

Output: 0

Input:
10
17 11 7 13 18 12 14 5 16 2

Output: 0

Input:
22
22 14 23 20 11 21 4 12 3 8 7 9 19 10 13 17 15 1 5 18 16 2

Output: 0

Input:
21
6 21 24 3 10 23 14 2 26 12 8 1 15 13 9 5 19 20 4 16 22

Output: 1

Input:
1
1

Output: 0

Input:
2
100 60

Output: 75

Input:
4
999 581 787 236

Output: 974

Input:
6
198 397 732 1234 309 827

Output: 1209

Input:
11
6494 3961 1858 4351 8056 780 7720 6211 1961 8192 3621

Output: 8167

Input:
14
18809 9534 11652 6493 8929 9370 4125 23888 16403 3559 23649 19243 14289 17852

Output: 23863

Input:
18
24939 35558 47058 70307 26221 12866 3453 40422 47557 36322 40698 64060 10825 77777 48645 26124 4859 64222

Output: 77752

Input:
24
633483 654321 122445 481150 347578 37803 525083 151084 211073 358699 339420 452023 219553 119727 74852 66750 371279 405099 618894 649977 235337 607819 81649 649804

Output: 654296

Input:
25
58115 794098 753382 484882 238434 674285 690118 858677 196185 173301 349729 918792 600745 636016 122678 366783 137179 377098 917081 369620 449039 379412 503678 1000000 292099

Output: 999975

Input:
2
26 27

Output: 2

Input:
3
40 30 35

Output: 15

Input:
2
46 45

Output: 21

Input:
3
1 25 90

Output: 65

Input:
5
14 15 16 30 92

Output: 67

Input:
2
1000 1001

Output: 976

Input:
25
3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28 2

Output: 3