{"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\u003eWord Search is a well-known hobby, although it is losing some of its prestige in recent years. The goal in this game is to find words in an array, where each cell in this matrix contains a letter.\u003c/p\u003e\u003cp\u003eBibika and her brother were playing Word Search, but soon they lost interest in the game, as finding all the words was getting relatively easy. Bibika would like to take her brother away from the computer, she searched the internet for games of the same style and ended up finding the \u003cspan class\u003d\"tex-font-style-it\"\u003eLavaspar Hunting\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eLavaspar Hunting is a game that follows the same idea of the famous Word Search. However, instead of simply having to find a word in the matrix, the goal is to find any anagram of the word, making the game more difficult and interesting. The anagram can be found in a row, column or diagonal.\u003c/p\u003e\u003cp\u003eAn anagram is a word formed by rearranging the letters of another. Sometimes, an anagram does not exist as a word in the language, but this does not matter. \u003cspan class\u003d\"tex-font-style-sc\"\u003ebalo\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-sc\"\u003eloba\u003c/span\u003e and \u003cspan class\u003d\"tex-font-style-sc\"\u003eaolb\u003c/span\u003e are examples of anagrams of the word \u003cspan class\u003d\"tex-font-style-sc\"\u003ebola\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eBibika realized that it was possible for the same cell in the matrix to make part of anagrams of different words and then she started to call these \u003cspan class\u003d\"tex-font-style-it\"\u003especial cells\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eNow she would like to know, given an array configuration and a collection of words, how many special cells are there?\u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/d845ad7924308c2cc5f00a484add50c2?v\u003d1726254817\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/center\u003e\u003cp\u003eThe picture above illustrates the first example, where the collection of words consists of three words: \u003cspan class\u003d\"tex-font-style-sc\"\u003ebola\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-sc\"\u003ecasa\u003c/span\u003e and \u003cspan class\u003d\"tex-font-style-sc\"\u003eboi\u003c/span\u003e. The rectangles of each color represent anagrams of different words from the entry. The $$$3$$$ special cells are painted yellow.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains two integers, $$$L$$$ and $$$C$$$, which correspond to the number of lines and columns of the array, respectively.\u003c/p\u003e\u003cp\u003eEach one of the next $$$L$$$ lines contains a word with $$$C$$$ letters.\u003c/p\u003e\u003cp\u003eThese lines are followed by a line containing an integer, $$$N$$$, which is the number of words in the collection of words to follow.\u003c/p\u003e\u003cp\u003eFinally, there are now $$$N$$$ lines, each of which contains a word in the collection.\u003c/p\u003e\u003cp\u003eAll characters in the array and in each word of the collection of words is a capital letter of the English alphabet.\u003c/p\u003e\u003cp\u003eNo two of the $$$N$$$ words in the collection are anagrams of each other. \u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$2 \\le L, C \\le 40$$$. \u003c/li\u003e\u003cli\u003e $$$2 \\le N \\le 20$$$. \u003c/li\u003e\u003cli\u003e The number $$$P$$$ of letters of each of the $$$N$$$ words is in the interval $$$2 \\le P \\le \\min(15, \\max(L, C))$$$. \u003c/li\u003e\u003c/ul\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eThe output consists of a single line that contains an integer corresponding to the number of special cells.\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 5\nXBOIC\nDKIRA\nALBOA\nBHGES\n3\nBOLA\nCASA\nBOI\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\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\u003e3 3\nAAB\nABA\nBAA\n2\nABA\nBBB\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\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 4\nAAAA\nAAAA\n2\nAAA\nBBB\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}