Frequent Friends
At UptoSkills Arena, students often form study groups. You are given a list of pairs of students who have met up. A 'friend pair' is formed by two students who have met an equal number of times. Your task is to count how many distinct friend pairs exist. A pair (A, B) is the same as (B, A). Ensure each pair is counted only once.
Input
The first line contains an integer N, the number of meetings. The next N lines each contain two strings, student1 and student2, representing a meeting between them.
Output
Print a single integer, the total count of distinct friend pairs.
Constraints
1 <= N <= 200000. Student names are non-empty strings containing only lowercase English letters. The total length of all student names does not exceed 1000000.
Example 1
4 Alice Bob Bob Charlie Alice David Charlie David
6
Alice met 2 times, Bob 2 times, Charlie 2 times, David 2 times. All 4 students met twice. Pairs: (Alice, Bob), (Alice, Charlie), (Alice, David), (Bob, Charlie), (Bob, David), (Charlie, David). Total 6 pairs.
Example 2
5 Alice Bob Bob Charlie Alice Charlie David Eve Eve Frank
7
Alice, Bob, Charlie met 2 times each. David, Eve, Frank met 1 time each. Pairs from group 1: (Alice, Bob), (Alice, Charlie), (Bob, Charlie) = 3 pairs. Pairs from group 2: (David, Eve), (David, Frank), (Eve, Frank) = 3 pairs. Total 3+3=6 pairs.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
4 Alice Bob Bob Charlie Alice David Charlie David
5 Alice Bob Bob Charlie Alice Charlie David Eve Eve Frank