CF BUDDY
← Problems·

1426E · Rock, Paper, Scissors

1800 · brute force, constructive algorithms, flows

Problem: Alice and Bob have decided to play the game "Rock, Paper, Scissors".

The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a draw. Otherwise, the following rules applied:

  • if one player showed rock and the other one showed scissors, then the player who showed rock is considered the winner and the other one is considered the loser;
  • if one player showed scissors and the other one showed paper, then the player who showed scissors is considered the winner and the other one is considered the loser;
  • if one player showed paper and the other one showed rock, then the player who showed paper is considered the winner and the other one is considered the loser.

Alice and Bob decided to play exactly nn rounds of the game described above. Alice decided to show rock a1a_1 times, show scissors a2a_2 times and show paper a3a_3 times. Bob decided to show rock b1b_1 times, show scissors b2b_2 times and show paper b3b_3 times. Though, both Alice and Bob did not choose the sequence in which they show things. It is guaranteed that a1+a2+a3=na_1 + a_2 + a_3 = n and b1+b2+b3=nb_1 + b_2 + b_3 = n.

Your task is to find two numbers:

  1. the minimum number of round Alice can win;
  2. the maximum number of rounds Alice can win.

Input Format: The first line of the input contains one integer nn (1n1091 \le n \le 10^{9}) — the number of rounds.

The second line of the input contains three integers a1,a2,a3a_1, a_2, a_3 (0ain0 \le a_i \le n) — the number of times Alice will show rock, scissors and paper, respectively. It is guaranteed that a1+a2+a3=na_1 + a_2 + a_3 = n.

The third line of the input contains three integers b1,b2,b3b_1, b_2, b_3 (0bjn0 \le b_j \le n) — the number of times Bob will show rock, scissors and paper, respectively. It is guaranteed that b1+b2+b3=nb_1 + b_2 + b_3 = n.

Output Format: Print two integers: the minimum and the maximum number of rounds Alice can win.

Note: In the first example, Alice will not win any rounds if she shows scissors and then paper and Bob shows rock and then scissors. In the best outcome, Alice will win one round if she shows paper and then scissors, and Bob shows rock and then scissors.

In the second example, Alice will not win any rounds if Bob shows the same things as Alice each round.

In the third example, Alice always shows paper and Bob always shows rock so Alice will win all three rounds anyway.

Sample Cases

Case 1

Input

2
0 1 1
1 1 0

Output

0 1

Case 2

Input

15
5 5 5
5 5 5

Output

0 15

Case 3

Input

3
0 0 3
3 0 0

Output

3 3

Case 4

Input

686
479 178 29
11 145 530

Output

22 334

Case 5

Input

319
10 53 256
182 103 34

Output

119 226

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback