The first line contains two integers n, k (1 ≤ n ≤ 50, 1 ≤ k ≤ 5000) — the number of people, including Greg, and the boat's weight limit. The next line contains n integers — the people's weights. A person's weight is either 50 kilos or 100 kilos. You can consider Greg and his friends indexed in some way.

NoteIn the first test Greg walks alone and consequently, he needs only one ride across the river.In the second test you should follow the plan:  transport two 50 kg. people;  transport one 50 kg. person back;  transport one 100 kg. person;  transport one 50 kg. person back;  transport two 50 kg. people. That totals to 5 rides. Depending on which person to choose at step 2, we can get two distinct ways.

In the first line print an integer — the minimum number of rides. If transporting everyone to the other bank is impossible, print an integer -1. In the second line print the remainder after dividing the number of ways to transport the people in the minimum number of rides by number 1000000007 (109 + 7). If transporting everyone to the other bank is impossible, print integer 0.

One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, just where the guys were standing. We know that the boat can hold people with the total weight of at most k kilograms.Greg immediately took a piece of paper and listed there the weights of all people in his group (including himself). It turned out that each person weights either 50 or 100 kilograms. Now Greg wants to know what minimum number of times the boat needs to cross the river to transport the whole group to the other bank. The boat needs at least one person to navigate it from one bank to the other. As the boat crosses the river, it can have any non-zero number of passengers as long as their total weight doesn't exceed k.Also Greg is wondering, how many ways there are to transport everybody to the other side in the minimum number of boat rides. Two ways are considered distinct if during some ride they have distinct sets of people on the boat.Help Greg with this problem.

Input:
1 50
50

Output:
1
1

Input:
3 100
50 50 100

Output:
5
2

Input:
2 50
50 50

Output:
-1
0

Input:
5 258
100 100 50 50 50

Output:
3
72

Input:
8 191
50 100 50 100 50 100 100 50

Output:
11
19318272

Input:
3 121
100 100 50

Output:
-1
0

Input:
8 271
100 50 100 50 50 50 100 50

Output:
5
78090

Input:
2 233
50 100

Output:
1
1

Input:
2 153
100 50

Output:
1
1

Input:
5 257
50 50 50 50 50

Output:
1
1

Input:
49 290
100 100 100 100 100 100 100 100 50 100 50 100 100 100 50 50 100 50 50 100 100 100 100 100 100 50 100 100 50 100 50 50 100 100 100 50 50 50 50 50 100 100 100 50 100 50 100 50 50

Output:
39
99624366

Input:
29 129
50 50 50 100 100 100 50 100 50 50 50 100 50 100 100 100 50 100 100 100 50 50 50 50 50 50 50 50 50

Output:
77
37050209

Input:
32 121
100 100 100 100 100 50 100 100 50 100 50 100 50 100 50 100 50 50 50 100 100 50 100 100 100 100 50 100 50 100 100 50

Output:
101
245361086

Input:
3 118
100 100 100

Output:
-1
0

Input:
10 4894
100 50 50 50 100 50 50 100 50 100

Output:
1
1

Input:
36 250
50 100 100 50 100 100 100 50 50 100 50 50 50 50 50 50 100 50 100 100 100 100 100 100 100 50 50 100 50 50 100 100 100 100 100 50

Output:
27
77447096

Input:
31 291
50 100 100 50 100 100 100 50 100 100 100 100 50 50 50 100 100 100 50 100 100 50 50 50 50 100 100 50 50 100 100

Output:
23
393964729

Input:
31 161
100 50 50 50 50 100 50 100 50 100 100 50 50 100 100 50 100 50 50 100 50 100 100 50 50 100 50 50 100 50 100

Output:
43
670669365

Input:
5 123
50 100 50 50 50

Output:
9
4536

Input:
43 293
50 50 100 100 50 100 100 50 100 100 50 100 50 100 50 50 50 50 50 100 100 100 50 50 100 50 100 100 100 50 100 100 100 50 50 50 100 50 100 100 50 100 50

Output:
31
658920847

Input:
23 100
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50

Output:
43
689584957

Input:
41 218
50 50 100 50 100 100 50 100 100 50 50 100 50 50 50 50 100 50 100 50 50 50 100 50 50 50 50 100 100 100 100 100 100 50 100 50 100 100 100 50 50

Output:
39
298372053

Input:
11 4668
50 100 100 100 50 100 50 50 100 100 100

Output:
1
1

Input:
43 178
50 50 100 100 100 50 100 100 50 100 100 100 50 100 50 100 50 50 100 100 50 100 100 50 50 50 100 50 50 50 100 50 100 100 100 50 100 50 50 50 50 100 100

Output:
63
503334985

Input:
33 226
50 50 50 50 50 100 100 100 100 50 100 50 100 50 100 50 100 100 50 50 50 100 100 50 50 100 50 100 50 100 50 50 50

Output:
31
370884215

Input:
1 2994
100

Output:
1
1

Input:
1 204
50

Output:
1
1

Input:
33 123
50 100 100 100 50 100 50 50 50 50 50 100 100 50 100 50 100 50 50 50 50 50 50 50 100 100 50 50 100 100 100 100 100

Output:
93
337243149

Input:
34 2964
50 50 50 50 50 100 50 100 50 100 100 50 50 50 50 50 50 100 100 100 50 50 100 100 50 50 50 100 50 100 100 50 100 50

Output:
1
1

Input:
27 200
50 50 50 50 100 100 50 50 100 100 100 50 100 50 100 50 50 100 100 100 50 100 100 50 50 50 100

Output:
25
271877303

Input:
31 197
50 100 50 50 100 50 100 100 100 50 50 100 50 100 50 50 50 50 100 100 50 50 100 50 50 50 50 50 100 50 100

Output:
41
24368657

Input:
28 183
50 100 100 50 100 50 100 100 50 100 50 100 100 100 50 50 100 50 50 50 100 50 100 50 50 100 100 100

Output:
41
844409785

Input:
48 204
100 100 100 50 50 50 50 100 100 50 100 100 50 100 50 50 50 100 100 100 50 100 50 50 50 100 50 100 50 100 100 100 50 50 100 100 100 50 100 50 50 50 50 50 100 50 50 50

Output:
45
538567333

Input:
5 188
50 50 50 50 50

Output:
3
30

Input:
29 108
100 50 100 100 100 100 100 50 50 100 100 100 50 100 50 50 100 50 100 50 50 100 100 50 50 50 100 100 50

Output:
87
417423429

Input:
50 125
50 50 50 100 100 50 100 100 50 50 100 100 100 100 100 100 50 50 100 50 100 100 50 50 50 100 100 50 100 100 100 100 100 100 100 50 50 50 100 50 50 50 50 100 100 100 100 100 50 50

Output:
153
971933773

Input:
50 2263
50 100 50 100 50 100 100 100 50 50 50 100 100 100 100 100 100 50 50 100 50 100 50 50 100 50 50 100 100 50 100 100 100 50 50 50 100 50 100 50 50 50 50 50 100 100 50 50 100 50

Output:
3
211048352

Input:
50 110
50 100 100 50 50 50 50 50 50 50 100 100 50 100 50 50 50 50 100 50 100 100 100 100 50 100 100 100 100 50 50 50 50 50 100 100 50 100 50 100 100 50 50 100 50 100 50 50 100 100

Output:
143
105841088

Input:
50 185
100 50 50 50 50 50 100 50 100 50 100 100 50 50 100 100 100 50 50 100 50 100 50 50 100 100 100 100 100 50 50 100 100 100 50 100 50 100 50 50 100 50 100 50 50 100 50 50 100 100

Output:
73
930170107

Input:
50 207
50 100 100 100 100 50 100 100 100 50 100 100 100 50 100 100 50 100 50 100 50 100 100 100 50 100 50 50 100 50 100 100 50 100 100 100 100 50 100 100 100 100 50 50 50 100 100 50 100 100

Output:
55
833060250

Input:
3 49
50 50 50

Output:
-1
0

Input:
3 50
50 50 50

Output:
-1
0

Input:
3 99
100 50 50

Output:
-1
0

Input:
4 100
100 100 100 50

Output:
-1
0


The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.

#include<stdio.h>
int minimo(int a, int b);
int main(){
    int v[5], i, j, k, total = 0, min;
    for(i = 0; i < 5; i++){
        scanf("%d", &v[i]);
        total = total + v[i];
    }
    min = total;
    for(i = 0; i < 5; i++){
        for(j = i + 1; j < 5; j++){
            if(v[i] == v[j]){
                if(total - 2*v[i] < min)
                    min = total - 2*v[i];
            }
        }
    }
    for(i = 0; i < 5; i++){
        for(j = i + 1; j < 5; j++){
            for(k = j + 1; k < 5; k++){
                if(v[i] == v[j] && v[i] == v[k]){
                    if(total - 3*v[i] < min)
                    min = total - 3*v[i];
                }
            }
        }
    }
    printf("%d", min);
}

NoteIn the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.  Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.  Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.  Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34. You are asked to minimize the sum so the answer is 26.In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.

Print the minimum possible sum of numbers written on remaining cards.

A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?

Input: 7 3 7 3 20

Output: 26

Input: 7 9 3 1 8

Output: 28

Input: 10 10 10 10 10

Output: 20

Input: 8 7 1 8 7

Output: 15

Input: 7 7 7 8 8

Output: 16

Input: 8 8 8 2 2

Output: 4

Input: 8 8 2 2 2

Output: 6

Input: 5 50 5 5 60

Output: 110

Input: 100 100 100 100 100

Output: 200

Input: 1 1 1 1 1

Output: 2

Input: 29 29 20 20 20

Output: 58

Input: 20 29 20 29 20

Output: 58

Input: 31 31 20 20 20

Output: 60

Input: 20 20 20 31 31

Output: 60

Input: 20 31 20 31 20

Output: 60

Input: 20 20 20 30 30

Output: 60

Input: 30 30 20 20 20

Output: 60

Input: 8 1 8 8 8

Output: 9

Input: 1 1 1 8 1

Output: 9

Input: 1 2 3 4 5

Output: 15

Input: 100 99 98 97 96

Output: 490

Input: 1 1 100 100 100

Output: 2

Input: 100 100 99 99 98

Output: 296

Input: 98 99 100 99 100

Output: 296

Input: 1 90 1 91 1

Output: 181

Input: 60 1 75 1 92

Output: 227

Input: 15 40 90 40 90

Output: 95

Input: 1 1 15 20 20

Output: 17

Input: 90 11 11 10 10

Output: 110

Input: 20 21 22 23 24

Output: 110

Input: 1 1 2 98 99

Output: 199

Input: 3 7 7 7 10

Output: 13

Input: 1 3 3 3 1

Output: 2

Input: 1 9 9 9 10

Output: 11

Input: 100 1 1 1 1

Output: 101

Input: 2 2 2 100 100

Output: 6

Input: 1 2 2 2 2

Output: 3

Input: 1 1 2 2 5

Output: 7

Input: 1 2 3 4 1

Output: 9

Input: 11 10 10 10 10

Output: 21

Input: 2 2 2 10 10

Output: 6

Input: 1 1 1 1 4

Output: 5

Input: 98 98 98 98 23

Output: 121

Input: 1 2 3 100 100

Output: 6

Input: 2 2 5 10 10

Output: 9

Input: 2 2 3 3 3

Output: 4

Input: 1 1 1 1 2

Output: 3

Input: 12 12 7 7 7

Output: 21


