This page is still under construction.

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

Automatic Friends

Interview

Time limit2sMemory limit1024 MB

Summary
Count pairs of triples that agree in exactly one coordinate and differ in the other two.
Level

Medium5 of 10

Topics
Hash map, Combinatorics, Math, Array
Solved
No attempts yet

Problem

A school for young programmers decided to build its own social network that automatically suggests potential friends to each user. When registering, every user takes a psychological test, and the results determine the values of three psychological characteristics for that user. Each characteristic value is a positive integer.

If two users differ in all three psychological characteristics, they will constantly quarrel, and if they match in two or three characteristics, they will be bored. So the only pairs of users who are potential friends are those that match in exactly one characteristic and differ in the other two.

Given nn triples (ai,bi,ci)(a_i, b_i, c_i) of characteristic values for the users, write a program that finds the number of pairs of potential friends, that is, the number of index pairs i<ji < j for which exactly one of the three equalities ai=aja_i = a_j, bi=bjb_i = b_j, ci=cjc_i = c_j holds.

Input

The first line of the input contains the number nn of users. Each of the next nn lines contains three positive integers aia_i, bib_i, and cic_i, the characteristic values of the ii-th user.

Output

The output must contain the required number of pairs of potential friends.

Hint

In the first example, the pairs of potential friends are users 1 and 2, and users 2 and 3. In both cases the users match in the first characteristic and differ in the second and third. Users 1 and 3 match in the first two characteristics, so they do not form a pair of potential friends.

Examples2

  1. Example 1

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

    Input
    4
    100 100 100
    100 100 100
    100 99 99
    99 99 100
    
    Expected output
    5