This page is still under construction.

Parts of this page are still being built. What you see may change.

The number of students

Time limit2sMemory limit256 MB

Summary
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 aa girl friends and exactly bb boy friends.

Every boy has exactly cc girl friends and exactly dd 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 aa, bb, cc, dd separated by spaces. (1≤a,b,c,d≤501 \le a, b, c, d \le 50)

Output

Print the number of girls mm and the number of boys nn on one line, separated by a space. If several classes fit, print the one with the smallest mm, which also makes nn smallest. Such a class always exists.

Hint

Count the friendships between a girl and a boy from both sides. The girls account for m×bm \times b of them and the boys account for n×cn \times c of them. Those two counts are equal, which fixes the ratio between mm and nn before anything else.

Examples2

  1. Example 1

    Input
    1 2 1 2
    
    Expected output
    2 4
    
  2. Example 2

    Input
    1 1 1 1
    
    Expected output
    2 2