The first line contains four space-separated integers — x1, x2, a and b (x1 ≠ x2, a ≤ b,  - 109 ≤ x1, x2, a, b ≤ 109) — coordinates of the points where the first and the second participant start, and the numbers that determine the players' moves, correspondingly.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,k,l,m,n;
  int x1, x2, a, b, fg, fgg;
  int mod;
  int stone;

  while(scanf("%d%d%d%d",&x1,&x2,&a,&b)==4){
    stone = x2 - x1;
    fg = 0;
    if(stone < 0) stone *= -1, k = a, a = b, b = k, a *= -1, b *= -1, fg = 1;
    if(b <= 0){ puts("DRAW"); continue; }

    fgg = 0;
    if(a <= 0) fgg = 1, a = 1;
    mod = stone % (a+b);
    if(mod == 0){
      if(fgg) puts("DRAW"); else puts("SECOND");
      continue;
    }
    if(mod < a || mod > b){
      puts("DRAW");
      continue;
    }

    if(stone > b && fgg){
      puts("DRAW");
      continue;
    }

    stone -= mod;
    puts("FIRST");
    if(fg==0) printf("%d\n",x2-stone);
    else      printf("%d\n",x2+stone);
  }

  return 0;
}

NoteIn the first sample the first player can win in one move.In the second sample the first participant must go to point 1, where the second participant immediately goes and wins. In the third sample changing the position isn't profitable to either participant, so nobody wins.

On the first line print the outcome of the battle as "FIRST" (without the quotes), if both players play optimally and the first player wins. Print "SECOND" (without the quotes) if the second player wins and print "DRAW" (without the quotes), if nobody is able to secure the victory. If the first player wins, print on the next line the single integer x — the coordinate of the point where the first player should transfer to win. The indicated move should be valid, that is, it should meet the following condition: x1 + a ≤ x ≤ x1 + b. If there are several winning moves, print any of them. If the first participant can't secure the victory, then you do not have to print anything.

The King of Flatland will organize a knights' tournament! The winner will get half the kingdom and the favor of the princess of legendary beauty and wisdom. The final test of the applicants' courage and strength will be a fencing tournament. The tournament is held by the following rules: the participants fight one on one, the winner (or rather, the survivor) transfers to the next round.Before the battle both participants stand at the specified points on the Ox axis with integer coordinates. Then they make moves in turn. The first participant moves first, naturally. During a move, the first participant can transfer from the point x to any integer point of the interval [x + a; x + b]. The second participant can transfer during a move to any integer point of the interval [x - b; x - a]. That is, the options for the players' moves are symmetric (note that the numbers a and b are not required to be positive, and if a ≤ 0 ≤ b, then staying in one place is a correct move). At any time the participants can be located arbitrarily relative to each other, that is, it is allowed to "jump" over the enemy in any direction. A participant wins if he uses his move to transfer to the point where his opponent is.Of course, the princess has already chosen a husband and now she wants to make her sweetheart win the tournament. He has already reached the tournament finals and he is facing the last battle. The princess asks the tournament manager to arrange the tournament finalists in such a way that her sweetheart wins the tournament, considering that both players play optimally. However, the initial location of the participants has already been announced, and we can only pull some strings and determine which participant will be first and which one will be second. But how do we know which participant can secure the victory? Alas, the princess is not learned in the military affairs... Therefore, she asks you to determine how the battle will end considering that both opponents play optimally. Also, if the first player wins, your task is to determine his winning move.

Input: 0 2 0 4

Output:
FIRST
2

Input: 0 2 1 1

Output: SECOND

Input: 0 2 0 1

Output: DRAW

Input: 3 1 -2 2

Output:
FIRST
1

Input: 3 10 1 6

Output: SECOND

Input: 1 2 2 2

Output: DRAW

Input: 0 10 -1 1

Output: DRAW

Input: 0 15 5 5

Output:
FIRST
5

Input: 20 1 -5 -1

Output:
FIRST
19

Input: 0 100 2 31

Output: DRAW

Input: 31 39 0 8

Output:
FIRST
39

Input: 75 37 9 33

Output: DRAW

Input: -44 -17 12 13

Output: DRAW

Input: -80 60 17 23

Output:
FIRST
-60

Input: -343 -119 -194 -60

Output: DRAW

Input: 439 722 206 325

Output:
FIRST
722

Input: 1621 733 -732 -156

Output: SECOND

Input: 2062 4167 2 2

Output: DRAW

Input: 45390 21963 -2047 -1023

Output:
FIRST
43453

Input: 258358 241272 -2 -1

Output:
FIRST
258357

Input: 965398 678942 -6666 -666

Output: DRAW

Input: 1234577 1234573 -3 3

Output: DRAW

Input: -186611 -745388 -776721 -308073

Output:
FIRST
-745388

Input: 2408736 -3517525 413342 557733

Output: DRAW

Input: -8006393 7731100 -478756 3592795

Output: DRAW

Input: -48549196 47782227 17235 109857

Output: DRAW

Input: 61190539 -40142693 -666666 -666666

Output: SECOND

Input: 25882413 -80674370 -999999 -9

Output:
FIRST
25326478

Input: 48011031 230545656 12345 67890

Output: SECOND

Input: -730305467 -514687698 2 7

Output: DRAW

Input: 411443207 739161876 -1 0

Output: DRAW

Input: 402211447 260733897 -52 275

Output: DRAW

Input: 35406031 214492689 -307333182 -305473200

Output: DRAW

Input: 44789577 44789576 -1 0

Output:
FIRST
44789576

Input: 434676805 434676075 -878 345

Output:
FIRST
434676075

Input: 547686188 61562151 -496372503 -115242932

Output:
FIRST
61562151

Input: 775517456 -869957101 -1 -1

Output:
FIRST
775517455

Input: 637107829 -403198378 -2 -2

Output: DRAW

Input: -318865784 794140986 2 3

Output: SECOND

Input: 999763526 -998481439 -815 -157

Output:
FIRST
999762965

Input: 416100128 -709112339 -190811 -190811

Output:
FIRST
415909317

Input: 183003032 -631999413 -1000002 -1

Output: SECOND

Input: 847094637 -152905363 -1000000000 -1000000000

Output:
FIRST
-152905363

Input: -1000000000 1000000000 1 1

Output: SECOND

Input: -1000000000 1000000000 0 0

Output: DRAW

Input: 1000000000 999999999 -1000000000 -2

Output: DRAW

Input: 0 1 -1000000000 1000000000

Output:
FIRST
1

Input: -1000000000 1000000000 1230987 9871231

Output:
FIRST
-998399240

Input: -1000000000 1000000000 0 1000000000

Output: DRAW

Input: -1000000000 1000000000 1 999999999

Output: SECOND

Input: -1000000000 1000000000 499999999 500000000

Output: DRAW

Input: -1000000000 1000000000 1000000000 1000000000

Output: SECOND

Input: 1000000000 -1000000000 1000000000 1000000000

Output: DRAW

Input: 0 6 2 5

Output: DRAW


The first line contains two integers a and m (1 ≤ a, m ≤ 105).

#include <stdio.h>
int a,m,k,r;
int main() {
	scanf("%d",&a);
	scanf("%d",&m);
	r=a%m;
	while(k<20) {
		if(r%m==0) {
			printf("Yes\n");
			return 0;
		}
		else {
			r*=2;
			++k;
		}
	}
	printf("No\n");
	return 0;
}

Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".

One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce  (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory. The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m). Given the number of details a on the first day and number m check if the production stops at some moment.

Input: 1 5

Output: No

Input: 3 6

Output: Yes

Input: 1 8

Output: Yes

Input: 2 3

Output: No

Input: 3 24

Output: Yes

Input: 1 1

Output: Yes

Input: 100000 100000

Output: Yes

Input: 1 99989

Output: No

Input: 512 2

Output: Yes

Input: 100 24

Output: No

Input: 1 100000

Output: No

Input: 100000 1

Output: Yes

Input: 3 99929

Output: No

Input: 99961 99971

Output: No

Input: 1 65536

Output: Yes

Input: 4 65536

Output: Yes

Input: 3 65536

Output: Yes

Input: 32768 65536

Output: Yes

Input: 65535 65536

Output: Yes

Input: 1 65535

Output: No

Input: 98812 100000

Output: No

Input: 10 5

Output: Yes

Input: 6 8

Output: Yes


The input contains the only integer n (1 ≤ n ≤ 106).

#include <stdio.h>

int gcm(int a, int b) // a<=bであること．
{
    if(a == 0)
        return b;
    else
        return gcm(b%a, a);
}

int rec(int a, int b) // a<bであること．
{
    if(a == 1)
        return b-1;
    return b/a + rec(b%a, a);
}

int main (int argc, const char * argv[]) {
    int i, a, b, min;
    scanf("%d", &a);
    min = a-1;
    for(i = 2; i <= a/2; i++){
        if(gcm(a, i) != 1)
            continue;
        if((b = rec(i, a)) < min)
            min = b;
    }
    printf("%d\n", min);
    return 0;
}

NoteThe pair (1,1) can be transformed into a pair containing 5 in three moves: (1,1)  →  (1,2)  →  (3,2)  →  (5,2).

Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step.Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n.


A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).

#include <math.h>
#include <float.h>
#include <stdio.h>
#include <stdlib.h>

int main (void) {
	int x, y, n, a = 0, b = 1, i, j;
	double t;
	scanf ("%d %d %d", &x, &y, &n);
	t = (double)x / y;
	for (j = 1; j <= n; ++j) {
		double A[] = {floor (t*j), ceil (t*j)};
		for (i = 0; (unsigned)i < sizeof A / sizeof *A; ++i) {
			if (fabs (t - A[i]/j) + DBL_EPSILON < fabs (t - (double)a/b)) {
				a = A[i];
				b = j;
			}
		}
	}
	printf ("%d/%d\n", a, b);
	exit (EXIT_SUCCESS);
}

Print the required fraction in the format "a/b" (without quotes).

You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction  whose denominator is no more than n. Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value  is as minimal as possible.If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.

Input: 3 7 6

Output: 2/5

Input: 7 2 4

Output: 7/2

Input: 1 1 1

Output: 1/1

Input: 1 2 1

Output: 0/1

Input: 1 2 2

Output: 1/2

Input: 17708 35362 1558

Output: 328/655

Input: 72657 93778 50943

Output: 38236/49351

Input: 1000 7 3

Output: 143/1

Input: 1000 11 20

Output: 1000/11

Input: 100000 2 100000

Output: 50000/1

Input: 99999 2 1

Output: 49999/1

Input: 38133 49787 9840

Output: 3295/4302

Input: 76730 91851 71438

Output: 49039/58703

Input: 7487 17563 1102

Output: 107/251

Input: 46084 75979 30535

Output: 11637/19186

Input: 60489 34395 34632

Output: 20163/11465

Input: 91245 43755 27191

Output: 6083/2917

Input: 29842 2171 245

Output: 811/59

Input: 44247 27883 24673

Output: 34667/21846

Input: 89781 34400 19222

Output: 49972/19147

Input: 36890 92817 22772

Output: 5951/14973

Input: 75486 2177 1983

Output: 58877/1698

Input: 6243 60593 42244

Output: 3565/34601

Input: 20648 86305 73795

Output: 15543/64967

Input: 59245 44721 45425

Output: 59245/44721

Input: 90002 86785 57380

Output: 23109/22283

Input: 28598 12497 10464

Output: 23710/10361

Input: 43003 70913 71178

Output: 43003/70913

Input: 14304 96625 53803

Output: 7934/53595

Input: 35646 27334 23417

Output: 17823/13667

Input: 99997 99999 99996

Output: 49999/50000

Input: 100000 10 10

Output: 10000/1

Input: 7 6 3

Output: 1/1


The first line contains the integer n (2 ≤ n ≤ 109). The second line contains the integer k (0 ≤ k < 1060), it is guaranteed that the number k contains no more than 60 symbols. All digits in the second line are strictly less than n. Alexander guarantees that the answer exists and does not exceed 1018. The number k doesn't contain leading zeros.

#include <stdio.h>
#include <string.h>

#define INF	((long long) 1e18)

int main() {
	static char s[128];
	static long long dp[128][128];
	int n, h, i, j, l;
	long long min;

	scanf("%d", &n);
	scanf("%s", s);
	l = strlen(s);
	for (i = 0; i <= l; i++)
		for (j = 0; j <= l; j++)
			dp[i][j] = INF;
	dp[0][0] = 0;
	for (i = 0; i < l; i++)
		for (j = 0; j < l; j++)
			if (dp[i][j] < INF) {
				long long x = dp[i][j];

				if (s[i] == '0') {
					if ((double) x * n <= INF)
						if (dp[i + 1][j + 1] > x * n)
							dp[i + 1][j + 1] = x * n;
				} else {
					long long y = 0;

					for (h = i; h < l; h++) {
						y = y * 10 + (s[h] - '0');
						if (y >= n)
							break;
						if ((double) x * n + y <= INF)
							if (dp[h + 1][j + 1] > x * n + y)
								dp[h + 1][j + 1] = x * n + y;
					}
				}
			}
	min = INF;
	for (j = 0; j <= l; j++)
		if (min > dp[l][j])
			min = dp[l][j];
	printf("%lld\n", min);
	return 0;
}

NoteIn the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·130 or 15 = 1·131 + 2·130.

Print the number x (0 ≤ x ≤ 1018) — the answer to the problem.

Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475 = 1·162 + 13·161 + 11·160). Alexander lived calmly until he tried to convert the number back to the decimal number system.Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k.

Input:
13
12

Output: 12

Input:
16
11311

Output: 475

Input:
20
999

Output: 3789

Input:
17
2016

Output: 594

Input:
1000
1001

Output: 100001

Input:
1000
1000

Output: 100000

Input:
2
110111100000101101101011001110100111011001000000000000000000

Output: 1000000000000000000

Input:
500
29460456244280453288

Output: 467528530570226788

Input:
1000000000
17289468142098080

Output: 17289468142098080

Input:
123
7719

Output: 9490

Input:
25
2172214240

Output: 26524975

Input:
2
1110110101111000010001011110101001011001110000000010111010

Output: 267367244641009850

Input:
3
1210020121011022121222022012121212020

Output: 268193483524125978

Input:
4
32323300000100133222012211322

Output: 269019726702209402

Input:
5
4230423222300004320404110

Output: 269845965585325530

Input:
6
20201051430024130310350

Output: 270672213058376250

Input:
7
325503632564034033331

Output: 271498451941492378

Input:
8
17073735641412635372

Output: 272324690824608506

Input:
9
1733607167155630041

Output: 273150934002691930

Input:
10
996517375802030516

Output: 996517375802030516

Input:
11
1107835458761401923

Output: 997343614685146644

Input:
20
905191218118181710131111

Output: 738505167292405431

Input:
50
303521849112318129

Output: 59962796634170079

Input:
100
7226127039816418

Output: 7226127039816418

Input:
1000
839105509657869885

Output: 839105509657869885

Input:
7501
2542549323761022905

Output: 805176557484307547

Input:
10981
5149151039259677113

Output: 748054672922159638

Input:
123358
458270676485260235

Output: 860152492903254335

Input:
2567853
5247911636981396703

Output: 346042641011647808

Input:
56132425
3102369282985322

Output: 10027171005317597

Input:
378135456
42831383491941211

Output: 582652156959951259

Input:
3
110021012201002100122001102110010002

Output: 68193483524125904

Input:
23
12007622911918220

Output: 1781911903273803

Input:
456
82103391245145170

Output: 1621222691867186

Input:
7897
14412516641926184

Output: 6062228032315859

Input:
23156
27612518525717145

Output: 3433598652149101

Input:
467879
333380108424158040

Output: 72980519445207316

Input:
7982154
129530518193255487

Output: 82535003403725833

Input:
21354646
47160699363858581

Output: 21776150370291089

Input:
315464878
113635473256292967

Output: 35848000882710261

Input:
1000000000
17289468142098026

Output: 17289468142098026

Input:
4
200002312103012003212121020

Output: 9019726702208584

Input:
46
342836241940392925

Output: 694167817136539

Input:
145
357987665524124

Output: 330396354354854

Input:
1344
2498394521019605

Output: 814487257688093

Input:
57974
3619236326439503

Output: 7079242212325439

Input:
215467
2082791630100848

Output: 966934630351661

Input:
7956123
6718643712272358

Output: 4255926011071634

Input:
13568864
2513398972677784

Output: 4621032639107192

Input:
789765212
1039927282755769

Output: 821298450375293

Input:
1000000000
7289468142097485

Output: 7289468142097485

Input:
5
22011100004310232330

Output: 45965585242840

Input:
98
11291073236468

Output: 10007394522984

Input:
364
284155255182196

Output: 4993183241788

Input:
8742
111445644633405

Output: 74498130012303

Input:
11346
573275516211238

Output: 83675287784142

Input:
442020
13825031303078

Output: 26973736400898

Input:
1740798
321470190942028

Output: 99531390411376

Input:
25623752
25636131538378

Output: 65689385274354

Input:
814730652
56899767577002

Output: 46358126945150

Input:
6
5543321344052

Output: 12975669536

Input:
79
9653454753

Output: 27953623755

Input:
158
25832612364

Output: 15908078858

Input:
1675
11480678916

Output: 8852883441

Input:
12650
25380755475

Output: 40587846725

Input:
165726
465015206

Output: 770641106

Input:
2015054
30501583737

Output: 6147498437

Input:
98000000
19440834812

Output: 19052834812

Input:
157137373
525141766938

Output: 82638887763

Input:
7
441214552

Output: 26508694

Input:
294
2251151163

Output: 72564361

Input:
2707
11341512

Output: 3071250

Input:
76559
100147383

Output: 76682942

Input:
124849
6172319

Output: 7688108

Input:
7014809
73084644

Output: 52188307

Input:
10849219
65200749

Output: 70296063

Input:
905835986
371320

Output: 371320

Input:
1000000000
69204007

Output: 69204007

Input:
8
2670

Output: 1464

Input:
25
71610

Output: 4785

Input:
1468
21107

Output: 4043

Input:
5723
4907

Output: 4907

Input:
251546
7278

Output: 7278

Input:
9
78

Output: 71

Input:
13
41

Output: 53

Input:
34
13

Output: 13

Input:
45
22

Output: 22

Input:
67
29

Output: 29

Input:
130
100

Output: 100

Input:
2
1

Output: 1

Input:
4
1

Output: 1

Input:
9
3

Output: 3

Input:
13
9

Output: 9

Input:
3215
3

Output: 3

Input:
1000000000
6

Output: 6

Input:
2
0

Output: 0

Input:
1000000000
0

Output: 0

Input:
378
1378

Output: 4992

Input:
378
380378377

Output: 65568783041

Input:
2
10000000000000000000000000

Output: 33554432

Input:
2
10000000000000000000000000000

Output: 268435456

Input:
2
100000000000000000000000

Output: 8388608


The single line contains two integers r, h (1 ≤ r, h ≤ 107).

#include<stdio.h>
#include<math.h>
int r,h,vol;
int main()
{
	scanf(" %d %d",&r,&h);

	vol = h / r * 2;
	h %= r;
	if (2*h<r)
		vol++;
	else if(h*2 >= sqrt(3)*r)
		vol += 3;
	else
		vol += 2;
	printf("%d",vol);
	return 0;
}

Print a single integer — the maximum number of balloons Xenia can put in the cupboard.

A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupboard's depth is r, that is, it looks like a rectangle with base r and height h + r from the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right).  Xenia got lots of balloons for her birthday. The girl hates the mess, so she wants to store the balloons in the cupboard. Luckily, each balloon is a sphere with radius . Help Xenia calculate the maximum number of balloons she can put in her cupboard. You can say that a balloon is in the cupboard if you can't see any part of the balloon on the left or right view. The balloons in the cupboard can touch each other. It is not allowed to squeeze the balloons or deform them in any way. You can assume that the cupboard's walls are negligibly thin.

Input: 1 1

Output: 3

Input: 1 2

Output: 5

Input: 2 1

Output: 2

Input: 2 2

Output: 3

Input: 2 3

Output: 4

Input: 4 1

Output: 1

Input: 5 1

Output: 1

Input: 5 2

Output: 1

Input: 5 3

Output: 2

Input: 5 4

Output: 2

Input: 5 5

Output: 3

Input: 5 6

Output: 3

Input: 5 9

Output: 4

Input: 5 10

Output: 5

Input: 5 11

Output: 5

Input: 674098 1358794

Output: 5

Input: 3983458 7761504

Output: 5

Input: 4841874 9131511

Output: 5

Input: 667586 5534221

Output: 17

Input: 1526002 6904227

Output: 10

Input: 4835362 5823289

Output: 3

Input: 5693778 7001807

Output: 3

Input: 6552194 8371814

Output: 3

Input: 2377906 4774524

Output: 5

Input: 4365659 4738707

Output: 3

Input: 98 1358794

Output: 27731

Input: 458 7761504

Output: 33894

Input: 874 9131511

Output: 20897

Input: 586 5534221

Output: 18889

Input: 2 6904227

Output: 6904228

Input: 1 10000000

Output: 20000001

Input: 2 10000000

Output: 10000001

Input: 3 10000000

Output: 6666667

Input: 4 10000000

Output: 5000001

Input: 3 9999999

Output: 6666667

Input: 10000000 866254

Output: 1

Input: 10000000 8660255

Output: 3

Input: 100 50

Output: 2

Input: 100 49

Output: 1

Input: 100 199

Output: 5

Input: 8 7

Output: 3

Input: 10000 9999

Output: 3

Input: 1000000 1999999

Output: 5

Input: 2000000 1999999

Output: 3

Input: 18 16

Output: 3

Input: 100 87

Output: 3

Input: 10 19

Output: 5

Input: 10000 38661

Output: 9


The first line contains two integers a, ta (1 ≤ a, ta ≤ 120) — the frequency of the buses from the city A to the city B and the travel time. Both values are given in minutes. The second line contains two integers b, tb (1 ≤ b, tb ≤ 120) — the frequency of the buses from the city B to the city A and the travel time. Both values are given in minutes. The last line contains the departure time of Simion from the city A in the format hh:mm. It is guaranteed that there are a bus from the city A at that time. Note that the hours and the minutes are given with exactly two digits.

#include<stdio.h>
int main()
{
	int a,ta;
	scanf("%d%d",&a,&ta);
	int b,tb;
	scanf("%d%d",&b,&tb);
	int h,m;
	scanf("%d:%d",&h,&m);
	int x,y,w=0,z=300;
	x=60*h+m;
	y=60*h+m+ta;
	jump:
		if(z+tb<x)
		{
			z=z+b;
			goto jump;
		}
		else if(z+tb>x && z<y && z<1440)
		{
			w+=1;
			z=z+b;
			goto jump;
		}
		else if(z>y)
		{
			goto temp;
		}
		else if(z+tb==x || z==y)
		{
			z=z+b;
			goto jump;
		}
		temp:
		printf("%d\n",w);
	return 0;
}

