#JSUTFPC2025J. All Winner —— 全胜者
All Winner —— 全胜者
Statement
There are teams participating in the chess team competition. Each team consists of players. The competition adopts a round-robin system, and a total of matches will be played. In each match, the players from both teams will be randomly paired for a game, and a winner will be determined in each game. After all matches are over, each player will have played exactly games. If a player wins all games, they will receive the undefeated award. Please find the maximum number of players who can possibly receive the undefeated award.
Input
The input consists of a single line containing two space-separated integers and , indicating that there are teams and each team has players (, ).
Output
Output a single number representing the maximum number of players who can potentially win the undefeated award.
Samples
3 3
4
1 1
1
Notes
For the st test case, assume that there are teams participating in the competition.
- Team : players ;
- Team : players ;
- Team : players ;
The results of the competition may be as follows:
- Team vs. Team :
- vs. , wins
- vs. , wins
- wins against
- Team vs. Team
- wins against
- vs. , wins
- wins against
- Team vs. Team
- vs. , wins
- vs. , wins
- wins against
At this time, only player from team won the undefeated award. In this example, the maximum number of players who could potentially win the undefeated award is .