Damian and Coco the Monkey are preparing themselves for programming contests.
They realise that an important part of preparing for a competition is the sharing of knowledge from experienced seniors to those who just started. Therefore, during the next training session Damian decided to make teams so that juniors are solving problems together with their seniors.
Damian believes that the optimal team (of three people) should consist of one senior and two juniors. This allows for seniors to share their experience with a greater number of people.
On the other hand, Coco the Monkey believes that the optimal team should consist of two seniors and one junior. Thus, each junior can gain more knowledge and experience.
As a result, they decided to compromise. All teams during the training sessions should belong to one of the two types described above. Additionally, they agreed that the total number of teams should be maximised.
There are N seniors and M juniors. Not every person(senior or junior) must be part of a team. Each person can only be part of one team. Can you calculate what is the maximum number of teams that can be formed?
The first line of input will contain two integers, N and M.
On a single line output the maximum number of teams that can be formed.
Subtask 1 (12%): 1 ≤ N, M ≤ 10
Subtask 2 (42%): 1 ≤ N, M ≤ 500 000
Subtask 3 (46%): 1 ≤ N, M ≤ 1018
Subtask 4 (0%): Sample Testcases
There are 2 seniors and 6 juniors. We can form two teams of (senior, junior, junior). This is the maximum.
There are 4 seniors and 5 juniors. We can form a total of three teams: two teams of (senior, junior, junior) and one team of (senior, senior, junior). This is the maximum.
HCI NOI November Training 2015 Session 4 Problem B