NoteIn the first example Simion departs form the city A at 05:20 AM and arrives to the city B at 05:50 AM. He will meet the first 5 buses from the city B that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city B at 05:50 AM, but he will not count it.Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed).

Print the only integer z — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities A and B.

Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a minutes and arrives to the city B in a ta minutes, and a bus from the city B departs every b minutes and arrives to the city A in a tb minutes.The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish.You know the time when Simion departed from the city A to the city B. Calculate the number of buses Simion will meet to be sure in his counting.

Input:
10 30
10 35
05:20

Output: 5

Input:
60 120
24 100
13:00

Output: 9

Input:
30 60
60 60
22:30

Output: 2

Input:
30 60
10 60
23:30

Output: 8

Input:
5 45
4 60
21:00

Output: 26

Input:
1 1
1 1
10:28

Output: 1

Input:
4 1
5 4
18:40

Output: 1

Input:
8 8
1 1
13:24

Output: 8

Input:
20 4
1 20
06:20

Output: 23

Input:
15 24
23 6
21:15

Output: 1

Input:
30 19
21 4
10:30

Output: 1

Input:
31 15
36 25
07:04

Output: 1

Input:
24 3
54 9
18:12

Output: 0

Input:
18 69
62 54
08:00

Output: 2

Input:
33 58
70 78
22:36

Output: 2

Input:
68 34
84 78
10:40

Output: 1

Input:
15 14
32 65
05:45

Output: 2

Input:
40 74
100 42
05:40

Output: 2

Input:
65 49
24 90
07:10

Output: 6

Input:
1 1
1 1
23:59

Output: 1

Input:
23 118
118 20
23:24

Output: 0

Input:
3 88
17 38
22:33

Output: 8

Input:
3 1
2 3
05:03

Output: 1

Input:
1 1
3 2
08:44

Output: 0

Input:
1 3
1 2
21:43

Output: 4

Input:
2 28
2 12
05:12

Output: 19

Input:
60 120
17 120
23:00

Output: 11

Input:
1 55
1 54
23:59

Output: 54

Input:
66 75
1 82
06:06

Output: 141

Input:
1 90
1 88
23:59

Output: 88

Input:
1 120
1 100
23:59

Output: 100


The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.  It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.

