Under construction

Still being built. Things may change

Couple Ring Match

Interview

Time limit1sMemory limit1024 MB

Summary
Find every ring feature worn by exactly two people and print those pairs of names, ignoring anyone whose feature is '-'.
Level

Easy3 of 10

Topics
Hash map, Implementation
Solved
No attempts yet

Problem

Jonghyeon wants to find out how many couples there are at his school. Couples wear a distinctive ring on their left ring finger as a couple ring. After noticing this, Jonghyeon decided to check the left ring finger of every enrolled student. If exactly two people wear rings with the same feature, Jonghyeon considers those two a suspected couple. For the given input, find the people Jonghyeon considers suspected couples.

Input

The first line contains NN, the number of people whose left ring finger Jonghyeon checks. (1≤N≤1 0001 \le N \le 1\,000) Each of the next NN lines contains a person's name pip_i and the feature of their ring sis_i, separated by a space. If the person is not wearing a ring, sis_i is given as -. Both pip_i and sis_i are strings of length at most 50. All names pip_i are distinct. All names and ring features consist of English letters, digits, and underscores (_).

Output

On the first line, print the number of suspected couple pairs. If there is at least one pair, print each pair on its own line starting from the second line, with the two names separated by a space. The order does not matter.

Examples2

  1. Example 1

    Input
    6
    jonghyeon -
    minkyu twisted_silver_matte
    hyegeun thin_plated_gold
    somin text_engraved_light_blue
    daeun twisted_silver_matte
    jiyoung thin_plated_gold
    
    Expected output
    2
    minkyu daeun
    hyegeun jiyoung
    
  2. Example 2

    Input
    6
    eardrum_buster motdoen_goyangi
    ksap motdoen_goyangi
    beenzino chanel
    bongjunho chanel
    poison motdoen_goyangi
    bts chanel
    
    Expected output
    0