{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eSuppose you are given two strings $$$a$$$ and $$$b$$$. You can apply the following operation any number of times: choose any \u003cspan class\u003d\"tex-font-style-bf\"\u003econtiguous\u003c/span\u003e substring of $$$a$$$ or $$$b$$$, and sort the characters in it in non-descending order. Let $$$f(a, b)$$$ the minimum number of operations you have to apply in order to make them equal (or $$$f(a, b) \u003d 1337$$$ if it is impossible to make $$$a$$$ and $$$b$$$ equal using these operations).\u003c/p\u003e\u003cp\u003eFor example: \u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$f(\\text{ab}, \\text{ab}) \u003d 0$$$; \u003c/li\u003e\u003cli\u003e $$$f(\\text{ba}, \\text{ab}) \u003d 1$$$ (in one operation, we can sort the whole first string); \u003c/li\u003e\u003cli\u003e $$$f(\\text{ebcda}, \\text{ecdba}) \u003d 1$$$ (in one operation, we can sort the substring of the second string starting from the $$$2$$$-nd character and ending with the $$$4$$$-th character); \u003c/li\u003e\u003cli\u003e $$$f(\\text{a}, \\text{b}) \u003d 1337$$$. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou are given $$$n$$$ strings $$$s_1, s_2, \\dots, s_k$$$ having equal length. Calculate $$$\\sum \\limits_{i \u003d 1}^{n} \\sum\\limits_{j \u003d i + 1}^{n} f(s_i, s_j)$$$.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) — the number of strings.\u003c/p\u003e\u003cp\u003eThen $$$n$$$ lines follow, each line contains one of the strings $$$s_i$$$, consisting of lowercase Latin letters. $$$|s_1| \u003d |s_2| \u003d \\ldots \u003d |s_n|$$$, and $$$n \\cdot |s_1| \\le 2 \\cdot 10^5$$$. All these strings are pairwise distinct.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint one integer: $$$\\sum \\limits_{i \u003d 1}^{n} \\sum\\limits_{j \u003d i + 1}^{n} f(s_i, s_j)$$$.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\nzzz\nbac\nabc\nacb\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4015\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\na\nb\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1337\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}