{"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\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eNastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.\u003c/p\u003e\u003cp\u003eTwo matrices $$$A$$$ and $$$B$$$ are given, each of them has size $$$n \\times m$$$. Nastya can perform the following operation to matrix $$$A$$$ unlimited number of times: \u003c/p\u003e\u003cul\u003e \u003cli\u003e take any square \u003cspan class\u003d\"tex-font-style-it\"\u003esquare submatrix\u003c/span\u003e of $$$A$$$ and transpose it (i.e. the element of the submatrix which was in the $$$i$$$-th row and $$$j$$$-th column of the submatrix will be in the $$$j$$$-th row and $$$i$$$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $$$A$$$). \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eNastya\u0027s task is to check whether it is possible to transform the matrix $$$A$$$ to the matrix $$$B$$$.\u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/7e2d8278dafe7e275d96ea0fa17d4b7f?v\u003d1714975102\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003cspan class\u003d\"tex-font-size-small\"\u003eExample of the operation\u003c/span\u003e \u003c/center\u003e\u003cp\u003eAs it may require a lot of operations, you are asked to answer this question for Nastya.\u003c/p\u003e\u003cp\u003eA \u003cspan class\u003d\"tex-font-style-it\"\u003esquare submatrix\u003c/span\u003e of matrix $$$M$$$ is a matrix which consist of all elements which comes from one of the rows with indeces $$$x, x+1, \\dots, x+k-1$$$ of matrix $$$M$$$ and comes from one of the columns with indeces $$$y, y+1, \\dots, y+k-1$$$ of matrix $$$M$$$. $$$k$$$ is the size of \u003cspan class\u003d\"tex-font-style-it\"\u003esquare submatrix\u003c/span\u003e. In other words, \u003cspan class\u003d\"tex-font-style-it\"\u003esquare submatrix\u003c/span\u003e is the set of elements of source matrix which form a solid square (i.e. without holes).\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains two integers $$$n$$$ and $$$m$$$ separated by space ($$$1 \\leq n, m \\leq 500$$$)\u0026nbsp;— the numbers of rows and columns in $$$A$$$ and $$$B$$$ respectively.\u003c/p\u003e\u003cp\u003eEach of the next $$$n$$$ lines contains $$$m$$$ integers, the $$$j$$$-th number in the $$$i$$$-th of these lines denotes the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$A$$$ ($$$1 \\leq A_{ij} \\leq 10^{9}$$$).\u003c/p\u003e\u003cp\u003eEach of the next $$$n$$$ lines contains $$$m$$$ integers, the $$$j$$$-th number in the $$$i$$$-th of these lines denotes the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$B$$$ ($$$1 \\leq B_{ij} \\leq 10^{9}$$$).\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eYES\u003c/span\u003e\" (without quotes) if it is possible to transform $$$A$$$ to $$$B$$$ and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eNO\u003c/span\u003e\" (without quotes) otherwise.\u003c/p\u003e\u003cp\u003eYou can print each letter in any case (upper or lower).\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\u003e2 2\n1 1\n6 1\n1 6\n1 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eYES\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 2\n4 4\n4 5\n5 4\n4 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eNO\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\n1 2 3\n4 5 6\n7 8 9\n1 4 7\n2 5 6\n3 8 9\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eYES\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eConsider the third example. The matrix $$$A$$$ initially looks as follows.\u003c/p\u003e\u003cp\u003e$$$$$$ \\begin{bmatrix} 1 \u0026amp; 2 \u0026amp; 3\\\\ 4 \u0026amp; 5 \u0026amp; 6\\\\ 7 \u0026amp; 8 \u0026amp; 9 \\end{bmatrix} $$$$$$\u003c/p\u003e\u003cp\u003eThen we choose the whole matrix as transposed submatrix and it becomes\u003c/p\u003e\u003cp\u003e$$$$$$ \\begin{bmatrix} 1 \u0026amp; 4 \u0026amp; 7\\\\ 2 \u0026amp; 5 \u0026amp; 8\\\\ 3 \u0026amp; 6 \u0026amp; 9 \\end{bmatrix} $$$$$$\u003c/p\u003e\u003cp\u003eThen we transpose the submatrix with corners in cells $$$(2, 2)$$$ and $$$(3, 3)$$$. \u003c/p\u003e\u003cp\u003e$$$$$$ \\begin{bmatrix} 1 \u0026amp; 4 \u0026amp; 7\\\\ 2 \u0026amp; \\textbf{5} \u0026amp; \\textbf{8}\\\\ 3 \u0026amp; \\textbf{6} \u0026amp; \\textbf{9} \\end{bmatrix} $$$$$$\u003c/p\u003e\u003cp\u003eSo matrix becomes\u003c/p\u003e\u003cp\u003e$$$$$$ \\begin{bmatrix} 1 \u0026amp; 4 \u0026amp; 7\\\\ 2 \u0026amp; 5 \u0026amp; 6\\\\ 3 \u0026amp; 8 \u0026amp; 9 \\end{bmatrix} $$$$$$\u003c/p\u003e\u003cp\u003eand it is $$$B$$$.\u003c/p\u003e"}}]}