NoteIn the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.

Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.

Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.   Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (r, c) the cell located at the row r and at the column c.There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.Moving upward means that the pawn located in (r, c) will go to the cell (r - 1, c), while moving down means the pawn located in (r, c) will go to the cell (r + 1, c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.

Input:
........
........
.B....B.
....W...
........
..W.....
........
........

Output: A

Input:
..B.....
..W.....
......B.
........
.....W..
......B.
........
........

Output: B

Input:
.BB.B.B.
B..B..B.
.B.BB...
BB.....B
BBB....B
B..BB...
BB.B...B
....WWW.

Output: B

Input:
..BB....
........
WW.W..WW
W...W...
.W...W..
.W..W.WW
W.....WW
WW......

Output: A

Input:
BB....B.
B.....B.
.....B..
..B...BB
.W.BWBWB
....W...
WW.WWW..
....W...

Output: B

Input:
B.B.BB.B
W.WWW.WW
.WWWWW.W
W.BB.WBW
.W..BBWB
BB.WWBBB
.W.W.WWB
WWW..WW.

Output: A

Input:
BB..BB..
BW.W.W.B
..B.....
.....BB.
.B..B..B
........
...BB.B.
W.WWWW.W

Output: A

Input:
BB......
W....BBW
........
.B.B.BBB
....BB..
B....BB.
...WWWW.
....WW..

Output: A

Input:
.B.B..B.
B.B....B
...B.B.B
..B.W..B
.BBB.B.B
B.BB.B.B
BB..BBBB
W.W.W.WW

Output: B

Input:
..BB....
.B.B.B.B
..B.B...
..B..B.B
WWWBWWB.
.BB...B.
..BBB...
......W.

Output: B

Input:
..BB....
.WBWBWBB
.....BBB
..WW....
.W.W...W
WWW...W.
.W....W.
W...W.W.

Output: A

Input:
B...BB..
WWBBW.BB
.W.W....
WWWW....
W....W..
W..WW...
...W....
WW.W....

Output: A

Input:
B..BB..B
..B.B...
BW..BBW.
...B.BBB
.B..BB..
..B.B.BB
........
........

Output: A

Input:
....BB..
BB......
.B.....B
WW..WWW.
...BB.B.
B...BB..
..W..WWW
...W...W

Output: B

Input:
B...BBBB
...BBB..
BBWBWW.W
.B..BB.B
W..W..WW
W.WW....
........
WW.....W

Output: A

Input:
.BB..B..
.B.....B
.B......
.B...B..
.......B
.WWB.WWB
W.....W.
...W....

Output: B

Input:
.B......
.B....B.
...W....
......W.
W.WWWW.W
W.WW....
..WWW...
..W...WW

Output: A

Input:
B.......
BBB.....
.B....B.
.W.BWB.W
......B.
W..WW...
...W....
W...W..W

Output: A

Input:
.B......
.B...B.B
.B..B.BB
W.......
..W.....
..WWW...
.......W
........

Output: A

Input:
.....B..
........
........
.BB..B..
..BB....
........
....WWW.
......W.

Output: B

Input:
B.B...B.
...BBBBB
....B...
...B...B
B.B.B..B
........
........
WWW..WW.

Output: B

Input:
B.B...B.
........
.......B
.BB....B
.....W..
.W.WW.W.
...W.WW.
W..WW..W

Output: A

Input:
......B.
B....B..
...B.BB.
...B....
........
..W....W
WW......
.W....W.

Output: B

Input:
.BBB....
B.B.B...
B.BB.B..
B.BB.B.B
........
........
W.....W.
..WW..W.

Output: B

Input:
..B..BBB
........
........
........
...W.W..
...W..W.
W.......
..W...W.

Output: A

Input:
........
.B.B....
...B..BB
........
........
W...W...
W...W...
W.WW.W..

Output: A

Input:
...B..BB
.B..B..B
........
........
........
W..W....
.....WW.
.W......

Output: A

Input:
B....BB.
...B...B
.B......
........
........
........
........
....W..W

Output: B

Input:
...BB.BB
BB...B..
........
........
........
........
..W..W..
......W.

Output: A

Input:
...BB...
........
........
........
........
........
......W.
WW...WW.

Output: A

Input:
...B.B..
........
........
........
........
........
........
WWW...WW

Output: A

Input:
BBBBBBB.
........
........
........
........
........
........
.WWWWWWW

Output: A

Input:
.BBBBBB.
B.......
........
........
........
........
........
.WWWWWWW

Output: B

Input:
.BBBBBBB
........
........
........
........
........
........
WWWWWWW.

Output: A

Input:
.BBBBBB.
.......B
........
........
........
........
........
WWWWWWW.

Output: B

Input:
B..BB...
..B...B.
.WBB...B
BW......
W.B...W.
..BBW.B.
BW..BB..
......W.

Output: B

Input:
BBB.BBBB
WB.W..B.
BBBB...B
B..B....
.......W
.BWB..BB
B..BW.BW
.W......

Output: A

Input:
B.BBBBBB
B..BBB.B
W.BB.W.B
B.BWBB.B
BWBWBBBB
...BBBBB
B.B...BB
WW..WW.W

Output: B

Input:
BBBB.BBB
BBBB.B.B
B.B..BBB
B.BB.BWW
B.BB.BBB
B.BB.BBB
..BW.BB.
W.WWWWWW

Output: B

Input:
BBBB.BBB
.B....WB
BB.B...B
WWWW.WWB
BB...BWW
WWW..BBB
W.BW.BB.
WWWWWWW.

Output: B

Input:
B.BBBBBB
W.WWBBBW
W.BB.WBB
W.W.BBBW
W.BWW.WB
B..B..BB
B.B.W.BB
WWWWW.WW

Output: B

Input:
BBBBBB.B
.BBWBB.B
WWW..B.W
..WW.W.W
BWB..W.W
..BW.B.W
B..B....
WWWW.WWW

Output: B

Input:
.B...BB.
WBB.BWBB
.BWBW...
..W...B.
WB.BWW..
WBW.....
.W..W.B.
.W.W.WW.

Output: A

Input:
.B..BBBB
BB...WWB
B..B.W.B
WB.W...B
...W.WW.
W.....W.
WB.W.W.W
.WW...WW

Output: A

Input:
B.BBBBBB
W.BB.W.B
W.BBW...
..WWWW.B
....W..B
.WW.W..W
.W..WW.W
W.W....W

Output: A

Input:
........
.......W
........
........
........
........
.......B
........

Output: A

Input:
..B.....
..W.....
.W....B.
........
.B...W..
......B.
.W......
........

Output: A

Input:
........
B.......
........
........
........
........
.......W
........

Output: A

Input:
........
........
........
.W......
......B.
........
........
........

Output: A

Input:
........
B.......
W.......
.......B
........
........
........
...W....

Output: B

Input:
........
.B......
.W......
........
....B...
........
........
.......W

Output: B

Input:
........
..B.....
..W...B.
........
.....W..
......B.
........
........

Output: B

Input:
........
W.......
........
........
........
........
.......B
........

Output: A

Input:
........
........
........
........
W.......
B.......
........
........

Output: B

Input:
........
........
.W......
........
........
........
.B......
........

Output: B

Input:
........
B.......
W.......
.W......
........
B.......
........
........

Output: B


Input will begin with an integer N (1 ≤ N ≤ 50), the number of slices of pie.  Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.

#include<stdio.h>

int max(int a,int b)
{
if(a>=b)return a;
else return b;
}
int main()
{
int ca[52];
int n;scanf("%d",&n);
int sumi[52];
int sum=0;
int dp[52]={-1};

int i=0;
for(i=0;i<n;i++)
{
scanf("%d",&ca[i]);
sum += ca[i];
sumi[i] = sum;
}
dp[n-1]=ca[n-1];

for(i=n-2;i>=0;i--)
{
dp[i]=max((ca[i]+(sumi[n-1]-dp[i+1]-sumi[i])),dp[i+1]);

}

int ans = dp[0];
int ans1 = sumi[n-1]-dp[0];

printf("%d %d\n",ans1,ans);

return 0;
}

NoteIn the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.

Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.

You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?

Input:
3
141 592 653

Output: 653 733

Input:
5
10 21 10 21 10

Output: 31 41

Input:
1
100000

Output: 0 100000

Input:
50
100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000

Output: 2500000 2500000

Input:
2
1 100000

Output: 1 100000

Input:
17
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536

Output: 65535 65536

Input:
15
3026 3027 4599 4854 7086 29504 38709 40467 40663 58674 61008 70794 77517 85547 87320

Output: 306375 306420

Input:
30
2351 14876 66138 87327 29940 73204 19925 50198 13441 54751 1383 92120 90236 13525 3920 16669 80637 94428 54890 71321 77670 57080 82145 39778 69967 38722 46902 82127 1142 21792

Output: 724302 724303

Input:
1
59139

Output: 0 59139

Input:
2
9859 48096

Output: 9859 48096

Input:
3
25987 64237 88891

Output: 88891 90224

Input:
4
9411 13081 2149 19907

Output: 19907 24641

Input:
5
25539 29221 6895 82089 18673

Output: 80328 82089

Input:
6
76259 10770 87448 3054 67926 81667

Output: 158428 168696

Input:
7
92387 35422 24898 32532 92988 84636 99872

Output: 192724 270011

Input:
8
8515 51563 5451 94713 9537 30709 63343 41819

Output: 138409 167241

Input:
9
91939 407 10197 24191 58791 9486 68030 25807 11

Output: 102429 186430

Input:
10
30518 96518 74071 59971 50121 4862 43967 73607 19138 90754

Output: 252317 291210

Input:
11
46646 21171 78816 89449 99375 50934 15950 90299 18702 62232 12657

Output: 288850 297381

Input:
12
30070 37311 92074 18927 91732 29711 12126 41583 52857 99118 73097 33928

Output: 296580 315954

Input:
13
13494 86155 96820 72596 40986 99976 16813 25571 87013 3301 832 26376 83769

Output: 325890 327812

Input:
14
96918 67704 10077 34778 90239 11457 80284 42263 53872 74779 93976 53416 83860 74518

Output: 414474 453667

Input:
15
13046 83844 14823 64255 15301 90234 84972 93547 88028 11665 54415 13159 83950 951 42336

Output: 362168 392358

Input:
16
29174 32688 95377 26437 64554 60498 56955 10239 22183 15847 47559 40199 92552 70488 4147 73082

Output: 370791 371188

Input:
17
79894 24637 8634 80107 81104 39275 53130 94227 56339 87326 7999 75751 92642 96921 74470 20999 69688

Output: 492038 551105

Input:
18
96022 73481 13380 42288 6166 85348 25113 78215 23198 24212 44246 35494 92733 66459 44793 68916 82818 3967

Output: 436157 470692

Input:
19
79446 55030 93934 39062 88123 88317 21289 62203 57354 28394 37390 95238 92823 92892 39308 16833 54733 51525 58759

Output: 538648 614005

Input:
20
5440 88704 61481 72140 15810 58854 43034 5150 80684 61360 50516 54301 78790 43678 46138 79893 89899 60260 2881 66499

Output: 506639 558873

Input:
21
21569 37548 74739 25809 65063 37631 71913 89138 47543 65542 10956 14045 78880 70111 73357 27810 70326 40523 899 6547 87440

Output: 506467 510922

Input:
22
72289 86393 79484 55287 14317 83704 11192 73126 81699 2429 4100 41085 87482 72352 10976 75727 42240 79569 31621 3492 51189 25936

Output: 513496 572193

Input:
23
88417 11045 92742 84765 6675 86673 40072 57114 15854 6611 40347 76636 87572 66082 38195 56348 89962 59831 29640 43541 14937 73713 52755

Output: 602650 616877

Input:
24
71841 27185 73295 46946 55928 65450 12055 73806 82714 78089 787 36380 87663 68323 75814 4265 94581 31581 51850 40486 11390 21491 27560 22678

Output: 560664 601494

Input:
25
87969 76030 78041 616 13694 11522 84038 25090 16869 14975 61226 96124 20457 62052 70329 76374 42303 11844 15276 37430 99330 77781 35069 64358 45168

Output: 586407 637558

Input:
26
71393 24874 91299 30093 62947 14491 80214 41782 51025 19158 21666 23163 20547 64293 40653 24291 46922 92106 13294 77479 63079 25559 42579 62933 24433 39507

Output: 569885 599895

Input:
27
54817 73719 96044 92275 12201 60564 84901 25770 17884 90636 14810 82907 20637 58023 10976 72208 94644 63856 11312 74424 26828 40632 58600 37316 38290 82420 48297

Output: 716531 728460

Input:
28
70945 22563 76598 21753 4558 39341 48372 77054 52039 27522 75249 18459 96536 60264 5491 20125 42367 44118 42034 38665 47472 88410 66109 78995 52147 68436 9814 71112

Output: 669482 697066

Input:
29
54369 14511 14048 83934 53812 75014 20356 17938 86195 31704 68393 78202 96626 86697 75814 746 46985 15868 40052 11417 11221 44700 40915 53378 98708 78644 4035 20164 37165

Output: 678299 683312

Input:
30
4555 13594 57403 75796 14203 12847 66292 60885 9525 40478 57327 69970 15297 37483 39540 31102 14855 412 84174 57684 65591 19837 80431 18385 3107 87740 15433 24854 73472 88205

Output: 620095 620382

Input:
31
20683 29734 37957 37978 63456 58920 70980 44873 76385 44661 17767 97009 15387 63916 77159 79019 86770 4866 14897 63141 86236 67614 87940 60064 16964 97948 9654 49714 30888 88075 63792

Output: 825663 838784

Input:
32
71403 78578 75406 67455 12710 37697 67155 28861 10540 48843 10911 56753 15477 33453 4378 26936 34492 19720 12915 27382 49984 91200 95449 34448 63525 83964 3875 98767 77905 63753 83018 58084

Output: 770578 774459

Input:
33
87531 27423 55960 53829 37771 40665 39138 12849 77399 53025 71350 83793 48271 59887 41997 74854 14919 24175 43637 24327 13733 38978 2959 319 10086 26876 65393 56332 68025 63623 93732 68354 83938

Output: 741185 823963

Input:
34
70955 19371 60706 50603 54321 86738 11122 29541 11555 57207 31790 19344 24170 29424 36512 22771 86833 4437 41655 64376 34378 19459 86276 74702 23943 69789 59614 48489 49634 63494 12958 11328 69333 1736

Output: 693927 744637

Input:
35
54379 920 41259 12784 3574 98219 40001 80825 45710 61390 24933 79088 24260 23153 6835 94880 67260 76187 39673 28616 98126 10341 26489 49085 37800 55805 86539 97542 39754 30660 32184 64703 11625 77872 63584

Output: 823487 862568

Input:
36
37803 17060 78709 42262 28636 68484 79280 97517 12570 98276 52669 6128 57054 58098 68646 75501 39174 56449 3099 1369 94579 58119 1295 90764 51657 66013 48056 55107 54066 30530 75602 74973 21212 21304 22589 4895

Output: 872694 876851

Input:
37
53932 65904 91967 4443 77890 47261 8160 81505 46725 69754 21621 65871 24440 51828 71673 23418 86896 4008 1117 65610 82519 5897 8804 65148 98218 76221 42277 79968 68379 30401 62125 61052 96207 64737 24698 99495 70720

Output: 989044 1011845

Input:
38
70060 14749 72520 58113 2951 26037 80143 32789 80881 73936 82060 92911 24531 78261 9292 71335 91515 8462 31839 62555 46268 29482 92121 31019 12075 94942 36498 96317 58499 30271 81351 71322 81602 8169 26807 69903 38154 20539

Output: 977736 1012543

Input:
39
20780 30889 9970 87591 19501 96302 76318 49481 47740 10823 42500 61167 57325 47798 36511 19252 39237 23316 29857 2603 10016 9964 99630 5402 82828 5150 98015 53882 72811 97437 57473 57400 91189 84305 85811 64503 40179 50614 52044

Output: 954593 973021

Input:
40
3670 5779 20621 87964 12595 34136 98063 92429 38366 43789 88330 52934 19100 22776 43342 82312 74404 64756 73980 14278 21283 85101 63339 70409 63034 14245 33606 58571 84927 14931 25355 15452 46072 4671 5838 69121 18243 87783 29748 84047

Output: 909877 959523

Input:
41
87094 21920 58071 41634 29145 45616 94239 76417 5226 47971 48770 79974 19190 25017 37857 30229 11726 12314 71998 54327 85032 8687 46656 12088 9595 24454 27827 7624 66535 14801 44581 25723 55659 48103 75242 39529 52973 17858 16985 41454 44182

Output: 799467 864856

Input:
42
70518 70764 38625 3816 78399 48585 66222 60405 72085 52153 85018 39717 51984 51451 8180 78146 59448 16768 2720 51272 48780 56464 21461 86471 23452 10470 22048 65189 56655 90480 31103 11801 73758 91536 10055 34129 20407 47933 4223 98861 84475 52291

Output: 1012190 1036128

Input:
43
86646 19609 43370 33293 3460 94658 95101 44393 6241 56335 78161 66757 52074 53692 2695 58767 31363 64326 738 15513 69425 4242 28971 60855 37309 53382 16269 57346 70968 90350 74522 22072 83345 67672 69060 4537 55137 78008 91461 32075 33280 70405 71607

Output: 1039942 1109548

Input:
44
70070 68453 23924 95475 52714 73435 34380 61085 40396 60518 38601 26501 52165 47421 73018 6684 79085 68781 31460 88265 33173 52020 44992 2534 8062 96295 77786 39103 85280 24812 93748 75446 92932 11105 71169 66433 89866 75379 11402 22186 73572 31624 70092 10734

Output: 1141992 1210184

Input:
45
53494 93105 37182 24953 1967 43700 39068 12369 7256 64700 31744 62052 84959 49662 34829 78793 51000 16339 29478 52506 96922 75606 52501 1109 21919 6503 72007 63964 75400 24682 45678 18420 67928 87241 73278 69545 24596 29646 65936 55401 89673 49738 35873 45189 3622

Output: 1052557 1068976

Input:
46
36918 9246 74631 78622 94325 22476 35243 96357 41411 68882 92184 21796 28153 43392 37856 26710 64130 20793 60200 16747 84862 23383 60010 42788 68480 92519 66229 56121 57009 24553 89096 4499 53323 30673 75386 31442 92030 59721 53173 45511 29966 67853 77462 12347 61811 81517

Output: 1199490 1212346

Input:
47
53046 58090 55185 8100 43578 1253 7226 13049 75567 73065 19920 48836 28243 45633 75475 74628 11853 68351 90922 89500 81315 71161 34816 49875 82337 2727 27746 37878 79833 24423 75618 82065 95614 82618 34391 1850 94056 57092 73115 70214 46067 29071 75947 46802 95807 42600 11211

Output: 1214201 1233568

Input:
48
69174 6934 59931 70281 68640 47326 3402 64333 42426 77247 13063 8579 61038 39362 2694 22545 83767 15909 88940 86445 45063 27451 18133 91555 28898 45640 21967 62738 61441 24293 19036 68144 5201 26050 69204 29154 85681 19871 60352 36133 86359 47186 74432 5448 53996 27876 58022 80559

Output: 1096672 1115247

Input:
49
19894 55779 73188 99759 17893 50295 8089 81025 76582 81429 73503 35619 61128 41603 40313 3166 31490 87660 19662 59197 8812 75229 25642 65938 42755 31656 16188 87599 51562 91460 38262 11118 90596 69482 71313 66858 87707 17242 14886 93539 35164 32596 83317 72606 12185 21664 80642 72099 7525

Output: 1233007 1259909

Input:
50
70081 97965 40736 24325 2476 20832 54026 23972 91400 47099 95141 27386 79799 49285 4039 818 23552 72203 55273 38168 52783 50365 89351 30945 47154 8047 27586 49184 20573 8953 38849 36466 45479 89848 82827 71475 74283 87115 92590 28903 97800 74550 74140 82514 10849 6786 67881 63456 53022 25051

Output: 1251581 1255820

Input:
4
10 3 2 1

Output: 4 12

Input:
6
5245 1414 21632 12159 31783 7412

Output: 38442 41203

Input:
46
1666 17339 9205 20040 30266 12751 11329 7951 9000 14465 11771 7600 19480 15993 19453 7470 1361 7922 27747 17347 4727 11280 403 16338 6064 11124 25723 18717 26118 271 9242 16952 26381 31795 28226 3646 27589 31472 30108 28354 25281 22429 30956 32264 14729 21685

Output: 379808 392222

Input:
3
100 90 80

Output: 90 180

Input:
5
10 9 8 7 6

Output: 16 24

Input:
4
100 40 50 10

Output: 50 150

Input:
6
5 4 3 2 1 1

Output: 7 9

Input:
33
30274 12228 26670 31244 5457 2643 27275 4380 30954 23407 8387 6669 25229 31591 27518 30261 25670 20962 31316 8992 8324 26216 10812 28467 15401 23077 10311 24975 14046 12010 11406 22841 7593

Output: 299163 327443

Input:
3
4 2 1

Output: 2 5

Input:
3
10 5 5

Output: 5 15

Input:
6
6 5 4 3 2 1

Output: 9 12

Input:
4
5 2 7 3

Output: 7 10


The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:    ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;  ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;  ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;  ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.

//DURING CONTEST: http://www.codeforces.com/contest/699/submission/19246509

#include <stdio.h>
#include <stdint.h>
int main() {
    /**
     * Variables are stored as follows:
     * whatWeCouldDoYesterday -- data & 0b11
     * whatWeCanDoToday       -- (data & 0b1100) >> 2
     * answer                 -- (data & 0xff00) >> 8
     * numDays                -- (data & 0xff0000) >> 16
     * todayCode              -- (data & 0xff000000) >> 24
    */

    //whatWeDidYesterday = whatWeCanDoToday = answer = numDays = todayCode = 0;
    uint32_t data = 0;
    //scanf("%i", &numDays);
    scanf("%hhi", ((signed char*)&data)+2);
    //whatWeCouldDoYesterday = 3;
    data += 3;
    //while ((numDays -= 1), numDays+1) {
    while ((data -= 0x10000), ((data+0x10000) & 0xff0000) >> 16) {
        //scanf("%i", &todayCode);
        scanf("%hhi", ((signed char*)&data)+3);
        //if ((whatWeCouldDoYesterday & 2) && (todayCode & 1)) whatWeCanDoToday += 1;
        if ((data & 2) && (data & 0x1000000) >> 24) data += 1 << 2;
        //if ((whatWeCouldDoYesterday & 1) && (todayCode & 2)) whatWeCanDoToday += 2;
        if ((data & 1) && (data & 0x2000000) >> 24) data += 2 << 2;
        //if (!whatWeCanDoToday) answer += 1, whatWeCanDoToday = 3;
        if (!(data & 0b1100)) data += 1 << 8, data += 3 << 2;
        //whatWeCouldDoYesterday = whatWeCanDoToday, whatWeCanDoToday = 0;
        *((signed char*)&data) >>= 2;
    }
    //printf("%i\n", answer);
    printf("%li\n", (data & 0xff00) >> 8);
}

NoteIn the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.

Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:   to do sport on any two consecutive days,  to write the contest on any two consecutive days.

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:  on this day the gym is closed and the contest is not carried out;  on this day the gym is closed and the contest is carried out;  on this day the gym is open and the contest is not carried out;  on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

Input:
4
1 3 2 0

Output: 2

Input:
7
1 3 3 2 1 2 3

Output: 0

Input:
2
2 2

Output: 1

Input:
1
0

Output: 1

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

Output: 8

Input:
100
3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3

Output: 16

Input:
10
2 3 0 1 3 1 2 2 1 0

Output: 3

Input:
45
3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3

Output: 6

Input:
1
1

Output: 0

Input:
1
2

Output: 0

Input:
1
3

Output: 0

Input:
2
1 1

Output: 1

Input:
2
1 3

Output: 0

Input:
2
0 1

Output: 1

Input:
2
0 0

Output: 2

Input:
2
3 3

Output: 0

Input:
3
3 3 3

Output: 0

Input:
2
3 2

Output: 0

Input:
2
0 2

Output: 1

Input:
10
2 2 3 3 3 3 2 1 3 2

Output: 2

Input:
15
0 1 0 0 0 2 0 1 0 0 0 2 0 0 0

Output: 11

Input:
15
1 3 2 2 2 3 3 3 3 2 3 2 2 1 1

Output: 4

Input:
15
3 1 3 2 3 2 2 2 3 3 3 3 2 3 2

Output: 3

Input:
20
0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0

Output: 12

Input:
20
2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3

Output: 5

Input:
20
3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2

Output: 4

Input:
25
0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1

Output: 16

Input:
25
1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3

Output: 5

Input:
25
2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3

Output: 3

Input:
30
0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0

Output: 22

Input:
30
1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2

Output: 9

Input:
30
1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3

Output: 2

Input:
35
0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0

Output: 21

Input:
35
2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2

Output: 11

Input:
35
1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2

Output: 7

Input:
40
2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0

Output: 28

Input:
40
2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1

Output: 10

Input:
40
1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3

Output: 8

Input:
45
2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2

Output: 29

Input:
45
3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3

Output: 8

Input:
50
3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0

Output: 32

Input:
50
3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2

Output: 16

Input:
50
3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3

Output: 7

Input:
55
0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0

Output: 40

Input:
55
3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2

Output: 13

Input:
55
3 3 1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 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: 50

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

Output: 50

Input:
99
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: 49

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

Output: 0

Input:
100
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Output: 100

Input:
2
0 3

Output: 1

Input:
2
1 0

Output: 1

Input:
2
1 2

Output: 0

Input:
2
2 0

Output: 1

Input:
2
2 1

Output: 0

Input:
2
2 3

Output: 0

Input:
2
3 0

Output: 1

Input:
2
3 1

Output: 0

Input:
100
3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0

Output: 50


The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).

