Similar Strings
Tag(s):

## Advanced Algorithms, Algorithms, Convolution, Fast Fourier transform, Medium-Hard

Problem
Editorial
Analytics

You are given three strings $a$, $b$ and $c$  each of length $n$ consisting of lower case English letters. The difference between the three strings is defined as $\sum\limits_{i=1}^n \ |a[i]-b[i]|+|a[i]-c[i]|$ where $|a[i]-b[i]|$ and $|a[i]-c[i]|$ are the absolute differences between ASCII values of the characters at the position $i$ in strings $a,b$ and $a,c$ respectively. However, the string $a$ can be rotated cyclically (for example the rotations of the string $xyz$ are $xyz,zxy,yzx$). There are a total of $n$ possible rotations of a string of length $n$.

Print the maximum and minimum difference of the three strings for all the possible rotations of the string $a$.

Input format

First line: Single integer $n$ (the length of the three strings)

Next three lines: Strings $a,b$ and $c$ respectively

Output Format:

Print two space-separated integers: the maximum and minimum difference of the three strings for all possible rotations of string $a$.

Constraints

$1 \le n \le 100000$

SAMPLE INPUT
4
abaa
aaba
aaba
SAMPLE OUTPUT
4 0

Explanation

The minimum difference is obtained when the first string is rotated cyclically once while the difference is maximum without any rotation.

Time Limit: 3.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: Bash, 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, Swift-4.1, TypeScript, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in Challenge Name

November Easy' 18

OTHER PROBLEMS OF THIS CHALLENGE
• Algorithms > String Algorithms
• Algorithms > Graphs
• Data Structures > Advanced Data Structures
• Data Structures > Trees