The number of students
Time limit2sMemory limit256 MB
Find the smallest numbers of girls and boys whose within-group and cross-group friend counts match the given a, b, c, and d.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Combinatorics
- Solved
- No attempts yet
Problem
Seonyeong's class has girls and boys. Some pairs of students are friends and some are not. Friendship always goes both ways, so if A is a friend of B, then B is a friend of A. Nobody is their own friend, and a pair of students is friends at most once.
Every girl has exactly girl friends and exactly boy friends.
Every boy has exactly girl friends and exactly boy friends.
Among the classes that fit these counts, find the one with the fewest students and report how many girls and how many boys it has.
Input
The first line contains , , , separated by spaces. ()
Output
Print the number of girls and the number of boys on one line, separated by a space. If several classes fit, print the one with the smallest , which also makes smallest. Such a class always exists.
Hint
Count the friendships between a girl and a boy from both sides. The girls account for of them and the boys account for of them. Those two counts are equal, which fixes the ratio between and before anything else.