← run

cf-2059-e2

0.000
0/2 tests· algorithms

Proposed solution

```python
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(n)]
    b = [list(map(int, input().split())) for _ in range(n)]
    ans = []
    pos = [0] * (2 * n * m + 1)
    for i in range(n):
        for j in range(m):
            pos[b[i][j]] = i + 1
    for i in range(n):
        for j in range(m):
            x = a[i][j]
            while pos[x] != i + 1:
                ans.append((i + 1, x))
                x, a[i][0] = a[i][0], x
                pos[x] = i + 1
    print(len(ans))
    for i in ans:
        print(i[0], i[1])

def main():
    t = int(input())
    for _ in range(t):
        solve()

if __name__ == "__main__":
    main()
```

Test output (stdout)

FF                                                                       [100%]
=================================== FAILURES ===================================
______________________________ test_cf_2059_e2[0] ______________________________

i = 0

    @pytest.mark.parametrize("i", range(len(_CASES)))
    def test_cf_2059_e2(i):
        c = _CASES[i]
        p = subprocess.run([sys.executable, str(_D / "solution.py")],
                           input=c["input"], capture_output=True, text=True, timeout=15)
        assert p.returncode == 0, f"runtime error: {p.stderr[-800:]}"
>       assert _norm(p.stdout) == _norm(c["output"]), (
            f"input={c['input']!r} expected={c['output']!r} got={p.stdout!r}")
E       AssertionError: input='4\n2 2\n2 6\n3 4\n1 2\n7 8\n1 5\n5 4 1 2 3\n5 4 3 2 1\n3 3\n1 2 3\n4 5 6\n7 8 9\n11 1 2\n12 3 4\n13 5 6\n4 4\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n17 1 2 3\n4 18 5 6\n7 19 8 20\n9 21 22 10\n' expected='3\n1 1\n2 8\n2 7\n5\n1 1\n1 2\n1 3\n1 4\n1 5\n3\n1 11\n2 12\n3 13\n6\n3 20\n2 18\n3 19\n4 22\n4 21\n1 17\n' got='3\n1 6\n2 3\n2 4\n0\n6\n1 3\n2 5\n2 6\n3 7\n3 8\n3 9\n11\n1 4\n2 7\n2 8\n3 9\n3 10\n3 11\n3 12\n4 13\n4 14\n4 15\n4 16\n'
E       assert '3\n1 6\n2 3\...4\n4 15\n4 16' == '3\n1 1\n2 8\...2\n4 21\n1 17'
E         
E           3
E         + 1 6
E         + 2 3
E         + 2 4
E         + 0
E         + 6...
E         
E         ...Full output truncated (41 lines hidden), use '-vv' to show

test_cf_2059_e2.py:20: AssertionError
______________________________ test_cf_2059_e2[1] ______________________________

i = 1

    @pytest.mark.parametrize("i", range(len(_CASES)))
    def test_cf_2059_e2(i):
        c = _CASES[i]
        p = subprocess.run([sys.executable, str(_D / "solution.py")],
                           input=c["input"], capture_output=True, text=True, timeout=15)
        assert p.returncode == 0, f"runtime error: {p.stderr[-800:]}"
>       assert _norm(p.stdout) == _norm(c["output"]), (
            f"input={c['input']!r} expected={c['output']!r} got={p.stdout!r}")
E       AssertionError: input='4\n2 2\n2 6\n3 4\n1 2\n7 8\n1 5\n5 4 1 2 3\n5 4 3 2 1\n3 3\n1 2 3\n4 5 6\n7 8 9\n11 1 2\n12 3 4\n13 5 6\n4 4\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n17 1 2 3\n4 18 5 6\n7 19 8 20\n9 21 22 10' expected='3\n1 1\n2 8\n2 7\n5\n1 1\n1 2\n1 3\n1 4\n1 5\n3\n1 11\n2 12\n3 13\n6\n3 20\n2 18\n3 19\n4 22\n4 21\n1 17' got='3\n1 6\n2 3\n2 4\n0\n6\n1 3\n2 5\n2 6\n3 7\n3 8\n3 9\n11\n1 4\n2 7\n2 8\n3 9\n3 10\n3 11\n3 12\n4 13\n4 14\n4 15\n4 16\n'
E       assert '3\n1 6\n2 3\...4\n4 15\n4 16' == '3\n1 1\n2 8\...2\n4 21\n1 17'
E         
E           3
E         + 1 6
E         + 2 3
E         + 2 4
E         + 0
E         + 6...
E         
E         ...Full output truncated (41 lines hidden), use '-vv' to show

