Under construction

Still being built. Things may change

A Homogeneous Country

Interview

Time limit1sMemory limit256 MB

Summary
Count class label frequencies over up to 100,000 lines and compute 1 minus the sum of squared relative frequencies.
Level

Easy3 of 10

Topics
Hash map, Math
Solved
No attempts yet

Problem

Many Westerners think Korea is a mere Eastern country hanging like a grapefruit next to China. However, Koreans have kept their unique ethnicity, struggling all the time not to be "a shrimp among whales": Chinese to the west, Japanese to the east, "barbarian" tribes, and an expanding Russia to the north. Bruce Cumings argued that a vast majority of Koreans look through the lens of race, thinking they have some essential quality making them and only them real Koreans, tracing a unique, homogeneous bloodline back some five thousand years, a story called Tan-gun mythology; "Koreans do this, Koreans do that" in shorthand. After a fratricidal war, the country divided into North and South Korea, creating the Demilitarized Zone. South Korea had no friend in the region and became a de facto island. During the Cold War, Communist countries supported its enemy, North Korea, and Japan was the last candidate because of their colonial history. Its extremely low ethnic diversity (158th out of 159 countries; North Korea ranked 159th) and cultural diversity (152nd) is understandable given its experience of occupation and war.

Though the homogeneity of South Korea played a crucial role in the miracle of its economic development, it has also been a growing concern. A certain amount of diversity is necessary to encourage understanding of different perspectives within the society and to dispel negative stereotypes and personal biases about different groups. Learning about others helps to recognize and respect minorities, which we all are in some categories. Better understanding makes collaboration and cooperation in the workplace easier.

The lack of other diversities left solely one inevitable diversity, gender, and called forth the recent fierce conflict between the two traditional genders in South Korea, where only men are subject to two years of savage conscription and its aftermath and women struggle with deeply imbued Confucianism, a 37% wage gap, and the paucity of sister politicians. Another recent case, Yemeni refugees, reveals a deeper nuance. In spite of the prevailing grievance over asylum seekers around the world, a poll estimates that between 49% and 56% of the general Korean population oppose granting asylum to the Yemeni refugees. But in a surprising result, the opposition among Korean youth in their 20s and 30s is considerably higher, 70% and 60% respectively, despite the increased number of lawful foreigners in the country. The discord between men and women has contributed to avoiding marriage among youngsters, lowering the overall fertility rate to a staggering 0.96 in 2018. Now, for Koreans, embracing outsiders is not only a matter of morality or economic growth but also a matter of their survival in the future.

Jason, writing an essay about this issue, wants to exemplify the heterogeneity of the groups around him. You are asked to write a program that calculates the heterogeneity of a group. He decided to use the Gini index. It is defined as 1−∑j=1npj21 - \sum_{j=1}^{n} p_j^2, where pjp_j is the relative frequency of class jj. Let's help him out.

Input

The class of an entity, CiC_i, is given line by line. For all ii, CiC_i consists only of alphabets and is case-sensitive, and its length is not longer than 10.

The number of entities, mm, is not greater than 100,000.

Output

Print the Gini index of the given group. Its relative error or absolute error must be less than 10−610^{-6}.

Hint

In the first case, the relative frequency of Korean is 9/10=0.99/10=0.9 and that of Chinese is 1/10=0.11/10=0.1. Hence, the Gini index is 1−(0.92+0.12)=0.181 - (0.9^2 + 0.1^2) = 0.18.

In the second case, 1−4×(1/4)2=0.751 - 4 \times (1 / 4)^2 = 0.75.

Examples2

  1. Example 1

    Input
    Korean
    Korean
    Korean
    Korean
    Korean
    Chinese
    Korean
    Korean
    Korean
    Korean
    
    Expected output
    0.18
    
  2. Example 2

    Input
    German
    French
    British
    Dutch
    
    Expected output
    0.75