#include<stdio.h>
#include<string.h>
int main()
{
	char a[500],temp,max;
	int c,n,i,j,k,x,f=1,h=4,m;
	scanf("%s",a);
	scanf("%d",&k);
	c=0;
	n=strlen(a);
	while(c!=n)
	{
		max='0';
		for(j=c;j<k+c+1;j++)
		{
			if(j==n)
			break;
			if(a[j]>max)
			{
				max=a[j];
				x=j;
			}
		}
		for(j=x;j>c;j--)
		{
			/*if(c==x)
			break;*/
			if(k==0)
			{
				f=0;
				break;
			}
			temp=a[j-1];
			a[j-1]=a[j];
			a[j]=temp;
			k--;
		}
		c++;
	//	printf("%d ",k);
		if(f==0)
		break;
	}
	printf("%s",a);
	return 0;
}

Print the maximum number that Pasha can get if he makes at most k swaps.

Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.Help Pasha count the maximum number he can get if he has the time to make at most k swaps.

Input: 1990 1

Output: 9190

Input: 300 0

Output: 300

Input: 1034 2

Output: 3104

Input: 9090000078001234 6

Output: 9907000008001234

Input: 1234 3

Output: 4123

Input: 5 100

Output: 5

Input: 1234 5

Output: 4312

Input: 1234 6

Output: 4321

Input: 9022 2

Output: 9220

Input: 66838 4

Output: 86863

Input: 39940894417248510 10

Output: 99984304417248510

Input: 5314 4

Output: 5431

Input: 1026 9

Output: 6210

Input: 4529 8

Output: 9542

Input: 83811284 3

Output: 88321184

Input: 92153348 6

Output: 98215334

Input: 5846059 3

Output: 8654059

Input: 521325125110071928 4

Output: 552132125110071928

Input: 39940894417248510 10

Output: 99984304417248510

Input: 77172428736634377 29

Output: 87777764122363437

Input: 337775999910796051 37

Output: 999997733751076051

Input: 116995340392134308 27

Output: 999654331120134308

Input: 10120921290110921 20

Output: 99221010120110921

Input: 929201010190831892 30

Output: 999928201010103182

Input: 111111111111111119 8

Output: 111111111911111111

Input: 219810011901120912 100

Output: 999822211111110000

Input: 191919191919119911 100

Output: 999999991111111111

Input: 801211288881101019 22

Output: 982111028888110101

Input: 619911311932347059 3

Output: 969111311932347059

Input: 620737553540689123 2

Output: 672037553540689123

Input: 621563797296514835 3

Output: 662153797296514835

Input: 915277434701161 9

Output: 977541234701161

Input: 15603712376708 28

Output: 87761503123670

Input: 784069392990841 0

Output: 784069392990841

Input: 787464780004 2

Output: 877644780004

Input: 74604713975 29

Output: 97776544310

Input: 901000000954321789 5

Output: 910009000054321789

Input: 901000000954321789 10

Output: 991000000504321789

Input: 901000000954321789 28

Output: 999100050000432178

Input: 901000000954321789 40

Output: 999810000050043217

Input: 901000000954321789 70

Output: 999875410000300021

Input: 1234567891234567 99

Output: 9877665544332211

Input: 123456789123456789 100

Output: 998877665544213123

Input: 12345670123456789 100

Output: 98776655443322101

Input: 12 100

Output: 21

Input: 11223344556677889 47

Output: 98821213344556677


The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ min(8, n)) — the number of the houses and the number k from the statement.

#include<stdio.h>
main()
{
    long long i=1000000007;
    long long n,k,j;
    scanf("%lld%lld",&n,&k);
    long long x=n-k,m=1,y=1;
    for(j=1;j<=x;j++)
        m=(m*x)%i;
    for(j=1;j<k;j++)
      y=(y*k)%i;
      m=(m*y)%i;
    printf("%I64d",m);
    return 0;
}

In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n).Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number x. Then he goes to the house whose number is written on the plaque of house x (that is, to house px), then he goes to the house whose number is written on the plaque of house px (that is, to house ppx), and so on.We know that:  When the penguin starts walking from any house indexed from 1 to k, inclusive, he can walk to house number 1.  When the penguin starts walking from any house indexed from k + 1 to n, inclusive, he definitely cannot walk to house number 1.  When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house. You need to find the number of ways you may write the numbers on the houses' plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by 1000000007 (109 + 7).

Input: 5 2

Output: 54

Input: 7 4

Output: 1728

Input: 8 5

Output: 16875

Input: 8 1

Output: 823543

Input: 10 7

Output: 3176523

Input: 12 8

Output: 536870912

Input: 50 2

Output: 628702797

Input: 100 8

Output: 331030906

Input: 1000 8

Output: 339760446

Input: 999 7

Output: 490075342

Input: 685 7

Output: 840866481

Input: 975 8

Output: 531455228

Input: 475 5

Output: 449471303

Input: 227 6

Output: 407444135

Input: 876 8

Output: 703293724

Input: 1000 1

Output: 760074701

Input: 1000 2

Output: 675678679

Input: 1000 3

Output: 330155123

Input: 1000 4

Output: 660270610

Input: 1000 5

Output: 583047503

Input: 1000 6

Output: 834332109

Input: 657 3

Output: 771999480

Input: 137 5

Output: 160909830

Input: 8 8

Output: 2097152

Input: 9 8

Output: 2097152

Input: 1 1

Output: 1

Input: 2 1

Output: 1

Input: 2 2

Output: 2

Input: 3 3

Output: 9

Input: 473 4

Output: 145141007


The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MAX 1000010
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

long long len, n, m, k, x, y;
long long X[MAX], Y[MAX], counter[1010][1010];

int main(){
    long long i, j, v, min_v, max_v;

    while (scanf("%lld %lld %lld %lld %lld", &n, &m, &k, &x, &y) != EOF){
        len = 0;
        clr(counter);
        for (i = 1; i < n; i++){
            for (j = 1; j <= m; j++){
                X[len] = i, Y[len++] = j;
            }
        }
        for (i = n; i > 1; i--){
            for (j = 1; j <= m; j++){
                X[len] = i, Y[len++] = j;
            }
        }

        if (n == 1){
            for (i = 1; i <= m; i++) X[len] = 1, Y[len++] = i;
        }

        for (i = 0; i < len; i++) counter[X[i]][Y[i]] += (k / len);
        k %= len;
        for (i = 0; i < k; i++) counter[X[i]][Y[i]]++;

        min_v = max_v = counter[1][1];
        for (i = 1; i <= n; i++){
            for (j = 1; j <= m; j++){
                if (counter[i][j] < min_v) min_v = counter[i][j];
                if (counter[i][j] > max_v) max_v = counter[i][j];
            }
        }

        printf("%lld %lld %lld\n", max_v, min_v, counter[x][y]);
    }
    return 0;
}