test_cf_2059_e2.py:20: AssertionError
=========================== short test summary info ============================
FAILED test_cf_2059_e2.py::test_cf_2059_e2[0] - AssertionError: input='4\n2 2...
FAILED test_cf_2059_e2.py::test_cf_2059_e2[1] - AssertionError: input='4\n2 2...
2 failed in 0.04s
Self-repair attempts
[
  {
    "total": 2,
    "answer": "```python\nimport sys\nfrom collections import deque\n\ndef solve():\n    input = sys.stdin.readline\n    n, m = map(int, input().split())\n    a = [list(map(int, input().split())) for _ in range(n)]\n    b = [list(map(int, input().split())) for _ in range(n)]\n    ans = []\n    pos = [0] * (2 * n * m + 1)\n    for i in range(n):\n        for j in range(m):\n            pos[b[i][j]] = i + 1\n    for i in range(n):\n        for j in range(m):\n            x = a[i][j]\n            while pos[x] != i + 1:\n                ans.append((i + 1, x))\n                x, a[i][0] = a[i][0], x\n                pos[x] = i + 1\n    print(len(ans))\n    for i in ans:\n        print(i[0], i[1])\n\ndef main():\n    t = int(input())\n    for _ in range(t):\n        solve()\n\nif __name__ == \"__main__\":\n    main()\n```",
    "passed": 0,
    "test_error": "assert _norm(p.stdout) == _norm(c[\"output\"]), (\n            f\"input={c['input']!r} expected={c['output']!r} got={p.stdout!r}\")\nE       AssertionError: input='4\\n2 2\\n2 6\\n3 4\\n1 2\\n7 8\\n1 5\\n5 4 1 2 3\\n5 4 3 2 1\\n3 3\\n1 2 3\\n4 5 6\\n7 8 9\\n11 1 2\\n12 3 4\\n13 5 6\\n4 4\\n1 2 3 4\\n5 6 7 8\\n9 10 11 12\\n13 14 15 16\\n17 1 2 3\\n4 18 5 6\\n7 19 8 20\\n9 21 22 10\\n' expected='3\\n1 1\\n2 8\\n2 7\\n5\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n3\\n1 11\\n2 12\\n3 13\\n6\\n3 20\\n2 18\\n3 19\\n4 22\\n4 21\\n1 17\\n' got='3\\n1 6\\n2 3\\n2 4\\n0\\n6\\n1 3\\n2 5\\n2 6\\n3 7\\n3 8\\n3 9\\n11\\n1 4\\n2 7\\n2 8\\n3 9\\n3 10\\n3 11\\n3 12\\n4 13\\n4 14\\n4 15\\n4 16\\n'\nE       assert '3\\n1 6\\n2 3\\...4\\n4 15\\n4 16' == '3\\n1 1\\n2 8\\...2\\n4 21\\n1 17'\nE         \nE           3\nE         + 1 6\nE         + 2 3\nE         + 2 4\nE         + 0\nE         + 6...\nE         \nE         ...Full output truncated (41 lines hidden), use '-vv' to show\n\ntest_cf_2059_e2.py:20: AssertionError\n______________________________ test_cf_2059_e2[1] ______________________________\n\ni = 1\n\n    @pytest.mark.parametrize(\"i\", range(len(_CASES)))\n    def test_cf_2059_e2(i):\n        c = _CASES[i]\n        p = subprocess.run([sys.executable, str(_D / \"solution.py\")],\n                           input=c[\"input\"], capture_output=True, text=True, timeout=15)\n        assert p.returncode == 0, f\"runtime error: {p.stderr[-800:]}\"\n>       assert _norm(p.stdout) == _norm(c[\"output\"]), (\n            f\"input={c['input']!r} expected={c['output']!r} got={p.stdout!r}\")\nE       AssertionError: input='4\\n2 2\\n2 6\\n3 4\\n1 2\\n7 8\\n1 5\\n5 4 1 2 3\\n5 4 3 2 1\\n3 3\\n1 2 3\\n4 5 6\\n7 8 9\\n11 1 2\\n12 3 4\\n13 5 6\\n4 4\\n1 2 3 4\\n5 6 7 8\\n9 10 11 12\\n13 14 15 16\\n17 1 2 3\\n4 18 5 6\\n7 19 8 20\\n9 21 22 10' expected='3\\n1 1\\n2 8\\n2 7\\n5\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n3\\n1 11\\n2 12\\n3 13\\n6\\n3 20\\n2 18\\n3 19\\n4 22\\n4 21\\n1 17' got='3\\n1 6\\n2 3\\n2 4\\n0\\n6\\n1 3\\n2 5\\n2 6\\n3 7\\n3 8\\n3 9\\n11\\n1 4\\n2 7\\n2 8\\n3 9\\n3 10\\n3 11\\n3 12\\n4 13\\n4 14\\n4 15\\n4 16\\n'\nE       assert '3\\n1 6\\n2 3\\...4\\n4 15\\n4 16' == '3\\n1 1\\n2 8\\...2\\n4 21\\n1 17'\nE         \nE           3\nE         + 1 6\nE         + 2 3\nE         + 2 4\nE         + 0\nE         + 6...\nE         \nE         ...Full output truncated (41 lines hidden), use '-vv' to show\n\ntest_cf_2059_e2.py:20: AssertionError\n=========================== short test summary info ============================\nFAILED test_cf_2059_e2.py::test_cf_2059_e2[0] - AssertionError: input='4\\n2 2...\nFAILED test_cf_2059_e2.py::test_cf_2059_e2[1] - AssertionError: input='4\\n2 2...\n2 failed in 0.04s"
  },
  {
    "total": 2,
    "answer": "```python\nimport sys\nfrom collections import deque\n\ndef solve():\n    input = sys.stdin.readline\n    n, m = map(int, input().split())\n    a = [list(map(int, input().split())) for _ in range(n)]\n    b = [list(map(int, input().split())) for _ in range(n)]\n    ans = []\n    pos = [0] * (2 * n * m + 1)\n    for i in range(n):\n        for j in range(m):\n            pos[b[i][j]] = i + 1\n    for i in range(n):\n        for j in range(m):\n            x = a[i][j]\n            while pos[x] != i + 1:\n                ans.append((i + 1, x))\n                x, a[i][0] = a[i][0], x\n                pos[x] = i + 1\n    print(len(ans))\n    for i in ans:\n        print(i[0], i[1])\n\ndef main():\n    t = int(input())\n    for _ in range(t):\n        solve()\n\nif __name__ == \"__main__\":\n    main()\n```",
    "passed": 0,
    "test_error": "assert _norm(p.stdout) == _norm(c[\"output\"]), (\n            f\"input={c['input']!r} expected={c['output']!r} got={p.stdout!r}\")\nE       AssertionError: input='4\\n2 2\\n2 6\\n3 4\\n1 2\\n7 8\\n1 5\\n5 4 1 2 3\\n5 4 3 2 1\\n3 3\\n1 2 3\\n4 5 6\\n7 8 9\\n11 1 2\\n12 3 4\\n13 5 6\\n4 4\\n1 2 3 4\\n5 6 7 8\\n9 10 11 12\\n13 14 15 16\\n17 1 2 3\\n4 18 5 6\\n7 19 8 20\\n9 21 22 10\\n' expected='3\\n1 1\\n2 8\\n2 7\\n5\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n3\\n1 11\\n2 12\\n3 13\\n6\\n3 20\\n2 18\\n3 19\\n4 22\\n4 21\\n1 17\\n' got='3\\n1 6\\n2 3\\n2 4\\n0\\n6\\n1 3\\n2 5\\n2 6\\n3 7\\n3 8\\n3 9\\n11\\n1 4\\n2 7\\n2 8\\n3 9\\n3 10\\n3 11\\n3 12\\n4 13\\n4 14\\n4 15\\n4 16\\n'\nE       assert '3\\n1 6\\n2 3\\...4\\n4 15\\n4 16' == '3\\n1 1\\n2 8\\...2\\n4 21\\n1 17'\nE         \nE           3\nE         + 1 6\nE         + 2 3\nE         + 2 4\nE         + 0\nE         + 6...\nE         \nE         ...Full output truncated (41 lines hidden), use '-vv' to show\n\ntest_cf_2059_e2.py:20: AssertionError\n______________________________ test_cf_2059_e2[1] ______________________________\n\ni = 1\n\n    @pytest.mark.parametrize(\"i\", range(len(_CASES)))\n    def test_cf_2059_e2(i):\n        c = _CASES[i]\n        p = subprocess.run([sys.executable, str(_D / \"solution.py\")],\n                           input=c[\"input\"], capture_output=True, text=True, timeout=15)\n        assert p.returncode == 0, f\"runtime error: {p.stderr[-800:]}\"\n>       assert _norm(p.stdout) == _norm(c[\"output\"]), (\n            f\"input={c['input']!r} expected={c['output']!r} got={p.stdout!r}\")\nE       AssertionError: input='4\\n2 2\\n2 6\\n3 4\\n1 2\\n7 8\\n1 5\\n5 4 1 2 3\\n5 4 3 2 1\\n3 3\\n1 2 3\\n4 5 6\\n7 8 9\\n11 1 2\\n12 3 4\\n13 5 6\\n4 4\\n1 2 3 4\\n5 6 7 8\\n9 10 11 12\\n13 14 15 16\\n17 1 2 3\\n4 18 5 6\\n7 19 8 20\\n9 21 22 10' expected='3\\n1 1\\n2 8\\n2 7\\n5\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n3\\n1 11\\n2 12\\n3 13\\n6\\n3 20\\n2 18\\n3 19\\n4 22\\n4 21\\n1 17' got='3\\n1 6\\n2 3\\n2 4\\n0\\n6\\n1 3\\n2 5\\n2 6\\n3 7\\n3 8\\n3 9\\n11\\n1 4\\n2 7\\n2 8\\n3 9\\n3 10\\n3 11\\n3 12\\n4 13\\n4 14\\n4 15\\n4 16\\n'\nE       assert '3\\n1 6\\n2 3\\...4\\n4 15\\n4 16' == '3\\n1 1\\n2 8\\...2\\n4 21\\n1 17'\nE         \nE           3\nE         + 1 6\nE         + 2 3\nE         + 2 4\nE         + 0\nE         + 6...\nE         \nE         ...Full output truncated (41 lines hidden), use '-vv' to show\n\ntest_cf_2059_e2.py:20: AssertionError\n=========================== short test summary info ============================\nFAILED test_cf_2059_e2.py::test_cf_2059_e2[0] - AssertionError: input='4\\n2 2...\nFAILED test_cf_2059_e2.py::test_cf_2059_e2[1] - AssertionError: input='4\\n2 2...\n2 failed in 0.04s"
  },
  {
    "total": 2,
    "answer": "```python\nimport sys\nfrom collections import deque\n\ndef solve():\n    input = sys.stdin.readline\n    n, m = map(int, input().split())\n    a = [list(map(int, input().split())) for _ in range(n)]\n    b = [list(map(int, input().split())) for _ in range(n)]\n    ans = []\n    pos = [0] * (2 * n * m + 1)\n    for i in range(n):\n        for j in range(m):\n            pos[b[i][j]] = i + 1\n    for i in range(n):\n        for j in range(m):\n            x = a[i][j]\n            while pos[x] != i + 1:\n                ans.append((i + 1, x))\n                x, a[i][0] = a[i][0], x\n                pos[x] = i + 1\n    print(len(ans))\n    for i in ans:\n        print(i[0], i[1])\n\ndef main():\n    t = int(input())\n    for _ in range(t):\n        solve()\n\nif __name__ == \"__main__\":\n    main()\n```",
    "passed": 0,
    "test_error": ""
  }
]
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.