Count how many pairs of players can be formed when two groups arrive in equal sizes or with a one-item difference.
Problem
There are two groups of players standing in line for a game. In one move, you can take one player from each group and form a pair.
Given the sizes of the two groups, determine how many pairs can be formed before one of the groups becomes empty.
This is a simple counting problem: each pair consumes one player from both groups, so the answer is limited by the smaller group size.
Input Format
- The input contains two integers and — the sizes of the two groups.
- .
Output Format
- Print a single integer: the maximum number of pairs that can be formed.
Constraints
- The answer fits in a 64-bit signed integer.
Example 1
Input
4 7
Output
4
Explanation
You can form 4 pairs. After that, the first group is empty and 3 players remain in the second group.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.