MCHAOS - Chaos Strings

English Vietnamese

Little Lovro likes to play games with words. During the last few weeks he realized that some words don't like each other.


The words A and B don't like each other if the word A is lexicographically before the word B, but the word B' is lexicographically before the word A', where X' stands for the word X reversed (if X="kamen" then X'="nemak"). For example, the words "lova" and "novac" like each other, but the words "aron" and "sunce" don't like each other.

Given some set of the words, we define  the degree of chaos of the set as  the number of pairs of different words that don't like each other.

Write a program that, given a set of words, finds the chaos degree for the set.

Input

The first line of input contains an integer N, 2 ≤ N ≤ 100 000.

Each of the following N lines contains one word – a sequence of at most 10 lowercase letters of the English alphabet ('a'-'z'). There will be no two identical words in the set.

Output

The first and only line of output should contain a single integer – the chaos degree of the given set of words.

Note: use 64-bit signed integer type (int64 in Pascal, long long in C/C++).

Sample

input 
 
2
lopta
kugla
 
output
 
0

input
 
4
lova
novac
aron
sunce
 
output
 
3

input
 
14
branimir
vladimir
tom
kruz
bred
pit
zemlja
nije
ravna
ploca
ko
je
zapalio
zito
 
output
 
48


Được gửi lên bởi:psetter
Ngày:2009-06-06
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:COI 06

hide comments
2021-03-09 02:20:48
one hit với nén và dùng bit
2020-03-29 12:16:19
vl hơn 1s vẫn AC, may!
2016-11-02 05:35:56
đm time như cc
2016-07-18 12:13:24
@@

Last edit: 2017-03-11 18:51:11
2016-07-18 12:08:57 nguyenngocanh
Trâu cũng AC

Last edit: 2016-10-09 17:44:43
2015-09-05 15:22:53
Tham khảo lời giải tại http://vnspoj.blogspot.com/p/blog-page_7.html
2014-12-01 15:16:54 livw
Thỏ con làm bánh
// WHAT'S WRONG WITH YOU GUYS??? WTF IS PENTIUM 3??? PLEASE UPGRADE SERVERS! IT'S RIDICULOUS TO TEST SOLUTIONS ON 9-YEAR OLD SYSTEM!
2014-11-09 17:48:47 Bitagi97
time chặt kiểu củ chuối ='=
2014-06-22 17:10:27 Anh Duc Le
Input có dấu cách trống ở cuối mỗi xâu, dùng C++ tránh STL.
2013-09-24 13:43:26 a;slkfjasl;fkj
Chaos knight :3

Last edit: 2013-09-24 13:52:27
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.