All Submissions


Do you want a story?
No! Let's get straight to business.

You are given an array of N strings, You need to sort the array in lexicographical order. Only move allowed while sorting is you can only swap strings at adjacent positions.That means
You can swap -
1. String Ai with String Ai+1
2. String Ai with String Ai-1
You need to output the minimum number of moves it will take to sort the Array.

Input
An integer N(<=1000) denoting the size of the array.
N strings on every next line, where ith string denotes string Ai(length of each string<=10)

Output
An integer denoting the minimum number of moves.

Sample Input
5
Catelyn
Jon
Sansa
Winterfell
Arya

Sample Output
4

Explanation
It will take 4 moves to move Arya from 5th to 1st position.

Languages: AWK,Bash,Brain,C,C++,Java,C#,JavaScript,Pascal,Perl,PHP,Python,Python3,Ruby,Text

Time Limit: 1 Second(s)
Score: 50 Point(s)
Input File Limit: 50000 Bytes

Submit

Login to post clarification.

No Clarifications.

Contest

Mode Judge

Passive

Online

Overall Rankings