NoteThe order of asking pupils in the first test:   the pupil from the first row who seats at the first table, it means it is Sergei;  the pupil from the first row who seats at the second table;  the pupil from the first row who seats at the third table;  the pupil from the first row who seats at the first table, it means it is Sergei;  the pupil from the first row who seats at the second table;  the pupil from the first row who seats at the third table;  the pupil from the first row who seats at the first table, it means it is Sergei;  the pupil from the first row who seats at the second table; The order of asking pupils in the second test:   the pupil from the first row who seats at the first table;  the pupil from the first row who seats at the second table;  the pupil from the second row who seats at the first table;  the pupil from the second row who seats at the second table;  the pupil from the third row who seats at the first table;  the pupil from the third row who seats at the second table;  the pupil from the fourth row who seats at the first table;  the pupil from the fourth row who seats at the second table, it means it is Sergei;  the pupil from the third row who seats at the first table;

Print three integers:   the maximum number of questions a particular pupil is asked,  the minimum number of questions a particular pupil is asked,  how many times the teacher asked Sergei.

On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:  the maximum number of questions a particular pupil is asked,  the minimum number of questions a particular pupil is asked,  how many times the teacher asked Sergei. If there is only one row in the class, then the teacher always asks children from this row.

Input: 1 3 8 1 1

Output: 3 2 3

Output: 3  2 3

Input: 4 2 9 4 2

Output: 2 1 1

Input: 5 5 25 4 3

Output: 1 1 1

Input: 100 100 1000000000000000000 100 100

Output: 101010101010101 50505050505051 50505050505051

Input: 3 2 15 2 2

Output: 4 2 3

Input: 4 1 8 3 1

Output: 3 1 2

Input: 3 2 8 2 1

Output: 2 1 2

Input: 4 2 9 4 1

Output: 2 1 1

Input: 1 3 7 1 1

Output: 3 2 3

Output: 3  2 3

Input: 2 2 8 2 1

Output: 2 2 2

Input: 3 1 6 2 1

Output: 3 1 3

Input: 5 6 30 5 4

Output: 1 1 1

Input: 3 8 134010 3 4

Output: 8376 4188 4188

Input: 10 10 25 5 1

Output: 1 0 0

Input: 100 100 1000000000 16 32

Output: 101011 50505 101010

Input: 100 100 1 23 39

Output: 1 0 0

Input: 1 1 1000000000 1 1

Output: 1000000000 1000000000 1000000000

Output: 1000000000  1000000000 1000000000

Input: 1 1 1 1 1

Output: 1 1 1

Output: 1  1 1

Input: 47 39 1772512 1 37

Output: 989 494 495

Input: 37 61 421692 24 49

Output: 192 96 192

Input: 89 97 875341288 89 96

Output: 102547 51273 51274

Input: 100 1 1000000000000 100 1

Output: 10101010101 5050505051 5050505051

Input: 1 100 1000000000000 1 100

Output: 10000000000 10000000000 10000000000

Output: 10000000000  10000000000 10000000000

Input: 2 4 6 1 4

Output: 1 0 1

Input: 2 4 6 1 3

Output: 1 0 1

Input: 2 4 49 1 1

Output: 7 6 7

Input: 3 3 26 1 1

Output: 4 2 3

Input: 5 2 77 4 2

Output: 10 5 10

Input: 2 5 73 2 3

Output: 8 7 7

Input: 5 2 81 5 1

Output: 10 5 5

Input: 4 5 93 1 2

Output: 6 3 4

Input: 4 4 74 4 1

Output: 6 3 3

Input: 5 3 47 2 1

Output: 4 2 4

Input: 5 4 61 1 1

Output: 4 2 2

Input: 4 4 95 1 1

Output: 8 4 4

Input: 2 5 36 1 3

Output: 4 3 4

Input: 5 2 9 5 1

Output: 1 0 1

Input: 4 1 50 1 1

Output: 17 8 9

Input: 3 2 83 1 2

Output: 21 10 11

Input: 3 5 88 1 5

Output: 9 4 5

Input: 4 2 89 1 2

Output: 15 7 8

Input: 2 1 1 1 1

Output: 1 0 1

Input: 5 3 100 2 1

Output: 9 4 9

Input: 4 4 53 3 1

Output: 5 2 4

Input: 4 3 1 3 3

Output: 1 0 0

Input: 3 5 1 2 1

Output: 1 0 0

Input: 5 2 2 4 1

Output: 1 0 0

Input: 3 3 1 3 2

Output: 1 0 0

Input: 1 1 100 1 1

Output: 100 100 100

Output: 100  100 100

Input: 4 30 766048376 1 23

Output: 8511649 4255824 4255825

Input: 3 90 675733187 1 33

Output: 3754073 1877036 1877037

Input: 11 82 414861345 1 24

Output: 505929 252964 252965

Input: 92 10 551902461 1 6

Output: 606487 303243 303244

Input: 18 83 706805205 1 17

Output: 500925 250462 250463

Input: 1 12 943872212 1 1

Output: 78656018  78656017 78656018

Output: 78656018 78656017 78656018

Input: 91 15 237966754 78 6

Output: 176272 88136 176272

Input: 58 66 199707458 15 9

Output: 53086 26543 53085

Input: 27 34 77794947 24 4

Output: 88004 44002 88004

Input: 22 89 981099971 16 48

Output: 524934 262467 524933

Input: 10 44 222787770 9 25

Output: 562596 281298 562596

Input: 9 64 756016805 7 55

Output: 1476596 738298 1476595

Input: 91 86 96470485 12 43

Output: 12464 6232 12464

Input: 85 53 576663715 13 1

Output: 129530 64765 129529

Input: 2 21 196681588 2 18

Output: 4682895 4682894 4682895

Input: 8 29 388254841 6 29

Output: 1912586 956293 1912585

Input: 2 59 400923999 2 43

Output: 3397662 3397661 3397661

Input: 3 71 124911502 1 67

Output: 879658 439829 439829

Input: 1 17 523664480 1 4

Output: 30803793 30803792 30803793

Output: 30803793  30803792 30803793

Input: 11 27 151005021 3 15

Output: 559278 279639 559278

Input: 7 32 461672865 4 11

Output: 2404547 1202273 2404546

Input: 2 90 829288586 1 57

Output: 4607159 4607158 4607159

Input: 17 5 370710486 2 1

Output: 4633882 2316941 4633881

Input: 88 91 6317 70 16

Output: 1 0 1

Input: 19 73 1193 12 46

Output: 1 0 1

Input: 84 10 405 68 8

Output: 1 0 0

Input: 92 80 20 9 69

Output: 1 0 0

Input: 69 21 203 13 16

Output: 1 0 0

Input: 63 22 1321 61 15

Output: 1 0 0

Input: 56 83 4572 35 22

Output: 1 0 1

Input: 36 19 684 20 15

Output: 1 1 1

Input: 33 2 1 8 2

Output: 1 0 0

Input: 76 74 1 38 39

Output: 1 0 0

Input: 1 71 1000000000000000000 1 5

Output: 14084507042253522  14084507042253521 14084507042253522

Output: 14084507042253522 14084507042253521 14084507042253522

Input: 13 89 1000000000000000000 10 14

Output: 936329588014982 468164794007491 936329588014982

Input: 1 35 1000000000000000000 1 25

Output: 28571428571428572  28571428571428571 28571428571428571

Output: 28571428571428572 28571428571428571 28571428571428571

Input: 81 41 1000000000000000000 56 30

Output: 304878048780488 152439024390244 304878048780488

Input: 4 39 1000000000000000000 3 32

Output: 8547008547008547 4273504273504273 8547008547008547

Input: 21 49 1000000000000000000 18 11

Output: 1020408163265307 510204081632653 1020408163265306

Input: 91 31 1000000000000000000 32 7

Output: 358422939068101 179211469534050 358422939068101

Input: 51 99 1000000000000000000 48 79

Output: 202020202020203 101010101010101 202020202020202

Input: 5 99 1000000000000000000 4 12

Output: 2525252525252526 1262626262626263 2525252525252525

Input: 100 100 1000000000000000000 1 1

Output: 101010101010101 50505050505051 50505050505051

Input: 100 100 1000000000000000000 31 31

Output: 101010101010101 50505050505051 101010101010101

Input: 1 100 1000000000000000000 1 1

Output: 10000000000000000  10000000000000000 10000000000000000

Output: 10000000000000000 10000000000000000 10000000000000000

Input: 1 100 1000000000000000000 1 35

Output: 10000000000000000  10000000000000000 10000000000000000

Output: 10000000000000000 10000000000000000 10000000000000000

Input: 100 1 1000000000000000000 1 1

Output: 10101010101010101 5050505050505051 5050505050505051

Input: 100 1 1000000000000000000 35 1

Output: 10101010101010101 5050505050505051 10101010101010101

Input: 1 1 1000000000000000000 1 1

Output: 1000000000000000000 1000000000000000000 1000000000000000000

Output: 1000000000000000000  1000000000000000000 1000000000000000000

Input: 3 2 5 1 1

Output: 1 0 1

Input: 100 100 10001 1 1

Output: 2 1 1

Input: 1 5 7 1 3

Output: 2 1 1

Output: 2  1 1

Input: 2 2 7 1 1

Output: 2 1 2

Input: 4 1 5 3 1

Output: 2 1 2

Input: 2 3 4 2 3

Output: 1 0 0

Input: 3 5 21 1 2

Output: 2 1 1

Input: 2 4 14 1 1

Output: 2 1 2

Input: 5 9 8 5 4

Output: 1 0 0

Input: 2 6 4 1 3

Output: 1 0 1

Input: 1 5 9 1 1

Output: 2 1 2

Output: 2  1 2

Input: 1 5 3 1 2

Output: 1  0 1

Output: 1 0 1


The first line contains four integers n, l, r, x (1 ≤ n ≤ 15, 1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ 106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 106) — the difficulty of each problem.

#include <stdio.h>

int main()
{
    char n,i;
    long l,r,x,j;
    long min,max,sum,count=0;
    char s;
    scanf("%d%ld%ld%ld",&n,&l,&r,&x);
    long c[n];
    for(i=0;i<n;i++)
        scanf("%ld",c+i);
    long a=1L<<n;
    for(j=1;j<a;j++){
        min=1000000;
        max=1;
        sum=0;
        s=0;
        for(i=0;i<n;i++)
            if(j&(1L<<i)){
                if(c[i]<min)min=c[i];
                if(c[i]>max)max=c[i];
                sum+=c[i];
                s++;
            }
        if(s>1 && sum>=l && sum<=r && (max-min)>=x)
            count++;
    }
    printf("%ld\n",count);
    return 0;
}

NoteIn the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.

Print the number of ways to choose a suitable problemset for the contest.

You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.Find the number of ways to choose a problemset for the contest.

Input:
3 5 6 1
1 2 3

Output: 2

Input:
4 40 50 10
10 20 30 25

Output: 2

Input:
5 25 35 10
10 10 20 10 20

Output: 6

Input:
4 15 60 10
10 20 30 25

Output: 6

Input:
1 10 20 1
15

Output: 0

