SOLVE

LATER

Almost Pallindrome

Problem

Editorial

Analytics

Rohan calls a string **almost pallindrome** if it can be separated into two halves such that each half is permutation of one another. But if length of string is odd then you can divide the string into two half, and there will be only one extra character that will be the middle character

For example : **"radar"** is an almost pallindrome because two halves are **"ra"** and **"ar"** are permutations of each other and d is extra character which is in the middle of the string.

Given a string **X** you have to count total adjacent swaps required to convert that string to **almost pallindrome** . If it is not possible , simply print -1 as output.

**Examples / Hints**

**ramaaamr** : This is almost pallindrome as it can be divided into rama and aamr and amar is permutation of aamr or vice versa. So total swaps required are 0

**raonraons** : This is not almost pallindrome as it can't be divided into two halves such that they are permutation of each other but if we swap **s** with 4 characters towards left then it would become **raonsraon** whcih is an almost pallindrome. So total swaps required are 4

**Input**

First line contains a string as input

**Output**

Output total adjacent swaps required to make the string almost pallindrome

**Constraints**

1≤ |String| ≤ 10^6+5

Explanation

If you swap d with two characters on the left then string formed is "radra" which is almost pallindrome

Time Limit:
1.0 sec(s)
for each input file.

Memory Limit:
256 MB

Source Limit:
1024 KB

Marking Scheme:
Marks are awarded when all the testcases pass.

Allowed Languages:
C,
C++,
C++14,
Clojure,
C#,
D,
Erlang,
F#,
Go,
Groovy,
Haskell,
Java,
Java 8,
JavaScript(Rhino),
JavaScript(Node.js),
Julia,
Kotlin,
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Swift,
Visual Basic

Initializing Code Editor...

{"b4ee560": "/pagelets/suggested-problems/algorithm/almost-pallindrome/", "af12063": "/pagelets/recommended-problems/algorithm/almost-pallindrome/", "1524b76": "/pagelets/problems-hint/algorithm/almost-pallindrome/", "052688b": "/pagelets/problem-author-tester/algorithm/almost-pallindrome/", "9101b90": "/pagelets/show-submission/algorithm/almost-pallindrome/"}

realtime.hackerearth.com

80

907a8f65bbc17088b87c1412370573e1a18901a6

58a29e5cae2309f04b28

/realtime/pusher/auth/