Under construction

Still being built. Things may change

Colorful Parrots

Interview

Time limit1sMemory limit1024 MB

Summary
Given the body and tail colors of two parrots, list every distinct body and tail color pair a chick can have, sorted in dictionary order.
Level

Easy2 of 10

Topics
Implementation, Sorting, Hash map
Solved
No attempts yet

Problem

Jaehyeon keeps two parrots, Popo and Lemon, and they have had many chicks over the years. While watching the parrots born to them, Jaehyeon noticed a simple rule about their colors. The body color of a chick is one of the father's body color, the father's tail color, the mother's body color, or the mother's tail color. The tail color of a chick is also one of these four colors.

Given the body color and tail color of the father, and the body color and tail color of the mother, print every possible pair of body color and tail color of a chick in dictionary order. (Do not print duplicate pairs of body color and tail color.)

Input

The first line contains the body color and tail color of the father parrot.

The second line contains the body color and tail color of the mother parrot.

Each color is a string of lowercase English letters with a length from 11 to 2020. The same color may appear more than once.

Output

Print the possible pairs of chick body color and tail color, one pair per line, in dictionary order. Dictionary order means that pairs are sorted by body color first, and pairs with the same body color are sorted by tail color.

Examples2

  1. Example 1

    Input
    blue purple
    green green
    
    Expected output
    blue blue
    blue green
    blue purple
    green blue
    green green
    green purple
    purple blue
    purple green
    purple purple
    
  2. Example 2

    Input
    white blue
    yellow purple
    
    Expected output
    blue blue
    blue purple
    blue white
    blue yellow
    purple blue
    purple purple
    purple white
    purple yellow
    white blue
    white purple
    white white
    white yellow
    yellow blue
    yellow purple
    yellow white
    yellow yellow