Input:
10 626451 11471247 246428
369649 684428 303821 287098 422756 301599 720377 177567 515216 750602

Output: 914

Input:
15 1415849 15540979 356865
8352 960238 276753 259695 712845 945369 60023 920446 181269 392011 318488 857649 30681 740872 115749

Output: 31485

Input:
7 1000 2000 1
10 20 30 40 50 60 70

Output: 0

Input:
4 10 20 1
4 6 4 6

Output: 9

Input:
4 10 20 1
5 15 13 7

Output: 4

Input:
2 10 20 5
5 10

Output: 1

Input:
5 1098816 3969849 167639
85627 615007 794045 530104 7091

Output: 15

Input:
13 700147 8713522 390093
996812 94040 954140 545670 369698 423872 365802 784830 700267 960664 949252 84637 257447

Output: 8026

Input:
15 4531977 20754263 137419
637830 85299 755530 64382 896833 879525 331501 148182 741013 192101 112217 52165 702790 988594 587499

Output: 6759

Input:
15 2572491 5084070 823435
570344 78552 775918 501843 844935 71141 331498 636557 435494 715447 992666 831188 28969 171046 989614

Output: 15078

Input:
15 4789415 23152928 233992
502422 273992 449428 947379 700461 681985 857134 243310 478052 77769 936151 642380 464695 281772 964693

Output: 10875

Input:
3 390224 390224 1
264237 125987 288891

Output: 1

Input:
7 1652707 1652707 1
492387 684636 235422 332532 924898 499872 192988

Output: 1

Input:
10 501107 501107 1
843967 30518 196518 619138 204862 690754 274071 550121 173607 359971

Output: 1

Input:
15 6627289 6627289 1
683844 183950 184972 764255 211665 842336 790234 815301 914823 513046 93547 713159 554415 200951 388028

Output: 1

Input:
15 5083470 5083470 1
978510 643688 591921 723137 573784 346171 920030 352119 528857 365128 627302 308557 716247 263519 654230

Output: 1

Input:
15 6558665 6558665 1
572491 435494 916457 775918 823435 78552 501843 331498 71141 844935 636557 992666 570344 831188 715447

Output: 1

Input:
10 159699 10967276 3542
998862 999751 995306 992648 992661 991407 997503 998809 999740 997669

Output: 942

Input:
5 2815840 8479687 4082
991137 992161 997887 998891 994990

Output: 14

Input:
15 2898377 6694755 721
992733 999159 990076 996808 990975 993338 993234 994757 997873 993303 994409 993801 998027 990495 999287

Output: 9819

Input:
6 20 70 1
10 10 20 20 30 30

Output: 35

Input:
6 20 70 1
10 10 10 10 10 10

Output: 0

Input:
15 1 1000000000 1
10 20 30 40 50 60 70 80 90 100 110 120 130 140 150

Output: 32752

Input:
6 30 40 1
19 20 21 14 15 16

Output: 13

Input:
4 5 234 2
10 9 12 11

Output: 8


The first line contains two integers w and h (1 ≤ w, h ≤ 4000) — the rectangle's sizes.

#include<stdio.h>
int main()
{
	long long int c=0,w,h,n,m;
	scanf("%lld %lld",&w,&h);
	if(w<2 || h<2)
	{
		printf("0\n");
		return 0;
	}
	for(n=2;w>=n;n=n+2)
	{
		for(m=2;h>=m;m=m+2)
			c=c+(h-(m-1))*(w-(n-1));
	}
	printf("%lld\n",c);
	return 0;
}

NoteIn the first example there exists only one such rhombus. Its vertices are located at points (1, 0), (2, 1), (1, 2), (0, 1).

Print a single number — the number of sought rhombi. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

You have two positive integers w and h. Your task is to count the number of rhombi which have the following properties:   Have positive area.  With vertices at integer points.  All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0, 0), (w, 0), (w, h), (0, h). In other words, for all vertices (xi, yi) of the rhombus the following conditions should fulfill: 0 ≤ xi ≤ w and 0 ≤ yi ≤ h.  Its diagonals are parallel to the axis.  Count the number of such rhombi.Let us remind you that a rhombus is a quadrilateral whose four sides all have the same length.

Input: 2 2

Output: 1

Input: 1 2

Output: 0

Input: 1 4000

Output: 0

Input: 4000 1

Output: 0

Input: 4000 4000

Output: 16000000000000

Input: 15 10

Output: 1400

Input: 7 9

Output: 240

Input: 17 17

Output: 5184

Input: 7 13

Output: 504

Input: 9 14

Output: 980

Input: 3 10

Output: 50

Input: 14 2

Output: 49

Input: 4 6

Output: 36

Input: 18 2858

Output: 165405321

Input: 14 1274

Output: 19882681

Input: 25 2986

Output: 347731644

Input: 13 1402

Output: 20638842

Input: 2955 21

Output: 240130660

Input: 1665 27

Output: 126136192

Input: 3671 19

Output: 303215400

Input: 2541 25

Output: 251810520

Input: 1913 3980

Output: 3623063809200

Input: 3727 2044

Output: 3627108561888

Input: 2437 460

Output: 78542851800

Input: 1499 2172

Output: 662525703000

Input: 1 1

Output: 0


The single line contains five integers C, Hr, Hb, Wr, Wb (1 ≤ C, Hr, Hb, Wr, Wb ≤ 109).

#include <stdio.h>

#define max(a, b) (((a) > (b)) ? (a) : (b))

int main(void) {
    int i;
    int c, wr, wb;
    long long hr, hb;
    long long ans;

    scanf("%d %lld %lld %d %d", &c, &hr, &hb, &wr, &wb);

    ans = 0;
    for (i = 0; i <= c / wr && i * i <= c; i++)
        ans = max(ans, hr * i + (c - wr * i) / wb * hb);
    for (i = 0; i <= c / wb && i * i <= c; i++)
        ans = max(ans, hb * i + (c - wb * i) / wr * hr);

    printf("%lld\n", ans);

    return 0;
}

NoteIn the sample test Om Nom can eat two candies of each type and thus get 16 joy units.

Print a single integer — the maximum number of joy units that Om Nom can get.

A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?  One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs Wr grams and each blue candy weighs Wb grams. Eating a single red candy gives Om Nom Hr joy units and eating a single blue candy gives Om Nom Hb joy units.Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than C grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.

Input: 10 3 5 2 3

Output: 16

Input: 5 3 1 6 7

Output: 0

Input: 982068341 55 57 106 109

Output: 513558662

Input: 930064129 32726326 25428197 83013449 64501049

Output: 363523396

Input: 927155987 21197 15994 54746 41309

Output: 358983713

Input: 902303498 609628987 152407246 8 2

Output: 68758795931537065

Input: 942733698 9180 9072 1020 1008

Output: 8484603228

Input: 951102310 39876134 24967176 70096104 43888451

Output: 539219654

Input: 910943911 107 105 60 59

Output: 1624516635

Input: 910943911 38162 31949 67084 56162

Output: 518210503

Input: 910943911 9063 9045 1007 1005

Output: 8198495199

Input: 903796108 270891702 270891702 1 1

Output: 244830865957095816

Input: 936111602 154673223 309346447 1 2

Output: 144791399037089047

Input: 947370735 115930744 347792233 1 3

Output: 109829394468167085

Input: 958629867 96557265 386229061 1 4

Output: 92562678344491221

Input: 969889000 84931386 424656931 1 5

Output: 82374017230131800

Input: 925819493 47350513 28377591 83230978 49881078

Output: 520855643

Input: 934395168 119 105 67 59

Output: 1662906651

Input: 934395168 29208 38362 51342 67432

Output: 531576348

Input: 934395168 9171 9045 1019 1005

Output: 8409556512

Input: 946401698 967136832 483568416 2 1

Output: 457649970001570368

Input: 962693577 967217455 967217455 2 2

Output: 465567015261784540

Input: 989976325 646076560 969114840 2 3

Output: 319800249268721000

Input: 901235456 485501645 971003291 2 4

Output: 218775648435471424

Input: 912494588 389153108 972882772 2 5

Output: 177550052841687584

Input: 995503930 29205027 18903616 51333090 33226507

Output: 565303099

Input: 983935533 115 108 65 61

Output: 1742049794

Input: 983935533 33986 27367 59737 48104

Output: 559787479

Input: 983935533 7105 7056 1015 1008

Output: 6887548731

Input: 994040035 740285170 246761723 3 1

Output: 245291032098926983

Input: 905299166 740361314 493574209 3 2

Output: 223416160034288041

Input: 911525551 740437472 740437472 3 3

Output: 224975891301803200

Input: 922784684 566833132 755777509 3 4

Output: 174354977531116762

Input: 955100178 462665160 771108601 3 5

Output: 147297192414486195

Input: 949164751 36679609 23634069 64467968 41539167

Output: 537909080

Input: 928443151 60 63 106 112

Output: 525533853

Input: 928443151 25031 33442 43995 58778

Output: 528241752

Input: 928443151 1006 1012 1006 1012

Output: 928443150

Input: 936645623 540336743 135084185 4 1

Output: 126526011319256470

Input: 947904756 540408420 270204210 4 2

Output: 128063927875111380

Input: 959163888 540480074 405360055 4 3

Output: 129602242291091928

Input: 970423020 540551739 540551739 4 4

Output: 131140962756657945

Input: 976649406 455467553 569334442 4 5

Output: 111208028918928288

Input: 923881933 18531902 53987967 32570076 94884602

Output: 524563246

Input: 977983517 57 63 101 112

Output: 551931291

Input: 977983517 29808 22786 52389 40047

Output: 556454318

Input: 977983517 9009 9108 1001 1012

Output: 8801851608

Input: 984283960 367291526 73458305 5 1

Output: 72303831537144592

Input: 990510345 367358723 146943489 5 2

Output: 72774523091497887

Input: 901769477 367425909 220455545 5 3

Output: 66266693959035917

Input: 907995862 367493085 293994468 5 4

Output: 66736440098722854

Input: 924287742 367560271 367560271 5 5

Output: 67946290439275508

Input: 1000000000 1000 999 100 1000000000

Output: 10000000000

Input: 999999999 10 499999995 2 99999999

Output: 4999999995

Input: 999999999 1 1000000000 2 1000000000

Output: 499999999

Input: 999999997 2 999999997 2 999999997

Output: 999999997

Input: 1000000000 1 1 11 11

Output: 90909090

Input: 999999999 999999998 5 999999999 5

Output: 999999998

Input: 100000001 3 100000000 3 100000001

Output: 100000000

Input: 999999999 2 3 1 2

Output: 1999999998

Input: 1000000000 2 1 3 4

Output: 666666666

Input: 999999999 10000 494999 2 99

Output: 4999999994999

Input: 1000000000 1 1 1 1

Output: 1000000000

Input: 998999 1000 999 1000 999

Output: 998999

Input: 3 100 101 2 3

Output: 101

Input: 345415838 13999 13997 13999 13997

Output: 345415838

Input: 5000005 3 2 5 1

Output: 10000010

Input: 1000000000 1 1 1 1000000000

Output: 1000000000

Input: 999999999 3 2 10 3

Output: 666666666

Input: 1000000000 1000 1000 1 1

Output: 1000000000000

Input: 200000001 100000002 1 100000001 1

Output: 200000002

Input: 100000000 1000000000 1 100000001 1

Output: 100000000

Input: 1000000000 99 100 1 2

Output: 99000000000

Input: 1000000000 5 5 1 1

Output: 5000000000

Input: 1000000000 1 1000000000 1 1000000000

Output: 1000000000