[
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.md",
    "content": "---\nname: Bug report\nabout: Create a report to help us improve\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Describe the bug**\nA clear and concise description of what the bug is.\n\n**Additional context**\nAdd any other context about the problem here.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "content": "---\nname: Feature request\nabout: Suggest an idea for this project\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Is your feature request related to a problem? Please describe.**\nA clear and concise description of what the problem is. Ex. I'm always frustrated when [...]\n\n**Describe the solution you'd like**\nA clear and concise description of what you want to happen.\n\n**Describe alternatives you've considered**\nA clear and concise description of any alternative solutions or features you've considered.\n\n**Additional context**\nAdd any other context or screenshots about the feature request here.\n"
  },
  {
    "path": ".github/workflows/sanitize.yml",
    "content": "name: sanitize\n\non: push\n\njobs:\n  build-sanitize:\n    runs-on: ubuntu-latest\n\n    steps:\n    - uses: actions/checkout@v1\n\n    - name: Set up Python\n      uses: actions/setup-python@v1\n\n    - name: Install dependencies\n      run: pip3 install -U git+https://github.com/online-judge-tools/verification-helper@master\n\n    - name: Run tests\n      env:\n        YUKICODER_TOKEN: ${{ secrets.YUKICODER_TOKEN }}\n      run: oj-verify --config-file .verify-helper/sanitize.toml run -j 2 --timeout 3600 --tle 600\n"
  },
  {
    "path": ".github/workflows/verify.yml",
    "content": "name: verify\n\non: push\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n\n    permissions:\n      contents: write\n\n    steps:\n    - uses: actions/checkout@v1\n\n    - name: Set up Python\n      uses: actions/setup-python@v1\n\n    - name: Install dependencies\n      run: pip3 install -U git+https://github.com/online-judge-tools/verification-helper@master\n\n    - name: Run tests\n      env:\n        GH_PAT: ${{ secrets.GH_PAT }}\n        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n        YUKICODER_TOKEN: ${{ secrets.YUKICODER_TOKEN }}\n      run: oj-verify all -j 2\n"
  },
  {
    "path": ".gitignore",
    "content": "#Do NOT edit this file manually. Use ./.gitignore_gen.sh > .gitignore\n### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Global/Vim.gitignore\n\n# Swap\n[._]*.s[a-v][a-z]\n[._]*.sw[a-p]\n[._]s[a-v][a-z]\n[._]sw[a-p]\n\n# Session\nSession.vim\n\n# Temporary\n.netrwhist\n*~\n# Auto-generated tag files\ntags\n\n\n### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Global/Emacs.gitignore\n\n# -*- mode: gitignore; -*-\n*~\n\\#*\\#\n/.emacs.desktop\n/.emacs.desktop.lock\n*.elc\nauto-save-list\ntramp\n.\\#*\n\n# Org-mode\n.org-id-locations\n*_archive\n\n# flymake-mode\n*_flymake.*\n\n# eshell files\n/eshell/history\n/eshell/lastdir\n\n# elpa packages\n/elpa/\n\n# reftex files\n*.rel\n\n# AUCTeX auto folder\n/auto/\n\n# cask packages\n.cask/\ndist/\n\n# Flycheck\nflycheck_*.el\n\n# server auth directory\n/server/\n\n# projectiles files\n.projectile\n\n# directory configuration\n.dir-locals.el\n\n\n### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/C.gitignore\n\n# Prerequisites\n*.d\n\n# Object files\n*.o\n*.ko\n*.obj\n*.elf\n\n# Linker output\n*.ilk\n*.map\n*.exp\n\n# Precompiled Headers\n*.gch\n*.pch\n\n# Libraries\n*.lib\n*.a\n*.la\n*.lo\n\n# Shared objects (inc. Windows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n*.i*86\n*.x86_64\n*.hex\n\n# Debug files\n*.dSYM/\n*.su\n*.idb\n*.pdb\n\n# Kernel Module Compile Results\n*.mod*\n*.cmd\n.tmp_versions/\nmodules.order\nModule.symvers\nMkfile.old\ndkms.conf\n\n\n### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/C++.gitignore\n\n# Prerequisites\n*.d\n\n# Compiled Object files\n*.slo\n*.lo\n*.o\n*.obj\n\n# Precompiled Headers\n*.gch\n*.pch\n\n# Compiled Dynamic libraries\n*.so\n*.dylib\n*.dll\n\n# Fortran module files\n*.mod\n*.smod\n\n# Compiled Static libraries\n*.lai\n*.la\n*.a\n*.lib\n\n# Executables\n*.exe\n*.out\n*.app\n\n\n### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Python.gitignore\n\n# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n*$py.class\n\n# C extensions\n*.so\n\n# Distribution / packaging\n.Python\nbuild/\ndevelop-eggs/\ndist/\ndownloads/\neggs/\n.eggs/\nlib/\nlib64/\nparts/\nsdist/\nvar/\nwheels/\n*.egg-info/\n.installed.cfg\n*.egg\nMANIFEST\n\n# PyInstaller\n#  Usually these files are written by a python script from a template\n#  before PyInstaller builds the exe, so as to inject date/other infos into it.\n*.manifest\n*.spec\n\n# Installer logs\npip-log.txt\npip-delete-this-directory.txt\n\n# Unit test / coverage reports\nhtmlcov/\n.tox/\n.coverage\n.coverage.*\n.cache\nnosetests.xml\ncoverage.xml\n*.cover\n.hypothesis/\n.pytest_cache/\n\n# Translations\n*.mo\n*.pot\n\n# Django stuff:\n*.log\nlocal_settings.py\ndb.sqlite3\n\n# Flask stuff:\ninstance/\n.webassets-cache\n\n# Scrapy stuff:\n.scrapy\n\n# Sphinx documentation\ndocs/_build/\n\n# PyBuilder\ntarget/\n\n# Jupyter Notebook\n.ipynb_checkpoints\n\n# pyenv\n.python-version\n\n# celery beat schedule file\ncelerybeat-schedule\n\n# SageMath parsed files\n*.sage.py\n\n# Environments\n.env\n.venv\nenv/\nvenv/\nENV/\nenv.bak/\nvenv.bak/\n\n# Spyder project settings\n.spyderproject\n.spyproject\n\n# Rope project settings\n.ropeproject\n\n# mkdocs documentation\n/site\n\n# mypy\n.mypy_cache/\n\n\n### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Java.gitignore\n\n# Compiled class file\n*.class\n\n# Log file\n*.log\n\n# BlueJ files\n*.ctxt\n\n# Mobile Tools for Java (J2ME)\n.mtj.tmp/\n\n# Package Files #\n*.jar\n*.war\n*.ear\n*.zip\n*.tar.gz\n*.rar\n\n# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml\nhs_err_pid*\n\n\nsetup.*\nbin\nrime-out\nlibrary-checker-problems\n.DS_Store\nin\nin1\nin2\nin3\nin4\nin5\n*.in\n"
  },
  {
    "path": ".gitignore_gen.sh",
    "content": "#!/bin/bash\necho \"#Do NOT edit this file manually. Use ./.gitignore_gen.sh > .gitignore\"\ngibo dump Vim Emacs C C++ Python Java\necho \"setup.*\"\necho \"bin\"\necho \"rime-out\"\necho \"library-checker-problems\"\necho \".DS_Store\"\necho \"in\"\necho \"in1\"\necho \"in2\"\necho \"in3\"\necho \"in4\"\necho \"in5\"\necho \"*.in\"\n"
  },
  {
    "path": ".verify-helper/config.toml",
    "content": "[[languages.cpp.environments]]\nCXX = \"g++\"\n\n[[languages.cpp.environments]]\nCXX = \"clang++\"\n"
  },
  {
    "path": ".verify-helper/docs/_config.yml",
    "content": "exclude: [\"./heuristic/\", \"./leetcode/\", \"./test/aoj/2432.ignore.cpp\", \"test/aoj/GRL_4_B.ignore.cpp\"]\n"
  },
  {
    "path": ".verify-helper/local.toml",
    "content": "[[languages.cpp.environments]]\nCXX = \"g++\"\n"
  },
  {
    "path": ".verify-helper/sanitize.toml",
    "content": "[[languages.cpp.environments]]\nCXX = \"g++\"\nCXXFLAGS = [\"-std=c++17\", \"-Wall\", \"-g\", \"-DSANITIZE\", \"-fsanitize=undefined\", \"-D_GLIBCXX_DEBUG\"]\n\n[[languages.cpp.environments]]\nCXX = \"clang++\"\nCXXFLAGS = [\"-std=c++17\", \"-Wall\", \"-g\", \"-DSANITIZE\", \"-fsanitize=undefined\", \"-D_GLIBCXX_DEBUG\"]\n"
  },
  {
    "path": ".verify-helper/timestamps.local.json.20201106",
    "content": "{\n\"test/aoj/0109.test.cpp\": \"2020-10-27 13:22:02 +0900\",\n\"test/aoj/0168.test.cpp\": \"2020-10-13 16:41:33 +0900\",\n\"test/aoj/0233.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0294.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0314.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/0343.test.cpp\": \"2020-10-27 12:52:35 +0900\",\n\"test/aoj/0367.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/0367.test.cpp\": \"2020-10-27 18:05:34 +0900\",\n\"test/aoj/0367.toptree.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/0377.test.cpp\": \"2020-10-27 15:55:39 +0900\",\n\"test/aoj/0391.test.cpp\": \"2020-11-02 16:39:41 +0900\",\n\"test/aoj/0403.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/0415.test.cpp\": \"2020-10-27 15:55:39 +0900\",\n\"test/aoj/0422.test.cpp\": \"2020-10-27 16:29:08 +0900\",\n\"test/aoj/0423.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0424.test.cpp\": \"2020-10-27 16:21:44 +0900\",\n\"test/aoj/0425.test.cpp\": \"2020-10-27 12:29:05 +0900\",\n\"test/aoj/0437.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/0438.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/0439.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/aoj/0502.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/0558.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0563.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0596.test.cpp\": \"2020-10-27 16:43:37 +0900\",\n\"test/aoj/0613.test.cpp\": \"2020-10-27 12:54:24 +0900\",\n\"test/aoj/1069.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/1197.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/1254.test.cpp\": \"2020-10-26 14:43:47 +0900\",\n\"test/aoj/1293.test.cpp\": \"2020-10-27 16:18:38 +0900\",\n\"test/aoj/1300.test.cpp\": \"2020-10-27 13:20:54 +0900\",\n\"test/aoj/1308.test.cpp\": \"2020-10-27 15:57:10 +0900\",\n\"test/aoj/1312.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/1328.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/1338.test.cpp\": \"2020-10-07 14:37:56 +0900\",\n\"test/aoj/1508.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/1549.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/aoj/1579.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/1595.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/1595.test.cpp\": \"2020-10-27 16:29:49 +0900\",\n\"test/aoj/1595.toptree.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/1599.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/1607.test.cpp\": \"2020-10-27 12:28:55 +0900\",\n\"test/aoj/1613.test.cpp\": \"2020-10-27 12:28:43 +0900\",\n\"test/aoj/1615.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/1630.test.cpp\": \"2020-10-27 17:57:02 +0900\",\n\"test/aoj/2060.test.cpp\": \"2020-10-27 16:03:41 +0900\",\n\"test/aoj/2187.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/2212.test.cpp\": \"2020-10-07 14:42:51 +0900\",\n\"test/aoj/2222.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/2230.test.cpp\": \"2020-10-27 16:28:23 +0900\",\n\"test/aoj/2235.test.cpp\": \"2020-10-27 18:02:37 +0900\",\n\"test/aoj/2257.test.cpp\": \"2020-10-07 14:42:51 +0900\",\n\"test/aoj/2270.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/aoj/2286.test.cpp\": \"2020-10-27 16:28:50 +0900\",\n\"test/aoj/2290.test.cpp\": \"2020-10-27 12:29:05 +0900\",\n\"test/aoj/2292.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/2294.test.cpp\": \"2020-10-27 12:29:08 +0900\",\n\"test/aoj/2308.test.cpp\": \"2020-10-27 15:49:25 +0900\",\n\"test/aoj/2309.tarjan.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/2309.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/2313.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/2324.test.cpp\": \"2020-10-27 15:54:31 +0900\",\n\"test/aoj/2328.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/2359.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/2397.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/2405.test.cpp\": \"2020-10-27 15:54:50 +0900\",\n\"test/aoj/2415.knuthyao.test.cpp\": \"2020-10-27 12:47:14 +0900\",\n\"test/aoj/2415.test.cpp\": \"2020-10-27 12:59:47 +0900\",\n\"test/aoj/2444.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/2450.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/2450.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/2488.test.cpp\": \"2020-10-27 12:47:14 +0900\",\n\"test/aoj/2513.test.cpp\": \"2020-10-27 16:19:34 +0900\",\n\"test/aoj/2560.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/2563.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/2603.test.cpp\": \"2020-10-27 12:32:38 +0900\",\n\"test/aoj/2624.test.cpp\": \"2020-10-27 15:57:10 +0900\",\n\"test/aoj/2627.test.cpp\": \"2020-10-27 18:00:48 +0900\",\n\"test/aoj/2636.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/2644.test.cpp\": \"2020-10-27 19:01:32 +0900\",\n\"test/aoj/2646.test.cpp\": \"2020-10-27 13:57:14 +0900\",\n\"test/aoj/2647.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/2659.test.cpp\": \"2020-10-27 16:28:57 +0900\",\n\"test/aoj/2667.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/2674.count.test.cpp\": \"2020-10-27 18:05:48 +0900\",\n\"test/aoj/2674.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/aoj/2679.test.cpp\": \"2020-10-07 13:03:03 +0900\",\n\"test/aoj/2711.test.cpp\": \"2020-10-27 19:01:32 +0900\",\n\"test/aoj/2720.test.cpp\": \"2020-10-24 13:43:25 +0900\",\n\"test/aoj/2725.test.cpp\": \"2020-10-27 12:59:18 +0900\",\n\"test/aoj/2736.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/2790.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/aoj/2842.BIT2D.test.cpp\": \"2020-10-27 12:59:35 +0900\",\n\"test/aoj/2842.test.cpp\": \"2020-10-27 18:05:43 +0900\",\n\"test/aoj/2871.test.cpp\": \"2020-10-27 19:19:44 +0900\",\n\"test/aoj/2872.test.cpp\": \"2020-10-27 16:28:23 +0900\",\n\"test/aoj/2890.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/2934.test.cpp\": \"2020-10-27 13:21:18 +0900\",\n\"test/aoj/2948.test.cpp\": \"2020-10-27 15:53:30 +0900\",\n\"test/aoj/2951.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/2959.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/2970.test.cpp\": \"2020-10-27 16:28:57 +0900\",\n\"test/aoj/2971.test.cpp\": \"2020-10-27 17:58:32 +0900\",\n\"test/aoj/2975.test.cpp\": \"2020-10-27 12:59:18 +0900\",\n\"test/aoj/2977.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/2979.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/2983.test.cpp\": \"2020-10-27 16:18:21 +0900\",\n\"test/aoj/2985.garner.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/2985.test.cpp\": \"2020-10-27 16:52:54 +0900\",\n\"test/aoj/2995.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/3024.test.cpp\": \"2020-10-27 13:26:17 +0900\",\n\"test/aoj/3033.test.cpp\": \"2020-10-27 19:01:32 +0900\",\n\"test/aoj/3035.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/3037.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/3047.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/3053.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/3058.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/3062.test.cpp\": \"2020-10-24 13:16:03 +0900\",\n\"test/aoj/3063.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/aoj/3069.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/3072.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/3073.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/3074.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/3081.test.cpp\": \"2020-10-27 13:20:33 +0900\",\n\"test/aoj/3084.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/aoj/3086.test.cpp\": \"2020-10-27 19:24:14 +0900\",\n\"test/aoj/3102.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/3112.test.cpp\": \"2020-10-27 19:01:32 +0900\",\n\"test/aoj/3117.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/3120.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/3138.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/3142.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/aoj/3143.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/3148.test.cpp\": \"2020-10-27 16:29:49 +0900\",\n\"test/aoj/3168.test.cpp\": \"2020-10-27 16:19:34 +0900\",\n\"test/aoj/3183.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/3198.test.cpp\": \"2020-10-27 16:19:34 +0900\",\n\"test/aoj/3208.test.cpp\": \"2020-10-30 12:17:32 +0900\",\n\"test/aoj/3506.test.cpp\": \"2020-10-27 12:38:29 +0900\",\n\"test/aoj/ALDS1_10_C.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/ALDS1_14_B.knuthmorrispratt.test.cpp\": \"2020-10-27 13:21:30 +0900\",\n\"test/aoj/ALDS1_14_B.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/ALDS1_14_C.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/ALDS1_15_B.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/ALDS1_1_C.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/ALDS1_9_C.test.cpp\": \"2020-10-27 12:59:47 +0900\",\n\"test/aoj/DPL_1_E.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/DPL_3_B.test.cpp\": \"2020-10-27 12:31:57 +0900\",\n\"test/aoj/DPL_3_C.test.cpp\": \"2020-10-27 12:31:57 +0900\",\n\"test/aoj/DPL_5_A.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_B.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_C.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_D.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_E.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_F.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_G.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_H.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_I.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_J.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_K.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_L.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DSL_1_A.quickfind.test.cpp\": \"2020-10-27 19:24:17 +0900\",\n\"test/aoj/DSL_1_A.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/DSL_1_B.test.cpp\": \"2020-10-27 19:25:22 +0900\",\n\"test/aoj/DSL_2_A.test.cpp\": \"2020-10-27 18:05:34 +0900\",\n\"test/aoj/DSL_2_B.test.cpp\": \"2020-10-27 12:53:16 +0900\",\n\"test/aoj/DSL_2_C.test.cpp\": \"2020-10-27 19:22:46 +0900\",\n\"test/aoj/DSL_2_D.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/DSL_2_E.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/DSL_2_F.bbst.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/DSL_2_F.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/DSL_2_G.bbst.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/DSL_2_H.bbst.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/DSL_2_H.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/DSL_2_I.bbst.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/DSL_2_I.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/DSL_3_D.cartesiantree.test.cpp\": \"2020-10-27 16:42:28 +0900\",\n\"test/aoj/DSL_3_D.disjointsparsetable.test.cpp\": \"2020-10-27 19:24:22 +0900\",\n\"test/aoj/DSL_3_D.slidingwindowaggregation.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/DSL_3_D.sparsetable.test.cpp\": \"2020-10-27 19:24:14 +0900\",\n\"test/aoj/DSL_3_D.test.cpp\": \"2020-10-27 12:54:24 +0900\",\n\"test/aoj/GRL_1_A.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/GRL_1_B.test.cpp\": \"2020-10-27 16:00:51 +0900\",\n\"test/aoj/GRL_2_A.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/GRL_2_B.tarjan.test.cpp\": \"2020-10-27 18:03:06 +0900\",\n\"test/aoj/GRL_2_B.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/GRL_3_A.test.cpp\": \"2020-10-27 15:53:46 +0900\",\n\"test/aoj/GRL_3_B.test.cpp\": \"2020-10-27 15:53:46 +0900\",\n\"test/aoj/GRL_5_A.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/GRL_5_A.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/GRL_5_C.lca.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/GRL_5_C.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/aoj/GRL_5_D.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/GRL_5_D.test.cpp\": \"2020-10-27 19:19:29 +0900\",\n\"test/aoj/GRL_5_E.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/GRL_6_A.test.cpp\": \"2020-10-27 18:00:21 +0900\",\n\"test/aoj/GRL_6_B.test.cpp\": \"2020-10-07 13:03:03 +0900\",\n\"test/aoj/GRL_7_A.test.cpp\": \"2020-10-27 16:19:34 +0900\",\n\"test/aoj/ITP1_11_A.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/ITP1_11_B.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/ITP1_11_C.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/ITP1_11_D.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/NTL_1_A.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/NTL_1_B.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/NTL_1_D.test.cpp\": \"2020-10-24 12:57:13 +0900\",\n\"test/aoj/NTL_1_E.test.cpp\": \"2020-10-27 16:28:57 +0900\",\n\"test/aoj/NTL_2_A.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_B.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_C.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_D.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_E.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_F.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/geometry/2334.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/geometry/2448.test.cpp\": \"2020-10-27 12:47:27 +0900\",\n\"test/aoj/geometry/2454.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/3049.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/geometry/3056.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/geometry/CGL_1_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_1_B.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_1_C.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_2_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_2_B.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_2_C.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_2_D.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/geometry/CGL_3_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_3_B.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_3_C.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_4_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_4_B.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_4_C.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_5_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_6_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_D.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_E.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_F.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_G.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_H.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/geometry/CGL_7_I.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/yosupo/assignment.test.cpp\": \"2020-10-27 16:28:23 +0900\",\n\"test/yosupo/associative_array.test.cpp\": \"2020-10-27 12:28:01 +0900\",\n\"test/yosupo/bernoulli_number.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/bipartitematching.test.cpp\": \"2020-10-27 16:21:44 +0900\",\n\"test/yosupo/cartesian_tree.test.cpp\": \"2020-10-27 16:42:28 +0900\",\n\"test/yosupo/convolution_mod.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/convolution_mod_1000000007.garner.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/convolution_mod_1000000007.test.cpp\": \"2020-10-27 16:52:54 +0900\",\n\"test/yosupo/discrete_logarithm_mod.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/dominatortree.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/dynamic_tree_vertex_add_path_sum.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/yosupo/dynamic_tree_vertex_add_subtree_sum.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/yosupo/dynamic_tree_vertex_add_subtree_sum.toptree.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yosupo/dynamic_tree_vertex_set_path_composite.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/yosupo/dynamic_tree_vertex_set_path_composite.toptree.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yosupo/enumerate_primes.test.cpp\": \"2020-10-07 11:58:48 +0900\",\n\"test/yosupo/enumerate_triangles.test.cpp\": \"2020-10-27 16:43:59 +0900\",\n\"test/yosupo/exp_of_formal_power_series.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/find_linear_recurrence.test.cpp\": \"2020-10-27 16:43:02 +0900\",\n\"test/yosupo/frequency_table_of_tree_distance.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/yosupo/inv_of_formal_power_series.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/kth_root_integer.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/lca.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/yosupo/lca.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/yosupo/line_add_get_min.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/log_of_formal_power_series.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/manhattanmst.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/yosupo/many_aplusb.test.cpp\": \"2020-10-27 12:27:57 +0900\",\n\"test/yosupo/matrix_det.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/yosupo/maximum_independent_set.test.cpp\": \"2020-10-27 15:53:30 +0900\",\n\"test/yosupo/min_cost_b_flow.test.cpp\": \"2020-10-27 16:28:23 +0900\",\n\"test/yosupo/montmort_number_mod.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/multipoint_evaluation.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/number_of_substrings.test.cpp\": \"2020-10-27 19:01:32 +0900\",\n\"test/yosupo/partition_function.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/persistent_queue.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/yosupo/point_add_range_sum.test.cpp\": \"2020-10-27 12:52:35 +0900\",\n\"test/yosupo/point_add_rectangle_sum.test.cpp\": \"2020-10-27 18:05:43 +0900\",\n\"test/yosupo/point_set_range_composite.test.cpp\": \"2020-10-27 18:05:34 +0900\",\n\"test/yosupo/polynomial_interpolation.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/polynomial_taylor_shift.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/pow_of_formal_power_series.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/queue_operate_all_composite.test.cpp\": \"2020-10-27 16:28:39 +0900\",\n\"test/yosupo/range_affine_range_sum.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/yosupo/range_kth_smallest.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yosupo/rectangle_sum.test.cpp\": \"2020-10-27 18:05:43 +0900\",\n\"test/yosupo/runenumerate.test.cpp\": \"2020-10-27 13:20:33 +0900\",\n\"test/yosupo/scc.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/yosupo/segment_add_get_min.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/set_xor_min.test.cpp\": \"2020-10-27 12:53:16 +0900\",\n\"test/yosupo/shortest_path.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/sort_points_by_argument.test.cpp\": \"2020-10-27 16:29:27 +0900\",\n\"test/yosupo/sqrt_mod.test.cpp\": \"2020-10-27 16:02:40 +0900\",\n\"test/yosupo/sqrt_of_formal_power_series.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/static_range_inversions_query.test.cpp\": \"2020-10-27 12:52:35 +0900\",\n\"test/yosupo/static_range_sum.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/staticrmq.disjointsparsetable.test.cpp\": \"2020-10-27 19:24:22 +0900\",\n\"test/yosupo/staticrmq.sparsetable.test.cpp\": \"2020-10-27 19:24:14 +0900\",\n\"test/yosupo/stirling_number_of_the_first_kind.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/stirling_number_of_the_second_kind.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/suffixarray.test.cpp\": \"2020-10-27 19:01:32 +0900\",\n\"test/yosupo/sum_of_floor_of_linear.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/tetration_mod.test.cpp\": \"2020-10-27 13:23:08 +0900\",\n\"test/yosupo/tree_decomposition_width_2.test.cpp\": \"2020-10-27 15:54:50 +0900\",\n\"test/yosupo/tree_diameter.test.cpp\": \"2020-10-27 12:47:27 +0900\",\n\"test/yosupo/two_edge_connected_components.test.cpp\": \"2020-10-27 15:55:39 +0900\",\n\"test/yosupo/two_sat.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/yosupo/unionfind.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/yosupo/vertex_add_path_sum.test.cpp\": \"2020-10-28 14:04:34 +0900\",\n\"test/yosupo/vertex_add_subtree_sum.test.cpp\": \"2020-10-27 19:19:44 +0900\",\n\"test/yosupo/zalgorithm.test.cpp\": \"2020-10-27 13:20:33 +0900\",\n\"test/yukicoder/0022.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/yukicoder/0104.test.cpp\": \"2020-10-27 16:43:02 +0900\",\n\"test/yukicoder/0143.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/yukicoder/0222.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yukicoder/0399.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/yukicoder/0444.test.cpp\": \"2020-10-27 16:52:54 +0900\",\n\"test/yukicoder/0472.test.cpp\": \"2020-10-27 13:23:08 +0900\",\n\"test/yukicoder/0831.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/yukicoder/1504.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yukicoder/1580.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yukicoder/1665.test.cpp\": \"2020-10-27 16:28:50 +0900\",\n\"test/yukicoder/1732.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yukicoder/1923.test.cpp\": \"2020-10-27 12:54:24 +0900\",\n\"test/yukicoder/1937.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yukicoder/1948.test.cpp\": \"2020-10-27 12:32:58 +0900\",\n\"test/yukicoder/1950.test.cpp\": \"2020-10-27 12:32:58 +0900\",\n\"test/yukicoder/1973.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/yukicoder/2063.test.cpp\": \"2020-10-27 18:05:43 +0900\",\n\"test/yukicoder/2085.test.cpp\": \"2020-10-27 16:29:49 +0900\",\n\"test/yukicoder/2113.test.cpp\": \"2020-10-27 12:32:58 +0900\",\n\"test/yukicoder/2125.test.cpp\": \"2020-10-27 12:52:35 +0900\",\n\"test/yukicoder/2147.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yukicoder/2587.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yukicoder/2600.test.cpp\": \"2020-10-27 12:51:44 +0900\",\n\"test/yukicoder/2744.test.cpp\": \"2020-10-27 16:52:54 +0900\",\n\"test/yukicoder/2772.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/yukicoder/3211.test.cpp\": \"2020-10-27 16:43:02 +0900\",\n\"test/yukicoder/3227.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yukicoder/3405.test.cpp\": \"2020-11-02 16:12:34 +0900\",\n\"test/yukicoder/3407.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/yukicoder/3453.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yukicoder/3592.test.cpp\": \"2020-10-27 19:25:22 +0900\",\n\"test/yukicoder/3912.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/yukicoder/3961.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/yukicoder/4072.test.cpp\": \"2020-10-27 19:24:22 +0900\",\n\"test/yukicoder/4271.test.cpp\": \"2020-10-27 16:42:52 +0900\",\n\"test/yukicoder/4387.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/yukicoder/4474.test.cpp\": \"2020-10-24 13:16:03 +0900\",\n\"test/yukicoder/4569.test.cpp\": \"2020-10-27 16:29:08 +0900\",\n\"test/yukicoder/4706.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yukicoder/4778.test.cpp\": \"2020-10-27 12:29:12 +0900\",\n\"test/yukicoder/4852.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/yukicoder/4862.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yukicoder/4918.test.cpp\": \"2020-10-27 12:28:47 +0900\",\n\"test/yukicoder/4941.test.cpp\": \"2020-10-07 14:35:46 +0900\",\n\"test/yukicoder/5011.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/yukicoder/5223.test.cpp\": \"2020-10-27 16:18:54 +0900\"\n}"
  },
  {
    "path": ".verify-helper/timestamps.local.json.20210324",
    "content": "{\n\"test/aoj/0109.test.cpp\": \"2020-12-19 16:43:05 +0900\",\n\"test/aoj/0168.test.cpp\": \"2020-12-20 13:43:25 +0900\",\n\"test/aoj/0233.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0294.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0314.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/0343.test.cpp\": \"2020-10-27 12:52:35 +0900\",\n\"test/aoj/0367.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/0367.test.cpp\": \"2021-02-05 14:58:50 +0900\",\n\"test/aoj/0367.toptree.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/0377.test.cpp\": \"2020-10-27 15:55:39 +0900\",\n\"test/aoj/0391.test.cpp\": \"2020-11-02 16:39:41 +0900\",\n\"test/aoj/0402.test.cpp\": \"2020-12-16 13:02:24 +0900\",\n\"test/aoj/0403.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/0415.test.cpp\": \"2020-10-27 15:55:39 +0900\",\n\"test/aoj/0422.test.cpp\": \"2020-10-27 16:29:08 +0900\",\n\"test/aoj/0423.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0424.test.cpp\": \"2020-10-27 16:21:44 +0900\",\n\"test/aoj/0425.test.cpp\": \"2020-10-27 12:29:05 +0900\",\n\"test/aoj/0437.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/0438.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/0439.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/aoj/0502.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/0558.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0563.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/0596.test.cpp\": \"2020-10-27 16:43:37 +0900\",\n\"test/aoj/0613.test.cpp\": \"2020-10-27 12:54:24 +0900\",\n\"test/aoj/1069.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/1197.test.cpp\": \"2020-11-15 18:49:57 +0900\",\n\"test/aoj/1254.test.cpp\": \"2020-10-26 14:43:47 +0900\",\n\"test/aoj/1293.test.cpp\": \"2020-10-27 16:18:38 +0900\",\n\"test/aoj/1300.test.cpp\": \"2020-10-27 13:20:54 +0900\",\n\"test/aoj/1308.test.cpp\": \"2020-10-27 15:57:10 +0900\",\n\"test/aoj/1312.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/1328.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/1338.test.cpp\": \"2020-10-07 14:37:56 +0900\",\n\"test/aoj/1508.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/1549.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/aoj/1579.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/1595.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/1595.test.cpp\": \"2020-10-27 16:29:49 +0900\",\n\"test/aoj/1595.toptree.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/1599.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/1607.test.cpp\": \"2020-10-27 12:28:55 +0900\",\n\"test/aoj/1613.test.cpp\": \"2020-10-27 12:28:43 +0900\",\n\"test/aoj/1615.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/1630.test.cpp\": \"2020-10-27 17:57:02 +0900\",\n\"test/aoj/1642.test.cpp\": \"2020-11-19 16:59:17 +0900\",\n\"test/aoj/2060.test.cpp\": \"2020-10-27 16:03:41 +0900\",\n\"test/aoj/2187.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/2212.test.cpp\": \"2021-01-22 18:37:25 +0900\",\n\"test/aoj/2222.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/2230.test.cpp\": \"2020-10-27 16:28:23 +0900\",\n\"test/aoj/2235.test.cpp\": \"2020-10-27 18:02:37 +0900\",\n\"test/aoj/2257.test.cpp\": \"2021-01-22 18:37:25 +0900\",\n\"test/aoj/2270.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/aoj/2286.test.cpp\": \"2020-10-27 16:28:50 +0900\",\n\"test/aoj/2290.test.cpp\": \"2020-10-27 12:29:05 +0900\",\n\"test/aoj/2292.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/2294.test.cpp\": \"2020-10-27 12:29:08 +0900\",\n\"test/aoj/2308.test.cpp\": \"2020-10-27 15:49:25 +0900\",\n\"test/aoj/2309.tarjan.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/2309.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/2313.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/2324.test.cpp\": \"2020-10-27 15:54:31 +0900\",\n\"test/aoj/2328.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/2359.test.cpp\": \"2020-11-15 18:14:06 +0900\",\n\"test/aoj/2397.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/2405.test.cpp\": \"2020-10-27 15:54:50 +0900\",\n\"test/aoj/2415.knuthyao.test.cpp\": \"2020-10-27 12:47:14 +0900\",\n\"test/aoj/2415.test.cpp\": \"2020-10-27 12:59:47 +0900\",\n\"test/aoj/2444.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/2446.test.cpp\": \"2020-12-16 13:02:24 +0900\",\n\"test/aoj/2450.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/2450.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/2488.test.cpp\": \"2020-10-27 12:47:14 +0900\",\n\"test/aoj/2513.test.cpp\": \"2020-10-27 16:19:34 +0900\",\n\"test/aoj/2560.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/2563.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/2603.test.cpp\": \"2021-03-05 12:18:38 +0900\",\n\"test/aoj/2624.test.cpp\": \"2020-10-27 15:57:10 +0900\",\n\"test/aoj/2627.test.cpp\": \"2020-10-27 18:00:48 +0900\",\n\"test/aoj/2636.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/2644.test.cpp\": \"2021-02-05 14:58:50 +0900\",\n\"test/aoj/2646.test.cpp\": \"2020-10-27 13:57:14 +0900\",\n\"test/aoj/2647.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/2659.test.cpp\": \"2020-11-13 17:53:54 +0900\",\n\"test/aoj/2667.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/2674.count.test.cpp\": \"2020-10-27 18:05:48 +0900\",\n\"test/aoj/2674.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/aoj/2679.test.cpp\": \"2020-10-07 13:03:03 +0900\",\n\"test/aoj/2687.test.cpp\": \"2021-03-11 20:23:34 +0900\",\n\"test/aoj/2711.test.cpp\": \"2020-12-28 13:48:49 +0900\",\n\"test/aoj/2720.test.cpp\": \"2020-10-24 13:43:25 +0900\",\n\"test/aoj/2725.test.cpp\": \"2020-10-27 12:59:18 +0900\",\n\"test/aoj/2736.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/2790.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/aoj/2842.BIT2D.test.cpp\": \"2020-10-27 12:59:35 +0900\",\n\"test/aoj/2842.test.cpp\": \"2020-10-27 18:05:43 +0900\",\n\"test/aoj/2871.test.cpp\": \"2020-10-27 19:19:44 +0900\",\n\"test/aoj/2872.test.cpp\": \"2020-10-27 16:28:23 +0900\",\n\"test/aoj/2890.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/aoj/2891.test.cpp\": \"2021-01-03 18:38:06 +0900\",\n\"test/aoj/2934.test.cpp\": \"2020-10-27 13:21:18 +0900\",\n\"test/aoj/2948.test.cpp\": \"2020-10-27 15:53:30 +0900\",\n\"test/aoj/2951.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/2959.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/2968.test.cpp\": \"2020-11-15 17:38:18 +0900\",\n\"test/aoj/2969.test.cpp\": \"2021-02-05 14:58:50 +0900\",\n\"test/aoj/2970.test.cpp\": \"2020-11-13 17:53:54 +0900\",\n\"test/aoj/2971.test.cpp\": \"2020-10-27 17:58:32 +0900\",\n\"test/aoj/2975.test.cpp\": \"2020-10-27 12:59:18 +0900\",\n\"test/aoj/2977.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/2979.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/2981.test.cpp\": \"2020-12-16 13:02:24 +0900\",\n\"test/aoj/2983.test.cpp\": \"2020-10-27 16:18:21 +0900\",\n\"test/aoj/2985.garner.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/aoj/2985.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/aoj/2995.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/3024.test.cpp\": \"2020-10-27 13:26:17 +0900\",\n\"test/aoj/3033.test.cpp\": \"2020-12-28 13:48:49 +0900\",\n\"test/aoj/3035.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/3037.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/3047.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/3053.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/3058.test.cpp\": \"2020-10-27 18:00:16 +0900\",\n\"test/aoj/3062.test.cpp\": \"2020-11-13 17:54:21 +0900\",\n\"test/aoj/3063.test.cpp\": \"2020-12-28 13:48:49 +0900\",\n\"test/aoj/3069.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/3072.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/aoj/3073.test.cpp\": \"2021-01-22 18:37:25 +0900\",\n\"test/aoj/3074.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/aoj/3081.test.cpp\": \"2021-03-04 16:59:57 +0900\",\n\"test/aoj/3084.test.cpp\": \"2020-11-22 16:22:14 +0900\",\n\"test/aoj/3086.test.cpp\": \"2020-10-27 19:24:14 +0900\",\n\"test/aoj/3102.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/3112.test.cpp\": \"2020-12-28 13:48:49 +0900\",\n\"test/aoj/3117.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/3120.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/3138.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/3142.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/aoj/3143.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/aoj/3148.test.cpp\": \"2020-10-27 16:29:49 +0900\",\n\"test/aoj/3168.test.cpp\": \"2020-10-27 16:19:34 +0900\",\n\"test/aoj/3183.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/3198.test.cpp\": \"2020-10-27 16:19:34 +0900\",\n\"test/aoj/3208.test.cpp\": \"2020-10-30 12:17:32 +0900\",\n\"test/aoj/3213.test.cpp\": \"2020-12-19 16:55:59 +0900\",\n\"test/aoj/3506.test.cpp\": \"2020-10-27 12:38:29 +0900\",\n\"test/aoj/ALDS1_10_C.test.cpp\": \"2020-12-21 13:20:36 +0900\",\n\"test/aoj/ALDS1_14_B.knuthmorrispratt.test.cpp\": \"2020-10-27 13:21:30 +0900\",\n\"test/aoj/ALDS1_14_B.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/ALDS1_14_C.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/aoj/ALDS1_15_B.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/ALDS1_1_C.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/ALDS1_9_C.test.cpp\": \"2020-10-27 12:59:47 +0900\",\n\"test/aoj/DPL_1_E.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/DPL_3_B.test.cpp\": \"2020-10-27 12:31:57 +0900\",\n\"test/aoj/DPL_3_C.test.cpp\": \"2020-10-27 12:31:57 +0900\",\n\"test/aoj/DPL_5_A.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_B.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_C.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_D.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_E.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_F.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_G.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_H.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_I.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_J.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_K.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DPL_5_L.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/aoj/DSL_1_A.quickfind.test.cpp\": \"2020-10-27 19:24:17 +0900\",\n\"test/aoj/DSL_1_A.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/DSL_1_B.test.cpp\": \"2020-10-27 19:25:22 +0900\",\n\"test/aoj/DSL_2_B.test.cpp\": \"2020-10-27 12:53:16 +0900\",\n\"test/aoj/DSL_2_C.test.cpp\": \"2020-10-27 19:22:46 +0900\",\n\"test/aoj/DSL_2_D.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/DSL_2_E.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/DSL_2_F.bbst.test.cpp\": \"2020-11-28 18:11:38 +0900\",\n\"test/aoj/DSL_2_F.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/DSL_2_G.bbst.test.cpp\": \"2020-11-28 18:12:25 +0900\",\n\"test/aoj/DSL_2_H.bbst.test.cpp\": \"2020-11-28 18:12:43 +0900\",\n\"test/aoj/DSL_2_H.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/DSL_2_I.bbst.test.cpp\": \"2020-11-28 18:14:23 +0900\",\n\"test/aoj/DSL_2_I.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/aoj/DSL_3_D.cartesiantree.test.cpp\": \"2020-10-27 16:42:28 +0900\",\n\"test/aoj/DSL_3_D.disjointsparsetable.test.cpp\": \"2020-10-27 19:24:22 +0900\",\n\"test/aoj/DSL_3_D.slidingwindowaggregation.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/DSL_3_D.sparsetable.test.cpp\": \"2020-10-27 19:24:14 +0900\",\n\"test/aoj/DSL_3_D.test.cpp\": \"2020-10-27 12:54:24 +0900\",\n\"test/aoj/GRL_1_A.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/GRL_1_B.test.cpp\": \"2020-10-27 16:00:51 +0900\",\n\"test/aoj/GRL_2_A.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/aoj/GRL_2_B.tarjan.test.cpp\": \"2020-10-27 18:03:06 +0900\",\n\"test/aoj/GRL_2_B.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/aoj/GRL_3_A.test.cpp\": \"2020-10-27 15:53:46 +0900\",\n\"test/aoj/GRL_3_B.test.cpp\": \"2020-10-27 15:53:46 +0900\",\n\"test/aoj/GRL_5_A.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/GRL_5_A.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/GRL_5_C.lca.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/GRL_5_C.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/aoj/GRL_5_D.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/GRL_5_D.test.cpp\": \"2020-10-27 19:19:29 +0900\",\n\"test/aoj/GRL_5_E.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/aoj/GRL_6_A.test.cpp\": \"2020-10-27 18:00:21 +0900\",\n\"test/aoj/GRL_6_B.test.cpp\": \"2020-10-07 13:03:03 +0900\",\n\"test/aoj/GRL_7_A.test.cpp\": \"2020-10-27 16:19:34 +0900\",\n\"test/aoj/ITP1_11_A.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/ITP1_11_B.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/ITP1_11_C.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/ITP1_11_D.test.cpp\": \"2020-10-25 17:34:04 +0900\",\n\"test/aoj/NTL_1_A.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/aoj/NTL_1_B.test.cpp\": \"2020-11-13 17:54:21 +0900\",\n\"test/aoj/NTL_1_D.test.cpp\": \"2020-10-24 12:57:13 +0900\",\n\"test/aoj/NTL_1_E.test.cpp\": \"2020-10-27 16:28:57 +0900\",\n\"test/aoj/NTL_2_A.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_B.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_C.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_D.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_E.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/NTL_2_F.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/aoj/geometry/2334.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/geometry/2448.test.cpp\": \"2020-10-27 12:47:27 +0900\",\n\"test/aoj/geometry/2454.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/3049.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/geometry/3056.test.cpp\": \"2020-10-27 12:28:09 +0900\",\n\"test/aoj/geometry/CGL_1_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_1_B.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_1_C.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_2_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_2_B.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_2_C.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_2_D.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/geometry/CGL_3_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_3_B.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_3_C.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_4_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_4_B.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_4_C.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_5_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_6_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_A.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_D.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_E.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_F.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_G.test.cpp\": \"2020-10-26 15:07:27 +0900\",\n\"test/aoj/geometry/CGL_7_H.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/aoj/geometry/CGL_7_I.test.cpp\": \"2020-10-27 12:28:39 +0900\",\n\"test/yosupo/assignment.test.cpp\": \"2020-10-27 16:28:23 +0900\",\n\"test/yosupo/associative_array.test.cpp\": \"2020-10-27 12:28:01 +0900\",\n\"test/yosupo/bernoulli_number.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yosupo/bipartitematching.test.cpp\": \"2020-10-27 16:21:44 +0900\",\n\"test/yosupo/bitwise_and_convolution.test.cpp\": \"2020-12-16 13:02:24 +0900\",\n\"test/yosupo/bitwise_xor_convolution.test.cpp\": \"2020-12-16 13:02:24 +0900\",\n\"test/yosupo/cartesian_tree.test.cpp\": \"2020-10-27 16:42:28 +0900\",\n\"test/yosupo/convolution_mod.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/convolution_mod_1000000007.garner.test.cpp\": \"2020-10-27 16:53:25 +0900\",\n\"test/yosupo/convolution_mod_1000000007.test.cpp\": \"2020-10-27 16:52:54 +0900\",\n\"test/yosupo/cycle_detection.test.cpp\": \"2021-01-03 18:34:38 +0900\",\n\"test/yosupo/discrete_logarithm_mod.test.cpp\": \"2020-11-13 17:53:32 +0900\",\n\"test/yosupo/dominatortree.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/dynamic_sequence_range_affine_range_sum.test.cpp\": \"2020-11-28 18:18:13 +0900\",\n\"test/yosupo/dynamic_tree_vertex_add_path_sum.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/yosupo/dynamic_tree_vertex_add_subtree_sum.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/yosupo/dynamic_tree_vertex_add_subtree_sum.toptree.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yosupo/dynamic_tree_vertex_set_path_composite.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/yosupo/dynamic_tree_vertex_set_path_composite.toptree.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yosupo/enumerate_primes.test.cpp\": \"2020-10-07 11:58:48 +0900\",\n\"test/yosupo/enumerate_triangles.test.cpp\": \"2020-10-27 16:43:59 +0900\",\n\"test/yosupo/exp_of_formal_power_series.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yosupo/find_linear_recurrence.test.cpp\": \"2020-10-27 16:43:02 +0900\",\n\"test/yosupo/frequency_table_of_tree_distance.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/yosupo/inv_of_formal_power_series.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yosupo/kth_root_integer.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/kth_term_of_linearly_recurrent_sequence.test.cpp\": \"2021-02-02 17:29:25 +0900\",\n\"test/yosupo/lca.linkcuttree.test.cpp\": \"2020-10-28 18:39:44 +0900\",\n\"test/yosupo/lca.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/yosupo/line_add_get_min.test.cpp\": \"2020-11-22 19:36:37 +0900\",\n\"test/yosupo/log_of_formal_power_series.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yosupo/manhattanmst.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/yosupo/many_aplusb.test.cpp\": \"2020-10-27 12:27:57 +0900\",\n\"test/yosupo/matrix_det.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/yosupo/maximum_independent_set.test.cpp\": \"2020-10-27 15:53:30 +0900\",\n\"test/yosupo/min_cost_b_flow.test.cpp\": \"2020-10-27 16:28:23 +0900\",\n\"test/yosupo/montmort_number_mod.test.cpp\": \"2020-11-13 17:52:53 +0900\",\n\"test/yosupo/multipoint_evaluation.test.cpp\": \"2020-11-22 16:24:54 +0900\",\n\"test/yosupo/number_of_substrings.test.cpp\": \"2020-12-28 13:48:49 +0900\",\n\"test/yosupo/partition_function.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yosupo/persistent_queue.test.cpp\": \"2020-11-04 18:44:56 +0900\",\n\"test/yosupo/point_add_range_sum.test.cpp\": \"2020-10-27 12:52:35 +0900\",\n\"test/yosupo/point_add_rectangle_sum.test.cpp\": \"2020-10-27 18:05:43 +0900\",\n\"test/yosupo/point_set_range_composite.test.cpp\": \"2021-02-05 14:58:50 +0900\",\n\"test/yosupo/polynomial_interpolation.test.cpp\": \"2020-11-22 16:24:54 +0900\",\n\"test/yosupo/polynomial_taylor_shift.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yosupo/pow_of_formal_power_series.test.cpp\": \"2020-11-22 16:22:14 +0900\",\n\"test/yosupo/queue_operate_all_composite.test.cpp\": \"2020-10-27 16:28:39 +0900\",\n\"test/yosupo/range_affine_range_sum.test.cpp\": \"2020-11-28 18:18:13 +0900\",\n\"test/yosupo/range_kth_smallest.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yosupo/rectangle_sum.test.cpp\": \"2020-10-27 18:05:43 +0900\",\n\"test/yosupo/runenumerate.test.cpp\": \"2021-03-04 16:59:57 +0900\",\n\"test/yosupo/scc.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/yosupo/segment_add_get_min.test.cpp\": \"2020-11-22 19:36:37 +0900\",\n\"test/yosupo/set_xor_min.test.cpp\": \"2020-10-27 12:53:16 +0900\",\n\"test/yosupo/sharp_p_subset_sum.test.cpp\": \"2020-12-21 13:43:02 +0900\",\n\"test/yosupo/shortest_path.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/sort_points_by_argument.test.cpp\": \"2020-10-27 16:29:27 +0900\",\n\"test/yosupo/sqrt_mod.test.cpp\": \"2020-11-13 20:21:23 +0900\",\n\"test/yosupo/sqrt_of_formal_power_series.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yosupo/static_range_inversions_query.test.cpp\": \"2020-10-27 12:52:35 +0900\",\n\"test/yosupo/static_range_sum.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/staticrmq.disjointsparsetable.test.cpp\": \"2020-10-27 19:24:22 +0900\",\n\"test/yosupo/staticrmq.sparsetable.test.cpp\": \"2020-10-27 19:24:14 +0900\",\n\"test/yosupo/stirling_number_of_the_first_kind.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yosupo/stirling_number_of_the_second_kind.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yosupo/subset_convolution.test.cpp\": \"2020-12-16 13:03:55 +0900\",\n\"test/yosupo/suffixarray.test.cpp\": \"2020-12-28 13:48:49 +0900\",\n\"test/yosupo/sum_of_floor_of_linear.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yosupo/tetration_mod.test.cpp\": \"2020-11-13 17:56:51 +0900\",\n\"test/yosupo/tree_decomposition_width_2.test.cpp\": \"2020-10-27 15:54:50 +0900\",\n\"test/yosupo/tree_diameter.test.cpp\": \"2020-10-27 12:47:27 +0900\",\n\"test/yosupo/two_edge_connected_components.test.cpp\": \"2020-10-27 15:55:39 +0900\",\n\"test/yosupo/two_sat.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/yosupo/unionfind.test.cpp\": \"2020-10-27 19:24:11 +0900\",\n\"test/yosupo/vertex_add_path_sum.test.cpp\": \"2020-10-28 14:04:34 +0900\",\n\"test/yosupo/vertex_add_subtree_sum.test.cpp\": \"2020-10-27 19:19:44 +0900\",\n\"test/yosupo/zalgorithm.test.cpp\": \"2021-03-04 17:00:27 +0900\",\n\"test/yukicoder/0022.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/yukicoder/0104.test.cpp\": \"2020-12-20 13:43:25 +0900\",\n\"test/yukicoder/0143.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/yukicoder/0222.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yukicoder/0399.test.cpp\": \"2020-10-27 19:01:09 +0900\",\n\"test/yukicoder/0444.test.cpp\": \"2020-12-20 13:43:25 +0900\",\n\"test/yukicoder/0472.test.cpp\": \"2020-11-13 17:56:51 +0900\",\n\"test/yukicoder/0831.test.cpp\": \"2020-10-27 12:49:07 +0900\",\n\"test/yukicoder/1013.test.cpp\": \"2021-01-22 18:37:25 +0900\",\n\"test/yukicoder/1504.test.cpp\": \"2020-11-13 17:54:01 +0900\",\n\"test/yukicoder/1580.test.cpp\": \"2020-10-05 16:59:31 +0900\",\n\"test/yukicoder/1665.test.cpp\": \"2020-10-27 16:28:50 +0900\",\n\"test/yukicoder/1732.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yukicoder/1923.test.cpp\": \"2020-10-27 12:54:24 +0900\",\n\"test/yukicoder/1937.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yukicoder/1948.test.cpp\": \"2020-10-27 12:32:58 +0900\",\n\"test/yukicoder/1950.test.cpp\": \"2020-10-27 12:32:58 +0900\",\n\"test/yukicoder/1973.test.cpp\": \"2020-12-19 16:21:21 +0900\",\n\"test/yukicoder/2063.test.cpp\": \"2020-10-27 18:05:43 +0900\",\n\"test/yukicoder/2085.test.cpp\": \"2020-10-27 16:29:49 +0900\",\n\"test/yukicoder/2113.test.cpp\": \"2020-10-27 12:32:58 +0900\",\n\"test/yukicoder/2125.test.cpp\": \"2020-10-27 12:52:35 +0900\",\n\"test/yukicoder/2147.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yukicoder/2587.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yukicoder/2600.test.cpp\": \"2020-12-10 16:27:42 +0900\",\n\"test/yukicoder/2744.test.cpp\": \"2020-11-22 16:21:33 +0900\",\n\"test/yukicoder/2772.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/yukicoder/3211.test.cpp\": \"2020-10-27 16:43:02 +0900\",\n\"test/yukicoder/3227.test.cpp\": \"2020-10-27 19:25:09 +0900\",\n\"test/yukicoder/3277.test.cpp\": \"2021-02-05 14:58:50 +0900\",\n\"test/yukicoder/3354.test.cpp\": \"2021-02-20 22:27:17 +0900\",\n\"test/yukicoder/3405.test.cpp\": \"2020-11-02 16:12:34 +0900\",\n\"test/yukicoder/3407.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/yukicoder/3453.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yukicoder/3592.test.cpp\": \"2020-10-27 19:25:22 +0900\",\n\"test/yukicoder/3912.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/yukicoder/3961.test.cpp\": \"2020-10-27 19:19:20 +0900\",\n\"test/yukicoder/4072.test.cpp\": \"2020-10-27 19:24:22 +0900\",\n\"test/yukicoder/4117.test.cpp\": \"2021-02-20 22:50:07 +0900\",\n\"test/yukicoder/4271.avx2.test.cpp\": \"2020-11-14 15:21:58 +0900\",\n\"test/yukicoder/4271.test.cpp\": \"2020-10-27 16:42:52 +0900\",\n\"test/yukicoder/4387.test.cpp\": \"2020-10-27 18:02:44 +0900\",\n\"test/yukicoder/4474.test.cpp\": \"2020-11-13 17:54:21 +0900\",\n\"test/yukicoder/4569.test.cpp\": \"2020-10-27 16:29:08 +0900\",\n\"test/yukicoder/4706.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yukicoder/4778.test.cpp\": \"2020-11-15 18:14:06 +0900\",\n\"test/yukicoder/4852.test.cpp\": \"2020-10-27 19:20:38 +0900\",\n\"test/yukicoder/4862.test.cpp\": \"2020-10-27 18:58:51 +0900\",\n\"test/yukicoder/4872.test.cpp\": \"2020-11-15 15:34:02 +0900\",\n\"test/yukicoder/4918.test.cpp\": \"2020-10-27 12:28:47 +0900\",\n\"test/yukicoder/4941.test.cpp\": \"2020-10-07 14:35:46 +0900\",\n\"test/yukicoder/5011.test.cpp\": \"2020-10-27 13:13:32 +0900\",\n\"test/yukicoder/5025.test.cpp\": \"2020-12-16 13:02:24 +0900\",\n\"test/yukicoder/5223.test.cpp\": \"2020-10-27 16:18:54 +0900\",\n\"test/yukicoder/5633.test.cpp\": \"2020-12-29 15:19:06 +0900\"\n}"
  },
  {
    "path": ".verify-helper/timestamps.remote.json",
    "content": "{\n\"test/aoj/0109.test.cpp\": \"2021-09-10 23:35:46 +0900\",\n\"test/aoj/0168.test.cpp\": \"2020-12-20 13:43:34 +0900\",\n\"test/aoj/0233.test.cpp\": \"2020-09-25 12:37:15 +0900\",\n\"test/aoj/0294.test.cpp\": \"2020-09-25 12:37:15 +0900\",\n\"test/aoj/0314.test.cpp\": \"2021-09-23 21:21:39 +0900\",\n\"test/aoj/0343.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/0367.linkcuttree.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/aoj/0367.test.cpp\": \"2021-02-05 14:59:47 +0900\",\n\"test/aoj/0367.toptree.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/aoj/0377.test.cpp\": \"2020-10-27 16:01:15 +0900\",\n\"test/aoj/0391.test.cpp\": \"2020-11-02 16:40:04 +0900\",\n\"test/aoj/0402.test.cpp\": \"2021-09-23 20:26:31 +0900\",\n\"test/aoj/0403.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/0415.test.cpp\": \"2020-10-27 16:01:15 +0900\",\n\"test/aoj/0422.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/aoj/0423.test.cpp\": \"2020-09-25 13:46:01 +0900\",\n\"test/aoj/0424.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/0425.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/0437.test.cpp\": \"2020-11-04 18:35:12 +0900\",\n\"test/aoj/0438.test.cpp\": \"2020-11-04 18:35:12 +0900\",\n\"test/aoj/0439.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/0502.test.cpp\": \"2020-10-25 17:34:17 +0900\",\n\"test/aoj/0558.test.cpp\": \"2020-09-30 16:50:39 +0900\",\n\"test/aoj/0563.test.cpp\": \"2020-09-25 12:37:15 +0900\",\n\"test/aoj/0596.test.cpp\": \"2020-10-27 16:52:37 +0900\",\n\"test/aoj/0613.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/1069.test.cpp\": \"2020-05-07 21:38:10 +0900\",\n\"test/aoj/1197.test.cpp\": \"2020-11-15 18:54:23 +0900\",\n\"test/aoj/1254.test.cpp\": \"2020-10-26 14:50:55 +0900\",\n\"test/aoj/1293.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/1300.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/1308.test.cpp\": \"2020-10-27 16:01:15 +0900\",\n\"test/aoj/1312.test.cpp\": \"2020-10-27 19:04:41 +0900\",\n\"test/aoj/1328.test.cpp\": \"2021-09-23 21:21:39 +0900\",\n\"test/aoj/1338.test.cpp\": \"2021-05-23 16:26:48 +0900\",\n\"test/aoj/1508.test.cpp\": \"2020-11-04 18:35:12 +0900\",\n\"test/aoj/1549.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/aoj/1579.test.cpp\": \"2020-11-04 18:35:12 +0900\",\n\"test/aoj/1595.linkcuttree.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/aoj/1595.test.cpp\": \"2020-10-27 16:41:24 +0900\",\n\"test/aoj/1595.toptree.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/aoj/1599.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/1607.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/1613.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/aoj/1615.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/1630.test.cpp\": \"2021-03-25 10:42:25 +0900\",\n\"test/aoj/1642.test.cpp\": \"2020-11-19 17:00:02 +0900\",\n\"test/aoj/2060.test.cpp\": \"2021-09-23 21:21:39 +0900\",\n\"test/aoj/2187.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/2212.test.cpp\": \"2021-01-22 18:37:50 +0900\",\n\"test/aoj/2222.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2230.test.cpp\": \"2020-10-27 16:41:24 +0900\",\n\"test/aoj/2235.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2257.test.cpp\": \"2021-01-22 18:37:50 +0900\",\n\"test/aoj/2270.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/2286.test.cpp\": \"2020-10-27 16:41:24 +0900\",\n\"test/aoj/2290.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/2292.test.cpp\": \"2020-10-27 19:04:41 +0900\",\n\"test/aoj/2294.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/2308.test.cpp\": \"2020-10-27 15:50:08 +0900\",\n\"test/aoj/2309.tarjan.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2309.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2313.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2324.test.cpp\": \"2020-10-27 16:01:15 +0900\",\n\"test/aoj/2328.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2359.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/2370.test.cpp\": \"2021-07-23 12:56:32 +0900\",\n\"test/aoj/2397.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2405.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2415.knuthyao.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/aoj/2415.test.cpp\": \"2020-10-27 13:13:52 +0900\",\n\"test/aoj/2444.test.cpp\": \"2020-10-27 19:04:41 +0900\",\n\"test/aoj/2446.test.cpp\": \"2021-09-23 20:26:31 +0900\",\n\"test/aoj/2450.linkcuttree.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/aoj/2450.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/2488.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/aoj/2513.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/2560.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2563.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/2603.test.cpp\": \"2021-03-05 12:19:04 +0900\",\n\"test/aoj/2624.test.cpp\": \"2020-10-27 16:01:15 +0900\",\n\"test/aoj/2627.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2636.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/aoj/2644.test.cpp\": \"2023-03-20 15:38:36 +0900\",\n\"test/aoj/2646.test.cpp\": \"2020-10-27 14:01:51 +0900\",\n\"test/aoj/2647.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2659.test.cpp\": \"2021-06-20 16:57:30 +0900\",\n\"test/aoj/2667.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/2674.count.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2674.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/aoj/2679.test.cpp\": \"2020-10-06 13:10:17 +0900\",\n\"test/aoj/2687.test.cpp\": \"2021-03-11 20:23:56 +0900\",\n\"test/aoj/2711.test.cpp\": \"2023-03-20 16:01:48 +0900\",\n\"test/aoj/2720.test.cpp\": \"2020-10-24 13:53:02 +0900\",\n\"test/aoj/2725.linecontainer.test.cpp\": \"2021-11-21 11:20:30 +0900\",\n\"test/aoj/2725.test.cpp\": \"2021-10-17 17:32:37 +0900\",\n\"test/aoj/2736.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/2790.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/2842.BIT2D.test.cpp\": \"2020-10-27 13:13:52 +0900\",\n\"test/aoj/2842.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2871.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/2872.test.cpp\": \"2020-10-27 16:41:24 +0900\",\n\"test/aoj/2890.test.cpp\": \"2020-11-04 18:35:12 +0900\",\n\"test/aoj/2891.test.cpp\": \"2021-01-03 18:39:08 +0900\",\n\"test/aoj/2934.test.cpp\": \"2020-10-27 13:26:46 +0900\",\n\"test/aoj/2948.test.cpp\": \"2020-10-27 15:54:11 +0900\",\n\"test/aoj/2951.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2959.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2968.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/2969.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/2970.test.cpp\": \"2021-06-20 16:57:30 +0900\",\n\"test/aoj/2971.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2975.test.cpp\": \"2021-10-17 17:32:37 +0900\",\n\"test/aoj/2977.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2979.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/2981.test.cpp\": \"2021-09-23 20:26:31 +0900\",\n\"test/aoj/2983.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2985.garner.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2985.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/2995.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/3024.test.cpp\": \"2020-10-27 13:26:46 +0900\",\n\"test/aoj/3033.test.cpp\": \"2023-03-20 15:38:36 +0900\",\n\"test/aoj/3035.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/3037.test.cpp\": \"2023-05-04 18:59:07 +0900\",\n\"test/aoj/3047.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/3053.test.cpp\": \"2020-09-25 13:59:55 +0900\",\n\"test/aoj/3058.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/3062.test.cpp\": \"2020-11-13 17:57:07 +0900\",\n\"test/aoj/3063.test.cpp\": \"2023-03-20 16:01:48 +0900\",\n\"test/aoj/3069.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/3072.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/3073.test.cpp\": \"2021-01-22 18:37:50 +0900\",\n\"test/aoj/3074.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/3081.test.cpp\": \"2021-03-04 17:00:41 +0900\",\n\"test/aoj/3084.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/3086.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/3102.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/3112.test.cpp\": \"2023-03-20 16:01:48 +0900\",\n\"test/aoj/3117.test.cpp\": \"2020-05-07 21:38:10 +0900\",\n\"test/aoj/3120.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/aoj/3138.test.cpp\": \"2020-10-25 17:34:17 +0900\",\n\"test/aoj/3142.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/3143.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/aoj/3148.test.cpp\": \"2020-10-27 16:41:24 +0900\",\n\"test/aoj/3168.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/3179.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/aoj/3183.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/3198.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/3208.test.cpp\": \"2020-10-30 12:18:04 +0900\",\n\"test/aoj/3213.test.cpp\": \"2020-12-20 13:43:34 +0900\",\n\"test/aoj/3506.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/3518.test.cpp\": \"2022-08-28 21:28:57 +0900\",\n\"test/aoj/ALDS1_10_C.test.cpp\": \"2020-12-21 13:22:00 +0900\",\n\"test/aoj/ALDS1_14_B.knuthmorrispratt.test.cpp\": \"2020-10-27 13:26:46 +0900\",\n\"test/aoj/ALDS1_14_B.test.cpp\": \"2020-10-27 19:04:41 +0900\",\n\"test/aoj/ALDS1_14_C.test.cpp\": \"2020-10-27 19:04:41 +0900\",\n\"test/aoj/ALDS1_15_B.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/ALDS1_1_C.test.cpp\": \"2020-09-25 14:33:00 +0900\",\n\"test/aoj/ALDS1_5_D.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/ALDS1_9_C.test.cpp\": \"2020-10-27 13:13:52 +0900\",\n\"test/aoj/DPL_1_E.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/DPL_3_B.test.cpp\": \"2020-10-27 12:43:10 +0900\",\n\"test/aoj/DPL_3_C.test.cpp\": \"2020-10-27 12:43:10 +0900\",\n\"test/aoj/DPL_5_A.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_B.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_C.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_D.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_E.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_F.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_G.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_H.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_I.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_J.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_K.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DPL_5_L.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/aoj/DSL_1_A.quickfind.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/DSL_1_A.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/DSL_1_B.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/DSL_2_B.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/aoj/DSL_2_C.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/DSL_2_D.test.cpp\": \"2020-09-25 14:47:24 +0900\",\n\"test/aoj/DSL_2_E.test.cpp\": \"2020-09-25 14:47:24 +0900\",\n\"test/aoj/DSL_2_F.bbst.test.cpp\": \"2020-11-28 18:14:40 +0900\",\n\"test/aoj/DSL_2_F.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/DSL_2_G.bbst.test.cpp\": \"2020-11-28 18:14:40 +0900\",\n\"test/aoj/DSL_2_H.bbst.test.cpp\": \"2020-11-28 18:14:40 +0900\",\n\"test/aoj/DSL_2_H.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/DSL_2_I.bbst.test.cpp\": \"2020-11-28 18:14:40 +0900\",\n\"test/aoj/DSL_2_I.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/DSL_3_D.cartesiantree.test.cpp\": \"2020-10-27 16:52:37 +0900\",\n\"test/aoj/DSL_3_D.disjointsparsetable.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/DSL_3_D.slidingwindowaggregation.test.cpp\": \"2020-09-25 15:01:13 +0900\",\n\"test/aoj/DSL_3_D.sparsetable.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/DSL_3_D.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/aoj/GRL_1_A.test.cpp\": \"2021-03-25 09:40:53 +0900\",\n\"test/aoj/GRL_1_B.test.cpp\": \"2020-10-27 16:01:15 +0900\",\n\"test/aoj/GRL_2_A.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/GRL_2_B.tarjan.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/GRL_2_B.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/GRL_3_A.test.cpp\": \"2020-10-27 15:54:11 +0900\",\n\"test/aoj/GRL_3_B.test.cpp\": \"2020-10-27 15:54:11 +0900\",\n\"test/aoj/GRL_5_A.linkcuttree.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/aoj/GRL_5_A.test.cpp\": \"2020-09-25 15:10:41 +0900\",\n\"test/aoj/GRL_5_C.lca.test.cpp\": \"2020-09-25 15:10:41 +0900\",\n\"test/aoj/GRL_5_C.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/aoj/GRL_5_D.linkcuttree.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/aoj/GRL_5_D.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/aoj/GRL_5_E.linkcuttree.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/aoj/GRL_6_A.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/aoj/GRL_6_B.test.cpp\": \"2020-10-06 13:10:17 +0900\",\n\"test/aoj/GRL_7_A.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/aoj/ITP1_11_A.test.cpp\": \"2020-10-25 17:34:17 +0900\",\n\"test/aoj/ITP1_11_B.test.cpp\": \"2020-10-25 17:34:17 +0900\",\n\"test/aoj/ITP1_11_C.test.cpp\": \"2020-10-25 17:34:17 +0900\",\n\"test/aoj/ITP1_11_D.test.cpp\": \"2020-10-25 17:34:17 +0900\",\n\"test/aoj/NTL_1_A.test.cpp\": \"2020-09-25 15:10:41 +0900\",\n\"test/aoj/NTL_1_B.test.cpp\": \"2020-11-13 17:57:07 +0900\",\n\"test/aoj/NTL_1_D.test.cpp\": \"2020-10-24 12:57:36 +0900\",\n\"test/aoj/NTL_1_E.test.cpp\": \"2021-06-20 16:57:30 +0900\",\n\"test/aoj/NTL_2_A.test.cpp\": \"2021-03-25 09:40:53 +0900\",\n\"test/aoj/NTL_2_B.test.cpp\": \"2021-03-25 09:40:53 +0900\",\n\"test/aoj/NTL_2_C.test.cpp\": \"2021-03-25 09:40:53 +0900\",\n\"test/aoj/NTL_2_D.test.cpp\": \"2021-03-25 09:40:53 +0900\",\n\"test/aoj/NTL_2_E.test.cpp\": \"2021-03-25 09:40:53 +0900\",\n\"test/aoj/NTL_2_F.test.cpp\": \"2021-03-25 09:40:53 +0900\",\n\"test/aoj/geometry/2334.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/geometry/2448.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/aoj/geometry/2454.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/3049.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/geometry/3056.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/geometry/CGL_1_A.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_1_B.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_1_C.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_2_A.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_2_B.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_2_C.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_2_D.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/geometry/CGL_3_A.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_3_B.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_3_C.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_4_A.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_4_B.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_4_C.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_5_A.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_6_A.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_7_A.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_7_D.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_7_E.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_7_F.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_7_G.test.cpp\": \"2020-10-26 15:08:18 +0900\",\n\"test/aoj/geometry/CGL_7_H.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/aoj/geometry/CGL_7_I.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/yosupo/assignment.test.cpp\": \"2020-10-27 16:41:24 +0900\",\n\"test/yosupo/associative_array.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/yosupo/bernoulli_number.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/bipartitematching.test.cpp\": \"2020-10-27 16:27:26 +0900\",\n\"test/yosupo/bitwise_and_convolution.test.cpp\": \"2021-09-23 20:26:31 +0900\",\n\"test/yosupo/bitwise_xor_convolution.test.cpp\": \"2021-09-23 20:26:31 +0900\",\n\"test/yosupo/cartesian_tree.test.cpp\": \"2020-10-27 16:52:37 +0900\",\n\"test/yosupo/convolution_mod.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/convolution_mod_1000000007.garner.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/convolution_mod_1000000007.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/cycle_detection.test.cpp\": \"2021-01-03 18:39:08 +0900\",\n\"test/yosupo/discrete_logarithm_mod.test.cpp\": \"2020-11-13 17:57:07 +0900\",\n\"test/yosupo/dominatortree.test.cpp\": \"2020-09-25 15:33:26 +0900\",\n\"test/yosupo/dynamic_sequence_range_affine_range_sum.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/dynamic_tree_vertex_add_path_sum.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/yosupo/dynamic_tree_vertex_add_subtree_sum.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/yosupo/dynamic_tree_vertex_add_subtree_sum.toptree.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/yosupo/dynamic_tree_vertex_set_path_composite.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/dynamic_tree_vertex_set_path_composite.toptree.test.cpp\": \"2023-05-04 18:59:07 +0900\",\n\"test/yosupo/enumerate_primes.test.cpp\": \"2020-10-07 11:59:04 +0900\",\n\"test/yosupo/enumerate_triangles.test.cpp\": \"2020-10-27 16:52:37 +0900\",\n\"test/yosupo/exp_of_formal_power_series.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/find_linear_recurrence.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/frequency_table_of_tree_distance.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yosupo/inv_of_formal_power_series.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/kth_root_integer.test.cpp\": \"2020-09-25 18:28:59 +0900\",\n\"test/yosupo/kth_term_of_linearly_recurrent_sequence.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/lca.linkcuttree.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/yosupo/lca.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yosupo/line_add_get_min.test.cpp\": \"2020-11-22 19:37:49 +0900\",\n\"test/yosupo/log_of_formal_power_series.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/manhattanmst.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yosupo/many_aplusb.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/yosupo/matrix_det.test.cpp\": \"2021-09-23 21:21:39 +0900\",\n\"test/yosupo/maximum_independent_set.test.cpp\": \"2020-10-27 15:54:11 +0900\",\n\"test/yosupo/min_cost_b_flow.test.cpp\": \"2020-10-27 16:41:24 +0900\",\n\"test/yosupo/montmort_number_mod.test.cpp\": \"2020-11-13 17:57:07 +0900\",\n\"test/yosupo/multipoint_evaluation.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/number_of_substrings.test.cpp\": \"2023-03-20 16:01:48 +0900\",\n\"test/yosupo/partition_function.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/persistent_queue.test.cpp\": \"2020-11-04 18:35:12 +0900\",\n\"test/yosupo/point_add_range_sum.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yosupo/point_add_rectangle_sum.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yosupo/point_set_range_composite.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/polynomial_interpolation.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/polynomial_taylor_shift.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/pow_of_formal_power_series.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/queue_operate_all_composite.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/range_affine_range_sum.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/range_kth_smallest.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/yosupo/rectangle_sum.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yosupo/runenumerate.test.cpp\": \"2021-03-04 17:00:41 +0900\",\n\"test/yosupo/scc.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/yosupo/segment_add_get_min.test.cpp\": \"2020-11-22 19:37:49 +0900\",\n\"test/yosupo/set_xor_min.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/yosupo/sharp_p_subset_sum.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/shortest_path.test.cpp\": \"2020-09-25 18:28:59 +0900\",\n\"test/yosupo/sort_points_by_argument.test.cpp\": \"2020-10-27 16:41:24 +0900\",\n\"test/yosupo/sqrt_mod.test.cpp\": \"2020-11-13 20:22:13 +0900\",\n\"test/yosupo/sqrt_of_formal_power_series.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/static_range_frequency.test.cpp\": \"2021-10-27 00:41:51 +0900\",\n\"test/yosupo/static_range_inversions_query.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yosupo/static_range_sum.test.cpp\": \"2020-09-25 16:01:41 +0900\",\n\"test/yosupo/staticrmq.disjointsparsetable.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yosupo/staticrmq.sparsetable.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yosupo/stirling_number_of_the_first_kind.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/stirling_number_of_the_second_kind.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yosupo/subset_convolution.test.cpp\": \"2021-09-23 20:26:31 +0900\",\n\"test/yosupo/suffixarray.test.cpp\": \"2023-03-20 15:38:36 +0900\",\n\"test/yosupo/sum_of_floor_of_linear.test.cpp\": \"2020-09-25 16:01:41 +0900\",\n\"test/yosupo/tetration_mod.test.cpp\": \"2020-11-13 17:57:07 +0900\",\n\"test/yosupo/tree_decomposition_width_2.test.cpp\": \"2020-10-27 16:01:15 +0900\",\n\"test/yosupo/tree_diameter.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/yosupo/two_edge_connected_components.test.cpp\": \"2020-10-27 16:01:15 +0900\",\n\"test/yosupo/two_sat.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/yosupo/unionfind.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yosupo/vertex_add_path_sum.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yosupo/vertex_add_subtree_sum.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yosupo/zalgorithm.test.cpp\": \"2021-03-04 17:00:41 +0900\",\n\"test/yukicoder/0022.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/0104.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/0143.test.cpp\": \"2021-03-25 09:40:53 +0900\",\n\"test/yukicoder/0206.test.cpp\": \"2021-06-20 18:05:51 +0900\",\n\"test/yukicoder/0222.test.cpp\": \"2020-09-30 16:50:39 +0900\",\n\"test/yukicoder/0399.test.cpp\": \"2020-10-27 19:04:41 +0900\",\n\"test/yukicoder/0444.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/0472.test.cpp\": \"2020-11-13 17:57:07 +0900\",\n\"test/yukicoder/0771.test.cpp\": \"2021-10-17 17:43:57 +0900\",\n\"test/yukicoder/0831.test.cpp\": \"2021-03-25 09:40:53 +0900\",\n\"test/yukicoder/1013.test.cpp\": \"2021-01-22 18:37:50 +0900\",\n\"test/yukicoder/1504.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/1580.test.cpp\": \"2020-09-25 16:15:28 +0900\",\n\"test/yukicoder/1665.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/1732.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yukicoder/1923.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/yukicoder/1937.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/yukicoder/1948.test.cpp\": \"2020-10-27 12:43:10 +0900\",\n\"test/yukicoder/1950.test.cpp\": \"2020-10-27 12:43:10 +0900\",\n\"test/yukicoder/1973.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/2063.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/yukicoder/2085.test.cpp\": \"2020-10-27 16:41:24 +0900\",\n\"test/yukicoder/2113.test.cpp\": \"2020-10-27 12:43:10 +0900\",\n\"test/yukicoder/2125.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yukicoder/2147.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/yukicoder/2520.test.cpp\": \"2021-08-08 16:43:28 +0900\",\n\"test/yukicoder/2587.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/yukicoder/2600.test.cpp\": \"2020-12-10 16:40:15 +0900\",\n\"test/yukicoder/2744.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/2772.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/3211.test.cpp\": \"2021-07-24 22:40:18 +0900\",\n\"test/yukicoder/3227.test.cpp\": \"2020-10-27 12:55:52 +0900\",\n\"test/yukicoder/3267.test.cpp\": \"2021-11-21 12:07:31 +0900\",\n\"test/yukicoder/3277.test.cpp\": \"2021-02-05 15:09:55 +0900\",\n\"test/yukicoder/3354.test.cpp\": \"2021-02-20 22:51:36 +0900\",\n\"test/yukicoder/3405.test.cpp\": \"2020-11-02 16:12:53 +0900\",\n\"test/yukicoder/3407.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yukicoder/3453.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/yukicoder/3592.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yukicoder/3912.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yukicoder/3961.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yukicoder/4072.test.cpp\": \"2020-10-27 19:32:25 +0900\",\n\"test/yukicoder/4117.test.cpp\": \"2021-02-20 22:51:36 +0900\",\n\"test/yukicoder/4271.avx2.test.cpp\": \"2020-11-14 15:24:41 +0900\",\n\"test/yukicoder/4271.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/4387.test.cpp\": \"2020-10-27 18:08:33 +0900\",\n\"test/yukicoder/4474.test.cpp\": \"2020-11-13 17:57:07 +0900\",\n\"test/yukicoder/4569.test.cpp\": \"2021-03-25 09:21:12 +0900\",\n\"test/yukicoder/4706.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/yukicoder/4778.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yukicoder/4852.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yukicoder/4862.test.cpp\": \"2021-09-25 22:06:41 +0900\",\n\"test/yukicoder/4872.test.cpp\": \"2020-11-15 16:01:34 +0900\",\n\"test/yukicoder/4918.test.cpp\": \"2020-10-27 12:29:50 +0900\",\n\"test/yukicoder/4941.test.cpp\": \"2021-05-23 16:26:48 +0900\",\n\"test/yukicoder/5011.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/5025.test.cpp\": \"2021-09-23 20:26:31 +0900\",\n\"test/yukicoder/5061.test.cpp\": \"2021-09-05 12:24:05 +0900\",\n\"test/yukicoder/5223.test.cpp\": \"2021-05-01 12:56:38 +0900\",\n\"test/yukicoder/5633.test.cpp\": \"2021-03-25 09:46:10 +0900\",\n\"test/yukicoder/6680.test.cpp\": \"2021-08-06 23:06:43 +0900\",\n\"test/yukicoder/7107.test.cpp\": \"2021-11-21 12:07:31 +0900\",\n\"test/yukicoder/9158.test.cpp\": \"2023-05-05 23:39:01 +0900\"\n}"
  },
  {
    "path": "README.md",
    "content": "# library\n\n[![Actions Status](https://github.com/beet-aizu/library/workflows/verify/badge.svg)](https://github.com/beet-aizu/library/actions)\n[![GitHub Pages](https://img.shields.io/static/v1?label=GitHub+Pages&message=+&color=brightgreen&logo=github)](https://beet-aizu.github.io/library/)\n\nうぃーんﾋﾞｰﾄﾋﾞｰﾄひるどwwwwwwうっくっくwwwwwwえいえいえt(←いずらいt)いえいwwwwらて。\n\n"
  },
  {
    "path": "algorithm/knuthyao.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// f(i,l) + f(j,k) >= f(i,k) + f(j,l) (i <= j, k <= l)\ntemplate<typename T, typename F>\nT KnuthYao(int n,F cost){\n  vector< vector<T> > dp(n,vector<T>(n));\n  vector< vector<int> > ar(n,vector<int>(n));\n  for(int i=0;i<n;i++) dp[i][i]=T(0),ar[i][i]=i;\n  for(int w=1;w<n;w++){\n    for(int i=0;i+w<n;i++){\n      int j=i+w;\n      int p=ar[i][j-1],q=ar[i+1][j];\n      dp[i][j]=dp[i][p]+dp[p+1][j]+cost(i,p,j);\n      ar[i][j]=p;\n      for(int k=p;k<=q and k+1<=j;k++){\n        T res=dp[i][k]+dp[k+1][j]+cost(i,k,j);\n        if(res<dp[i][j]) dp[i][j]=res,ar[i][j]=k;\n      }\n    }\n  }\n  return dp[0][n-1];\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "algorithm/largestrectangle.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nT largestrectangle(vector<T> &v){\n  int n=v.size();\n  T res=0;\n  using P = pair<int, T>;\n  stack<P> sp;\n  sp.emplace(-1,T(0));\n  for(int i=0;i<n;i++){\n    int j=i;\n    while(sp.top().second>v[i]){\n      j=sp.top().first;\n      res=max(res,(i-j)*sp.top().second);\n      sp.pop();\n    }\n    if(sp.top().second<v[i]) sp.emplace(j,v[i]);\n  }\n  while(!sp.empty()){\n    res=max(res,(n-sp.top().first)*sp.top().second);\n    sp.pop();\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "algorithm/mo.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct Mo{\n  using F = function<void(int)>;\n  vector<int> ls,rs,ord;\n  int n,width,nl,nr,ptr;\n  F expandL,expandR;\n  F shrinkL,shrinkR;\n\n  Mo(int n,int width,F expandL,F expandR,F shrinkL,F shrinkR):\n    n(n),width(width),nl(0),nr(0),ptr(0),\n    expandL(expandL),expandR(expandR),\n    shrinkL(shrinkL),shrinkR(shrinkR){}\n\n  Mo(int n,int width,F expand,F shrink):\n    Mo(n,width,expand,expand,shrink,shrink){}\n\n  void add(int l,int r){\n    ls.emplace_back(l);\n    rs.emplace_back(r);\n  }\n\n  void build(){\n    ord.resize(ls.size());\n    iota(ord.begin(),ord.end(),0);\n    sort(ord.begin(),ord.end(),\n         [&](int a,int b){\n           if(ls[a]/width!=ls[b]/width) return ls[a]<ls[b];\n           if(rs[a]==rs[b]) return ls[a]<ls[b];\n           return bool((rs[a]<rs[b])^((ls[a]/width)&1));\n         });\n  }\n\n  int process(){\n    if(ptr==(int)ord.size()) return -1;\n    const int idx=ord[ptr++];\n    while(nl>ls[idx]) expandL(--nl);\n    while(nr<rs[idx]) expandR(nr++);\n    while(nl<ls[idx]) shrinkL(nl++);\n    while(nr>rs[idx]) shrinkR(--nr);\n    return idx;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "algorithm/monotoneminima.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nnamespace MonotoneMinima{\n  template<typename T,typename F>\n  void induce(int l,int r,int a,int b,vector<int> &dp,F dist){\n    if(l==r) return;\n    int m=(l+r)>>1;\n    int &idx=(dp[m]=a);\n    T res=dist(m,idx);\n    for(int i=a;i<b;i++){\n      T tmp=dist(m,i);\n      if(tmp<res) res=tmp,idx=i;\n    }\n    induce<T>(l,m,a,idx+1,dp,dist);\n    induce<T>(m+1,r,idx,b,dp,dist);\n  }\n\n  // p < q -> argmin f(p, *) <= argmin f(q, *)\n  template<typename T,typename F>\n  vector<int> args(int n,int m,F dist){\n    vector<int> dp(n,-1);\n    induce<T>(0,n,0,m,dp,dist);\n    return dp;\n  }\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "algorithm/offlineonline.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n// https://qiita.com/tmaehara/items/0687af2cfb807cde7860\n//BEGIN CUT HERE\nnamespace OfflineOnline{\n  vector<int> used;\n\n  template<typename T>\n  void update(vector<T> &dp,int k,T val){\n    if(!used[k]) dp[k]=val;\n    dp[k]=min(dp[k],val);\n    used[k]=1;\n  }\n\n  // [l, r), [a, b]\n  template<typename T,typename F>\n  void induce(int l,int r,int a,int b,vector<T> &dp,F dist){\n    if(l==r) return;\n    int m=(l+r)>>1;\n    assert(m<a);\n    int idx=a;\n    T res=dist(m,idx)+dp[idx];\n    for(int i=a;i<=b;i++){\n      T tmp=dist(m,i)+dp[i];\n      if(tmp<res) res=tmp,idx=i;\n    }\n    update(dp,m,res);\n    induce(l,m+0,a,idx,dp,dist);\n    induce(m+1,r,idx,b,dp,dist);\n  }\n\n  template<typename T,typename F>\n  void solve(int l,int r,vector<T> &dp,F dist){\n    if(l+1==r) return update(dp,l,dist(l,r)+dp[r]);\n    int m=(l+r)>>1;\n    solve(m,r,dp,dist);\n    induce(l,m,m,r,dp,dist);\n    solve(l,m,dp,dist);\n  }\n\n  // dp[i] = min_{i<j} dist(i,j) + dp[j]\n  template<typename T,typename F>\n  T solve(int n,F dist){\n    vector<T> dp(n+1,0);\n    used.assign(n+1,0);\n    used[n]=1;\n    solve(0,n,dp,dist);\n    return dp[0];\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "algorithm/optimalbinarytree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../datastructure/skewheap.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nT optimalbinarytree(vector<T> ws){\n  const T INF = numeric_limits<T>::max()/2;\n  using Heap=SkewHeap<T, T>;\n\n  auto g=[](T a,T b){return a+b;};\n  auto c=[](T a,T b){return a>b;};\n  Heap heap(g,g,c,INF,0);\n\n  int n=ws.size();\n  vector<typename Heap::Node* > hs(n-1,nullptr);\n  vector<int> ls(n),rs(n);\n  vector<T> cs(n-1);\n\n  using P = pair<T, int>;\n  priority_queue<P,vector<P>,greater<P> > pq;\n  for(int i=0;i<n-1;i++){\n    ls[i]=i-1;\n    rs[i]=i+1;\n    cs[i]=ws[i]+ws[i+1];\n    pq.emplace(cs[i],i);\n  }\n\n  T res=0;\n  for(int k=0;k<n-1;k++){\n    T c;\n    int i;\n    do{\n      tie(c,i)=pq.top();pq.pop();\n    }while(rs[i]<0 or cs[i]!=c);\n\n    bool ml=false,mr=false;\n    if(ws[i]+heap.top(hs[i])==c){\n      hs[i]=heap.pop(hs[i]);\n      ml=true;\n    }else if(ws[i]+ws[rs[i]]==c){\n      ml=mr=true;\n    }else if(heap.top(hs[i])+heap.snd(hs[i])==c){\n      hs[i]=heap.pop(heap.pop(hs[i]));\n    }else{\n      hs[i]=heap.pop(hs[i]);\n      mr=true;\n    }\n\n    res+=c;\n    hs[i]=heap.meld(hs[i],heap.push(c));\n\n    if(ml) ws[i]=INF;\n    if(mr) ws[rs[i]]=INF;\n\n    if(ml and i>0){\n      int j=ls[i];\n      hs[j]=heap.meld(hs[j],hs[i]);\n      rs[j]=rs[i];\n      rs[i]=-1;\n      ls[rs[j]]=j;\n      i=j;\n    }\n\n    if(mr and rs[i]+1<n){\n      int j=rs[i];\n      hs[i]=heap.meld(hs[i],hs[j]);\n      rs[i]=rs[j];\n      rs[j]=-1;\n      ls[rs[i]]=i;\n    }\n\n    cs[i]=min({ws[i]+ws[rs[i]],INF,\n               min(ws[i],ws[rs[i]])+heap.top(hs[i]),\n               heap.top(hs[i])+heap.snd(hs[i])});\n    pq.emplace(cs[i],i);\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "algorithm/parallelbinarysearch.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// n questions, q operations\nvector<int> parallel_binary_search(int n,int q,\n                                   function<void(void)> init,\n                                   function<void(int)> apply,\n                                   function<bool(int)> check){\n  vector< vector<int> > C(q);\n  vector<int> L(n,-1),R(n,q);\n  bool flg=1;\n  while(flg){\n    flg=0;\n    init();\n    for(int i=0;i<n;i++)\n      if(L[i]+1<R[i]) C[(L[i]+R[i])>>1].emplace_back(i);\n    for(int i=0;i<q;i++){\n      flg|=!C[i].empty();\n      apply(i);\n      for(int j:C[i]){\n        if(check(j)) R[j]=i;\n        else L[j]=i;\n      }\n      C[i].clear();\n    }\n  }\n  return R;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "algorithm/partialsum.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(n sqrt(n) / w)\n// w: wordsize\ntemplate<size_t N>\nbitset<N+1> partial_sum(vector<int> vs){\n  int sum=0;\n  for(int v:vs) sum+=v;\n  assert(sum<=N);\n  vector<int> cnt(sum+1,0);\n  for(int v:vs) cnt[v]++;\n  for(int i=1;i*2<=sum;i++){\n    int num=(cnt[i]-1)/2;\n    cnt[i]-=num*2;\n    cnt[i*2]+=num;\n  }\n  bitset<N+1> dp;\n  dp[0]=1;\n  for(int i=1;i<=sum;i++)\n    for(int t=0;t<cnt[i];t++)\n      dp|=dp<<i;\n  return dp;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "bbst/pb_ds_tree.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\n#include<ext/pb_ds/tag_and_trait.hpp>\nusing namespace __gnu_pbds;\ntemplate <typename T>\nusing gtree = tree<T, null_type, less<T>, rb_tree_tag,\n                   tree_order_statistics_node_update>;\n// usage:\n// find_by_order(int k):\n// return the iterator of k-th smallest element (0-indexed)\n// order_of_key(T key):  return the index of key in tree\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "bbst/rbst/data/array.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct Array{\n  struct Node{\n    Node *l,*r,*p;\n    size_t cnt;\n    bool rev;\n    T val;\n    Node(T val):\n      cnt(1),rev(0),val(val){l=r=p=nullptr;}\n  };\n\n  static inline size_t count(const Node *t){\n    return t?t->cnt:0;\n  }\n\n  inline void toggle(Node *t){\n    swap(t->l,t->r);\n    t->rev^=1;\n  }\n\n  inline bool dirty(Node *t){\n    return t->rev;\n  }\n\n  inline Node* eval(Node* t){\n    if(t->rev){\n      if(t->l) toggle(t->l);\n      if(t->r) toggle(t->r);\n      t->rev=false;\n    }\n    return t;\n  }\n\n  inline Node* pushup(Node *t){\n    t->cnt=count(t->l)+1+count(t->r);\n    return t;\n  }\n\n  inline T get_val(Node *t){\n    assert(t);\n    return t->val;\n  }\n\n  void dump(typename vector<Node>::iterator it,Node* const t,bool rev){\n    if(!count(t)) return;\n\n    Node *l=t->l,*r=t->r;\n    if(rev) swap(l,r);\n    rev^=t->rev;\n\n    dump(it,l,rev);\n    *(it+count(l))=Node(t->val);\n    dump(it+count(l)+1,r,rev);\n  }\n\n  vector<Node> dump(Node* t){\n    assert(t!=nullptr);\n    vector<Node> vs(count(t),*t);\n    dump(vs.begin(),t,false);\n    return vs;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "bbst/rbst/data/dual.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename E, typename H>\nstruct Dual{\n  struct Node{\n    Node *l,*r,*p;\n    size_t cnt;\n    bool rev;\n    E val,laz;\n    Node(E val):\n      cnt(1),rev(0),val(val),laz(val){l=r=p=nullptr;}\n  };\n\n  H h;\n  E ei;\n  Dual(H h,E ei):h(h),ei(ei){}\n\n  static inline size_t count(const Node *t){\n    return t?t->cnt:0;\n  }\n\n  inline void toggle(Node *t){\n    swap(t->l,t->r);\n    t->rev^=1;\n  }\n\n  inline void propagate(Node *t,E x){\n    t->val=h(t->val,x);\n    t->laz=h(t->laz,x);\n  }\n\n  inline bool dirty(Node *t){\n    return t->rev or t->laz!=ei;\n  }\n\n  inline Node* eval(Node* t){\n    if(t->rev){\n      if(t->l) toggle(t->l);\n      if(t->r) toggle(t->r);\n      t->rev=false;\n    }\n    if(t->laz!=ei){\n      if(t->l) propagate(t->l,t->laz);\n      if(t->r) propagate(t->r,t->laz);\n      t->laz=ei;\n    }\n    return t;\n  }\n\n  inline Node* pushup(Node *t){\n    t->cnt=count(t->l)+1+count(t->r);\n    return t;\n  }\n\n  inline E get_val(Node *t){\n    assert(t);\n    return t->val;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "bbst/rbst/data/lazy.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T, typename E,\n         typename F, typename G, typename H, typename Flip>\nstruct Lazy{\n  F f;\n  G g;\n  H h;\n  Flip flip;\n  T ti;\n  E ei;\n\n  Lazy(F f,G g,H h,Flip flip,T ti,E ei):\n    f(f),g(g),h(h),flip(flip),ti(ti),ei(ei){}\n\n  struct Node{\n    Node *l,*r,*p;\n    size_t cnt;\n    bool rev;\n    T val,dat;\n    E laz;\n    Node(T val,E laz):\n      cnt(1),rev(0),val(val),dat(val),laz(laz){l=r=p=nullptr;}\n  };\n\n  static inline size_t count(const Node *t){\n    return t?t->cnt:0;\n  }\n\n  inline void toggle(Node *t){\n    swap(t->l,t->r);\n    t->val=flip(t->val);\n    t->dat=flip(t->dat);\n    t->rev^=1;\n  }\n\n  inline bool dirty(Node *t){\n    return t->rev or t->laz!=ei;\n  }\n\n  inline void propagate(Node *t,E v){\n    t->laz=h(t->laz,v);\n    t->val=g(t->val,v);\n    t->dat=g(t->dat,v);\n  }\n\n  inline Node* eval(Node* t){\n    if(t->rev){\n      if(t->l) toggle(t->l);\n      if(t->r) toggle(t->r);\n      t->rev=false;\n    }\n    if(t->laz!=ei){\n      if(t->l) propagate(t->l,t->laz);\n      if(t->r) propagate(t->r,t->laz);\n      t->laz=ei;\n    }\n    return t;\n  }\n\n  inline Node* pushup(Node *t){\n    t->cnt=count(t->l)+1+count(t->r);\n    t->dat=t->val;\n    if(t->l) t->dat=f(t->l->dat,t->dat);\n    if(t->r) t->dat=f(t->dat,t->r->dat);\n    return t;\n  }\n\n  inline T get_val(Node *t){\n    assert(t);\n    return t->val;\n  }\n\n  inline T reflect(Node *t){\n    assert(t);\n    return t->dat;\n  }\n\n  void dump(typename vector<Node>::iterator it,\n            const Node* t,bool rev,E laz){\n    if(!count(t)) return;\n\n    Node *l=t->l,*r=t->r;\n    if(rev) swap(l,r);\n    rev^=t->rev;\n\n    dump(it,l,rev,h(laz,t->laz));\n    *(it+count(l))=Node(g(t->val,laz),ei);\n    dump(it+count(l)+1,r,rev,h(laz,t->laz));\n  }\n\n  vector<Node> dump(Node* t){\n    assert(t!=nullptr);\n    vector<Node> vs(count(t),*t);\n    dump(vs.begin(),t,false,ei);\n    return vs;\n  }\n};\n\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "bbst/rbst/data/ushi.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T, typename F, typename Flip>\nstruct Ushi{\n  F f;\n  Flip flip;\n  T ti;\n\n  Ushi(F f,Flip flip,T ti):f(f),flip(flip),ti(ti){}\n\n  struct Node{\n    Node *l,*r,*p;\n    size_t cnt;\n    bool rev;\n    T val,dat;\n    Node(T val):\n      cnt(1),rev(0),val(val),dat(val){l=r=p=nullptr;}\n  };\n\n  static inline size_t count(const Node *t){\n    return t?t->cnt:0;\n  }\n\n  inline void toggle(Node *t){\n    swap(t->l,t->r);\n    t->val=flip(t->val);\n    t->dat=flip(t->dat);\n    t->rev^=1;\n  }\n\n  inline bool dirty(Node *t){\n    return t->rev;\n  }\n\n  inline Node* eval(Node* t){\n    if(t->rev){\n      if(t->l) toggle(t->l);\n      if(t->r) toggle(t->r);\n      t->rev=false;\n    }\n    return t;\n  }\n\n  inline Node* pushup(Node *t){\n    t->cnt=count(t->l)+1+count(t->r);\n    t->dat=t->val;\n    if(t->l) t->dat=f(t->l->dat,t->dat);\n    if(t->r) t->dat=f(t->dat,t->r->dat);\n    return t;\n  }\n\n  inline T get_val(Node *t){\n    assert(t);\n    return t->val;\n  }\n\n  inline T reflect(Node *t){\n    assert(t);\n    return t->dat;\n  }\n\n  void dump(typename vector<Node>::iterator it,Node* const t,bool rev){\n    if(!count(t)) return;\n\n    Node *l=t->l,*r=t->r;\n    if(rev) swap(l,r);\n    rev^=t->rev;\n\n    dump(it,l,rev);\n    *(it+count(l))=Node(t->val);\n    dump(it+count(l)+1,r,rev);\n  }\n\n  vector<Node> dump(Node* t){\n    assert(t!=nullptr);\n    vector<Node> vs(count(t),*t);\n    dump(vs.begin(),t,false);\n    return vs;\n  }\n};\n\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "bbst/rbst/impl/basic.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../rbst.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename Data, size_t LIM>\nstruct Basic : RBST<Basic<Data, LIM>, Data, typename Data::Node, LIM>{\n  using super = RBST<Basic, Data, typename Data::Node, LIM>;\n  using Node = typename Data::Node;\n\n  Data data;\n\n  template<class... Args>\n  Basic(Args... args):data(forward<Args>(args)...){}\n\n  inline Node* touch(Node *t){return data.eval(t);}\n\n  using super::toggle;\n  inline void toggle(Node *t){return data.toggle(t);}\n  template<typename E>\n  inline void propagate(Node *t,E x){return data.propagate(t,x);}\n  inline Node* pushup(Node *t){return data.pushup(t);}\n\n  inline decltype(auto) get_val(Node *a,size_t k){\n    return data.get_val(super::get_val(a,k));\n  }\n\n  using super::query;\n  inline decltype(auto) query(Node *a){\n    return data.reflect(a);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "bbst/rbst/impl/persistent.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../rbst.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename Data, size_t LIM>\nstruct Persistent : RBST<Persistent<Data, LIM>, Data, typename Data::Node, LIM>{\n  using super = RBST<Persistent, Data, typename Data::Node, LIM>;\n  using Node = typename Data::Node;\n\n  Data data;\n\n  template<class... Args>\n  Persistent(Args... args):data(forward<Args>(args)...){}\n\n  inline Node* clone(Node *t){\n    if(t==nullptr) return t;\n    return super::create(*t);\n  }\n\n  inline Node* touch(Node *t){\n    if(t==nullptr) return t;\n    t=clone(t);\n    if(data.dirty(t)){\n      t->l=clone(t->l);\n      t->r=clone(t->r);\n    }\n    return data.eval(t);\n  }\n\n  using super::toggle;\n  inline void toggle(Node *t){return data.toggle(t);}\n  template<typename E>\n  inline void propagate(Node *t,E x){return data.propagate(t,x);}\n  inline Node* pushup(Node *t){return data.pushup(t);}\n\n  inline decltype(auto) get_val(Node *a,size_t k){\n    return data.get_val(super::get_val(a,k));\n  }\n\n  using super::merge, super::split;\n  decltype(auto) query(Node *a,size_t l,size_t r){\n    auto s=split(a,l);\n    auto t=split(s.second,r-l);\n    auto u=t.first;\n    return data.reflect(u);\n  }\n\n  bool almost_full() const{\n    return super::size+1000>LIM;\n  }\n\n  Node* rebuild(Node* a){\n    auto vs=data.dump(a);\n    super::size=0;\n    return super::build(vs);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"../data/array.cpp\"\n#undef call_from_test\n\nsigned JOISC2012_COPYPASTE(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  int m;\n  string buf;\n  cin>>m>>buf;\n\n  using Data = Array<char>;\n  using Node = Data::Node;\n  const size_t LIM = 1e7;\n  Persistent<Data, LIM> pa;\n\n  vector<Node> vs(buf.begin(),buf.end());\n  auto rt=pa.build(vs);\n\n  int n;\n  cin>>n;\n  for(int i=0;i<n;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    auto s=pa.split(rt,a);\n    auto t=pa.split(s.second,b-a);\n    auto u=pa.split(rt,c);\n    rt=pa.merge(pa.merge(u.first,t.first),u.second);\n\n    if((int)pa.count(rt)>m)\n      rt=pa.split(rt,m).first;\n\n    if(pa.almost_full()) rt=pa.rebuild(rt);\n  }\n\n  auto ds=pa.data.dump(rt);\n  buf.resize(ds.size());\n  for(int i=0;i<(int)ds.size();i++) buf[i]=ds[i].val;\n  cout<<buf<<endl;\n  return 0;\n}\n/*\n  verified on 2020/11/04\n  https://atcoder.jp/contests/joisc2012/tasks/joisc2012_copypaste\n*/\n\n\n#define call_from_test\n#include \"../data/lazy.cpp\"\n#undef call_from_test\n\nsigned ARC030_D(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n\n  using ll = long long;\n  using P = pair<ll, ll>;\n  vector<P> vp(n,P(0,1));\n  for(int i=0;i<n;i++) cin>>vp[i].first;\n\n  auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);};\n  auto g=[](P a,ll b){return P(a.first+b*a.second,a.second);};\n  auto h=[](ll a,ll b){return a+b;};\n  auto flip=[](P a){return a;};\n\n  using Data = Lazy<P, ll, decltype(f), decltype(g), decltype(h),\n                    decltype(flip)>;\n  using Node = Data::Node;\n  constexpr size_t LIM = 6e6;\n  Persistent<Data, LIM> G(f,g,h,flip,P(0,0),0);\n\n  vector<Node> vs;\n  for(auto v:vp) vs.emplace_back(v,0);\n  auto rt=G.build(vs);\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n\n    if(t==1){\n      int a,b,v;\n      cin>>a>>b>>v;\n      a--;\n      rt=G.update(rt,a,b,v);\n    }\n\n    if(t==2){\n      int a,b,c,d;\n      cin>>a>>b>>c>>d;\n      a--;c--;\n      auto s=G.split(rt,a);\n      auto t=G.split(s.second,b-a);\n      auto u=G.split(rt,c);\n      auto v=G.split(u.second,d-c);\n\n      rt=G.merge(G.merge(s.first,v.first),t.second);\n    }\n\n    if(t==3){\n      int a,b;\n      cin>>a>>b;\n      a--;\n      cout<<G.query(rt,a,b).first<<newl;\n    }\n\n    if(G.almost_full()) rt=G.rebuild(rt);\n  }\n  return 0;\n}\n/*\n  verified on 2020/11/04\n  https://atcoder.jp/contests/arc030/tasks/arc030_4\n*/\n\n//INSERT ABOVE HERE\nsigned main(){\n  //JOISC2012_COPYPASTE();\n  //ARC030_D();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "bbst/rbst/rbst.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename Impl, typename Data, typename Node, size_t LIM>\nstruct RBST{\n  using u32 = uint32_t;\n  u32 xor128(){\n    static u32 x = 123456789;\n    static u32 y = 362436069;\n    static u32 z = 521288629;\n    static u32 w = 88675123;\n\n    u32 t = x ^ (x << 11);\n    x = y; y = z; z = w;\n    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));\n  }\n\n  alignas(Node) static inline char pool[sizeof(Node)*LIM];\n  static inline Node* ptr = (Node*)pool;\n  static inline size_t size;\n\n  template<typename... Args>\n  inline Node* create(Args&&... args){\n    return new (ptr+size++) Node(std::forward<Args>(args)...);\n  }\n\n  inline size_t count(const Node *t){return Data::count(t);}\n\n  inline Node* touch(Node *t){\n    return static_cast<Impl*>(this)->touch(t);\n  }\n\n  inline void toggle(Node *t){\n    return static_cast<Impl*>(this)->toggle(t);\n  }\n\n  inline Node* pushup(Node *t){\n    return static_cast<Impl*>(this)->pushup(t);\n  }\n\n  Node* toggle(Node *a,size_t l,size_t r){\n    auto s=split(a,l);\n    auto t=split(s.second,r-l);\n    auto u=touch(t.first);\n    toggle(u);\n    return merge(s.first,merge(u,t.second));\n  }\n\n  Node* merge(Node* a,Node* b){\n    if(a==nullptr) return b;\n    if(b==nullptr) return a;\n    if(xor128()%(count(a)+count(b))<count(a)){\n      a=touch(a);\n      a->r=merge(a->r,b);\n      a->r->p=a;\n      return pushup(a);\n    }\n    b=touch(b);\n    b->l=merge(a,b->l);\n    b->l->p=b;\n    return pushup(b);\n  }\n\n  pair<Node*, Node*> split(Node* a,size_t k){\n    if(a==nullptr) return make_pair(a,a);\n    a=touch(a);\n    if(k<=count(a->l)){\n      if(a->l) a->l->p=nullptr;\n      auto s=split(a->l,k);\n      a->l=s.second;\n      if(a->l) a->l->p=a;\n      return make_pair(s.first,pushup(a));\n    }\n    if(a->r) a->r->p=nullptr;\n    auto s=split(a->r,k-(count(a->l)+1));\n    a->r=s.first;\n    if(a->r) a->r->p=a;\n    return make_pair(pushup(a),s.second);\n  }\n\n  Node* insert(Node *a,size_t k,Node v){\n    Node* b=create(v);\n    auto s=split(a,k);\n    return merge(merge(s.first,b),s.second);\n  }\n\n  Node* erase(Node *a,size_t k){\n    assert(k<count(a));\n    auto s=split(a,k);\n    auto t=split(s.second,1);\n    return merge(s.first,t.second);\n  }\n\n  Node* find_by_order(Node *a,size_t k){\n    assert(k<count(a));\n    a=touch(a);\n    size_t num=count(a->l);\n    if(k<num) return find_by_order(a->l,k);\n    if(k>num) return find_by_order(a->r,k-(num+1));\n    return a;\n  }\n\n  inline bool is_right(Node* a){\n    return a->p and a->p->r==a;\n  }\n\n  size_t order_of_key(Node* a){\n    size_t res=count(a->l);\n    while(a){\n      if(is_right(a)) res+=count(a->p->l)+1;\n      a=a->p;\n    }\n    return res;\n  }\n\n  Node* build(size_t l,size_t r,const vector<Node> &vs){\n    if(l+1==r) return create(vs[l]);\n    size_t m=(l+r)>>1;\n    return merge(build(l,m,vs),build(m,r,vs));\n  }\n\n  Node* build(const vector<Node> &vs){\n    return build(0,vs.size(),vs);\n  }\n\n  template<typename T>\n  Node* set_val(Node *a,size_t k,T val){\n    assert(k<count(a));\n    a=touch(a);\n    size_t num=count(a->l);\n    if(k<num) a->l=set_val(a->l,k,val);\n    if(k>num) a->r=set_val(a->r,k-(num+1),val);\n    if(k==num) a->val=val;\n    return pushup(a);\n  }\n\n  Node* get_val(Node *a,size_t k){\n    assert(k<count(a));\n    a=touch(a);\n    size_t num=count(a->l);\n    if(k<num) return get_val(a->l,k);\n    if(k>num) return get_val(a->r,k-(num+1));\n    return a;\n  }\n\n  template<typename E>\n  Node* update(Node *a,size_t l,size_t r,E v){\n    auto s=split(a,l);\n    auto t=split(s.second,r-l);\n    auto u=touch(t.first);\n    static_cast<Impl*>(this)->propagate(u,v);\n    return merge(s.first,merge(u,t.second));\n  }\n\n  decltype(auto) query(Node *&a,size_t l,size_t r){\n    auto s=split(a,l);\n    auto t=split(s.second,r-l);\n    auto u=t.first;\n    auto res=static_cast<Impl*>(this)->query(u);\n    a=merge(s.first,merge(u,t.second));\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "bflow/capacityscaling.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(m^2 \\log m \\log U)\n// U: maximum capacity\nenum Objective{\n  MINIMIZE = +1,\n  MAXIMIZE = -1,\n};\ntemplate<typename Flow, typename Cost,\n         Objective objective = Objective::MINIMIZE>\nstruct MinCostFlow{\n  template<typename T> inline void chmin(T &x,T y){x=min(x,y);}\n\n  struct Edge{\n    int src,dst;\n    Flow flow,cap;\n    Cost cost;\n    int rev;\n    Edge(int src,int dst,Flow cap,Cost cost,int rev):\n      src(src),dst(dst),flow(0),cap(cap),cost(cost),rev(rev){}\n    Flow residual_cap()const{return cap-flow;}\n  };\n\n  struct EdgePtr{\n    int v,e;\n    EdgePtr(int v,int e):v(v),e(e){}\n  };\n\n  int n;\n  vector<vector<Edge>> G;\n  vector<Flow> b;\n  vector<Cost> p;\n\n  MinCostFlow(int n):n(n),G(n),b(n,0){}\n\n  EdgePtr add_edge(int src,int dst,Flow lower,Flow upper,Cost cost){\n    int e=G[src].size();\n    int r=(src==dst?e+1:G[dst].size());\n    assert(lower<=upper);\n    G[src].emplace_back(src,dst,+upper,+cost*objective,r);\n    G[dst].emplace_back(dst,src,-lower,-cost*objective,e);\n    return EdgePtr(src,e);\n  }\n\n  const Edge &get_edge(EdgePtr ep)const{return G[ep.v][ep.e];}\n\n  void push(Edge &e,Flow amount){\n    e.flow+=amount;\n    G[e.dst][e.rev].flow-=amount;\n  }\n\n  void add_supply(int v,Flow amount){b[v]+=amount;}\n  void add_demand(int v,Flow amount){b[v]-=amount;}\n\n  Cost residual_cost(const Edge &e){\n    return e.cost+p[e.src]-p[e.dst];\n  }\n\n  vector<int> excess_vs,deficit_vs;\n  void saturate_negative(const Flow delta){\n    for(auto &es:G){\n      for(auto &e:es){\n        Flow cap=e.residual_cap();\n        cap-=cap%delta;\n        if(cap<0 or residual_cost(e)<0){\n          push(e,cap);\n          b[e.src]-=cap;\n          b[e.dst]+=cap;\n        }\n      }\n    }\n\n    excess_vs.clear();\n    deficit_vs.clear();\n    for(int v=0;v<n;v++){\n      if(b[v]>0) excess_vs.emplace_back(v);\n      if(b[v]<0) deficit_vs.emplace_back(v);\n    }\n  }\n\n  const Cost unreachable = std::numeric_limits<Cost>::max();\n  Cost farthest;\n  vector<Cost> dist;\n  vector<Edge*> parent;\n\n  struct P{\n    Cost first;\n    int second;\n    P(Cost first,int second):first(first),second(second){}\n    bool operator<(const P o)const{return first>o.first;}\n  };\n\n  priority_queue<P> pq;\n\n  template<typename Predicate>\n  void eliminate(vector<int> &vs,Predicate predicate){\n    vs.erase(remove_if(begin(vs),end(vs),predicate),end(vs));\n  }\n\n  bool dual(const Flow delta){\n    eliminate(excess_vs, [&](int v){return b[v]<+delta;});\n    eliminate(deficit_vs,[&](int v){return b[v]>-delta;});\n\n    dist.assign(n,unreachable);\n    for(int v:excess_vs) pq.emplace(dist[v]=0,v);\n\n    parent.assign(n,nullptr);\n    auto emplace=[&](Edge& e){\n      if(e.residual_cap()<delta) return;\n      Cost nxt=dist[e.src]+residual_cost(e);\n      if(nxt>=dist[e.dst]) return;\n      pq.emplace(dist[e.dst]=nxt,e.dst);\n      parent[e.dst]=&e;\n    };\n\n    farthest=0;\n    int deficit_count=0;\n    while(!pq.empty()){\n      Cost d=pq.top().first;\n      int v=pq.top().second;\n      pq.pop();\n      if(dist[v]<d) continue;\n      farthest=d;\n\n      if(b[v]<=-delta) deficit_count++;\n      if(deficit_count>=(int)deficit_vs.size()) break;\n\n      for(auto &e:G[v]) emplace(e);\n    }\n    pq=decltype(pq)();\n\n    for(int v=0;v<n;v++)\n      p[v]+=min(dist[v],farthest);\n\n    return deficit_count>0;\n  }\n\n  void primal(const Flow delta){\n    for(int t:deficit_vs){\n      if(dist[t]>farthest) continue;\n      Flow f=-b[t];\n      int v;\n      for(v=t;parent[v];v=parent[v]->src)\n        chmin(f,parent[v]->residual_cap());\n      chmin(f,b[v]);\n\n      f-=f%delta;\n      if(f<=0) continue;\n\n      for(v=t;parent[v];){\n        auto &e=*parent[v];\n        push(e,f);\n        int u=parent[v]->src;\n        if(e.residual_cap()<=0) parent[v]=nullptr;\n        v=u;\n      }\n      b[t]+=f;\n      b[v]-=f;\n    }\n  }\n\n  template<Flow SCALING_FACTOR=2>\n  bool build(){\n    p.resize(n);\n    Flow max_flow=1;\n    for(auto t:b) max_flow=max({max_flow,t,-t});\n    for(auto &es:G)\n      for(auto &e:es)\n        max_flow=max({max_flow,e.residual_cap(),-e.residual_cap()});\n\n    Flow delta=1;\n    while(delta<max_flow) delta*=SCALING_FACTOR;\n    for(;delta;delta/=SCALING_FACTOR){\n      saturate_negative(delta);\n      while(dual(delta)) primal(delta);\n    }\n\n    return excess_vs.empty() and deficit_vs.empty();\n  }\n\n  template<typename T=Cost>\n  T get_cost(){\n    T res=0;\n    for(auto &es:G)\n      for(auto &e:es)\n        res+=T(e.flow)*T(e.cost)/T(objective);\n    return res/T(2);\n  }\n  template<typename T=Cost> T get_gain(){return get_cost();}\n\n  vector<Cost> get_potential(){\n    fill(p.begin(),p.end(),0);\n    for(int i=0;i<n;i++)\n      for(auto &es:G)\n        for(auto &e:es)\n          if(e.residual_cap()>0)\n            chmin(p[e.dst],p[e.src]+e.cost);\n    return p;\n  }\n};\n\ntemplate<typename Flow, typename Cost>\nusing MaxGainFlow = MinCostFlow<Flow, Cost, Objective::MAXIMIZE>;\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "clean.sh",
    "content": "#!/bin/bash\nfind . -name '*~' | xargs rm -v\nfind . -name 'a.out' | grep -v verify-helper | xargs rm -v\n"
  },
  {
    "path": "combinatorics/bell.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"enumeration.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n// put n distinct balls into at most k identical boxes\ntemplate<typename M>\nM bell(int n,int k){\n  if(n==0) return M(1);\n\n  using E = Enumeration<M>;\n  k=min(k,n);\n  E::init(k);\n\n  vector<M> dp(k+1);\n  dp[0]=M(1);\n  for(int i=1;i<=k;i++)\n    dp[i]=dp[i-1]+((i&1)?-E::Finv(i):E::Finv(i));\n\n  M res(0);\n  for(int i=1;i<=k;i++)\n    res+=M(i).pow(n)*E::Finv(i)*dp[k-i];\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "combinatorics/bernoulli.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"enumeration.cpp\"\n#include \"../formalpowerseries/base.cpp\"\n#include \"../formalpowerseries/inv.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M_>\nstruct Bernoulli : FormalPowerSeries<M_>{\n  using M = M_;\n  using super = FormalPowerSeries<M>;\n  using Poly = typename super::Poly;\n  using super::super, super::fact, super::finv;\n\n  Poly rs;\n  void build(int n){\n    super::init(n+2);\n    rs.assign(n+1,M(1));\n    for(int i=1;i<=n;i++) rs[i]=finv[i+1];\n    rs=super::inv(rs,n+1);\n    for(int i=1;i<=n;i++) rs[i]*=fact[i];\n  }\n\n  M operator[](int k)const{return rs[k];}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "combinatorics/enumeration.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename M_>\nclass Enumeration{\n  using M = M_;\nprotected:\n  inline static vector<M> fact,finv,invs;\npublic:\n  static void init(int n){\n    n=min<decltype(M::mod)>(n,M::mod-1);\n\n    int m=fact.size();\n    if(n<m) return;\n\n    fact.resize(n+1,1);\n    finv.resize(n+1,1);\n    invs.resize(n+1,1);\n\n    if(m==0) m=1;\n    for(int i=m;i<=n;i++) fact[i]=fact[i-1]*M(i);\n    finv[n]=M(1)/fact[n];\n    for(int i=n;i>=m;i--) finv[i-1]=finv[i]*M(i);\n    for(int i=m;i<=n;i++) invs[i]=finv[i]*fact[i-1];\n  }\n\n  static M Fact(int n){\n    init(n);\n    return fact[n];\n  }\n  static M Finv(int n){\n    init(n);\n    return finv[n];\n  }\n  static M Invs(int n){\n    init(n);\n    return invs[n];\n  }\n\n  static M C(int n,int k){\n    if(n<k or k<0) return M(0);\n    init(n);\n    return fact[n]*finv[n-k]*finv[k];\n  }\n\n  static M P(int n,int k){\n    if(n<k or k<0) return M(0);\n    init(n);\n    return fact[n]*finv[n-k];\n  }\n\n  // put n identical balls into k distinct boxes\n  static M H(int n,int k){\n    if(n<0 or k<0) return M(0);\n    if(!n and !k) return M(1);\n    init(n+k);\n    return C(n+k-1,n);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "combinatorics/partition.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"enumeration.cpp\"\n#include \"../formalpowerseries/base.cpp\"\n#include \"../formalpowerseries/inv.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M_>\nstruct Partition : FormalPowerSeries<M_>{\n  using M = M_;\n  using super = FormalPowerSeries<M>;\n  using Poly = typename super::Poly;\n  using super::super;\n\n  Poly rs;\n  void build(int n){\n    rs.resize(n+1);\n    rs[0]=M(1);\n    for(int k=1;k<=n;k++){\n      if(1LL*k*(3*k+1)/2<=n) rs[k*(3*k+1)/2]+=k%2?-M(1):M(1);\n      if(1LL*k*(3*k-1)/2<=n) rs[k*(3*k-1)/2]+=k%2?-M(1):M(1);\n    }\n    rs=super::inv(rs,n+1);\n  }\n\n  M operator[](int k)const{return rs[k];}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "combinatorics/partitiontable.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename M>\nstruct PartitionTable{\n  vector< vector<M> > dp;\n  PartitionTable(int h,int w):dp(h+1,vector<M>(w+1,0)){\n    dp[0][0]=M(1);\n    for(int i=0;i<=h;i++){\n      for(int j=1;j<=w;j++){\n        dp[i][j]=dp[i][j-1];\n        if(i-j>=0) dp[i][j]+=dp[i-j][j];\n      }\n    }\n  }\n\n  // put n identical balls into k identical boxes\n  M operator()(int n,int k){return dp[n][k];}\n\n  // put n identical balls into some boxes\n  M operator()(int n){return dp[n][n];}\n};\n//END CUT HERE\n\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "combinatorics/stirling1st.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"enumeration.cpp\"\n#include \"../formalpowerseries/base.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M_>\nstruct Stirling1st : FormalPowerSeries<M_>{\n  using M = M_;\n  using super = FormalPowerSeries<M>;\n  using Poly = typename super::Poly;\n  using super::super, super::fact, super::finv, super::mul;\n\n  Poly rs;\n  void build(int n){\n    super::init(n+1);\n    if(n==0){\n      rs={M(1)};\n      return;\n    }\n    int m=1;\n    rs=Poly({M(0),M(1)});\n    for(int e=31-__builtin_clz(n)-1;e>=0;e--){\n      Poly as(m+1),bs(m+1);\n      for(int i=0;i<=m;i++) as[i]=fact[i]*rs[i];\n      bs[m-0]=M(1);\n      for(int i=1;i<=m;i++) bs[m-i]=bs[m-(i-1)]*-M(m);\n      for(int i=0;i<=m;i++) bs[m-i]*=finv[i];\n      Poly cs=mul(as,bs);\n      Poly ds(m+1);\n      for(int i=0;i<=m;i++) ds[i]=finv[i]*cs[m+i];\n      rs=mul(rs,ds);\n      m<<=1;\n      if((n>>e)&1){\n        Poly ts(m+1+1,M(0));\n        for(int i=0;i<=m;i++){\n          ts[i+0]+=rs[i]*-M(m);\n          ts[i+1]+=rs[i];\n        }\n        rs=ts;\n        m|=1;\n      }\n    }\n    assert(m==n);\n  }\n\n  M operator[](int k)const{return rs[k];}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "combinatorics/stirling2nd.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"enumeration.cpp\"\n#include \"../formalpowerseries/base.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M_>\nstruct Stirling2nd : FormalPowerSeries<M_>{\n  using M = M_;\n  using super = FormalPowerSeries<M>;\n  using Poly = typename super::Poly;\n  using super::super, super::finv;\n\n  Poly rs;\n  void build(int n){\n    super::init(n+1);\n    Poly as(n+1),bs(n+1);\n    for(int i=0;i<=n;i++){\n      as[i]=M(i).pow(n)*finv[i];\n      bs[i]=(i&1?-M(1):M(1))*finv[i];\n    }\n    rs=super::pre(super::mul(as,bs),n+1);\n  }\n\n  M operator[](int k)const{return rs[k];}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "combinatorics/surjection.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"enumeration.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n// put n distinct balls into k distinct boxes\ntemplate<typename M>\nM surjection(int n,int k){\n  using E = Enumeration<M>;\n  E::init(k);\n  M res(0);\n  for(int i=1;i<=k;i++){\n    M tmp=E::C(k,i)*M(i).pow(n);\n    if((k-i)&1) res-=tmp;\n    else res+=tmp;\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convexhulltrick/convexhulltrick.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nenum Objective{\n  MINIMIZE = +1,\n  MAXIMIZE = -1,\n};\n\ntemplate<typename T> struct Line {\n  T k,m;\n  T operator()(const T x)const{return k*x+m;}\n};\n\ntemplate <typename T, Objective objective>\nstruct ConvexHullTrick : deque<Line<T>>{\n  inline int sgn(T x){return x==0?0:(x<0?-1:1);}\n\n  using D = long double;\n  inline bool check(const Line<T> &a,const Line<T> &b,const Line<T> &c){\n    if(b.m==a.m or c.m==b.m)\n      return sgn(b.k-a.k)*sgn(c.m-b.m) >= sgn(c.k-b.k)*sgn(b.m-a.m);\n    // return (b.k-a.k)*(c.m-b.m) >= (b.m-a.m)*(c.k-b.k);\n    return\n      D(b.k-a.k)*sgn(c.m-b.m)/D(abs(b.m-a.m)) >=\n      D(c.k-b.k)*sgn(b.m-a.m)/D(abs(c.m-b.m));\n  }\n\n  using super = deque<Line<T>>;\n  using super::empty,super::size,super::front,super::back;\n  using super::emplace_front,super::emplace_back;\n  using super::pop_front,super::pop_back;\n  const Line<T> at(int i) const{return (*this)[i];}\n\n  void add(T k_,T m_){\n    Line<T> l({k_*objective,m_*objective});\n    if(empty()){\n      emplace_front(l);\n      return;\n    }\n    if(front().k<=l.k){\n      if(front().k==l.k){\n        if(front().m<=l.m) return;\n        pop_front();\n      }\n      while(size()>=2 and check(l,at(0),at(1))) pop_front();\n      emplace_front(l);\n    }else{\n      assert(l.k<=back().k);\n      if(back().k==l.k){\n        if(back().m<=l.m) return;\n        pop_back();\n      }\n      while(size()>=2 and check(at(size()-2),at(size()-1),l)) pop_back();\n      emplace_back(l);\n    }\n  }\n\n  T query(T x){\n    assert(!empty());\n    int l=-1,r=size()-1;\n    while(l+1<r){\n      int m=(l+r)>>1;\n      if(at(m)(x)>=at(m+1)(x)) l=m;\n      else r=m;\n    }\n    return at(r)(x)*objective;\n  }\n\n  T queryMonotoneInc(T x){\n    assert(!empty());\n    while(size()>=2 and at(0)(x)>=at(1)(x)) pop_front();\n    return front()(x)*objective;\n  }\n\n  T queryMonotoneDec(T x){\n    assert(!empty());\n    while(size()>=2 and at(size()-1)(x)>=at(size()-2)(x)) pop_back();\n    return back()(x)*objective;\n  }\n\n  vector<pair<T, T>> getVertices(){\n    vector<pair<T, T>> res;\n    for(int i=0;i+1<(int)size();i++){\n      auto l0=at(i+0),l1=at(i+1);\n      assert(l0.k!=l1.k);\n      T x=(l1.m-l0.m)/(l0.k-l1.k);\n      res.emplace_back(x,at(i)(x)*objective);\n    }\n    return res;\n  }\n};\ntemplate<typename T>\nusing MinConvexHullTrick = ConvexHullTrick<T, Objective::MINIMIZE>;\ntemplate<typename T>\nusing MaxConvexHullTrick = ConvexHullTrick<T, Objective::MAXIMIZE>;\n\ntemplate<typename T>\nvoid chmin(optional<T> &a,const T& b){if(!a or *a>b) a=b;}\n\n// O(n \\log n) (n = as.size())\ntemplate<typename T, Objective objective>\noptional<T> solve_lp(T p0,T p1,vector<T> as,vector<T> bs,vector<T> cs){\n  auto calc=[&](T y0,T y1){return y0*p0+y1*p1;};\n  using P = pair<T, T>;\n  vector<P> vp;\n  for(int i=0;i<(int)as.size();i++)\n    vp.emplace_back(-bs[i]/as[i],cs[i]/as[i]);\n  sort(vp.begin(),vp.end());\n\n  ConvexHullTrick<T, objective> cht;\n  for(auto[k,m]:vp) cht.add(k,m);\n\n  optional<T> res;\n  for(auto[y1,y0]:cht.getVertices())\n    if(y0>=0 and y1>=0) chmin(res,calc(y0,y1));\n  return res;\n}\n\n// minimize_{y0, y1 >=0} p0 y0 + p1 y1\n// s.t. as[i] * y0 + bs[i] * y1 >= cs[i]\n// assume as[i], bs[i] >0\ntemplate<typename T>\nT solve_lp_min(T p0,T p1,vector<T> as,vector<T> bs,vector<T> cs){\n  T y0=0,y1=0;\n  for(int i=0;i<(int)as.size();i++){\n    y0=max(y0,cs[i]/as[i]);\n    y1=max(y1,cs[i]/bs[i]);\n  }\n  auto res=solve_lp<T, Objective::MAXIMIZE>(+p0,+p1,as,bs,cs);\n  chmin(res,p0*y0);\n  chmin(res,p1*y1);\n  return *res;\n}\n\n// maximize_{y0, y1 >=0} p0 y0 + p1 y1\n// s.t. as[i] * y0 + bs[i] * y1 <= cs[i]\n// assume as[i], bs[i] >0, cs[i] >=0\ntemplate<typename T>\nT solve_lp_max(T p0,T p1,vector<T> as,vector<T> bs,vector<T> cs){\n  T y0=cs[0]/as[0],y1=cs[0]/bs[0];\n  for(int i=0;i<(int)as.size();i++){\n    y0=min(y0,cs[i]/as[i]);\n    y1=min(y1,cs[i]/bs[i]);\n    as[i]=-as[i];bs[i]=-bs[i];cs[i]=-cs[i];\n  }\n  auto res=solve_lp<T, Objective::MINIMIZE>(-p0,-p1,as,bs,cs);\n  chmin(res,-p0*y0);\n  chmin(res,-p1*y1);\n  return -*res;\n}\n\n\n//END CUT HERE\n#ifndef call_from_test\n\nsigned ARC128_C(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,s;\n  cin>>n>>m>>s;\n\n  using D = double;\n  vector<D> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  vector<D> bs(n+1,0),cs(n+1,0);\n  for(int i=0;i<=n;i++) bs[i]=n-i;\n  for(int i=n;i>0;i--) cs[i-1]=as[i-1]+cs[i];\n\n  D ans=solve_lp_min<D>(m,s,vector<D>(n+1,1),bs,cs);\n  cout<<fixed<<setprecision(12)<<ans<<endl;\n  return 0;\n}\n/*\n  verified on 2021/10/17\n  https://atcoder.jp/contests/arc128/tasks/arc128_c\n*/\n\nsigned main(){\n  ARC128_C();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convexhulltrick/linecontainer.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nenum Objective{\n  MAXIMIZE = +1,\n  MINIMIZE = -1,\n};\n\ntemplate<typename T>\nstruct Line {\n  mutable T k,m,p;\n  bool operator<(const Line&o)const{return k<o.k;}\n  bool operator<(T x)const{return p<x;}\n};\n\ntemplate<typename T> T lc_inf(){return numeric_limits<T>::max();}\ntemplate<> double lc_inf<double>(){return 1/.0;}\n\ntemplate<typename T> T lc_div(T a,T b){return a/b-((a^b)<0 and a%b);}\ntemplate<> double lc_div(double a,double b){return a/b;};\n\ntemplate<typename T, Objective objective>\nstruct LineContainer : multiset<Line<T>, less<>>{\n  using super = multiset<Line<T>, less<>>;\n  using super::begin,super::end,super::insert,super::erase;\n  using super::empty,super::lower_bound;\n  const T inf = lc_inf<T>();\n  bool insect(typename super::iterator x,typename super::iterator y){\n    if(y==end()) return x->p=inf,false;\n    if(x->k==y->k) x->p=(x->m>y->m?inf:-inf);\n    else x->p=lc_div(y->m-x->m,x->k-y->k);\n    return x->p>=y->p;\n  }\n  void add(T k,T m){\n    auto z=insert({k*objective,m*objective,0}),y=z++,x=y;\n    while(insect(y,z)) z=erase(z);\n    if(x!=begin() and insect(--x,y)) insect(x,y=erase(y));\n    while((y=x)!=begin() and (--x)->p>=y->p) insect(x,erase(y));\n  }\n  T query(T x){\n    assert(!empty());\n    auto l=*lower_bound(x);\n    return (l.k*x+l.m)*objective;\n  }\n};\ntemplate<typename T>\nusing MinLineContainer = LineContainer<T, Objective::MINIMIZE>;\ntemplate<typename T>\nusing MaxLineContainer = LineContainer<T, Objective::MAXIMIZE>;\n//END CUT HERE\n\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convexhulltrick/segmentcontainer.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nenum Objective{\n  MINIMIZE = +1,\n  MAXIMIZE = -1,\n};\n\ntemplate <typename T,Objective objective>\nstruct SegmentContainer{\n  const T INF = numeric_limits<T>::max() / 2;\n  struct Segment{\n    T a,b;\n    T operator()(T x) const{return a*x+b;}\n  };\n\n  int n;\n  vector<T> xs;\n  vector<Segment> dat;\n  SegmentContainer(const vector<T> &xs_):xs(xs_){\n    sort(xs.begin(),xs.end());\n    xs.erase(unique(xs.begin(),xs.end()),xs.end());\n    n=xs.size();\n    dat.assign(n<<1,Segment({T(0),INF}));\n  }\n\n  inline int index(T x) const{\n    return lower_bound(xs.begin(),xs.end(),x)-xs.begin();\n  }\n\n  // [xl, xr)\n  void add(T a,T b,T xl,T xr){\n    Segment g({a*objective,b*objective});\n    for(int l=index(xl)+n,r=index(xr)+n;l<r;l>>=1,r>>=1){\n      if(l&1) update(g,l++);\n      if(r&1) update(g,--r);\n    }\n  }\n\n  void update(Segment g,int i){\n    int l=i,r=i+1;\n    while(l<n) l<<=1,r<<=1;\n    while(l<r){\n      int m=(l+r)>>1;\n      T xl=xs[l-n],xr=xs[r-1-n],xm=xs[m-n];\n      Segment &f=dat[i];\n      if(f(xl)<=g(xl) and f(xr)<=g(xr)) return;\n      if(f(xl)>=g(xl) and f(xr)>=g(xr)) return (void)(f=g);\n      if(f(xm)>g(xm)) swap(f,g);\n      if(f(xl)>g(xl)) i=(i<<1)|0,r=m;\n      else i=(i<<1)|1,l=m;\n    }\n  }\n\n  T query(T x){\n    T res=INF;\n    for(int i=index(x)+n;i;i>>=1) res=min(res,dat[i](x));\n    return res*objective;\n  }\n};\ntemplate<typename T>\nusing MinSegmentContainer = SegmentContainer<T, Objective::MINIMIZE>;\ntemplate<typename T>\nusing MaxSegmentContainer = SegmentContainer<T, Objective::MAXIMIZE>;\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convexhulltrick/withindex.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n//BEGIN CUT HERE\n// index siyou kimattenai\ntemplate <typename T,bool isMin>\nstruct ConvexHullTrickWithIndex {\n  struct P{\n    T m,b;\n    int idx;\n    P(T m,T b,int idx):m(m),b(b),idx(idx){};\n    bool operator<(const P &a){\n      return m!=a.m?m<a.m:b<a.b;\n    }\n  };\n\n  deque<P> H;\n  bool empty()const{return H.empty();}\n  void clear(){H.clear();}\n\n  inline int sgn(T x){return x==0?0:(x<0?-1:1);}\n\n  using D = long double;\n  inline bool check(const P &a,const P &b,const P &c){\n    if(b.b==a.b or c.b==b.b)\n      return sgn(b.m-a.m)*sgn(c.b-b.b) >= sgn(c.m-b.m)*sgn(b.b-a.b);\n    return D(b.m-a.m)*sgn(c.b-b.b)/D(abs(b.b-a.b))\n      >= D(c.m-b.m)*sgn(b.b-a.b)/D(abs(c.b-b.b));\n  }\n\n  void addLine(T m,T b,int idx){\n    if(!isMin) m*=-1,b*=-1;\n    P line(m,b,idx);\n    if(empty()){\n      H.emplace_front(line);\n      return;\n    }\n\n    if(empty() or H.front().m<=m){\n      if(H.front().m==m){\n        if(H.front().b<=b) return;\n        H.pop_front();\n      }\n      while(H.size()>=2 and check(line,H.front(),H[1])) H.pop_front();\n      H.emplace_front(line);\n    }else{\n      assert(m<=H.back().m);\n      if(H.back().m==m){\n        if(H.back().b<=b) return;\n        H.pop_back();\n      }\n      while(H.size()>=2 and check(H[H.size()-2],H.back(),line)) H.pop_back();\n      H.emplace_back(line);\n    }\n  }\n\n  inline pair<T, int> getY(const P &a,const T &x){\n    return make_pair(a.m*x+a.b,a.idx);\n  }\n\n  pair<T, int> query(T x){\n    assert(!empty());\n    int l=-1,r=H.size()-1;\n    while(l+1<r){\n      int m=(l+r)>>1;\n      if(getY(H[m],x)>=getY(H[m+1],x)) l=m;\n      else r=m;\n    }\n    if(isMin) return getY(H[r],x);\n    return make_pair(-getY(H[r],x).first,H[r].idx);\n  }\n\n  pair<T, int> queryMonotoneInc(T x){\n    assert(!empty());\n    while(H.size()>=2 and getY(H.front(),x)>=getY(H[1],x)) H.pop_front();\n    if(isMin) return getY(H.front(),x);\n    return make_pair(-getY(H.front(),x).first,H.front().idx);\n  }\n\n  pair<T, int> queryMonotoneDec(T x){\n    assert(!empty());\n    while(H.size()>=2 and getY(H.back(),x)>=getY(H[H.size()-2],x)) H.pop_back();\n    if(isMin) return getY(H.back(),x);\n    return make_pair(-getY(H.back(),x).first,H.back().idx);\n  }\n};\n//END CUT HERE\n//INSERT ABOVE HERE\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  ll n,m;\n  cin>>n>>m;\n\n  using CHT = ConvexHullTrickWithIndex<ll, true>;\n\n  CHT cht;\n  ll bs=0,ss=0,len=n;\n  cht.addLine(0,-bs,0);\n\n  for(int i=0;i<m;i++){\n    int t;\n    cin>>t;\n    if(t==1){\n      ll k;\n      cin>>k;\n      cht.clear();\n      cht.addLine(0,-bs,0);\n      len+=k;\n    }\n    if(t==2){\n      ll k;\n      cin>>k;\n      cht.addLine(len,-(bs+len*ss),len);\n      len+=k;\n    }\n    if(t==3){\n      ll b,s;\n      cin>>b>>s;\n      bs+=b;\n      ss+=s;\n    }\n    auto p=cht.queryMonotoneInc(ss);\n    cout<<p.second+1<<\" \"<<bs+p.first<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n/*\n  verified on 2019/05/14\n  https://codeforces.com/contest/1137/problem/E\n*/\n"
  },
  {
    "path": "convolution/arbitrarymod.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"fastfouriertransform.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct ArbitraryMod{\n  using dbl=FFT::dbl;\n  using num=FFT::num;\n\n  vector<T> multiply(vector<T> as,vector<T> bs){\n    int need=as.size()+bs.size()-1;\n    int sz=1;\n    while(sz<need) sz<<=1;\n    vector<num> fa(sz),fb(sz);\n    for(int i=0;i<(int)as.size();i++)\n      fa[i]=num(as[i].v&((1<<15)-1),as[i].v>>15);\n    for(int i=0;i<(int)bs.size();i++)\n      fb[i]=num(bs[i].v&((1<<15)-1),bs[i].v>>15);\n\n    fft(fa);fft(fb);\n\n    dbl ratio=0.25/sz;\n    num r2(0,-1),r3(ratio,0),r4(0,-ratio),r5(0,1);\n    for(int i=0;i<=(sz>>1);i++){\n      int j=(sz-i)&(sz-1);\n      num a1=(fa[i]+conj(fa[j]));\n      num a2=(fa[i]-conj(fa[j]))*r2;\n      num b1=(fb[i]+conj(fb[j]))*r3;\n      num b2=(fb[i]-conj(fb[j]))*r4;\n      if(i!=j){\n        num c1=(fa[j]+conj(fa[i]));\n        num c2=(fa[j]-conj(fa[i]))*r2;\n        num d1=(fb[j]+conj(fb[i]))*r3;\n        num d2=(fb[j]-conj(fb[i]))*r4;\n        fa[i]=c1*d1+c2*d2*r5;\n        fb[i]=c1*d2+c2*d1;\n      }\n      fa[j]=a1*b1+a2*b2*r5;\n      fb[j]=a1*b2+a2*b1;\n    }\n    fft(fa);fft(fb);\n\n    vector<T> cs(need);\n    using ll = long long;\n    for(int i=0;i<need;i++){\n      ll aa=T(llround(fa[i].x)).v;\n      ll bb=T(llround(fb[i].x)).v;\n      ll cc=T(llround(fa[i].y)).v;\n      cs[i]=T(aa+(bb<<15)+(cc<<30));\n    }\n    return cs;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convolution/bitwise/and.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nnamespace bitwise_and{\n  auto zeta=[](auto& lo,auto& hi){lo+=hi;};\n  auto moebius=[](auto& lo,auto& hi){lo-=hi;};\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convolution/bitwise/fwht.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n// https://kazuma8128.hatenablog.com/entry/2018/05/31/144519\n//BEGIN CUT HERE\n// O(n \\log n)\ntemplate<typename T, typename F>\nvoid fwht(vector<T> &as,F f){\n  int n=as.size();\n  for(int d=1;d<n;d<<=1)\n    for(int m=d<<1,i=0;i<n;i+=m)\n      for(int j=0;j<d;j++)\n        f(as[i+j],as[i+j+d]);\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convolution/bitwise/or.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nnamespace bitwise_or{\n  auto zeta=[](auto& lo,auto& hi){hi+=lo;};\n  auto moebius=[](auto& lo,auto& hi){hi-=lo;};\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convolution/bitwise/xor.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nnamespace bitwise_xor{\n  auto zeta=[](auto& lo,auto& hi){\n    auto x=lo+hi,y=lo-hi;\n    lo=x;\n    hi=y;\n  };\n  auto moebius=[](auto& lo,auto& hi){\n    auto x=lo+hi,y=lo-hi;\n    lo=x/decltype(x)(2);\n    hi=y/decltype(y)(2);\n  };\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convolution/convolution2D.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T,typename Transformer>\nstruct Convolution2D{\n  using Matrix = vector< vector<T> >;\n  const Transformer tran;\n  Convolution2D(Transformer tran):tran(tran){}\n\n  void transpose(Matrix &as){\n    int n=as.size(),m=as[0].size();\n    Matrix cs(as);\n    as.assign(m,vector<T>(n));\n    for(int i=0;i<n;i++)\n      for(int j=0;j<m;j++)\n        as[j][i]=cs[i][j];\n  }\n\n  void transform(Matrix &as,bool f){\n    for(int t=0;t<2;t++){\n      for(auto &a:as) tran(a,f);\n      transpose(as);\n    }\n  }\n\n  Matrix multiply(Matrix as,Matrix bs){\n    int nt=as.size()+bs.size()-1;\n    int mt=as[0].size()+bs[0].size()-1;\n    int n=1,m=1;\n    while(n<nt) n<<=1;\n    while(m<mt) m<<=1;\n    as.resize(n);bs.resize(n);\n    for(int i=0;i<n;i++){\n      as[i].resize(m,T(0));\n      bs[i].resize(m,T(0));\n    }\n    transform(as,0);transform(bs,0);\n    for(int i=0;i<n;i++)\n      for(int j=0;j<m;j++)\n        as[i][j]*=bs[i][j];\n    transform(as,1);\n    return as;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\n#endif\n"
  },
  {
    "path": "convolution/divisor.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n// https://noshi91.hatenablog.com/entry/2019/09/23/002445\n//BEGIN CUT HERE\n// O(n \\log \\log n)\nnamespace DivisorTransform{\n  template<typename T, typename F>\n  void inc(vector<T> &as,F f){\n    assert(as[0]==T(0));\n    int n=as.size();\n    vector<bool> sieve(n,false);\n    for(int p=2;p<n;p++){\n      if(sieve[p]) continue;\n      for(int k=1;k*p<n;k++){\n        sieve[k*p]=true;\n        f(as[k],as[k*p]);\n      }\n    }\n  }\n  template<typename T, typename F>\n  void dec(vector<T> &as,F f){\n    assert(as[0]==T(0));\n    int n=as.size();\n    vector<bool> sieve(n,false);\n    for(int p=2;p<n;p++){\n      if(sieve[p]) continue;\n      for(int k=(n-1)/p;k!=0;--k){\n        sieve[k*p]=true;\n        f(as[k],as[k*p]);\n      }\n    }\n  }\n}\nnamespace GCDConvolution{\n  template<typename T>\n  void zeta(vector<T> &as){\n    auto f=[](T &lo,T &hi){lo+=hi;};\n    DivisorTransform::dec(as,f);\n  }\n  template<typename T>\n  void moebius(vector<T> &as){\n    auto f=[](T &lo,T &hi){lo-=hi;};\n    DivisorTransform::inc(as,f);\n  }\n}\nnamespace LCMConvolution{\n  template<typename T>\n  void zeta(vector<T> &as){\n    auto f=[](T &lo,T &hi){hi+=lo;};\n    DivisorTransform::inc(as,f);\n  }\n  template<typename T>\n  void moebius(vector<T> &as){\n    auto f=[](T &lo,T &hi){hi-=lo;};\n    DivisorTransform::dec(as,f);\n  }\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convolution/fastfouriertransform.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nnamespace FFT{\n  using dbl = double;\n\n  struct num{\n    dbl x,y;\n    num(){x=y=0;}\n    num(dbl x,dbl y):x(x),y(y){}\n  };\n\n  inline num operator+(num a,num b){\n    return num(a.x+b.x,a.y+b.y);\n  }\n  inline num operator-(num a,num b){\n    return num(a.x-b.x,a.y-b.y);\n  }\n  inline num operator*(num a,num b){\n    return num(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);\n  }\n  inline num conj(num a){\n    return num(a.x,-a.y);\n  }\n\n  int base=1;\n  vector<num> rts={{0,0},{1,0}};\n  vector<int> rev={0,1};\n\n  const dbl PI=asinl(1)*2;\n\n  void ensure_base(int nbase){\n    if(nbase<=base) return;\n\n    rev.resize(1<<nbase);\n    for(int i=0;i<(1<<nbase);i++)\n      rev[i]=(rev[i>>1]>>1)+((i&1)<<(nbase-1));\n\n    rts.resize(1<<nbase);\n    while(base<nbase){\n      dbl angle=2*PI/(1<<(base+1));\n      for(int i=1<<(base-1);i<(1<<base);i++){\n        rts[i<<1]=rts[i];\n        dbl angle_i=angle*(2*i+1-(1<<base));\n        rts[(i<<1)+1]=num(cos(angle_i),sin(angle_i));\n      }\n      base++;\n    }\n  }\n\n  void fft(vector<num> &as){\n    int n=as.size();\n    assert((n&(n-1))==0);\n\n    int zeros=__builtin_ctz(n);\n    ensure_base(zeros);\n    int shift=base-zeros;\n    for(int i=0;i<n;i++)\n      if(i<(rev[i]>>shift))\n        swap(as[i],as[rev[i]>>shift]);\n\n    for(int k=1;k<n;k<<=1){\n      for(int i=0;i<n;i+=2*k){\n        for(int j=0;j<k;j++){\n          num z=as[i+j+k]*rts[j+k];\n          as[i+j+k]=as[i+j]-z;\n          as[i+j]=as[i+j]+z;\n        }\n      }\n    }\n  }\n\n  template<typename T>\n  vector<long long> multiply(vector<T> &as,vector<T> &bs){\n    int need=as.size()+bs.size()-1;\n    int nbase=0;\n    while((1<<nbase)<need) nbase++;\n    ensure_base(nbase);\n\n    int sz=1<<nbase;\n    vector<num> fa(sz);\n    for(int i=0;i<sz;i++){\n      T x=(i<(int)as.size()?as[i]:0);\n      T y=(i<(int)bs.size()?bs[i]:0);\n      fa[i]=num(x,y);\n    }\n    fft(fa);\n\n    num r(0,-0.25/sz);\n    for(int i=0;i<=(sz>>1);i++){\n      int j=(sz-i)&(sz-1);\n      num z=(fa[j]*fa[j]-conj(fa[i]*fa[i]))*r;\n      if(i!=j)\n        fa[j]=(fa[i]*fa[i]-conj(fa[j]*fa[j]))*r;\n      fa[i]=z;\n    }\n    fft(fa);\n\n    vector<long long> res(need);\n    for(int i=0;i<need;i++)\n      res[i]=round(fa[i].x);\n\n    return res;\n  }\n\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convolution/garner.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../mod/mint.cpp\"\n#include \"numbertheoretictransform.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nstruct Garner{\n  using ll = long long;\n  inline static NTT<0> ntt0;\n  inline static NTT<1> ntt1;\n  inline static NTT<2> ntt2;\n\n  static constexpr int pow(int a,int b,int md){\n    int res=1;\n    a=a%md;\n    while(b){\n      if(b&1) res=(ll)res*a%md;\n      a=(ll)a*a%md;\n      b>>=1;\n    }\n    return res;\n  }\n\n  static constexpr int inv(int x,int md){\n    return pow(x,md-2,md);\n  }\n\n  inline void garner(int &c0,int c1,int c2,int m01,int MOD){\n    static constexpr int r01=inv(ntt0.md,ntt1.md);\n    static constexpr int r02=inv(ntt0.md,ntt2.md);\n    static constexpr int r12=inv(ntt1.md,ntt2.md);\n\n    c1=(ll)(c1-c0)*r01%ntt1.md;\n    if(c1<0) c1+=ntt1.md;\n\n    c2=(ll)(c2-c0)*r02%ntt2.md;\n    c2=(ll)(c2-c1)*r12%ntt2.md;\n    if(c2<0) c2+=ntt2.md;\n\n    c0%=MOD;\n    c0+=(ll)c1*ntt0.md%MOD;\n    if(c0>=MOD) c0-=MOD;\n    c0+=(ll)c2*m01%MOD;\n    if(c0>=MOD) c0-=MOD;\n  }\n\n  inline void garner(vector< vector<int> > &cs,int MOD){\n    int m01 =(ll)ntt0.md*ntt1.md%MOD;\n    int sz=cs[0].size();\n    for(int i=0;i<sz;i++) garner(cs[0][i],cs[1][i],cs[2][i],m01,MOD);\n  }\n\n  vector<int> multiply(vector<int> as,vector<int> bs,int MOD){\n    vector< vector<int> > cs(3);\n    cs[0]=ntt0.multiply(as,bs);\n    cs[1]=ntt1.multiply(as,bs);\n    cs[2]=ntt2.multiply(as,bs);\n    size_t sz=as.size()+bs.size()-1;\n    for(auto& v:cs) v.resize(sz);\n    garner(cs,MOD);\n    return cs[0];\n  }\n\n  template<typename T>\n  decltype(auto) multiply(vector<T> am,\n                          vector<T> bm){\n    vector<int> as(am.size()),bs(bm.size());\n    for(int i=0;i<(int)as.size();i++) as[i]=am[i].v;\n    for(int i=0;i<(int)bs.size();i++) bs[i]=bm[i].v;\n    vector<int> cs=multiply(as,bs,T::mod);\n    vector<T> cm(cs.size());\n    for(int i=0;i<(int)cm.size();i++) cm[i]=T(cs[i]);\n    return cm;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convolution/naive.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(N M)\ntemplate<typename T>\ndecltype(auto) naive(){\n  using Poly = vector<T>;\n  auto conv=[](Poly as, Poly bs){\n    Poly cs(as.size()+bs.size()-1,0);\n    for(int i=0;i<(int)as.size();i++)\n      for(int j=0;j<(int)bs.size();j++)\n        cs[i+j]+=as[i]*bs[j];\n    return cs;\n  };\n  return +conv;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "convolution/numbertheoretictransform.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../mod/mint.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nconstexpr int bmds(int x){\n  const int v[] = {1012924417, 924844033, 998244353,\n                   897581057, 645922817};\n  return v[x];\n}\nconstexpr int brts(int x){\n  const int v[] = {5, 5, 3, 3, 3};\n  return v[x];\n}\n\ntemplate<int X>\nstruct NTT{\n  inline static constexpr int md = bmds(X);\n  inline static constexpr int rt = brts(X);\n  using M = Mint<int, md>;\n  vector< vector<M> > rts,rrts;\n\n  void ensure_base(int n){\n    if((int)rts.size()>=n) return;\n    rts.resize(n);rrts.resize(n);\n    for(int i=1;i<n;i<<=1){\n      if(!rts[i].empty()) continue;\n      M w=M(rt).pow((md-1)/(i<<1));\n      M rw=w.inv();\n      rts[i].resize(i);rrts[i].resize(i);\n      rts[i][0]=M(1);rrts[i][0]=M(1);\n      for(int k=1;k<i;k++){\n        rts[i][k]=rts[i][k-1]*w;\n        rrts[i][k]=rrts[i][k-1]*rw;\n      }\n    }\n  }\n\n  void ntt(vector<M> &as,bool f){\n    int n=as.size();\n    assert((n&(n-1))==0);\n    ensure_base(n);\n\n    for(int i=0,j=1;j+1<n;j++){\n      for(int k=n>>1;k>(i^=k);k>>=1);\n      if(i>j) swap(as[i],as[j]);\n    }\n\n    for(int i=1;i<n;i<<=1){\n      for(int j=0;j<n;j+=i*2){\n        for(int k=0;k<i;k++){\n          M z=as[i+j+k]*(f?rrts[i][k]:rts[i][k]);\n          as[i+j+k]=as[j+k]-z;\n          as[j+k]+=z;\n        }\n      }\n    }\n\n    if(f){\n      M tmp=M(n).inv();\n      for(int i=0;i<n;i++) as[i]*=tmp;\n    }\n  }\n\n  vector<M> multiply(vector<M> as,vector<M> bs){\n    int need=as.size()+bs.size()-1;\n    int sz=1;\n    while(sz<need) sz<<=1;\n    as.resize(sz,M(0));\n    bs.resize(sz,M(0));\n\n    ntt(as,0);ntt(bs,0);\n    for(int i=0;i<sz;i++) as[i]*=bs[i];\n    ntt(as,1);\n\n    as.resize(need);\n    return as;\n  }\n\n  vector<int> multiply(vector<int> as,vector<int> bs){\n    vector<M> am(as.size()),bm(bs.size());\n    for(int i=0;i<(int)am.size();i++) am[i]=M(as[i]);\n    for(int i=0;i<(int)bm.size();i++) bm[i]=M(bs[i]);\n    vector<M> cm=multiply(am,bm);\n    vector<int> cs(cm.size());\n    for(int i=0;i<(int)cs.size();i++) cs[i]=cm[i].v;\n    return cs;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/BIT2D.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct BIT2D{\n  int n,m;\n  T d;\n  vector< vector<T> > bit;\n  //1-indexed\n  BIT2D():n(-1),m(-1){}\n  BIT2D(int n_,int m_):n(n_),m(m_),bit(n_+1,vector<T>(m+1,0)){}\n  T sum(int i,int j){\n    T s(0);\n    for(int x=i;x>0;x-=(x&-x))\n      for(int y=j;y>0;y-=(y&-y))\n        s+=bit[x][y];\n    return s;\n  }\n  void add(int i,int j,T a){\n    if(i==0 or j==0) return;\n    for(int x=i;x<=n;x+=(x&-x))\n      for(int y=j;y<=m;y+=(y&-y))\n        bit[x][y]+=a;\n  }\n  // (x1,x2] * (y1,y2];\n  T sum(int x1,int y1,int x2,int y2){\n    return sum(x1,y1)-sum(x1,y2)-sum(x2,y1)+sum(x2,y2);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/absolutesum.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct AbsoluteSum{\n  multiset<T> lp,rp;\n  T sum;\n  AbsoluteSum():sum(0){}\n  T insert(T x){\n    if(lp.empty()){\n      lp.emplace(x);\n      rp.emplace(x);\n      return T(0);\n    }\n    auto p=interval();\n    lp.emplace(x);\n    rp.emplace(x);\n    if(p.first<=x and x<=p.second) return T(0);\n    if(*lp.rbegin()>*rp.begin()){\n      T a=*lp.rbegin();\n      T b=*rp.begin();\n      lp.erase(lp.find(a));\n      rp.erase(rp.find(b));\n      rp.emplace(a);\n      lp.emplace(b);\n    }\n    T res=min(abs(p.first-x),abs(p.second-x));\n    sum+=res;\n    return res;\n  }\n\n  T erase(T x){\n    assert(lp.count(x)+rp.count(x)>=2);\n    if(lp.count(x) and rp.count(x)){\n      lp.erase(lp.find(x));\n      rp.erase(rp.find(x));\n      return T(0);\n    }\n    if(lp.count(x)){\n      lp.erase(lp.find(x));\n      lp.erase(lp.find(x));\n      lp.emplace(*rp.begin());\n      rp.erase(rp.begin());\n    }else{\n      rp.erase(rp.find(x));\n      rp.erase(rp.find(x));\n      rp.emplace(*lp.rbegin());\n      lp.erase(--lp.end());\n    }\n    auto p=interval();\n    if(p.first<=x and x<=p.second) return T(0);\n    T res=min(abs(p.first-x),abs(p.second-x));\n    sum-=res;\n    return res;\n  }\n\n  pair<T, T> interval(){\n    assert(!lp.empty());\n    return make_pair(*lp.rbegin(),*rp.begin());\n  }\n\n  T value(){return sum;}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\n\n// test interval()\nsigned ABC127_F(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  int q;\n  cin>>q;\n  using ll = long long;\n  AbsoluteSum<ll> as;\n  ll sum=0;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==1){\n      ll a,b;\n      cin>>a>>b;\n      as.insert(a);\n      sum+=b;\n    }\n    if(t==2){\n      cout<<as.interval().first<<\" \"<<sum+as.value()<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n/*\n  verified on 2019/06/19\n  https://atcoder.jp/contests/abc127/tasks/abc127_f\n*/\n\nsigned main(){\n  //ABC127_F();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/binaryindexedtree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T>\nclass BIT{\nprivate:\n  // \\sum_{j < i}  v[j]\n  T sum(int i){\n    T s(0);\n    for(int x=i;x>0;x-=(x&-x))\n      s+=bit[x];\n    return s;\n  }\npublic:\n  int n;\n  vector<T> bit;\n  BIT(int n_):n(n_+1),bit(n_+2,0){}\n\n  // v[i] += a\n  void add(int i,T a){\n    for(int x=++i;x<=n;x+=(x&-x))\n      bit[x]+=a;\n  }\n\n  // \\sum_{l <= i < r} v[i]\n  T query(int l,int r){return sum(r)-sum(l);}\n\n  // min({x | sum(x) >= w})\n  int lower_bound(const T w){\n    if(w<=0) return 0;\n    T r=w;\n    int x=0,p=1;\n    while(p<n) p<<=1;\n    for(int k=p;k>0;k>>=1){\n      if(x+k<=n and bit[x+k]<r){\n        r-=bit[x+k];\n        x+=k;\n      }\n    }\n    x++;\n    assert(sum(x-1)<w and sum(x)>=w);\n    return x;\n  }\n\n  // min({x | sum(x) > w})\n  int upper_bound(T w){return lower_bound(w+1);}\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/binarytrie.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T,size_t X>\nstruct BinaryTrie{\n  struct Node{\n    size_t cnt;\n    Node *p,*l,*r;\n    Node(Node* p):cnt(0),p(p){l=r=nullptr;}\n  };\n\n  T acc;\n  Node *root;\n  BinaryTrie():acc(0){root=emplace(nullptr);}\n\n  void clear(Node *a){\n    if(!a) return;\n    clear(a->l);clear(a->r);\n    delete(a);\n  }\n\n  inline Node* emplace(Node* p){\n    return new Node(p);\n  }\n\n  inline size_t count(Node* a){\n    return a?a->cnt:0;\n  }\n\n  void add(const T b,size_t k=1){\n    const T nb=b^acc;\n    Node* a=root;\n    for(int i=X-1;i>=0;i--){\n      bool f=(nb>>i)&1;\n      if(!f and !a->l) a->l=emplace(a);\n      if( f and !a->r) a->r=emplace(a);\n      a=f?a->r:a->l;\n    }\n    a->cnt+=k;\n    while((a=a->p)) a->cnt=count(a->l)+count(a->r);\n  }\n\n  inline void update(const T b){acc^=b;}\n\n  Node* find(const T b){\n    const T nb=b^acc;\n    Node* a=root;\n    for(int i=X-1;i>=0;i--){\n      bool f=(nb>>i)&1;\n      a=f?a->r:a->l;\n      if(!a) return a;\n    }\n    return a;\n  }\n\n  Node* check(Node *a){\n    if(!a or count(a)) return a;\n    delete(a);\n    return nullptr;\n  }\n\n  void sub(Node* a,size_t k=1){\n    assert(a and a->cnt>=k);\n    a->cnt-=k;\n    while((a=a->p)){\n      a->l=check(a->l);\n      a->r=check(a->r);\n      a->cnt=count(a->l)+count(a->r);\n    }\n  }\n\n  Node* xmax(const T b){\n    assert(count(root));\n    const T nb=b^acc;\n    Node* a=root;\n    for(int i=X-1;i>=0;i--){\n      bool f=(nb>>i)&1;\n      if(!a->l or !a->r) a=a->l?a->l:a->r;\n      else a=f?a->l:a->r;\n    }\n    return a;\n  }\n\n  Node* xmin(const T b){\n    return xmax(~b&((T(1)<<X)-1));\n  }\n\n  Node* ge(Node *a,int i){\n    if(!a) return a;\n    Node *l=a->l,*r=a->r;\n    if((acc>>i)&1) swap(l,r);\n    if(l or r) return ge(l?l:r,i+1);\n    return a;\n  }\n\n  Node* next(Node* a,int i){\n    if(!(a->p)) return nullptr;\n    Node *l=a->p->l,*r=a->p->r;\n    if((acc>>(i+1))&1) swap(l,r);\n    if(a==l and r) return ge(r,i);\n    return next(a->p,i+1);\n  }\n\n  Node* lower_bound(const T b){\n    const T nb=b^acc;\n    Node* a=root;\n    for(int i=X-1;i>=0;i--){\n      bool f=(nb>>i)&1;\n      if(!f and a->l){a=a->l;continue;}\n      if( f and a->r){a=a->r;continue;}\n      if((b>>i)&1) return next(a,i);\n      return ge(a,i);\n    }\n    return a;\n  }\n\n  Node* upper_bound(const T b){\n    return lower_bound(b+1);\n  }\n\n  T val(Node* a){\n    T res(0);\n    for(int i=0;i<(int)X;i++){\n      assert(a->p);\n      res|=(T(a==a->p->r)<<i);\n      a=a->p;\n    }\n    return res^acc;\n  }\n\n  Node* find_by_order(size_t k){\n    Node *a=root;\n    if(count(a)<=k) return nullptr;\n    for(int i=X-1;i>=0;i--){\n      bool f=(acc>>i)&1;\n      if(count(f?a->r:a->l)<=k){\n        k-=count(f?a->r:a->l);\n        a=f?a->l:a->r;\n      }else{\n        a=f?a->r:a->l;\n      }\n    }\n    return a;\n  }\n\n  size_t order_of_key(const T b){\n    Node *a=root;\n    size_t res=0;\n    for(int i=X-1;i>=0;i--){\n      Node *l=a->l,*r=a->r;\n      if((acc>>i)&1) swap(l,r);\n      bool f=(b>>i)&1;\n      if(f) res+=count(l);\n      a=f?r:l;\n      if(!a) break;\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n// find_by_order (weak)\nsigned ARC033_C(){\n  int q;\n  scanf(\"%d\",&q);\n  BinaryTrie<int, 30> bt;\n  while(q--){\n    int t,x;\n    scanf(\"%d %d\",&t,&x);\n    if(t==1) bt.add(x);\n    if(t==2){\n      auto k=bt.find_by_order(x-1);\n      printf(\"%d\\n\",bt.val(k));\n      bt.sub(k);\n    }\n  }\n  return 0;\n}\n/*\n  verified on 2020/06/06\n  https://atcoder.jp/contests/arc033/tasks/arc033_3\n*/\n\n// upper_bound\nsigned CFR477_C(){\n  using ll = long long;\n\n  int n;\n  scanf(\"%d\",&n);\n  vector<ll> bs(n);\n  for(int i=0;i<n;i++) scanf(\"%lld\",&bs[i]);\n\n  BinaryTrie<ll, 61> bt;\n  for(int i=0;i<n;i++) bt.add(bs[i]);\n\n  ll z=0;\n  auto apply=[&](ll a){\n    z^=a;\n    bt.update(a);\n  };\n\n  vector<ll> ans;\n  ll x=bt.val(bt.xmin(0));\n\n  ans.emplace_back(x);\n  bt.sub(bt.find(x));\n  apply(x);\n\n  for(int i=1;i<n;i++){\n    if(bt.val(bt.xmax(0))<=x){\n      printf(\"No\\n\");\n      return 0;\n    }\n    auto nxt=bt.upper_bound(x);\n    ll y=bt.val(nxt);\n\n    ans.emplace_back(y^z);\n    bt.sub(nxt);\n    apply(x^y);\n    x=y;\n  }\n\n  printf(\"Yes\\n\");\n  for(int i=0;i<n;i++){\n    if(i) printf(\" \");\n    printf(\"%lld\",ans[i]);\n  }\n  puts(\"\");\n  return 0;\n}\n/*\n  verified on 2020/06/06\n  http://codeforces.com/contest/966/problem/C\n*/\n\nsigned main(){\n  //ARC033_C();\n  //CFR477_C();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/bitvector.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\n// half open interval [l, r)\ntemplate<typename T=unsigned long long>\nstruct BitVector{\n  inline static constexpr size_t B = sizeof(T) * CHAR_BIT;\n  size_t n;\n  vector<T> dat;\n  BitVector(size_t n_):n(n_),dat(n_/B+1,0){}\n\n  inline T get(size_t i)const{return (dat[i/B]>>(i%B))&T(1);}\n\n  void set(size_t i,T v){\n    dat[i/B]&=~(T(1)<<(i%B));\n    dat[i/B]|=v<<(i%B);\n  }\n\n  // O(B + (r - l) / B)\n  BitVector get(size_t l,size_t r)const{\n    BitVector res(r-l);\n    if(r-l<=B){\n      for(size_t i=l;i<r;i++) res.set(i-l,get(i));\n      return res;\n    }\n    size_t p=(l+B-1)/B*B,q=r/B*B;\n    // [l, p)\n    for(size_t i=l;i<p;i++) res.set(i-l,get(i));\n    // [p, q)\n    for(size_t i=p;i<q;i+=B){\n      if(l%B==0) res.dat[(i-l)/B]=dat[i/B];\n      else{\n        res.dat[(i-l)/B+0]|=dat[i/B]<<(p-l);\n        res.dat[(i-l)/B+1]|=dat[i/B]>>(B-(p-l));\n      }\n    }\n    // [q, r)\n    for(size_t i=q;i<r;i++) res.set(i-l,get(i));\n    return res;\n  }\n\n  void set(size_t l,size_t r,const BitVector& bv){\n    if(r-l<=B){\n      for(size_t i=l;i<r;i++) set(i,bv.get(i-l));\n      return;\n    }\n    size_t p=(l+B-1)/B*B,q=r/B*B;\n    // [l, p)\n    for(size_t i=l;i<p;i++) set(i,bv.get(i-l));\n    // [p, q)\n    for(size_t i=p;i<q;i+=B){\n      if(l%B==0) dat[i/B]=bv.dat[(i-l)/B];\n      else dat[i/B]=(bv.dat[(i-l)/B+0]>>(p-l))|(bv.dat[(i-l)/B+1]<<(B-(p-l)));\n    }\n    // [q, r)\n    for(size_t i=q;i<r;i++) set(i,bv.get(i-l));\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/cartesiantree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T>\nvector<int> cartesian_tree(const vector<T> &vs){\n  int n=vs.size();\n  vector<int> ps(n,-1),ls(n,-1),rs(n,-1);\n  int cur=0;\n  for(int i=1;i<n;i++){\n    if(vs[cur]<=vs[i]){\n      rs[cur]=i;\n      ps[i]=cur;\n      cur=i;\n      continue;\n    }\n    while(~ps[cur] and vs[i]<vs[ps[cur]]) cur=ps[cur];\n    ps[i]=ps[cur];\n    if(~ps[i]) rs[ps[i]]=i;\n    ls[i]=cur;\n    ps[cur]=i;\n    cur=i;\n  }\n  return ps;\n}\n//END CUT HERE\n\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/cumulativesum.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct CumulativeSum{\n  vector<T> sm;\n  CumulativeSum(const vector<T> &as){\n    int n=as.size();\n    sm.resize(n+1);\n    sm[0]=T();\n    for(int i=0;i<n;i++)\n      sm[i+1]=sm[i]+as[i];\n  }\n  // [l, r)\n  T query(int l,int r){return -sm[l]+sm[r];}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/disjointsparsetable.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct DisjointSparseTable{\n  using F = function<T(T, T)>;\n  vector< vector<T> > dat;\n  vector<int> ht;\n  const F f;\n\n  DisjointSparseTable(F f):f(f){}\n\n  void build(const vector<T> &vs){\n    int n=vs.size(),h=1;\n    while((1<<h)<=n) h++;\n    dat.assign(h,vector<T>(n));\n    ht.assign((1<<h)+1,0);\n    for(int j=2;j<(1<<h)+1;j++) ht[j]=ht[j>>1]+1;\n\n    for(int j=0;j<n;j++) dat[0][j]=vs[j];\n    for(int i=1;i<h;i++){\n      int s=1<<i;\n      for(int j=0;j<n;j+=s<<1){\n        int t=min(j+s,n);\n        dat[i][t-1]=vs[t-1];\n        for(int k=t-2;k>=j;k--) dat[i][k]=f(vs[k],dat[i][k+1]);\n        if(n<=t) break;\n        dat[i][t]=vs[t];\n        int r=min(t+s,n);\n        for(int k=t+1;k<r;k++) dat[i][k]=f(dat[i][k-1],vs[k]);\n      }\n    }\n  }\n\n  T query(int l,int r){\n    if(l>=--r) return dat[0][l];\n    return f(dat[ht[l^r]][l],dat[ht[l^r]][r]);\n  }\n\n};\n//END CUT HERE\n#ifndef call_from_test\n\n// find with non-idempotent monoid\nsigned CODECHEF_SEGPROD(){\n  int T;\n  scanf(\"%d\",&T);\n\n  int p;\n  auto f=[&](int a,int b)->int{return (long long)a*b%p;};\n  DisjointSparseTable<int> dst(f);\n\n  for(int t=1;t<=T;t++){\n    int n,q;\n    scanf(\"%d %d %d\",&n,&p,&q);\n    vector<int> v(n);\n    for(int i=0;i<n;i++) scanf(\"%d\",&v[i]),v[i]%=p;\n    vector<int> b(q/64+2);\n    for(int i=0;i<(q/64+2);i++) scanf(\"%d\",&b[i]);\n\n    dst.build(v);\n\n    int x=0,l=0,r=0;\n    for(int i=0;i<q;i++){\n      if(i%64==0){\n        l=(b[i/64]+x)%n;\n        r=(b[i/64+1]+x)%n;\n      }else{\n        l=(l+x)%n;\n        r=(r+x)%n;\n      }\n      if(l>r) swap(l,r);\n      x=dst.query(l,r+1)+1;\n      if(x>=p) x-=p;\n    }\n    printf(\"%d\\n\",x);\n  }\n  return 0;\n}\n/*\n  verified on 2019/10/29\n  https://www.codechef.com/problems/SEGPROD\n*/\n\n//INSERT ABOVE HERE\nsigned main(){\n  //CODECHEF_SEGPROD();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/kdtree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct KDTree{\n  static const int NIL = -1;\n\n  class Node{\n  public:\n    int pos,p,l,r;\n    Node(){pos=p=l=r=NIL;}\n  };\n\n  class Point{\n  public:\n    int id;\n    T x,y;\n    Point(int id,T x,T y): id(id),x(x),y(y){}\n    bool operator<(const Point &p)const{\n      return id<p.id;\n    }\n  };\n\n  vector<Point> ps;\n  vector<Node> ts;\n  int np;\n\n  void add_point(int i,int x,int y){\n    ps.emplace_back(i,x,y);\n    ts.emplace_back();\n  }\n\n  static bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}\n  static bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}\n\n  int dfs(int l,int r,int depth){\n    if(l>=r) return NIL;\n    int mid=(l+r)/2;\n    int t=np++;\n    if(depth%2==0){\n      sort(ps.begin()+l,ps.begin()+r,lessX);\n    }else{\n      sort(ps.begin()+l,ps.begin()+r,lessY);\n    }\n    ts[t].pos=mid;\n    ts[t].l=dfs(l,mid,depth+1);\n    ts[t].r=dfs(mid+1,r,depth+1);\n    return t;\n  }\n\n  int build(){\n    np=0;\n    return dfs(0,ps.size(),0);\n  }\n\n  // [sx, tx] * [sy, ty]\n  void find(int v,T sx,T tx,T sy,T ty,int depth,vector<Point> &ans){\n    T x=ps[ts[v].pos].x;\n    T y=ps[ts[v].pos].y;\n    if(sx<=x and x<=tx and sy<=y and y<=ty)\n      ans.emplace_back(ps[ts[v].pos]);\n\n    if(depth%2==0){\n      if(ts[v].l!=NIL){\n        if(sx<=x) find(ts[v].l,sx,tx,sy,ty,depth+1,ans);\n      }\n      if(ts[v].r!=NIL){\n        if(x<=tx) find(ts[v].r,sx,tx,sy,ty,depth+1,ans);\n      }\n    }else{\n      if(ts[v].l!=NIL){\n        if(sy<=y) find(ts[v].l,sx,tx,sy,ty,depth+1,ans);\n      }\n      if(ts[v].r!=NIL){\n        if(y<=ty) find(ts[v].r,sx,tx,sy,ty,depth+1,ans);\n      }\n    }\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/pb_ds_cc_hash_table.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\ntemplate<typename T,typename U, typename H=hash<T> >\nusing gmap = cc_hash_table<T, U, H>;\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/prioritysum.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n//BEGIN CUT HERE\n// return sum of top K element (default: maximum)\ntemplate<typename T, T identity, typename V=vector<T>,\n         typename C1=less<T>, typename C2=greater<T> >\nstruct PrioritySum{\n  size_t num;\n  T sum;\n  priority_queue<T, V, C1> pq1;\n  priority_queue<T, V, C2> pq2;\n  PrioritySum():num(0),sum(identity){}\n  PrioritySum(size_t num):num(num),sum(identity){}\n\n  void resolve(){\n    assert(size()>=num);\n    while(pq2.size()<num){\n      sum+=pq1.top();\n      pq2.emplace(pq1.top());\n      pq1.pop();\n    }\n    while(pq2.size()>num){\n      sum-=pq2.top();\n      pq1.emplace(pq2.top());\n      pq2.pop();\n    }\n    if(pq1.empty() or pq2.empty()) return;\n    while(C2()(pq1.top(),pq2.top())){\n      T t1=pq1.top();pq1.pop();\n      T t2=pq2.top();pq2.pop();\n      sum+=t1;\n      sum-=t2;\n      pq1.emplace(t2);\n      pq2.emplace(t1);\n    }\n  }\n\n  T query(){resolve();return sum;}\n\n  void push(const T &x){pq1.emplace(x);}\n  void expand(){num++;}\n  void shrink(){assert(num);num--;}\n\n  size_t size()const{return pq1.size()+pq2.size();}\n};\ntemplate<typename T>\nusing MaximumSum=PrioritySum<T, T(0), vector<T>, less<T>, greater<T> >;\ntemplate<typename T>\nusing MinimumSum=PrioritySum<T, T(0), vector<T>, greater<T>, less<T> >;\n\n//END CUT HERE\n\nstruct FastIO{\n  FastIO(){\n    cin.tie(0);\n    ios::sync_with_stdio(0);\n  }\n}fastio_beet;\n\ntemplate<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}\ntemplate<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}\n\n//INSERT ABOVE HERE\nsigned ARC074_D(){\n  using ll = long long;\n\n  int n;\n  cin>>n;\n  vector<ll> a(3*n);\n  for(int i=0;i<3*n;i++) cin>>a[i];\n\n  MaximumSum<ll> ps1(n);\n  vector<ll> dp1(3*n);\n  for(int i=0;i<3*n;i++){\n    if(i>=n) dp1[i]=ps1.query();\n    ps1.push(a[i]);\n  }\n\n  MinimumSum<ll> ps2(n);\n  vector<ll> dp2(3*n);\n  for(int i=3*n-1;i>=0;i--){\n    ps2.push(a[i]);\n    if(i<=2*n) dp2[i]=ps2.query();\n  }\n\n  ll ans=dp1[n]-dp2[n];\n  for(int i=n;i<=2*n;i++) chmax(ans,dp1[i]-dp2[i]);\n\n  cout<<ans<<endl;\n  return 0;\n}\n/*\n  verified on 2019/04/09\n  https://atcoder.jp/contests/arc074/tasks/arc074_b\n*/\n\nsigned CGR002_F(){\n  using ll = long long;\n  using P = pair<ll, ll>;\n  int n;\n  cin>>n;\n  vector<vector<P> > G(n);\n  for(int i=1;i<n;i++){\n    ll a,b,c;\n    cin>>a>>b>>c;\n    a--;b--;\n    G[a].emplace_back(b,c);\n    G[b].emplace_back(a,c);\n  }\n\n  auto cmp=[&](P a,P b){\n             return G[a.first].size()>G[b.first].size();\n           };\n  for(auto &v:G)\n    sort(v.begin(),v.end(),cmp);\n\n  vector<vector<int> > alive(n),death(n);\n  for(int i=0;i<n;i++){\n    for(int j=0;j<=(int)G[i].size();j++)\n      alive[j].emplace_back(i);\n    death[G[i].size()].emplace_back(i);\n  }\n\n  vector<MinimumSum<ll> > ms(n);\n\n  vector<int> par(n,-1),cst(n,0),children(n,0);\n  auto dfs=\n    [&](int v,int p,auto func)->void{\n      for(auto e:G[v]){\n        ll u=e.first,c=e.second;\n        if(u==p) continue;\n        par[u]=v;\n        cst[u]=c;\n        children[v]++;\n        func(u,v,func);\n      }\n    };\n  dfs(0,-1,dfs);\n\n  const ll INF = 1e18;\n\n  vector<int> used(n,0),dead(n,0);\n  auto dfs2=\n    [&](int v,int p,int t,auto func)->P{\n      used[v]=1;\n      vector<ll> res;\n      ll sum=0;\n      for(auto e:G[v]){\n        ll u=e.first,c=e.second;\n        if(u==p) continue;\n        if(dead[u]) break;\n        P tmp=func(u,v,t,func);\n        sum+=tmp.second;\n        res.emplace_back((tmp.first+c)-tmp.second);\n      }\n      sort(res.begin(),res.end());\n\n      ll x=INF,y=INF,z=0;\n      int num=children[v]-t;\n      assert(num>=-1);\n      for(int i=0;i<=(int)res.size();i++){\n        int j=max(num-i,0);\n        if(j<=(int)ms[v].size()){\n          while((int)ms[v].num<j) ms[v].expand();\n          while((int)ms[v].num>j) ms[v].shrink();\n          chmin(x,sum+z+ms[v].query());\n        }\n        int k=max(num-i+1,0);\n        if(k<=(int)ms[v].size()){\n          while((int)ms[v].num<k) ms[v].expand();\n          while((int)ms[v].num>k) ms[v].shrink();\n          chmin(y,sum+z+ms[v].query());\n        }\n        if(i<(int)res.size()) z+=res[i];\n      }\n      return P(x,y);\n    };\n\n  for(int t=0;t<n;t++){\n    if(t) cout<<\" \";\n    ll res=0;\n    for(int v:alive[t]){\n      if(used[v]) continue;\n      int u=v;\n      while(~par[u] and !dead[par[u]]) u=par[u];\n      P tmp=dfs2(u,par[u],t,dfs2);\n      res+=min(tmp.first+cst[u],tmp.second);\n    }\n\n    cout<<res;\n    for(int v:alive[t]) used[v]=0;\n    for(int v:death[t]){\n      dead[v]=1;\n      for(auto e:G[v])\n        if(e.first==par[v])\n          ms[e.first].push(e.second);\n    }\n  }\n  cout<<endl;\n  return 0;\n}\n/*\n  verified on 2019/04/10\n  https://codeforces.com/contest/1119/problem/F\n*/\n\nsigned main(){\n  //ARC074_D();\n  //CGR002_F();\n  return 0;\n}\n"
  },
  {
    "path": "datastructure/quickfind.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct QuickFind{\n  vector<int> rs,ps;\n  vector< vector<int> > vs;\n  QuickFind(int n):rs(n,1),ps(n),vs(n){\n    iota(ps.begin(),ps.end(),0);\n    for(int i=0;i<n;i++) vs[i].assign(1,i);\n  }\n  int find(int x) const{return ps[x];}\n  bool same(int x,int y) const{\n    return find(x)==find(y);\n  }\n  void unite(int x,int y){\n    x=ps[x];y=ps[y];\n    if(x==y) return;\n    if(rs[x]<rs[y]) swap(x,y);\n    rs[x]+=rs[y];\n    for(int e:vs[y]){\n      ps[e]=x;\n      vs[x].emplace_back(e);\n    }\n    vs[y].clear();\n    vs[y].shrink_to_fit();\n  }\n  const vector<int>& elements(int x) const{return vs[x];}\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/radixheap.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// prohibited to push an element less than popped one\n// Key: int or long long\ntemplate<typename K,typename V>\nstruct RadixHeap{\n  inline static constexpr int bit = sizeof(K) * 8;\n  array<vector< pair<K, V> >, bit> vs;\n\n  int size;\n  K last;\n  RadixHeap():size(0),last(0){}\n\n  bool empty() const{return size==0;}\n\n  inline int getbit(int a){\n    return a?bit-__builtin_clz(a):0;\n  }\n\n  inline int getbit(long long a){\n    return a?bit-__builtin_clzll(a):0;\n  }\n\n  void emplace(K key,V val){\n    size++;\n    vs[getbit(key^last)].emplace_back(key,val);\n  }\n\n  pair<K, V> pop(){\n    if(vs[0].empty()){\n      int idx=1;\n      while(vs[idx].empty()) idx++;\n      last=min_element(vs[idx].begin(),vs[idx].end())->first;\n      for(auto &p:vs[idx]) vs[getbit(p.first^last)].emplace_back(p);\n      vs[idx].clear();\n    }\n    --size;\n    auto res=vs[0].back();\n    vs[0].pop_back();\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/rangeslide.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T, typename F>\nstruct RangeSlide{\n  vector<size_t> ls,rs;\n  vector<T> vs;\n  F cmp;\n  RangeSlide(vector<T> vs,F cmp):vs(vs),cmp(cmp){}\n\n  void add_range(size_t l,size_t r){\n    ls.emplace_back(l);\n    rs.emplace_back(r);\n  }\n\n  vector<size_t> build(){\n    deque<size_t> deq;\n    vector<size_t> res;\n    for(size_t i=0,l=0,r=0;i<ls.size();i++){\n      if(r<=ls[i]){\n        deq.clear();\n        l=r=ls[i];\n      }\n      while(r<rs[i]){\n        while(!deq.empty() and\n              !cmp(vs[deq.back()],vs[r])) deq.pop_back();\n        deq.emplace_back(r++);\n      }\n      while(l<ls[i]){\n        if(deq.front()==l++) deq.pop_front();\n      }\n      res.emplace_back(deq.front());\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/rotcev.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// no resize() because it is dangerous\ntemplate<typename T>\nstruct Rotcev{\n  vector<T> data;\n\n  size_t size()const{return data.size();};\n  bool empty()const{return data.empty();}\n\n  T& operator[](size_t n){return data[size()-1-n];}\n  const T& operator[](size_t n)const{return data[size()-1-n];}\n\n  void push_front(T val){data.push_back(val);}\n  void pop_front(){data.pop_back();};\n  void clear(){data.clear();}\n\n  template<typename... Args>\n  Rotcev(Args ...args):data(forward<Args>(args)...){}\n  template<typename... Args>\n  void emplace_front(Args ...args){data.emplace_back(forward<Args>(args)...);}\n  template<typename... Args>\n  void assign(Args ...args){data.assign(forward<Args>(args)...);}\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/skewheap.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T, typename E>\nstruct SkewHeap{\n  using G = function<T(T,E)>;\n  using H = function<E(E,E)>;\n  using C = function<bool(T,T)>;\n  G g;\n  H h;\n  C c;\n  T INF;\n  E ei;\n  SkewHeap(G g,H h,C c,T INF,E ei):g(g),h(h),c(c),INF(INF),ei(ei){}\n\n  struct Node{\n    Node *l,*r;\n    T val;\n    E add;\n    Node(T val,E add):val(val),add(add){l=r=nullptr;}\n  };\n\n  void eval(Node *a){\n    if(a==nullptr) return;\n    if(a->add==ei) return;\n    if(a->l) a->l->add=h(a->l->add,a->add);\n    if(a->r) a->r->add=h(a->r->add,a->add);\n    a->val=g(a->val,a->add);\n    a->add=ei;\n  }\n\n  T top(Node *a){\n    return a!=nullptr?g(a->val,a->add):INF;\n  }\n\n  T snd(Node *a){\n    eval(a);\n    return a!=nullptr?min(top(a->l),top(a->r)):INF;\n  }\n\n  Node* add(Node *a,E d){\n    if(a!=nullptr) a->add=h(a->add,d);\n    return a;\n  }\n\n  Node* push(T v){\n    return new Node(v,ei);\n  }\n\n  Node* meld(Node *a,Node *b){\n    if(!a or !b) return a?a:b;\n    if(c(top(a),top(b))) swap(a,b);\n    eval(a);\n    a->r=meld(a->r,b);\n    swap(a->l,a->r);\n    return a;\n  }\n\n  Node* pop(Node* a){\n    eval(a);\n    auto res=meld(a->l,a->r);\n    delete a;\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"unionfind.cpp\"\n#undef call_from_test\n\nsigned APC001_D(){\n  using ll = long long;\n  using Heap = SkewHeap<ll, ll>;\n  ll n,m;\n  cin>>n>>m;\n  vector<ll> a(n);\n  for(ll i=0;i<n;i++) cin>>a[i];\n\n  auto g=[](ll a,ll b){return a+b;};\n  auto h=[](ll a,ll b){return a+b;};\n  auto c=[](ll a,ll b){return a>b;};\n\n  const ll INF = 1e16;\n  Heap heap(g,h,c,INF,0);\n  vector<Heap::Node*> v(n);\n  for(ll i=0;i<n;i++) v[i]=heap.push(a[i]);\n\n  UnionFind uf(n);\n  for(ll i=0;i<m;i++){\n    ll x,y;\n    cin>>x>>y;\n    x=uf.find(x);y=uf.find(y);\n    uf.unite(x,y);\n    if(uf.find(x)!=x) swap(x,y);\n    v[x]=heap.meld(v[x],v[y]);\n    v[y]=NULL;\n  }\n\n  if(m==n-1){\n    cout<<0<<endl;\n    return 0;\n  }\n\n  Heap::Node* base=NULL;\n\n  ll ans=0,cnt=0;\n  for(ll i=0;i<n;i++){\n    if(uf.find(i)==i){\n      ans+=heap.top(v[i]);\n      v[i]=heap.pop(v[i]);\n      base=heap.meld(base,v[i]);\n      cnt++;\n    }\n  }\n\n  while(m*2+cnt<(n-1)*2){\n    if(base==NULL){\n      cout<<\"Impossible\"<<endl;\n      return 0;\n    }\n    ans+=heap.top(base);\n    base=heap.pop(base);\n    cnt++;\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n/*\n  verified on 2019/12/17\n  https://atcoder.jp/contests/apc001/tasks/apc001_d\n*/\n\nsigned main(){\n  APC001_D();\n}\n#endif\n"
  },
  {
    "path": "datastructure/slidingwindowaggregation.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T,typename S>\nstruct SWAG{\n  using F1 = function<S(S,T)>;\n  using F2 = function<S(T,S)>;\n  const F1 f1;\n  const F2 f2;\n  S id;\n  vector<T> lt,rt;\n  vector<S> ls,rs;\n  SWAG(F1 f1,F2 f2,S id):f1(f1),f2(f2),id(id),ls(1,id),rs(1,id){}\n\n  // S, T identical / commutative is not required\n  SWAG(F1 f1,S id):f1(f1),f2([&](T y,S x){return f1(y,x);}),\n                   id(id),ls(1,id),rs(1,id){}\n\n  void push(T x){\n    rt.emplace_back(x);\n    rs.emplace_back(f1(rs.back(),x));\n  }\n\n  void pop(){\n    if(lt.empty()){\n      reverse(rt.begin(),rt.end());\n      for(auto x:rt){\n        lt.emplace_back(x);\n        ls.emplace_back(f2(x,ls.back()));\n      }\n      rt.resize(0);\n      rs.resize(1);\n    }\n    lt.pop_back();\n    ls.pop_back();\n  }\n\n  template<typename Q>\n  void fold(Q q){q(ls.back(),rs.back());}\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"../tools/fastio.cpp\"\n#include \"../tools/chminmax.cpp\"\n#undef call_from_test\n\n//INSERT ABOVE HERE\n\nclass Crypto {\npublic:\n  Crypto() {\n    sm = cnt = 0;\n    seed();\n  }\n\n  int decode(int z) {\n    z ^= next();\n    z ^= (next() << 8);\n    z ^= (next() << 16);\n    z ^= (next() << 22);\n    return z;\n  }\n\n  void query(long long z) {\n    const long long B = 425481007;\n    const long long MD = 1000000007;\n    cnt++;\n    sm = ((sm * B % MD + z) % MD + MD) % MD;\n    seed();\n  }\nprivate:\n  long long sm;\n  int cnt;\n\n  uint8_t data[256];\n  int I, J;\n\n  void swap_data(int i, int j) {\n    uint8_t tmp = data[i];\n    data[i] = data[j];\n    data[j] = tmp;\n  }\n\n  void seed() {\n    uint8_t key[8];\n    for (int i = 0; i < 4; i++) {\n      key[i] = (sm >> (i * 8));\n    }\n    for (int i = 0; i < 4; i++) {\n      key[i+4] = (cnt >> (i * 8));\n    }\n\n    for (int i = 0; i < 256; i++) {\n      data[i] = i;\n    }\n    I = J = 0;\n\n    int j = 0;\n    for (int i = 0; i < 256; i++) {\n      j = (j + data[i] + key[i%8]) % 256;\n      swap_data(i, j);\n    }\n  }\n\n  uint8_t next() {\n    I = (I+1) % 256;\n    J = (J + data[I]) % 256;\n    swap_data(I, J);\n    return data[(data[I] + data[J]) % 256];\n  }\n};\n\nsigned JAG2018_DAY2_D(){\n  int MOD;\n  cin>>MOD;\n  int q;\n  cin>>q;\n  Crypto c;\n\n  using ll = long long;\n  const ll INF = 1e18;\n  using T = pair<ll, ll>;\n  using S = array<ll, 512>;\n  auto f1=\n    [&](S x,T y){\n      S z(x);\n      for(int i=0;i<MOD;i++){\n        int j=(i+y.first)%MOD;\n        chmax(z[j],x[i]+y.second);\n      }\n      return z;\n    };\n  auto f2=\n    [&](T y,S x){\n      return f1(x,y);\n    };\n\n  S id;\n  fill(id.begin(),id.end(),-INF);\n  id[0]=0;\n\n  SWAG<T, S> swag(f1,f2,id);\n\n  for(int i=0;i<q;i++){\n    int t,w,v,l,r;\n    cin>>t>>w>>v>>l>>r;\n    t = c.decode(t);\n    w = c.decode(w);\n    v = c.decode(v);\n    l = c.decode(l);\n    r = c.decode(r);\n    if(t == 1) swag.push(T(w,v));\n    else swag.pop();\n\n    r++;\n    auto ask=\n      [&](S x,S y){\n        SWAG<ll, ll> rmq([](ll a,ll b){return max(a,b);},-INF);\n        for(int i=0;i<r;i++) rmq.push(x[i]);\n        for(int i=0;i<l;i++) rmq.pop();\n\n        ll ans=-1;\n        for(int i=MOD;i>0;i--){\n          rmq.fold([&](ll a,ll b){chmax(ans,max(a,b)+y[i%MOD]);});\n          rmq.push(x[(r+(MOD-i))%MOD]);\n          rmq.pop();\n        }\n        c.query(ans);\n        cout<<ans<<\"\\n\";\n      };\n    swag.fold(ask);\n  }\n  return 0;\n}\n/*\n  verified on 2019/12/28\n  https://atcoder.jp/contests/jag2018summer-day2/tasks/jag2018summer_day2_d\n*/\n\nsigned main(){\n  JAG2018_DAY2_D();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/slope.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// https://maspypy.com/slope-trick-1-%e8%a7%a3%e8%aa%ac%e7%b7%a8\ntemplate<typename T>\nstruct Slope{\n\n  template<template<typename> typename Comp_>\n  struct PQ{\n    template<typename X> using Comp = Comp_<X>;\n    inline static constexpr Comp<T> comp{};\n    using P = pair<T, T>;\n    priority_queue<P, vector<P>, Comp<P>> pq;\n    bool empty()const{return pq.empty();}\n\n    T offset;\n    PQ():offset(0){}\n    bool compare(T a){return comp(a,pq.top().first+offset);}\n\n    // f_{new}(x) =  f_{old}(x - diff)\n    void shift(T diff){offset+=diff;}\n\n    void push(T pos,T num){\n      if(num!=T(0)) pq.emplace(pos-offset,num);\n    }\n\n    P pop(){\n      auto[pos,num]=pq.top();pq.pop();\n      return P(pos+offset,num);\n    }\n  };\n\n  PQ<less> L;\n  PQ<greater> R;\n  T entire;\n  Slope():entire(0){}\n\n  inline T relu(T x){return max<T>(0,x);}\n\n  template<typename From,typename To>\n  void fix(T a,T cnt,From &from,To &to){\n    T use(0);\n    while(use<cnt and not from.empty() and from.compare(a)){\n      auto[pos,num]=from.pop();\n      T tmp=min(cnt-use,num);\n      to.push(pos,tmp);\n      from.push(pos,relu(num-tmp));\n      from.push(a,tmp);\n      entire+=max(a-pos,pos-a)*tmp;\n      use+=tmp;\n    }\n    to.push(a,cnt-use);\n  }\n\n  // _/\n  void add_x_minus_a(T a,T cnt=T(1)){\n    fix(a,cnt,L,R);\n  }\n\n  // \\_\n  void add_a_minus_x(T a,T cnt=T(1)){\n    fix(a,cnt,R,L);\n  }\n\n  // f_{new}(x) =  \\min_{x-b<=y<=x-a} f_{old}(y)\n  void shift(T a,T b){\n    assert(a<=b);\n    L.shift(a);\n    R.shift(b);\n  }\n\n  // f_{new}(x) = f_{old}(x - a)\n  void shift(T a){shift(a,a);}\n\n  // f_{new}(x) = min_{y<=x} f_{old}(y)\n  void apply_cumulative_min(){\n    while(!R.empty()) R.pop();\n  }\n\n  T get_min(){return entire;}\n\n  T get_val(T x){\n    T res=entire;\n    auto vectorize=[](auto pq){\n      vector<pair<T, T>> vp;\n      vp.reserve(pq.pq.size());\n      while(!pq.empty()) vp.emplace_back(pq.pop());\n      return vp;\n    };\n    for(auto[pos,num]:vectorize(L)) res+=relu(pos-x)*num;\n    for(auto[pos,num]:vectorize(R)) res+=relu(x-pos)*num;\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\n\n// test shift(a, b)\nsigned ABC217_H(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  Slope<ll> S;\n  S.add_a_minus_x(0,1e9);\n  S.add_x_minus_a(0,1e9);\n\n  ll n;\n  cin>>n;\n  ll l=0;\n  for(ll i=0;i<n;i++){\n    ll t,d,x;\n    cin>>t>>d>>x;\n    S.shift(l-t,t-l);\n    l=t;\n    if(d==0) S.add_a_minus_x(x);\n    if(d==1) S.add_x_minus_a(x);\n  }\n\n  cout<<S.get_min()<<endl;\n  return 0;\n}\n\nsigned main(){\n  ABC217_H();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/sparsetable.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct SparseTable{\n  using F = function<T(T, T)>;\n  vector< vector<T> > dat;\n  vector<int> ht;\n  const F f;\n\n  SparseTable(F f):f(f){}\n\n  void build(const vector<T> &v){\n    int n=v.size(),h=1;\n    while((1<<h)<=n) h++;\n    dat.assign(h,vector<T>(n));\n    ht.assign(n+1,0);\n    for(int j=2;j<=n;j++) ht[j]=ht[j>>1]+1;\n\n    for(int j=0;j<n;j++) dat[0][j]=v[j];\n    for(int i=1,p=1;i<h;i++,p<<=1)\n      for(int j=0;j<n;j++)\n        dat[i][j]=f(dat[i-1][j],dat[i-1][min(j+p,n-1)]);\n  };\n\n  T query(int a,int b){\n    int l=b-a;\n    return f(dat[ht[l]][a],dat[ht[l]][b-(1<<ht[l])]);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/unionfind.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct UnionFind{\n  int num;\n  vector<int> rs,ps;\n  UnionFind(int n):num(n),rs(n,1),ps(n,0){\n    iota(ps.begin(),ps.end(),0);\n  }\n  int find(int x){\n    return (x==ps[x]?x:ps[x]=find(ps[x]));\n  }\n  bool same(int x,int y){\n    return find(x)==find(y);\n  }\n  void unite(int x,int y){\n    x=find(x);y=find(y);\n    if(x==y) return;\n    if(rs[x]<rs[y]) swap(x,y);\n    rs[x]+=rs[y];\n    ps[y]=x;\n    num--;\n  }\n  int size(int x){\n    return rs[find(x)];\n  }\n  int count() const{\n    return num;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/waveletmatrix.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\nstruct FullyIndexableDictionary{\n  int len,blk;\n  vector<unsigned> bit;\n  vector<int> sum;\n\n  FullyIndexableDictionary(){}\n  FullyIndexableDictionary(int len)\n    :len(len),blk((len+31)>>5),bit(blk,0),sum(blk,0){}\n\n  void set(int k){\n    bit[k>>5]|=1u<<(k&31);\n  }\n\n  void build(){\n    sum[0]=0;\n    for(int i=1;i<blk;i++)\n      sum[i]=sum[i-1]+__builtin_popcount(bit[i-1]);\n  }\n\n  bool operator[](int k) const{\n    return bool((bit[k>>5]>>(k&31))&1);\n  }\n\n  int rank(int k){\n    return sum[k>>5]+__builtin_popcount(bit[k>>5]&((1u<<(k&31))-1));\n  }\n\n  int rank(bool v,int k){\n    return (v?rank(k):k-rank(k));\n  }\n\n  int select(bool v,int k){\n    if(k<0 or rank(v,len)<=k) return -1;\n    int l=0,r=len;\n    while(l+1<r){\n      int m=(l+r)>>1;\n      if(rank(v,m)>=k+1) r=m;\n      else l=m;\n    }\n    return r-1;\n  }\n\n  int select(bool v,int i,int l){\n    return select(v,i+rank(v,l));\n  }\n};\n\ntemplate<class T,int MAXLOG>\nstruct WaveletMatrix{\n  int len;\n  FullyIndexableDictionary mat[MAXLOG];\n  int zs[MAXLOG],buff1[MAXLOG],buff2[MAXLOG];\n  static const T npos=-1;\n\n  WaveletMatrix(vector<T> data){\n    len=data.size();\n    vector<T> ls(len),rs(len);\n    for(int dep=0;dep<MAXLOG;dep++){\n      mat[dep]=FullyIndexableDictionary(len+1);\n      int p=0,q=0;\n      for(int i=0;i<len;i++){\n        bool k=(data[i]>>(MAXLOG-(dep+1)))&1;\n        if(k) rs[q++]=data[i],mat[dep].set(i);\n        else  ls[p++]=data[i];\n      }\n      zs[dep]=p;\n      mat[dep].build();\n      swap(ls,data);\n      for(int i=0;i<q;i++) data[p+i]=rs[i];\n    }\n  }\n\n  T access(int k){\n    T res=0;\n    for(int dep=0;dep<MAXLOG;dep++){\n      bool bit=mat[dep][k];\n      res=(res<<1)|bit;\n      k=mat[dep].rank(bit,k)+zs[dep]*dep;\n    }\n    return res;\n  }\n\n  // return the number of v in [0,k)\n  int rank(T v,int k){\n    int l=0,r=k;\n    for(int dep=0;dep<MAXLOG;dep++){\n      buff1[dep]=l;buff2[dep]=r;\n      bool bit=(v>>(MAXLOG-(dep+1)))&1;\n      l=mat[dep].rank(bit,l)+zs[dep]*bit;\n      r=mat[dep].rank(bit,r)+zs[dep]*bit;\n    }\n    return r-l;\n  }\n\n  // return the position of k-th v\n  int select(T v,int k){\n    rank(v,len);\n    for(int dep=MAXLOG-1;dep>=0;dep--){\n      bool bit=(v>>(MAXLOG-(dep+1)))&1;\n      k=mat[dep].select(bit,k,buff1[dep]);\n      if(k>=buff2[dep] or k<0) return -1;\n      k-=buff1[dep];\n    }\n    return k;\n  }\n\n  int select(T v,int k,int l){\n    return select(v,k+rank(v,l));\n  }\n\n  // return k-th largest value in [l,r)\n  T quantile(int l,int r,int k){\n    if(r-l<=k or k<0) return -1;\n    T res=0;\n    for(int dep=0;dep<MAXLOG;dep++){\n      int p=mat[dep].rank(1,l);\n      int q=mat[dep].rank(1,r);\n      if(q-p>k){\n        l=p+zs[dep];\n        r=q+zs[dep];\n        res|=T(1)<<(MAXLOG-(dep+1));\n      }else{\n        k-=(q-p);\n        l-=p;\n        r-=q;\n      }\n    }\n    return res;\n  }\n\n  T rquantile(int l,int r,int k){\n    return quantile(l,r,r-l-k-1);\n  }\n\n  int freq_dfs(int d,int l,int r,T val,T a,T b){\n    if(l==r) return 0;\n    if(d==MAXLOG) return (a<=val and val<b)?r-l:0;\n    T nv=T(1)<<(MAXLOG-d-1)|val;\n    T nnv=((T(1)<<(MAXLOG-d-1))-1)|nv;\n    if(nnv<a or b<=val) return 0;\n    if(a<=val and nnv<b) return r-l;\n    int lc=mat[d].rank(1,l),rc=mat[d].rank(1,r);\n    return freq_dfs(d+1,l-lc,r-rc,val,a,b)\n      +freq_dfs(d+1,lc+zs[d],rc+zs[d],nv,a,b);\n  }\n\n  // return number of points in [left, right) * [lower, upper)\n  int rangefreq(int left,int right,T lower,T upper){\n    return freq_dfs(0,left,right,0,lower,upper);\n  }\n\n  pair<int, int> ll(int l,int r,T v){\n    int res=0;\n    for(int dep=0;dep<MAXLOG;dep++){\n      buff1[dep]=l;buff2[dep]=r;\n      bool bit=(v>>(MAXLOG-(dep+1)))&1;\n      if(bit) res+=r-l+mat[dep].rank(bit,l)-mat[dep].rank(bit,r);\n      l=mat[dep].rank(bit,l)+zs[dep]*bit;\n      r=mat[dep].rank(bit,r)+zs[dep]*bit;\n    }\n    return make_pair(res,r-l);\n  }\n\n  int lt(int l,int r,T v){\n    auto p=ll(l,r,v);\n    return p.first;\n  }\n\n  int le(int l,int r,T v){\n    auto p=ll(l,r,v);\n    return p.first+p.second;\n  }\n\n  T succ(int l,int r,T v){\n    int k=le(l,r,v);\n    return k==r-l?npos:rquantile(l,r,k);\n  }\n\n  T pred(int l,int r,T v){\n    int k=lt(l,r,v);\n    return k?rquantile(l,r,k-1):npos;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "datastructure/weightedunionfind.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate <typename T>\nstruct WeightedUnionFind{\n  vector<int> rs,ps;\n  vector<T> ws;\n\n  WeightedUnionFind(int n):rs(n,1),ps(n),ws(n,T(0)){\n    iota(ps.begin(),ps.end(),0);\n  }\n\n  int find(int x){\n    if(x==ps[x]) return x;\n    int t=find(ps[x]);\n    ws[x]+=ws[ps[x]];\n    return ps[x]=t;\n  }\n\n  T weight(int x){\n    find(x);\n    return ws[x];\n  }\n\n  bool same(int x,int y){\n    return find(x)==find(y);\n  }\n\n  void unite(int x,int y,T w){\n    w+=weight(x);\n    w-=weight(y);\n    x=find(x);y=find(y);\n    if(x==y) return;\n    if(rs[x]<rs[y]) swap(x,y),w=-w;\n    rs[x]+=rs[y];\n    ps[y]=x;\n    ws[y]=w;\n  }\n\n  T diff(int x,int y){\n    return weight(y)-weight(x);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "docs/bflow/capacityscaling.md",
    "content": "---\ntitle: Minimum Cost Flow with Capacity Scaling\ndocumentation_of: //bflow/capacityscaling.cpp\n---\n\n## `INF` の決め方\n### 上限\n`m * INF` がオーバーフローすると死ぬことがある\n### 下限\n`max - INF < min` を満たしていないと区別できない\n### 結論\n`max - min < INF < 2^w / m`\n\n`w` はビット幅\n\n## 解説記事\n[Are there any learning materials of polynomial minimum cost flow algorithms?](https://codeforces.com/blog/entry/70740)\n\n[ぼくの考えたさいきょうのフローライブラリ](http://misawa.github.io/others/flow/library_design.html)\n\n[最小費用流の双対について](https://beet-aizu.hatenablog.com/entry/2019/10/20/150649)\n\n[b-flow と双対](https://beet-aizu.hatenablog.com/entry/2020/09/24/152856)\n"
  },
  {
    "path": "docs/datastructure/binaryindexedtree.md",
    "content": "---\ntitle: Binary Indexed Tree\ndocumentation_of: //datastructure/binaryindexedtree.cpp\n---\n\n## できること\n- `add(i,a)`\n-- $v_i := v_i + a$ とする\n- `query(l,r)`\n-- $\\sum_{l \\leq i \\lt r} v_i$ を求める\n- `lower_bound(w)`\n-- $v_i \\geq 0$ の仮定のもと、$\\min (\\lbrace i \\mid \\rm{sum}(i) \\ge w \\rbrace)$ を求める\n- `upper_bound(w)`\n-- $v_i \\geq 0$ の仮定のもと、$\\min (\\lbrace i \\mid \\rm{sum}(i) \\gt w \\rbrace)$ を求める\n\n## verify 用問題一覧\n- lower_bound\n-- [AOJ 0343](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0343)\n"
  },
  {
    "path": "docs/datastructure/waveletmatrix.md",
    "content": "---\ntitle: Wavelet Matrix\ndocumentation_of: //datastructure/waveletmatrix.cpp\n---\n\n## できること\n- `rank(v,k)`\n-- $\\lbrack 0, k)$ に含まれる $v$ の個数を求める\n- `select(v,k)`\n-- $k$ 番目の $v$ の位置を求める\n- `quantile(l,r,k)`\n-- $\\lbrack l, r)$ に含まれる要素の中で $k$ 番目に大きいものを求める\n- `rquantile(l,r,k)`\n-- $\\lbrack l, r)$ に含まれる要素の中で $k$ 番目に小さいものを求める\n- `rangefreq(l,r,d,u)`\n-- $\\vert \\lbrace i \\mid i \\in \\lbrack l, r), x _ i \\in \\lbrack d, u) \\rbrace \\vert$ を求める\n- `succ(l,r,v)`\n-- $\\lbrack l, r)$ に含まれる要素の中で $v$ の次に大きいものを求める\n- `pred(l,r,v)`\n-- $\\lbrack l, r)$ に含まれる要素の中で $v$ の次に小さいものを求める\n"
  },
  {
    "path": "docs/graph/rangetorange.md",
    "content": "---\ntitle: Range to Range\ndocumentation_of: //graph/rangetorange.cpp\n---\n\n## できること\n区間から区間に向けて辺を貼る\n\n## 注意\n元のグラフでの頂点 $v$ は内部的には $n + v$ に対応している\n\nクラスの外からは `idx(v)` を使うこと\n\n\n## 解説記事\n[区間に辺を張るテクの実装例（Dijkstra法セット）と使用例](https://lorent-kyopro.hatenablog.com/entry/2020/07/24/170656)\n"
  },
  {
    "path": "docs/maxflow/dinic.md",
    "content": "---\ntitle: 最大流\ndocumentation_of: //maxflow/dinic.cpp\n---\n\n## 解説記事\n[Dinic 法と, その注意点](https://topcoder-g-hatena-ne-jp.jag-icpc.org/Mi_Sawa/20140311/1394730336.html)\n\n[Dinic 法の速さ](https://topcoder-g-hatena-ne-jp.jag-icpc.org/Mi_Sawa/20140311/1394730337.html)\n"
  },
  {
    "path": "docs/maxflow/fordfulkerson.md",
    "content": "---\ntitle: 最大流 (計算量が流量依存)\ndocumentation_of: //maxflow/fordfulkerson.cpp\n---\n"
  },
  {
    "path": "docs/maxflow/leastflow.md",
    "content": "---\ntitle: 最小流量制限付き最大流\ndocumentation_of: //maxflow/leastflow.cpp\n---\n\n## 解説記事\n[最小流量制限付き最大流](https://snuke.hatenablog.com/entry/2016/07/10/043918)\n"
  },
  {
    "path": "docs/maxflow/twocommodity.md",
    "content": "---\ntitle: 最大二品種流\ndocumentation_of: //maxflow/twocommodity.cpp\n---\n\n## 解説記事\n[多品種流の話](http://www.kurims.kyoto-u.ac.jp/~kenkyubu/kokai-koza/hirai.pdf)\n"
  },
  {
    "path": "docs/mincostflow/negativeedge.md",
    "content": "---\ntitle: 最小費用流の負辺除去\ndocumentation_of: //mincostflow/negativeedge.cpp\n---\n\n## 解説記事\n[最小費用流の負辺除去](https://snuke.hatenablog.com/entry/2017/06/07/115821)\n"
  },
  {
    "path": "docs/mincostflow/primaldual.md",
    "content": "---\ntitle: 最小費用流\ndocumentation_of: //mincostflow/primaldual.cpp\n---\n\n## 解説記事\n[最小費用流の双対について](https://beet-aizu.hatenablog.com/entry/2019/10/20/150649)\n\n## 計算量\n流量を $F$ として、$O(F E \\log V)$\n\n## ポテンシャルの初期化\nコストが負の辺が存在する場合、 `build` の際に `init` を渡すことでポテンシャルの初期化の仕方を指定できる。\n\n一般の場合には bellman-ford を用いて $O(VE)$ で初期化する。\n\nDAG の場合には DP を用いて $O(E)$ で初期化することもできる。[例](https://beet-aizu.github.io/library/test/aoj/2290.test.cpp)\n\nコストが負の辺の最大流量の和が小さい場合は、[最小費用流の負辺除去](https://beet-aizu.github.io/library/mincostflow/negativeedge.cpp) を使用する。"
  },
  {
    "path": "docs/segtree/basic/lazy.md",
    "content": "---\ntitle: 遅延伝播セグメント木\ndocumentation_of: //segtree/basic/lazy.cpp\n---\n\n## 解説記事\n[遅延伝播セグメント木について（旧：遅延評価セグメント木について）](https://beet-aizu.hatenablog.com/entry/2017/12/01/225955)\n"
  },
  {
    "path": "docs/string/longestcommonprefix.md",
    "content": "---\ntitle: Longest Common Prefix\ndocumentation_of: //string/longestcommonprefix.cpp\n---\n\n## できること\n- `query(a,b)`\n-- $S$ の末尾辞の中で $a$ 番目に小さいものと $b$ 番目に小さいもののLCPを求める\n- `lcp(a,b)`\n-- $S[a:\\|S\\|]$ と $S[b:\\|S\\|]$ のLCPを求める\n\n## 計算量\n構築: $O(\\|S\\| \\log \\|S\\|)$\n\nクエリ: $O(\\log \\|S\\|)$\n\n## 注意\n- $a \\neq b$ を仮定している\n"
  },
  {
    "path": "docs/string/suffixarray.md",
    "content": "---\ntitle: Suffix Array\ndocumentation_of: //string/suffixarray.cpp\n---\n\n## できること\n- `sa[i]` : $S$ の末尾辞の中で $i$ 番目に小さいものの位置\n- `rev[i]` : $S[i:\\|S\\|]$ が辞書順で何番目か\n\n\n## 計算量\n$O(\\|S\\| \\log \\|S\\|)$\n\n## 注意\n- `sa[0]` は常に $\\|S\\|$ になる\n\n## 解説記事\n[ Suffix Array in O(N * logN) and LCP in O(N) ](https://sites.google.com/site/indy256/algo/suffix_array)"
  },
  {
    "path": "docs/test/aoj/0438.test.md",
    "content": "---\ntitle: test find_by_order, order_of_key\ndocumentation_of: //test/aoj/0438.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/0563.test.md",
    "content": "---\ntitle: test find_by_order\ndocumentation_of: //test/aoj/0563.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/1549.test.md",
    "content": "---\ntitle: test succ, pred\ndocumentation_of: //test/aoj/1549.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/1595.toptree.test.md",
    "content": "---\ntitle: Farthest (without index)\ndocumentation_of: //test/aoj/1549.toptree.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/2290.test.md",
    "content": "---\ntitle: initialize potential\ndocumentation_of: //test/aoj/2290.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/2313.test.md",
    "content": "---\ntitle: test link cut\ndocumentation_of: //test/aoj/2313.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/2636.test.md",
    "content": "---\ntitle: Distance Sum\ndocumentation_of: //test/aoj/2636.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/2667.test.md",
    "content": "---\ntitle: Path & Subtree Queries\ndocumentation_of: //test/aoj/2667.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/2679.test.md",
    "content": "---\ntitle: lexicographical cost\ndocumentation_of: //test/aoj/2679.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/2711.test.md",
    "content": "---\ntitle: test lcp\ndocumentation_of: //test/aoj/2711.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/2725.linecontainer.test.md",
    "content": "---\ntitle: test MaxLineContainer\ndocumentation_of: //test/aoj/2725.linecontainer.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/2890.test.md",
    "content": "---\ntitle: test order_of_key\ndocumentation_of: //test/aoj/2890.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/3069.test.md",
    "content": "---\ntitle: test MinLineContainer\ndocumentation_of: //test/aoj/3069.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/3112.test.md",
    "content": "---\ntitle: test query\ndocumentation_of: //test/aoj/3112.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/3117.test.md",
    "content": "---\ntitle: test order_of_key\ndocumentation_of: //test/aoj/3117.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/3143.test.md",
    "content": "---\ntitle: Farthest (with index)\ndocumentation_of: //test/aoj/3143.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/DSL_2_F.test.md",
    "content": "---\ntitle: RMQ & RUQ\ndocumentation_of: //test/aoj/DSL_2_F.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/DSL_2_H.test.md",
    "content": "---\ntitle: RMQ & RAQ\ndocumentation_of: //test/aoj/DSL_2_H.test.cpp\n---\n"
  },
  {
    "path": "docs/test/aoj/DSL_2_I.test.md",
    "content": "---\ntitle: RSQ & RUQ\ndocumentation_of: //test/aoj/DSL_2_I.test.cpp\n---\n"
  },
  {
    "path": "docs/test/yosupo/range_kth_smallest.test.md",
    "content": "---\ntitle: test rquantile\ndocumentation_of: //test/yosupo/range_kth_smallest.test.cpp\n---\n"
  },
  {
    "path": "docs/test/yukicoder/1732.test.md",
    "content": "---\ntitle: test quantile\ndocumentation_of: //test/yukicoder/1732.test.cpp\n---\n"
  },
  {
    "path": "docs/test/yukicoder/1937.test.md",
    "content": "---\ntitle: test rangefreq\ndocumentation_of: //test/yukicoder/1937.test.cpp\n---\n"
  },
  {
    "path": "docs/test/yukicoder/3267.test.md",
    "content": "---\ntitle: test GCDConvolution\ndocumentation_of: //test/yukicoder/3267.test.cpp\n---\n"
  },
  {
    "path": "docs/test/yukicoder/3453.test.md",
    "content": "---\ntitle: Minimum Steiner Tree\ndocumentation_of: //test/yukicoder/3453.test.cpp\n---\n"
  },
  {
    "path": "docs/test/yukicoder/7107.test.md",
    "content": "---\ntitle: test LCMConvolution\ndocumentation_of: //test/yukicoder/7107.test.cpp\n---\n"
  },
  {
    "path": "docs/toptree/toptree.md",
    "content": "---\ntitle: Top Tree\ndocumentation_of: //toptree/toptree.cpp\n---\n\n## 解説記事\n[Toptree 導入編](https://niuez.hatenablog.com/entry/2019/08/04/191420)\n\n[Toptree - Link & Cut編](https://niuez.hatenablog.com/entry/2019/08/05/114511)\n\n"
  },
  {
    "path": "docs/tree/ahu.md",
    "content": "---\ntitle: 根付き木の同型性判定\ndocumentation_of: //tree/ahu.cpp\n---\n\n## できること\n与えられた根付き木の決定的なハッシュ値を求める\n\n一般の木について同型性判定を行う場合は、まず木の中心や重心を求め、それらを根にすればよい\n\n## 計算量\n$O(N \\log N)$\n"
  },
  {
    "path": "docs/tree/auxiliarytree.md",
    "content": "---\ntitle: Auxiliary Tree\ndocumentation_of: //tree/auxiliarytree.cpp\n---\n\n## できること\n与えられた木の頂点の部分集合に関して、その頂点を全て含むような最小の木を構築する\n\n## つかいかた\n- `query(ws)`: 部分集合 `ws` の Aux Tree を破壊的に構築する（必要な頂点が `ws` に追加される）\n- `clear(ws)`: `ws` から伸びている辺を削除する\n\n## 計算量\n部分集合のサイズを$k$として、$O(k \\log k)$\n\nAux Treeの頂点数は $2k$ 以下になる\n\n\n## 参考リンク\n[LCAをベースに構築するAuxiliary Treeのメモ](https://smijake3.hatenablog.com/entry/2019/09/15/200200)\n"
  },
  {
    "path": "docs/tree/heavylightdecomposition.md",
    "content": "---\ntitle: Heavy Light Decomposition\ndocumentation_of: //tree/heavylightdecomposition.cpp\n---\n\n## できること\n\nHL分解では、木（あるいは森 ）上のパスを $O(\\log N)$ 個に分割することができます。\n分割後のパスに対して操作を行った後にマージし直すことで、操作を高速に行うことができます。\n\nHL分解を使えるかどうかの条件は、載せるデータ構造（セグ木、BIT）等のみに依存します。\nつまり、ある単純な（一直線に並んでいるような）要素列に対しての問題が $O(X)$ で解けるなら、\nそれが木の上のパスになった場合でも $O(X \\log N)$ で解くことができます。\n\n## つかいかた\n頂点属性のクエリの場合は `for_each()` 、辺属性のクエリの場合は `for_each_edge()` で処理します\n\n演算が可換でない場合は `w = lca(u, v)` として、`for_each(w, u)` と `for_each_edge(w, v)` の結果を合成すればよいです\n\n\n### 解説記事\n[Easiest HLD with subtree queries](https://codeforces.com/blog/entry/53170)\n\n[Heavy-Light Decomposition](https://beet-aizu.hatenablog.com/entry/2017/12/12/235950) (実装が古い)\n"
  },
  {
    "path": "docs/tree/rerooting.md",
    "content": "---\ntitle: ReRooting\ndocumentation_of: //tree/rerooting.cpp\n---\n\n## できること\n全ての頂点について、その頂点を根としたときの木DPの結果を求める\n\nある頂点を根としたときの部分木の結果を求めることもできる [問題](https://atcoder.jp/contests/tenka1-2015-quala/tasks/tenka1_2015_qualA_d) [提出例](https://atcoder.jp/contests/tenka1-2015-quala/submissions/11218391)\n\n## データの持ち方\n- `T`: 結果\n- `Edge`: 辺の情報\n- `Node`: 逆辺のindexなどを管理する\n\n## つかいかた\n以下のラムダ式を実装する\n- `fold(x, y)`: 結果 `x` と結果 `y` をマージ\n- `lift(x, e)`: 結果 `x` を辺 `e` を使って上に持ち上げる\n\n## 計算量\n頂点数を $N$ として $O(N \\log N)$\n\n「ある頂点を根としたときの部分木の結果」が必要なければ $O(N)$ にもできる\n\n## 参考リンク\n[†全方位木DP†について](https://ei1333.hateblo.jp/entry/2017/04/10/224413)\n\n[もうひとつの全方位木DP](https://ei1333.hateblo.jp/entry/2018/12/21/004022)\n"
  },
  {
    "path": "docs/tree/sack.md",
    "content": "---\ntitle: Sack (dsu on tree)\ndocumentation_of: //tree/sack.cpp\n---\n\n## できること\n部分木に対するクエリを処理できる\n\nunordered 系を使ったマージテクより定数倍が軽いことが多い\n\n## つかいかた\n以下のラムダ式を実装する\n- `expand(v)` : `v` を追加したときの処理\n- `shrink(v)` : `v` を削除したときの処理\n- `query(k)` : `k` 番目のクエリに対する処理\n\n## 計算量\n頂点数を $N$ として、`expand`, `shrink` が $O(N \\log N)$ 回呼び出される\n\n## 注意\n- `shrink(v)` を呼ぶときは全体が初期化されるので、 `expand(v)` で変更した値を全て初期値にしてもよい（直前の操作のロールバックができる必要はない）\n- 頂点 `v` の追加削除の際に複数の処理を行う必要がある場合は、`v` の子としてダミーの頂点を追加するとよい\n\n\n## 参考リンク\n[[Tutorial] Sack (dsu on tree)](https://codeforces.com/blog/entry/44351)\n"
  },
  {
    "path": "formalpowerseries/998244353.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../mod/mint.cpp\"\n#include \"../convolution/numbertheoretictransform.cpp\"\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nnamespace fps_998244353{\n  NTT<2> ntt;\n  using M = decltype(ntt)::M;\n  using E = Enumeration<M>;\n  auto conv=[](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n}\n\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/base.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#undef call_from_test\n\n#endif\n// http://beet-aizu.hatenablog.com/entry/2019/09/27/224701\n//BEGIN CUT HERE\ntemplate<typename M_>\nstruct FormalPowerSeries : Enumeration<M_> {\n  using M = M_;\n  using super = Enumeration<M>;\n  using super::fact;\n  using super::finv;\n  using super::invs;\n\n  using Poly = vector<M>;\n  using Conv = function<Poly(Poly, Poly)>;\n  Conv conv;\n  FormalPowerSeries(Conv conv):conv(conv){}\n\n  Poly pre(const Poly &as,int deg){\n    return Poly(as.begin(),as.begin()+min((int)as.size(),deg));\n  }\n\n  Poly add(Poly as,Poly bs){\n    int sz=max(as.size(),bs.size());\n    Poly cs(sz,M(0));\n    for(int i=0;i<(int)as.size();i++) cs[i]+=as[i];\n    for(int i=0;i<(int)bs.size();i++) cs[i]+=bs[i];\n    return cs;\n  }\n\n  Poly sub(Poly as,Poly bs){\n    int sz=max(as.size(),bs.size());\n    Poly cs(sz,M(0));\n    for(int i=0;i<(int)as.size();i++) cs[i]+=as[i];\n    for(int i=0;i<(int)bs.size();i++) cs[i]-=bs[i];\n    return cs;\n  }\n\n  Poly mul(Poly as,Poly bs){\n    return conv(as,bs);\n  }\n\n  Poly mul(Poly as,M k){\n    for(auto &a:as) a*=k;\n    return as;\n  }\n\n  bool is_zero(Poly as){\n    return as==Poly(as.size(),0);\n  }\n\n  void shrink(Poly &as){\n    assert(not is_zero(as));\n    while(as.back()==M(0)) as.pop_back();\n  }\n\n  // F(0) must not be 0\n  Poly inv(Poly as,int deg);\n\n  // not zero\n  Poly div(Poly as,Poly bs);\n\n  // not zero\n  Poly mod(Poly as,Poly bs);\n\n  // F(0) must be 1\n  Poly sqrt(Poly as,int deg);\n\n  Poly diff(Poly as);\n  Poly integral(Poly as);\n\n  // F(0) must be 1\n  Poly log(Poly as,int deg);\n\n  // F(0) must be 0\n  Poly exp(Poly as,int deg);\n\n  // not zero\n  Poly pow(Poly as,long long k,int deg);\n\n  // x <- x + c\n  Poly shift(Poly as,M c);\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/diff.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::diff(Poly as){\n  int n=as.size();\n  Poly rs(n);\n  for(int i=1;i<n;i++) rs[i-1]=as[i]*M(i);\n  return rs;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/div.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#include \"inv.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::div(Poly as,Poly bs){\n  shrink(as);shrink(bs);\n  if(as.size()<bs.size()) return Poly({0});\n  reverse(as.begin(),as.end());\n  reverse(bs.begin(),bs.end());\n  int need=as.size()-bs.size()+1;\n  Poly ds=pre(mul(as,inv(bs,need)),need);\n  reverse(ds.begin(),ds.end());\n  return ds;\n}\n\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/exp.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#include \"inv.cpp\"\n#include \"diff.cpp\"\n#include \"integral.cpp\"\n#include \"log.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::exp(Poly as,int deg){\n  Poly fs({M(1)});\n  as[0]+=M(1);\n  for(int i=1;i<deg;i<<=1)\n    fs=pre(mul(fs,sub(pre(as,i<<1),log(fs,i<<1))),i<<1);\n  return fs;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/integral.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::integral(Poly as){\n  super::init(as.size()+1);\n  int n=as.size();\n  Poly rs(n+1);\n  rs[0]=M(0);\n  for(int i=0;i<n;i++) rs[i+1]=as[i]*invs[i+1];\n  return rs;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/inv.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::inv(Poly as,int deg){\n  assert(as[0]!=M(0));\n  Poly rs({M(1)/as[0]});\n  for(int i=1;i<deg;i<<=1)\n    rs=pre(sub(add(rs,rs),mul(mul(rs,rs),pre(as,i<<1))),i<<1);\n  return rs;\n}\n\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/log.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#include \"inv.cpp\"\n#include \"diff.cpp\"\n#include \"integral.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::log(Poly as,int deg){\n  return pre(integral(mul(diff(as),inv(as,deg))),deg);\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/mod.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#include \"inv.cpp\"\n#include \"div.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::mod(Poly as,Poly bs){\n  if(is_zero(as)) return Poly({0});\n  shrink(as);shrink(bs);\n  as=sub(as,mul(div(as,bs),bs));\n  if(is_zero(as)) return Poly({0});\n  shrink(as);\n  return as;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/pow.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#include \"inv.cpp\"\n#include \"diff.cpp\"\n#include \"integral.cpp\"\n#include \"log.cpp\"\n#include \"exp.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::pow(Poly as,long long k,int deg){\n  if(is_zero(as)) return Poly(deg,M(0));\n  shrink(as);\n\n  int cnt=0;\n  while(as[cnt]==M(0)) cnt++;\n  if(cnt*k>=deg) return Poly(deg,M(0));\n  as.erase(as.begin(),as.begin()+cnt);\n  deg-=cnt*k;\n\n  M c=as[0];\n  Poly zs(cnt*k,M(0));\n  Poly rs=mul(exp(mul(log(mul(as,c.inv()),deg),M(k)),deg),c.pow(k));\n  zs.insert(zs.end(),rs.begin(),rs.end());\n  return pre(zs,deg+cnt*k);\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/shift.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::shift(Poly as,M c){\n  super::init(as.size()+1);\n  int n=as.size();\n  for(int i=0;i<n;i++) as[i]*=fact[i];\n  reverse(as.begin(),as.end());\n  Poly bs(n,M(1));\n  for(int i=1;i<n;i++)\n    bs[i]=bs[i-1]*c*invs[i];\n  as=pre(mul(as,bs),n);\n  reverse(as.begin(),as.end());\n  for(int i=0;i<n;i++) as[i]*=finv[i];\n  return as;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "formalpowerseries/sqrt.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"base.cpp\"\n#include \"inv.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nvector<M> FormalPowerSeries<M>::sqrt(Poly as,int deg){\n  assert(as[0]==M(1));\n  M inv2=M(1)/M(2);\n  Poly ss({M(1)});\n  for(int i=1;i<deg;i<<=1){\n    ss=pre(add(ss,mul(pre(as,i<<1),inv(ss,i<<1))),i<<1);\n    for(M &x:ss) x*=inv2;\n  }\n  return ss;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "geometry/3D/geometry3D.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n//BEGIN CUT HERE\n\n#define EPS (1e-10)\n#define equals(a,b) (fabs((a)-(b)) < EPS)\n#define PI 3.141592653589793238\nstruct Point3D{\n  double x,y,z;\n  Point3D(){}\n  Point3D(double x,double y,double z):x(x),y(y),z(z){}\n  Point3D operator+(Point3D p) {return Point3D(x+p.x,y+p.y,z+p.z);}\n  Point3D operator-(Point3D p) {return Point3D(x-p.x,y-p.y,z-p.z);}\n  Point3D operator*(double k){return Point3D(x*k,y*k,z*k);}\n  Point3D operator/(double k){return Point3D(x/k,y/k,z/k);}\n  Point3D operator*(Point3D p){\n    return Point3D(y*p.z-z*p.y,z*p.x-x*p.z,x*p.y-y*p.x);\n  }\n  double operator^(Point3D p){\n    return x*p.x+y*p.y+z*p.z;\n  }\n  double norm(){return x*x+y*y+z*z;}\n  double abs(){return sqrt(norm());}\n  bool operator < (const Point3D &p) const{\n    if(x!=p.x) return x<p.x;\n    if(y!=p.y) return y<p.y;\n    return z<p.z;\n  }\n  bool operator == (const Point3D &p) const{\n    return fabs(x-p.x)<EPS  and  fabs(y-p.y)<EPS  and  fabs(z-p.z)<EPS;\n  }\n};\nistream &operator >> (istream &is,Point3D &p){\n  is>>p.x>>p.y>>p.z;\n  return is;\n}\nostream &operator << (ostream &os,Point3D p){\n  os<<fixed<<setprecision(12)<<p.x<<\" \"<<p.y<<\" \"<<p.z;\n  return os;\n}\n\ntypedef Point3D Vector3D;\ntypedef vector<Point3D> Polygon3D;\n\nstruct Segment3D{\n  Point3D p1,p2;\n  Segment3D(){}\n  Segment3D(Point3D p1, Point3D p2):p1(p1),p2(p2){}\n};\ntypedef Segment3D Line3D;\n\nistream &operator >> (istream &is,Segment3D &s){\n  is>>s.p1>>s.p2;\n  return is;\n}\n\nstruct Sphere{\n  Point3D c;\n  double r;\n  Sphere(){}\n  Sphere(Point3D c,double r):c(c),r(r){}\n};\n\nistream &operator >> (istream &is,Sphere &c){\n  is>>c.c>>c.r;\n  return is;\n}\n\ndouble norm(Vector3D a){\n  return a.x*a.x+a.y*a.y+a.z*a.z;\n}\ndouble abs(Vector3D a){\n  return sqrt(norm(a));\n}\ndouble dot(Vector3D a,Vector3D b){\n  return a.x*b.x+a.y*b.y+a.z*b.z;\n}\nVector3D cross(Vector3D a,Vector3D b){\n  return Vector3D(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);\n}\n\nPoint3D project(Line3D l,Point3D p){\n  Point3D b=l.p2-l.p1;\n  double t=dot(p-l.p1,b)/norm(b);\n  return l.p1+b*t;\n}\n\nPoint3D reflect(Line3D l,Point3D p){\n  return p+(project(l,p)-p)*2.0;\n}\n\ndouble getDistanceLP(Line3D l,Point3D p){\n  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));\n}\n\ndouble getDistanceSP(Segment3D s,Point3D p){\n  if(dot(s.p2-s.p1,p-s.p1) < 0.0 ) return abs(p-s.p1);\n  if(dot(s.p1-s.p2,p-s.p2) < 0.0 ) return abs(p-s.p2);\n  return getDistanceLP(s,p);\n}\n\nbool intersectSC(Segment3D s,Sphere c){\n  double d=getDistanceSP(s,c.c);\n  if(d>c.r) return 0;\n  return !((abs(s.p1-c.c)<=c.r) and (abs(s.p2-c.c)<=c.r));\n}\n\nstruct ConvexHull3D{\n  struct face{\n    int a,b,c;\n    bool ok;\n    face(){}\n    face(int a,int b,int c,bool ok):a(a),b(b),c(c),ok(ok){}\n  };\n  int n,num;\n  vector<Point3D> p;\n  vector<face> f;\n  vector<vector<int> >  g;\n\n  ConvexHull3D(int n):n(n),p(n),f(n*8),g(n,vector<int>(n)){}\n\n  void input(){\n    for(int i=0;i<n;i++) cin>>p[i];\n  }\n\n  double dblcmp(Point3D q,face f){\n    Point3D m=p[f.b]-p[f.a];\n    Point3D n=p[f.c]-p[f.a];\n    Point3D t=q-p[f.a];\n    return (m*n)^t;\n  }\n\n  void deal(int q,int a,int b){\n    int idx=g[a][b];\n    face add;\n    if(f[idx].ok){\n      if(dblcmp(p[q],f[idx])>EPS) dfs(q,idx);\n      else{\n        add=face(b,a,q,1);\n        g[q][b]=g[a][q]=g[b][a]=num;\n        f[num++]=add;\n      }\n    }\n  }\n\n  void dfs(int q,int now){\n    f[now].ok=0;\n    deal(q,f[now].b,f[now].a);\n    deal(q,f[now].c,f[now].b);\n    deal(q,f[now].a,f[now].c);\n  }\n\n  void build(){\n    num=0;\n    if(n<4) return;\n    bool flg=1;\n    for(int i=1;i<n;i++){\n      if(abs(p[0]-p[i])>EPS){\n        swap(p[1],p[i]);\n        flg=0;\n        break;\n      }\n    }\n    if(flg) return;\n    flg=1;\n    for(int i=2;i<n;i++){\n      if(abs((p[0]-p[1])*(p[1]-p[i]))>EPS){\n        swap(p[2],p[i]);\n        flg=0;\n        break;\n      }\n    }\n    if(flg) return;\n    flg=1;\n    for(int i=3;i<n;i++){\n      if(abs(((p[0]-p[1])*(p[1]-p[2]))^(p[0]-p[i]))>EPS){\n        swap(p[3],p[i]);\n        flg=0;\n        break;\n      }\n    }\n    if(flg) return;\n    face add;\n    for(int i=0;i<4;i++){\n      add=face((i+1)%4,(i+2)%4,(i+3)%4,1);\n      if(dblcmp(p[i],add)>0) swap(add.b,add.c);\n      g[add.a][add.b]=g[add.b][add.c]=g[add.c][add.a]=num;\n      f[num++]=add;\n    }\n    for(int i=4;i<n;i++){\n      for(int j=0;j<num;j++){\n        if(f[j].ok and dblcmp(p[i],f[j])>EPS){\n          dfs(i,j);\n          break;\n        }\n      }\n    }\n    int tmp=num;\n    num=0;\n    for(int i=0;i<tmp;i++)\n      if(f[i].ok) f[num++]=f[i];\n  }\n\n  double volume(Point3D a,Point3D b,Point3D c,Point3D d){\n    return ((b-a)*(c-a))^(d-a);\n  }\n\n  bool same(int s,int t){\n    Point3D &a=p[f[s].a];\n    Point3D &b=p[f[s].b];\n    Point3D &c=p[f[s].c];\n    return  (abs(volume(a,b,c,p[f[t].a]))<EPS)\n       and     (abs(volume(a,b,c,p[f[t].b]))<EPS)\n       and     (abs(volume(a,b,c,p[f[t].c]))<EPS);\n  }\n\n  int polygon(){\n    int res=0;\n    for(int i=0;i<num;i++){\n      int flg=1;\n      for(int j=0;j<i;j++)\n        flg&=!same(i,j);\n      res+=flg;\n    }\n    return res;\n  }\n\n  int triangle(){\n    return num;\n  }\n\n  double area(Point3D a,Point3D b,Point3D c){\n    return abs((b-a)*(c-a));\n  }\n\n  Point3D cross(Point3D a,Point3D b,Point3D c){\n    return Point3D((b.y-a.y)*(c.z-a.z)-(b.z-a.z)*(c.y-a.y),\n                   (b.z-a.z)*(c.x-a.x)-(b.x-a.x)*(c.z-a.z),\n                   (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x));\n  }\n\n  double area(){\n    double res=0;\n    if(n==3){\n      Point3D q=cross(p[0],p[1],p[2]);\n      res=abs(q)/2.0;\n      return res;\n    }\n    return res;\n    for(int i=0;i<num;i++)\n      res+=area(p[f[i].a],p[f[i].b],p[f[i].c]);\n    return res/2.0;\n  }\n};\n\n//END CUT HERE\n\nsigned main(){\n  int n;\n  while(cin>>n){\n    ConvexHull3D ch(n);\n    ch.input();\n    ch.build();\n    cout<<ch.polygon()<<endl;\n  }\n  return 0;\n}\n\n/*\n  verified on 2019/10/22\n  https://vjudge.net/problem/HDU-3662\n*/\n"
  },
  {
    "path": "geometry/argsort.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// (-pi, pi], atan2(0, 0) = 0\ntemplate<typename P>\nvoid argsort(vector<P> &ps){\n  auto getA=\n    [&](P p){\n      if(p.x>=0 and p.y>=0) return 0;\n      if(p.y>=0) return 1;\n      if(p.x<=0) return -2;\n      return -1;\n    };\n  auto cross=[&](P a,P b){return a.x*b.y-a.y*b.x;};\n  auto cmp=\n    [&](P a,P b){\n      if(getA(a)!=getA(b)) return getA(a)<getA(b);\n      if(a.x==0 and a.y==0) return !(b.x==0 and b.y==0);\n      if(b.x==0 and b.y==0) return false;\n      return cross(a,b)>0;\n    };\n  sort(ps.begin(),ps.end(),cmp);\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "geometry/geometry.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n\n#define equals(a,b) (fabs((a)-(b))<EPS)\n\nnamespace geometry {\n  const double EPS = 1e-10;\n  const double PI = asinl(1) * 2;\n\n  struct Point{\n    double x,y;\n    Point(){}\n    Point(double x,double y):x(x),y(y){}\n    Point operator+(Point p) {return Point(x+p.x,y+p.y);}\n    Point operator-(Point p) {return Point(x-p.x,y-p.y);}\n    Point operator*(double k){return Point(x*k,y*k);}\n    Point operator/(double k){return Point(x/k,y/k);}\n    double norm(){return x*x+y*y;}\n    double abs(){return sqrt(norm());}\n\n    bool operator<(const Point &p) const{\n      return x!=p.x?x<p.x:y<p.y;\n      //grid-point only\n      //return !equals(x,p.x)?x<p.x:!equals(y,p.y)?y<p.y:0;\n    }\n\n    bool operator==(const Point &p) const{\n      return fabs(x-p.x)<EPS and fabs(y-p.y)<EPS;\n    }\n  };\n\n  bool sort_x(Point a,Point b){\n    return a.x!=b.x?a.x<b.x:a.y<b.y;\n  }\n\n  bool sort_y(Point a,Point b){\n    return a.y!=b.y?a.y<b.y:a.x<b.x;\n  }\n\n  typedef Point Vector;\n  typedef vector<Point> Polygon;\n\n  struct Segment{\n    Point p1,p2;\n    Segment(){}\n    Segment(Point p1, Point p2):p1(p1),p2(p2){}\n  };\n  typedef Segment Line;\n\n  struct Circle{\n    Point c;\n    double r;\n    Circle(){}\n    Circle(Point c,double r):c(c),r(r){}\n  };\n\n  double norm(Vector a){\n    return a.x*a.x+a.y*a.y;\n  }\n\n  double abs(Vector a){\n    return sqrt(norm(a));\n  }\n\n  double dot(Vector a,Vector b){\n    return a.x*b.x+a.y*b.y;\n  }\n\n  double cross(Vector a,Vector b){\n    return a.x*b.y-a.y*b.x;\n  }\n\n  Point orth(Point p){return Point(-p.y,p.x);}\n\n  bool isOrthogonal(Vector a,Vector b){\n    return equals(dot(a,b),0.0);\n  }\n\n  bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){\n    return isOrthogonal(a1-a2,b1-b2);\n  }\n\n  bool isOrthogonal(Segment s1,Segment s2){\n    return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);\n  }\n\n  bool isParallel(Vector a,Vector b){\n    return equals(cross(a,b),0.0);\n  }\n\n  bool isParallel(Point a1,Point a2,Point b1,Point b2){\n    return isParallel(a1-a2,b1-b2);\n  }\n\n  bool isParallel(Segment s1,Segment s2){\n    return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0);\n  }\n\n  Point project(Segment s,Point p){\n    Vector base=s.p2-s.p1;\n    double r=dot(p-s.p1,base)/norm(base);\n    return s.p1+base*r;\n  }\n\n  Point reflect(Segment s,Point p){\n    return p+(project(s,p)-p)*2.0;\n  }\n\n  double arg(Vector p){\n    return atan2(p.y,p.x);\n  }\n\n  Vector polar(double a,double r){\n    return Point(cos(r)*a,sin(r)*a);\n  }\n\n  // COUNTER CLOCKWISE\n  static const int CCW_COUNTER_CLOCKWISE = 1;\n  static const int CCW_CLOCKWISE = -1;\n  static const int CCW_ONLINE_BACK = 2;\n  static const int CCW_ONLINE_FRONT = -2;\n  static const int CCW_ON_SEGMENT = 0;\n\n  int ccw(Point p0,Point p1,Point p2){\n    Vector a = p1-p0;\n    Vector b = p2-p0;\n    if(cross(a,b) > EPS) return CCW_COUNTER_CLOCKWISE;\n    if(cross(a,b) < -EPS) return CCW_CLOCKWISE;\n    if(dot(a,b) < -EPS) return CCW_ONLINE_BACK;\n    if(a.norm()<b.norm()) return CCW_ONLINE_FRONT;\n    return CCW_ON_SEGMENT;\n  }\n\n  bool intersectSS(Point p1,Point p2,Point p3,Point p4){\n    return (ccw(p1,p2,p3)*ccw(p1,p2,p4) <= 0 and\n            ccw(p3,p4,p1)*ccw(p3,p4,p2) <= 0 );\n  }\n\n  bool intersectSS(Segment s1,Segment s2){\n    return intersectSS(s1.p1,s1.p2,s2.p1,s2.p2);\n  }\n\n  bool intersectPS(Polygon p,Segment l){\n    int n=p.size();\n    for(int i=0;i<n;i++)\n      if(intersectSS(Segment(p[i],p[(i+1)%n]),l)) return 1;\n    return 0;\n  }\n\n  double getDistanceLP(Line l,Point p){\n    return fabs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));\n  }\n\n  double getDistanceSP(Segment s,Point p){\n    if(dot(s.p2-s.p1,p-s.p1) < 0.0 ) return abs(p-s.p1);\n    if(dot(s.p1-s.p2,p-s.p2) < 0.0 ) return abs(p-s.p2);\n    return getDistanceLP(s,p);\n  }\n\n  double getDistanceSS(Segment s1,Segment s2){\n    if(intersectSS(s1,s2)) return 0.0;\n    return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),\n               min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));\n  }\n\n  // intercsect of circles\n  static const int ICC_SEPERATE = 4;\n  static const int ICC_CIRCUMSCRIBE = 3;\n  static const int ICC_INTERSECT = 2;\n  static const int ICC_INSCRIBE = 1;\n  static const int ICC_CONTAIN = 0;\n\n  int intersectCC(Circle c1,Circle c2){\n    if(c1.r<c2.r) swap(c1,c2);\n    double d=abs(c1.c-c2.c);\n    double r=c1.r+c2.r;\n    if(equals(d,r)) return ICC_CIRCUMSCRIBE;\n    if(d>r) return ICC_SEPERATE;\n    if(equals(d+c2.r,c1.r)) return ICC_INSCRIBE;\n    if(d+c2.r<c1.r) return ICC_CONTAIN;\n    return ICC_INTERSECT;\n  }\n\n  bool intersectSC(Segment s,Circle c){\n    return getDistanceSP(s,c.c)<=c.r;\n  }\n\n  int intersectCS(Circle c,Segment s){\n    if(norm(project(s,c.c)-c.c)-c.r*c.r>EPS) return 0;\n    double d1=abs(c.c-s.p1),d2=abs(c.c-s.p2);\n    if(d1<c.r+EPS and d2<c.r+EPS) return 0;\n    if((d1<c.r-EPS and d2>c.r+EPS) or (d1>c.r+EPS and d2<c.r-EPS)) return 1;\n    Point h=project(s,c.c);\n    if(dot(s.p1-h,s.p2-h)<0) return 2;\n    return 0;\n  }\n\n  Point getCrossPointSS(Segment s1,Segment s2){\n    for(int k=0;k<2;k++){\n      if(getDistanceSP(s1,s2.p1)<EPS) return s2.p1;\n      if(getDistanceSP(s1,s2.p2)<EPS) return s2.p2;\n      swap(s1,s2);\n    }\n    Vector base=s2.p2-s2.p1;\n    double d1=fabs(cross(base,s1.p1-s2.p1));\n    double d2=fabs(cross(base,s1.p2-s2.p1));\n    double t=d1/(d1+d2);\n    return s1.p1+(s1.p2-s1.p1)*t;\n  }\n\n  Point getCrossPointLL(Line l1,Line l2){\n    double a=cross(l1.p2-l1.p1,l2.p2-l2.p1);\n    double b=cross(l1.p2-l1.p1,l1.p2-l2.p1);\n    if(fabs(a)<EPS and fabs(b)<EPS) return l2.p1;\n    return l2.p1+(l2.p2-l2.p1)*(b/a);\n  }\n\n  Polygon getCrossPointCL(Circle c,Line l){\n    Polygon ps;\n    Point pr=project(l,c.c);\n    Vector e=(l.p2-l.p1)/abs(l.p2-l.p1);\n    if(equals(getDistanceLP(l,c.c),c.r)){\n      ps.emplace_back(pr);\n      return ps;\n    }\n    double base=sqrt(c.r*c.r-norm(pr-c.c));\n    ps.emplace_back(pr+e*base);\n    ps.emplace_back(pr-e*base);\n    return ps;\n  }\n\n  Polygon getCrossPointCS(Circle c,Segment s){\n    Line l(s);\n    Polygon res=getCrossPointCL(c,l);\n    if(intersectCS(c,s)==2) return res;\n    if(res.size()>1u){\n      if(dot(l.p1-res[0],l.p2-res[0])>0) swap(res[0],res[1]);\n      res.pop_back();\n    }\n    return res;\n  }\n\n\n  Polygon getCrossPointCC(Circle c1,Circle c2){\n    Polygon p(2);\n    double d=abs(c1.c-c2.c);\n    double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));\n    double t=arg(c2.c-c1.c);\n    p[0]=c1.c+polar(c1.r,t+a);\n    p[1]=c1.c+polar(c1.r,t-a);\n    return p;\n  }\n\n  // IN:2 ON:1 OUT:0\n  int contains(Polygon g,Point p){\n    int n=g.size();\n    bool x=false;\n    for(int i=0;i<n;i++){\n      Point a=g[i]-p,b=g[(i+1)%n]-p;\n      if(fabs(cross(a,b)) < EPS and dot(a,b) < EPS) return 1;\n      if(a.y>b.y) swap(a,b);\n      if(a.y < EPS and EPS < b.y and cross(a,b) > EPS ) x = !x;\n    }\n    return (x?2:0);\n  }\n\n  Polygon andrewScan(Polygon s){\n    Polygon u,l;\n    if(s.size()<3) return s;\n    sort(s.begin(),s.end());\n    u.push_back(s[0]);\n    u.push_back(s[1]);\n    l.push_back(s[s.size()-1]);\n    l.push_back(s[s.size()-2]);\n    for(int i=2;i<(int)s.size();i++){\n      for(int n=u.size();\n          n>=2 and ccw(u[n-2],u[n-1],s[i])!=CCW_CLOCKWISE;\n          n--){\n        u.pop_back();\n      }\n      u.push_back(s[i]);\n    }\n    for(int i=s.size()-3;i>=0;i--){\n      for(int n=l.size();\n          n>=2 and ccw(l[n-2],l[n-1],s[i])!=CCW_CLOCKWISE;\n          n--){\n        l.pop_back();\n      }\n      l.push_back(s[i]);\n    }\n    reverse(l.begin(),l.end());\n    for(int i=u.size()-2;i>=1;i--) l.push_back(u[i]);\n    return l;\n  }\n\n  Polygon convex_hull(Polygon ps){\n    int n=ps.size();\n    sort(ps.begin(),ps.end(),sort_y);\n    int k=0;\n    Polygon qs(n*2);\n    for(int i=0;i<n;i++){\n      while(k>1 and cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--;\n      qs[k++]=ps[i];\n    }\n    for(int i=n-2,t=k;i>=0;i--){\n      while(k>t and cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--;\n      qs[k++]=ps[i];\n    }\n    qs.resize(k-1);\n    return qs;\n  }\n\n  double diameter(Polygon s){\n    Polygon p=s;\n    int n=p.size();\n    if(n==2) return abs(p[0]-p[1]);\n    int i=0,j=0;\n    for(int k=0;k<n;k++){\n      if(p[i]<p[k]) i=k;\n      if(!(p[j]<p[k])) j=k;\n    }\n    double res=0;\n    int si=i,sj=j;\n    while(i!=sj or j!=si){\n      res=max(res,abs(p[i]-p[j]));\n      if(cross(p[(i+1)%n]-p[i],p[(j+1)%n]-p[j])<0.0){\n        i=(i+1)%n;\n      }else{\n        j=(j+1)%n;\n      }\n    }\n    return res;\n  }\n\n  bool isConvex(Polygon p){\n    bool f=1;\n    int n=p.size();\n    for(int i=0;i<n;i++){\n      int t=ccw(p[(i+n-1)%n],p[i],p[(i+1)%n]);\n      f&=t!=CCW_CLOCKWISE;\n    }\n    return f;\n  }\n\n  double area(Polygon s){\n    double res=0;\n    for(int i=0;i<(int)s.size();i++){\n      res+=cross(s[i],s[(i+1)%s.size()])/2.0;\n    }\n    return res;\n  }\n\n  double area(Circle c1,Circle c2){\n    double d=abs(c1.c-c2.c);\n    if(c1.r+c2.r<=d+EPS) return 0;\n    if(d<=fabs(c1.r-c2.r)){\n      double r=min(c1.r,c2.r);\n      return PI*r*r;\n    }\n    double res=0;\n    for(int k=0;k<2;k++){\n      double rc=(d*d+c1.r*c1.r-c2.r*c2.r)/(2*d*c1.r);\n      double th=acosl(rc)*2;\n      res+=(th-sinl(th))*c1.r*c1.r/2;\n      swap(c1,c2);\n    }\n    return res;\n  }\n\n  Polygon convexCut(Polygon p,Line l){\n    Polygon q;\n    for(int i=0;i<(int)p.size();i++){\n      Point a=p[i],b=p[(i+1)%p.size()];\n      if(ccw(l.p1,l.p2,a)!=-1) q.push_back(a);\n      if(ccw(l.p1,l.p2,a)*ccw(l.p1,l.p2,b)<0)\n        q.push_back(getCrossPointLL(Line(a,b),l));\n    }\n    return q;\n  }\n\n  Line bisector(Point p1,Point p2){\n    Circle c1=Circle(p1,abs(p1-p2)),c2=Circle(p2,abs(p1-p2));\n    Polygon p=getCrossPointCC(c1,c2);\n    if(cross(p2-p1,p[0]-p1)>0) swap(p[0],p[1]);\n    return Line(p[0],p[1]);\n  }\n\n  Vector translate(Vector v,double theta){\n    Vector res;\n    res.x=cos(theta)*v.x-sin(theta)*v.y;\n    res.y=sin(theta)*v.x+cos(theta)*v.y;\n    return res;\n  }\n\n  vector<Line> corner(Line l1,Line l2){\n    vector<Line> res;\n    if(isParallel(l1,l2)){\n      double d=getDistanceLP(l1,l2.p1)/2.0;\n      Vector v1=l1.p2-l1.p1;\n      v1=v1/v1.abs()*d;\n      Point p=l2.p1+translate(v1,90.0*(PI/180.0));\n      double d1=getDistanceLP(l1,p);\n      double d2=getDistanceLP(l2,p);\n      if(fabs(d1-d2)>d){\n        p=l2.p1+translate(v1,-90.0*(PI/180.0));\n      }\n      res.push_back(Line(p,p+v1));\n    }else{\n      Point p=getCrossPointLL(l1,l2);\n      Vector v1=l1.p2-l1.p1,v2=l2.p2-l2.p1;\n      v1=v1/v1.abs();\n      v2=v2/v2.abs();\n      res.push_back(Line(p,p+(v1+v2)));\n      res.push_back(Line(p,p+translate(v1+v2,90.0*(PI/180.0))));\n    }\n    return res;\n  }\n\n  Polygon tangent(Circle c1,Point p2){\n    Circle c2=Circle(p2,sqrt(norm(c1.c-p2)-c1.r*c1.r));\n    Polygon p=getCrossPointCC(c1,c2);\n    sort(p.begin(),p.end());\n    return p;\n  }\n\n  vector<Line> tangent(Circle c1,Circle c2){\n    vector<Line> ls;\n    if(c1.r<c2.r) swap(c1,c2);\n    double g=norm(c1.c-c2.c);\n    if(equals(g,0)) return ls;\n    Point u=(c2.c-c1.c)/sqrt(g);\n    Point v=orth(u);\n    for(int s=1;s>=-1;s-=2){\n      double h=(c1.r+s*c2.r)/sqrt(g);\n      if(equals(1-h*h,0)){\n        ls.emplace_back(c1.c+u*c1.r,c1.c+(u+v)*c1.r);\n      }else if(1-h*h>0){\n        Point uu=u*h,vv=v*sqrt(1-h*h);\n        ls.emplace_back(c1.c+(uu+vv)*c1.r,c2.c-(uu+vv)*c2.r*s);\n        ls.emplace_back(c1.c+(uu-vv)*c1.r,c2.c-(uu-vv)*c2.r*s);\n      }\n    }\n\n    return ls;\n  }\n\n  double closest_pair(Polygon &a,int l=0,int r=-1){\n    if(r<0){\n      r=a.size();\n      sort(a.begin(),a.end(),sort_x);\n    }\n    if(r-l<=1) return abs(a[0]-a[1]);\n    int m=(l+r)>>1;\n    double x=a[m].x;\n    double d=min(closest_pair(a,l,m),closest_pair(a,m,r));\n    inplace_merge(a.begin()+l,a.begin()+m,a.begin()+r,sort_y);\n\n    Polygon b;\n    for(int i=l;i<r;i++){\n      if(fabs(a[i].x-x)>=d) continue;\n      for(int j=0;j<(int)b.size();j++){\n        double dy=a[i].y-next(b.rbegin(),j)->y;\n        if(dy>=d) break;\n        d=min(d,abs(a[i]-*next(b.rbegin(),j)));\n      }\n      b.emplace_back(a[i]);\n    }\n    return d;\n  }\n\n  vector<vector<int>>\n  segmentArrangement(vector<Segment> &ss, Polygon &ps){\n    int n=ss.size();\n    for(int i=0;i<n;i++){\n      ps.emplace_back(ss[i].p1);\n      ps.emplace_back(ss[i].p2);\n      for(int j=i+1;j<n;j++)\n        if(intersectSS(ss[i],ss[j]))\n          ps.emplace_back(getCrossPointSS(ss[i],ss[j]));\n    }\n    sort(ps.begin(),ps.end());\n    ps.erase(unique(ps.begin(),ps.end()),ps.end());\n\n    vector<vector<int> > G(ps.size());\n    for(int i=0;i<n;i++){\n      vector<pair<double,int> > ls;\n      for(int j=0;j<(int)ps.size();j++)\n        if(getDistanceSP(ss[i],ps[j])<EPS)\n          ls.emplace_back(make_pair(norm(ss[i].p1-ps[j]),j));\n\n      sort(ls.begin(),ls.end());\n      for(int j=0;j+1<(int)ls.size();j++){\n        int a=ls[j].second,b=ls[j+1].second;\n        G[a].emplace_back(b);\n        G[b].emplace_back(a);\n      }\n    }\n    for(auto &v:G){\n      sort(v.begin(),v.end());\n      v.erase(unique(v.begin(),v.end()),v.end());\n    }\n    return G;\n  }\n\n  struct EndPoint{\n    Point p;\n    int seg,st;\n    EndPoint(){}\n    EndPoint(Point p,int seg,int st):p(p),seg(seg),st(st){}\n    bool operator<(const EndPoint &ep)const{\n      if(p.y==ep.p.y) return st<ep.st;\n      return p.y<ep.p.y;\n    }\n  };\n\n  int manhattan_intersection(vector<Segment> ss,const int INF){\n    const int BTM = 0;\n    const int LFT = 1;\n    const int RGH = 2;\n    const int TOP = 3;\n\n    int n=ss.size();\n    vector<EndPoint> ep;\n    for(int i=0;i<n;i++){\n      if(ss[i].p1.y==ss[i].p2.y){\n        if(ss[i].p1.x>ss[i].p2.x) swap(ss[i].p1,ss[i].p2);\n        ep.emplace_back(ss[i].p1,i,LFT);\n        ep.emplace_back(ss[i].p2,i,RGH);\n      }else{\n        if(ss[i].p1.y>ss[i].p2.y) swap(ss[i].p1,ss[i].p2);\n        ep.emplace_back(ss[i].p1,i,BTM);\n        ep.emplace_back(ss[i].p2,i,TOP);\n      }\n    }\n    sort(ep.begin(),ep.end());\n\n    set<int> bt;\n    bt.insert(INF);\n\n    int cnt=0;\n    for(int i=0;i<n*2;i++){\n      if(ep[i].st==TOP){\n        bt.erase(ep[i].p.x);\n      }else if(ep[i].st==BTM){\n        bt.emplace(ep[i].p.x);\n      }else if(ep[i].st==LFT){\n        auto b=bt.lower_bound(ss[ep[i].seg].p1.x);\n        auto e=bt.upper_bound(ss[ep[i].seg].p2.x);\n        cnt+=distance(b,e);\n      }\n    }\n\n    return cnt;\n  }\n\n  double area(Polygon ps,Circle c){\n    if(ps.size()<3u) return 0;\n    function<double(Circle, Point, Point)> dfs=\n      [&](Circle c,Point a,Point b){\n        Vector va=c.c-a,vb=c.c-b;\n        double f=cross(va,vb),res=0;\n        if(equals(f,0.0)) return res;\n        if(max(abs(va),abs(vb))<c.r+EPS) return f;\n        Vector d(dot(va,vb),cross(va,vb));\n        if(getDistanceSP(Segment(a,b),c.c)>c.r-EPS)\n          return c.r*c.r*atan2(d.y,d.x);\n        auto u=getCrossPointCS(c,Segment(a,b));\n        if(u.empty()) return res;\n        if(u.size()>1u and dot(u[1]-u[0],a-u[0])>0) swap(u[0],u[1]);\n        u.emplace(u.begin(),a);\n        u.emplace_back(b);\n        for(int i=1;i<(int)u.size();i++)\n          res+=dfs(c,u[i-1],u[i]);\n        return res;\n      };\n    double res=0;\n    for(int i=0;i<(int)ps.size();i++)\n      res+=dfs(c,ps[i],ps[(i+1)%ps.size()]);\n    return res/2;\n  }\n}\nusing namespace geometry;\n\nnamespace geometry{\n  istream &operator>>(istream &is,Point &p){\n    is>>p.x>>p.y;\n    return is;\n  }\n  istream &operator>>(istream &is,Polygon &p){\n    for(int i=0;i<(int)p.size();i++) is>>p[i];\n    return is;\n  }\n  istream &operator>>(istream &is,Segment &s){\n    is>>s.p1>>s.p2;\n    return is;\n  }\n  istream &operator>>(istream &is,Circle &c){\n    is>>c.c>>c.r;\n    return is;\n  }\n  ostream &operator<<(ostream &os,Point p){\n    os<<fixed<<setprecision(12)<<p.x<<\" \"<<p.y;\n    return os;\n  }\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "geometry/projectilemotion.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// throw from origin to (x,y) with verocity v (x>0)\n// g: gravity\ntemplate<typename D>\nvector< pair<D, D> > projectile_motion(D v,D g,D x,D y){\n  D a=x*x+y*y;\n  D b=g*x*x*y-v*v*x*x;\n  D c=g*g*x*x*x*x/4;\n  if(b*b<4*a*c) return {};\n  vector< pair<D, D> > res;\n  {\n    D p=(-b+sqrt(b*b-4*a*c))/(2*a);\n    if(0<p and p<v*v) res.emplace_back(sqrt(p),sqrt(v*v-p));\n  }\n  {\n    D p=(-b-sqrt(b*b-4*a*c))/(2*a);\n    if(0<p and p<v*v) res.emplace_back(sqrt(p),sqrt(v*v-p));\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/arborescence_edmond.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"stronglyconnectedcomponent.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct Arborescence{\n  struct edge{\n    int to;\n    T cost;\n    edge(int to,T cost):to(to),cost(cost){}\n  };\n  vector<vector<edge>> B;\n\n  Arborescence(int n):B(n){}\n\n  void add_edge(int u,int v,T cost){\n    assert(u!=v);\n    B[u].emplace_back(v,cost);\n  }\n\n  T build(int r){\n    T res=0;\n    auto G=B;\n    const T INF = numeric_limits<T>::max()/2;\n    while(1){\n      int n=G.size();\n      vector<T> ws(n,INF);\n      vector<int> rs(n,-1);\n      for(int v=0;v<n;v++){\n        for(edge &e:G[v]){\n          if(e.cost<ws[e.to]){\n            ws[e.to]=e.cost;\n            rs[e.to]=v;\n          }\n        }\n      }\n      SCC scc(n);\n      for(int i=0;i<n;i++){\n        if(i==r) continue;\n        scc.add_edge(rs[i],i);\n        res+=ws[i];\n      }\n      int m=scc.build();\n      if(m==n) break;\n      vector<vector<edge>> H(m);\n      for(int v=0;v<n;v++){\n        for(auto &e:G[v]){\n          if(scc[v]==scc[e.to]) continue;\n          H[scc[v]].emplace_back(scc[e.to],e.cost-ws[e.to]);\n        }\n      }\n      r=scc[r];\n      G=H;\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/arborescence_tarjan.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct Arborescence{\n  struct SkewHeap{\n    using P = pair<T, int>;\n    const P INF;\n    const T add_identity;\n    SkewHeap(T inf):INF(inf,-1),add_identity(0){}\n\n    struct Node{\n      Node *l,*r;\n      P val;\n      T add;\n      Node(P val,T add):val(val),add(add){l=r=nullptr;}\n    };\n\n    P reflect(P x,T y){return P(x.first+y,x.second);}\n\n    void eval(Node *a){\n      if(a==nullptr) return;\n      if(a->add==add_identity) return;\n      if(a->l) a->l->add+=a->add;\n      if(a->r) a->r->add+=a->add;\n      a->val=reflect(a->val,a->add);\n      a->add=add_identity;\n    }\n\n    P top(Node *a){\n      return a?reflect(a->val,a->add):INF;\n    }\n\n    P snd(Node *a){\n      eval(a);\n      return a?min(top(a->l),top(a->r)):INF;\n    }\n\n    Node* add(Node *a,T d){\n      if(a) a->add+=d;\n      return a;\n    }\n\n    Node* push(T v,int i){\n      return new Node(P(v,i),add_identity);\n    }\n\n    Node* meld(Node *a,Node *b){\n      if(!a or !b) return a?a:b;\n      if(top(b)<top(a)) swap(a,b);\n      eval(a);\n      a->r=meld(a->r,b);\n      swap(a->l,a->r);\n      return a;\n    }\n\n    Node* pop(Node* a){\n      eval(a);\n      auto res=meld(a->l,a->r);\n      delete a;\n      return res;\n    }\n  };\n\n  struct UnionFind{\n    vector<int> r,p;\n    UnionFind(int sz):r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}\n    int find(int x){\n      return (x==p[x]?x:p[x]=find(p[x]));\n    }\n    bool same(int x,int y){\n      return find(x)==find(y);\n    }\n    void unite(int x,int y){\n      x=find(x);y=find(y);\n      if(x==y) return;\n      r[x]+=r[y];\n      p[y]=x;\n    }\n  };\n\n  struct edge{\n    int from,to;\n    T cost;\n    edge(int from,int to,T cost):from(from),to(to),cost(cost){}\n  };\n\n  int n;\n  vector<edge> es;\n\n  Arborescence(int n):n(n){};\n\n  void add_edge(int from,int to,T cost){\n    es.emplace_back(from,to,cost);\n  }\n\n  T build(int r){\n    UnionFind uf(n);\n    const T INF = numeric_limits<T>::max()/2;\n    SkewHeap hp(INF);\n    vector<typename SkewHeap::Node*> come(n,nullptr);\n    vector<int> used(n,0),from(n,-1);\n    vector<T> cost(n,-1);\n\n    used[r]=2;\n    for(int i=0;i<(int)es.size();i++){\n      edge &e=es[i];\n      come[e.to]=hp.meld(come[e.to],hp.push(e.cost,i));\n    }\n\n    T res=0;\n    for(int i=0;i<n;i++){\n      if(used[i]) continue;\n      int v=i;\n      vector<int> l;\n      while(used[v]!=2){\n        used[v]=1;\n        l.emplace_back(v);\n        if(!come[v]) return T(-1);\n        from[v]=uf.find(es[come[v]->val.second].from);\n        cost[v]=hp.top(come[v]).first;\n        come[v]=hp.pop(come[v]);\n        if(from[v]==v) continue;\n\n        res+=cost[v];\n        if(used[from[v]]==1){\n          int p=v;\n          do{\n            if(come[p]!=nullptr) hp.add(come[p],-cost[p]);\n            if(p!=v){\n              uf.unite(v,p);\n              come[v]=hp.meld(come[v],come[p]);\n            }\n            p=uf.find(from[p]);\n          }while(p!=v);\n        }else{\n          v=from[v];\n        }\n      }\n      for(int u:l) used[u]=2;\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned UVA_11183(){\n  using ll = long long;\n  int T;\n  cin>>T;\n  for(int t=1;t<=T;t++){\n    int n,m;\n    cin>>n>>m;\n    Arborescence<ll> G(n);\n    for(int i=0;i<m;i++){\n      int s,t,w;\n      cin>>s>>t>>w;\n      G.add_edge(s,t,w);\n    }\n    ll ans=G.build(0);\n    cout<<\"Case #\"<<t<<\": \";\n    if(ans<0) cout<<\"Possums!\"<<endl;\n    else cout<<ans<<endl;\n  }\n  return 0;\n}\n/*\n  verified on 2019/12/17\n  https://vjudge.net/problem/UVA-11183\n*/\n\n\nsigned main(){\n  //UVA_11183();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/bellmanford.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct BellmanFord{\n  struct edge{\n    int u,v;\n    T w;\n    edge(int u,int v,T w):u(u),v(v),w(w){}\n  };\n\n  vector< vector<int> > G;\n  vector<int> used,reach;\n  BellmanFord(int n):G(n),used(n,0),reach(n,1){}\n\n  vector<edge> es;\n  void add_edge(int u,int v,T c){\n    es.emplace_back(u,v,c);\n    G[u].emplace_back(v);\n  }\n\n  vector<T> build(int from,int &neg_loop){\n    const T INF = numeric_limits<T>::max();\n    int n=G.size();\n    vector<T> ds(n,INF);\n    ds[from]=0;\n    for(int j=0;j<n;j++){\n      bool update=0;\n      for(auto e:es){\n        if(!reach[e.u] or !reach[e.v] or ds[e.u]==INF) continue;\n        if(ds[e.v]>ds[e.u]+e.w){\n          ds[e.v]=ds[e.u]+e.w;\n          update=1;\n        }\n      }\n      if(!update) break;\n      if(j==n-1){\n        neg_loop=1;\n        return ds;\n      }\n    }\n    neg_loop=0;\n    return ds;\n  }\n\n  void dfs(int v){\n    if(used[v]) return;\n    used[v]=1;\n    for(int u:G[v]) dfs(u);\n  }\n\n  T shortest_path(int from,int to,int &neg_loop){\n    int n=G.size();\n    for(int i=0;i<n;i++){\n      fill(used.begin(),used.end(),0);\n      dfs(i);\n      reach[i]=used[to];\n    }\n    return build(from,neg_loop)[to];\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/bfs.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nvector<int> bfs(int s,vector< vector<int> > G){\n  int n=G.size();\n  vector<int> dp(n,-1);\n  queue<int> que;\n  dp[s]=0;\n  que.emplace(s);\n  while(!que.empty()){\n    int v=que.front();que.pop();\n    for(int u:G[v]){\n      if(~dp[u]) continue;\n      dp[u]=dp[v]+1;\n      que.emplace(u);\n    }\n  }\n  return dp;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/bipartitedecomposition.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(n)\nstruct BipartiteDecomposition{\n  vector<vector<int>> G;\n  BipartiteDecomposition(int n):G(n){}\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n  vector<pair<int, int>> build(){\n    vector<pair<int, int>> res;\n    vector<int> used(G.size(),-1);\n    for(int i=0;i<(int)G.size();i++){\n      if(~used[i]) continue;\n      queue<int> que;\n      used[i]=0;\n      que.emplace(i);\n      pair<int, int> cnt;\n      while(!que.empty()){\n        int v=que.front();que.pop();\n        if(used[v]==0) cnt.first++;\n        else cnt.second++;\n        for(int u:G[v]){\n          if(~used[u]){\n            if(used[u]==used[v]) return {};\n            continue;\n          }\n          used[u]=used[v]^1;\n          que.emplace(u);\n        }\n      }\n      res.emplace_back(cnt);\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nint main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/chromatic.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nint chromatic(vector< vector<int> > G){\n  int n=G.size();\n  if(n==0) return 0;\n  assert(n<=30);\n\n  vector<int> es(n,0);\n  for(int i=0;i<n;i++)\n    for(int j=0;j<n;j++)\n      es[i]|=G[i][j]<<j;\n\n  int s=1<<n;\n  vector<int> dp(s);\n  for(int b=0;b<s;b++)\n    dp[b]=((n-__builtin_popcount(b))&1?-1:1);\n\n  auto calc=\n    [&](const int MOD){\n      vector<int> res(s);\n      res[0]=1;\n      for(int b=1;b<s;b++){\n        int ctz=__builtin_ctz(b);\n        res[b]=res[b-(1<<ctz)]+res[(b-(1<<ctz))&~es[ctz]];\n        if(res[b]>=MOD) res[b]-=MOD;\n      }\n      return res;\n    };\n\n  constexpr int MOD1 = 1077563119;\n  constexpr int MOD2 = 1e9+7;\n  vector<int> ind1=calc(MOD1);\n  vector<int> ind2=calc(MOD2);\n\n  using ll = long long;\n  vector<int> dp1=dp,dp2=dp;\n  for(int i=1;i<n;i++){\n    ll sum1=0,sum2=0;\n    for(int b=0;b<s;b++){\n      dp1[b]=((ll)dp1[b]*ind1[b])%MOD1;\n      sum1+=dp1[b];\n\n      dp2[b]=((ll)dp2[b]*ind2[b])%MOD2;\n      sum2+=dp2[b];\n    }\n    if(sum1%MOD1!=0) return i;\n    if(sum2%MOD2!=0) return i;\n  }\n  return n;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\n#endif\n"
  },
  {
    "path": "graph/cycle.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<bool directed>\nstruct Cycle{\n  vector<int> used;\n  vector<vector<int>> G;\n  Cycle(int n_):used(n_,0),G(n_){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    if(not directed) G[v].emplace_back(u);\n  }\n\n  vector<int> vs;\n  int dfs(int v,int p){\n    used[v]=1;\n    vs.emplace_back(v);\n    for(int u:G[v]){\n      if((not directed) and u==p) continue;\n      if(used[u]==2) continue;\n      if(used[u]==1) return u;\n      int res=dfs(u,v);\n      if(~res) return res;\n    }\n    used[v]=2;\n    vs.pop_back();\n    return -1;\n  }\n\n  vector<int> build(){\n    for(int i=0;i<(int)G.size();i++){\n      if(used[i]) continue;\n      int start=dfs(i,-1);\n      if(start<0) continue;\n      vs.erase(vs.begin(),find(vs.begin(),vs.end(),start));\n      return vs;\n    }\n    return {};\n  }\n};\nusing DirectedCycle = Cycle<true>;\nusing UndirectedCycle = Cycle<false>;\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/dijkstra.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct Dijkstra{\n  struct Edge{\n    int to;\n    T cost;\n    Edge(int to,T cost):to(to),cost(cost){}\n    bool operator<(const Edge &o)const{return cost>o.cost;}\n  };\n\n  vector< vector<Edge> > G;\n  vector<T> ds;\n  vector<int> bs;\n  Dijkstra(int n):G(n){}\n\n  void add_edge(int u,int v,T c){\n    G[u].emplace_back(v,c);\n  }\n\n  void build(int s){\n    int n=G.size();\n    ds.assign(n,numeric_limits<T>::max());\n    bs.assign(n,-1);\n\n    priority_queue<Edge> pq;\n    ds[s]=0;\n    pq.emplace(s,ds[s]);\n\n    while(!pq.empty()){\n      auto p=pq.top();pq.pop();\n      int v=p.to;\n      if(ds[v]<p.cost) continue;\n      for(auto e:G[v]){\n        if(ds[e.to]>ds[v]+e.cost){\n          ds[e.to]=ds[v]+e.cost;\n          bs[e.to]=v;\n          pq.emplace(e.to,ds[e.to]);\n        }\n      }\n    }\n  }\n\n  T operator[](int k){return ds[k];}\n\n  vector<int> restore(int to){\n    vector<int> res;\n    if(bs[to]<0) return res;\n    while(~to) res.emplace_back(to),to=bs[to];\n    reverse(res.begin(),res.end());\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/dominatortree.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct DominatorTree{\n  struct UnionFind{\n    vector<int> &semi;\n    vector<int> ps,ms;\n    UnionFind(vector<int> &semi):\n      semi(semi),ps(semi.size()),ms(semi.size()){\n      iota(ps.begin(),ps.end(),0);\n      iota(ms.begin(),ms.end(),0);\n    }\n    int find(int v){\n      if(ps[v]==v) return v;\n      int r=find(ps[v]);\n      if(semi[ms[v]]>semi[ms[ps[v]]]) ms[v]=ms[ps[v]];\n      return ps[v]=r;\n    }\n    int eval(int v){\n      find(v);\n      return ms[v];\n    }\n    void link(int p,int v){ps[v]=p;}\n  };\n\n  vector< vector<int> > G,R;\n  vector<int> ord,par,idom,semi;\n  DominatorTree(int n):\n    G(n),R(n),par(n),idom(n,-1),semi(n,-1){\n    ord.reserve(n);\n  }\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    R[v].emplace_back(u);\n  }\n\n  void dfs(int v){\n    semi[v]=ord.size();\n    ord.emplace_back(v);\n    for(int u:G[v]){\n      if(~semi[u]) continue;\n      par[u]=v;\n      dfs(u);\n    }\n  }\n\n  void build(int rt){\n    int n=G.size();\n    dfs(rt);\n\n    vector< vector<int> > bkt(n);\n    UnionFind uf(semi);\n    vector<int> us(n);\n\n    for(int i=(int)ord.size()-1;i>=0;i--){\n      int v=ord[i];\n      for(int u:R[v]){\n        if(semi[u]<0) continue;\n        u=uf.eval(u);\n        if(semi[v]>semi[u]) semi[v]=semi[u];\n      }\n      bkt[ord[semi[v]]].emplace_back(v);\n      for(int u:bkt[par[v]]) us[u]=uf.eval(u);\n      bkt[par[v]].clear();\n      uf.link(par[v],v);\n    }\n\n    for(int i=1;i<(int)ord.size();i++){\n      int v=ord[i],u=us[v];\n      idom[v]=(semi[v]==semi[u]?semi[v]:idom[u]);\n    }\n\n    for(int i=1;i<(int)ord.size();i++){\n      int v=ord[i];\n      idom[v]=ord[idom[v]];\n    }\n\n    idom[rt]=rt;\n  }\n\n  int operator[](int k){return idom[k];}\n};\n//END CUT HERE\n#ifndef call_from_test\nint main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/dynamicconnectivity.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct PersistentUnionFind{\n  using T = pair<int, int>;\n  vector<int> rs,ps;\n  stack<T> st;\n  PersistentUnionFind(int n):\n    rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);}\n  int find(int x){\n    return x==ps[x]?ps[x]:find(ps[x]);\n  }\n  bool same(int x,int y){\n    return find(x)==find(y);\n  }\n  void unite(int x,int y){\n    x=find(x);y=find(y);\n    st.emplace(-1,-1);\n    if(x==y) return;\n    if(rs[x]<rs[y]) swap(x,y);\n    rs[x]+=rs[y];\n    ps[y]=x;\n    st.top()=T(x,y);\n  }\n  void undo(int t=1){\n    for(int i=0;i<t;i++){\n      int x,y;\n      tie(x,y)=st.top();st.pop();\n      if(x<0) continue;\n      rs[x]-=rs[y];\n      ps[y]=y;\n    }\n  }\n};\n\nstruct DynamicConnectivity{\n  using edge = pair<int, int>;\n  using range = pair<int, int>;\n\n  int q;\n  PersistentUnionFind puf;\n  vector< vector<edge> > edges;\n  vector <pair<range, edge> > prc;\n  map<edge, int> cnt,app;\n\n  DynamicConnectivity(int n,int q_):q(1),puf(n){\n    while(q<q_) q<<=1;\n    edges.resize(q*2);\n  }\n\n  void insert(int t,int u,int v){\n    edge e=minmax(u,v);\n    if(cnt[e]++==0) app[e]=t;\n  }\n\n  void erase(int t,int u,int v){\n    edge e=minmax(u,v);\n    if(--cnt[e]==0) prc.emplace_back(range(app[e],t),e);\n  }\n\n  void add(int a,int b,edge e,int k,int l,int r){\n    if(r<=a or b<=l) return;\n    if(a<=l and r<=b){\n      edges[k].emplace_back(e);\n      return;\n    }\n    int m=(l+r)>>1;\n    add(a,b,e,(k<<1)|0,l,m);\n    add(a,b,e,(k<<1)|1,m,r);\n  }\n\n  void add(range r,edge e){\n    add(r.first,r.second,e,1,0,q);\n  }\n\n  void build(){\n    for(auto &e:cnt){\n      if(!e.second) continue;\n      prc.emplace_back(range(app[e.first],q),e.first);\n    }\n    for(auto &s:prc)\n      add(s.first,s.second);\n  }\n\n  template<typename F>\n  void exec(const F &f,int k=1){\n    for(auto &e:edges[k])\n      puf.unite(e.first,e.second);\n\n    if(k<q){\n      exec(f,(k<<1)|0);\n      exec(f,(k<<1)|1);\n    }else{\n      f(k-q);\n    }\n\n    puf.undo(edges[k].size());\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/girth.cpp",
    "content": "#include <bits/stdc++.h>\nusing namespace std;\n//BEGIN CUT HERE\n// size of minimum cycle in undirected graph\nint girth(vector< vector<int> > G){\n  int n=G.size();\n  int res=n+1;\n  vector<int> dp(n),pr(n);\n  for(int s=0;s<n;s++){\n    fill(dp.begin(),dp.end(),-1);\n    fill(pr.begin(),pr.end(),-1);\n    queue<int> que;\n    dp[s]=0;\n    que.emplace(s);\n    while(!que.empty()){\n      int v=que.front();que.pop();\n      if(res<=dp[v]*2) break;\n      for(int u:G[v]){\n        if(u==pr[v]) continue;\n        if(~dp[u]){\n          res=min(res,dp[u]+dp[v]+1);\n          continue;\n        }\n        dp[u]=dp[v]+1;\n        pr[u]=v;\n        que.emplace(u);\n      }\n    }\n  }\n  if(res>n) res=-1;\n  return res;\n}\n//END CUT HERE\n//INSERT ABOVE HERE\n\nsigned CFR580_B(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n;\n  cin>>n;\n  vector<ll> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n  sort(as.rbegin(),as.rend());\n\n  if(as[0]==0){\n    cout<<-1<<endl;\n    return 0;\n  }\n\n  while(as.back()==0) as.pop_back();\n  n=as.size();\n\n  if(n>=200){\n    cout<<3<<endl;\n    return 0;\n  }\n\n  vector< vector<int> > G(n);\n  for(int i=0;i<n;i++)\n    for(int j=0;j<n;j++)\n      if((i!=j) and (as[i]&as[j]))\n        G[i].emplace_back(j);\n\n  cout<<girth(G)<<endl;\n  return 0;\n}\n/*\n  verified on 2019/08/21\n  https://codeforces.com/contest/1205/problem/B\n*/\n\nsigned main(){\n  CFR580_B();\n  return 0;\n}\n"
  },
  {
    "path": "graph/grid.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename F>\nstruct Grid{\n  const int h,w;\n  const F f;\n  Grid(int h_,int w_,F f_):h(h_),w(w_),f(f_){}\n  int idx(int y,int x){return y*w+x;}\n  using T = typename invoke_result<F, int, int>::type;\n  T operator[](int k){return f(k/w,k%w);}\n  decltype(auto) edges(){\n    vector<pair<int, int>> es;\n    for(int i=0;i<h;i++){\n      for(int j=0;j<w;j++){\n        if(i+1<h) es.emplace_back(idx(i,j),idx(i+1,j));\n        if(j+1<w) es.emplace_back(idx(i,j),idx(i,j+1));\n      }\n    }\n    return es;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/independentset.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct IndependentSet{\n  int n;\n  vector<int> deg,used,dead,pre,ans;\n  vector<vector<int> > G;\n\n  IndependentSet(int n):\n    n(n),deg(n),used(n,0),dead(n,0),G(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  int res,cnt,alive;\n  void dfs(){\n    if(cnt+alive<=res) return;\n\n    int v=-1;\n    for(int i=0;i<n;i++){\n      if(used[i] or dead[i]) continue;\n      if(deg[i]<=1){\n        v=i;\n        break;\n      }\n      if(v<0 or deg[v]<deg[i]) v=i;\n    }\n    if(v<0) return;\n\n    if(deg[v]!=1){\n      dead[v]=1;\n      alive--;\n      for(int u:G[v]) deg[u]--;\n\n      dfs();\n\n      dead[v]=0;\n      alive++;\n      for(int u:G[v]) deg[u]++;\n    }\n    {\n      used[v]=1;\n      alive--;\n      for(int u:G[v])\n        if(0==dead[u]++) alive-=!used[u];\n      cnt++;\n      if(res<cnt) pre=used;\n      res=max(res,cnt);\n\n      dfs();\n\n      used[v]=0;\n      alive++;\n      for(int u:G[v])\n        if(--dead[u]==0) alive+=!used[u];\n      cnt--;\n    }\n  }\n\n  int build(){\n    for(int i=0;i<n;i++) deg[i]=G[i].size();\n    res=0,cnt=0,alive=n;\n    dfs();\n    for(int i=0;i<n;i++)\n      if(pre[i]) ans.emplace_back(i);\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/kruskal.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../datastructure/unionfind.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct Kruskal : UnionFind{\n  using UnionFind::UnionFind;\n  struct Edge{\n    int src,dst;\n    T cost;\n    int used;\n    Edge(int src,int dst,T cost):\n      src(src),dst(dst),cost(cost),used(0){}\n    bool operator<(const Edge& o) const{\n      return cost<o.cost;\n    }\n  };\n\n  vector<Edge> es;\n  void add_edge(int u,int v,T c){\n    es.emplace_back(u,v,c);\n  }\n\n  T build(){\n    sort(es.begin(),es.end());\n    T res=0;\n    for(auto &e:es){\n      if(same(e.src,e.dst)) continue;\n      res+=e.cost;\n      unite(e.src,e.dst);\n      e.used=1;\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nint main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/lowlink.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct LowLink{\n  int n,pos;\n  vector<int> ord,low,par,blg,num;\n  vector<vector<int> > G,C,T;\n  vector<vector<pair<int, int> > > E;\n\n  vector<int> ap;\n  vector<pair<int, int> > bs,cand;\n\n  LowLink(int n):n(n),pos(0),ord(n,-1),low(n),\n                 par(n,-1),blg(n,-1),num(n,1),G(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  bool is_bridge(int u,int v){\n    if(ord[u]>ord[v]) swap(u,v);\n    return ord[u]<low[v];\n  }\n\n  void dfs(int v){\n    ord[v]=low[v]=pos++;\n    int dup=0;\n    for(int u:G[v]){\n      if(u==par[v]){\n        if(dup) low[v]=min(low[v],ord[u]);\n        dup=1;\n        continue;\n      }\n      if(ord[u]<ord[v])\n        cand.emplace_back(min(u,v),max(u,v));\n      if(~ord[u]){\n        low[v]=min(low[v],ord[u]);\n        continue;\n      }\n      par[u]=v;\n      dfs(u);\n      num[v]+=num[u];\n      low[v]=min(low[v],low[u]);\n      if(is_bridge(u,v)) bs.emplace_back(u,v);\n      if(low[u]>=ord[v]){\n        E.emplace_back();\n        while(1){\n          auto e=cand.back();\n          cand.pop_back();\n          E.back().emplace_back(e);\n          if(make_pair(min(u,v),max(u,v))==e) break;\n        }\n      }\n    }\n  }\n\n  void fill_component(int v){\n    C[blg[v]].emplace_back(v);\n    for(int u:G[v]){\n      if(~blg[u] or is_bridge(u,v)) continue;\n      blg[u]=blg[v];\n      fill_component(u);\n    }\n  }\n\n  void add_component(int v,int &k){\n    if(~blg[v]) return;\n    blg[v]=k++;\n    C.emplace_back();\n    fill_component(v);\n  }\n\n  int build(){\n    for(int i=0;i<n;i++)\n      if(ord[i]<0) dfs(i);\n\n    vector<int> cnt(n,0);\n    for(int i=0;i<n;i++){\n      int p=par[i];\n      if(p<0) continue;\n      if(par[p]<0) cnt[p]++;\n      else if(ord[p]<=low[i]) ap.emplace_back(p);\n    }\n\n    for(int i=0;i<n;i++)\n      if(cnt[i]>1) ap.emplace_back(i);\n\n    sort(ap.begin(),ap.end());\n    ap.erase(unique(ap.begin(),ap.end()),ap.end());\n\n    int k=0;\n    for(int i=0;i<n;i++) add_component(i,k);\n\n    T.assign(k,vector<int>());\n    for(auto e:bs){\n      int u=blg[e.first],v=blg[e.second];\n      T[u].emplace_back(v);\n      T[v].emplace_back(u);\n    }\n    return k;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"../datastructure/unionfind.cpp\"\n#include \"../mod/mint.cpp\"\n#include \"../combinatorics/enumeration.cpp\"\n#undef call_from_test\n\n\n//INSERT ABOVE HERE\n// test num\nsigned ARC045_D(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<int> xs(2*n+1),ys(2*n+1);\n  for(int i=0;i<2*n+1;i++) cin>>xs[i]>>ys[i];\n\n  vector<vector<int> > R(2*n+2),C(2*n+2);\n  for(int i=0;i<2*n+1;i++) R[xs[i]].emplace_back(i);\n  for(int i=0;i<2*n+1;i++) C[ys[i]].emplace_back(i);\n\n  UnionFind uf(2*n+1);\n  for(auto &v:R)\n    for(auto u:v) uf.unite(v[0],u);\n  for(auto &v:C)\n    for(auto u:v) uf.unite(v[0],u);\n\n  vector<int> vs;\n  for(int i=0;i<2*n+1;i++){\n    if(uf.find(i)!=i) continue;\n    if(uf.size(i)&1) vs.emplace_back(i);\n  }\n  assert(!vs.empty());\n\n  if(vs.size()>1u){\n    for(int i=0;i<2*n+1;i++) cout<<\"NG\\n\";\n    cout<<flush;\n    return 0;\n  }\n\n  LowLink G(2*n+1);\n  auto add_edge=\n    [&](auto &V)->void{\n      for(auto &v:V){\n        if(v.empty()) continue;\n        if(!uf.same(vs[0],v[0])) continue;\n        if(v.size()>0u) for(auto u:v) G.add_edge(v[0],u);\n        if(v.size()>1u) for(auto u:v) G.add_edge(v[1],u);\n      }\n    };\n  add_edge(R);\n  add_edge(C);\n\n  G.build();\n  auto ap=G.ap;\n\n  vector<int> ans(2*n+1,0);\n  for(int i=0;i<2*n+1;i++)\n    if(uf.same(vs[0],i)) ans[i]=1;\n\n  for(int v:ap){\n    if(!uf.same(vs[0],v)) continue;\n    for(int u:G.G[v]){\n      if(G.par[u]!=v) continue;\n      if(~G.par[v] and G.ord[v]>G.low[u]) continue;\n      if(G.num[u]&1) ans[v]=0;\n    }\n  }\n\n  for(int i=0;i<2*n+1;i++) cout<<(ans[i]?\"OK\\n\":\"NG\\n\");\n  cout<<flush;\n  return 0;\n}\n/*\n  verified on 2019/10/25\n  https://atcoder.jp/contests/arc045/tasks/arc045_d\n*/\n\n\nsigned ARC062_F(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,k;\n  cin>>n>>m>>k;\n\n  using P = pair<int, int>;\n  map<P, int> idx;\n\n  LowLink G(n);\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    G.add_edge(a,b);\n    idx[P(a,b)]=idx[P(b,a)]=i;\n  }\n\n  G.build();\n\n  UnionFind uf(m);\n  for(auto vs:G.E)\n    for(auto p:vs) uf.unite(idx[p],idx[vs[0]]);\n\n  vector<set<int>> cnt(m);\n  for(auto vs:G.E){\n    for(auto p:vs){\n      cnt[uf.find(idx[p])].emplace(p.first);\n      cnt[uf.find(idx[p])].emplace(p.second);\n    }\n  }\n\n  using M = Mint<int>;\n  using E = Enumeration<M>;\n  E::init(1000);\n\n  auto calc1=\n    [&](int x)->M{\n      M res{0};\n\n      for(int i=0;i<x;i++)\n        res+=M(k).pow(__gcd(i,x));\n\n      res*=E::Invs(x);\n      return res;\n    };\n\n  M ans{1};\n  for(int i=0;i<m;i++){\n    if(uf.find(i)!=i) continue;\n    if(uf.size(i)< (int)cnt[i].size()) ans*=M(k).pow(uf.size(i));\n    if(uf.size(i)==(int)cnt[i].size()) ans*=calc1(uf.size(i));\n    if(uf.size(i)> (int)cnt[i].size()) ans*=E::H(uf.size(i),k);\n  }\n  cout<<ans.v<<endl;\n  return 0;\n}\n/*\n  verified on 2020/02/19\n  https://atcoder.jp/contests/arc062/tasks/arc062_d\n*/\n\n\nsigned main(){\n  //ARC045_D();\n  //ARC062_F();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/manhattanmst.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nvector<pair<int, int>> manhattanmst(vector<T> xs,vector<T> ys){\n  using P = pair<int, int>;\n  vector<P> es;\n  int n=xs.size();\n\n  // xs[i] <- xs[i] + \\eps^i, ys[i] <- ys[i] + \\eps^(n+i),\n  for(int s=0;s<2;s++){\n    for(int t=0;t<2;t++){\n      vector<int> ord(n);\n      iota(ord.begin(),ord.end(),0);\n      auto cmp=[&](int i,int j)->bool{\n        if(xs[i]+ys[i]!=xs[j]+ys[j]) return xs[i]+ys[i]<xs[j]+ys[j];\n        return s^(i>j);\n      };\n      sort(ord.begin(),ord.end(),cmp);\n\n      map<pair<T, int>, int> idx;\n      for(int i:ord){\n        for(auto it=idx.lower_bound({-ys[i],(s&t)?+i:-i});\n            it!=idx.end();it=idx.erase(it)){\n          int j=it->second;\n          if(xs[i]-xs[j]<ys[i]-ys[j]) break;\n          es.emplace_back(i,j);\n        }\n        idx[{-ys[i],(s&t)?+i:-i}]=i;\n      }\n      swap(xs,ys);\n    }\n    for(int i=0;i<n;i++) xs[i]*=-1;\n  }\n  return es;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/multipleeuleriantrail.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// no muliple edge\ntemplate<typename Graph>\nbool hasMultipleEulerianTrail(Graph &G){\n  int n=G.size();\n  vector<int> ind(n,0),outd(n,0),pre(n,-1),loop(n,0);\n  for(int v=0;v<n;v++){\n    for(int u:G[v]){\n      ind[u]++,outd[v]++;\n      if(u==v) loop[v]=1;\n      if(u!=v) pre[u]=v;\n    }\n  }\n\n  int st=-1,en=-1,sz=0;\n  for(int i=0;i<n;i++){\n    if(ind[i]>=3 or outd[i]>=3) return true;\n    if(ind[i]<outd[i]) st=i;\n    if(ind[i]>outd[i]) en=i;\n    if(ind[i]+outd[i]) sz++;\n  }\n  if(sz<2) return false;\n  if(st<0) return true;\n\n  while(ind[en]==1+loop[en] and st!=en) en=pre[en];\n  if(st==en) return false;\n\n  queue<int> que;\n  vector<int> rs(n,0);\n  que.emplace(st);\n  rs[st]=1;\n  while(!que.empty()){\n    int v=que.front();que.pop();\n    for(int u:G[v]){\n      if(u==en or rs[u]) continue;\n      rs[u]=1;\n      que.emplace(u);\n    }\n  }\n\n  vector<int> us(n,0);\n  que.emplace(en);\n  us[en]=1;\n  while(!que.empty()){\n    int v=que.front();que.pop();\n    if(rs[v]) return true;\n    for(int u:G[v]){\n      if(u==en or us[u]) continue;\n      us[u]=1;\n      que.emplace(u);\n    }\n  }\n  return false;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\n#endif\n"
  },
  {
    "path": "graph/nicetree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct NiceTree{\n  vector< vector<int> > G;\n  vector< set<int> > ex;\n  vector<int> buff;\n  NiceTree(int n):G(n),ex(n),buff(n){}\n\n  void add_edge(int u,int v){\n    if(u>v) swap(u,v);\n    if(ex[u].count(v)) return;\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n    ex[u].emplace(v);\n  }\n\n  enum Type{LEAF, JOIN, INTRODUCE, FORGET};\n  struct Node{\n    int type,is_root;\n    Node():type(-1),is_root(1){}\n\n    // index for G\n    vector<int> bag;\n    void add_vertex(int v){bag.emplace_back(v);}\n\n    // index for T\n    vector<int> child;\n    void add_child(int v){child.emplace_back(v);}\n  };\n\n  vector<Node> T;\n  void to_nice(){\n    for(auto &vs:T){\n      sort(vs.bag.begin(),vs.bag.end());\n      for(int c:vs.child) T[c].is_root=0;\n    }\n\n    stack<int> st;\n    for(int i=0;i<(int)T.size();i++)\n      if(T[i].is_root) st.emplace(i);\n\n    while(!st.empty()){\n      int v=st.top();st.pop();\n\n      while(T[v].child.size()>2){\n        Node r;\n        r.add_child(T[v].child.back());\n        T[v].child.pop_back();\n        r.add_child(T[v].child.back());\n        T[v].child.pop_back();\n        r.bag=T[v].bag;\n        T[v].add_child(T.size());\n        T.emplace_back(r);\n      }\n\n      if(T[v].child.size()==2){\n        for(auto &u:T[v].child){\n          if(T[u].bag!=T[v].bag){\n            Node r;\n            r.add_child(u);\n            r.bag=T[v].bag;\n            u=T.size();\n            T.emplace_back(r);\n          }\n        }\n        T[v].type=JOIN;\n      }\n\n      if(T[v].child.size()==1){\n        int &u=T[v].child[0];\n        vector<int> latte,malta;\n        auto &ps=T[v].bag;\n        auto &qs=T[u].bag;\n        set_difference(ps.begin(),ps.end(),qs.begin(),qs.end(),\n                       back_inserter(latte));\n        set_difference(qs.begin(),qs.end(),ps.begin(),ps.end(),\n                       back_inserter(malta));\n        if(latte.size()+malta.size()>1){\n          Node r;\n          r.add_child(u);\n          r.bag=T[v].bag;\n          if(!latte.empty()){\n            r.bag.erase(find(r.bag.begin(),r.bag.end(),latte.back()));\n          }else{\n            r.bag.emplace_back(malta.back());\n          }\n          u=T.size();\n          T.emplace_back(r);\n        }\n        if(T[v].bag.size()<T[u].bag.size()) T[v].type=FORGET;\n        if(T[v].bag.size()>T[u].bag.size()) T[v].type=INTRODUCE;\n      }\n\n      if(T[v].child.empty()){\n        if(T[v].bag.size()>1){\n          Node r;\n          r.bag=T[v].bag;\n          r.bag.pop_back();\n          T[v].type=INTRODUCE;\n          T[v].add_child(T.size());\n          T.emplace_back(r);\n        }else{\n          T[v].type=LEAF;\n        }\n      }\n\n      for(auto &u:T[v].child)\n        st.emplace(u);\n    }\n\n    for(auto &vs:T)\n      for(int c:vs.child) T[c].is_root=0;\n  }\n\n  // root = 0 (if connected)\n  void build(){\n    int n=G.size();\n    if(n<=3){\n      Node r;\n      for(int i=0;i<n;i++) r.add_vertex(i);\n      T=vector<Node>({r});\n      return to_nice();\n    }\n\n    vector<int> deg(n);\n    queue<int> que;\n    for(int i=0;i<n;i++){\n      deg[i]=G[i].size();\n      if(deg[i]<=2) que.emplace(i);\n    }\n\n    vector<int> used(n,-1);\n    T.emplace_back();\n    while(!que.empty()){\n      int v=que.front();que.pop();\n      if(deg[v]>2 or used[v]!=-1) continue;\n      Node r;\n      r.add_vertex(v);\n\n      int p=-1,q=-1;\n      for(int u:G[v]){\n        if(used[u]==-1){\n          (p==-1?p:q)=u;\n          r.add_vertex(u);\n        }else if(used[u]>=0){\n          r.add_child(used[u]);\n          used[u]=-2;\n        }\n      }\n\n      if(deg[v]==0){\n        used[v]=T.size();\n        T.emplace_back(r);\n        continue;\n      }\n\n      if(q==-1){\n        deg[p]--;\n      }else{\n        if(p>q) swap(p,q);\n        if(!ex[p].count(q)){\n          add_edge(p,q);\n        }else{\n          deg[p]--;\n          deg[q]--;\n        }\n      }\n      for(int u:G[v])\n        if(deg[u]<=2) que.emplace(u);\n      deg[v]=0;\n      used[v]=T.size();\n      T.emplace_back(r);\n    }\n\n    for(int i=0;i<n;i++){\n      if(deg[i]>0){\n        T={};\n        return;\n      }\n    }\n\n    T.front()=T.back();T.pop_back();\n    to_nice();\n  }\n\n  template<typename F1,typename F2,typename F3,typename F4>\n  void dfs(int v,F1 &leaf,F2 &join,F3 &introduce,F4 &forget){\n    const auto &chd=T[v].child;\n    for(int u:chd) dfs(u,leaf,join,introduce,forget);\n\n    if(T[v].type==LEAF){\n      leaf(v);\n      return;\n    }\n    if(T[v].type==JOIN){\n      join(v);\n      return;\n    }\n\n    const auto &bag=T[v].bag;\n    for(int i=0;i<(int)bag.size();i++)\n      buff[bag[i]]=1<<i;\n\n    const auto &chd_bag=T[chd[0]].bag;\n    int dif=0;\n    for(int b:bag) dif^=b;\n    for(int b:chd_bag) dif^=b;\n\n    if(T[v].type==INTRODUCE){\n      introduce(v,dif);\n      return;\n    }\n    if(T[v].type==FORGET){\n      forget(v,dif);\n      return;\n    }\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"../tools/fastio.cpp\"\n#include \"../tools/chminmax.cpp\"\n#undef call_from_test\n\nsigned CSA_SPECIAL_MVC(){\n  int n,m;\n  cin>>n>>m;\n  NiceTree G(n);\n  using P = pair<int, int>;\n  set<P> es;\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    G.add_edge(a,b);\n    es.emplace(a,b);\n    es.emplace(b,a);\n  }\n\n  G.build();\n  auto &T=G.T;\n  auto &buff=G.buff;\n\n  vector< vector<int> > dps(T.size());\n\n  const int INF = 1e9;\n  auto base=\n    [&](int v){\n      const auto &bag=T[v].bag;\n      auto &dp=dps[v];\n      dp.assign(1<<bag.size(),-INF);\n    };\n\n  auto leaf=\n    [&](int v){\n      base(v);\n      auto &dp=dps[v];\n      dp[0]=0;\n      dp[1]=1;\n    };\n\n  auto join=\n    [&](int v){\n      base(v);\n      const auto &chd=T[v].child;\n      auto &dp=dps[v];\n      for(int i=0;i<(int)dp.size();i++)\n        chmax(dp[i],dps[chd[0]][i]+dps[chd[1]][i]-__builtin_popcount(i));\n    };\n\n  auto introduce=\n    [&](int v,int add){\n      base(v);\n\n      const auto &chd=T[v].child;\n      const auto &chd_bag=T[chd[0]].bag;\n      const auto &pr=dps[chd[0]];\n\n      auto &dp=dps[v];\n      for(int i=0;i<(int)pr.size();i++){\n        int bit=0,valid=1;\n        for(int j=0;j<(int)chd_bag.size();j++){\n          if((~i>>j)&1) continue;\n          bit|=buff[chd_bag[j]];\n          valid&=!es.count(P(chd_bag[j],add));\n        }\n        assert(!(bit&buff[add]));\n        if(valid) chmax(dp[bit|buff[add]],pr[i]+1);\n        chmax(dp[bit],pr[i]);\n      }\n    };\n\n  auto forget=\n    [&](int v,int rmv){\n      base(v);\n\n      const auto &chd=T[v].child;\n      const auto &chd_bag=T[chd[0]].bag;\n      const auto &pr=dps[chd[0]];\n\n      auto &dp=dps[v];\n      for(int i=0;i<(int)pr.size();i++){\n        int bit=0;\n        for(int j=0;j<(int)chd_bag.size();j++){\n          if((~i>>j)&1) continue;\n          if(rmv!=chd_bag[j]) bit|=buff[chd_bag[j]];\n        }\n        chmax(dp[bit],pr[i]);\n      }\n    };\n\n  int ans=n;\n  for(int i=0;i<(int)T.size();i++){\n    if(!T[i].is_root) continue;\n    G.dfs(i,leaf,join,introduce,forget);\n    ans-=*max_element(dps[i].begin(),dps[i].end());\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n/*\n  verified 2020/02/21\n  https://csacademy.com/contest/archive/task/special-mvc/statement/\n*/\n\nsigned main(){\n  CSA_SPECIAL_MVC();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/rangetorange.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n// https://lorent-kyopro.hatenablog.com/entry/2020/07/24/170656\n//BEGIN CUT HERE\nstruct RangeToRange{\n  const int n;\n  int ptr;\n  RangeToRange(int n):n(n),ptr(3*n){}\n\n  // (0n, 2n) : top segtree (to)\n  // (2n, 4n) : bottom segtree (from)\n\n  // map [3n, 4n) -> [n, 2n)\n  template<typename F>\n  void add_edge(int u,int v,F f){\n    if(3*n<=u and u<4*n) u-=2*n;\n    f(u,v);\n  }\n\n  template<typename F>\n  void init(F f){\n    for(int i=1;i<n;i++){\n      int l=(i<<1)|0;\n      int r=(i<<1)|1;\n      add_edge(0*n+i,0*n+l,f);\n      add_edge(0*n+i,0*n+r,f);\n      add_edge(2*n+l,2*n+i,f);\n      add_edge(2*n+r,2*n+i,f);\n    }\n  }\n\n  // [l1, r1) -> [l2, r2)\n  template<typename F,typename G>\n  void add_edge(int l1,int r1,int l2,int r2,F f,G g){\n    int k=ptr++;\n    for(l1+=n,r1+=n;l1<r1;l1>>=1,r1>>=1){\n      if(l1&1) add_edge(2*n+(l1++),k,f);\n      if(r1&1) add_edge(2*n+(--r1),k,f);\n    }\n    for(l2+=n,r2+=n;l2<r2;l2>>=1,r2>>=1){\n      if(l2&1) g(k,l2++);\n      if(r2&1) g(k,--r2);\n    }\n  }\n  int idx(int v)const{return 1*n+v;}\n  size_t size()const{return ptr;}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/semikernel.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n//BEGIN CUT HERE\n// https://link.springer.com/content/pdf/10.1007%2FBFb0066192.pdf\nstruct SemiKernel{\n  int n;\n  vector<vector<int> > G,R;\n  vector<int> used,dp,S;\n  SemiKernel(int n):n(n),G(n),R(n),used(n,0),dp(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    R[v].emplace_back(u);\n  }\n\n  void dfs(int v){\n    if(v==n) return;\n    if(used[v]){\n      dfs(v+1);\n      return;\n    }\n    used[v]=1;\n    for(int u:G[v]) used[u]=1;\n    dfs(v+1);\n    dp[v]=1;\n    for(int u:R[v]) dp[v]&=!dp[u];\n    if(dp[v]) S.emplace_back(v);\n  }\n\n  vector<int> build(){\n    dfs(0);\n    reverse(S.begin(),S.end());\n    return S;\n  }\n};\n//END CUT HERE\n//INSERT ABOVE HERE\nsigned CFR503_C(){\n  int n,m;\n  scanf(\"%d %d\",&n,&m);\n\n  SemiKernel sk(n);\n\n  for(int i=0;i<m;i++){\n    int a,b;\n    scanf(\"%d %d\",&a,&b);\n    a--;b--;\n    sk.add_edge(a,b);\n  }\n\n  auto ans=sk.build();\n  printf(\"%d\\n\",(int)ans.size());\n  for(int i=0;i<(int)ans.size();i++){\n    if(i) printf(\" \");\n    printf(\"%d\",ans[i]+1);\n  }\n  puts(\"\");\n  return 0;\n}\n/*\n  verified on 2018/08/12\n  http://codeforces.com/contest/1019/problem/C\n*/\n\nsigned main(){\n  CFR503_C();\n  return 0;\n}\n"
  },
  {
    "path": "graph/stronglyconnectedcomponent.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct SCC{\n  vector< vector<int> > G,R,H,C;\n  vector<int> vs,used,blg;\n  SCC(int n):G(n),R(n),used(n),blg(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    R[v].emplace_back(u);\n  }\n\n  void dfs(int v){\n    used[v]=1;\n    for(int u:G[v])\n      if(!used[u]) dfs(u);\n    vs.emplace_back(v);\n  }\n\n  void rdfs(int v,int k){\n    used[v]=1;\n    blg[v]=k;\n    C[k].emplace_back(v);\n    for(int u:R[v])\n      if(!used[u]) rdfs(u,k);\n  }\n\n  int build(bool uniq=true){\n    int n=G.size();\n    for(int v=0;v<n;v++)\n      if(!used[v]) dfs(v);\n\n    fill(used.begin(),used.end(),0);\n    int k=0;\n    for(int i=n-1;i>=0;i--){\n      if(!used[vs[i]]){\n        H.emplace_back();\n        C.emplace_back();\n        rdfs(vs[i],k++);\n      }\n    }\n\n    for(int v=0;v<n;v++)\n      for(int u:G[v])\n        if(blg[v]!=blg[u])\n          H[blg[v]].emplace_back(blg[u]);\n\n    if(uniq){\n      for(int i=0;i<k;i++){\n        sort(H[i].begin(),H[i].end());\n        H[i].erase(unique(H[i].begin(),H[i].end()),H[i].end());\n      }\n    }\n    return k;\n  }\n\n  int operator[](int k) const{return blg[k];}\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/topologicalsort.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct TopologicalSort{\n  vector<vector<int>> G;\n  vector<int> indeg;\n  TopologicalSort(int n):G(n),indeg(n,0){}\n\n  void add_edge(int s,int t){\n    G[s].emplace_back(t);\n    indeg[t]++;\n  }\n\n  vector<int> build(){\n    int n=G.size();\n\n    queue<int> que;\n    vector<int> used(n,0);\n    auto push=[&](int v){\n      if(used[v]) return;\n      que.emplace(v);\n      used[v]=1;\n    };\n\n    for(int i=0;i<n;i++)\n      if(indeg[i]==0) push(i);\n\n    vector<int> ps;\n    while(!que.empty()){\n      int v=que.front();que.pop();\n      ps.emplace_back(v);\n      for(int u:G[v]){\n        indeg[u]--;\n        if(indeg[u]==0) push(u);\n      }\n    }\n\n    if(n!=(int)ps.size()) return {};\n    return ps;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n#endif\n"
  },
  {
    "path": "graph/triangle.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct Triangle{\n  // if not simple, use vector<set<int>>\n  vector<vector<int>> G;\n  Triangle(int n):G(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  template<typename F>\n  void build(F f){\n    int n=G.size();\n    using P = pair<int, int>;\n    vector<P> vp(n);\n    for(int i=0;i<n;i++) vp[i]=P(G[i].size(),i);\n\n    vector<vector<int>> H(n);\n    for(int i=0;i<n;i++)\n      for(int j:G[i])\n        if(vp[i]>vp[j])\n          H[i].emplace_back(j);\n\n    vector<int> used(n,0);\n    // x->y->z\n    for(int x=0;x<n;x++){\n      for(int z:H[x]) used[z]=1;\n      for(int y:H[x])\n        for(int z:H[y])\n          if(used[z]) f(x,y,z);\n      for(int z:H[x]) used[z]=0;\n    }\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/twoedgeconnectedcomponents.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// work with multigraph\nstruct TwoEdgeConnectedComponents{\n  vector<int> ord,low,par,blg,sz;\n  vector<vector<int>> G,C;\n\n  TwoEdgeConnectedComponents(int n):\n    ord(n,-1),low(n),par(n,-1),blg(n,-1),sz(n,1),G(n){}\n\n  void add_edge(int u,int v){\n    if(u==v) return;\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  bool is_bridge(int u,int v){\n    if(ord[u]>ord[v]) swap(u,v);\n    return ord[u]<low[v];\n  }\n\n  void dfs(int v,int &pos){\n    ord[v]=low[v]=pos++;\n    int dup=0;\n    for(int u:G[v]){\n      if(u==par[v] and !dup){\n        dup=1;\n        continue;\n      }\n      if(~ord[u]){\n        low[v]=min(low[v],ord[u]);\n        continue;\n      }\n      par[u]=v;\n      dfs(u,pos);\n      sz[v]+=sz[u];\n      low[v]=min(low[v],low[u]);\n    }\n  }\n\n  void fill_component(int v){\n    C[blg[v]].emplace_back(v);\n    for(int u:G[v]){\n      if(~blg[u] or is_bridge(u,v)) continue;\n      blg[u]=blg[v];\n      fill_component(u);\n    }\n  }\n\n  void add_component(int v,int &k){\n    if(~blg[v]) return;\n    blg[v]=k++;\n    C.emplace_back();\n    fill_component(v);\n  }\n\n  int build(){\n    int n=G.size(),pos=0;\n    for(int i=0;i<n;i++)\n      if(ord[i]<0) dfs(i,pos);\n\n    int k=0;\n    for(int i=0;i<n;i++) add_component(i,k);\n\n    return k;\n  }\n\n  const vector<int>& operator[](int i)const{return C[i];}\n\n  vector<vector<int>> forest(){\n    int n=G.size(),k=C.size();\n    vector<vector<int>> T(k);\n    for(int v=0;v<n;v++)\n      for(int u:G[v])\n        if(blg[v]!=blg[u])\n          T[blg[v]].emplace_back(blg[u]);\n    return T;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/twosatisfiability.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"stronglyconnectedcomponent.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nstruct TwoSat{\n  int n;\n  SCC scc;\n  TwoSat(int n):n(n),scc(n*2){}\n  int negate(int v){return (n+v)%(n*2);}\n  void add_if(int u,int v){\n    // u -> v <=> !v -> !u\n    scc.add_edge(u,v);\n    scc.add_edge(negate(v),negate(u));\n  }\n  void add_or(int u,int v){\n    // u or v <=> !u -> v\n    add_if(negate(u),v);\n  }\n  void add_nand(int u,int v){\n    // u nand v <=> u -> !v\n    add_if(u,negate(v));\n  }\n  void set_true(int v){\n    //  v <=> !v ->  v\n    scc.add_edge(negate(v),v);\n  }\n  void set_false(int v){\n    // !v <=>  v -> !v\n    scc.add_edge(v,negate(v));\n  }\n  vector<int> build(){\n    scc.build();\n    vector<int> res(n);\n    for(int i=0;i<n;i++){\n      if(scc[i]==scc[n+i]) return {};\n      res[i]=scc[i]>scc[n+i];\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n// test add_if, set_true, set_false\nsigned CFR441_C(){\n  int n,m;\n  scanf(\"%d %d\",&n,&m);\n\n  vector<vector<int>> G(n);\n  for(int i=0;i<n;i++){\n    int k;\n    scanf(\"%d\",&k);\n    G[i].assign(k,0);\n    for(int &v:G[i]){\n      scanf(\"%d\",&v);\n      v--;\n    }\n  }\n  auto NG=[](){puts(\"No\");exit(0);};\n\n  TwoSat ts(m);\n  auto add_edge=\n    [&](vector<int> &as,vector<int> &bs){\n      int x=min(as.size(),bs.size());\n      int i;\n      for(i=0;i<x;i++){\n        if(as[i]==bs[i]) continue;\n        if(as[i]<bs[i]){\n          ts.add_if(bs[i],as[i]);\n        }else{\n          ts.set_true(as[i]);\n          ts.set_false(bs[i]);\n        }\n        break;\n      }\n      if((i==x) and (as.size()>bs.size())) NG();\n    };\n\n  for(int i=0;i+1<n;i++)\n    add_edge(G[i],G[i+1]);\n\n  auto vs=ts.build();\n  if(vs.empty()) NG();\n\n  vector<int> ans;\n  for(int i=0;i<m;i++)\n    if(vs[i]) ans.emplace_back(i);\n\n  puts(\"Yes\");\n  printf(\"%d\\n\",(int)ans.size());\n  for(int i=0;i<(int)ans.size();i++){\n    if(i) printf(\" \");\n    printf(\"%d\",ans[i]+1);\n  }\n  puts(\"\");\n\n  return 0;\n}\n/*\n  verified 2019/06/20\n  http://codeforces.com/contest/875/problem/C\n*/\n\n// test add_nand\nsigned YUKI_470(){\n  int n;\n  cin>>n;\n  vector<string> u(n);\n  for(int i=0;i<n;i++) cin>>u[i];\n\n  auto NO=[](){cout<<\"Impossible\"<<endl;exit(0);};\n\n  if(n>=100) NO();\n\n  TwoSat ts(n);\n  for(int i=0;i<n;i++){\n    for(int j=0;j<i;j++){\n      auto &as=u[i];\n      auto &bs=u[j];\n      if(as[0]==bs[0] and as[1]==bs[1])\n        ts.add_nand(i,j);\n\n      if(as[0]==bs[1] and as[1]==bs[2])\n        ts.add_nand(i,ts.negate(j));\n\n      if(as[1]==bs[0] and as[2]==bs[1])\n        ts.add_nand(ts.negate(i),j);\n\n      if(as[1]==bs[1] and as[2]==bs[2])\n        ts.add_nand(ts.negate(i),ts.negate(j));\n\n      if(as[0]==bs[0]) ts.add_nand(ts.negate(i),ts.negate(j));\n      if(as[0]==bs[2]) ts.add_nand(ts.negate(i),j);\n      if(as[2]==bs[0]) ts.add_nand(i,ts.negate(j));\n      if(as[2]==bs[2]) ts.add_nand(i,j);\n    }\n  }\n\n  auto res=ts.build();\n  if(res.empty()) NO();\n\n  for(int i=0;i<n;i++){\n    if(res[i])\n      cout<<u[i][0]<<u[i][1]<<\" \"<<u[i][2]<<endl;\n    else\n      cout<<u[i][0]<<\" \"<<u[i][1]<<u[i][2]<<endl;\n  }\n  return 0;\n}\n/*\n  verified 2019/10/24\n  https://yukicoder.me/problems/no/470\n*/\n\nsigned main(){\n  //CFR441_C();\n  //YUKI_470();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "graph/voronoiminimumspanningtree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct VoronoiMST{\n  int n;\n  using E = pair<int, T>;\n  using P = pair<T, int>;\n  vector<vector<E> > G;\n  VoronoiMST(vector<T> &x){\n    n=x.size();\n    G.assign(n<<1,vector<E>());\n    for(int i=0;i<n;i++) G[i].emplace_back(n+i,x[i]);\n  }\n  void add_edge(int u,int v,T c){\n    G[u+n].emplace_back(v+n,c);\n    G[v+n].emplace_back(u+n,c);\n  }\n  vector<vector<E> > build(){\n    priority_queue<P, vector<P>, greater<P> > pq;\n    const T INF = numeric_limits<T>::max();\n    vector<T> dist(n<<1,INF);\n    vector<int> from(n<<1,-1);\n    for(int i=0;i<n;i++){\n      dist[i]=0;from[i]=i;\n      pq.emplace(dist[i],i);\n    }\n    while(!pq.empty()){\n      T d;\n      int v;\n      tie(d,v)=pq.top();pq.pop();\n      if(dist[v]<d) continue;\n      for(E e:G[v]){\n        int u=e.first;\n        T c=e.second;\n        if(dist[u]<=dist[v]+c) continue;\n        dist[u]=dist[v]+c;\n        from[u]=from[v];\n        pq.emplace(dist[u],u);\n      }\n    }\n    vector<vector<E> > H(n);\n    for(int v=0;v<(n<<1);v++){\n      for(E e:G[v]){\n        int u=e.first;\n        T c=e.second;\n        if(from[v]==from[u]) continue;\n        int x=from[v],y=from[u];\n        T z=dist[v]+dist[u]+c;\n        H[x].emplace_back(y,z);\n        H[y].emplace_back(x,z);\n      }\n    }\n    return H;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"kruskal.cpp\"\n#undef call_from_test\n\n//INSERT ABOVE HERE\nsigned CF17FINAL_J(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n;\n  cin>>n;\n  vector<ll> x(n);\n  for(int i=0;i<n;i++) cin>>x[i];\n  VoronoiMST<ll> vo(x);\n  for(int i=1;i<n;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    a--;b--;\n    vo.add_edge(a,b,c);\n  }\n  auto G=vo.build();\n  Kruskal<ll> ks(n);\n  for(int v=0;v<n;v++){\n    for(auto e:G[v]){\n      int u=e.first;\n      ll c=e.second;\n      if(v<u) ks.add_edge(v,u,c);\n    }\n  }\n  cout<<ks.build()<<endl;\n  return 0;\n}\n/*\n  verified on 2020/05/07\n  https://atcoder.jp/contests/cf17-final/tasks/cf17_final_j\n*/\nsigned main(){\n  CF17FINAL_J();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "heuristic/timer.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n/**\n * @ignore\n */\n//BEGIN CUT HERE\nusing i16 = int16_t;\nusing i32 = int32_t;\nusing i64 = int64_t;\n\nusing u16 = uint16_t;\nusing u32 = uint32_t;\nusing u64 = uint64_t;\n\n// AtCoder\nconst i64 CYCLES_PER_SEC = 2800000000;\n\nstruct Timer {\n\ti64 start;\n\tTimer(){reset();}\n\tvoid reset(){start=getCycle();}\n\tinline double get(){return (double)(getCycle()-start)/CYCLES_PER_SEC;}\n\tinline i64 getCycle(){\n\t\tu32 low,high;\n\t\t__asm__ volatile (\"rdtsc\" : \"=a\" (low), \"=d\" (high));\n\t\treturn ((i64)low)|((i64)high<<32);\n\t}\n};\n\nTimer timer;\n//END CUT HERE\n\n//INSERT ABOVE HERE\nvoid nxt(){\n  static i64 x = 0;\n  static i64 y = 1;\n  x=(x<<10)+y;\n  y=x/3;\n}\n\nsigned main(){\n  cout<<fixed<<setprecision(12);\n  auto start1=clock(),stop1=clock();\n  for(int i=0;i<1000000;i++) stop1=clock();\n\n  double d=0;\n  auto start2=clock();\n  for(int i=0;i<1000000;i++) d+=timer.get();\n  auto stop2=clock();\n\n  cout<<(double)(stop1-start1)/CLOCKS_PER_SEC<<endl;\n  cout<<(double)(stop2-start2)/CLOCKS_PER_SEC<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "heuristic/xorshift.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n/**\n * @ignore\n */\n\n//BEGIN CUT HERE\nuint32_t xor128(){\n  static uint32_t x = 123456789;\n  static uint32_t y = 362436069;\n  static uint32_t z = 521288629;\n  static uint32_t w = 88675123;\n  uint32_t t = x ^ (x << 11);\n  x = y; y = z; z = w;\n  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));\n}\n//END CUT HERE\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n"
  },
  {
    "path": "includes/formalpowerseries.h",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\n#define call_from_test\n#include \"../mod/mint.cpp\"\n#include \"../combinatorics/enumeration.cpp\"\n#include \"../formalpowerseries/base.cpp\"\n#include \"../formalpowerseries/inv.cpp\"\n#include \"../formalpowerseries/div.cpp\"\n#include \"../formalpowerseries/mod.cpp\"\n#include \"../formalpowerseries/sqrt.cpp\"\n#include \"../formalpowerseries/diff.cpp\"\n#include \"../formalpowerseries/integral.cpp\"\n#include \"../formalpowerseries/log.cpp\"\n#include \"../formalpowerseries/exp.cpp\"\n#include \"../formalpowerseries/pow.cpp\"\n#include \"../formalpowerseries/shift.cpp\"\n#undef call_from_test\n//END CUT HERE\n"
  },
  {
    "path": "io/precision.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct Precision{\n  Precision(){\n    cout<<fixed<<setprecision(12);\n  }\n}precision_beet;\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "io/single.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T=int>\nvector<T> read(size_t n){\n  vector<T> ts(n);\n  for(size_t i=0;i<n;i++) cin>>ts[i];\n  return ts;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "io/space.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T>\nvoid space(const vector<T> &vs){\n  for(size_t i=0;i<vs.size();i++){\n    if(i) cout<<' ';\n    cout<<vs[i];\n  }\n  cout<<'\\n';\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "io/tuple.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename TV, const int N> void read_tuple_impl(TV&) {}\ntemplate<typename TV, const int N, typename Head, typename... Tail>\nvoid read_tuple_impl(TV& ts) {\n  get<N>(ts).emplace_back(*(istream_iterator<Head>(cin)));\n  read_tuple_impl<TV, N+1, Tail...>(ts);\n}\ntemplate<typename... Ts> decltype(auto) read_tuple(size_t n) {\n  tuple<vector<Ts>...> ts;\n  for(size_t i=0;i<n;i++) read_tuple_impl<decltype(ts), 0, Ts...>(ts);\n  return ts;\n}\n//END CUT HERE\n\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "io/yesno.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\nstruct BoolPrinter{\n  const string a,b;\n  BoolPrinter(string a_,string b_):a(a_),b(b_){}\n  string operator[](int k){return k?a:b;}\n};\nBoolPrinter yesno(\"yes\",\"no\");\nBoolPrinter YesNo(\"Yes\",\"No\");\nBoolPrinter YESNO(\"YES\",\"NO\");\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "leetcode/treenode.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n/**\n * @ignore\n */\n\n//BEGIN CUT HERE\n\nstruct TreeNode {\n  int val;\n  TreeNode *left;\n  TreeNode *right;\n  TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n};\n\nint dfs(TreeNode* v,int &k,vector<vector<int> > &G,vector<int> &x){\n  if(!v) return -1;\n  int s=k++;\n  x.emplace_back(v->val);\n  G.emplace_back(vector<int>());\n  int a=dfs(v->left,k,G,x);\n  int b=dfs(v->right,k,G,x);\n  if(~a){\n    G[s].emplace_back(a);\n    G[a].emplace_back(s);\n  }\n  if(~b){\n    G[s].emplace_back(b);\n    G[b].emplace_back(s);\n  }\n  return s;\n}\n\nvoid build(TreeNode* v,vector<vector<int> > &G,vector<int> &x){\n  assert(G.empty());\n  int k=0;\n  dfs(v,k,G,x);\n}\n\n//END CUT HERE\n\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n"
  },
  {
    "path": "linearalgebra/binarymatrix.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nconst int MAX = 2002;\nusing BS = bitset<MAX*2>;\nusing mat = vector<BS>;\n\nvoid gauss(mat &v){\n  int n=v.size();\n  for(int i=0;i<n;i++){\n    for(int k=i;k<n;k++){\n      if(v[k][i]){\n        swap(v[i],v[k]);\n        break;\n      }\n    }\n    for(int k=0;k<n;k++)\n      if(i!=k and v[k][i]) v[k]^=v[i];\n  }\n}\n\nint mrank(mat v,int m){\n  int n=v.size();\n  int r=0,c=0;\n  for(int i=0;i<n;i++){\n    int s=-1;\n    while(c<m){\n      for(int j=i;j<n;j++){\n        if(v[j][c]){\n          s=j;\n          break;\n        }\n      }\n      if(~s) break;\n      c++;\n    }\n    if(c>=m) break;\n\n    swap(v[i],v[s]);\n    for(int j=0;j<n;j++)\n      if(i!=j and v[j][c]) v[j]^=v[i];\n\n    r++;c++;\n  }\n  return r;\n}\n\nmat mul(const mat &a,const mat &b){\n  int n=a.size();\n  vector<vector<int> > tmp(n,vector<int>(n,0));\n  mat res(n,BS(0));\n  for(int i=0;i<n;i++)\n    for(int j=0;j<n;j++)\n      for(int k=0;k<n;k++)\n        tmp[i][j]+=(a[i][k]&b[k][j]);\n\n  for(int i=0;i<n;i++)\n    for(int j=0;j<n;j++)\n      res[i][j]=tmp[i][j]&1;\n\n  return res;\n}\n\nmat mat_pow(mat v,long long k){\n  int n=v.size();\n  mat res(n,BS(0));\n  for(int i=0;i<n;i++)\n    res[i][i]=1;\n  while(k){\n    if(k&1) res=mul(res,v);\n    v=mul(v,v);\n    k>>=1;\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"../tools/fastio.cpp\"\n#undef call_from_test\n\nsigned CFR382_D(){\n  int n,m;\n  cin>>n>>m;\n  mat v(n,BS(0));\n  for(int i=0;i<n;i++) v[i][n+i]=1;\n  vector<int> as(m),bs(m);\n  for(int i=0;i<m;i++){\n    cin>>as[i]>>bs[i];\n    as[i]--;bs[i]--;\n    v[as[i]][bs[i]]=1;\n  }\n  gauss(v);\n  for(int i=0;i<m;i++)\n    cout<<(v[bs[i]][as[i]+n]?\"NO\":\"YES\")<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n/*\n  verified on 2019/12/17\n  http://codeforces.com/contest/736/problem/D\n*/\n\nsigned ARC054_D(){\n  int n;\n  cin>>n;\n  mat v(n,BS(0));\n  for(int i=0;i<n;i++){\n    for(int j=0;j<n;j++){\n      char c;\n      cin>>c;\n      v[i][j]=c-'0';\n    }\n  }\n  int ans=mrank(v,n);\n  cout<<(ans==n?\"Odd\":\"Even\")<<endl;\n  return 0;\n}\n/*\n  verified on 2019/12/17\n  https://atcoder.jp/contests/arc054/tasks/arc054_c\n*/\n\nsigned main(){\n  //CFR382_D();\n  //ARC054_D();\n  return 0;\n}\n\n#endif\n"
  },
  {
    "path": "linearalgebra/matrix.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename K>\nstruct Matrix{\n  typedef vector<K> arr;\n  typedef vector<arr> mat;\n  mat dat;\n\n  Matrix(size_t r,size_t c):dat(r,arr(c,K())){}\n  Matrix(mat dat):dat(dat){}\n\n  size_t size() const{return dat.size();}\n  bool empty() const{return size()==0;}\n  arr& operator[](size_t k){return dat[k];}\n  const arr& operator[](size_t k) const {return dat[k];}\n\n  static Matrix matmul(const Matrix &A,const Matrix &B){\n    Matrix res(A.size(),B[0].size());\n    for(int i=0;i<(int)A.size();i++)\n      for(int j=0;j<(int)B[0].size();j++)\n        for(int k=0;k<(int)B.size();k++)\n          res[i][j]+=A[i][k]*B[k][j];\n    return res;\n  }\n\n  static Matrix identity(size_t n){\n    Matrix res(n,n);\n    for(int i=0;i<(int)n;i++) res[i][i]=K(1);\n    return res;\n  }\n\n  Matrix pow(long long n) const{\n    assert(n>=0);\n    assert(dat.size()==dat[0].size());\n    Matrix a(dat),res=identity(size());\n    while(n){\n      if(n&1) res=matmul(res,a);\n      a=matmul(a,a);\n      n>>=1;\n    }\n    return res;\n  }\n\n  template<typename T>\n  using ET = enable_if<is_floating_point<T>::value>;\n  template<typename T>\n  using EF = enable_if<!is_floating_point<T>::value>;\n\n  template<typename T, typename ET<T>::type* = nullptr>\n  static bool is_zero(T x){return abs(x)<1e-8;}\n  template<typename T, typename EF<T>::type* = nullptr>\n  static bool is_zero(T x){return x==T(0);}\n\n  template<typename T, typename ET<T>::type* = nullptr>\n  static bool compare(T x,T y){return abs(x)<abs(y);}\n  template<typename T, typename EF<T>::type* = nullptr>\n  static bool compare(T,T y){return !is_zero(y);}\n\n  // assume regularity\n  static Matrix gauss_jordan(const Matrix &A,const Matrix &B){\n    int n=A.size(),l=B[0].size();\n    Matrix C(n,n+l);\n    for(int i=0;i<n;i++){\n      for(int j=0;j<n;j++)\n        C[i][j]=A[i][j];\n      for(int j=0;j<l;j++)\n        C[i][n+j]=B[i][j];\n    }\n    for(int i=0;i<n;i++){\n      int p=i;\n      for(int j=i;j<n;j++)\n        if(compare(C[p][i],C[j][i])) p=j;\n      swap(C[i],C[p]);\n      if(is_zero(C[i][i])) return Matrix(0,0);\n      for(int j=i+1;j<n+l;j++) C[i][j]/=C[i][i];\n      for(int j=0;j<n;j++){\n        if(i==j) continue;\n        for(int k=i+1;k<n+l;k++)\n          C[j][k]-=C[j][i]*C[i][k];\n      }\n    }\n    Matrix res(n,l);\n    for(int i=0;i<n;i++)\n      for(int j=0;j<l;j++)\n        res[i][j]=C[i][n+j];\n    return res;\n  }\n\n  Matrix inv() const{\n    Matrix B=identity(size());\n    return gauss_jordan(*this,B);\n  }\n\n  static arr linear_equations(const Matrix &A,const arr &b){\n    Matrix B(b.size(),1);\n    for(int i=0;i<(int)b.size();i++) B[i][0]=b[i];\n    Matrix tmp=gauss_jordan(A,B);\n    arr res(tmp.size());\n    for(int i=0;i<(int)tmp.size();i++) res[i]=tmp[i][0];\n    return res;\n  }\n\n  K determinant() const{\n    Matrix A(dat);\n    K res(1);\n    int n=size();\n    for(int i=0;i<n;i++){\n      int p=i;\n      for(int j=i;j<n;j++)\n        if(compare(A[p][i],A[j][i])) p=j;\n      if(i!=p) swap(A[i],A[p]),res=-res;\n      if(is_zero(A[i][i])) return K(0);\n      res*=A[i][i];\n      for(int j=i+1;j<n;j++) A[i][j]/=A[i][i];\n      for(int j=i+1;j<n;j++)\n        for(int k=i+1;k<n;k++)\n          A[j][k]-=A[j][i]*A[i][k];\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n#define call_from_test\n#include \"../mod/rint.cpp\"\n#undef call_from_test\n\n// test inv\nsigned SPOJ_MIFF(){\n  int first=1;\n  int n,p;\n  while(scanf(\"%d %d\",&n,&p),n){\n    if(!first) puts(\"\");\n    first=0;\n    using M = Rint<int>;\n    M::set_mod(p);\n    using MM = Matrix<M>;\n    MM A(n,n);\n    for(int i=0;i<n;i++)\n      for(int j=0;j<n;j++)\n        scanf(\"%d\",&A[i][j].v);\n    MM B=A.inv();\n    if(B.empty()) puts(\"singular\");\n    else{\n      for(int i=0;i<n;i++){\n        for(int j=0;j<n;j++){\n          if(j) printf(\" \");\n          printf(\"%d\",B[i][j].v);\n        }\n        puts(\"\");\n      }\n    }\n  }\n  return 0;\n}\n/*\n  verified on 2021/09/23\n  https://www.spoj.com/problems/MIFF/\n*/\n\n// test pow\nsigned SPOJ_MPOW(){\n  int T;\n  scanf(\"%d\",&T);\n  while(T--){\n    int n,p;\n    scanf(\"%d %d\",&n,&p);\n    using M = Rint<int>;\n    M::set_mod(1e9+7);\n    using MM = Matrix<M>;\n    MM A(n,n);\n    for(int i=0;i<n;i++)\n      for(int j=0;j<n;j++)\n        scanf(\"%d\",&A[i][j].v);\n    MM B=A.pow(p);\n    for(int i=0;i<n;i++){\n      for(int j=0;j<n;j++){\n        if(j) printf(\" \");\n        printf(\"%d\",B[i][j].v);\n      }\n      puts(\"\");\n    }\n  }\n  return 0;\n}\n/*\n  verified on 2021/09/23\n  https://www.spoj.com/problems/MPOW/\n*/\n\nsigned main(){\n  //SPOJ_MIFF();\n  //SPOJ_MPOW();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "linearalgebra/squarematrix.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename R, size_t N>\nstruct SquareMatrix{\n  typedef array<R, N> arr;\n  typedef array<arr, N> mat;\n  mat dat;\n\n  SquareMatrix(){\n    for(size_t i=0;i<N;i++)\n      for(size_t j=0;j<N;j++)\n        dat[i][j]=R::add_identity();\n  }\n\n  bool operator==(const SquareMatrix& a) const{\n    return dat==a.dat;\n  }\n\n  size_t size() const{return N;}\n  arr& operator[](size_t k){return dat[k];}\n  const arr& operator[](size_t k) const {return dat[k];}\n\n  static SquareMatrix add_identity(){return SquareMatrix();}\n  static SquareMatrix mul_identity(){\n    SquareMatrix res;\n    for(size_t i=0;i<N;i++) res[i][i]=R::mul_identity();\n    return res;\n  }\n\n  SquareMatrix operator*(const SquareMatrix &B) const{\n    SquareMatrix res;\n    for(size_t i=0;i<N;i++)\n      for(size_t j=0;j<N;j++)\n        for(size_t k=0;k<N;k++)\n          res[i][j]=res[i][j]+(dat[i][k]*B[k][j]);\n    return res;\n  }\n\n  SquareMatrix operator+(const SquareMatrix &B) const{\n    SquareMatrix res;\n    for(size_t i=0;i<N;i++)\n      for(size_t j=0;j<N;j++)\n        res[i][j]=dat[i][j]+B[i][j];\n    return res;\n  }\n\n  SquareMatrix pow(long long n) const{\n    SquareMatrix a=*this,res=mul_identity();\n    while(n){\n      if(n&1) res=res*a;\n      a=a*a;\n      n>>=1;\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "linearalgebra/tree_theorem.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"matrix.cpp\"\n#include \"../datastructure/unionfind.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename K, typename T>\nstruct MatrixTreeTheorem{\n  using M = Matrix<K>;\n  struct edge{\n    int a,b;\n    T c;\n    edge(int a,int b,T c):a(a),b(b),c(c){}\n    bool operator<(const edge &e)const{\n      return c<e.c;\n    }\n  };\n\n  vector<edge> es;\n  vector<int> used;\n  vector<vector<int> > H;\n  UnionFind uf;\n\n  MatrixTreeTheorem(int n):used(n),H(n),uf(n){}\n\n  void add_edge(int a,int b,T c){\n    es.emplace_back(a,b,c);\n  }\n\n  vector<int> bfs(int v){\n    vector<int> vs;\n    queue<int> q;\n    used[v]=1;\n    q.emplace(v);\n    while(!q.empty()){\n      v=q.front();q.pop();\n      vs.emplace_back(v);\n      for(int u:H[v]){\n        if(used[u]) continue;\n        used[u]=1;\n        q.emplace(u);\n      }\n    }\n    return vs;\n  }\n\n  tuple<int, K, T> build(){\n    sort(es.begin(),es.end());\n    fill(used.begin(),used.end(),0);\n    K res(1);\n    T cost(0);\n    for(int i=0;i<(int)es.size();){\n      queue<int> q,r;\n      for(auto &h:H) h.clear();\n      int p=i;\n      while(i<(int)es.size() and es[i].c==es[p].c){\n        int u=uf.find(es[i].a);\n        int v=uf.find(es[i++].b);\n        H[u].emplace_back(v);\n        H[v].emplace_back(u);\n        q.emplace(u);q.emplace(v);\n        r.emplace(u);r.emplace(v);\n      }\n      while(!q.empty()){\n        int v=q.front();q.pop();\n        if(used[v]) continue;\n        vector<int> vs=bfs(v);\n        int m=vs.size();\n        if(m==1) continue;\n\n        sort(vs.begin(),vs.end());\n        auto idx=[&](int x){\n          return lower_bound(vs.begin(),vs.end(),x)-vs.begin();\n        };\n        M A(m,m);\n        for(int x:vs)\n          for(int y:H[x])\n            if(x!=y) A[idx(x)][idx(y)]-=K(1);\n\n        for(int x=0;x<m;x++)\n          for(int y=0;y<m;y++)\n            if(x!=y) A[x][x]-=A[x][y];\n\n        A.dat.pop_back();\n        for(auto &a:A.dat) a.pop_back();\n\n        res*=A.determinant();\n        for(int x:vs) uf.unite(v,x);\n        cost+=T(m-1)*es[p].c;\n      }\n      while(!r.empty()){\n        int v=r.front();r.pop();\n        used[v]=0;\n      }\n    }\n    return make_tuple(uf.count(),res,cost);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"../mod/mint.cpp\"\n#undef call_from_test\n\n//INSERT ABOVE HERE\nsigned ARC018_D(){\n  using M = Mint<int>;\n  int n,m;\n  scanf(\"%d %d\",&n,&m);\n  MatrixTreeTheorem<M, int> mtt(n);\n  for(int i=0;i<m;i++){\n    int a,b,c;\n    scanf(\"%d %d %d\",&a,&b,&c);\n    a--;b--;\n    mtt.add_edge(a,b,c);\n  }\n  auto[k,res,cost]=mtt.build();\n  printf(\"%d %d\\n\",cost,res.v);\n  return 0;\n}\n/*\n  verified on 2021/09/23\n  https://atcoder.jp/contests/arc018/tasks/arc018_4\n*/\n\nsigned main(){\n  ARC018_D();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "linkcuttree/base.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename Node, size_t LIM, typename Impl>\nstruct LinkCutTreeBase{\n  alignas(Node) inline static char pool[sizeof(Node) * LIM];\n  inline static Node* ptr = (Node*)pool;\n  inline static size_t size = 0;\n\n  template<typename... Args>\n  inline Node* create(Args&&... args){\n    return new (ptr+size++) Node(std::forward<Args>(args)...);\n  }\n\n  inline size_t idx(Node *t){return t-ptr;}\n  Node* operator[](size_t k){return ptr+k;}\n\n  inline void toggle(Node *t){\n    static_cast<Impl*>(this)->toggle(t);\n  }\n\n  inline Node* eval(Node *t){\n    return static_cast<Impl*>(this)->eval(t);\n  }\n\n  inline void pushup(Node *t){\n    static_cast<Impl*>(this)->pushup(t);\n  }\n\n  inline Node* expose(Node *t){\n    return static_cast<Impl*>(this)->expose(t);\n  }\n\n  void rotR(Node *t){\n    Node *x=t->p,*y=x->p;\n    if((x->l=t->r)) t->r->p=x;\n    t->r=x;x->p=t;\n    pushup(x);pushup(t);\n    if((t->p=y)){\n      if(y->l==x) y->l=t;\n      if(y->r==x) y->r=t;\n      pushup(y);\n    }\n  }\n\n  void rotL(Node *t){\n    Node *x=t->p,*y=x->p;\n    if((x->r=t->l)) t->l->p=x;\n    t->l=x;x->p=t;\n    pushup(x);pushup(t);\n    if((t->p=y)){\n      if(y->l==x) y->l=t;\n      if(y->r==x) y->r=t;\n      pushup(y);\n    }\n  }\n\n  // for splay tree (not original tree)\n  bool is_root(Node *t){\n    return !t->p or (t->p->l!=t and t->p->r!=t);\n  }\n\n  void splay(Node *t){\n    eval(t);\n    while(!is_root(t)){\n      Node *q=t->p;\n      if(is_root(q)){\n        eval(q);eval(t);\n        if(q->l==t) rotR(t);\n        else rotL(t);\n      }else{\n        auto *r=q->p;\n        eval(r);eval(q);eval(t);\n        if(r->l==q){\n          if(q->l==t) rotR(q),rotR(t);\n          else rotL(t),rotR(t);\n        }else{\n          if(q->r==t) rotL(q),rotL(t);\n          else rotR(t),rotL(t);\n        }\n      }\n    }\n  }\n\n  // c must be root on LCT\n  void link(Node *par,Node *c){\n    expose(c);\n    expose(par);\n    c->p=par;\n    par->r=c;\n    pushup(par);\n  }\n\n  void cut(Node *c){\n    expose(c);\n    Node *par=c->l;\n    c->l=nullptr;\n    pushup(c);\n    par->p=nullptr;\n  }\n\n  void evert(Node *t){\n    expose(t);\n    toggle(t);\n    eval(t);\n  }\n\n  Node *parent(Node *t){\n    expose(t);\n    if(!(t->l)) return nullptr;\n    t=eval(t->l);\n    while(t->r) t=eval(t->r);\n    splay(t);\n    return t;\n  }\n\n  Node *root(Node *t){\n    expose(t);\n    while(t->l) t=eval(t->l);\n    splay(t);\n    return t;\n  }\n\n  bool is_connected(Node *a,Node *b){\n    return root(a)==root(b);\n  }\n\n  Node *lca(Node *a,Node *b){\n    expose(a);\n    return expose(b);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "linkcuttree/farthest.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"base.cpp\"\n#undef call_from_test\n\n#endif\n// https://ei1333.hateblo.jp/entry/2019/06/13/133736\n//BEGIN CUT HERE\ntemplate<typename Tp>\nstruct NodeBase{\n  using T = Tp;\n  NodeBase *l,*r,*p;\n  bool rev;\n  T val,ld,rd,smd;\n  multiset<T> td;\n  NodeBase(T val):rev(0),val(val){\n    l=r=p=nullptr;\n    ld=rd=smd=val;\n    td.emplace(0);\n  }\n};\n\ntemplate<typename Np, size_t LIM>\nstruct Farthest : LinkCutTreeBase<Np, LIM, Farthest<Np, LIM>>{\n  using super = LinkCutTreeBase<Np, LIM, Farthest>;\n  using Node = Np;\n  using T = typename Node::T;\n\n  Node* create(T val){\n    return super::create(Node(val));\n  }\n\n  inline void toggle(Node *t){\n    swap(t->l,t->r);\n    swap(t->ld,t->rd);\n    t->rev^=1;\n  }\n\n  inline Node* eval(Node *t){\n    if(t->rev){\n      if(t->l) toggle(t->l);\n      if(t->r) toggle(t->r);\n      t->rev=false;\n    }\n    return t;\n  }\n\n  inline void pushup(Node *t){\n    if(t==nullptr) return;\n    t->smd=t->val;\n    if(t->l) t->smd+=t->l->smd;\n    if(t->r) t->smd+=t->r->smd;\n\n    T lld=t->l?t->l->ld:0;\n    T rrd=t->r?t->r->rd:0;\n\n    T lsmd=t->l?t->l->smd:0;\n    T rsmd=t->r?t->r->smd:0;\n\n    t->ld=max(lld,lsmd+t->val+*(t->td).rbegin());\n    if(t->r) t->ld=max(t->ld,lsmd+t->val+t->r->ld);\n\n    t->rd=max(rrd,rsmd+t->val+*(t->td).rbegin());\n    if(t->l) t->rd=max(t->rd,rsmd+t->val+t->l->rd);\n  }\n\n  using super::splay;\n\n  inline Node* expose(Node *t){\n    Node *rp=nullptr;\n    for(Node *c=t;c;c=c->p){\n      splay(c);\n      if(c->r) c->td.emplace(c->r->ld);\n      c->r=rp;\n      if(c->r) c->td.erase(c->td.find(c->r->ld));\n      pushup(c);\n      rp=c;\n    }\n    splay(t);\n    return rp;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned TKPPC2015_J(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n  using Node = NodeBase<ll>;\n  constexpr size_t LIM = 1e6+200;\n  using LCT = Farthest<Node, LIM>;\n  LCT lct;\n\n  vector<LCT::Node*> vs;\n  vector<LCT::Node*> es;\n  vs.reserve(5e5+100);\n  es.reserve(5e5+100);\n\n  int num=0;\n  vs.emplace_back(lct.create(0));\n  es.emplace_back(lct.create(0));\n  num++;\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int t,a,c;\n    cin>>t>>a>>c;\n    if(t==1){\n      vs.emplace_back(lct.create(0));\n      es.emplace_back(lct.create(c));\n      lct.link(vs[a],es[num]);\n      lct.link(es[num],vs[num]);\n      num++;\n    }\n    if(t==2){\n      lct.expose(es[a]);\n      es[a]->val=c;\n      lct.pushup(es[a]);\n    }\n    if(t==3){\n      lct.evert(vs[a]);\n      cout<<(vs[a]->ld)<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n/*\n  verified on 2020/10/28\n  https://atcoder.jp/contests/tkppc/tasks/tkppc2015_j\n*/\n\nsigned main(){\n  TKPPC2015_J();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "linkcuttree/path.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"base.cpp\"\n#undef call_from_test\n\n#endif\n// https://ei1333.hateblo.jp/entry/2018/05/29/011140\n//BEGIN CUT HERE\ntemplate<typename Tp,typename Ep>\nstruct NodeBase{\n  using T = Tp;\n  using E = Ep;\n  NodeBase *l,*r,*p;\n  bool rev;\n  T val,dat;\n  E laz;\n  NodeBase(T val,E laz):\n    rev(0),val(val),dat(val),laz(laz){\n    l=r=p=nullptr;}\n};\n\ntemplate<typename Np, size_t LIM>\nstruct Path : LinkCutTreeBase<Np, LIM, Path<Np, LIM>>{\n  using super = LinkCutTreeBase<Np, LIM, Path>;\n  using Node = Np;\n  using T = typename Node::T;\n  using E = typename Node::E;\n\n  using F = function<T(T, T)>;\n  using G = function<T(T, E)>;\n  using H = function<E(E, E)>;\n  using S = function<T(T)>;\n  F f;\n  G g;\n  H h;\n  S flip;\n  E ei;\n\n  Path(F f,G g,H h,S flip,E ei):\n    f(f),g(g),h(h),flip(flip),ei(ei){}\n\n  Path(F f,G g,H h,E ei):\n    Path(f,g,h,[](T a){return a;},ei){}\n\n  Node* create(T val){\n    return super::create(Node(val,ei));\n  }\n\n  inline void propagate(Node *t,E v){\n    t->laz=h(t->laz,v);\n    t->val=g(t->val,v);\n    t->dat=g(t->dat,v);\n  }\n\n  inline void toggle(Node *t){\n    swap(t->l,t->r);\n    t->dat=flip(t->dat);\n    t->rev^=1;\n  }\n\n  inline Node* eval(Node *t){\n    if(t->laz!=ei){\n      if(t->l) propagate(t->l,t->laz);\n      if(t->r) propagate(t->r,t->laz);\n      t->laz=ei;\n    }\n    if(t->rev){\n      if(t->l) toggle(t->l);\n      if(t->r) toggle(t->r);\n      t->rev=false;\n    }\n    return t;\n  }\n\n  inline void pushup(Node *t){\n    t->dat=t->val;\n    if(t->l) t->dat=f(t->l->dat,t->dat);\n    if(t->r) t->dat=f(t->dat,t->r->dat);\n  }\n\n  using super::splay;\n\n  inline Node* expose(Node *t){\n    Node *rp=nullptr;\n    for(Node *c=t;c;c=c->p){\n      splay(c);\n      c->r=rp;\n      pushup(c);\n      rp=c;\n    }\n    splay(t);\n    return rp;\n  }\n\n  T query(Node *t){\n    expose(t);\n    return t->dat;\n  }\n\n  void update(Node *t,E v){\n    expose(t);\n    propagate(t,v);\n    eval(t);\n  }\n\n  void set_val(Node *t,T v){\n    expose(t);\n    t->val=v;\n    eval(t);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n// test dynamic tree\nsigned SPOJ_DYNACON1(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  using Node = NodeBase<int, int>;\n  constexpr size_t LIM = 1e6;\n  using LCT = Path<Node, LIM>;\n\n  auto f=[](int a,int b){return a+b;};\n  LCT lct(f,f,f,0);\n  for(int i=0;i<n;i++) lct.create(0);\n\n  for(int i=0;i<m;i++){\n    string s;\n    int a,b;\n    cin>>s>>a>>b;\n    a--;b--;\n    if(s==\"add\"s){\n      lct.evert(lct[b]);\n      lct.link(lct[a],lct[b]);\n    }\n    if(s==\"rem\"s){\n      auto v=lct.lca(lct[a],lct[b])==lct[a]?lct[b]:lct[a];\n      lct.cut(v);\n    }\n    if(s==\"conn\"s)\n      cout<<(lct.is_connected(lct[a],lct[b])?\"YES\\n\":\"NO\\n\");\n  }\n  cout<<flush;\n  return 0;\n}\n/*\n  verified on 2020/10/28\n  https://www.spoj.com/problems/DYNACON1/\n*/\n\nsigned main(){\n  //SPOJ_DYNACON1();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "linkcuttree/subtree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"base.cpp\"\n#undef call_from_test\n\n#endif\n// http://beet-aizu.hatenablog.com/entry/2019/06/08/221833\n//BEGIN CUT HERE\ntemplate<typename Ap>\nstruct NodeBase{\n  using A = Ap;\n  NodeBase *l,*r,*p;\n  bool rev;\n  A val,dat,sum;\n  NodeBase(A val,A dat,A sum):\n    rev(0),val(val),dat(dat),sum(sum){\n    l=r=p=nullptr;}\n};\n\ntemplate<typename Np, size_t LIM>\nstruct Subtree : LinkCutTreeBase<Np, LIM, Subtree<Np, LIM>>{\n  using super = LinkCutTreeBase<Np, LIM, Subtree>;\n  using Node = Np;\n  using A = typename Node::A;\n\n  Node* create(A val){\n    return super::create(Node(val,A(),val));\n  }\n\n  inline void toggle(Node *t){\n    swap(t->l,t->r);\n    t->rev^=1;\n  }\n\n  inline Node* eval(Node *t){\n    if(t->rev){\n      if(t->l) toggle(t->l);\n      if(t->r) toggle(t->r);\n      t->rev=false;\n    }\n    return t;\n  }\n\n  inline A resolve(Node *t){\n    return t?t->sum:A();\n  }\n\n  inline void pushup(Node *t){\n    if(t==nullptr) return;\n    t->sum=t->val+t->dat;\n    t->sum+=resolve(t->l);\n    t->sum+=resolve(t->r);\n  }\n\n  using super::splay;\n\n  inline Node* expose(Node *t){\n    Node *rp=nullptr;\n    for(Node *c=t;c;c=c->p){\n      splay(c);\n      c->dat+=resolve(c->r);\n      c->r=rp;\n      c->dat-=resolve(c->r);\n      pushup(c);\n      rp=c;\n    }\n    splay(t);\n    return rp;\n  }\n\n  A query(Node *t){\n    expose(t);\n    return t->sum;\n  }\n\n  void set_val(Node *t,A a){\n    expose(t);\n    t->val=a;\n    pushup(t);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"../tools/fastio.cpp\"\n#undef call_from_test\n\n//INSERT ABOVE HERE\n\n// sum of square\nsigned CFR564_E(){\n  int n,m;\n  cin>>n>>m;\n  vector<vector<int>> modv(n),modt(n);\n  vector<int> cs(n);\n\n  for(int i=0;i<n;i++){\n    cin>>cs[i];\n    cs[i]--;\n    modv[cs[i]].emplace_back(i);\n    modt[cs[i]].emplace_back(0);\n  }\n\n  vector<vector<int> > G(n+1);\n  for(int i=1;i<n;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    G[a].emplace_back(b);\n    G[b].emplace_back(a);\n  }\n  G[n].emplace_back(0);\n\n  for(int i=1;i<=m;i++){\n    int v,x;\n    cin>>v>>x;\n    v--;x--;\n    modv[cs[v]].emplace_back(v);\n    modt[cs[v]].emplace_back(i);\n    cs[v]=x;\n    modv[cs[v]].emplace_back(v);\n    modt[cs[v]].emplace_back(i);\n  }\n\n  using ll = long long;\n  struct A{\n    ll sz1,sz2;\n    A():sz1(0),sz2(0){}\n    A(ll sz1,ll sz2):sz1(sz1),sz2(sz2){}\n    A operator+(const A &a)const{\n      return A(sz1+a.sz1,sz2+a.sz2);\n    };\n    A& operator+=(const A &a){\n      sz1+=a.sz1;\n      sz2+=a.sz1*a.sz1;\n      return (*this);\n    }\n    A& operator-=(const A &a){\n      sz1-=a.sz1;\n      sz2-=a.sz1*a.sz1;\n      return (*this);\n    }\n  };\n\n  using Node = NodeBase<A>;\n  constexpr size_t LIM = 1e6;\n  using LCT = Subtree<Node, LIM>;\n  LCT lct;\n\n  for(int i=0;i<n+1;i++) lct.create(A(1,0));\n\n  vector<int> par(n+1,0);\n  {\n    using P = pair<int, int>;\n    queue<P> q;\n    q.emplace(n,-1);\n    while(!q.empty()){\n      int v,p;\n      tie(v,p)=q.front();q.pop();\n      par[v]=p;\n      if(~p) lct.link(lct[p],lct[v]);\n      for(int u:G[v])\n        if(u!=p) q.emplace(u,v);\n    }\n  }\n\n  vector<ll> delta(m+1,0);\n  vector<int> color(n+1,0);\n\n  for(int c=0;c<n;c++){\n    ll lst=(ll)n*n,cur=(ll)n*n;\n    delta[0]+=lst;\n\n    if(modv[c].empty()) continue;\n    for(int i=0;i<(int)modv[c].size();i++){\n      int v=modv[c][i];\n      color[v]^=1;\n      if(color[v]){\n        cur-=lct.query(lct.root(lct[v])).sz2;\n        lct.cut(lct[v]);\n        cur+=lct.query(lct.root(lct[par[v]])).sz2;\n        cur+=lct.query(lct[v]).sz2;\n      }else{\n        cur-=lct.query(lct.root(lct[par[v]])).sz2;\n        cur-=lct.query(lct[v]).sz2;\n        lct.link(lct[par[v]],lct[v]);\n        cur+=lct.query(lct.root(lct[v])).sz2;\n      }\n      if(i+1==(int)modv[c].size() or modt[c][i]!=modt[c][i+1]){\n        delta[modt[c][i]]+=cur-lst;\n        lst=cur;\n      }\n    }\n\n    for(int i=0;i<(int)modv[c].size();i++){\n      int v=modv[c][i];\n      if(!color[v]) continue;\n      color[v]^=1;\n      lct.link(lct[par[v]],lct[v]);\n    }\n  }\n\n  ll ans=(ll)n*n*n;\n  for(int i=0;i<=m;i++){\n    ans-=delta[i];\n    cout<<ans<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n/*\n  verified on 2020/10/28\n  https://codeforces.com/contest/1172/problem/E\n*/\n\n// test root\nsigned NIKKEI2019_QUAL_E(){\n  int n,m;\n  cin>>n>>m;\n  vector<int> xs(n);\n  for(int i=0;i<n;i++) cin>>xs[i];\n  using T = tuple<int, int, int>;\n  vector<T> vt;\n  for(int i=0;i<m;i++){\n    int a,b,y;\n    cin>>a>>b>>y;\n    a--;b--;\n    vt.emplace_back(y,a,b);\n  }\n  sort(vt.begin(),vt.end());\n\n  using ll = long long;\n  using Node = NodeBase<ll>;\n  constexpr size_t LIM = 1e6;\n  using LCT = Subtree<Node, LIM>;\n  LCT lct;\n\n  for(int i=0;i<n;i++) lct.create(xs[i]);\n\n  using P = pair<int, int>;\n  set<P> es;\n  for(auto t:vt){\n    int a,b;\n    tie(ignore,a,b)=t;\n    if(lct.is_connected(lct[a],lct[b])) continue;\n    lct.evert(lct[b]);\n    lct.link(lct[a],lct[b]);\n    es.emplace(a,b);\n  }\n\n  int ans=0;\n  reverse(vt.begin(),vt.end());\n  for(auto t:vt){\n    int y,a,b;\n    tie(y,a,b)=t;\n    auto rt=lct.root(lct[a]);\n    ll sum=lct.query(rt);\n    if(sum>=y) continue;\n    ans++;\n    if(es.count(P(a,b))){\n      lct.evert(lct[a]);\n      lct.cut(lct[b]);\n    }\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n/*\n  verified on 2020/10/28\n  https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_e\n*/\n\nsigned main(){\n  //CFR564_E();\n  //NIKKEI2019_QUAL_E();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "matching/bipartite.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(N M)\nstruct Bipartite{\n  int time;\n  vector< vector<int> > G;\n  vector<int> match,used,dead;\n\n  Bipartite(int n):\n    time(0),G(n),match(n,-1),used(n,-1),dead(n,0){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  int dfs(int v){\n    used[v]=time;\n    for(int u:G[v]){\n      if(dead[u]) continue;\n      int w=match[u];\n      if((w<0) or (used[w]<time and dfs(w))){\n        match[v]=u;\n        match[u]=v;\n        return 1;\n      }\n    }\n    return 0;\n  }\n\n  int build(){\n    int res=0;\n    for(int v=0;v<(int)G.size();v++){\n      if(dead[v] or ~match[v]) continue;\n      time++;\n      res+=dfs(v);\n    }\n    return res;\n  }\n\n  int disable(int v){\n    assert(!dead[v]);\n    int u=match[v];\n    if(~u) match[u]=-1;\n    match[v]=-1;\n    dead[v]=1;\n    time++;\n    return ~u?dfs(u)-1:0;\n  }\n\n  int enable(int v){\n    assert(dead[v]);\n    dead[v]=0;\n    time++;\n    return dfs(v);\n  }\n\n  int cut_edge(int u,int v){\n    assert(find(G[u].begin(),G[u].end(),v)!=G[u].end());\n    assert(find(G[v].begin(),G[v].end(),u)!=G[v].end());\n    G[u].erase(find(G[u].begin(),G[u].end(),v));\n    G[v].erase(find(G[v].begin(),G[v].end(),u));\n    if(match[u]==v){\n      match[u]=match[v]=-1;\n      return 1;\n    }\n    return 0;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "matching/hopcroft_karp.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(E \\sqrt V)\nstruct HopcroftKarp{\n  int L,R;\n  vector< vector<int> > G;\n  vector<int> match,level;\n\n  HopcroftKarp(int L,int R):\n    L(L),R(R),G(L+R),match(L+R,-1),level(L+R){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v+L);\n    G[v+L].emplace_back(u);\n  }\n\n  bool bfs(){\n    fill(level.begin(),level.end(),-1);\n    queue<int> que;\n    for(int i=0;i<L;i++){\n      if(~match[i]) continue;\n      level[i]=0;\n      que.emplace(i);\n    }\n    bool found=false;\n    while(!que.empty()){\n      int v=que.front();que.pop();\n      for(int u:G[v]){\n        if(~level[u]) continue;\n        level[u]=level[v]+1;\n        int w=match[u];\n        if(w==-1){\n          found=true;\n          continue;\n        }\n        if(~level[w]) continue;\n        level[w]=level[u]+1;\n        que.emplace(w);\n      }\n    }\n    return found;\n  }\n\n  bool dfs(int v){\n    for(int u:G[v]){\n      if(level[v]+1!=level[u]) continue;\n      level[u]=-1;\n      int w=match[u];\n      if(w<0 or dfs(w)){\n        match[v]=u;\n        match[u]=v;\n        level[v]=-1;\n        return true;\n      }\n    }\n    level[v]=-1;\n    return false;\n  }\n\n  int build(){\n    int res=0;\n    while(bfs())\n      for(int i=0;i<L;i++)\n        if(match[i]<0 and dfs(i))\n          res++;\n    return res;\n  }\n\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "matching/tutte.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../mod/mint.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nint maximal_matching(vector< vector<int> > G){\n  int n=G.size();\n\n  random_device rd;\n  mt19937 mt(rd());\n  using M = Mint<int>;\n  uniform_int_distribution<int> ud(1,M::mod-1);\n\n  vector< vector<M> > H(n,vector<M>(n,0));\n  for(int v=0;v<n;v++){\n    for(int u:G[v]){\n      if(u>=v) continue;\n      M val(ud(mt));\n      H[u][v]= val;\n      H[v][u]=-val;\n    }\n  }\n\n  int res=0;\n  for(int i=0,j=0;i<n;i++){\n    while(j<n and H[i][j]==M(0)){\n      int p=i;\n      for(int k=i+1;k<n;k++)\n        if(H[k][j]!=M(0)) p=k;\n      if(i!=p) swap(H[i],H[p]);\n      else j++;\n    }\n    if(j==n) break;\n    M tmp=H[i][j].inv();\n    for(int s=j;s<n;s++) H[i][s]*=tmp;\n    for(int k=i+1;k<n;k++)\n      for(int s=n-1;s>=j;s--)\n        H[k][s]-=H[k][j]*H[i][s];\n\n    j++;res++;\n  }\n  return (res+1)/2;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/affine.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nnamespace Affine{\n  template<typename T>\n  T op(T a,T b){return T(a.first+b.first,a.second+b.second);}\n  template<typename T, typename E>\n  T mapping(T a,E b){return T(a.first*b.first+a.second*b.second,a.second);}\n  template<typename E>\n  E composition(E a,E b){return E(a.first*b.first,a.second*b.first+b.second);}\n\n  template<typename T> T e(){return T(0,0);};\n  template<typename E> E id(){return E(1,0);};\n\n  template<typename T, typename E>\n  decltype(auto) params(){\n    auto f=[](T a,T b){return op(a,b);};\n    auto g=[](T a,E b){return mapping(a,b);};\n    auto h=[](E a,E b){return composition(a,b);};\n    return make_tuple(f,g,h,e<T>(),id<E>());\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/bostanmori.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n// ref. https://qiita.com/ryuhe1/items/da5acbcce4ac1911f47a\n//BEGIN CUT HERE\n// Find k-th term of linear recurrence\n// execute `conv` O(\\log k) times\ntemplate<typename T>\nstruct BostanMori{\n  using Poly = vector<T>;\n  using Conv = function<Poly(Poly, Poly)>;\n\n  Conv conv;\n  BostanMori(Conv conv_):conv(conv_){}\n\n  Poly sub(Poly as,int odd){\n    Poly bs((as.size()+!odd)/2);\n    for(int i=odd;i<(int)as.size();i+=2) bs[i/2]=as[i];\n    return bs;\n  }\n\n  // as: initial values\n  // cs: monic polynomial\n  T build(long long k,Poly as,Poly cs){\n    reverse(cs.begin(),cs.end());\n    assert(cs[0]==T(1));\n    int n=cs.size()-1;\n    as.resize(n,0);\n    Poly bs=conv(as,cs);\n    bs.resize(n);\n    while(k){\n      Poly ds(cs);\n      for(int i=1;i<(int)ds.size();i+=2) ds[i]=-ds[i];\n      bs=sub(conv(bs,ds),k&1);\n      cs=sub(conv(cs,ds),0);\n      k>>=1;\n    }\n    return bs[0];\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/carmichael.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// min m s.t. a^m = 1 mod n (a, n are coprime)\ntemplate<typename T>\nT carmichael_lambda(T n){\n  T res=1;\n  if(n%8==0) n/=2;\n  for(int i=2;i*i<=n;i++){\n    if(n%i==0){\n      T tmp=i-1;\n      for(n/=i;n%i==0;n/=i) tmp*=i;\n      res=lcm(res,tmp);\n    }\n  }\n  if(n!=1) res=lcm(res,n-1);\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/combination.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"extgcd.cpp\"\n#include \"../mod/inverse.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T, size_t sz>\nstruct Combination{\n  using ll = long long;\n  array<T, sz> fact;\n\n  T mod;\n  Combination(T mod):mod(mod){init();}\n\n  void init(){\n    fact[0]=1;\n    for(int i=1;i<(int)sz;i++)\n      fact[i]=(ll)fact[i-1]*i%mod;\n  }\n\n  T mod_fact(T n,T& e){\n    e=0;\n    if(n==0) return 1;\n    T res=mod_fact(n/mod,e);\n    e+=n/mod;\n    if(n/mod%2!=0)return res*(mod-fact[n%mod])%mod;\n    return res*fact[n%mod]%mod;\n  }\n\n  T mod_comb(T n,T k){\n    if(n==k or k==0) return 1;\n    T e1,e2,e3;\n    T a1=mod_fact(n,e1),a2=mod_fact(k,e2),a3=mod_fact(n-k,e3);\n    if(e1>e2+e3) return 0;\n    return a1*mod_inverse<ll>((ll)a2*a3%mod,mod)%mod;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  string s;\n  cin>>s;\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) as[i]=s[i]-'1';\n\n  const int sz = 1e6+10;\n  Combination<int, sz> C(2);\n\n  int is_one=0;\n  for(int i=0;i<n;i++)\n    if(as[i]&1) is_one^=C.mod_comb(n-1,i);\n\n  if(is_one){\n    cout<<1<<endl;\n    return 0;\n  }\n\n  for(int i=0;i<n;i++){\n    if(as[i]==1){\n      cout<<0<<endl;\n      return 0;\n    }\n    as[i]/=2;\n  }\n\n  int is_two=0;\n  for(int i=0;i<n;i++)\n    if(as[i]&1) is_two^=C.mod_comb(n-1,i);\n\n  cout<<is_two*2<<endl;\n  return 0;\n}\n/*\n  verified on 2020/03/22\n  https://atcoder.jp/contests/agc043/tasks/agc043_b\n*/\n#endif\n"
  },
  {
    "path": "math/convertbase.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nvector<T> convert_base(T x,T b){\n  vector<T> res;\n  T t=1,k=abs(b);\n  while(x){\n    res.emplace_back((x*t)%k);\n    if(res.back()<0) res.back()+=k;\n    x-=res.back()*t;\n    x/=k;\n    t*=b/k;\n  }\n  if(res.empty()) res.emplace_back(0);\n  reverse(res.begin(),res.end());\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/dual.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct Dual{\n  T v;\n  Dual(T v=T()):v(v){}\n  Dual operator+(const Dual &o)const{return Dual(o.v+v);}\n  Dual operator*(const Dual &o)const{return Dual(o.v*v);}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/enumerate_primes.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(n)\nvector<int> enumerate_primes(int n){\n  vector<bool> dp((n+1)/2,false);\n  vector<int> ps;\n  ps.reserve(n/10);\n  if(2<=n) ps.emplace_back(2);\n  for(int i=3;i<=n;i+=2){\n    if(!dp[i/2]) ps.emplace_back(i);\n    for(int j=1;i*ps[j]<=n;j++){\n      dp[i*ps[j]/2]=1;\n      if(i%ps[j]==0) break;\n    }\n  }\n  return ps;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/extgcd.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// find (x, y) s.t. ax + by = gcd(a, b), minimize |x| + |y|\n// |x| <= b, |y| <= a\n// return gcd(a, b)\ntemplate<typename T>\nT extgcd(T a,T b,T& x,T& y){\n  T d=a;\n  if(b!=0){\n    d=extgcd(b,a%b,y,x);\n    y-=(a/b)*x;\n  }else{\n    x=1;y=0;\n  }\n  return d;\n}\ntemplate<typename T>\npair<T, T> extgcd(T a,T b){\n  T x,y;\n  extgcd(a,b,x,y);\n  return make_pair(x,y);\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/factorize.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nmap<T, int> factorize(T x){\n  map<T, int> res;\n  for(int i=2;i*i<=x;i++){\n    while(x%i==0){\n      x/=i;\n      res[i]++;\n    }\n  }\n  if(x!=1) res[x]++;\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/fraction.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct fraction{\n  T num,den;\n  fraction(T n,T d):num(n),den(d){\n    assert(den!=0);\n    if(den<0) num*=-1,den*=-1;\n    T tmp=gcd(abs(num),abs(den));\n    num/=tmp;\n    den/=tmp;\n  }\n  const fraction operator+(const fraction& a) const{\n    return fraction(num*a.den+a.num*den,den*a.den);\n  }\n  const fraction operator-(const fraction& a) const{\n    return fraction(num*a.den-a.num*den,den*a.den);\n  }\n  const fraction operator*(const fraction& a) const{\n    return fraction(num*a.num,den*a.den);\n  }\n  const fraction operator/(const fraction& a) const{\n    return fraction(num*a.den,den*a.num);\n  }\n  const fraction operator*(T k) const{return fraction(num*k,den);}\n  const fraction operator/(T k) const{return fraction(num,den*k);}\n#define define_cmp(op) \\\n  bool operator op (const fraction& a) const{return num*a.den op a.num*den;}\n  define_cmp(==)\n  define_cmp(!=)\n  define_cmp(<)\n  define_cmp(>)\n  define_cmp(<=)\n  define_cmp(>=)\n#undef define_cmp\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/isprime.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nint isprime(T x){\n  if(x<=1) return 0;\n  for(T i=2;i*i<=x;i++)\n    if(x%i==0) return 0;\n  return 1;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/kitamasa.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename R>\nstruct Kitamasa{\n  using VR = vector<R>;\n  VR cs;\n  vector<VR> rs;\n  int m;\n\n  Kitamasa(const VR &C)\n    :cs(C),rs(1),m(C.size()){\n    rs[0].assign(2*m+1,R::add_identity());\n    rs[0][1]=R::mul_identity();\n  }\n\n  VR merge(const VR &xs,const VR &ys){\n    VR zs(2*m+1,R::add_identity());\n    for(int i=1;i<=m;i++)\n      for(int j=1;j<=m;j++)\n        zs[i+j]=zs[i+j]+(xs[i]*ys[j]);\n\n    for(int i=2*m;i>m;zs[i--]=R::add_identity())\n      for(int j=1;j<=m;j++)\n        zs[i-j]=zs[i-j]+(cs[m-j]*zs[i]);\n    return zs;\n  }\n\n  R calc(const VR &A,long long n){\n    assert((int)A.size()==m);\n    VR res(rs[0]);\n    for(int i=0;n;i++,n>>=1){\n      if(i>=(int)rs.size())\n        rs.emplace_back(merge(rs[i-1],rs[i-1]));\n      if(~n&1) continue;\n      res=merge(res,rs[i]);\n    }\n    R ans=R::add_identity();\n    for(int i=1;i<=m;i++) ans=ans+(res[i]*A[i-1]);\n    return ans;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned ABC009_D(){\n  int k,m;\n  scanf(\"%d %d\",&k,&m);\n\n  struct M{\n    uint32_t v;\n    M(){*this=add_identity();}\n    M(uint32_t v):v(v){}\n    M operator+(const M &a)const{return M(v^a.v);}\n    M operator*(const M &a)const{return M(v&a.v);}\n    static M add_identity(){return M(0);}\n    static M mul_identity(){return M(~0u);}\n  };\n\n  vector<M> as(k),cs(k);\n  for(int i=0;i<k;i++) scanf(\"%u\",&as[i].v);\n  for(int i=0;i<k;i++) scanf(\"%u\",&cs[k-(i+1)].v);\n  Kitamasa<M> v(cs);\n\n  printf(\"%u\\n\",v.calc(as,--m).v);\n  return 0;\n}\n/*\n  verified on 2020/10/13\n  https://atcoder.jp/contests/abc009/tasks/abc009_4\n*/\n\nsigned main(){\n  ABC009_D();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/linearcongruence.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"extgcd.cpp\"\n#include \"../mod/inverse.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\npair<T, T> linear_congruence(const vector<T> &A,\n                             const vector<T> &B,\n                             const vector<T> &M){\n  T x=0,m=1;\n  for(int i=0;i<(int)A.size();i++){\n    T a=A[i]*m,b=B[i]-A[i]*x,d=__gcd(M[i],a);\n    if(b%d!=0) return make_pair(0,-1);\n    T t=b/d*mod_inverse(a/d,M[i]/d)%(M[i]/d);\n    x=x+m*t;\n    m*=M[i]/d;\n  }\n  return make_pair((x%m+m)%m,m);\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/linearfunction.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// a * x + b\ntemplate<typename T>\nstruct LinearFunction{\n  T a,b;\n  LinearFunction():a(0),b(0){}\n  LinearFunction(T a,T b):a(a),b(b){}\n\n  using LF = LinearFunction;\n  static LF add_identity(){return LF(T(0),T(0));}\n  static LF mul_identity(){return LF(T(1),T(0));}\n  LF& operator+=(const LF &o){\n    a+=o.a;b+=o.b;\n    return *this;\n  }\n  LF& operator*=(const LF &o){\n    a=a*o.a;\n    b=b*o.a+o.b;\n    return *this;\n  }\n  LF operator+(const LF &o)const{return LF(*this)+=o;}\n  LF operator*(const LF &o)const{return LF(*this)*=o;}\n\n  T operator()(T x) const{return a*x+b;}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/moebius.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// [0, n]\nvector<int> moebius(int n){\n  n++;\n  vector<int> pr(n),sq(n);\n  using ll = long long;\n  for(ll i=2;i<n;i++){\n    if(pr[i]) continue;\n    for(ll j=i;j<n;j+=i) pr[j]=i;\n    for(ll j=i*i;j<n;j+=i*i) sq[j]=1;\n  }\n  vector<int> sign(n,0);\n  sign[1]=1;\n  for(ll i=2;i<n;i++){\n    if(sq[i]) continue;\n    sign[i]=-sign[i/pr[i]];\n  }\n  return sign;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/quotients.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// split [1, n] into ranges whose elements have same quotients\ntemplate<typename T>\ndecltype(auto) quotients(T n){\n  vector<pair<T, T>> vp;\n  T m;\n  for(m=1;m*m<=n;m++) vp.emplace_back(m,m);\n  for(T i=m;i>=1;i--){\n    T l=n/(i+1)+1,r=n/i;\n    if(l<=r and vp.back().second<l)\n      vp.emplace_back(l,r);\n  }\n  return vp;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/sum_of_floor.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// sum_{i=0}^{n-1} (ai + b) // m\n// 0 <= a, b\ntemplate<typename T>\nT sum_of_floor(T n,T m,T a,T b){\n  T res=0;\n  if(a>=m){\n    res+=(n-1)*n*(a/m)/2;\n    a%=m;\n  }\n  if(b>=m){\n    res+=n*(b/m);\n    b%=m;\n  }\n  T y=(a*n+b)/m;\n  T x=y*m-b;\n  if(y==0) return res;\n  res+=(n-(x+a-1)/a)*y;\n  res+=sum_of_floor(y,a,m,(a-x%a)%a);\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/sum_of_geometric_sequence.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// first: sum_{i=0}^{n-1} r^i\n// second: r^n\ntemplate<typename T>\npair<T, T> sum_of_geometric_sequence_impl(T r,long long n){\n  if(n==1) return {T(1),r};\n  auto p=sum_of_geometric_sequence_impl(r,n/2);\n  T sum=p.first*(T(1)+p.second);\n  T pow=p.second*p.second;\n  if(n&1) sum+=pow,pow*=r;\n  return {sum,pow};\n}\n// sum_{i=0}^{n-1} r^i\ntemplate<typename T>\nT sum_of_geometric_sequence(T r,long long n){\n  return sum_of_geometric_sequence_impl(r,n).first;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/tetrahedra.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../linearalgebra/matrix.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nbool isTriangle(double a1,double a2,double a3){\n  if(a1+a2<=a3 or a2+a3<=a1 or a3+a1<=a2) return 0;\n  return 1;\n}\n\ndouble tetrahedra(double OA,double OB,double OC,\n                  double AB,double AC,double BC){\n  if(!isTriangle(OA,OB,AB)) return 0;\n  if(!isTriangle(OB,OC,BC)) return 0;\n  if(!isTriangle(OC,OA,AC)) return 0;\n  if(!isTriangle(AB,AC,BC)) return 0;\n  Matrix<double> A(5,5);\n  A[0][0]=    0;A[0][1]=AB*AB;A[0][2]=AC*AC;A[0][3]=OA*OA;A[0][4]=1;\n  A[1][0]=AB*AB;A[1][1]=    0;A[1][2]=BC*BC;A[1][3]=OB*OB;A[1][4]=1;\n  A[2][0]=AC*AC;A[2][1]=BC*BC;A[2][2]=    0;A[2][3]=OC*OC;A[2][4]=1;\n  A[3][0]=OA*OA;A[3][1]=OB*OB;A[3][2]=OC*OC;A[3][3]=    0;A[3][4]=1;\n  A[4][0]=    1;A[4][1]=    1;A[4][2]=    1;A[4][3]=    1;A[4][4]=0;\n  double res=A.determinant();\n  if(res<=0) return 0;\n  return sqrt(res/288.0);\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/totient.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nT totient(T n){\n  T res=n;\n  for(T i=2;i*i<=n;i++){\n    if(n%i) continue;\n    res=res/i*(i-1);\n    while(n%i==0) n/=i;\n  }\n  if(n!=1) res=res/n*(n-1);\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/totient_table.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nvector<int> totient_table(int n){\n  vector<int> ts(n+1);\n  iota(ts.begin(),ts.end(),0);\n  for(int i=2;i<=n;i++){\n    if(ts[i]!=i) continue;\n    for(int j=i;j<=n;j+=i) ts[j]=ts[j]/i*(i-1);\n  }\n  return ts;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "math/twoway.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct TwoWay{\n  T x,y;\n  TwoWay(T z=T()):x(z),y(z){}\n  TwoWay(T x,T y):x(x),y(y){}\n  TwoWay operator+(const TwoWay &o)const{return TwoWay(x+o.x,o.y+y);}\n  TwoWay operator*(const TwoWay &o)const{return TwoWay(x*o.x,o.y*y);}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "maxflow/dinic.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(E V^2)\n// O(E \\min(E^{1/2}, V^{2/3})) if caps are constant\ntemplate<typename Flow,bool directed>\nstruct Dinic{\n  struct Edge {\n    int dst;\n    Flow cap;\n    int rev;\n    Edge(int dst,Flow cap,int rev):dst(dst),cap(cap),rev(rev){}\n  };\n\n  vector< vector<Edge> > G;\n  vector<int> level,iter;\n\n  Dinic(int n):G(n),level(n),iter(n){}\n\n  int add_edge(int src,int dst,Flow cap){\n    int e=G[src].size();\n    int r=(src==dst?e+1:G[dst].size());\n    G[src].emplace_back(dst,cap,r);\n    G[dst].emplace_back(src,directed?0:cap,e);\n    return e;\n  }\n\n  void bfs(int s){\n    fill(level.begin(),level.end(),-1);\n    queue<int> que;\n    level[s]=0;\n    que.emplace(s);\n    while(!que.empty()){\n      int v=que.front();que.pop();\n      for(Edge &e : G[v]) {\n        if(e.cap>0 and level[e.dst]<0){\n          level[e.dst]=level[v]+1;\n          que.emplace(e.dst);\n        }\n      }\n    }\n  }\n\n  Flow dfs(int v,int t,Flow f){\n    if(v==t) return f;\n    for(int &i=iter[v];i<(int)G[v].size();i++){\n      Edge &e=G[v][i];\n      if(e.cap>0 and level[v]<level[e.dst]){\n        Flow d=dfs(e.dst,t,min(f,e.cap));\n        if(d==0) continue;\n        e.cap-=d;\n        G[e.dst][e.rev].cap+=d;\n        return d;\n      }\n    }\n    return 0;\n  }\n\n  Flow flow(int s,int t,Flow lim){\n    Flow fl=0;\n    while(1){\n      bfs(s);\n      if(level[t]<0 or lim==0) break;\n      fill(iter.begin(),iter.end(),0);\n\n      while(1){\n        Flow f=dfs(s,t,lim);\n        if(f==0) break;\n        fl+=f;\n        lim-=f;\n      }\n    }\n    return fl;\n  }\n\n  Flow flow(int s,int t){\n    return flow(s,t,numeric_limits<Flow>::max()/2);\n  }\n\n  Flow cut(int s,int t,int x,int a){\n    static_assert(directed, \"must be directed\");\n    auto &e=G[x][a];\n    int y=e.dst;\n    Flow cr=G[y][e.rev].cap;\n    if(cr==0) return e.cap=0;\n    e.cap=G[y][e.rev].cap=0;\n    Flow cap=cr-flow(x,y,cr);\n    if(x!=s and cap!=0) flow(x,s,cap);\n    if(t!=y and cap!=0) flow(t,y,cap);\n    return cap;\n  }\n\n  Flow link(int s,int t,int x,int a,Flow f){\n    auto &e=G[x][a];\n    e.cap+=f;\n    return flow(s,t,f);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "maxflow/fordfulkerson.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(F E)\ntemplate<typename Flow, bool directed>\nstruct FordFulkerson{\n  struct Edge{\n    int dst;\n    Flow cap;\n    int rev;\n    Edge(int dst,Flow cap,int rev):dst(dst),cap(cap),rev(rev){}\n  };\n\n  vector< vector<Edge> > G;\n  vector<int> used;\n\n  FordFulkerson(int n):G(n),used(n){}\n\n  int add_edge(int src,int dst,Flow cap){\n    int e=G[src].size();\n    int r=(src==dst?e+1:G[dst].size());\n    G[src].emplace_back(dst,cap,r);\n    G[dst].emplace_back(src,directed?0:cap,e);\n    return e;\n  }\n\n  Flow dfs(int v,int t,Flow f){\n    if(v==t) return f;\n    used[v]=true;\n    for(Edge &e:G[v]){\n      if(used[e.dst] or e.cap==0) continue;\n      Flow d=dfs(e.dst,t,min(f,e.cap));\n      if(d==0) continue;\n      e.cap-=d;\n      G[e.dst][e.rev].cap+=d;\n      return d;\n    }\n    return 0;\n  }\n\n  Flow flow(int s,int t,Flow lim){\n    Flow res=0;\n    while(1){\n      fill(used.begin(),used.end(),0);\n      Flow f=dfs(s,t,lim);\n      if(f==0) break;\n      res+=f;\n      lim-=f;\n    }\n    return res;\n  }\n\n  Flow flow(int s,int t){\n    return flow(s,t,numeric_limits<Flow>::max()/2);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "maxflow/leastflow.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"dinic.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct LeastFlow{\n  Dinic<T, true> G;\n  int X,Y;\n  T sum;\n  LeastFlow(int n):G(n+2),X(n),Y(n+1),sum(0){}\n\n  void add_edge(int from,int to,T low,T hgh){\n    assert(low<=hgh);\n    G.add_edge(from,to,hgh-low);\n    G.add_edge(X,to,low);\n    G.add_edge(from,Y,low);\n    sum+=low;\n  }\n\n  T flow(int s,int t){\n    T a=G.flow(X,Y);\n    T b=G.flow(s,Y);\n    T c=G.flow(X,t);\n    T d=G.flow(s,t);\n    return (b==c and a+b==sum)?b+d:T(-1);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "maxflow/twocommodity.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"./dinic.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename Flow, bool directed>\nstruct TwoCommodity{\n  Dinic<Flow, directed> G,H;\n  int S,T;\n  TwoCommodity(int n):G(n+2),H(n+2),S(n),T(n+1){}\n\n  void add_edge(int src,int dst,Flow cap){\n    G.add_edge(src,dst,cap);\n    H.add_edge(src,dst,cap);\n  }\n\n  // maximize sum of two flows (s -> t) and (u -> v)\n  Flow build(int s,int t,int u,int v){\n    const Flow INF = numeric_limits<Flow>::max()/4;\n\n    G.add_edge(S,s,INF);\n    G.add_edge(S,u,INF);\n    G.add_edge(t,T,INF);\n    G.add_edge(v,T,INF);\n\n    H.add_edge(S,s,INF);\n    H.add_edge(S,v,INF);\n    H.add_edge(t,T,INF);\n    H.add_edge(u,T,INF);\n\n    return min(G.flow(S,T),H.flow(S,T));\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mincostflow/negativeedge.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"primaldual.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n// O((F+F') E \\log V), F': sum of caps with negative cost\ntemplate<typename Flow, typename Cost>\nstruct NegativeEdge{\n  PrimalDual<Flow, Cost> G;\n  vector<Flow> fs;\n  Cost sum;\n  int S,T;\n  NegativeEdge(int n):G(n+2),fs(n+2,0),sum(0),S(n),T(n+1){}\n\n  void use_edge(int u,int v,Flow cap,Cost cost){\n    fs[u]-=cap;\n    fs[v]+=cap;\n    sum=sum+cost*cap;\n  }\n\n  void add_edge(int u,int v,Flow cap,Cost cost){\n    if(cost<Cost(0)){\n      use_edge(u,v,cap,cost);\n      swap(u,v);\n      cost=-cost;\n    }\n    G.add_edge(u,v,cap,cost);\n  }\n\n  bool build(){\n    Flow f=0;\n    for(int i=0;i<S;i++){\n      if(fs[i]>0){\n        f+=fs[i];\n        G.add_edge(S,i,+fs[i],Cost(0));\n      }\n      if(fs[i]<0){\n        G.add_edge(i,T,-fs[i],Cost(0));\n      }\n    }\n    return G.build(S,T,f);\n  }\n\n  bool build(int ts,int tt,Flow tf){\n    fs[ts]+=tf;\n    fs[tt]-=tf;\n    return build();\n  }\n\n  Cost get_cost(){\n    return sum+G.get_cost();\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mincostflow/primaldual.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(F E \\log V)\ntemplate<typename Flow, typename Cost>\nstruct PrimalDual{\n  struct Edge{\n    int dst;\n    Flow cap;\n    Cost cost;\n    int rev;\n    Edge(int dst,Flow cap,Cost cost,int rev):\n      dst(dst),cap(cap),cost(cost),rev(rev){}\n  };\n\n  vector<vector<Edge>> G;\n  vector<Cost> h,dist;\n  vector<int> prevv,preve;\n\n  PrimalDual(int n):G(n),h(n),dist(n),prevv(n),preve(n){}\n\n  void add_edge(int u,int v,Flow cap,Cost cost){\n    int e=G[u].size();\n    int r=(u==v?e+1:G[v].size());\n    G[u].emplace_back(v,cap,cost,r);\n    G[v].emplace_back(u,0,-cost,e);\n  }\n\n  Cost residual_cost(int src,Edge &e){\n    return e.cost+h[src]-h[e.dst];\n  }\n\n  void dijkstra(int s){\n    struct P{\n      Cost first;\n      int second;\n      P(Cost first,int second):first(first),second(second){}\n      bool operator<(const P&a) const{return first>a.first;}\n    };\n    priority_queue<P> pq;\n\n    dist[s]=0;\n    pq.emplace(dist[s],s);\n    while(!pq.empty()){\n      P p=pq.top();pq.pop();\n      int v=p.second;\n      if(dist[v]<p.first) continue;\n      for(int i=0;i<(int)G[v].size();i++){\n        Edge &e=G[v][i];\n        if(e.cap==0) continue;\n        if(!(dist[v]+residual_cost(v,e)<dist[e.dst])) continue;\n        dist[e.dst]=dist[v]+e.cost+h[v]-h[e.dst];\n        prevv[e.dst]=v;\n        preve[e.dst]=i;\n        pq.emplace(dist[e.dst],e.dst);\n      }\n    }\n  }\n\n  Cost res;\n\n  bool build(int s,int t,Flow f,\n             function<void(decltype(h)&)> init=[](decltype(h) &p){\n               fill(p.begin(),p.end(),0);\n             }){\n    res=0;\n    init(h);\n    const Cost INF = numeric_limits<Cost>::max();\n    while(f>0){\n      fill(dist.begin(),dist.end(),INF);\n      dijkstra(s);\n      if(dist[t]==INF) return false;\n\n      for(int v=0;v<(int)h.size();v++)\n        if(dist[v]<INF) h[v]=h[v]+dist[v];\n\n      Flow d=f;\n      for(int v=t;v!=s;v=prevv[v])\n        d=min(d,G[prevv[v]][preve[v]].cap);\n\n      f-=d;\n      res=res+h[t]*d;\n      for(int v=t;v!=s;v=prevv[v]){\n        Edge &e=G[prevv[v]][preve[v]];\n        e.cap-=d;\n        G[v][e.rev].cap+=d;\n      }\n    }\n    return true;\n  }\n\n  Cost get_cost(){return res;}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/factorial.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../mod/mint.cpp\"\n#include \"../convolution/numbertheoretictransform.cpp\"\n#include \"../convolution/garner.cpp\"\n#include \"../mod/rint.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n// MOD: prime\nint factorial(long long n,const int MOD){\n  if(n>=MOD) return 0;\n  Garner arb;\n  using R = Rint<int>;\n  R::set_mod(MOD);\n\n  int d=1<<15;\n  vector<R> fact(d*2+1,1),finv(d*2+1,1);\n  for(int i=1;i<=d*2;i++) fact[i]=fact[i-1]*R(i);\n  finv[d*2]=fact[d*2].inv();\n  for(int i=d*2-1;i>=0;i--) finv[i]=finv[i+1]*R(i+1);\n\n  vector<R> seq({1,d+1});\n  seq.reserve(d+1);\n\n  int sz=1;\n  while(sz<d){\n    vector<R> aux(sz,1);\n    vector<R> f(sz*4,0),g(sz*4,0);\n    for(int i=0;i<=sz;i++){\n      f[i]=finv[i]*finv[sz-i]*seq[i];\n      if(((sz+i)&1) and (f[i].v!=0)) f[i]=-f[i];\n    }\n\n    vector<R> pf(f);\n    vector<R> as;\n    as.emplace_back(R(sz+1));\n    as.emplace_back(R(sz)/R(d));\n    as.emplace_back(R(sz)/R(d)+R(sz+1));\n\n    for(int idx=0;idx<3;idx++){\n      for(int i=0;i<sz*4;i++) f[i]=pf[i];\n      for(int i=1;i<sz*2+2;i++)\n        g[i]=(as[idx]-R(sz-i+1)).inv();\n      f=arb.multiply(f,g);\n      f.resize(sz*4);\n\n      R prod=1;\n      for(int i=0;i<=sz;i++) prod*=as[idx]-R(i);\n\n      for(int i=0;i<=sz;i++){\n        f[sz+i+1]*=prod;\n        prod*=as[idx]+R(i+1);\n        prod/=as[idx]-R(sz-i);\n      }\n      if(idx==0){\n        for(int i=0;i<sz;i++)\n          aux[i]=f[sz+i+1];\n      }\n      if(idx==1){\n        for(int i=0;i<=sz;i++)\n          seq[i]*=f[sz+i+1];\n      }\n      if(idx==2){\n        for(int i=0;i<sz;i++)\n          aux[i]*=f[sz+i+1];\n      }\n    }\n    for(R x:aux) seq.emplace_back(x);\n    sz<<=1;\n  }\n\n  using ll = long long;\n  R res=1;\n  int l=min((ll)d,(n+1)/d);\n  for(ll i=0;i<l;i++) res*=seq[i];\n  for(ll i=l*d+1;i<=n;i++) res*=R(i);\n  return res.v;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/inverse.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../math/extgcd.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n// a, MOD coprime\ntemplate<typename T>\nT mod_inverse(T a,const T MOD){\n  T x,y;\n  extgcd(a,MOD,x,y);\n  return (x%MOD+MOD)%MOD;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/log.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// find x s.t. a^x = b (x >= 0)\n// return MOD if not found\n// MOD can be composite numbers\ntemplate<typename T>\nT mod_log(T a,T b,const T MOD){\n  using ll = long long;\n  ll g=1;\n  {\n    ll m=MOD;\n    while(m){\n      g=(ll)g*a%MOD;\n      m>>=1;\n    }\n  }\n  g=__gcd(g,(ll)MOD);\n  ll c=0,t=1;\n  while(t%g){\n    if(t==b) return c;\n    t=t*a%MOD;\n    c++;\n  }\n  // not found\n  if(b%g) return MOD;\n  t/=g;b/=g;\n  const ll n=MOD/g;\n  ll h=0,gs=1;\n  while(h*h<n){\n    gs=gs*a%n;\n    ++h;\n  }\n  unordered_map<ll, ll> bs;\n  {\n    ll s=0,e=b;\n    while(s<h){\n      e=e*a%n;\n      bs[e]=++s;\n    }\n  }\n  {\n    ll s=0,e=t;\n    while(s<n){\n      e=e*gs%n;\n      s+=h;\n      if(bs.count(e))\n        return c+s-bs[e];\n    }\n  }\n  // not found\n  return MOD;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/mint.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T, T MOD = 1000000007>\nstruct Mint{\n  inline static constexpr T mod = MOD;\n  T v;\n  Mint():v(0){}\n  Mint(signed v):v(v){}\n  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}\n\n  Mint pow(long long k){\n    Mint res(1),tmp(v);\n    while(k){\n      if(k&1) res*=tmp;\n      tmp*=tmp;\n      k>>=1;\n    }\n    return res;\n  }\n\n  static Mint add_identity(){return Mint(0);}\n  static Mint mul_identity(){return Mint(1);}\n\n  Mint inv(){return pow(MOD-2);}\n\n  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}\n  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}\n  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}\n  Mint& operator/=(Mint a){return (*this)*=a.inv();}\n\n  Mint operator+(Mint a) const{return Mint(v)+=a;}\n  Mint operator-(Mint a) const{return Mint(v)-=a;}\n  Mint operator*(Mint a) const{return Mint(v)*=a;}\n  Mint operator/(Mint a) const{return Mint(v)/=a;}\n\n  Mint operator+() const{return *this;}\n  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}\n\n  bool operator==(const Mint a)const{return v==a.v;}\n  bool operator!=(const Mint a)const{return v!=a.v;}\n\n  static Mint comb(long long n,int k){\n    Mint num(1),dom(1);\n    for(int i=0;i<k;i++){\n      num*=Mint(n-i);\n      dom*=Mint(i+1);\n    }\n    return num/dom;\n  }\n};\ntemplate<typename T, T MOD>\nostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/montmort.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// number of permutations with p_i != i\ntemplate<typename T>\nstruct Montmort{\n  using ll = long long;\n  vector<T> dp;\n\n  // MOD can be composite numbers\n  Montmort(int n,const int MOD):dp(n+1,0){\n    for(int k=2;k<=n;k++){\n      dp[k]=(ll)dp[k-1]*k%MOD;\n      if(~k&1) dp[k]+=1;\n      else dp[k]+=MOD-1;\n      if(dp[k]>=MOD) dp[k]-=MOD;\n    }\n  }\n\n  T operator[](int n){return dp[n];}\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/order.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"pow.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n// mod can be composite numbers\ntemplate<typename T>\nT order(T x,const T MOD){\n  static map<T, vector<T>> dp;\n  static map<T, T> phi;\n\n  vector<T> &ps=dp[MOD];\n  if(ps.empty()){\n    T res=MOD,n=MOD;\n    for(T i=2;i*i<=n;i++){\n      if(n%i) continue;\n      while(n%i==0) n/=i;\n      res=res/i*(i-1);\n    }\n    if(n!=1) res=res/n*(n-1);\n    phi[MOD]=res;\n\n    for(T i=2;i*i<=res;i++){\n      if(res%i) continue;\n      while(res%i==0) res/=i;\n      ps.emplace_back(i);\n    }\n    if(res!=1) ps.emplace_back(res);\n  }\n\n  T res=phi[MOD];\n  for(T p:ps){\n    while(res%p==0){\n      if(mod_pow(x,res/p,MOD)!=1) break;\n      res/=p;\n    }\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/pow.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// MOD can be composite numbers\ntemplate<typename T>\nT mod_pow(T a,long long n,const T MOD){\n  using ll = long long;\n  T res(1);\n  while(n){\n    if(n&1) res=(ll)res*a%MOD;\n    a=(ll)a*a%MOD;\n    n>>=1;\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/rint.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct Rint{\n  inline static T mod;\n  static void set_mod(T nmod){mod=nmod;}\n\n  T v;\n  Rint():v(0){}\n  Rint(signed v):v(v){}\n  Rint(long long t){v=t%mod;if(v<0) v+=mod;}\n\n  Rint pow(long long k){\n    Rint res(1),tmp(v);\n    while(k){\n      if(k&1) res*=tmp;\n      tmp*=tmp;\n      k>>=1;\n    }\n    return res;\n  }\n\n  static Rint add_identity(){return Rint(0);}\n  static Rint mul_identity(){return Rint(1);}\n\n  Rint inv(){return pow(mod-2);}\n\n  Rint& operator+=(Rint a){v+=a.v;if(v>=mod)v-=mod;return *this;}\n  Rint& operator-=(Rint a){v+=mod-a.v;if(v>=mod)v-=mod;return *this;}\n  Rint& operator*=(Rint a){v=1LL*v*a.v%mod;return *this;}\n  Rint& operator/=(Rint a){return (*this)*=a.inv();}\n\n  Rint operator+(Rint a) const{return Rint(v)+=a;}\n  Rint operator-(Rint a) const{return Rint(v)-=a;}\n  Rint operator*(Rint a) const{return Rint(v)*=a;}\n  Rint operator/(Rint a) const{return Rint(v)/=a;}\n\n  Rint operator-() const{return v?Rint(mod-v):Rint(v);}\n\n  bool operator==(const Rint a)const{return v==a.v;}\n  bool operator!=(const Rint a)const{return v!=a.v;}\n  bool operator <(const Rint a)const{return v <a.v;}\n};\ntemplate<typename T>\nostream& operator<<(ostream &os,Rint<T> m){os<<m.v;return os;}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/sqrt.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nint jacobi(T a,T m){\n  int s=1;\n  if(a<0) a=a%m+m;\n  while(m>1){\n    a%=m;\n    if(a==0) return 0;\n    int r=__builtin_ctz(a);\n    if((r&1) and ((m+2)&4)) s=-s;\n    a>>=r;\n    if(a&m&2) s=-s;\n    swap(a,m);\n  }\n  return s;\n}\n\n// MOD: prime\ntemplate<typename T>\nvector<T> mod_sqrt(T a,const T MOD){\n  if(MOD==2) return {a&1};\n  int j=jacobi(a,MOD);\n  if(j== 0) return {0};\n  if(j==-1) return {};\n\n  using ll = long long;\n  mt19937 mt;\n  ll b,d;\n  while(1){\n    b=mt()%MOD;\n    d=(b*b-a)%MOD;\n    if(d<0) d+=MOD;\n    if(jacobi<ll>(d,MOD)==-1) break;\n  }\n\n  ll f0=b,f1=1,g0=1,g1=0;\n  for(ll e=(MOD+1)>>1;e;e>>=1){\n    if(e&1){\n      ll tmp=(g0*f0+d*((g1*f1)%MOD))%MOD;\n      g1=(g0*f1+g1*f0)%MOD;\n      g0=tmp;\n    }\n    ll tmp=(f0*f0+d*((f1*f1)%MOD))%MOD;\n    f1=(2*f0*f1)%MOD;\n    f0=tmp;\n  }\n  if(g0>MOD-g0) g0=MOD-g0;\n  return {T(g0),T(MOD-g0)};\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "mod/tetration.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../math/totient.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nT mpow(T a,T n,T m,T &f){\n  using ull = unsigned long long;\n  if(a==1 or n==0) return 1;\n  ull v=1,x=a,z=m;\n  f|=x>=z;\n  x%=m;\n  while(1){\n    if(n&1) v*=x;\n    if(v>=z) f=1,v%=m;\n    n>>=1;\n    if(!n) break;\n    x=x*x;\n    if(x>=z) f=1,x%=m;\n  }\n  return v;\n}\n\n// a^a^a^... (repeat n times)\n// MOD can be composite numbers\ntemplate<typename T>\nT tetration(T a,T n,const T MOD,T &f){\n  if(a==0) return ~n&1;\n  if(MOD==1) return f=1;\n  if(a==1 or n==0) return 1;\n  if(n==1){\n    f|=a>=MOD;\n    return a%MOD+f*MOD;\n  }\n  T z=tetration(a,n-1,totient(MOD),f);\n  T r=mpow(a,z,MOD,f);\n  return r+f*MOD;\n}\n\n// MOD can be composite numbers\ntemplate<typename T>\nT tetration(T a,T n,const T MOD){\n  T f=0;\n  return tetration(a,n,MOD,f)%MOD;\n}\n\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "polynomial/berlekampmassey.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// construct a charasteristic equation from sequence\n// return a monic polynomial in O(n^2)\ntemplate<typename T>\nvector<T> berlekamp_massey(vector<T> &as){\n  using Poly = vector<T>;\n  int n=as.size();\n  Poly bs({-T(1)}),cs({-T(1)});\n  T y(1);\n  for(int ed=1;ed<=n;ed++){\n    int l=cs.size(),m=bs.size();\n    T x(0);\n    for(int i=0;i<l;i++) x+=cs[i]*as[ed-l+i];\n    bs.emplace_back(0);\n    m++;\n    if(x==T(0)) continue;\n    T freq=x/y;\n    if(m<=l){\n      for(int i=0;i<m;i++)\n        cs[l-1-i]-=freq*bs[m-1-i];\n      continue;\n    }\n    auto ts=cs;\n    cs.insert(cs.begin(),m-l,T(0));\n    for(int i=0;i<m;i++) cs[m-1-i]-=freq*bs[m-1-i];\n    bs=ts;\n    y=x;\n  }\n  for(auto &c:cs) c/=cs.back();\n  return cs;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "polynomial/hash.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../mod/mint.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T,typename M1,typename M2,typename M3>\nstruct PolynomialHash{\n  struct V{\n    M1 v1;\n    M2 v2;\n    M3 v3;\n    V(int x):v1(x),v2(x),v3(x){}\n    V(long long x):v1(x),v2(x),v3(x){}\n    V(M1 v1,M2 v2,M3 v3):v1(v1),v2(v2),v3(v3){}\n\n    V& operator+=(V a){v1+=a.v1;v2+=a.v2;v3+=a.v3;;return *this;}\n    V& operator-=(V a){v1-=a.v1;v2-=a.v2;v3-=a.v3;;return *this;}\n    V& operator*=(V a){v1*=a.v1;v2*=a.v2;v3*=a.v3;;return *this;}\n    V& operator/=(V a){v1/=a.v1;v2/=a.v2;v3/=a.v3;;return *this;}\n\n    V operator+(V a) const{return V(*this)+=a;}\n    V operator-(V a) const{return V(*this)-=a;}\n    V operator*(V a) const{return V(*this)*=a;}\n    V operator/(V a) const{return V(*this)/=a;}\n\n    tuple<M1, M2, M3> norm() const{return make_tuple(v1,v2,v3);}\n\n    bool operator==(const V a)const{return norm()==a.norm();}\n    bool operator!=(const V a)const{return norm()!=a.norm();}\n    bool operator <(const V a)const{return norm() <a.norm();}\n  };\n  const T BASE = 1777771;\n\n  vector<M1> po1,op1;\n  vector<M2> po2,op2;\n  vector<M3> po3,op3;\n\n  template<typename M>\n  void init(int n,vector<M>& po,vector<M>& op){\n    po.assign(n+1,1);\n    op.assign(n+1,1);\n    M x(BASE);\n    M y=M(x).inv();\n    for(int i=1;i<=(int)n;i++) po[i]=po[i-1]*x;\n    for(int i=1;i<=(int)n;i++) op[i]=op[i-1]*y;\n  }\n\n  PolynomialHash(size_t n){\n    init(n,po1,op1);\n    init(n,po2,op2);\n    init(n,po3,op3);\n  }\n\n  V build(const vector<T> &v){\n    int n=v.size();\n    M1 r1;M2 r2;M3 r3;\n    for(int i=0;i<n;i++){\n      r1+=M1(v[i])*po1[i];\n      r2+=M2(v[i])*po2[i];\n      r3+=M3(v[i])*po3[i];\n    }\n    return V(r1,r2,r3);\n  }\n\n  V term(size_t x,T k){\n    M1 a1=po1[x]*M1((long long)k);\n    M2 a2=po2[x]*M2((long long)k);\n    M3 a3=po3[x]*M3((long long)k);\n    return V(a1,a2,a3);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\ntemplate<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}\n\n//INSERT ABOVE HERE\nsigned CODEFLYER2018_F(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  const int MAX = 2020;\n  using BS = bitset<MAX>;\n\n  int h,w,q;\n  cin>>h>>w>>q;\n\n  vector<string> s(h);\n  for(int i=0;i<h;i++) cin>>s[i];\n\n  vector<BS> rs(h),cs(w);\n  for(int i=0;i<h;i++){\n    for(int j=0;j<w;j++){\n      rs[i][j]=(s[i][j]=='#');\n      cs[j][i]=(s[i][j]=='#');\n    }\n  }\n\n  auto conv=\n    [&](BS &v,int k){\n      vector<int> a(k);\n      for(int i=0;i<k;i++) a[i]=v[i];\n      return a;\n    };\n\n  using M1 = Mint<int, int(1e9+7)>;\n  using M2 = Mint<int, int(1e9+9)>;\n  using M3 = Mint<int, int(1e8+7)>;\n\n  PolynomialHash<int, M1, M2, M3> ph(MAX);\n  using V = decltype(ph)::V;\n\n  vector<V> vrs(h,0),vcs(w,0);\n  vector<int> tmp(w,1);\n  V ri=ph.build(tmp);\n  tmp.assign(h,1);\n  V ci=ph.build(tmp);\n\n  for(int i=0;i<h;i++){\n    auto v=conv(rs[i],w);\n    vrs[i]=ph.build(v);\n    if(rs[i][0]) vrs[i]=ri-vrs[i];\n  }\n\n  for(int j=0;j<w;j++){\n    auto v=conv(cs[j],h);\n    vcs[j]=ph.build(v);\n    if(cs[j][0]) vcs[j]=ci-vcs[j];\n  }\n\n  map<V, set<int> > mrs, mcs;\n  for(int i=0;i<h;i++) mrs[vrs[i]].emplace(i);\n  for(int j=0;j<w;j++) mcs[vcs[j]].emplace(j);\n\n  auto print=[&](string s){cout<<s<<\"\\n\";};\n\n  auto check=\n    [&](){\n      int a1=-1,b1=-1,c1=-1,d1=-1;\n      int a2=-1,b2=-1,c2=-1,d2=-1;\n\n      int A,B,C,D;\n\n      {\n        auto latte=mrs.begin();\n        set<int> &s=latte->second;\n        latte++;\n        set<int> &t=latte->second;\n        if(*--s.end()-*s.begin()+1==(int)s.size()){\n          a1=*s.begin();\n          b1=*--s.end();\n        }\n        if(*--t.end()-*t.begin()+1==(int)t.size()){\n          a2=*t.begin();\n          b2=*--t.end();\n        }\n        A=*s.begin();\n        B=*t.begin();\n      }\n      if(a1<0 and a2<0){\n        print(\"No\");\n        return;\n      }\n\n      {\n        auto latte=mcs.begin();\n        set<int> &s=latte->second;\n        latte++;\n        set<int> &t=latte->second;\n        if(*--s.end()-*s.begin()+1==(int)s.size()){\n          c1=*s.begin();\n          d1=*--s.end();\n        }\n        if(*--t.end()-*t.begin()+1==(int)t.size()){\n          c2=*t.begin();\n          d2=*--t.end();\n        }\n        C=*s.begin();\n        D=*t.begin();\n      }\n\n      if(c1<0 and c2<0){\n        print(\"No\");\n        return;\n      }\n\n      {\n        int flg=0;\n        if(~c1){\n          BS r=rs[A]^rs[B];\n          r>>=c1;\n          int k=r.count();\n          r>>=(d1-c1+1);\n          k-=r.count();\n          flg|=(d1-c1+1)==k;\n        }\n        if(~c1){\n          BS r=rs[A]^~rs[B];\n          r>>=c1;\n          int k=r.count();\n          r>>=(d1-c1+1);\n          k-=r.count();\n          flg|=(d1-c1+1)==k;\n        }\n        if(~c2){\n          BS r=rs[A]^rs[B];\n          r>>=c2;\n          int k=r.count();\n          r>>=(d2-c2+1);\n          k-=r.count();\n          flg|=(d2-c2+1)==k;\n        }\n        if(~c2){\n          BS r=rs[A]^~rs[B];\n          r>>=c2;\n          int k=r.count();\n          r>>=(d2-c2+1);\n          k-=r.count();\n          flg|=(d2-c2+1)==k;\n        }\n        if(!flg){\n          print(\"No\");\n          return;\n        }\n      }\n\n      {\n        int flg=0;\n        if(~a1){\n          BS r=cs[C]^cs[D];\n          r>>=a1;\n          int k=r.count();\n          r>>=(b1-a1+1);\n          k-=r.count();\n          flg|=(b1-a1+1)==k;\n        }\n        if(~a1){\n          BS r=cs[C]^~cs[D];\n          r>>=a1;\n          int k=r.count();\n          r>>=(b1-a1+1);\n          k-=r.count();\n          flg|=(b1-a1+1)==k;\n        }\n        if(~a2){\n          BS r=cs[C]^cs[D];\n          r>>=a2;\n          int k=r.count();\n          r>>=(b2-a2+1);\n          k-=r.count();\n          flg|=(b2-a2+1)==k;\n        }\n        if(~a2){\n          BS r=cs[C]^~cs[D];\n          r>>=a2;\n          int k=r.count();\n          r>>=(b2-a2+1);\n          k-=r.count();\n          flg|=(b2-a2+1)==k;\n        }\n        if(!flg){\n          print(\"No\");\n          return;\n        }\n      }\n\n      print(\"Yes\");\n    };\n\n  auto calc=\n    [&](){\n      if(mrs.size()>2u or mcs.size()>2u){\n        print(\"No\");\n        return;\n      }\n      if(mrs.size()==1u or mcs.size()==1u){\n        print(\"Yes\");\n        return;\n      }\n\n      if(mrs.size()==2u or mcs.size()==2u){\n        check();\n        return;\n      }\n      print(\"No\");\n    };\n\n  calc();\n\n  for(int i=1;i<q;i++){\n    int r,c;\n    cin>>r>>c;\n    r--;c--;\n\n    mrs[vrs[r]].erase(r);\n    if(mrs[vrs[r]].empty()) mrs.erase(vrs[r]);\n    mcs[vcs[c]].erase(c);\n    if(mcs[vcs[c]].empty()) mcs.erase(vcs[c]);\n\n    if(rs[r][0]) vrs[r]=ri-vrs[r];\n    if(cs[c][0]) vcs[c]=ci-vcs[c];\n\n    if(rs[r][c]){\n      vrs[r]-=ph.term(c,1);\n      vcs[c]-=ph.term(r,1);\n    }else{\n      vrs[r]+=ph.term(c,1);\n      vcs[c]+=ph.term(r,1);\n    }\n\n    rs[r][c].flip();\n    cs[c][r].flip();\n\n    if(rs[r][0]) vrs[r]=ri-vrs[r];\n    if(cs[c][0]) vcs[c]=ci-vcs[c];\n\n    mrs[vrs[r]].emplace(r);\n    mcs[vcs[c]].emplace(c);\n\n    calc();\n  }\n\n  cout<<flush;\n  return 0;\n}\n/*\n  verified on 2019/10/15\n  https://atcoder.jp/contests/bitflyer2018-final/tasks/bitflyer2018_final_f\n*/\n\nusing M1 = Mint<int, int(1e9+7)>;\nusing M2 = Mint<int, int(1e9+9)>;\nusing M3 = Mint<int, int(1e8+7)>;\n\nPolynomialHash<int, M1, M2, M3> ph(2000);\nusing V = decltype(ph)::V;\n\nstruct Point{\n  V x,y;\n  Point():x(0),y(0){}\n  Point(V x,V y):x(x),y(y){}\n};\n\nusing Vector = Point;\n\nPoint getP(){\n  int x,y;\n  cin>>x>>y;\n  return Point(V((long long)x),V((long long)y));\n}\n\nsigned JAG2018SUMMER_DAY2_F(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  Point d=getP();\n\n  vector<Point> a(n),b(n),c(n);\n  for(int i=0;i<n;i++){\n    a[i]=getP();\n    b[i]=getP();\n    c[i]=getP();\n  }\n\n  for(int i=0;i<n;i++){\n    if(c[i].x==d.x and c[i].y==d.y) drop(i);\n\n    if(a[i].x==b[i].x and c[i].x==d.x) drop(i);\n\n    if(a[i].x==b[i].x){\n      V nx=a[i].x;\n      V ny=c[i].y;\n      ny+=(nx-c[i].x)/(d.x-c[i].x)*(d.y-c[i].y);\n      d=Point(nx,ny);\n      continue;\n    }\n\n    if(c[i].x==d.x){\n      V nx=c[i].x;\n      V ny=a[i].y;\n      ny+=(nx-a[i].x)/(b[i].x-a[i].x)*(b[i].y-a[i].y);\n      d=Point(nx,ny);\n      continue;\n    }\n\n    V al=(b[i].y-a[i].y)/(b[i].x-a[i].x);\n    V bt=(d.y-c[i].y)/(d.x-c[i].x);\n\n    if(al==bt) drop(i);\n\n    V nx=al*a[i].x;\n    nx-=bt*c[i].x;\n    nx-=a[i].y;\n    nx+=c[i].y;\n    nx/=al-bt;\n\n    V ny=al*nx;\n    ny-=al*a[i].x;\n    ny+=a[i].y;\n\n    d=Point(nx,ny);\n  }\n  cout<<n<<endl;\n  return 0;\n}\n/*\n  verified on 2019/10/15\n  https://atcoder.jp/contests/jag2018summer-day2/tasks/jag2018summer_day2_f\n*/\n\n\nsigned main(){\n  //CODEFLYER2018_F();\n  //JAG2018SUMMER_DAY2_F();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "polynomial/interpolate.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"../formalpowerseries/base.cpp\"\n#include \"../formalpowerseries/inv.cpp\"\n#include \"../formalpowerseries/div.cpp\"\n#include \"../formalpowerseries/mod.cpp\"\n#include \"../formalpowerseries/diff.cpp\"\n#include \"multieval.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n// O(N log^2 N)\ntemplate<typename T>\nstruct Interpolate : MultiEval<T>{\n  using super = MultiEval<T>;\n  using typename super::Poly;\n  using super::super, super::FPS, super::mem;\n\n  Poly interpolate(const vector<T> &xs,const vector<T> &ws,int l,int r){\n    if(l+1==r) return Poly({ws[l]});\n    int m=(l+r)>>1;\n    return FPS.add(FPS.mul(interpolate(xs,ws,l,m),mem[{m,r}]),\n                   FPS.mul(interpolate(xs,ws,m,r),mem[{l,m}]));\n  }\n\n  vector<T> build(const vector<T> &xs,const vector<T> &ys){\n    int n=xs.size();\n    mem.clear();\n    super::dfs(xs,0,n);\n    auto ls=FPS.diff(mem[{0,n}]);\n    ls.resize(n,T(0));\n    vector<T> ws(n);\n    super::multi_eval(ls,ws,0,n);\n    for(int i=0;i<n;i++) ws[i]=ys[i]/ws[i];\n    return interpolate(xs,ws,0,n);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "polynomial/lagrangeinterpolation.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename M>\nM lagrange_interpolation(vector<M> &y,M t){\n  int n=y.size()-1;\n  if(t.v<=n) return y[t.v];\n\n  vector<M> dp(n+1,1),pd(n+1,1);\n  for(int i=0;i<n;i++) dp[i+1]=dp[i]*(t-M(i));\n  for(int i=n;i>0;i--) pd[i-1]=pd[i]*(t-M(i));\n\n  vector<M> fact(n+1,1),finv(n+1,1);\n  for(int i=1;i<=n;i++) fact[i]=fact[i-1]*M(i);\n  finv[n]=M(1)/fact[n];\n  for(int i=n;i>=1;i--) finv[i-1]=finv[i]*M(i);\n\n  M res(0);\n  for(int i=0;i<=n;i++){\n    M tmp=y[i]*dp[i]*pd[i]*finv[i]*finv[n-i];\n    if((n-i)&1) res-=tmp;\n    else res+=tmp;\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "polynomial/multieval.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../combinatorics/enumeration.cpp\"\n#include \"../formalpowerseries/base.cpp\"\n#include \"../formalpowerseries/inv.cpp\"\n#include \"../formalpowerseries/div.cpp\"\n#include \"../formalpowerseries/mod.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n// O(N log^2 N)\ntemplate<typename T>\nstruct MultiEval{\n  FormalPowerSeries<T> FPS;\n  using Poly = typename FormalPowerSeries<T>::Poly;\n  using Conv = typename FormalPowerSeries<T>::Conv;\n\n  MultiEval(Conv conv):FPS(conv){}\n\n  using P = pair<int, int>;\n  map<P, Poly> mem;\n  void dfs(const vector<T> &cs,int l,int r){\n    if(l+1==r){\n      mem[{l,r}]=Poly({-cs[l],T(1)});\n      return;\n    }\n    int m=(l+r)>>1;\n    dfs(cs,l,m);\n    dfs(cs,m,r);\n    mem[{l,r}]=FPS.mul(mem[{l,m}],mem[{m,r}]);\n  }\n\n  void multi_eval(Poly ps,vector<T> &ws,int l,int r){\n    if(l+1==r){\n      ws[l]=FPS.mod(ps,mem[{l,r}])[0];\n      return;\n    }\n    int m=(l+r)>>1;\n    multi_eval(FPS.mod(ps,mem[{l,m}]),ws,l,m);\n    multi_eval(FPS.mod(ps,mem[{m,r}]),ws,m,r);\n  }\n\n  vector<T> build(Poly ps,const vector<T> &cs){\n    int n=cs.size();\n    mem.clear();\n    dfs(cs,0,n);\n    vector<T> ws(n);\n    multi_eval(ps,ws,0,n);\n    return ws;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "polynomial/polynomial.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct Polynomial{\n  using P = Polynomial;\n  vector<T> co;\n  Polynomial():co(1,T(1)){}\n  Polynomial(int sz):co(sz,0){}\n  Polynomial(vector<T> co):co(co){}\n\n  size_t size() const{\n    return co.size();\n  };\n\n  void shrink(){\n    while(co.size()>1u and !co.back())\n      co.pop_back();\n  }\n\n  void reduce(){\n    T g=abs(co.back());\n    if(!g) return;\n    for(T c:co)\n      if(c!=0) g=__gcd(g,abs(c));\n    if(co.back()<0) g*=-1;\n    for(T &c:co) c/=g;\n  }\n\n  void print(){\n    shrink();\n    reduce();\n    int n=size(),flg=0;\n    for(int i=n-1;i>0;i--){\n      if(!co[i]) continue;\n      flg=1;\n      if(i!=n-1 and co[i]>0) cout<<\"+\";\n      if(co[i]==-1) cout<<\"-\";\n      else if(co[i]!=1) cout<<co[i];\n\n      cout<<\"x\";\n      if(i!=1) cout<<\"^\"<<i;\n    }\n    if(co[0]){\n      if(flg and co[0]>0) cout<<\"+\";\n      cout<<co[0];\n    }\n    cout<<endl;\n  }\n\n  T operator[](int i) const{\n    return co[i];\n  }\n\n  T &operator[](int i){\n    return co[i];\n  }\n\n  P operator-() const{\n    P res=*this;\n    for(T &c:res.co) c*=-1;\n    return res;\n  }\n\n  P operator+(const P &a) const{\n    int n=size(),m=a.size();\n    P res(max(n,m));\n    for(int i=0;i<n;i++) res[i]+=co[i];\n    for(int i=0;i<m;i++) res[i]+=a[i];\n    return res;\n  }\n\n  P operator-(const P &a) const{return *this+(-a);};\n\n  P operator*(const P &a) const{\n    int n=size(),m=a.size();\n    P res(n+m);\n    for(int i=0;i<n;i++)\n      for(int j=0;j<m;j++)\n        res[i+j]+=co[i]*a[j];\n    res.shrink();\n    return res;\n  }\n\n  P pow(const P &a,int k) const{\n    P res;\n    for(int i=0;i<k;i++) res=res*a;\n    return res;\n  }\n\n  pair<P, P> divide(const P &a) const{\n    int n=size(),m=a.size(),s=n-m+1;\n    if(s<0) return make_pair(P(1),*this);\n    P div(s);\n    P rest=*this;\n    for(int i=0;i<s;i++){\n      if(rest[n-(i+1)]%a[m-1]!=0)\n        for(T &c:rest.co) c*=a[m-1];\n      T d=rest[n-(i+1)]/a[m-1];\n      div[s-(i+1)]=d;\n      for(int j=m;j>0;j--) rest[n-(i+j)]-=a[m-j]*d;\n    }\n    return make_pair(div,rest);\n  }\n\n  P operator/(const P &a) const{return divide(a).first;};\n  P operator%(const P &a) const{return divide(a).second;};\n};\n\ntemplate<typename T>\nPolynomial<T> gcd(Polynomial<T> a,Polynomial<T> b){\n  a.shrink();a.reduce();\n  b.shrink();b.reduce();\n  if(a.size()<b.size()) swap(a,b);\n  if(b.size()==1u and !b[0]) return a;\n  return gcd(b,a%b);\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "polynomial/recursivesequence.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#endif\n//BEGIN CUT HERE\n// add recursive sequence\ntemplate<typename T>\nstruct RecursiveSequence{\n  vector<vector<int>> add,sub;\n  RecursiveSequence(int n):add(n),sub(n+1){}\n\n  // add a_0, ..., a_{r-l-1} to [l, r)\n  void query(int l,int r){\n    add[l].emplace_back(0);\n    sub[r].emplace_back(r-l);\n  }\n\n  // a_i = \\sum_{k} c_k a_{i-k}\n  vector<T> build(vector<T> as,vector<T> cs){\n    assert(as.size()==cs.size());\n    int n=add.size();\n    int k=as.size();\n\n    reverse(cs.begin(),cs.end());\n    as.resize(n+k);\n    for(int i=0;i<n;i++)\n      for(int j=0;j<k;j++)\n        as[i+k]+=as[i+j]*cs[j];\n\n    vector<T> ss(n+k,T(0));\n    for(int i=0;i<n;i++){\n      for(int l:add[i])\n        for(int j=0;j<k;j++)\n          ss[i+j]+=as[l+j];\n\n      for(int l:sub[i])\n        for(int j=0;j<k;j++)\n          ss[i+j]-=as[l+j];\n\n      for(int j=0;j<k;j++)\n        ss[i+k]+=ss[i+j]*cs[j];\n    }\n    ss.resize(n);\n    return ss;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "segtree/2d/ushi.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename index_t,typename SegmentTree>\nstruct SegmentTree2D{\n  using F = typename SegmentTree::F;\n  using T = typename F::result_type;\n  const F f;\n  const T ti;\n  SegmentTree2D(F f_,T ti_):f(f_),ti(ti_){}\n\n  vector<pair<index_t, index_t>> vp;\n  void preupdate(index_t p,index_t q){\n    vp.emplace_back(p,q);\n  }\n\n  void compress(vector<index_t> &vs){\n    sort(vs.begin(),vs.end());\n    vs.erase(unique(vs.begin(),vs.end()),vs.end());\n  }\n\n  int idx(index_t v,const vector<index_t> &vs){\n    return lower_bound(vs.begin(),vs.end(),v)-vs.begin();\n  }\n\n  int sz;\n  vector<index_t> ps;\n  vector<vector<index_t>> I;\n  vector<vector<int>> L,R;\n  vector<SegmentTree> seg;\n  void build(){\n    for(auto[p,q]:vp) ps.emplace_back(p);\n    compress(ps);\n\n    sz=1;\n    while(sz<(int)ps.size()) sz<<=1;\n\n    I.resize(sz<<1);\n    for(auto[p,q]:vp) I[sz+idx(p,ps)].emplace_back(q);\n    for(int k=(int)I.size()-1;k>=sz;k--) compress(I[k]);\n\n    L.resize(sz);\n    R.resize(sz);\n    for(int k=sz-1;k>0;k--){\n      auto& cur=I[k];\n      const auto& lft=I[(k<<1)|0];\n      const auto& rgh=I[(k<<1)|1];\n      cur.resize(lft.size()+rgh.size());\n      merge(lft.begin(),lft.end(),rgh.begin(),rgh.end(),cur.begin());\n      cur.erase(unique(cur.begin(),cur.end()),cur.end());\n      L[k].resize(cur.size()+1);\n      R[k].resize(cur.size()+1);\n      int tl=0,tr=0;\n      for(int i=0;i<(int)cur.size();i++){\n        while(tl<(int)lft.size() and lft[tl]<cur[i]) tl++;\n        while(tr<(int)rgh.size() and rgh[tr]<cur[i]) tr++;\n        L[k][i]=tl;R[k][i]=tr;\n      }\n      L[k][cur.size()]=lft.size();\n      R[k][cur.size()]=rgh.size();\n    }\n    for(int k=0;k<(int)I.size();k++){\n      seg.emplace_back(f,ti);\n      seg.back().build(vector<T>(I[k].size(),ti));\n    }\n  }\n\n  void update(int p,int q,T v,int k,int l,int r){\n    if(r<=p||p+1<=l) return;\n    if(p<=l&&r<=p+1) return seg[k].set_val(q,v);\n    int m=(l+r)>>1;\n    update(p,L[k][q],v,(k<<1)|0,l,m);\n    update(p,R[k][q],v,(k<<1)|1,m,r);\n    T res=ti;\n    const auto& cur=I[k];\n    const auto& lft=I[(k<<1)|0];\n    const auto& rgh=I[(k<<1)|1];\n    if(L[k][q]<(int)lft.size() and cur[q]==lft[L[k][q]])\n      res=f(res,seg[(k<<1)|0].query(L[k][q],L[k][q]+1));\n    if(R[k][q]<(int)rgh.size() and cur[q]==rgh[R[k][q]])\n      res=f(res,seg[(k<<1)|1].query(R[k][q],R[k][q]+1));\n    seg[k].set_val(q,res);\n  }\n\n  void update(index_t p,index_t q,T v){\n    update(idx(p,ps),idx(q,I[1]),v,1,0,sz);\n  }\n\n  T query(int pa,int pb,int qa,int qb,int k,int l,int r){\n    if(r<=pa||pb<=l) return ti;\n    if(pa<=l&&r<=pb) return seg[k].query(qa,qb);\n    int m=(l+r)>>1;\n    return f(query(pa,pb,L[k][qa],L[k][qb],(k<<1)|0,l,m),\n             query(pa,pb,R[k][qa],R[k][qb],(k<<1)|1,m,r));\n  }\n\n  // [pa, pb) x [qa, qb)\n  T query(index_t pa,index_t pb,index_t qa,index_t qb){\n    return query(idx(pa,ps),idx(pb,ps),idx(qa,I[1]),idx(qb,I[1]),1,0,sz);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"../basic/ushi.cpp\"\n#include \"../../vector/zip.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#undef call_from_test\n\nsigned ABC266_H(){\n  int n;\n  cin>>n;\n  vector<int> ts(n),xs(n),ys(n),as(n);\n  for(int i=0;i<n;i++) cin>>ts[i]>>xs[i]>>ys[i]>>as[i];\n\n  {\n    auto zs=zip(ys,ts,xs,as);\n    sort(zs.begin(),zs.end());\n    for(int i=0;i<n;i++) tie(ys[i],ts[i],xs[i],as[i])=zs[i];\n  }\n  vector<int> bs(n),cs(n);\n  for(int i=0;i<n;i++){\n    bs[i]=ts[i]-ys[i]+xs[i];\n    cs[i]=ts[i]-ys[i]-xs[i];\n  }\n\n  using ll = long long;\n  auto f=[&](ll a,ll b){return max(a,b);};\n  SegmentTree2D<int, SegmentTree<ll>> seg(f,0LL);\n  for(int i=0;i<n;i++){\n    seg.preupdate(bs[i],cs[i]);\n  }\n  seg.build();\n\n  ll ans=0;\n  for(int i=0;i<n;i++){\n    if(ts[i]<xs[i]+ys[i]) continue;\n    ll res=as[i]+seg.query(0,bs[i]+1,0,cs[i]+1);\n    seg.update(bs[i],cs[i],res);\n    chmax(ans,res);\n  }\n  cout<<ans<<endl;\n\n  return 0;\n}\n/*\n  verified on 2022/08/28\n  https://atcoder.jp/contests/abc266/tasks/abc266_h\n*/\n\nsigned main(){\n  ABC266_H();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "segtree/basic/dual.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate <typename E>\nstruct SegmentTree{\n  using H = function<E(E,E)>;\n  int n,height;\n  H h;\n  E ei;\n  vector<E> laz;\n\n  SegmentTree(H h,E ei):h(h),ei(ei){}\n\n  void init(int n_){\n    n=1;height=0;\n    while(n<n_) n<<=1,height++;\n    laz.assign(2*n,ei);\n  }\n\n  inline void propagate(int k){\n    if(laz[k]==ei) return;\n    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);\n    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);\n    laz[k]=ei;\n  }\n\n  inline void thrust(int k){\n    for(int i=height;i;i--) propagate(k>>i);\n  }\n\n  void update(int a,int b,E x){\n    if(a>=b) return;\n    thrust(a+=n);\n    thrust(b+=n-1);\n    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){\n      if(l&1) laz[l]=h(laz[l],x),l++;\n      if(r&1) --r,laz[r]=h(laz[r],x);\n    }\n  }\n\n  E get_val(int a){\n    thrust(a+=n);\n    return laz[a];\n  }\n\n  void set_val(int a,E x){\n    thrust(a+=n);\n    laz[a]=x;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "segtree/basic/lazy.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate <typename T,typename E>\nstruct SegmentTree{\n  using F = function<T(T,T)>;\n  using G = function<T(T,E)>;\n  using H = function<E(E,E)>;\n  int n,height;\n  F f;\n  G g;\n  H h;\n  T ti;\n  E ei;\n  vector<T> dat;\n  vector<E> laz;\n  SegmentTree(F f,G g,H h,T ti,E ei):\n    f(f),g(g),h(h),ti(ti),ei(ei){}\n\n  void init(int n_){\n    n=1;height=0;\n    while(n<n_) n<<=1,height++;\n    dat.assign(2*n,ti);\n    laz.assign(2*n,ei);\n  }\n\n  void build(const vector<T> &v){\n    int n_=v.size();\n    init(n_);\n    for(int i=0;i<n_;i++) dat[n+i]=v[i];\n    for(int i=n-1;i;i--)\n      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);\n  }\n\n  inline T reflect(int k){\n    return laz[k]==ei?dat[k]:g(dat[k],laz[k]);\n  }\n\n  inline void propagate(int k){\n    if(laz[k]==ei) return;\n    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);\n    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);\n    dat[k]=reflect(k);\n    laz[k]=ei;\n  }\n\n  inline void thrust(int k){\n    for(int i=height;i;i--) propagate(k>>i);\n  }\n\n  inline void recalc(int k){\n    while(k>>=1)\n      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));\n  }\n\n  void update(int a,int b,E x){\n    if(a>=b) return;\n    thrust(a+=n);\n    thrust(b+=n-1);\n    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){\n      if(l&1) laz[l]=h(laz[l],x),l++;\n      if(r&1) --r,laz[r]=h(laz[r],x);\n    }\n    recalc(a);\n    recalc(b);\n  }\n\n  void set_val(int a,T x){\n    thrust(a+=n);\n    dat[a]=x;laz[a]=ei;\n    recalc(a);\n  }\n\n  T query(int a,int b){\n    if(a>=b) return ti;\n    thrust(a+=n);\n    thrust(b+=n-1);\n    T vl=ti,vr=ti;\n    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {\n      if(l&1) vl=f(vl,reflect(l++));\n      if(r&1) vr=f(reflect(--r),vr);\n    }\n    return f(vl,vr);\n  }\n\n  template<typename C>\n  int find(int st,C &check,T &acc,int k,int l,int r){\n    if(l+1==r){\n      acc=f(acc,reflect(k));\n      return check(acc)?k-n:-1;\n    }\n    propagate(k);\n    int m=(l+r)>>1;\n    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);\n    if(st<=l and !check(f(acc,dat[k]))){\n      acc=f(acc,dat[k]);\n      return -1;\n    }\n    int vl=find(st,check,acc,(k<<1)|0,l,m);\n    if(~vl) return vl;\n    return find(st,check,acc,(k<<1)|1,m,r);\n  }\n\n  template<typename C>\n  int find(int st,C &check){\n    T acc=ti;\n    return find(st,check,acc,1,0,n);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\nsigned CFR569_C(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  vector<int> as(n),bs(m);\n  for(int i=0;i<n;i++) cin>>as[i];\n  for(int i=0;i<m;i++) cin>>bs[i];\n\n  auto f=[](int a,int b){return max(a,b);};\n  auto g=[](int a,int b){return a+b;};\n  int ti=0,ei=0;\n  SegmentTree<int, int> seg(f,g,g,ti,ei);\n\n  const int sz = 1<<20;\n  seg.build(vector<int>(sz,0));\n\n  for(int i=0;i<n;i++) seg.update(sz-as[i],sz,+1);\n  for(int i=0;i<m;i++) seg.update(sz-bs[i],sz,-1);\n\n  int q;\n  cin>>q;\n  auto check=[](int d){return d>0;};\n  for(int i=0;i<q;i++){\n    int t,k,v;\n    cin>>t>>k>>v;\n    k--;\n    if(t==1){\n      seg.update(sz-as[k],sz,-1);\n      as[k]=v;\n      seg.update(sz-as[k],sz,+1);\n    }\n    if(t==2){\n      seg.update(sz-bs[k],sz,+1);\n      bs[k]=v;\n      seg.update(sz-bs[k],sz,-1);\n    }\n    int pos=seg.find(0,check);\n    cout<<(pos<0?pos:sz-pos)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n/*\n  verified on 2019/10/28\n  https://codeforces.com/contest/1179/problem/C\n*/\n\nsigned main(){\n  CFR569_C();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "segtree/basic/ushi.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate <typename T>\nstruct SegmentTree{\n  using F = function<T(T,T)>;\n  int n;\n  F f;\n  T ti;\n  vector<T> dat;\n\n  SegmentTree(F f,T ti):f(f),ti(ti){}\n\n  void init(int n_){\n    n=1;\n    while(n<n_) n<<=1;\n    dat.assign(n<<1,ti);\n  }\n\n  void build(const vector<T> &v){\n    int n_=v.size();\n    init(n_);\n    for(int i=0;i<n_;i++) dat[n+i]=v[i];\n    for(int i=n-1;i;i--)\n      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);\n  }\n\n  void set_val(int k,T x){\n    dat[k+=n]=x;\n    while(k>>=1)\n      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);\n  }\n\n  T query(int a,int b){\n    if(a>=b) return ti;\n    T vl=ti,vr=ti;\n    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {\n      if(l&1) vl=f(vl,dat[l++]);\n      if(r&1) vr=f(dat[--r],vr);\n    }\n    return f(vl,vr);\n  }\n\n  template<typename C>\n  int max_right(int s,C &check,T &acc,int k,int l,int r){\n    if(l+1==r){\n      acc=f(acc,dat[k]);\n      return check(acc)?-1:k-n;\n    }\n    int m=(l+r)>>1;\n    if(m<=s) return max_right(s,check,acc,(k<<1)|1,m,r);\n    if(s<=l and check(f(acc,dat[k]))){\n      acc=f(acc,dat[k]);\n      return -1;\n    }\n    int vl=max_right(s,check,acc,(k<<1)|0,l,m);\n    if(~vl) return vl;\n    return max_right(s,check,acc,(k<<1)|1,m,r);\n  }\n\n  // max t s.t. check(query(s,t))\n  // O(\\log N)\n  template<typename C>\n  int max_right(int s,C &check){\n    assert(s<n and check(ti) and not check(query(s,n)));\n    T acc=ti;\n    return max_right(s,check,acc,1,0,n);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "segtree/count/dynamic_offline.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename Key,typename T>\nstruct RangeCount{\n  struct BIT{\n    vector<T> dat;\n    BIT(int n){dat.assign(++n,0);}\n    T sum(int k){\n      T res=0;\n      for(;k;k-=k&-k) res+=dat[k];\n      return res;\n    }\n    void add(int k,T v){\n      for(++k;k<(int)dat.size();k+=k&-k) dat[k]+=v;\n    }\n  };\n  int n;\n  vector< vector<Key> > val;\n  vector<BIT> dat;\n  RangeCount(int n):n(n){\n    val.assign(n<<1,vector<Key>());\n    dat.reserve(n<<1);\n  }\n  void preupdate(int a,Key x){\n    a+=n;\n    while(a){\n      val[a].emplace_back(x);\n      a>>=1;\n    }\n  }\n  void build(){\n    for(int i=0;i<n*2;i++){\n      auto &vs=val[i];\n      sort(vs.begin(),vs.end());\n      vs.erase(unique(vs.begin(),vs.end()),vs.end());\n      dat.emplace_back(vs.size());\n    }\n  }\n  void update(int a,Key x,T z){\n    a+=n;\n    while(a){\n      auto &vs=val[a];\n      int k=lower_bound(vs.begin(),vs.end(),x)-vs.begin();\n      dat[a].add(k,z);\n      a>>=1;\n    }\n  }\n  T calc(int k,Key x,Key y){\n    auto &vs=val[k];\n    int p=lower_bound(vs.begin(),vs.end(),x)-vs.begin();\n    int q=lower_bound(vs.begin(),vs.end(),y)-vs.begin();\n    return dat[k].sum(q)-dat[k].sum(p);\n  }\n  // [a, b) * [x, y)\n  T query(int a,int b,Key x,Key y){\n    T res=0;\n    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){\n      if(l&1) res+=calc(l++,x,y);\n      if(r&1) res+=calc(--r,x,y);\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\n//END CUT HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "segtree/count/static.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename Key>\nstruct SegmentTree{\n  using P = pair<int, Key>;\n  int n;\n  vector< vector<Key> > dat;\n  SegmentTree(int n,vector<P> vs):n(n){\n    dat.assign(n<<1,vector<Key>());\n    for(auto p:vs)\n      dat[p.first+n].emplace_back(p.second);\n\n    for(int i=0;i<n;i++)\n      sort(dat[i+n].begin(),dat[i+n].end());\n\n    for(int i=n-1;i;i--){\n      merge(dat[(i<<1)|0].begin(),dat[(i<<1)|0].end(),\n            dat[(i<<1)|1].begin(),dat[(i<<1)|1].end(),\n            back_inserter(dat[i]));\n    }\n  }\n\n  // [a, b) * [c, d)\n  inline int query(int a,int b,Key c,Key d){\n    int res=0;\n    auto calc=[a,b,c,d](vector<Key> &xs){\n      auto latte=lower_bound(xs.begin(),xs.end(),d);\n      auto malta=lower_bound(xs.begin(),xs.end(),c);\n      return int(latte-malta);\n    };\n    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){\n      if(l&1) res+=calc(dat[l++]);\n      if(r&1) res+=calc(dat[--r]);\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "segtree/persistent/ushi.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate <typename T>\nstruct SegmentTree{\n  using F = function<T(T,T)>;\n  F f;\n  T ti;\n  SegmentTree(F f,T ti):f(f),ti(ti){}\n\n  struct Node{\n    Node *l,*r;\n    T dat;\n    Node(T dat):dat(dat){l=r=nullptr;}\n  };\n\n  Node* clone(Node *a){\n    return new Node(*a);\n  }\n\n  Node* reflect(Node *a){\n    a->dat=f(a->l->dat,a->r->dat);\n    return a;\n  }\n\n  int n,height;\n  Node* build(const vector<T> &v){\n    int n_=v.size();\n    n=1;height=0;\n    while(n<n_) n<<=1,height++;\n    vector<Node*> vs(n<<1);\n    for(int i=0;i<n_;i++) vs[n+i]=new Node(v[i]);\n    for(int i=n_;i<n;i++) vs[n+i]=new Node(ti);\n    for(int i=n-1;i;i--){\n      vs[i]=new Node(ti);\n      vs[i]->l=vs[(i<<1)|0];\n      vs[i]->r=vs[(i<<1)|1];\n      reflect(vs[i]);\n    }\n    return vs[1];\n  }\n\n  Node* set_val(Node* t,int k,T x,int h){\n    t=clone(t);\n    if(h<0){\n      t->dat=x;\n      return t;\n    }\n    if((k>>h)&1) t->r=set_val(t->r,k,x,h-1);\n    else t->l=set_val(t->l,k,x,h-1);\n    return reflect(t);\n  }\n\n  T query(Node* t,int l,int r,int lb,int ub){\n    if(r<=lb or ub<=l) return ti;\n    if(l<=lb and ub<=r) return t->dat;\n    int m=(lb+ub)>>1;\n    return f(query(t->l,l,r,lb,m),query(t->r,l,r,m,ub));\n  }\n\n  Node* set_val(Node* t,int k,T x){\n    return set_val(t,k,x,height-1);\n  }\n\n  T query(Node* t,int l,int r){\n    return query(t,l,r,0,n);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "segtree/types/offline.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define IGNORE\n\ntemplate<typename T>\nstruct RangeCount{\n  struct BIT{\n    vector<T> dat;\n    BIT(int n){dat.assign(++n,0);}\n    T sum(int k){\n      T res=0;\n      for(;k;k-=k&-k) res+=dat[k];\n      return res;\n    }\n    void add(int k,T v){\n      for(++k;k<(int)dat.size();k+=k&-k) dat[k]+=v;\n    }\n  };\n  int n;\n  vector<vector<int> > val;\n  vector<BIT> dat;\n  RangeCount(int n_){\n    n=1;\n    while(n<n_) n<<=1;\n    val.assign(n<<1,vector<int>());\n    dat.reserve(n<<1);\n  }\n  void preupdate(int a,int x){\n    a+=n;\n    while(a){\n      val[a].emplace_back(x);\n      a>>=1;\n    }\n  }\n  void build(){\n    for(int i=0;i<n*2;i++){\n      auto &v=val[i];\n      sort(v.begin(),v.end());\n      v.erase(unique(v.begin(),v.end()),v.end());\n      dat.emplace_back(v.size());\n    }\n  }\n  void update(int a,int x,int z){\n    a+=n;\n    while(a){\n      auto &v=val[a];\n      int k=lower_bound(v.begin(),v.end(),x)-v.begin();\n      dat[a].add(k,z);\n      a>>=1;\n    }\n  }\n  T calc(int k,int x,int y){\n    auto &v=val[k];\n    int p=lower_bound(v.begin(),v.end(),x)-v.begin();\n    int q=lower_bound(v.begin(),v.end(),y)-v.begin();\n    return dat[k].sum(q)-dat[k].sum(p);\n  }\n  // [a, b) * [x, y)\n  T query(int a,int b,int x,int y){\n    T res=0;\n    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){\n      if(l&1) res+=calc(l++,x,y);\n      if(r&1) res+=calc(--r,x,y);\n    }\n    return res;\n  }\n};\n\nstruct RangeTypes{\n  struct range{\n    int l,r,c;\n    range(int l,int r,int c):l(l),r(r),c(c){}\n    bool operator<(const range &a)const{\n      return l<a.l;\n    }\n  };\n\n  int n,m,time;\n  vector<int> nxt,dat,upd;\n  set<int> sx;\n\n  set<range> sr;\n  vector<set<range> > se;\n  RangeCount<int> rc;\n  using T = tuple<int, int, int>;\n  vector<T> mvs;\n\n  RangeTypes(int n_,int m):m(m),time(0),se(m+1),rc(n_){\n    n=1;\n    while(n<n_) n<<=1;\n\n    nxt.assign(n,0);\n    iota(nxt.begin(),nxt.end(),1);\n\n    sr.emplace(0,n,m);\n    se[m].emplace(0,n,m);\n\n    dat.assign(n<<1,0);\n    upd.assign(n<<1,0);\n\n    for(int i=0;i<n;i++) rc.preupdate(i,i+1);\n  }\n\n  int get(int k) const{\n    k+=n;\n    int t=upd[k],c=dat[k];\n    while(k>>=1)\n      if(t<upd[k]) t=upd[k],c=dat[k];\n    return c;\n  }\n\n  void reset(int a,int v){\n    if(nxt[a]==v) return;\n    mvs.emplace_back(a,nxt[a],v);\n    rc.preupdate(a,nxt[a]);\n    rc.preupdate(a,v);\n    nxt[a]=v;\n  }\n\n  void update(const int a,const int b,const int c){\n    assert(a<b);\n    assert(c<m);\n    time++;\n    // gather information\n    vector<int> vx,vc;\n    if(a) vc.emplace_back(get(a-1));\n    vc.emplace_back(c);\n    for(auto it=sx.lower_bound(a);it!=sx.end();++it){\n      if(*it>=b) break;\n      vx.emplace_back(*it);\n      vc.emplace_back(get(*it));\n    }\n    if(vx.empty() or vx.back()!=b-1){\n      vx.emplace_back(b-1);\n      vc.emplace_back(get(b-1));\n    }\n\n    vector<range> vr;\n    {\n      auto it=sr.lower_bound(range(a,0,0));\n      if(it!=sr.begin()) --it;\n      if(it->l<a and a<it->r) vr.emplace_back(*it);\n    }\n    for(auto it=sr.lower_bound(range(a,0,0));it!=sr.end();++it){\n      if(it->l>=b) break;\n      vr.emplace_back(*it);\n    }\n\n    // update information\n    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){\n      if(l&1) dat[l]=c,upd[l]=time,l++;\n      if(r&1) --r,dat[r]=c,upd[r]=time;\n    }\n\n    for(auto r:vr){\n      sr.erase(r);\n      se[r.c].erase(r);\n    }\n    sr.emplace(a,b,c);\n    se[c].emplace(a,b,c);\n\n    {\n      auto r=vr.front();\n      if(r.l<a){\n        sr.emplace(r.l,a,r.c);\n        se[r.c].emplace(r.l,a,r.c);\n      }\n    }\n    {\n      auto r=vr.back();\n      if(b<r.r){\n        sr.emplace(b,r.r,r.c);\n        se[r.c].emplace(b,r.r,r.c);\n      }\n    }\n\n    for(int x:vx){\n      if(x<b-1){\n        if(sx.count(x)) sx.erase(x);\n        reset(x,x+1);\n      }\n    }\n\n    {\n      int nb=n;\n      auto it=se[c].upper_bound(range(a,0,0));\n      if(it!=se[c].end()) nb=it->l;\n      reset(b-1,nb);\n      if(nb!=b) sx.emplace(b-1);\n    }\n\n    sort(vc.begin(),vc.end());\n    vc.erase(unique(vc.begin(),vc.end()),vc.end());\n    for(int x:vc){\n      auto it=se[x].lower_bound(range(a,0,0));\n      if(it==se[x].begin()) continue;\n      int ny=(it==se[x].end()?n:it->l),y=(--it)->r-1;\n      reset(y,ny);\n      if(ny!=y+1) sx.emplace(y);\n    }\n  }\n\n  void count(const int a,const int b){\n    mvs.emplace_back(-1,a,b);\n  }\n\n  vector<int> build(){\n    rc.build();\n    for(int i=0;i<n;i++) rc.update(i,i+1,1);\n    vector<int> res;\n    for(auto mv:mvs){\n      int a,b,c;\n      tie(a,b,c)=mv;\n      if(~a){\n        rc.update(a,b,-1);\n        rc.update(a,c, 1);\n      }else{\n        res.emplace_back(rc.query(b,c,c,n<<1));\n      }\n    }\n    return res;\n  }\n};\n\ntemplate<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}\ntemplate<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}\n\n\nstruct EulerTour{\n  int n,pos;\n  vector<vector<int> > G;\n  vector<int> ls,rs;\n\n  EulerTour(int n):n(n),G(n),ls(n),rs(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void dfs(int v,int p){\n    ls[v]=pos++;\n    for(int u:G[v])\n      if(u!=p) dfs(u,v);\n    rs[v]=pos;\n  }\n\n  void build(int r=0){\n    pos=0;\n    dfs(r,-1);\n  }\n\n};\n\n//INSERT ABOVE HERE\nsigned main(){\n  int T;\n  scanf(\"%d\",&T);\n\n  for(int t=1;t<=T;t++){\n    printf(\"Case #%d:\\n\",t);\n    int n;\n    scanf(\"%d\",&n);\n    EulerTour et(n);\n    for(int i=1;i<n;i++){\n      int u,v;\n      scanf(\"%d %d\",&u,&v);\n      u--;v--;\n      et.add_edge(u,v);\n    }\n    vector<int> c(n);\n    for(int i=0;i<n;i++) scanf(\"%d\",&c[i]);\n\n    et.build();\n    int q;\n    scanf(\"%d\",&q);\n\n    if(n<=50000 or q<=50000){\n      vector<int> val(n),used(n+1,-1);\n      for(int i=0;i<n;i++) val[et.ls[i]]=c[i];\n\n      for(int i=0;i<q;i++){\n        int type;\n        scanf(\"%d\",&type);\n        if(type==0){\n          int u,w;\n          scanf(\"%d %d\",&u,&w);\n          u--;\n          for(int j=et.ls[u];j<et.rs[u];j++) val[j]=w;\n        }\n        if(type==1){\n          int u;\n          scanf(\"%d\",&u);\n          u--;\n          int cnt=0;\n          for(int j=et.ls[u];j<et.rs[u];j++){\n            if(used[val[j]]!=i) cnt++;\n            used[val[j]]=i;\n          }\n          printf(\"%d\\n\",cnt);\n        }\n      }\n      continue;\n    }\n\n    RangeTypes rt(n,n+10);\n    function<void(int, int)> dfs=\n      [&](int v,int p){\n        rt.update(et.ls[v],et.rs[v],c[v]);\n        for(int u:et.G[v])\n          if(p!=u) dfs(u,v);\n      };\n    dfs(0, -1);\n\n    for(int i=0;i<q;i++){\n      int type;\n      scanf(\"%d\",&type);\n\n      if(type==0){\n        int u,w;\n        scanf(\"%d %d\",&u,&w);\n        u--;\n        rt.update(et.ls[u],et.rs[u],w);\n      }\n      if(type==1){\n        int u;\n        scanf(\"%d\",&u);\n        u--;\n        rt.count(et.ls[u],et.rs[u]);\n      }\n    }\n    auto vx=rt.build();\n    for(int x:vx) printf(\"%d\\n\",x);\n  }\n  return 0;\n}\n"
  },
  {
    "path": "segtree/types/online.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define IGNORE\n\n#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\n#include<ext/pb_ds/tag_and_trait.hpp>\nusing namespace __gnu_pbds;\n\nstruct RangeTypes{\n  template <typename T>\n  using gtree = tree<T, null_type, less<T>, rb_tree_tag,\n                     tree_order_statistics_node_update>;\n  struct range{\n    int l,r,c;\n    range(int l,int r,int c):l(l),r(r),c(c){}\n    bool operator<(const range &a)const{\n      return l<a.l;\n    }\n  };\n\n  int n,m,time;\n  vector<int> nxt,dat,upd;\n  set<int> sx;\n\n  set<range> sr;\n  vector<set<range> > se;\n  vector<gtree<int> > rc;\n\n  RangeTypes(int n_,int m):m(m),time(0),se(m+1){\n    n=1;\n    while(n<n_+1) n<<=1;\n\n    nxt.assign(n,0);\n    iota(nxt.begin(),nxt.end(),1);\n\n    sr.emplace(0,n,m);\n    se[m].emplace(0,n,m);\n\n    dat.assign(n<<1,0);\n    upd.assign(n<<1,0);\n\n    rc.resize(n<<1);\n    for(int i=0;i<n;i++)\n      for(int k=i+n;k;k>>=1)\n        rc[k].insert(nxt[i]);\n\n    for(int i=0;i<n*2;i++)\n      rc[i].insert(INT_MAX);\n  }\n\n  int get(int k) const{\n    k+=n;\n    int t=upd[k],c=dat[k];\n    while(k>>=1)\n      if(t<upd[k]) t=upd[k],c=dat[k];\n    return c;\n  }\n\n  void reset(int a,int v){\n    if(nxt[a]==v) return;\n    int k=a+n;\n    while(k){\n      rc[k].erase(nxt[a]);\n      rc[k].insert(v);\n      k>>=1;\n    }\n    nxt[a]=v;\n  }\n\n  void update(const int a,const int b,const int c){\n    assert(a<b);\n    assert(c<m);\n    time++;\n    // gather information\n    vector<int> vx,vc;\n    if(a) vc.emplace_back(get(a-1));\n    vc.emplace_back(c);\n    for(auto it=sx.lower_bound(a);it!=sx.end();++it){\n      if(*it>=b) break;\n      vx.emplace_back(*it);\n      vc.emplace_back(get(*it));\n    }\n    if(vx.empty() or vx.back()!=b-1){\n      vx.emplace_back(b-1);\n      vc.emplace_back(get(b-1));\n    }\n\n    vector<range> vr;\n    {\n      auto it=sr.lower_bound(range(a,0,0));\n      if(it!=sr.begin()) --it;\n      if(it->l<a and a<it->r) vr.emplace_back(*it);\n    }\n    for(auto it=sr.lower_bound(range(a,0,0));it!=sr.end();++it){\n      if(it->l>=b) break;\n      vr.emplace_back(*it);\n    }\n\n    // update information\n    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){\n      if(l&1) dat[l]=c,upd[l]=time,l++;\n      if(r&1) --r,dat[r]=c,upd[r]=time;\n    }\n\n    for(auto r:vr){\n      sr.erase(r);\n      se[r.c].erase(r);\n    }\n    sr.emplace(a,b,c);\n    se[c].emplace(a,b,c);\n\n    {\n      auto r=vr.front();\n      if(r.l<a){\n        sr.emplace(r.l,a,r.c);\n        se[r.c].emplace(r.l,a,r.c);\n      }\n    }\n    {\n      auto r=vr.back();\n      if(b<r.r){\n        sr.emplace(b,r.r,r.c);\n        se[r.c].emplace(b,r.r,r.c);\n      }\n    }\n\n    for(int x:vx){\n      if(x<b-1){\n        if(sx.count(x)) sx.erase(x);\n        reset(x,x+1);\n      }\n    }\n\n    {\n      int nb=n+(++time);\n      auto it=se[c].upper_bound(range(a,0,0));\n      if(it!=se[c].end()) nb=it->l;\n      reset(b-1,nb);\n      if(nb!=b) sx.emplace(b-1);\n    }\n\n    sort(vc.begin(),vc.end());\n    vc.erase(unique(vc.begin(),vc.end()),vc.end());\n    for(int x:vc){\n      auto it=se[x].lower_bound(range(a,0,0));\n      if(it==se[x].begin()) continue;\n      int ny=(it==se[x].end()?n+(++time):it->l),y=(--it)->r-1;\n      reset(y,ny);\n      if(ny!=y+1) sx.emplace(y);\n    }\n  }\n\n  int query(const int a,const int b,const int c,const int d) const{\n    int res=0;\n    auto calc=[&](const gtree<int> &g){\n      int lb=*g.lower_bound(c);\n      int ub=*g.upper_bound(d);\n      return g.order_of_key(ub)-g.order_of_key(lb);\n    };\n    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){\n      if(l&1) res+=calc(rc[l++]);\n      if(r&1) res+=calc(rc[--r]);\n    }\n    return res;\n  }\n\n  int count(const int a,const int b) const{\n    return query(a,b,b,INT_MAX-1);\n  }\n};\n\n\ntemplate<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}\ntemplate<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}\n\n\nstruct EulerTour{\n  int n,pos;\n  vector<vector<int> > G;\n  vector<int> ls,rs;\n\n  EulerTour(int n):n(n),G(n),ls(n),rs(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void dfs(int v,int p){\n    ls[v]=pos++;\n    for(int u:G[v])\n      if(u!=p) dfs(u,v);\n    rs[v]=pos;\n  }\n\n  void build(int r=0){\n    pos=0;\n    dfs(r,-1);\n  }\n\n};\n\n//INSERT ABOVE HERE\nsigned main(){\n  int T;\n  scanf(\"%d\",&T);\n\n  int casecnt=0;\n  for(int t=1;t<=T;t++){\n    printf(\"Case #%d:\\n\",t);\n    int n;\n    scanf(\"%d\",&n);\n    EulerTour et(n);\n    for(int i=1;i<n;i++){\n      int u,v;\n      scanf(\"%d %d\",&u,&v);\n      u--;v--;\n      et.add_edge(u,v);\n    }\n    vector<int> c(n);\n    for(int i=0;i<n;i++) scanf(\"%d\",&c[i]);\n\n    et.build();\n    int q;\n    scanf(\"%d\",&q);\n\n    if(n<=5000 or q<=5000 or casecnt>=2){\n      vector<int> val(n),used(n+1,-1);\n      for(int i=0;i<n;i++) val[et.ls[i]]=c[i];\n\n      for(int i=0;i<q;i++){\n        int type;\n        scanf(\"%d\",&type);\n        if(type==0){\n          int u,w;\n          scanf(\"%d %d\",&u,&w);\n          u--;\n          for(int j=et.ls[u];j<et.rs[u];j++) val[j]=w;\n        }\n        if(type==1){\n          int u;\n          scanf(\"%d\",&u);\n          u--;\n          int cnt=0;\n          for(int j=et.ls[u];j<et.rs[u];j++){\n            if(used[val[j]]!=i) cnt++;\n            used[val[j]]=i;\n          }\n          printf(\"%d\\n\",cnt);\n        }\n      }\n      continue;\n    }\n    casecnt++;\n\n    RangeTypes rt(n,n+10);\n    function<void(int, int)> dfs=\n      [&](int v,int p){\n        rt.update(et.ls[v],et.rs[v],c[v]);\n        for(int u:et.G[v])\n          if(p!=u) dfs(u,v);\n      };\n    dfs(0, -1);\n\n    for(int i=0;i<q;i++){\n      int type;\n      scanf(\"%d\",&type);\n\n      if(type==0){\n        int u,w;\n        scanf(\"%d %d\",&u,&w);\n        u--;\n        rt.update(et.ls[u],et.rs[u],w);\n      }\n      if(type==1){\n        int u;\n        scanf(\"%d\",&u);\n        u--;\n        printf(\"%d\\n\",rt.count(et.ls[u],et.rs[u]));\n      }\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "string/ahocorasick.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"trie.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<size_t X, bool heavy>\nstruct AhoCorasick : Trie<X+1>{\n  using super = Trie<X+1>;\n  using super::super, super::next, super::size;\n  using super::vs, super::conv;\n\n  vector<int> cnt,ord;\n\n  // O(\\sigma \\sum |T_i|)\n  void build(){\n    int n=vs.size();\n    cnt.resize(n);\n    for(int i=0;i<n;i++){\n      if(heavy) sort(vs[i].idxs.begin(),vs[i].idxs.end());\n      cnt[i]=vs[i].idxs.size();\n    }\n\n    queue<int> que;\n    for(int i=0;i<(int)X;i++){\n      if(~next(0,i)){\n        next(next(0,i),X)=0;\n        que.emplace(next(0,i));\n      }else{\n        next(0,i)=0;\n      }\n    }\n\n    while(!que.empty()){\n      ord.emplace_back(que.front());\n      auto &x=vs[que.front()];\n      int fail=x.nxt[X];\n\n      cnt[que.front()]+=cnt[fail];\n      que.pop();\n\n      for(int i=0;i<(int)X;i++){\n        int &nx=x.nxt[i];\n        if(nx<0){\n          nx=next(fail,i);\n          continue;\n        }\n        que.emplace(nx);\n        next(nx,X)=next(fail,i);\n        if(heavy){\n          auto &idx=vs[nx].idxs;\n          auto &idy=vs[next(fail,i)].idxs;\n          vector<int> idz;\n          set_union(idx.begin(),idx.end(),\n                    idy.begin(),idy.end(),\n                    back_inserter(idz));\n          idx=idz;\n        }\n      }\n    }\n    reverse(ord.begin(),ord.end());\n  }\n\n  int count(int pos){\n    return cnt[pos];\n  }\n\n  // O(|S|)\n  long long match(string s){\n    long long res=0;\n    int pos=0;\n    for(auto &c:s){\n      pos=next(pos,conv(c));\n      res+=count(pos);\n    }\n    return res;\n  }\n\n  // O(|S| + \\sum |T_i|)\n  vector<int> frequency(string s){\n    vector<int> res(size(),0);\n    int pos=0;\n    for(auto &c:s){\n      pos=next(pos,conv(c));\n      res[pos]++;\n    }\n    for(int p:ord)\n      res[vs[p].nxt[X]]+=res[p];\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/editdistance.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../tools/chminmax.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nint edit_distance(string s,string t){\n  int n=s.size(),m=t.size();\n  vector< vector<int> > dp(n+1,vector<int>(m+1,n+m+1));\n  dp[0][0]=0;\n  for(int i=0;i<=n;i++){\n    for(int j=0;j<=m;j++){\n      if(i<n) chmin(dp[i+1][j],dp[i][j]+1);\n      if(j<m) chmin(dp[i][j+1],dp[i][j]+1);\n      if(i<n and j<m)\n        chmin(dp[i+1][j+1],dp[i][j]+(s[i]!=t[j]));\n    }\n  }\n  return dp[n][m];\n}\n//END CUT HERE\n//INSERT ABOVE HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/knuthmorrispratt.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n// https://snuke.hatenablog.com/entry/2017/07/18/101026\n//BEGIN CUT HERE\nvector<int> knuth_morris_pratt(const string &s){\n  int n=s.size();\n  vector<int> kmp(n+1,-1);\n  for(int i=0,j=-1;i<n;i++){\n    while(~j and s[i]!=s[j]) j=kmp[j];\n    kmp[i+1]=++j;\n    if(i+1<n and s[i+1]==s[j]) kmp[i+1]=kmp[j];\n  }\n  return kmp;\n}\n// positions for t that match s\nvector<int> pattern_match(string s,string t){\n  int n=s.size(),m=t.size();\n  vector<int> kmp=knuth_morris_pratt(s);\n\n  vector<int> res;\n  int i=0,j=0;\n  while(i+j<m){\n    if(s[j]==t[i+j]){\n      if(++j!=n) continue;\n      res.emplace_back(i);\n    }\n    i+=j-kmp[j];\n    j=max(kmp[j],0);\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n\ntemplate<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}\ntemplate<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}\n\n//INSERT ABOVE HERE\n\n// test knuth_morris_pratt\nsigned ABC135_F(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  string s,t;\n  cin>>s>>t;\n\n  int n=s.size(),m=t.size();\n\n  string b;\n  while(b.size()<t.size()) b+=s;\n  auto kmp=knuth_morris_pratt(t+'$'+b+b);\n\n  vector<int> match(n);\n  for(int i=m+1;i<=m+n;i++)\n    match[i-(m+1)]=kmp[i+m]==m;\n\n  vector< vector<int> > G(n);\n  for(int i=0;i<n;i++)\n    if(match[i]) G[i].emplace_back((i+m)%n);\n\n  vector<int> indeg(n,0);\n  for(int i=0;i<n;i++)\n    for(int j:G[i]) indeg[j]++;\n\n  queue<int> que;\n  for(int i=0;i<n;i++)\n    if(indeg[i]==0) que.emplace(i);\n\n  vector<int> dp(n,0);\n  while(!que.empty()){\n    int v=que.front();que.pop();\n    for(int u:G[v]){\n      chmax(dp[u],dp[v]+1);\n      indeg[u]--;\n      if(indeg[u]==0) que.emplace(u);\n    }\n  }\n\n  for(int i=0;i<n;i++){\n    if(indeg[i]!=0){\n      cout<<-1<<endl;\n      return 0;\n    }\n  }\n\n  cout<<*max_element(dp.begin(),dp.end())<<endl;\n  return 0;\n}\n/*\n  verified on 2020/08/20\n  https://atcoder.jp/contests/abc135/tasks/abc135_f\n*/\n\nsigned main(){\n  ABC135_F();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/longestcommonprefix.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"suffixarray.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n\ntemplate<typename Seq = string>\nstruct LongestCommonPrefix{\n  SuffixArray<Seq> sa;\n\n  vector<int> ht;\n  vector< vector<int> > dat;\n  LongestCommonPrefix(const Seq &s):sa(s){\n    int n=s.size();\n    vector<int> lcp(n,0);\n\n    int t=0;\n    lcp[0]=0;\n    for(int i=0;i<n;i++){\n      int j=sa[sa.rev[i]-1];\n      if(t>0) t--;\n      for(;j+t<n and i+t<n;t++){\n        if(s[j+t]!=s[i+t]) break;\n      }\n      lcp[sa.rev[i]-1]=t;\n    }\n\n    int h=1;\n    while((1<<h)<n) h++;\n    dat.assign(h,vector<int>(n));\n    ht.assign(n+1,0);\n    for(int j=2;j<=n;j++) ht[j]=ht[j>>1]+1;\n\n    for(int j=0;j<n;j++) dat[0][j]=lcp[j];\n    for(int i=1,p=1;i<h;i++,p<<=1)\n      for(int j=0;j<n;j++)\n        dat[i][j]=min(dat[i-1][j],dat[i-1][min(j+p,n-1)]);\n  }\n\n  // a, b are indices for suffix array\n  int query(int a,int b){\n    assert(a!=b);\n    if(a>b) swap(a,b);\n    int l=b-a;\n    return min(dat[ht[l]][a],dat[ht[l]][b-(1<<ht[l])]);\n  }\n\n  // a, b are indices for string\n  int lcp(int a,int b){\n    return query(sa.rev[a],sa.rev[b]);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/longestcommonsubstring.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// O(nm)\nstring longest_common_substring(string s,string t){\n  int n=s.size(),m=t.size();\n  s+='$';t+='%';\n  vector< vector<int> > dp(n+2,vector<int>(m+2,-(n+m)));\n  dp[0][0]=0;\n\n  auto chmax=[&](int &a,int b){if(a<b) a=b;};\n  for(int i=0;i<=n;i++){\n    for(int j=0;j<=m;j++){\n      chmax(dp[i+1][j],dp[i][j]);\n      chmax(dp[i][j+1],dp[i][j]);\n      chmax(dp[i+1][j+1],dp[i][j]+(s[i]==t[j]));\n    }\n  }\n  if(dp[n][m]==0) return \"\"s;\n  string ans;\n  int i=n,j=m;\n  while(dp[i][j]){\n    if((dp[i][j]==dp[i-1][j-1]+1) and (s[i-1]==t[j-1])){\n      ans+=s[i-1];\n      i--;j--;\n    }else if(dp[i][j]==dp[i-1][j]) i--;\n    else j--;\n  }\n  reverse(ans.begin(),ans.end());\n  return ans;\n}\n//END CUT HERE\n//INSERT ABOVE HERE\n#ifndef call_from_test\nsigned DP_F(){\n  string s,t;\n  cin>>s>>t;\n  cout<<longest_common_substring(s,t)<<endl;\n  return 0;\n}\n/*\n  verified on 2020/12/21\n  https://atcoder.jp/contests/dp/tasks/dp_f\n*/\n\nsigned main(){\n  DP_F();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/manacher.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n// https://snuke.hatenablog.com/entry/2014/12/02/235837\n//BEGIN CUT HERE\nvector<int> manacher(string s){\n  int n=s.size();\n  vector<int> vs(n);\n  for(int i=0,j=0;i<n;){\n    while(i-j>=0 and i+j<n and s[i-j]==s[i+j]) j++;\n    vs[i]=j;\n    int k=1;\n    while(i-k>=0 and i+k<n and k+vs[i-k]<j) vs[i+k]=vs[i-k],k++;\n    i+=k;j-=k;\n  }\n  return vs;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/morrispratt.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n// https://snuke.hatenablog.com/entry/2014/12/01/235807\n// https://kopricky.github.io/code/String/kmp.html\n//BEGIN CUT HERE\n// longest prefix suffix matching of [0, i)\nvector<int> morris_pratt(const string &s){\n  int n=s.size();\n  vector<int> mp(n+1,-1);\n  for(int i=0,j=-1;i<n;i++){\n    while(~j and s[i]!=s[j]) j=mp[j];\n    mp[i+1]=++j;\n  }\n  return mp;\n}\n// smallest d s.t. s[x] == s[x + d] for all x\nvector<int> minimum_period(const string &s){\n  auto mp=morris_pratt(s);\n  for(int i=1;i<(int)mp.size();i++) mp[i]=i-mp[i];\n  return mp;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\n// test minimum_period\nsigned ARC060_F(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  string w;\n  cin>>w;\n\n  int n=w.size();\n  if(w==string(n,w[0])){\n    cout<<n<<endl<<1<<endl;\n    return 0;\n  }\n\n  auto kmp=minimum_period(w);\n  if(n%kmp[n]!=0 or n==kmp[n]){\n    cout<<1<<endl<<1<<endl;\n    return 0;\n  }\n\n  string w_rev=w;\n  reverse(w_rev.begin(),w_rev.end());\n  auto kmp_rev=minimum_period(w_rev);\n\n  int cnt=0;\n  for(int i=1;i<n;i++){\n    int j=n-i;\n    if(i%kmp[i]==0 and i>kmp[i]) continue;\n    if(j%kmp_rev[j]==0 and j>kmp_rev[j]) continue;\n    cnt++;\n  }\n  cout<<2<<endl<<cnt<<endl;\n  return 0;\n}\n/*\n  verified on 2020/08/20\n  https://atcoder.jp/contests/arc060/tasks/arc060_d\n*/\n\nsigned main(){\n  ARC060_F();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/palindromictree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct PalindromicTree{\n  struct node{\n    map<char, int> nxt;\n    int len,suf,app,cnt;\n    node():len(-1){}\n    node(int len,int suf,int app,int cnt)\n      :len(len),suf(suf),app(app),cnt(cnt){}\n  };\n  vector<node> vs;\n  vector<int> ord;\n  int n,ptr;\n\n  PalindromicTree(const string &s)\n    :vs(s.size()+10),n(2),ptr(1){\n\n    vs[0]=node(-1,0,-1,0);\n    vs[1]=node( 0,0,-1,0);\n\n    for(int i=0;i<(int)s.size();i++) add_char(s,i);\n    calc_order();\n    calc_count();\n  }\n\n  bool add_char(const string &s,int pos){\n    char ch=s[pos];\n    int cur=ptr;\n    while(1){\n      int rev=pos-1-vs[cur].len;\n      if(rev>=0 and s[rev]==ch) break;\n      cur=vs[cur].suf;\n    }\n\n    if(vs[cur].nxt.count(ch)){\n      ptr=vs[cur].nxt[ch];\n      vs[ptr].cnt++;\n      return false;\n    }\n    ptr=n++;\n\n    vs[ptr]=node(vs[cur].len+2,-1,pos-vs[cur].len-1,1);\n    vs[cur].nxt[ch]=ptr;\n\n    if(vs[ptr].len==1){\n      vs[ptr].suf=1;\n      return true;\n    }\n\n    while(1){\n      cur=vs[cur].suf;\n      int rev=pos-1-vs[cur].len;\n      if(rev>=0 and s[rev]==ch){\n        vs[ptr].suf=vs[cur].nxt[ch];\n        break;\n      }\n    }\n    return true;\n  }\n\n  void calc_order(){\n    ord.clear();\n    ord.emplace_back(0);\n    ord.emplace_back(1);\n    for(int i=0;i<(int)ord.size();i++)\n      for(auto &p:vs[ord[i]].nxt) ord.emplace_back(p.second);\n  }\n\n  void calc_count(){\n    for(int i=(int)ord.size()-1;i>=0;i--)\n      vs[vs[ord[i]].suf].cnt+=vs[ord[i]].cnt;\n  }\n\n  size_t size()const{return n;}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/parse.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nint expression(string&,int&);\nint term(string&,int&);\nint factor(string&,int&);\nint number(string&,int&);\n\nbool f;\n\nint expression(string& s,int& p){\n  int res=term(s,p);\n  while(p<(int)s.size()){\n    if(s[p]=='+'){\n      p++;\n      res+=term(s,p);\n      continue;\n    }\n    if(s[p]=='-'){\n      p++;\n      res-=term(s,p);\n      continue;\n    }\n    break;\n  }\n  return res;\n}\n\nint term(string& s,int& p){\n  int res=factor(s,p);\n  while(p<(int)s.size()){\n    if(s[p]=='*'){\n      p++;\n      res*=factor(s,p);\n      continue;\n    }\n    if(s[p]=='/'){\n      p++;\n      int tmp=factor(s,p);\n      if(tmp==0){\n        f=1;\n        break;\n      }\n      res/=tmp;\n      continue;\n    }\n    break;\n  }\n  return res;\n}\n\nint factor(string& s,int& p){\n  int res;\n  if(s[p]=='('){\n    p++;\n    res=expression(s,p);\n    p++;\n  }else{\n    res=number(s,p);\n  }\n  return res;\n}\n\nint number(string& s,int& p){\n  int res=0;\n  while(p<(int)s.size() and isdigit(s[p]))\n    res=res*10+s[p++]-'0';\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/rectanglehash.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"rollinghash.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T,T MOD,T B1,T B2>\nauto rectangle_hash(vector<string> vs,int r,int c){\n  vector< RollingHash<T, MOD, B1> > hs;\n  for(string s:vs) hs.emplace_back(s);\n\n  int h=vs.size(),w=vs[0].size();\n  vector< vector<T> > res(h-r+1,vector<T>(w-c+1));\n\n  for(int j=0;j+c<=w;j++){\n    vector<T> ts(h);\n    for(int i=0;i<h;i++)\n      ts[i]=hs[i].find(j,j+c);\n\n    RollingHash<T, MOD, B2> rh(ts);\n    for(int i=0;i+r<=h;i++)\n      res[i][j]=rh.find(i,i+r);\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/rollinghash.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T,T MOD,T B>\nstruct RollingHash{\n  using ll = long long;\n  vector<T> hash,po;\n  RollingHash(vector<T> vs){init(vs);}\n  RollingHash(string &s){\n    vector<T> vs;\n    for(char c:s) vs.emplace_back(c);\n    init(vs);\n  }\n  void init(vector<T> vs){\n    int n=vs.size();\n    hash.assign(n+1,0);\n    po.assign(n+1,1);\n    for(int i=0;i<n;i++){\n      hash[i+1]=((ll)hash[i]*B+vs[i])%MOD;\n      po[i+1]=(ll)po[i]*B%MOD;\n    }\n  }\n  //S[l, r)\n  T find(int l,int r){\n    T res=(ll)hash[r]+MOD-(ll)hash[l]*po[r-l]%MOD;\n    return res>=MOD?res-MOD:res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/run.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"zalgorithm.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nnamespace Run{\n  using T = tuple<int, int, int>;\n  using P = pair<int, int>;\n  vector<vector<P>> run;\n\n  template<typename C>\n  vector<T> sub(const vector<C> &xs,const vector<C> &ys){\n    auto ps=xs;\n    auto qs=ys;\n    reverse(ps.begin(),ps.end());\n    qs.insert(qs.end(),xs.begin(),xs.end());\n    qs.insert(qs.end(),ys.begin(),ys.end());\n    auto zp=zalgorithm(ps);\n    auto zq=zalgorithm(qs);\n    vector<T> res;\n    for(int i=0;i<(int)xs.size();i++){\n      int a=xs.size()-i;\n      int b=i-zp[a];\n      int c=max(0,(int)ys.size()-zq[ys.size()+i]);\n      if((int)(xs.size()+ys.size())-b-c>=2*a)\n        res.emplace_back(a,b,c);\n    }\n    return res;\n  }\n\n  template<typename C>\n  void dfs(int l,int r,const vector<C> &cs){\n    if(l+1>=r) return;\n    int m=(l+r)>>1;\n    vector<C> xs(cs.begin()+l,cs.begin()+m);\n    vector<C> ys(cs.begin()+m,cs.begin()+r);\n    {\n      auto zs=sub(xs,ys);\n      for(auto w:zs){\n        int a,b,c;\n        tie(a,b,c)=w;\n        run[a].emplace_back(l+b,r-c);\n      }\n    }\n    reverse(xs.begin(),xs.end());\n    reverse(ys.begin(),ys.end());\n    {\n      auto zs=sub(ys,xs);\n      for(auto w:zs){\n        int a,b,c;\n        tie(a,b,c)=w;\n        run[a].emplace_back(l+c,r-b);\n      }\n    }\n    dfs(l,m,cs);\n    dfs(m,r,cs);\n  }\n\n  // return all t (not only minimal)\n  template<typename C>\n  vector<vector<P>> enumerate(const vector<C> &cs){\n    int n=cs.size();\n    run.clear();\n    run.resize(n+1);\n    dfs(0,n,cs);\n\n    auto cmp=[&](P a,P b){return P(a.first,-a.second)<P(b.first,-b.second);};\n    for(int i=1;i<=n;i++){\n      auto &rs=run[i];\n      sort(rs.begin(),rs.end(),cmp);\n      int mx=-1;\n      vector<P> tmp;\n      for(auto p:rs){\n        if(mx<p.second){\n          tmp.emplace_back(p);\n          mx=p.second;\n        }\n      }\n      rs=tmp;\n    }\n    return run;\n  }\n\n  vector<vector<P>> enumerate(string ss){\n    return enumerate(vector<char>(ss.begin(),ss.end()));\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/split.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nvector<string> split(string& s,char c){\n  int n=s.size();\n  vector<string> res;\n  for(int i=0;i<n;i++){\n    if(s[i]==c) continue;\n    res.emplace_back();\n    while(i<n and s[i]!=c) res.back()+=s[i++];\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/suffixarray.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename Seq = string>\nstruct SuffixArray{\n  const Seq s;\n  vector<int> sa,rev;\n\n  SuffixArray(const Seq &s_):s(s_){\n\n    int n=s.size();\n    auto cmp=[&](int a,int b){\n      if(a==b) return false;\n      if(a==n) return true;\n      if(b==n) return false;\n      if(s[a]==s[b]) return a>b;\n      return s[a]<s[b];\n    };\n\n    sa.resize(n+1);\n    iota(sa.begin(),sa.end(),0);\n    sort(sa.begin(),sa.end(),cmp);\n\n    vector<int> rs(n+1);\n    {\n      Seq t(s);\n      sort(t.begin(),t.end());\n      t.erase(unique(t.begin(),t.end()),t.end());\n      for(int i=0;i<n;i++)\n        rs[i]=std::lower_bound(t.begin(),t.end(),s[i])-t.begin();\n      rs[n]=0;\n    }\n\n    for(int len=1;len<=n;len*=2){\n      vector<int> cs(n+1);\n      for(int i=0;i<=n;i++){\n        cs[sa[i]]=i;\n        if(i==0) continue;\n        if(rs[sa[i-1]]!=rs[sa[i]]) continue;\n        if(sa[i-1]+len>=n) continue;\n        if(rs[sa[i-1]+len/2]!=rs[sa[i]+len/2]) continue;\n        cs[sa[i]]=cs[sa[i-1]];\n      }\n      vector<int> cnt(n+1);\n      iota(cnt.begin(),cnt.end(),0);\n      copy(sa.begin(),sa.end(),rs.begin());\n      for(int i=0;i<=n;i++){\n        int s1=rs[i]-len;\n        if(s1>=0) sa[cnt[cs[s1]]++]=s1;\n      }\n      cs.swap(rs);\n    }\n    rev.resize(n+1);\n    for(int i=0;i<=n;i++) rev[sa[i]]=i;\n  }\n\n  int operator[](int i) const{return sa[i];}\n\n  bool lt_substr(const Seq &t,int si,int ti){\n    int sn=s.size(),tn=t.size();\n    while(si<sn and ti<tn){\n      if(s[si]<t[ti]) return 1;\n      if(s[si]>t[ti]) return 0;\n      si++;ti++;\n    }\n    return si==sn and ti<tn;\n  }\n\n  int lower_bound(Seq t){\n    int l=0,r=s.size()+1;\n    while(l+1<r){\n      int m=(l+r)>>1;\n      if(lt_substr(t,sa[m],0)) l=m;\n      else r=m;\n    }\n    return r;\n  }\n\n  int upper_bound(Seq t){\n    t.back()++;\n    int res=lower_bound(t);\n    t.back()--;\n    return res;\n  }\n\n  // O(|t| \\log|s|)\n  int count(Seq t){\n    return upper_bound(t)-lower_bound(t);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  vector<int> vs({1, 2, 3, 1, 2, 1});\n  SuffixArray sa(vs);\n  for(int i=0;i<=(int)vs.size();i++) cout<<sa[i]<<endl;\n\n  cout<<sa.count({1})<<endl;\n  cout<<sa.count({1, 2})<<endl;\n  cout<<sa.count({1, 2, 3})<<endl;\n  cout<<sa.count({1, 2, 3, 4})<<endl;\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/trie.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<size_t X>\nstruct Trie{\n  struct Node{\n    array<int, X> nxt;\n    vector<int> idxs;\n    int idx;\n    Node():idx(-1){fill(nxt.begin(),nxt.end(),-1);}\n  };\n\n  using F = function<int(char)>;\n  vector<Node> vs;\n  F conv;\n\n  Trie(F conv):conv(conv){vs.emplace_back();}\n  Trie(char start):Trie([=](char a){return a-start;}){}\n\n  inline int &next(int i,int j){\n    return vs[i].nxt[j];\n  }\n\n  void add(const string &s,int x){\n    int pos=0;\n    for(char c:s){\n      int k=conv(c);\n      if(~next(pos,k)){\n        pos=next(pos,k);\n        continue;\n      }\n      int npos=vs.size();\n      next(pos,k)=npos;\n      vs.emplace_back();\n      pos=npos;\n    }\n    vs[pos].idx=x;\n    vs[pos].idxs.emplace_back(x);\n  }\n\n  int find(const string &s){\n    int pos=0;\n    for(char c:s){\n      int k=conv(c);\n      if(next(pos,k)<0) return -1;\n      pos=next(pos,k);\n    }\n    return pos;\n  }\n\n  int move(int pos,char c){\n    assert(pos<(int)vs.size());\n    return pos<0?-1:next(pos,conv(c));\n  }\n\n  int size(){return vs.size();}\n\n  int idx(int pos){\n    return pos<0?-1:vs[pos].idx;\n  }\n\n  vector<int> idxs(int pos){\n    return pos<0?vector<int>():vs[pos].idxs;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "string/zalgorithm.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\n// longest common prefix of s and s[i:n]\n// return n + 1 elements for run enumerate\ntemplate<typename T>\nvector<int> zalgorithm(vector<T> vs){\n  int n=vs.size();\n  vector<int> as(n+1,0);\n  as[0]=n;\n  int i=1,j=0;\n  while(i<n){\n    while(i+j<n and vs[j]==vs[i+j]) j++;\n    as[i]=j;\n    if(j==0){\n      i++;\n      continue;\n    }\n    int k=1;\n    while(i+k<n and k+as[k]<j) as[i+k]=as[k],k++;\n    i+=k;\n    j-=k;\n  }\n  return as;\n}\nvector<int> zalgorithm(string s){\n  return zalgorithm(vector<char>(s.begin(),s.end()));\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "test/aoj/0109.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0109\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/parse.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  while(n--){\n    string s;\n    int p=0;\n    cin>>s;\n    s.pop_back();\n    cout<<expression(s,p)<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0168.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0168\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../convolution/naive.cpp\"\n#include \"../../math/bostanmori.cpp\"\n#undef call_from_test\n\nsigned main(){\n  using ll = long long;\n  BostanMori<ll> bm(naive<ll>());\n\n  using Poly = vector<ll>;\n  Poly as({0,0,1}),cs({-1,-1,-1,1});\n\n  int n;\n  while(cin>>n,n)\n    cout<<(bm.build(n+2,as,cs)+3650-1)/3650<<endl;\n\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0233.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0233\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/convertbase.cpp\"\n#undef call_from_test\n\nsigned main(){\n  long long p;\n  while(cin>>p,p){\n    auto ans=convert_base(p,-10LL);\n    for(auto x:ans) cout<<x;\n    cout<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0294.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0294\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/dominatortree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  DominatorTree G(n);\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    G.add_edge(a,b);\n  }\n  G.build(0);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int r;\n    cin>>r;\n    r--;\n    cout<<(G[r]?G[r]:r)+1<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0314.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0314\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../linearalgebra/matrix.cpp\"\n#include \"../../datastructure/unionfind.cpp\"\n#include \"../../linearalgebra/tree_theorem.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  using M = Mint<int>;\n  using edge=MatrixTreeTheorem<M, int>::edge;\n  vector<edge> es;\n  for(int i=0;i<m;i++){\n    int s,t,d;\n    cin>>s>>t>>d;\n    s--;t--;\n    es.emplace_back(s,t,d);\n  }\n  sort(es.begin(),es.end());\n  UnionFind uf(n);\n  int cost=0;\n  for(auto e:es){\n    uf.unite(e.a,e.b);\n    cost=e.c;\n    if(uf.count()==1) break;\n  }\n  cout<<cost<<\" \";\n\n  uf=UnionFind(n);\n  for(auto e:es){\n    if(e.c==cost) break;\n    uf.unite(e.a,e.b);\n  }\n\n  vector<int> rs;\n  for(int i=0;i<n;i++)\n    if(uf.find(i)==i) rs.emplace_back(i);\n\n  M ans{0};\n  int k=rs.size();\n  int sz=1<<k;\n  for(int b=1;b+1<sz;b++){\n    UnionFind tmp(uf);\n    for(int i=0;i<k;i++)\n      for(int j=0;j<k;j++)\n        if(((b>>i)&1)==((b>>j)&1))\n          tmp.unite(rs[i],rs[j]);\n\n    MatrixTreeTheorem<M, int> G(n);\n    for(auto e:es)\n      if(tmp.same(e.a,e.b))\n        G.add_edge(e.a,e.b,0);\n\n    auto[k,res,_]=G.build();\n    if(k==2) ans+=res;\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0343.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0343\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../vector/compress.cpp\"\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n,c;\n  cin>>n>>c;\n  vector<int> ts(c),is(c),ps(c);\n  for(int i=0;i<c;i++){\n    cin>>ts[i]>>is[i];\n    if(ts[i]==0) cin>>ps[i],is[i]--;\n  }\n\n  vector<ll> ss(n,0);\n\n  using P = pair<ll, int>;\n  vector<P> vp;\n  for(int i=0;i<n;i++) vp.emplace_back(-ss[i],i);\n\n  for(int i=0;i<c;i++){\n    if(ts[i]==0){\n      ss[is[i]]+=ps[i];\n      vp.emplace_back(-ss[is[i]],is[i]);\n    }\n  }\n  vp=compress(vp);\n  auto dc=dict(vp);\n\n  BIT<int> bit(vp.size());\n\n  fill(ss.begin(),ss.end(),0);\n  for(int i=0;i<n;i++) bit.add(dc[P(-ss[i],i)],+1);\n\n  for(int i=0;i<c;i++){\n    if(ts[i]==0){\n      bit.add(dc[P(-ss[is[i]],is[i])],-1);\n      ss[is[i]]+=ps[i];\n      bit.add(dc[P(-ss[is[i]],is[i])],+1);\n    }\n    if(ts[i]==1){\n      int k=bit.lower_bound(is[i])-1;\n      cout<<vp[k].second+1<<' '<<-vp[k].first<<'\\n';\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0367.linkcuttree.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0367\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/path.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n,k;\n  cin>>n>>k;\n\n  using T = tuple<ll, ll, ll>;\n  vector<ll> ws(n,0);\n  vector< unordered_map<ll, ll> > m(n);\n\n  auto mget=[&](ll a,ll b){\n    if(!m[a].count(b)) return 0LL;\n    ll res=ws[a]+ws[b]+m[a][b];\n    if(res%k) return res;\n    return 0LL;\n  };\n\n  auto f=[&](T a,T b){\n    ll al,ar,av;\n    tie(al,ar,av)=a;\n    ll bl,br,bv;\n    tie(bl,br,bv)=b;\n    return T(al,br,av+bv+mget(ar,bl));\n  };\n\n  auto g=[&](T a,ll){return a;};\n\n  auto h=[&](ll a,ll){return a;};\n\n  auto s=[&](T a){\n    ll al,ar,av;\n    tie(al,ar,av)=a;\n    return T(ar,al,av);\n  };\n\n  using Node = NodeBase<T, ll>;\n  constexpr size_t LIM = 1e6;\n  using LCT = Path<Node, LIM>;\n  LCT lct(f,g,h,s,0);\n  for(int i=0;i<n;i++) lct.create(T(i,i,0));\n\n  for(int i=0;i<n-1;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    lct.evert(lct[b]);\n    lct.link(lct[a],lct[b]);\n    m[a][b]=m[b][a]=c;\n  }\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    string op;\n    cin>>op;\n    if(op==\"add\"){\n      int x,d;\n      cin>>x>>d;\n      lct.expose(lct[x]);\n      ws[x]+=d;\n      lct.pushup(lct[x]);\n    }\n    if(op==\"send\"){\n      int s,t;\n      cin>>s>>t;\n      lct.evert(lct[s]);\n      cout<<get<2>(lct.query(lct[t]))<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0367.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0367\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../tools/trio.cpp\"\n#include \"../../tree/heavylightdecomposition.cpp\"\n#include \"../../segtree/basic/ushi.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n,k;\n  cin>>n>>k;\n\n  HLD hld(n);\n  using P = pair<int, int>;\n  map<P, int> es;\n  for(int i=1;i<n;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    hld.add_edge(a,b);\n    es[P(a,b)]=es[P(b,a)]=c;\n  }\n  hld.build();\n\n  vector<ll> dep(n);\n  MFP([&](auto dfs,int v,int p,ll d)->void{\n        dep[v]=d;\n        for(int u:hld.G[v])\n          if(u!=p) dfs(u,v,d+es[P(u,v)]);\n      })(0,-1,0);\n\n  vector<ll> ws(n,0);\n  auto con=[&](int a,int b){return hld.par[a]==b||hld.par[b]==a;};\n  auto cst=\n    [&](int a,int b)->ll{\n      if(!con(a,b)) return 0;\n      ll res=ws[a]+ws[b]+abs(dep[a]-dep[b]);\n      return res%k?res:0;\n    };\n\n  using T = trio<int, int, ll>;\n  T ti(-1,-1,-1);\n  auto f=\n    [&](T a,T b){\n      if(a.first<0||a.second<0) return b;\n      if(b.first<0||b.second<0) return a;\n      for(int i=0;i<2;i++){\n        for(int j=0;j<2;j++){\n          if(con(a.first,b.first))\n            return T(a.second,b.second,a.third+b.third+cst(a.first,b.first));\n          swap(a.first,a.second);\n        }\n        swap(b.first,b.second);\n      }\n      return ti;\n    };\n\n  SegmentTree<T> seg(f,ti);\n  vector<T> vt;\n  for(int i=0;i<n;i++)\n    vt.emplace_back(hld.inv[i],hld.inv[i],0);\n  seg.build(vt);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    string op;\n    cin>>op;\n    if(op==\"add\"){\n      int x,d;\n      cin>>x>>d;\n      ws[x]+=d;\n      seg.set_val(hld.vid[x],T(x,x,0));\n    }\n    if(op==\"send\"){\n      int s,t;\n      cin>>s>>t;\n      int u=hld.lca(s,t);\n      T r1(ti),r2(ti);\n      hld.for_each(s,u,[&](int l,int r){r1=f(r1,seg.query(l,r));});\n      hld.for_each_edge(t,u,[&](int l,int r){r2=f(r2,seg.query(l,r));});\n      cout<<f(r1,r2).third<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0367.toptree.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0367\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../toptree/toptree.cpp\"\n#undef call_from_test\n\nusing ll = long long;\n\nll K;\nll calc(ll val){return val%K?val:0;}\n\nstruct Vertex{\n  ll w;\n  void* handle;\n  Vertex(ll w=0):w(w),handle(nullptr){}\n};\n\nstruct Cluster{\n  ll edge,all,lft,rgh;\n  Cluster(ll edge=-1):edge(edge),all(0),lft(0),rgh(0){}\n  void toggle(){\n    swap(lft,rgh);\n  }\n  static Cluster compress(Cluster x,Vertex *v,Cluster y){\n    Cluster nxt;\n    nxt.all=x.all+y.all;\n\n    if(~x.edge) x.lft=x.edge+(v->w);\n    else nxt.all+=calc(x.rgh+(v->w));\n\n    if(~y.edge) y.rgh=(v->w)+y.edge;\n    else nxt.all+=calc((v->w)+y.lft);\n\n    nxt.lft=x.lft;\n    nxt.rgh=y.rgh;\n    return nxt;\n  }\n  static Cluster rake(Cluster x,Cluster){\n    return x;\n  }\n};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n;\n  cin>>n>>K;\n\n  const size_t N = 1e5;\n  TopTree<Vertex, Cluster, N> T;\n\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++) vs[i]=T.create();\n\n  for(int i=1;i<n;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    T.link(vs[a],Cluster(c),vs[b]);\n  }\n\n  vector<ll> ws(n,0);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    string op;\n    cin>>op;\n    if(op==\"add\"){\n      int x,d;\n      cin>>x>>d;\n      ws[x]+=d;\n      T.set_vertex(vs[x],Vertex(ws[x]));\n    }\n    if(op==\"send\"){\n      int s,t;\n      cin>>s>>t;\n      Cluster res=T.get_path(vs[s],vs[t]);\n      if(~res.edge) cout<<calc(ws[s]+res.edge+ws[t])<<newl;\n      else cout<<res.all+calc(ws[s]+res.lft)+calc(res.rgh+ws[t])<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0377.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0377\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../graph/twoedgeconnectedcomponents.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  TwoEdgeConnectedComponents tecc(n);\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    tecc.add_edge(a,b);\n  }\n  int k=tecc.build();\n  auto G=tecc.forest();\n\n  vector<int> cs(k);\n  for(int i=0;i<k;i++) cs[i]=tecc[i].size();\n\n  vector<vector<int>> dp(2,vector<int>(k,0));\n  vector<int> used(k,0);\n  auto dfs=\n    MFP([&](auto dfs,int v,int p)->void{\n          if(used[v]) return;\n          used[v]=1;\n          dp[0][v]=0;\n          dp[1][v]=cs[v];\n          for(int u:G[v]){\n            if(u==p) continue;\n            dfs(u,v);\n            dp[0][v]+=max(dp[0][u],dp[1][u]);\n            dp[1][v]+=dp[0][u];\n          }\n          return;\n        });\n\n  int ans=0;\n  for(int i=0;i<k;i++){\n    if(used[i]) continue;\n    dfs(i,-1);\n    ans+=max(dp[0][i],dp[1][i]);\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0391.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0391\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../tree/levelancestor.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n  using P = pair<int, int>;\n  vector<vector<P> > G(n);\n  LevelAncestor la(n);\n  for(int i=1;i<n;i++){\n    int u,v,w;\n    cin>>u>>v>>w;\n    u--;v--;\n    la.add_edge(u,v);\n    G[u].emplace_back(v,w);\n    G[v].emplace_back(u,w);\n  }\n  la.build();\n\n  vector<int> dep(n,0);\n  {\n    queue<P> q;\n    q.emplace(0,-1);\n    while(!q.empty()){\n      int v,p;\n      tie(v,p)=q.front();q.pop();\n      for(auto e:G[v]){\n        int u,c;\n        tie(u,c)=e;\n        if(u==p) continue;\n        dep[u]=dep[v]+c;\n        q.emplace(u,v);\n      }\n    }\n  }\n\n  auto dist=[&](int u,int v){return dep[u]+dep[v]-2*dep[la.lca(u,v)];};\n  auto path=\n    [&](int u,int v,int d){\n      if(d==0) return u;\n      int r=la.lca(u,v);\n      int x=la.distance(u,r),y=la.distance(r,v);\n      if(d<=x) return la.up(u,d);\n      return la.up(v,(x+y)-d);\n    };\n\n  for(int i=0;i<q;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    a--;b--;c--;\n    auto calc=\n      [&](int v,int u=-1){\n        return max({dist(a,v)*(a!=u),\n                    dist(b,v)*(b!=u),\n                    dist(c,v)*(c!=u)});\n      };\n\n    int p=la.lca(a,b),q=la.lca(b,c),r=la.lca(c,a);\n    int v=la.dep[p]>la.dep[q]?p:(la.dep[q]>la.dep[r]?q:r);\n\n    int ans=min({calc(a),calc(b),calc(c),calc(v)});\n    for(int u:{a,b,c}){\n      if(calc(v,u)>=ans) continue;\n      int l=0,r=la.distance(u,v);\n      while(l+1<r){\n        int m=(l+r)>>1;\n        int x=path(u,v,m);\n        if(calc(x,u)<dist(x,u)) r=m;\n        else l=m;\n      }\n      chmin(ans,calc(path(u,v,l)));\n      chmin(ans,calc(path(u,v,r)));\n    }\n    cout<<ans<<newl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0402.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0402\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../convolution/bitwise/fwht.cpp\"\n#include \"../../convolution/bitwise/xor.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  ll n,k;\n  cin>>n>>k;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  const int LOG = 20;\n  const int sz = 1<<LOG;\n  vector<ll> cnt(sz,0);\n  cnt[0]++;\n  for(int i=0,s=0;i<n;i++){\n    s^=as[i];\n    cnt[s]++;\n  }\n\n  fwht(cnt,bitwise_xor::zeta);\n  for(ll &v:cnt) v=v*v;\n  fwht(cnt,bitwise_xor::moebius);\n\n  k--;\n  for(int v=sz-1;v>=0;v--){\n    cnt[v]/=2;\n    if(cnt[v]<=k){\n      k-=cnt[v];\n      continue;\n    }\n    cout<<v<<endl;\n    break;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0403.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0403\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/manhattanmst.cpp\"\n#include \"../../datastructure/unionfind.cpp\"\n#include \"../../graph/kruskal.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  vector<int> xs(n),ys(n);\n  for(int i=0;i<n;i++)\n    cin>>xs[i]>>ys[i];\n\n  vector<long long> us(n),vs(n);\n  for(int i=0;i<n;i++){\n    us[i]=xs[i]+ys[i];\n    vs[i]=xs[i]-ys[i];\n  }\n\n  Kruskal<long long> G(n);\n  for(auto [u,v]:manhattanmst(us,vs)){\n    int c=max(abs(xs[u]-xs[v]),abs(ys[u]-ys[v]));\n    G.add_edge(u,v,c);\n  }\n  cout<<G.build()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0415.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0415\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../graph/twoedgeconnectedcomponents.cpp\"\n#include \"../../tree/diameterforvertex.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n,m;\n  cin>>n>>m;\n  vector<ll> vs(n);\n  for(int i=0;i<n;i++) cin>>vs[i];\n\n  TwoEdgeConnectedComponents C(n);\n  for(int i=0;i<m;i++){\n    int s,t;\n    cin>>s>>t;\n    s--;t--;\n    C.add_edge(s,t);\n  }\n\n  int k=C.build();\n  vector<ll> sm(k,0);\n  for(int i=0;i<n;i++)\n    sm[C.blg[i]]+=vs[i];\n\n  auto T=C.forest();\n\n  ll ans=0;\n  vector<int> used(k,-1);\n  for(int i=0;i<k;i++){\n    if(~used[i]) continue;\n    int sz=0;\n    queue<int> que;\n    used[i]=sz++;\n    que.emplace(i);\n\n    vector<int> vv;\n    vector<ll> ws;\n    while(!que.empty()){\n      int v=que.front();que.pop();\n      vv.emplace_back(v);\n      ws.emplace_back(sm[v]);\n      for(int u:T[v]){\n        if(~used[u]) continue;\n        used[u]=sz++;\n        que.emplace(u);\n      }\n    }\n\n    DiameterForVertex<ll> H(ws);\n    for(int v:vv)\n      for(int u:T[v])\n        if(u<v) H.add_edge(used[u],used[v]);\n\n    chmax(ans,H.build());\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0422.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0422\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/drop.cpp\"\n#include \"../../mod/rint.cpp\"\n#undef call_from_test\n\nsigned main(){\n\n  int n,k,m;\n  cin>>n>>k>>m;\n\n  using R = Rint<int>;\n  R::set_mod(m);\n  if(n>k*2) drop(R(k).pow(n));\n\n  int sz=1<<(k*2-1);\n  vector< vector<R> > dp(k,vector<R>(sz,0));\n  for(int i=0;i<k;i++) dp[i][0]=1;\n\n  R ans=R(k).pow(n);\n  for(int bit=0;bit<sz;bit++){\n    for(int i=0;i<k;i++){\n      if(dp[i][bit]==0) continue;\n      if(__builtin_popcount(bit)+1==n){\n        ans-=dp[i][bit];\n      }\n      for(int j=0;j<k;j++){\n        int d=(i-j)+(k-1);\n        if((bit>>d)&1) continue;\n        dp[j][bit|(1<<d)]+=dp[i][bit];\n      }\n    }\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0423.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0423\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/dijkstra.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  vector<int> ts(n),es(n);\n  for(int i=0;i<n;i++) cin>>ts[i]>>es[i];\n\n  Dijkstra<int> G(n+1);\n  for(int i=0;i<m;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    a--;b--;c--;\n    G.add_edge(b,a,c);\n  }\n\n  for(int i=0;i<n;i++) G.add_edge(n,i,ts[i]);\n  G.build(n);\n\n  long long ans=0;\n  for(int i=0;i<n;i++) ans+=(long long)G[i]*es[i];\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0424.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0424\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../matching/hopcroft_karp.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<string> ss(n);\n  for(int i=0;i<n;i++) cin>>ss[i];\n\n  int L=0,R=0;\n  map<string, int> mp;\n  for(int i=0;i<n;i++){\n    if(ss[i].size()&1){\n      mp[ss[i]]=L++;\n    }else{\n      mp[ss[i]]=R++;\n    }\n  }\n\n  HopcroftKarp G(L,R);\n  for(int i=0;i<n;i++){\n    int m=ss[i].size();\n    for(int j=0;j<m;j++){\n      string t(ss[i]);\n      t.erase(t.begin()+j);\n      if(!mp.count(t)) continue;\n      int u=mp[ss[i]],v=mp[t];\n      if(t.size()&1) swap(u,v);\n      G.add_edge(u,v);\n    }\n  }\n\n  cout<<G.build()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0425.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0425\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../algorithm/mo.cpp\"\n#include \"../../vector/identity.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,k,q;\n  cin>>n>>k>>q;\n  vector<int> as(k),bs(k);\n  for(int i=0;i<k;i++) cin>>as[i]>>bs[i],as[i]--,bs[i]--;\n\n  vector<int> ord=identity(n);\n  vector<int> pos=identity(n);\n  auto moveL=\n    [&](int i){\n      int x=pos[as[i]],y=pos[bs[i]];\n      swap(ord[x],ord[y]);\n      swap(pos[ord[x]],pos[ord[y]]);\n    };\n  auto moveR=\n    [&](int i){\n      int x=as[i],y=bs[i];\n      swap(ord[x],ord[y]);\n      swap(pos[ord[x]],pos[ord[y]]);\n    };\n  Mo mo(q,400,moveL,moveR,moveL,moveR);\n\n  vector<int> qs(q),ls(q),rs(q),xs(q);\n  for(int i=0;i<q;i++){\n    cin>>qs[i]>>ls[i]>>rs[i]>>xs[i];\n    ls[i]--;xs[i]--;\n    mo.add(ls[i],rs[i]);\n  }\n  mo.build();\n\n  vector<int> ans(q,-1);\n  for(int i=0;i<q;i++){\n    int p=mo.process();\n    if(qs[p]==1) ans[p]=ord[xs[p]]+1;\n    if(qs[p]==2) ans[p]=pos[xs[p]]+1;\n  }\n\n  for(int a:ans) cout<<a<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0437.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0437\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/ushi.cpp\"\n#include \"../../bbst/rbst/impl/persistent.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  using ll = long long;\n  auto f=[&](ll a,ll b){return a+b;};\n  auto flip=[&](ll a){return a;};\n  using Data = Ushi<ll, decltype(f), decltype(flip)>;\n  using Node = Data::Node;\n  const size_t LIM = 3e6;\n  Persistent<Data, LIM> G(f,flip,0);\n\n  int n,m;\n  cin>>n>>m;\n  auto as=read<ll>(n);\n  auto bs=read<ll>(n);\n\n  auto A=G.build(vector<Node>(as.begin(),as.end()));\n  auto B=G.build(vector<Node>(bs.begin(),bs.end()));\n  auto R=G.merge(A,B);\n\n  for(int i=0;i<m;i++){\n    int t;\n    cin>>t;\n\n    tie(A,B)=G.split(R,n);\n\n    if(t==0){\n      int x,y,z;\n      cin>>x>>y>>z;\n      x--;y--;\n      auto pa=G.split(A,x);\n      auto qa=G.split(pa.second,z);\n\n      auto pb=G.split(B,y);\n      auto qb=G.split(pb.second,z);\n\n      A=G.merge(pa.first,G.merge(qb.first,qa.second));\n    }\n\n    if(t==1){\n      int p,q;\n      cin>>p>>q;\n      p--;\n      cout<<G.query(A,p,q)<<newl;\n    }\n\n    R=G.merge(A,B);\n\n    if(G.almost_full()) R=G.rebuild(R);\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0438.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0438\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/array.cpp\"\n#include \"../../bbst/rbst/impl/basic.cpp\"\n#undef call_from_test\n\nstruct T;\nusing Node = Array<T>::Node;\n\nstruct T{\n  Node* nxt;\n  char c;\n  T():nxt(nullptr){}\n  T(Node* nxt,char c):nxt(nxt),c(c){}\n};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  auto cs=read<char>(n);\n\n  vector<vector<int>> G(n);\n  for(int i=0;i+1<n;i++)\n    G[i].emplace_back(i+1);\n\n  for(int i=0;i<m;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    G[u].emplace_back(v);\n  }\n\n  const size_t LIM = 1e6;\n  using Data = Array<T>;\n  Basic<Data, LIM> H;\n  vector<Node*> ps(n,nullptr);\n  ps[n-1]=H.create(Node(T(nullptr,cs[n-1])));\n  auto R=ps[n-1];\n\n  for(int i=n-2;i>=0;i--){\n    auto nxt=ps[i+1];\n\n    auto comp1=[&](Node* a,Node* b){\n      return H.order_of_key(a)<H.order_of_key(b);\n    };\n\n    for(int j:G[i])\n      if(comp1(ps[j],nxt)) nxt=ps[j];\n\n    ps[i]=H.create(Node(T(nxt,cs[i])));\n\n    auto comp2=[&](Node* a,Node* b){\n      if(a->val.c!=b->val.c) return (a->val.c)<(b->val.c);\n      if(a->val.nxt==b->val.nxt) return false;\n      if(!a->val.nxt) return true;\n      if(!b->val.nxt) return false;\n      return comp1(a->val.nxt,b->val.nxt);\n    };\n\n    int l=-1,r=n-(i+1);\n    // comp(ps[i], l) : false\n    // comp(ps[i], r) : true\n    while(l+1<r){\n      int m=(l+r)>>1;\n      auto p=H.find_by_order(R,m);\n      if(comp2(ps[i],p)) r=m;\n      else l=m;\n    }\n    auto s=H.split(R,r);\n    R=H.merge(H.merge(s.first,ps[i]),s.second);\n  }\n\n  auto cur=ps[0];\n  while(cur){\n    cout<<(cur->val.c);\n    cur=cur->val.nxt;\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0439.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0439\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../tree/lowestcommonancestor.cpp\"\n#include \"../../tree/auxiliarytree.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\ncin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n;\n  cin>>n;\n\n  auto cs=read(n);\n\n  AuxiliaryTree G(n);\n  for(int i=1;i<n;i++){\n    int s,t;\n    cin>>s>>t;\n    s--;t--;\n    G.add_edge(s,t);\n  }\n  G.build();\n  auto dep=G.dep;\n\n  vector<vector<int>> C(n);\n  for(int i=0;i<n;i++)\n    C[cs[i]-1].emplace_back(i);\n\n  vector<int> ds(n),idx(n);\n  auto dijkstra=[&](auto &vs,auto &ss){\n    using P = pair<int, int>;\n    priority_queue<P, vector<P>, greater<P>> pq;\n    for(int v:vs) ds[v]=n,idx[v]=-1;\n    for(int s:ss) ds[s]=0,idx[s]=s,pq.emplace(ds[s],s);\n    while(!pq.empty()){\n      int d=pq.top().first;\n      int v=pq.top().second;\n      pq.pop();\n      if(ds[v]<d) continue;\n      for(auto u:G.T[v]){\n        int c=abs(dep[u]-dep[v]);\n        if(ds[u]>ds[v]+c){\n          ds[u]=ds[v]+c;\n          idx[u]=idx[v];\n          pq.emplace(ds[u],u);\n        }\n      }\n    }\n  };\n\n  vector<int> ans(n,n);\n  for(int c=0;c<n;c++){\n    if(C[c].empty()) continue;\n    assert(C[c].size()>1);\n    auto vs=C[c];\n\n    G.query(vs);\n\n    dijkstra(vs,C[c]);\n\n    for(int v:vs){\n      for(int u:G.T[v]){\n        if(idx[v]==idx[u]) continue;\n        chmin(ans[idx[v]],G.distance(idx[v],idx[u]));\n        chmin(ans[idx[u]],G.distance(idx[v],idx[u]));\n      }\n    }\n\n    G.clear(vs);\n  }\n\n  for(int a:ans) cout<<a<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0502.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0502\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/dice.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  while(cin>>n,n){\n    Die d;\n    for(int i=0;i<6;i++) d.fs[i]=i+1;\n\n    int ans=d.top();\n    for(int i=0;i<n;i++){\n      string s;\n      cin>>s;\n      d.roll(s[0]);\n      ans+=d.top();\n    }\n    cout<<ans<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0558.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0558\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/gridbfs.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int h,w,n;\n  cin>>h>>w>>n;\n\n  vector<string> st(h);\n  for(int i=0;i<h;i++) cin>>st[i];\n\n  for(int i=0;i<h;i++)\n    for(int j=0;j<w;j++)\n      if(st[i][j]=='S') st[i][j]='0';\n\n  vector<int> ys(n+1),xs(n+1);\n  for(int i=0;i<h;i++){\n    for(int j=0;j<w;j++){\n      if(!isdigit(st[i][j])) continue;\n      int p=st[i][j]-'0';\n      ys[p]=i;xs[p]=j;\n    }\n  }\n\n  int ans=0;\n  for(int k=0;k<n;k++)\n    ans+=gridbfs(st,ys[k],xs[k],'X',4)[ys[k+1]][xs[k+1]];\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0563.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0563\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/pb_ds_tree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int w,h,n;\n  cin>>w>>h>>n;\n  vector<int> xs(n),ys(n);\n  for(int i=0;i<n;i++) cin>>xs[i]>>ys[i];\n\n  using P = pair<int, int>;\n  gtree<P> gx,gy;\n  for(int i=0;i<n;i++){\n    gx.insert(P(xs[i],i));\n    gy.insert(P(ys[i],i));\n    gx.insert(P(xs[i],n+i));\n    gy.insert(P(ys[i],n+i));\n  }\n\n  ll ans=1e18;\n  int ax=-1,ay=-1;\n\n  map<int, ll> mx,my;\n\n  for(int i=0;i<n;i++){\n    gx.erase(P(xs[i],i));\n    gy.erase(P(ys[i],i));\n\n\n    int tx=gx.find_by_order(n-1)->first;\n    int ty=gy.find_by_order(n-1)->first;\n\n    if(!mx.count(tx)){\n      mx[tx]=0;\n      for(int j=0;j<n;j++)\n        mx[tx]+=abs(xs[j]-tx)*2;\n    }\n\n    if(!my.count(ty)){\n      my[ty]=0;\n      for(int j=0;j<n;j++)\n        my[ty]+=abs(ys[j]-ty)*2;\n    }\n\n    ll res=mx[tx]+my[ty]-(abs(xs[i]-tx)+abs(ys[i]-ty));\n    if((res< ans)||\n       (res==ans&&tx< ax)||\n       (res==ans&&tx==ax&&ty< ay)){\n      ans=res;\n      ax=tx;\n      ay=ty;\n    }\n\n\n    gx.insert(P(xs[i],i));\n    gy.insert(P(ys[i],i));\n  }\n\n  cout<<ans<<endl;\n  cout<<ax<<\" \"<<ay<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0596.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0596\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/bfs.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  cin>>n>>k;\n\n  vector<int> cs(n),rs(n);\n  for(int i=0;i<n;i++) cin>>cs[i]>>rs[i];\n\n  vector<vector<int> > G(n);\n  for(int i=0;i<k;i++){\n    int x,y;\n    cin>>x>>y;\n    x--;y--;\n    G[x].emplace_back(y);\n    G[y].emplace_back(x);\n  }\n\n  vector< vector<int> > di(n);\n  for(int i=0;i<n;i++) di[i]=bfs(i,G);\n\n  const int INF = 1e9;\n  vector<int> dp(n,INF);\n  vector<int> used(n,0);\n  dp[0]=0;\n\n  for(int i=0;i<n;i++){\n    int u=-1;\n    for(int j=0;j<n;j++){\n      if(used[j]||dp[j]==INF) continue;\n      if(u<0||dp[u]>dp[j]) u=j;\n    }\n    if(u<0) break;\n    used[u]=1;\n    for(int j=0;j<n;j++){\n      if(di[u][j]>rs[u]) continue;\n      chmin(dp[j],dp[u]+cs[u]);\n    }\n  }\n\n  cout<<dp[n-1]<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/0613.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0613\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../datastructure/rangeslide.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n;\n  ll d;\n  cin>>n>>d;\n  vector<ll> xs(n),ys(n);\n  for(int i=0;i<n;i++) cin>>xs[i]>>ys[i];\n\n  if(n==1){\n    cout<<(xs[0]<=d?ys[0]:0)<<endl;\n    return 0;\n  }\n\n  int h=n/2;\n  using P = pair<ll, ll>;\n  auto calc=\n    [&](int a,int b){\n      vector<P> res;\n      MFP([&](auto dfs,int k,ll s,ll t)->void{\n            if(k==b){\n              res.emplace_back(s,t);\n              return;\n            }\n            dfs(k+1,s,t);\n            dfs(k+1,s+xs[k],t+ys[k]);\n            dfs(k+1,s-xs[k],t-ys[k]);\n          })(a,0,0);\n      sort(res.begin(),res.end());\n      return res;\n    };\n  auto v1=calc(0,h);\n  auto v2=calc(h,n);\n  reverse(v2.begin(),v2.end());\n\n  const ll INF = 1e17;\n  vector<ll> vs;\n  for(auto p:v1) vs.emplace_back(p.first);\n  vs.emplace_back(-INF);\n  vs.emplace_back(+INF);\n  vs=compress(vs);\n\n  vector<ll> ws(vs.size(),-INF);\n  {\n    int k=0;\n    for(auto p:v1){\n      while(vs[k]<p.first) k++;\n      chmax(ws[k],p.second);\n    }\n  }\n  v1.clear();\n\n  auto cmp=[](ll a,ll b){return a>b;};\n  RangeSlide<ll, decltype(cmp)> slide(ws,cmp);\n\n  vector<ll> ks;\n  {\n    int l=0,r=0;\n    for(auto p:v2){\n      ll x=p.first,k=p.second;\n      while(l<(int)vs.size()&&vs[l]< -x-d) l++;\n      while(r<(int)vs.size()&&vs[r]<=-x+d) r++;\n      if(l==r) continue;\n      slide.add_range(l,r);\n      ks.emplace_back(k);\n    }\n  }\n  vs.clear();\n  v2.clear();\n\n  auto res=slide.build();\n\n  ll ans=0;\n  for(int i=0;i<(int)res.size();i++)\n    chmax(ans,ws[res[i]]+ks[i]);\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1069.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1069\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/int128.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nusing ll = __int128_t;\n\nll sqrt(ll x){\n  assert(x>=0);\n  if(x<=1) return x;\n  ll l=0,r=x;\n  while(l+1<r){\n    ll m=(l+r)>>1;\n    if(m<=x/m&&m*m<=x) l=m;\n    else r=m;\n  }\n  return l;\n}\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  while(cin>>n,n){\n    int m=n*(n+1)/2;\n\n    vector<ll> bs(m),es,os;\n    for(int i=0;i<m;i++) cin>>bs[i];\n    for(ll b:bs)\n      ((b&1)?os:es).emplace_back(b);\n\n    sort(es.begin(),es.end());\n    sort(os.begin(),os.end());\n\n    ll a=sqrt(es[0]*es[1]/os[0]);\n    cout<<a<<endl;\n    for(int i=0;i<n;i++){\n      if(i) cout<<\" \";\n      cout<<es[i]/a;\n    }\n    cout<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1197.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1197\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/dice.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  vector<int> ts(6);\n  do{\n    for(int i=0;i<6;i++) cin>>ts[i];\n    int sum=0;\n    for(int t:ts) sum+=t;\n    if(sum==0) break;\n\n    auto check=\n      [&](Die<int> d)->int{\n        for(int i=0;i<6;i++)\n          if(d.fs[i]<0) return 0;\n        int a=d.top()+d.bottom();\n        int b=d.east()+d.west();\n        int c=d.south()+d.north();\n        if(a>b+c) return 0;\n        if(b>(a+1)+c) return 0;\n        if(c>(a+1)+b) return 0;\n        return 1;\n      };\n\n    string ans(sum,'Z');\n    sort(ts.begin(),ts.end());\n    do{\n      Die d;\n      for(int i=0;i<6;i++) d.fs[i]=ts[i];\n      if(!check(d)) continue;\n\n      string res(sum,'Z');\n      int flg=0;\n      for(int i=0;i<sum;i++){\n        string B=\"ENSW\";\n        string R=\"WSNE\";\n        for(int j=0;j<4;j++){\n          d.roll(B[j]);\n          d.bottom()--;\n          if(check(d)){\n            res[i]=B[j];\n            break;;\n          }\n          d.bottom()++;\n          d.roll(R[j]);\n        }\n        flg|=res[i]<ans[i];\n        if(flg) continue;\n        if(res[i]>ans[i]) break;\n      }\n\n      if(flg) ans=res;\n    }while(next_permutation(ts.begin(),ts.end()));\n\n    int p,q;\n    cin>>p>>q;\n    p--;\n    if(ans[0]!='Z') cout<<ans.substr(p,q-p)<<endl;\n    else cout<<\"impossible\"<<endl;\n  }while(1);\n\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1254.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1254\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/chromatic.cpp\"\n#undef call_from_test\n\nconst double EPS = 1e-10;\n\nstruct Point{\n  double x,y;\n  Point(){}\n  Point(double x,double y) :x(x),y(y){}\n  Point operator+(Point p) {return Point(x+p.x,y+p.y);}\n  Point operator-(Point p) {return Point(x-p.x,y-p.y);}\n  Point operator*(double k){return Point(x*k,y*k);}\n  Point operator/(double k){return Point(x/k,y/k);}\n};\n\ntypedef Point Vector;\ntypedef vector<Point> Polygon;\n\ndouble norm(Vector a){\n  return a.x*a.x+a.y*a.y;\n}\ndouble abs(Vector a){\n  return sqrt(norm(a));\n}\ndouble cross(Vector a,Vector b){\n  return a.x*b.y-a.y*b.x;\n}\n\nbool calc(Point a1,Point a2,Point b1,Point b2){\n  if(abs(cross(a2-a1,b1-a1))>EPS) return 0;\n  if(abs(cross(a2-a1,b2-a1))>EPS) return 0;\n  double ml=0;\n  ml=max(ml,abs(a1-a2));\n  ml=max(ml,abs(a1-b1));\n  ml=max(ml,abs(a1-b2));\n  ml=max(ml,abs(a2-b1));\n  ml=max(ml,abs(a2-b2));\n  ml=max(ml,abs(b1-b2));\n  return (ml+EPS<abs(a1-a2)+abs(b1-b2));\n}\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  while(cin>>n,n){\n    vector<Polygon> p(n);\n    vector<string> name(n);\n    map<string,int> m;\n    for(int i=0;i<n;i++){\n      cin>>name[i];\n      if(!m.count(name[i])){\n        int k=m.size();\n        m[name[i]]=k;\n      }\n      int x,y;\n      while(cin>>x,~x){\n        cin>>y;\n        p[i].emplace_back(x,y);\n      }\n    }\n\n    vector<vector<int> > G(m.size(),vector<int>(m.size(),0));\n    for(int i=0;i<n;i++){\n      for(int j=i+1;j<n;j++){\n        if(name[i]==name[j]) continue;\n        for(int k=0;k<(int)p[i].size();k++){\n          for(int l=0;l<(int)p[j].size();l++){\n            G[m[name[i]]][m[name[j]]]|=\n              calc(p[i][k],p[i][(k+1)%p[i].size()],\n                   p[j][l],p[j][(l+1)%p[j].size()]);\n            G[m[name[j]]][m[name[i]]]|=\n              calc(p[i][k],p[i][(k+1)%p[i].size()],\n                   p[j][l],p[j][(l+1)%p[j].size()]);\n          }\n        }\n      }\n    }\n    cout<<chromatic(G)<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1293.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1293\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../polynomial/polynomial.cpp\"\n#undef call_from_test\n\nusing P = Polynomial<int>;\n\nP expr(string s,int &p);\nP factor(string s,int &p);\nP term(string s,int &p);\nint number(string s,int &p);\n\nP expr(string s,int &p){\n  P res;\n  if(s[p]=='-'){\n    p++;\n    res=-factor(s,p);\n  }else res=factor(s,p);\n\n  while(p<(int)s.size()){\n    if(s[p]=='+'){\n      p++;\n      res=res+factor(s,p);\n      continue;\n    }\n    if(s[p]=='-'){\n      p++;\n      res=res-factor(s,p);\n      continue;\n    }\n    break;\n  }\n  return res;\n}\n\nP factor(string s,int &p){\n  P res=term(s,p);\n  while(p<(int)s.size()){\n    if(s[p]=='+') break;\n    if(s[p]=='-') break;\n    if(s[p]==')') break;\n    res=res*term(s,p);\n  }\n  return res;\n}\n\nP term(string s,int &p){\n  if(s[p]=='('){\n    p++;\n    P res=expr(s,p);\n    assert(s[p]==')');\n    p++;\n    if(s[p]=='^'){\n      p++;\n      int k=number(s,p);\n      res=res.pow(res,k);\n    }\n    return res;\n  }\n  int v=(s[p]=='x'?1:number(s,p));\n  if(p<(int)s.size()&&s[p]=='x'){\n    p++;\n    if(p<(int)s.size()&&s[p]=='^'){\n      p++;\n      int k=number(s,p);\n      P res(k+1);\n      res[k]=v;\n      return res;\n    }\n    P res(2);\n    res[1]=v;\n    return res;\n  }\n  P res;\n  res[0]=v;\n  return res;\n}\n\nint number(string s,int &p){\n  int res=0;\n  while(p<(int)s.size()&&isdigit(s[p]))\n    res=res*10+(s[p++]-'0');\n  return res;\n}\n\nP calc(string s){\n  int p=0;\n  return expr(s,p);\n}\n\nsigned main(){\n  string s,t;\n  while(cin>>s,s!=\".\"){\n    cin>>t;\n    P ps=calc(s);\n    P pt=calc(t);\n    P ans=gcd(ps,pt);\n    ans.print();\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1300.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1300\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/split.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../mod/mint.cpp\"\n#undef call_from_test\n\nusing S = map<string, int>;\nS add(S x,S y){\n  for(auto p:y)\n    x[p.first]+=p.second;\n  return x;\n}\nS mul(S x,int k){\n  for(auto &p:x)\n    p.second*=k;\n  return x;\n}\n\nS term(string s){\n  S res;\n  int n=s.size();\n  for(int i=0;i<n;){\n    if(s[i]=='('){\n      int j=s.find(')',i);\n      string t=s.substr(i+1,j-(i+1));\n      auto tmp=term(t);\n      i=j+1;\n      if(i==n) continue;\n      if(isdigit(s[i])){\n        int num=0;\n        while(i<n&&isdigit(s[i]))\n          num=num*10+(s[i]-'0'),i++;\n        tmp=mul(tmp,num);\n      }\n      res=add(res,tmp);\n      continue;\n    }\n    assert(isupper(s[i]));\n    string c;\n    c+=s[i],i++;\n    while(i<n&&islower(s[i])) c+=s[i],i++;\n    int num=0;\n    while(i<n&&isdigit(s[i]))\n      num=num*10+(s[i]-'0'),i++;\n    if(num==0) num=1;\n    res[c]+=num;\n  }\n  return res;\n}\n\nvector<S> conv(string s){\n  vector<S> res;\n  for(auto t:split(s,'+'))\n    res.emplace_back(term(t));\n  return res;\n}\n\nsigned solve(string s){\n  s.pop_back();\n  string x=s.substr(0,s.find(\"->\"));\n  string y=s.substr(s.find(\"->\")+2);\n  auto t1=conv(x);\n  auto t2=conv(y);\n\n  vector<string> ms;\n  for(auto rs:t1)\n    for(auto p:rs)\n      ms.emplace_back(p.first);\n  for(auto rs:t2)\n    for(auto p:rs)\n      ms.emplace_back(p.first);\n  ms=compress(ms);\n  auto dc=dict(ms);\n\n  int n=ms.size();\n  int m=t1.size()+t2.size();\n\n  using M = Mint<int>;\n  vector< vector<M> > mat(n,vector<M>(m));\n  for(int i=0;i<(int)t1.size();i++)\n    for(auto p:t1[i])\n      mat[dc[p.first]][i]=M(p.second);\n\n  for(int i=0;i<(int)t2.size();i++)\n    for(auto p:t2[i])\n      mat[dc[p.first]][t1.size()+i]=-M(p.second);\n\n  for(int j=0;j+1<m;j++){\n    {\n      int k=-1;\n      for(int i=j;i<n;i++)\n        if(mat[i][j]!=M(0)) k=i;\n      assert(~k);\n      swap(mat[j],mat[k]);\n    }\n    for(int k=m-1;k>=j;k--)\n      mat[j][k]/=mat[j][j];\n\n    for(int i=j+1;i<n;i++){\n      M cof=mat[i][j];\n      for(int k=0;k<m;k++)\n        mat[i][k]-=cof*mat[j][k];\n    }\n  }\n\n  for(int j=m-2;j>=0;j--){\n    for(int i=0;i<j;i++){\n      M cof=mat[i][j];\n      for(int k=0;k<m;k++)\n        mat[i][k]-=cof*mat[j][k];\n    }\n  }\n\n  using ll = long long;\n  auto check=\n    [&](vector<ll> cof)->int{\n      map<string, ll> res;\n      for(int i=0;i<(int)t1.size();i++)\n        for(auto p:t1[i])\n          res[p.first]+=p.second*cof[i];\n      for(int i=0;i<(int)t2.size();i++)\n        for(auto p:t2[i])\n          res[p.first]-=p.second*cof[t1.size()+i];\n      for(auto p:res)\n        if(p.second!=0) return 0;\n      return 1;\n    };\n\n  const int MAX = 40000;\n  for(ll l=1;l<=MAX;l++){\n    vector<ll> cof(m,0);\n    cof[m-1]=l;\n    for(int i=0;i+1<m;i++)\n      cof[i]=(-M(l)*mat[i][m-1]).v;\n    if(*max_element(cof.begin(),cof.end())>MAX) continue;\n\n    if(check(cof)){\n      for(int i=0;i<m;i++){\n        if(i) cout<<\" \";\n        cout<<cof[i];\n      }\n      cout<<endl;\n      break;\n    }\n  }\n  return 0;\n}\n\nsigned main(){\n  string s;\n  while(cin>>s,s!=\".\") solve(s);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1308.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1308\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linearalgebra/binarymatrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int m,n,d;\n  while(cin>>m>>n>>d,m){\n    vector<vector<int> > s(n,vector<int>(m));\n    for(int i=0;i<n;i++)\n      for(int j=0;j<m;j++)\n        cin>>s[i][j];\n\n    mat v(n*m,BS(0));\n    auto idx=[&](int y,int x){return y*m+x;};\n    auto in=[&](int y,int x){return 0<=y&&y<n&&0<=x&&x<m;};\n\n    auto bfs=\n      [&](int y,int x){\n        int z=idx(y,x);\n        v[z][z]=1;\n        v[z][n*m]=s[y][x];\n\n        vector<vector<int> > dp(n,vector<int>(m,-1));\n        using P = pair<int, int>;\n        queue<P> q;\n        dp[y][x]=0;\n        q.emplace(y,x);\n        int dy[]={0,0,1,-1};\n        int dx[]={1,-1,0,0};\n        while(!q.empty()){\n          tie(y,x)=q.front();q.pop();\n          if(dp[y][x]==d) v[z][idx(y,x)]=1;\n          for(int k=0;k<4;k++){\n            int ny=y+dy[k],nx=x+dx[k];\n            if(!in(ny,nx)||~dp[ny][nx]) continue;\n            dp[ny][nx]=dp[y][x]+1;\n            q.emplace(ny,nx);\n          }\n        }\n      };\n\n    for(int i=0;i<n;i++)\n      for(int j=0;j<m;j++)\n        bfs(i,j);\n\n    int a=mrank(v,n*m);\n    int b=mrank(v,n*m+1);\n    cout<<(a==b)<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1312.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1312\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/rollinghash.cpp\"\n#include \"../../string/rectanglehash.cpp\"\n#undef call_from_test\n\nint conv(char c){\n  if(isupper(c)) return c-'A';\n  if(islower(c)) return 26+c-'a';\n  if(isdigit(c)) return 52+c-'0';\n  if(c=='+') return 62;\n  if(c=='/') return 63;\n  assert(0);\n}\n\nvector<string> decode(vector<string> vs,int h,int w){\n  vector<string> rs(h,string(w,'$'));\n  for(int i=0;i<h;i++)\n    for(int j=0;j<(int)vs[i].size();j++)\n      for(int k=0;k<6&&j*6+k<w;k++)\n        rs[i][j*6+k]=char('0'+((conv(vs[i][j])>>(5-k))&1));\n  return rs;\n}\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int w,h,p;\n  while(cin>>w>>h>>p,w){\n    vector<string> ss(h);\n    for(int i=0;i<h;i++) cin>>ss[i];\n\n    vector<string> ts(p);\n    for(int i=0;i<p;i++) cin>>ts[i];\n\n    const int MOD = 1e9+7;\n    const int B1 = 1777771;\n    const int B2 = 1e8+7;\n    auto srh=rectangle_hash<int, MOD, B1, B2>(decode(ss,h,w),p,p);\n\n    vector< vector<int> > found(h,vector<int>(w,0));\n\n    auto pat=decode(ts,p,p);\n    for(int rev=0;rev<2;rev++){\n      for(int rot=0;rot<4;rot++){\n        auto tmp(pat);\n        for(int i=0;i<p;i++)\n          for(int j=0;j<p;j++)\n            pat[i][j]=tmp[j][p-(i+1)];\n\n        auto val=rectangle_hash<int, MOD, B1, B2>(pat,p,p)[0][0];\n\n        for(int i=0;i<h-p+1;i++)\n          for(int j=0;j<w-p+1;j++)\n            if(srh[i][j]==val) found[i][j]=1;\n      }\n\n      for(auto &s:pat)\n        reverse(s.begin(),s.end());\n    }\n\n    int cnt=0;\n    for(int i=0;i<h-p+1;i++)\n      for(int j=0;j<w-p+1;j++)\n        if(found[i][j]) cnt++;\n\n    cout<<cnt<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1328.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1328\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linearalgebra/matrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using M = Matrix<double>;\n  using arr = M::arr;\n\n  int d;\n  while(cin>>d,d){\n    arr vs(d+3);\n    for(int i=0;i<d+3;i++) cin>>vs[i];\n    int ans=0;\n    M m(d+3,d+2);\n    for(int i=0;i<d+3;i++)\n      for(int j=0;j<d+1;j++)\n        m[i][j]=pow(1.0*i,j);\n\n    for(int i=0;i<d+3;i++){\n      for(int j=i+1;j<d+3;j++){\n        arr b(d+1);\n        M A(d+1,d+1);\n        for(int k=0,l=0;k<d+3;k++)\n          if(i!=k&&j!=k) A[l]=m[k],b[l]=vs[k],l++;\n\n        arr x=M::linear_equations(A,b);\n        if(x.empty()) continue;\n        double res[2]={};\n        for(int k=0;k<d+1;k++){\n          res[0]+=x[k]*m[i][k];\n          res[1]+=x[k]*m[j][k];\n        }\n        const double EPS = 1e-5;\n        if(abs(res[0]-vs[i])>0.5&&abs(res[1]-vs[j])<EPS) ans=i;\n        if(abs(res[0]-vs[i])<EPS&&abs(res[1]-vs[j])>0.5) ans=j;\n      }\n    }\n    cout<<ans<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1338.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1338\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/fraction.cpp\"\n#undef call_from_test\n\nusing ll = long long;\nusing frac = fraction<ll>;\n\nint H,h,m,s;\nvoid print(frac f){\n  int t=f.num/(f.den*60);\n  cout<<(t%(60*H))/60<<\" \";\n  cout<<(t%60)<<\" \";\n  cout<<(f.num)%(f.den*60)<<\" \"<<f.den<<endl;\n}\n\nfrac norm2(frac a){\n  if(a.num==0) return frac(0,1);\n  while(a.num<0) a.num+=a.den;\n  while(a.num>=a.den) a.num-=a.den;\n  ll tmp=__gcd(a.num,a.den);\n  return frac(a.num/tmp,a.den/tmp);\n}\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  while(cin>>H>>h>>m>>s,H){\n    const frac base(h*3600+m*60+s,1);\n    const frac vh(1,3600*H),vm(1,3600),vs(1,60);\n    frac t(max(h*3600+m*60+s-100,0),1);\n    while(1){\n      frac x=norm2(t*vh);\n      frac y=norm2(t*vm);\n      frac z=norm2(t*vs);\n      if(y<x) y=y+frac(1,1);\n      if(z<x) z=z+frac(1,1);\n      frac ans(10000000,1);\n      {\n        frac t1=frac(1,1)-(z-x);\n        frac t2=z-y;\n        frac tmp=t+(t1-t2)/(vs*2-(vh+vm));\n        if(base<=tmp){\n          frac a=norm2(tmp*vh);\n          frac b=norm2(tmp*vm);\n          frac c=norm2(tmp*vs);\n          if(b<a) b=b+frac(1,1);\n          if(c<a) c=c+frac(1,1);\n          if(b<c){\n            t1=frac(1,1)-(c-a);\n            t2=c-b;\n            if(a!=b&&b!=c&&c!=a&&t1==t2)\n              ans=min(ans,tmp);\n          }\n        }\n      }\n      {\n        frac t1=z-x;\n        frac t2=y-z;\n        frac tmp=t+(t2-t1)/(vs*2-(vh+vm));\n        if(base<=tmp){\n          frac a=norm2(tmp*vh);\n          frac b=norm2(tmp*vm);\n          frac c=norm2(tmp*vs);\n          if(b<a) b=b+frac(1,1);\n          if(c<a) c=c+frac(1,1);\n          if(b>c){\n            t1=c-a;\n            t2=b-c;\n            if(a!=b&&b!=c&&c!=a&&t1==t2)\n              ans=min(ans,tmp);\n          }\n        }\n      }\n      if(ans!=frac(10000000,1)){\n        print(ans);\n        break;\n      }\n      t=t+frac(1,1);\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1508.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1508\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/ushi.cpp\"\n#include \"../../bbst/rbst/impl/basic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n  vector<int> vs(n);\n  for(int i=0;i<n;i++) cin>>vs[i];\n\n  auto f=[](int a,int b){return min(a,b);};\n  auto flip=[](int a){return a;};\n  const int INF = 1e9;\n\n  using Data = Ushi<int, decltype(f), decltype(flip)>;\n  using Node = Data::Node;\n  constexpr size_t LIM = 1e6;\n  Basic<Data, LIM> G(f,flip,INF);\n\n  auto rt=G.build(vector<Node>(vs.begin(),vs.end()));\n\n  for(int i=0;i<q;i++){\n    int x,y,z;\n    cin>>x>>y>>z;\n    if(x==0){\n      int l=y,r=z+1;\n      rt=G.toggle(rt,l,r);\n      rt=G.toggle(rt,l+1,r);\n    }\n    if(x==1){\n      int l=y,r=z+1;\n      cout<<G.query(rt,l,r)<<newl;\n    }\n    if(x==2){\n      rt=G.set_val(rt,y,z);\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1549.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1549\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../datastructure/waveletmatrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  const int OFS = 1e6;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i],as[i]+=OFS;\n  WaveletMatrix<int, 21> wm(as);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int l,r,d;\n    cin>>l>>r>>d;\n    r++;\n    d+=OFS;\n    int ans=OFS*2;\n    if(wm.rank(d,l)<wm.rank(d,r)) ans=0;\n    else{\n      int succ=wm.succ(l,r,d);\n      if(~succ) chmin(ans,abs(succ-d));\n      int pred=wm.pred(l,r,d);\n      if(~pred) chmin(ans,abs(pred-d));\n    }\n    cout<<ans<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1579.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1579\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/dual.cpp\"\n#include \"../../bbst/rbst/impl/basic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,a,d;\n  cin>>n>>a>>d;\n\n  using ll = long long;\n  struct E{\n    ll a,b,c;\n    E(){}\n    E(ll a,ll b,ll c):a(a),b(b),c(c){}\n    bool operator!=(const E &o) const{\n      return make_tuple(a,b,c)!=make_tuple(o.a,o.b,o.c);\n    }\n  };\n\n  const ll MAX = 1e9;\n  auto h=[](E a,E b){\n    E c(a.a+a.b*(a.c+b.a),a.b*b.b,0);\n    c.c=c.a/c.b+b.c;\n    c.a%=c.b;\n    if(c.b>MAX){\n      c.a=max(0LL,MAX-(c.b-c.a));\n      c.b=MAX;\n    }\n    return c;\n  };\n  E ei(0,1,0);\n\n  using Data = Dual<E, decltype(h)>;\n  using Node = Data::Node;\n  constexpr size_t LIM = 1e6;\n  Basic<Data, LIM> G(h,ei);\n\n  auto r=G.build(vector<Node>(n,ei));\n  for(int i=0;i<n;i++){\n    int v=a+d*i;\n    r=G.update(r,i,i+1,E(0,1,v));\n  }\n\n  int m;\n  cin>>m;\n  for(int i=0;i<m;i++){\n    int x,y,z;\n    cin>>x>>y>>z;\n    y--;\n    if(x==0) r=G.toggle(r,y,z);\n    if(x==1) r=G.update(r,y,z,E(0,1,1));\n    if(x==2) r=G.update(r,y,z,E(0,2,0));\n  }\n\n  int k;\n  cin>>k;\n  k--;\n  cout<<G.get_val(r,k).c<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1595.linkcuttree.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1595\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/farthest.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using Node = NodeBase<int>;\n  constexpr size_t LIM = 1e6;\n  using LCT = Farthest<Node, LIM>;\n  LCT lct;\n\n  int n;\n  cin>>n;\n  for(int i=0;i<n;i++) lct.create(1);\n\n  for(int i=1;i<n;i++){\n    int s,t;\n    cin>>s>>t;\n    s--;t--;\n    lct.evert(lct[t]);\n    lct.link(lct[s],lct[t]);\n  }\n\n  for(int i=0;i<n;i++){\n    lct.evert(lct[i]);\n    cout<<(n-1)*2-(lct[i]->ld)+1<<\"\\n\";\n  }\n\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1595.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1595\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/rerooting.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  auto fold=[&](int a,int b){return max(a,b);};\n  auto lift=[&](int a,int b){return a+b;};\n  ReRooting<int, int> G(n,fold,lift,0);\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    G.add_edge(u,v,1);\n  }\n  auto ans=G.build();\n  for(int a:ans) cout<<(n-1)*2-a<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1595.toptree.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1595\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../toptree/toptree.cpp\"\n#undef call_from_test\n\nstruct Vertex{\n  void* handle;\n  int idx;\n  Vertex(int idx=-1):handle(nullptr),idx(idx){}\n};\n\nstruct Cluster{\n  int ans,lf,rg,len;\n  Cluster(int l=0):ans(l),lf(l),rg(l),len(l){}\n  Cluster(int ans,int lf,int rg,int len):\n    ans(ans),lf(lf),rg(rg),len(len){}\n  void toggle(){swap(lf,rg);}\n  static Cluster compress(Cluster x,Vertex*,Cluster y){\n    return Cluster(\n      max(x.rg,y.lf),\n      max(x.lf,x.len+y.lf),\n      max(y.rg,y.len+x.rg),\n      x.len+y.len);\n  }\n  static Cluster rake(Cluster x,Cluster y){\n    return Cluster(0,max(x.lf,x.len+y.rg),max(x.rg,y.rg),x.len);\n  }\n};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  const size_t N = 1e5;\n  TopTree<Vertex, Cluster, N> T;\n\n  int n;\n  cin>>n;\n\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++) vs[i]=T.create(i);\n\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    T.link(vs[u],Cluster(1),vs[v]);\n  }\n\n  for(int i=0;i<n;i++)\n    cout<<(n-1)*2-T.get_subtree(vs[i]).ans<<newl;\n\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1599.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1599\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../vector/compress.cpp\"\n#include \"../../maxflow/dinic.cpp\"\n#undef call_from_test\n\nint main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<string> es(n);\n  for(int i=0;i<n;i++) cin>>es[i];\n\n  const int L=5;\n  vector<string> vs;\n  for(string &s:es){\n    for(char &c:s){\n      if(isdigit(c)) c=c-'0';\n      else c=c-'a'+10;\n    }\n    for(int i=0;i<L;i++){\n      if(s[i]&1) continue;\n      s[i]=(s[i]+1)%16;\n      vs.emplace_back(s);\n      s[i]=(s[i]+15)%16;\n\n      s[i]=(s[i]+15)%16;\n      vs.emplace_back(s);\n      s[i]=(s[i]+1)%16;\n    }\n  }\n  es=compress(es);\n  vs=compress(vs);\n  auto vd=dict(vs);\n\n  auto restore=\n    [](string s){\n      for(char &c:s){\n        if(c>=10) c='a'+(c-10);\n        else c='0'+c;\n      }\n      return s;\n    };\n\n  int m=vd.size();\n  Dinic<int, true> G(m+2);\n  int S=m,T=m+1;\n\n  vector<int> used(m,0);\n  using P = pair<int, int>;\n  map<string, P> mp;\n\n  for(string &s:es){\n    for(int i=0;i<L;i++){\n      if(s[i]&1) continue;\n\n      s[i]=(s[i]+1)%16;\n      int x=vd[s];\n      s[i]=(s[i]+15)%16;\n\n      s[i]=(s[i]+15)%16;\n      int y=vd[s];\n      s[i]=(s[i]+1)%16;\n\n      int sum=0;\n      for(char c:vs[x]) sum+=c/2;\n      if(sum&1) swap(x,y);\n\n      mp[s]=P(x,G.add_edge(x,y,1));\n\n      if(!used[x]){\n        mp[vs[x]]=P(S,G.add_edge(S,x,1));\n        used[x]=1;\n      }\n\n      if(!used[y]){\n        mp[vs[y]]=P(y,G.add_edge(y,T,1));\n        used[y]=1;\n      }\n    }\n  }\n\n  vector<string> as;\n  for(auto s:es) as.emplace_back(s);\n  for(auto s:vs) as.emplace_back(s);\n  sort(as.begin(),as.end());\n\n  cout<<G.flow(S,T)<<\"\\n\";\n  for(auto s:as){\n    int x=mp[s].first;\n    int a=mp[s].second;\n    if(G.cut(S,T,x,a)==1){\n      cout<<restore(s)<<\"\\n\";\n    }else{\n      G.link(S,T,x,a,1);\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1607.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1607\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../datastructure/radixheap.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nconst int BS = 8, BS2 = BS * 2;\nconst int msk = (1<<BS)-1;\nconst int MAX = 12 * (1<<BS) * (1<<BS);\nint dist[MAX];\nbool hole[MAX];\nlong long add[(1<<BS) * (1<<BS)];\nlong long dp[(1<<BS)][(1<<BS)];\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  while(cin>>n,n){\n    int m,k,r;\n    cin>>m>>k>>r;\n    vector<int> x(n),y(n),z(n);\n    for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i];\n    vector<int> u1(m),v1(m),u2(m),v2(m),w(m);\n    for(int i=0;i<m;i++) cin>>u1[i]>>v1[i]>>u2[i]>>v2[i]>>w[i];\n\n    vector<int> vx(x),vy(y);\n    for(int p=0;p<m;p++){\n      vx.emplace_back(u1[p]);\n      vx.emplace_back(u2[p]);\n      vy.emplace_back(v1[p]);\n      vy.emplace_back(v2[p]);\n      if(w[p]!=k) continue;\n      if(u1[p]-1>=1) vx.emplace_back(u1[p]-1);\n      if(u2[p]+1<=r) vx.emplace_back(u2[p]+1);\n      if(v1[p]-1>=1) vy.emplace_back(v1[p]-1);\n      if(v2[p]+1<=r) vy.emplace_back(v2[p]+1);\n    }\n\n    vx=compress(vx);\n    vy=compress(vy);\n    auto mx=dict(vx);\n    auto my=dict(vy);\n\n    // kokokara y yuusen\n    auto idx=[&](int cy,int cx,int f){return (f<<BS2)|(cy<<BS)|cx;};\n\n    memset(hole,0,sizeof(hole));\n    for(int p=0;p<m;p++)\n      for(int i=my[v1[p]];i<=my[v2[p]];i++)\n        for(int j=mx[u1[p]];j<=mx[u2[p]];j++)\n          hole[idx(i,j,w[p])]=1;\n\n    int sy=vy.size(),sx=vx.size();\n\n    auto dijkstra=\n      [&](int a)->void{\n        vector<int> wy,wx;\n        for(int p=0;p<m;p++){\n          if(w[p]<=z[a]) continue;\n          wy.emplace_back(v1[p]);\n          wy.emplace_back(v2[p]);\n          wx.emplace_back(u1[p]);\n          wx.emplace_back(u2[p]);\n        }\n        wy.emplace_back(y[a]);\n        wx.emplace_back(x[a]);\n        wy=compress(wy);\n        wx=compress(wx);\n        auto zy=dict(wy);\n        auto zx=dict(wx);\n        int ty=zy.size(),tx=zx.size();\n\n        vector<pair<int, int> > vs;\n        {\n          for(int i=0;i<MAX;i++) dist[i]=INT_MAX;\n          RadixHeap<int, int> q;\n          {\n            int v=idx(zy[y[a]],zx[x[a]],z[a]);\n            dist[v]=0;\n            q.emplace(dist[v],v);\n          }\n\n          while(!q.empty()){\n            auto p=q.pop();\n            int v=p.second;\n            if(dist[v]<p.first) continue;\n\n            int f=v>>BS2,i=(v>>BS)&msk,j=v&msk;\n            int ai=my[wy[i]],aj=mx[wx[j]];\n            if(f==k){\n              vs.emplace_back((ai<<BS)|aj,dist[v]);\n              continue;\n            }\n\n            auto push=\n              [&](int ni,int nj,int nf){\n                int u=idx(ni,nj,nf);\n                int c=abs(wy[ni]-wy[i])+abs(wx[nj]-wx[j]);\n\n                if(dist[u]>dist[v]+c){\n                  dist[u]=dist[v]+c;\n                  q.emplace(dist[u],u);\n                }\n              };\n\n            if(hole[idx(ai,aj,f+1)]){\n              push(i,j,f+1);\n              continue;\n            }\n\n            if(i+1<ty) push(i+1,j,f);\n            if(i-1>=0) push(i-1,j,f);\n            if(j+1<tx) push(i,j+1,f);\n            if(j-1>=0) push(i,j-1,f);\n          }\n        }\n        {\n          for(int i=0;i<(sy<<BS);i++) add[i]=INT_MAX;\n          RadixHeap<int, int> q;\n          for(auto p:vs){\n            int v=p.first,d=p.second;\n            add[v]=d;\n            q.emplace(add[v],v);\n          }\n\n          while(!q.empty()){\n            auto p=q.pop();\n            int v=p.second;\n            if(add[v]<p.first) continue;\n\n            int i=v>>BS,j=v&msk;\n            auto push=\n              [&](int ni,int nj){\n                int u=(ni<<BS)|nj;\n                int c=abs(vy[ni]-vy[i])+abs(vx[nj]-vx[j]);\n                if(add[u]>add[v]+c){\n                  add[u]=add[v]+c;\n                  q.emplace(add[u],u);\n                }\n              };\n\n            if(i+1<sy) push(i+1,j);\n            if(i-1>=0) push(i-1,j);\n            if(j+1<sx) push(i,j+1);\n            if(j-1>=0) push(i,j-1);\n          }\n        }\n      };\n\n    memset(dp,0,sizeof(dp));\n    for(int p=0;p<n;p++){\n      dijkstra(p);\n      for(int i=0;i<sy;i++)\n        for(int j=0;j<sx;j++)\n          dp[i][j]+=add[(i<<BS)|j];\n    }\n\n    long long ans=1e18;\n    for(int i=0;i<sy;i++)\n      for(int j=0;j<sx;j++)\n        if(!hole[idx(i,j,k)]) chmin(ans,dp[i][j]);\n\n    for(int p=0;p<n;p++) ans+=(k-z[p])*100;\n    cout<<ans<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1613.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1613\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../tree/ahu.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  auto construct=[&](int h,int w){\n    auto st=read<string>(h);\n    st.emplace(st.begin(),string(w,'.'));\n    st.emplace(st.end(),string(w,'.'));\n    for(auto &s:st) s='.'+s+'.';\n    h=st.size();w=st[0].size();\n\n    int dy[]={0,0,1,-1,1,1,-1,-1};\n    int dx[]={1,-1,0,0,1,-1,1,-1};\n    auto in=[&](int y,int x){return 0<=y and y<h and 0<=x and x<w;};\n\n    int n=0;\n    vector blg(h,vector(w,-1));\n    auto bfs=[&](int y,int x){\n      int dir=(1+(st[y][x]=='#'))*4;\n      using P = pair<int, int>;\n      queue<P> que;\n      auto push=[&](int ny,int nx){\n        if(~blg[ny][nx]) return;\n        blg[ny][nx]=n;\n        que.emplace(ny,nx);\n      };\n      push(y,x);\n      while(!que.empty()){\n        auto[cy,cx]=que.front();que.pop();\n        for(int k=0;k<dir;k++){\n          int ny=cy+dy[k],nx=cx+dx[k];\n          if(in(ny,nx) and st[cy][cx]==st[ny][nx]) push(ny,nx);\n        }\n      }\n      n++;\n    };\n\n    for(int i=0;i<h;i++)\n      for(int j=0;j<w;j++)\n        if(blg[i][j]<0) bfs(i,j);\n\n    vector<set<int>> S(n);\n    for(int i=0;i<h;i++){\n      for(int j=0;j<w;j++){\n        for(int k=0;k<4;k++){\n          int ni=i+dy[k],nj=j+dx[k];\n          if(in(ni,nj) and blg[i][j]!=blg[ni][nj])\n            S[blg[i][j]].emplace(blg[ni][nj]);\n        }\n      }\n    }\n\n    AHU G(n);\n    for(int i=0;i<n;i++)\n      for(int j:S[i])\n        if(i<j) G.add_edge(i,j);\n    return G.build();\n  };\n\n  int h,w;\n  while(cin>>h>>w,h||w){\n    auto T1=construct(h,w);\n    cin>>h>>w;\n    auto T2=construct(h,w);\n    cout<<(T1==T2?\"yes\":\"no\")<<'\\n';\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1615.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1615\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../maxflow/dinic.cpp\"\n#include \"../../maxflow/leastflow.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  while(cin>>n>>m,n){\n    vector<int> xs(m),ys(m);\n    for(int i=0;i<m;i++) cin>>xs[i]>>ys[i],xs[i]--,ys[i]--;\n\n    for(int d=0;d<=n;d++){\n      for(int l=n-d;l>=0;l--){\n        int r=l+d;\n\n        int S=n+m,T=n+m+1;\n        LeastFlow<int> G(n+m+2);\n\n        for(int i=0;i<m;i++){\n          G.add_edge(S,i,1,1);\n          G.add_edge(i,m+ys[i],0,1);\n          G.add_edge(i,m+xs[i],0,1);\n        }\n\n        for(int i=0;i<n;i++)\n          G.add_edge(m+i,T,l,r);\n\n        if(G.flow(S,T)==m){\n          cout<<l<<\" \"<<r<<endl;\n          goto END;\n        }\n      }\n    }\n  END:\n    ;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1630.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1630\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../polynomial/hash.cpp\"\n#undef call_from_test\n\nusing M1 = Mint<int, int(1e9+7)>;\nusing M2 = Mint<int, int(1e9+9)>;\nusing M3 = Mint<int, int(1e8+7)>;\nPolynomialHash<int, M1, M2, M3> ph(100);\nusing V = decltype(ph)::V;\n\nvector<vector<V> > vs;\nvector<vector<vector<V> > > vm;\n\nV expr(string &s,int &p,int d);\nV term(string &s,int &p,int d);\nV factor(string &s,int &p,int d);\nV number(string &s,int &p);\n\nV expr(string &s,int &p,int d){\n  V res=term(s,p,d);\n  vs[d].emplace_back(res);\n  while(p<(int)s.size()){\n    if(s[p]=='+'){\n      p++;\n      V b=term(s,p,d);\n      vs[d].emplace_back(b);\n      res+=b;\n      continue;\n    }\n    break;\n  }\n  vs[d].emplace_back(0);\n  vm[d].emplace_back();\n  return res;\n}\n\nV term(string &s,int &p,int d){\n  V res=factor(s,p,d);\n  vm[d].emplace_back();\n  vm[d].back().emplace_back(res);\n  while(p<(int)s.size()){\n    if(s[p]=='*'){\n      p++;\n      V b=factor(s,p,d);\n      vm[d].back().emplace_back(b);\n      res*=b;\n      continue;\n    }\n    break;\n  }\n  return res;\n}\n\nV factor(string &s,int &p,int d){\n  if(s[p]=='('){\n    p++;\n    V res=expr(s,p,d+1);\n    assert(s[p]==')');\n    p++;\n    return res;\n  }\n  return number(s,p);\n}\n\nV number(string &s,int &p){\n  int k=s[p++]-'0';\n  return V(k);\n}\n\nsigned main(){\n  using ll = long long;\n\n  int n;\n  while(cin>>n,n){\n    string s;\n    cin>>s;\n    vs.assign(1010,vector<V>());\n    vm.assign(1010,vector<vector<V> >());\n\n    V nv((ll)n);\n\n    int p=0;\n    expr(s,p,0);\n    ll ans=0;\n\n    for(int i=0;i<1010;i++){\n      auto &v=vs[i];\n      if(v.empty()) continue;\n\n      auto comp=[](V a,V b){\n        auto [a1,a2,a3]=a;\n        auto [b1,b2,b3]=b;\n        return make_tuple(a1.v,a2.v,a3.v)<make_tuple(b1.v,b2.v,b3.v);\n      };\n      map<V, ll, decltype(comp)> dp(comp);\n      V uku(0);\n\n      dp[uku]++;\n      for(int j=0;j<(int)v.size();j++){\n        if(v[j]==V(0)){\n          dp.clear();\n          uku=V(0);\n          dp[uku]++;\n          continue;\n        }\n\n        {\n          V malta(1);\n          for(int k=0;k<(int)vm[i][j].size();k++){\n            malta*=vm[i][j][k];\n            ans+=dp[uku+malta-nv];\n          }\n        }\n\n        {\n          V malta(1);\n          map<V, ll, decltype(comp)> dp2(comp);\n          dp2[malta*nv]++;\n          for(int k=1;k<(int)vm[i][j].size();k++){\n            malta*=vm[i][j][k];\n            ans+=dp2[malta];\n            dp2[malta*nv]++;\n          }\n        }\n\n        {\n          V malta(1);\n          uku+=v[j];\n          for(int k=0;k+1<(int)vm[i][j].size();k++){\n            malta*=vm[i][j][k];\n            dp[uku-v[j]/malta]++;\n          }\n        }\n        dp[uku]++;\n      }\n    }\n    cout<<ans<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/1642.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1642\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../math/enumerate_primes.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  auto ps=enumerate_primes(4e7);\n\n  ll n;\n  while(cin>>n,n){\n    vector<ll> qs,vs;\n    {\n      ll t=n;\n      for(auto p:ps){\n        if(t<p) break;\n        if(t%p) continue;\n        qs.emplace_back(p);\n        vs.emplace_back(0);\n        while(t%p==0) t/=p,vs.back()++;\n      }\n      if(t!=1){\n        qs.emplace_back(t);\n        vs.emplace_back(1);\n      }\n      reverse(qs.begin(),qs.end());\n      reverse(vs.begin(),vs.end());\n    }\n\n    int m=qs.size();\n    ll ans=n+2;\n    MFP([&](auto dfs,int t,ll x,ll y,ll z)->void{\n      if(x+y+z>=ans) return;\n      if(t==m){\n        assert(x*y*z==n);\n        chmin(ans,x+y+z);\n        return;\n      }\n      int s=vs[t];\n      vector<ll> po(s+1,1);\n      for(int i=0;i<s;i++) po[i+1]=po[i]*qs[t];\n      for(int i=0;i<=s;i++)\n        for(int j=0;i+j<=s;j++)\n          dfs(t+1,x*po[i],y*po[j],z*po[s-(i+j)]);\n    })(0,1,1,1);\n\n    cout<<ans<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2060.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2060\n// verification-helper: ERROR 1e-6\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linearalgebra/matrix.cpp\"\n#include \"../../math/tetrahedra.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n;\n  while(cin>>n,n){\n    vector<double> as(n);\n    for(int i=0;i<n;i++) cin>>as[i];\n\n    double ans=0;\n    for(int i=0;i<n;i++){\n      for(int j=i+1;j<n;j++){\n        for(int k=j+1;k<n;k++){\n          for(int x=0;x<n;x++){\n            if(i==x||j==x||k==x) continue;\n            for(int y=0;y<n;y++){\n              if(i==y||j==y||k==y||x==y) continue;\n              for(int z=0;z<n;z++){\n                if(i==z||j==z||k==z||x==z||y==z) continue;\n                ans=max(ans,tetrahedra(as[i],as[j],as[k],\n                                       as[x],as[y],as[z]));\n              }\n            }\n          }\n        }\n      }\n    }\n    cout<<fixed<<setprecision(12)<<ans<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2187.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2187\n// verification-helper: ERROR 1e-5\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../tools/all_permutations.cpp\"\n#undef call_from_test\n\nsigned solve(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  const int n=9;\n  vector<int> as(n),bs(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n  for(int i=0;i<n;i++) cin>>bs[i];\n  int num=0,cnt=0;\n  auto f=\n    [&](vector<int> vs){\n      int x=0,y=0;\n      for(int i=0;i<n;i++){\n        if(as[vs[i]]<bs[i]) x+=as[vs[i]]+bs[i];\n        if(as[vs[i]]>bs[i]) y+=as[vs[i]]+bs[i];\n      }\n      if(x<y) num++;\n      cnt++;\n    };\n  all_permutations(n,f);\n\n  double A=(double)num/cnt;\n  double B=1.0-A;\n  cout<<fixed<<setprecision(5);\n  cout<<A<<\" \"<<B<<endl;\n  return 0;\n}\n\nsigned main(){\n  int T;\n  cin>>T;\n  while(T--) solve();\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2212.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2212\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/trie.cpp\"\n#include \"../../string/ahocorasick.cpp\"\n#undef call_from_test\n\nint dp[111][55][55];\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int h,w;\n  while(cin>>h>>w,h){\n    vector<string> ss(h);\n    for(int i=0;i<h;i++) cin>>ss[i];\n    int p;\n    cin>>p;\n    vector<string> ps(p);\n    for(int i=0;i<p;i++) cin>>ps[i];\n    auto conv=\n      [&](char c){\n        if(c=='U') return 0;\n        if(c=='R') return 1;\n        if(c=='D') return 2;\n        if(c=='L') return 3;\n        return -1;\n      };\n    AhoCorasick<4, false> aho(conv);\n    for(int i=0;i<p;i++) aho.add(ps[i],i);\n    aho.build();\n\n    memset(dp,-1,sizeof(dp));\n    using T = tuple<int, int, int>;\n    queue<T> que;\n    for(int i=0;i<h;i++){\n      for(int j=0;j<w;j++){\n        if(ss[i][j]=='S'){\n          dp[0][i][j]=0;\n          que.emplace(0,i,j);\n        }\n      }\n    }\n\n    string base=\"URDL\";\n    int dy[]={-1,0,1,0};\n    int dx[]={0,1,0,-1};\n    auto in=[&](int y,int x){return 0<=y&&y<h&&0<=x&&x<w;};\n\n    int ans=-1;\n    while(!que.empty()){\n      int p,y,x;\n      tie(p,y,x)=que.front();que.pop();\n      if(ss[y][x]=='G'){\n        ans=dp[p][y][x];\n        break;\n      }\n      for(int k=0;k<4;k++){\n        int ny=y+dy[k],nx=x+dx[k];\n        if(!in(ny,nx)||ss[ny][nx]=='#') continue;\n        char c=base[k];\n        int q=aho.move(p,c);\n        if(aho.count(q)) continue;\n        if(~dp[q][ny][nx]) continue;\n        dp[q][ny][nx]=dp[p][y][x]+1;\n        que.emplace(q,ny,nx);\n      }\n    }\n    cout<<ans<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2222.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2222\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using M = Mint<int>;\n\n  int n,m;\n  cin>>n>>m;\n\n  SCC scc(n);\n  for(int i=0;i<m;i++){\n    int s,d;\n    cin>>s>>d;\n    s--;d--;\n    scc.add_edge(s,d);\n  }\n\n  int k=scc.build();\n  vector<M> dp(k,1);\n  vector<int> indeg(k,0);\n\n  M ans(1);\n  for(int i=0;i<k;i++){\n    if(indeg[i]!=0) dp[i]-=M(1);\n    for(int j:scc.H[i])\n      dp[j]*=dp[i]+M(1);\n    if(scc.H[i].empty()) ans*=dp[i]+M(1);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2230.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2230\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../bflow/capacityscaling.cpp\"\n#undef call_from_test\n\nsigned main(){\n  using P = pair<int, int>;\n  using ll = long long;\n  const ll INF = 1<<30;\n\n  int n,m;\n  cin>>n>>m;\n  vector< vector<P> > H(n);\n  MinCostFlow<ll, ll> G(n);\n  for(int i=0;i<m;i++){\n    int x,y,s;\n    cin>>x>>y>>s;\n    H[x].emplace_back(y,s);\n    G.add_edge(y,x,1,INF,-s);\n  }\n\n  vector<int> dp(n,0);\n  for(int i=0;i<n;i++)\n    for(auto e:H[i])\n      chmax(dp[e.first],dp[i]+e.second);\n  G.add_edge(0,n-1,0,INF,dp[n-1]);\n\n  assert(G.build());\n  cout<<G.get_cost()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2235.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2235\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/dynamicconnectivity.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  DynamicConnectivity dc(n,q);\n  vector<int> ts(q),us(q),vs(q);\n  for(int i=0;i<q;i++){\n    cin>>ts[i]>>us[i]>>vs[i];\n    if(ts[i]==1) dc.insert(i,us[i],vs[i]);\n    if(ts[i]==2) dc.erase( i,us[i],vs[i]);\n  }\n  dc.build();\n  auto f=\n    [&](int x){\n      if(x>=q||ts[x]!=3) return;\n      cout<<(dc.puf.same(us[x],vs[x])?\"YES\":\"NO\")<<endl;\n    };\n  dc.exec(f);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2257.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2257\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/trie.cpp\"\n#include \"../../string/ahocorasick.cpp\"\n#undef call_from_test\n\nsigned dp[2][2][501][21][601];\nbool used[2][2][501][21][601];\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,k;\n  while(cin>>n>>m>>k,n){\n    memset(dp,0,sizeof(dp));\n    memset(used,0,sizeof(used));\n\n    vector<string> from(n),to(n);\n    for(int i=0;i<n;i++) cin>>from[i]>>to[i];\n    vector<string> season(k);\n    for(int i=0;i<k;i++) cin>>season[i];\n\n    AhoCorasick<26, false> aho('a');\n    for(int i=0;i<k;i++) aho.add(season[i],i);\n    aho.build();\n    int l=aho.size();\n\n    vector<string> v;\n    for(int i=0;i<n;i++){\n      v.emplace_back(from[i]);\n      v.emplace_back(to[i]);\n    }\n    sort(v.begin(),v.end());\n    v.erase(unique(v.begin(),v.end()),v.end());\n\n    map<string, int> idx;\n    for(int i=0;i<(int)v.size();i++) idx[v[i]]=i;\n\n    vector<vector<int> > G(v.size());\n    for(int i=0;i<n;i++)\n      G[idx[from[i]]].emplace_back(idx[to[i]]);\n\n    const int MOD = 1e9+7;\n    using T = tuple<int, int, int, int, int>;\n    queue<T> q;\n    for(int i=0;i<(int)v.size();i++){\n      dp[0][0][i][0][0]=1;\n      q.emplace(0,0,i,0,0);\n    }\n\n    while(!q.empty()){\n      int c,d,x,p,pos;\n      tie(c,d,x,p,pos)=q.front();q.pop();\n      if(d==m) break;\n      int f=d&1;\n\n      if(p==(int)v[x].size()){\n        for(int y:G[x]){\n          int npos=aho.move(pos,v[y][0]);\n          if(aho.cnt[npos]>1) continue;\n          int nc=aho.cnt[npos];\n          if(c&&nc) continue;\n          dp[c||nc][!f][y][1][npos]+=dp[c][f][x][p][pos];\n          dp[c||nc][!f][y][1][npos]%=MOD;\n          if(!used[c||nc][!f][y][1][npos])\n            q.emplace((c||nc),d+1,y,1,npos);\n          used[c||nc][!f][y][1][npos]=1;\n        }\n      }else{\n        int npos=aho.move(pos,v[x][p]);\n        int np=p+1;\n        if(aho.cnt[npos]>1) goto END;\n        int nc=aho.cnt[npos];\n        if(c&&nc) goto END;\n        dp[c||nc][!f][x][np][npos]+=dp[c][f][x][p][pos];\n        dp[c||nc][!f][x][np][npos]%=MOD;\n        if(!used[c||nc][!f][x][np][npos])\n          q.emplace((c||nc),d+1,x,np,npos);\n        used[c||nc][!f][x][np][npos]=1;\n      }\n    END:\n      dp[c][f][x][p][pos]=0;\n      used[c][f][x][p][pos]=0;\n    }\n\n    int ans=0;\n    for(int i=0;i<(int)v.size();i++){\n      for(int j=0;j<l;j++){\n        ans+=dp[1][m&1][i][v[i].size()][j];\n        ans%=MOD;\n      }\n    }\n    cout<<ans<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2270.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2270\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../vector/compress.cpp\"\n#include \"../../algorithm/mo.cpp\"\n#include \"../../tree/eulertourforedge.cpp\"\n#include \"../../tree/lowestcommonancestor.cpp\"\n#include \"../../tree/mo_on_tree.cpp\"\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  vector<int> xs(n+1);\n  for(int i=1;i<=n;i++) cin>>xs[i];\n  auto cs=compress(xs);\n  auto dc=dict(cs);\n  vector<int> ys(n+1);\n  for(int i=0;i<=n;i++) ys[i]=dc[xs[i]];\n\n\n  vector<int> zs(n);\n  BIT<int> bit(n);\n  auto expand=[&](int e){bit.add(zs[e],+1);};\n  auto shrink=[&](int e){bit.add(zs[e],-1);};\n  MoOnTree mo(n+1,400,expand,shrink);\n  LowestCommonAncestor lca(n+1);\n\n  vector<int> as(n),bs(n);\n  as[0]=0;bs[0]=1;\n  mo.add_edge(as[0],bs[0]);\n  lca.add_edge(as[0],bs[0]);\n  for(int i=1;i<n;i++){\n    cin>>as[i]>>bs[i];\n    mo.add_edge(as[i],bs[i]);\n    lca.add_edge(as[i],bs[i]);\n  }\n  vector<int> vs(q),ws(q),ls(q);\n  for(int i=0;i<q;i++){\n    cin>>vs[i]>>ws[i]>>ls[i];\n    mo.add_query(vs[i],ws[i]);\n  }\n  mo.build();\n  lca.build();\n\n  for(int i=0;i<n;i++)\n    zs[i]=ys[mo.et.child(as[i],bs[i])];\n\n  vector<int> ans(q);\n  for(int i=0;i<q;i++){\n    int k=mo.process();\n    int r=lca.lca(vs[k],ws[k]);\n    bit.add(ys[r],+1);\n    ans[k]=bit.lower_bound(ls[k])-1;\n    bit.add(ys[r],-1);\n  }\n\n  for(int a:ans) cout<<cs[a]<<'\\n';\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2286.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2286\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/totient_table.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  const int MAX = 1e6;\n  auto ts=totient_table(MAX);\n  vector<long long> sm(ts.begin(),ts.end());\n  for(int i=0;i<MAX;i++) sm[i+1]+=sm[i];\n\n  int t;\n  cin>>t;\n  for(int i=0;i<t;i++){\n    int n;\n    cin>>n;\n    cout<<sm[n]+1<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2290.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2290\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mincostflow/primaldual.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../vector/identity.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,v,xleft,xright;\n  cin>>n>>v>>xleft>>xright;\n\n  int S=n+n,T=n+n+1,L=n+n+2,R=n+n+3;\n  PrimalDual<int, int> G(n+n+4);\n\n  G.add_edge(S,L,1,0);\n  G.add_edge(L,T,1,0);\n\n  G.add_edge(S,R,1,0);\n  G.add_edge(R,T,1,0);\n\n  vector<int> xs(n),ts(n),ps(n);\n  for(int i=0;i<n;i++){\n    cin>>xs[i]>>ts[i]>>ps[i];\n\n    if(abs(xs[i]-xleft)<=ts[i]*v)\n      G.add_edge(L,i,1,0);\n\n    if(abs(xs[i]-xright)<=ts[i]*v)\n      G.add_edge(R,i,1,0);\n  }\n\n  auto init=[&](auto &h)->void{\n    fill(h.begin(),h.end(),0);\n\n    auto ord=identity(n);\n    sort(ord.begin(),ord.end(),\n         [&](int i,int j){return ts[i]<ts[j];});\n\n    auto add_edge=[&](int u,int v,int f,int c){\n      G.add_edge(u,v,f,c);\n      chmin(h[v],h[u]+c);\n    };\n\n    for(int i=0;i<n;i++){\n      int x=ord[i];\n      add_edge(x,n+x,1,-ps[x]);\n      for(int j=i+1;j<n;j++){\n        int y=ord[j];\n        if(abs(xs[x]-xs[y])<=(ts[y]-ts[x])*v)\n          add_edge(n+x,y,1,0);\n      }\n      add_edge(n+x,T,1,0);\n    }\n  };\n  assert(G.build(S,T,2,init));\n  cout<<-G.get_cost()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2292.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2292\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/palindromictree.cpp\"\n#include \"../../string/rollinghash.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  string s,t;\n  cin>>s>>t;\n\n  PalindromicTree p1(s),p2(t);\n  const int MOD = 1e9+7;\n  const int BASE1 = 1777771;\n  const int BASE2 = 1e6+3;\n  RollingHash<int, MOD, BASE1> rs1(s),rt1(t);\n  RollingHash<int, MOD, BASE2> rs2(s),rt2(t);\n\n  const int MAX = 5e5+100;\n  map<pair<int, int>, int> m1[MAX];\n  for(int i=2;i<(int)p1.size();i++){\n    PalindromicTree::node& u=p1.vs[i];\n    if(u.app<0) continue;\n    auto p=make_pair(rs1.find(u.app,u.app+u.len),\n                     rs2.find(u.app,u.app+u.len));\n    m1[u.len][p]=u.cnt;\n  }\n\n  ll ans=0;\n  for(int i=2;i<(int)p2.size();i++){\n    PalindromicTree::node& u=p2.vs[i];\n    auto p=make_pair(rt1.find(u.app,u.app+u.len),\n                     rt2.find(u.app,u.app+u.len));\n    if(u.app<0||!m1[u.len].count(p)) continue;\n    ans+=(ll)m1[u.len][p]*u.cnt;\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2294.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2294\n// verification-helper: ERROR 1e-6\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/precision.cpp\"\n#include \"../../vector/multi.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using D = long double;\n  int h,n,p,m,k;\n  cin>>h>>n>>p>>m>>k;\n  p--;\n\n  vector<int> bs(h,-1);\n  for(int i=0;i<m;i++){\n    int x,y;\n    cin>>x>>y;\n    bs[h-x]=y-1;\n  }\n\n  auto dp=make_v<D>(h+1,k+1,n+1);\n  fill_v<D>(dp,0);\n\n  dp[0][0][p]=1;\n  for(int i=0;i<h;i++){\n    for(int j=0;j<=k;j++){\n      if(~bs[i]){\n        swap(dp[i][j][bs[i]],dp[i][j][bs[i]+1]);\n        for(int l=0;l<n;l++) dp[i+1][j][l]+=dp[i][j][l];\n        continue;\n      }\n      for(int l=0;l<n;l++) dp[i+1][j][l]+=dp[i][j][l];\n      if(j+1>k) continue;\n      for(int l=0;l<n;l++){\n        D x=0.0;\n        if(l+1<n)  dp[i+1][j+1][l+1]+=dp[i][j][l]/(n-1.0),x+=1.0;\n        if(l-1>=0) dp[i+1][j+1][l-1]+=dp[i][j][l]/(n-1.0),x+=1.0;\n        dp[i+1][j+1][l]+=dp[i][j][l]*(n-1.0-x)/(n-1.0);\n      }\n    }\n  }\n\n  D ans=*max_element(dp[h][k].begin(),dp[h][k].end());\n  for(int i=0;i<k;i++){\n    ans/=(h-m-i);\n    ans*=(i+1);\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2308.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2308\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../tools/drop.cpp\"\n#include \"../../io/precision.cpp\"\n#include \"../../geometry/projectilemotion.cpp\"\n#undef call_from_test\n\nusing D = double;\nstruct Point{\n  D x,y;\n  Point(){}\n  Point(D x,D y):x(x),y(y){}\n};\n\nistream &operator>>(istream &is,Point &p){\n  is>>p.x>>p.y;\n  return is;\n}\n\nsigned main(){\n  int n;\n  D v;\n  cin>>n>>v;\n  Point t;\n  cin>>t;\n  vector<Point> ps(n),qs(n);\n  for(int i=0;i<n;i++) cin>>ps[i]>>qs[i];\n  for(int i=0;i<n;i++) chmin(qs[i].x,t.x);\n\n  D g=9.8;\n\n  if(t.x==0){\n    D ti=v/g;\n    D y=v*ti-g/2*ti*ti;\n    if(y>=t.y) drop(\"Yes\");\n    drop(\"No\");\n  }\n\n  const D EPS = 1e-10;\n  vector<D> cand;\n  auto push=\n    [&](Point s){\n      for(auto pq:projectile_motion(v,g,s.x,s.y)){\n        D d=pq.first;\n        cand.emplace_back(d);\n        cand.emplace_back(d+EPS);\n        cand.emplace_back(d-EPS);\n      }\n    };\n\n  for(int i=0;i<n;i++){\n    if(ps[i].x>=t.x) continue;\n    push(ps[i]);\n    push(qs[i]);\n    push(Point(ps[i].x,qs[i].y));\n    push(Point(qs[i].x,ps[i].y));\n  }\n  push(t);\n\n  auto getY=\n    [&](D p,D q,D x){\n      D ti=x/p;\n      return q*ti-g/2*ti*ti;\n    };\n\n  auto in=\n    [&](int k,D p,D q)->int{\n      if(ps[k].x>=t.x) return 0;\n\n      if(ps[k].y<getY(p,q,ps[k].x) && getY(p,q,ps[k].x)<qs[k].y) return 1;\n      if(ps[k].y<getY(p,q,qs[k].x) && getY(p,q,qs[k].x)<qs[k].y) return 1;\n\n      if(ps[k].y<getY(p,q,ps[k].x) && getY(p,q,qs[k].x)<ps[k].y) return 1;\n      if(ps[k].y<getY(p,q,qs[k].x) && getY(p,q,ps[k].x)<ps[k].y) return 1;\n\n      if(qs[k].y<getY(p,q,ps[k].x) && getY(p,q,qs[k].x)<qs[k].y) return 1;\n      if(qs[k].y<getY(p,q,qs[k].x) && getY(p,q,ps[k].x)<qs[k].y) return 1;\n\n      D ti=q/g;\n      Point top(p*ti,getY(p,q,p*ti));\n      if(ps[k].x<top.x && top.x<qs[k].x &&\n         ps[k].y<top.y && top.y<qs[k].y) return 1;\n\n      return 0;\n    };\n\n\n  for(D p:cand){\n    D q=sqrt(v*v-p*p);\n\n    if(getY(p,q,t.x)<t.y) continue;\n\n    int flg=1;\n    for(int i=0;i<n;i++)\n      if(in(i,p,q)) flg=0;\n\n    if(flg) drop(\"Yes\");\n  }\n\n  cout<<\"No\"<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2309.tarjan.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2309\n// verification-helper: ERROR 1e-6\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/precision.cpp\"\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#include \"../../graph/arborescence_edmond.cpp\"\n#undef call_from_test\n\nconst int MAX = 111;\ndouble v[MAX][MAX];\ndouble c[MAX][MAX];\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  for(int i=0;i<m;i++)\n    for(int j=0;j<n;j++)\n      cin>>v[i][j];\n\n  for(int i=0;i<m;i++){\n    c[i][i]=0;\n    for(int j=0;j<n;j++) c[i][i]+=v[i][j]*v[i][j];\n  }\n\n  for(int i=0;i<m;i++){\n    for(int j=0;j<m;j++){\n      if(i==j) continue;\n      if(c[j][j]==0){\n        c[i][j]=c[i][i];\n        continue;\n      }\n      double r=0;\n      for(int k=0;k<n;k++)\n        r+=v[i][k]*v[j][k];\n      r/=c[j][j];\n      c[i][j]=0;\n      for(int k=0;k<n;k++)\n        c[i][j]+=(v[i][k]-r*v[j][k])*(v[i][k]-r*v[j][k]);\n    }\n  }\n\n  Arborescence<double> G(m+1);\n  for(int i=0;i<m;i++){\n    G.add_edge(m,i,c[i][i]);\n    for(int j=0;j<m;j++){\n      if(i==j) continue;\n      G.add_edge(j,i,c[i][j]);\n    }\n  }\n\n  cout<<G.build(m)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2309.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2309\n// verification-helper: ERROR 1e-6\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/precision.cpp\"\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#include \"../../graph/arborescence_edmond.cpp\"\n#undef call_from_test\n\nconst int MAX = 111;\ndouble v[MAX][MAX];\ndouble c[MAX][MAX];\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  for(int i=0;i<m;i++)\n    for(int j=0;j<n;j++)\n      cin>>v[i][j];\n\n  for(int i=0;i<m;i++){\n    c[i][i]=0;\n    for(int j=0;j<n;j++) c[i][i]+=v[i][j]*v[i][j];\n  }\n\n  for(int i=0;i<m;i++){\n    for(int j=0;j<m;j++){\n      if(i==j) continue;\n      if(c[j][j]==0){\n        c[i][j]=c[i][i];\n        continue;\n      }\n      double r=0;\n      for(int k=0;k<n;k++)\n        r+=v[i][k]*v[j][k];\n      r/=c[j][j];\n      c[i][j]=0;\n      for(int k=0;k<n;k++)\n        c[i][j]+=(v[i][k]-r*v[j][k])*(v[i][k]-r*v[j][k]);\n    }\n  }\n\n  Arborescence<double> G(m+1);\n  for(int i=0;i<m;i++){\n    G.add_edge(m,i,c[i][i]);\n    for(int j=0;j<m;j++){\n      if(i==j) continue;\n      G.add_edge(j,i,c[i][j]);\n    }\n  }\n\n  cout<<G.build(m)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2313.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2313\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../maxflow/dinic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,e,q;\n  cin>>n>>e>>q;\n  Dinic<int, true> G(n);\n  vector< map<int, int> > I(n);\n  for(int i=0;i<e;i++){\n    int f,t;\n    cin>>f>>t;\n    f--;t--;\n    I[f][t]=G.add_edge(f,t,1);\n    I[t][f]=G.add_edge(t,f,1);\n  }\n\n  vector<int> ms(q),as(q),bs(q);\n  for(int i=0;i<q;i++){\n    cin>>ms[i]>>as[i]>>bs[i];\n    as[i]--;bs[i]--;\n    if(I[as[i]].count(bs[i])) continue;\n    I[as[i]][bs[i]]=G.add_edge(as[i],bs[i],0);\n    I[bs[i]][as[i]]=G.add_edge(bs[i],as[i],0);\n  }\n\n  int res=G.flow(0,n-1);\n  for(int i=0;i<q;i++){\n    if(ms[i]==1){\n      res+=G.link(0,n-1,as[i],I[as[i]][bs[i]],1);\n      res+=G.link(0,n-1,bs[i],I[bs[i]][as[i]],1);\n    }\n    if(ms[i]==2){\n      res-=G.cut(0,n-1,as[i],I[as[i]][bs[i]]);\n      res-=G.cut(0,n-1,bs[i],I[bs[i]][as[i]]);\n    }\n    cout<<res<<\"\\n\";\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2324.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2324\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/multipleeuleriantrail.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  const int MAX = 52;\n  auto idx=[&](char c)->int{\n             if(islower(c)) return c-'a';\n             assert(isupper(c));\n             return c-'A'+26;\n           };\n\n  string s;\n  while(cin>>s,s!=\"#\"){\n    int n=s.size();\n    if(n<=2){\n      cout<<\"No Results\"<<endl;\n      continue;\n    }\n\n    vector< set<int> > G(MAX);\n    for(int i=0;i+1<n;i++){\n      int x=idx(s[i]);\n      int y=idx(s[i+1]);\n      G[x].emplace(y);\n    }\n\n    vector<int> ind(MAX,0),outd(MAX,0);\n    for(int v=0;v<MAX;v++)\n      for(int u:G[v]) ind[u]++,outd[v]++;\n\n    int res=0;\n    for(int i=0;i<MAX;i++)\n      res+=max<int>(ind[i]-outd[i],0);\n\n    int m=accumulate(ind.begin(),ind.end(),0)+1;\n    int add=max<int>(res-1,0);\n    m+=add;\n\n    if(m<n||add){\n      cout<<m<<endl;\n      continue;\n    }\n\n    vector< vector<int> > H(MAX);\n    for(int v=0;v<MAX;v++)\n      for(int u:G[v])\n        H[v].emplace_back(u);\n\n    int flg=hasMultipleEulerianTrail(H);\n    cout<<(flg?m:m+1)<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2328.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2328\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/split.cpp\"\n#include \"../../maxflow/dinic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  const int DEG = 55;\n  const int INF = 1<<28;\n  int n,m;\n  while(cin>>n>>m,n){\n    Dinic<int, false> flow(n);\n    int ed[DEG][55][55];\n    memset(ed,0,sizeof(ed));\n\n    for(int i=0;i<m;i++){\n      int a,b;\n      string s;\n      cin>>a>>b>>s;\n      a--;b--;\n      flow.add_edge(a,b,0);\n      for(string t:split(s,'+')){\n        if(!count(t.begin(),t.end(),'x')){\n          ed[0][a][b]+=stoi(t);\n          ed[0][b][a]+=stoi(t);\n        }else if(t.back()=='x'){\n          t.pop_back();\n          if(t.empty()) t=\"1\";\n          ed[1][a][b]+=stoi(t);\n          ed[1][b][a]+=stoi(t);\n        }else{\n          auto v=split(t,'^');\n          v[0].pop_back();\n          if(v[0].empty()) v[0]=\"1\";\n          ed[stoi(v[1])][a][b]+=stoi(v[0]);\n          ed[stoi(v[1])][b][a]+=stoi(v[0]);\n        }\n      }\n    }\n\n    vector<int> ans(DEG);\n    for(int i=DEG-1;i>=0;i--){\n      for(auto& v:flow.G){\n        for(auto& e:v){\n          if(e.cap) e.cap=INF;\n          e.cap+=ed[i][e.dst][flow.G[e.dst][e.rev].dst];\n        }\n      }\n      ans[i]=flow.flow(0,n-1);\n    }\n\n    bool f=1;\n    for(int i=DEG-1;i>=0;i--){\n      if(!ans[i]){\n        if(i) continue;\n        if(f) cout<<ans[i],f=0;\n        continue;\n      }\n      if(!f) cout<<\"+\";\n      f=0;\n      if(!(i&&ans[i]==1)) cout<<ans[i];\n      if(i>0) cout<<\"x\";\n      if(i>1) cout<<\"^\"<<i;\n    }\n    cout<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2359.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2359\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/drop.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../vector/fusion.cpp\"\n#include \"../../vector/near.cpp\"\n#include \"../../segtree/basic/dual.cpp\"\n#define SegmentTree SegmentTree2\n#include \"../../segtree/basic/lazy.cpp\"\n#undef SegmentTree\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int q;\n  cin>>q;\n  vector<int> ts(q),as(q),bs(q),ys(q);\n  for(int i=0;i<q;i++) cin>>ts[i]>>as[i]>>bs[i]>>ys[i];\n\n  vector<int> vs=near(fusion(as,bs),-1,0,1);\n  vs.emplace_back(0);\n  vs.emplace_back(1e9+10);\n  vs=compress(vs);\n  auto dc=dict(vs);\n  int m=dc.size();\n\n  using P = pair<int, int>;\n  auto h=[&](P a,P b){\n    if(a.first) return a;\n    return P(b.first,max(a.second,b.second));\n  };\n  P ei(0,0);\n  SegmentTree<P> seg(h,ei);\n  seg.init(m);\n\n  for(int i=0;i<q;i++){\n    int l=dc[as[i]];\n    int r=dc[bs[i]+1];\n\n    if(ts[i]==0) seg.update(l,r,P(0,ys[i]));\n    if(ts[i]==1) seg.update(l,r,P(1,0));\n  }\n\n  vector<int> zs(m);\n  for(int i=0;i<m;i++) zs[i]=seg.get_val(i).second;\n\n  auto ff=[&](int a,int b){return min(a,b);};\n  auto gg=[&](int  ,int b){return b;};\n  SegmentTree2<int, int> seg2(ff,gg,gg,INT_MAX,-1);\n  seg2.build(zs);\n\n  for(int i=0;i<q;i++){\n    int l=dc[as[i]];\n    int r=dc[bs[i]+1];\n    if(ts[i]==0){\n      if(seg2.query(l,r)!=ys[i]) drop(\"NO\");\n    }\n    if(ts[i]==1){\n      seg2.update(l,r,ys[i]);\n    }\n  }\n  drop(\"YES\");\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2370.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2370\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/bipartitedecomposition.cpp\"\n#include \"../../algorithm/partialsum.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  BipartiteDecomposition G(n);\n  for(int i=0;i<m;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    G.add_edge(u,v);\n  }\n  auto res=G.build();\n  if(res.empty()){\n    cout<<-1<<endl;\n    return 0;\n  }\n\n  int offset=0;\n  vector<int> vs;\n  for(auto[x,y]:res){\n    offset+=min(x,y);\n    vs.emplace_back(abs(x-y));\n  }\n  auto dp=partial_sum<100000>(vs);\n\n  long long ans=0;\n  for(int i=0;i<=n;i++){\n    if(!dp[i]) continue;\n    long long part=offset+i;\n    ans=max(ans,part*(n-part)-m);\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2397.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2397\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linearalgebra/squarematrix.cpp\"\n#include \"../../mod/mint.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  const int MAX = 80;\n  const int MOD = 1e9+9;\n  using M = Mint<int, MOD>;\n  using SM = SquareMatrix<M, MAX>;\n\n  using ll = long long;\n  ll w,h,n;\n  ll cnt=0;\n  while(cin>>w>>h>>n,w){\n    vector<ll> x(n),y(n);\n    for(int i=0;i<n;i++) cin>>x[i]>>y[i];\n    {\n      using P = pair<ll, ll>;\n      vector<P> vp;\n      for(int i=0;i<n;i++) vp.emplace_back(y[i],x[i]);\n      sort(vp.begin(),vp.end());\n      for(int i=0;i<n;i++) tie(y[i],x[i])=vp[i];\n    }\n    SM b;\n    for(int i=0;i<w;i++){\n      b[i][i]=M(1);\n      if(i-1>=0) b[i][i-1]=M(1);\n      if(i+1<w)  b[i][i+1]=M(1);\n    }\n    ll d=1;\n    SM res=SM::mul_identity();\n    for(int k=0;k<n;k++){\n      if(y[k]==d) continue;\n      res=b.pow(y[k]-d-1)*res;\n      int j=k;\n      SM c(b);\n      while(j<n&&y[k]==y[j]){\n        for(int i=0;i<w;i++) c[x[j]-1][i]=0;\n        j++;\n      }\n      res=c*res;\n      d=y[k];\n    }\n    res=b.pow(h-d)*res;\n    cout<<\"Case \"<<++cnt<<\": \"<<res[w-1][0].v<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2405.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2405\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/nicetree.cpp\"\n#include \"../../mod/mint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  while(cin>>n>>m,n){\n    NiceTree G(n);\n    using P = pair<int, int>;\n    set<P> es;\n    for(int i=0;i<n;i++){\n      int j=(i+1)%n;\n      G.add_edge(i,j);\n      es.emplace(i,j);\n      es.emplace(j,i);\n    }\n    for(int i=0;i<m;i++){\n      int a,b;\n      cin>>a>>b;\n      a--;b--;\n      G.add_edge(a,b);\n      es.emplace(a,b);\n      es.emplace(b,a);\n    }\n    if(n&1){\n      cout<<0<<endl;\n      continue;\n    }\n    G.build();\n    auto &T=G.T;\n    auto &buff=G.buff;\n\n    using M = Mint<int, 1000003>;\n    vector<vector<M>> dps(T.size());\n\n    auto base=\n      [&](int v){\n        const auto &bag=T[v].bag;\n        auto &dp=dps[v];\n        dp.assign(1<<bag.size(),0);\n      };\n\n    auto leaf=\n      [&](int v){\n        base(v);\n        auto &dp=dps[v];\n        dp[0]=M(1);\n      };\n\n    auto join=\n      [&](int v){\n        base(v);\n        const auto &chd=T[v].child;\n        auto &dp=dps[v];\n\n        for(int i=0;i<(int)dp.size();i++)\n          for(int j=0;j<(int)dp.size();j++)\n            if((i&j)==0) dp[i|j]+=dps[chd[0]][i]*dps[chd[1]][j];\n      };\n\n    auto introduce=\n      [&](int v,int){\n        base(v);\n        const auto &chd=T[v].child;\n\n        const auto &chd_bag=T[chd[0]].bag;\n        const auto &pr=dps[chd[0]];\n\n        auto &dp=dps[v];\n        for(int i=0;i<(int)pr.size();i++){\n          int bit=0;\n          for(int j=0;j<(int)chd_bag.size();j++)\n            if((i>>j)&1) bit|=buff[chd_bag[j]];\n          dp[bit]=pr[i];\n        }\n      };\n\n    auto forget=\n      [&](int v,int rmv){\n        base(v);\n        const auto &bag=T[v].bag;\n        const auto &chd=T[v].child;\n\n        const auto &chd_bag=T[chd[0]].bag;\n        const auto &pr=dps[chd[0]];\n\n        auto &dp=dps[v];\n        for(int i=0;i<(int)pr.size();i++){\n          int bit=0,used=0;\n          for(int j=0;j<(int)chd_bag.size();j++){\n            if((~i>>j)&1) continue;\n            if(rmv==chd_bag[j]) used=1;\n            if(rmv!=chd_bag[j]) bit|=buff[chd_bag[j]];\n          }\n          if(!used){\n            for(int j=0;j<(int)bag.size();j++){\n              if((bit>>j)&1) continue;\n              if(es.count(P(bag[j],rmv))) dp[bit|(1<<j)]+=pr[i];\n            }\n          }else{\n            dp[bit]+=pr[i];\n          }\n        }\n      };\n\n    G.dfs(0,leaf,join,introduce,forget);\n\n    cout<<dps[0][1]<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2415.knuthyao.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2415\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../algorithm/knuthyao.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n;\n  cin>>n;\n  vector<ll> ws(n);\n  for(int i=0;i<n;i++) cin>>ws[i];\n  vector<ll> sm(n+1);\n  for(int i=0;i<n;i++) sm[i+1]=sm[i]+ws[i];\n  auto cost=[&](int i,int k,int j){(void) k;return sm[j+1]-sm[i];};\n  cout<<KnuthYao<ll>(n,cost)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2415.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2415\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/skewheap.cpp\"\n#include \"../../algorithm/optimalbinarytree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n;\n  cin>>n;\n  vector<ll> ws(n);\n  for(int i=0;i<n;i++) cin>>ws[i];\n  cout<<optimalbinarytree(ws)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2432.ignore.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2432\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../linearalgebra/squarematrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  const int MAX = 160;\n  const int INF = 1e8;\n\n  struct M{\n    int v;\n    M(){*this=add_identity();}\n    M(int v):v(v){}\n    M operator+(const M &a)const{return M(max(v,a.v));}\n    M operator*(const M &a)const{return M(v+a.v);}\n    static M add_identity(){return M(-INF);}\n    static M mul_identity(){return M(0);}\n  };\n  using SM = SquareMatrix<M, MAX>;\n\n  int n,m,k;\n  cin>>n>>m>>k;\n  vector<SM> vs(1),ws(1);\n\n  for(int i=0;i<n;i++){\n    vs[0][i][i]=0;\n    ws[0][i][i]=0;\n  }\n\n  for(int i=0;i<m;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    chmax(vs[0][a][b].v,c);\n  }\n\n  for(int t=0;t<20;t++){\n    SM tv=vs[t]*vs[t];\n    SM tw=vs[t]*ws[t];\n    vs.emplace_back(tv);\n    ws.emplace_back(tw);\n  }\n\n  auto len=[&](SM &sm)->int{\n             int res=0;\n             for(int i=0;i<n;i++)\n               for(int j=0;j<n;j++)\n                 chmax(res,sm[i][j].v);\n             return res;\n           };\n\n  if(len(vs.back())<k){\n    cout<<-1<<endl;\n    return 0;\n  }\n\n  int ans=0;\n  SM res(ws[0]);\n  for(int t=20;t>=0;t--){\n    SM tmp=res*ws[t];\n    SM nxt=res*vs[t];\n    if(len(tmp)<k){\n      res.dat=nxt.dat;\n      ans+=1<<t;\n    }\n  }\n  cout<<ans<<endl;\n  if(ans>100) return 0;\n\n  int dp[MAX][MAX];\n  int pr[MAX][MAX];\n  for(int i=0;i<MAX;i++){\n    for(int j=0;j<MAX;j++){\n      dp[i][j]=-INF;\n      pr[i][j]=-1;\n    }\n  }\n  for(int v=0;v<n;v++) dp[0][v]=0;\n  for(int i=0;i<ans;i++){\n    for(int v=0;v<n;v++){\n      for(int u=0;u<n;u++){\n        if(dp[i+1][u]<dp[i][v]+vs[0][v][u].v){\n          dp[i+1][u]=dp[i][v]+vs[0][v][u].v;\n          pr[i+1][u]=v;\n        }\n      }\n    }\n  }\n  int pos=0;\n  for(int v=0;v<n;v++)\n    if(dp[ans][v]>dp[ans][pos]) pos=v;\n\n  vector<int> vx;\n  for(int i=ans;i>=0;i--){\n    vx.emplace_back(pos);\n    pos=pr[i][pos];\n  }\n  reverse(vx.begin(),vx.end());\n  for(int i=0;i<=ans;i++){\n    if(i) cout<<\" \";\n    cout<<vx[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2444.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2444\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/rollinghash.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  string s;\n  cin>>s;\n  const int MOD = 1e9+7;\n  const int B1 = 1e8+7;\n  const int B2 = 1777771;\n  RollingHash<int, MOD, B1> rh1(s);\n  RollingHash<int, MOD, B2> rh2(s);\n\n  int l=0,r=1;\n  set<pair<int, int>> sp;\n  for(int i=0;i<m;i++){\n    string t;\n    cin>>t;\n    if(t==\"L++\") l++;\n    if(t==\"L--\") l--;\n    if(t==\"R++\") r++;\n    if(t==\"R--\") r--;\n    sp.emplace(rh1.find(l,r),rh2.find(l,r));\n  }\n\n  cout<<sp.size()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2446.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2446\n// verification-helper: ERROR 1e-7\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/precision.cpp\"\n#include \"../../convolution/bitwise/fwht.cpp\"\n#include \"../../convolution/bitwise/or.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n;\n  ll m;\n  cin>>n>>m;\n  vector<ll> as(n),ps(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n  for(int i=0;i<n;i++) cin>>ps[i];\n\n  vector<ll> dp(1<<n,0);\n  for(int bit=1;bit<(1<<n);bit++){\n    ll t=1;\n    for(int i=0;i<n;i++){\n      if((~bit>>i)&1) continue;\n      ll k=as[i]/gcd(t,as[i]);\n      t=(t<=m/k?t*k:m+1);\n      if(t>m) break;\n    }\n    dp[bit]=m/t;\n  }\n\n  fwht(dp,bitwise_or::moebius);\n\n  double ans=0;\n  for(int bit=0;bit<(1<<n);bit++){\n    double po=1;\n    for(int i=0;i<n;i++)\n      if((bit>>i)&1) po*=ps[i]/100.0;\n      else po*=1.0-(ps[i]/100.0);\n    ans+=po*abs(dp[bit]);\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2450.linkcuttree.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2450\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/path.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  struct T{\n    int sm,va,vi,vl,vr;\n    T(int sm,int va,int vi,int vl,int vr):\n      sm(sm),va(va),vi(vi),vl(vl),vr(vr){}\n    T(){}\n  };\n  const int INF = 1e9;\n  int ei=-INF;\n\n  auto f=[&](T a,T b){\n           T c;\n           c.sm=a.sm+b.sm;\n           c.va=a.va+b.va;\n           c.vi=max({a.vi,b.vi,a.vr+b.vl});\n           c.vl=max({a.vl,a.va+b.vl});\n           c.vr=max({b.vr,a.vr+b.va});\n           return c;\n         };\n\n  auto g=[&](T a,int b){\n           if(b>=0) return T(a.sm,b*a.sm,b*a.sm,b*a.sm,b*a.sm);\n           return T(a.sm,b*a.sm,b,b,b);\n         };\n\n  auto h=[&](int,int b){return b;};\n  auto s=\n    [&](T a){\n      swap(a.vl,a.vr);\n      return a;\n    };\n\n  using Node = NodeBase<T, int>;\n  constexpr size_t LIM = 2e5+100;\n  using LCT = Path<Node, LIM>;\n\n  LCT lct(f,g,h,s,ei);\n\n  vector<int> ws(n);\n  for(int i=0;i<n;i++) cin>>ws[i];\n  for(int i=0;i<n;i++) lct.create(g(T(1,0,0,0,0),ws[i]));\n\n  for(int i=0;i<n-1;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    lct.evert(lct[b]);\n    lct.link(lct[a],lct[b]);\n  }\n\n  for(int i=0;i<q;i++){\n    int t,a,b,c;\n    cin>>t>>a>>b>>c;\n    a--;b--;\n    if(t==1){\n      lct.evert(lct[a]);\n      lct.update(lct[b],c);\n    }\n    if(t==2){\n      lct.evert(lct[a]);\n      auto res=lct.query(lct[b]);\n      cout<<max({res.va,res.vi,res.vl,res.vr})<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2450.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2450\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/heavylightdecomposition.cpp\"\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  HLD hld(n);\n  vector<int> ws(n);\n  for(int i=0;i<n;i++) cin>>ws[i];\n  for(int i=0;i+1<n;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    hld.add_edge(a,b);\n  }\n  hld.build();\n\n  using T = tuple<int, int, int, int, int>;\n  using E = pair<int, int>;\n\n  T ti(-1,-1,-1,-1,-1);\n  E ei(-1,-(1e4+10));\n\n  auto f=[&](T a,T b){\n    if(a==ti) return b;\n    if(b==ti) return a;\n\n    auto[asz,ava,avi,avl,avr]=a;\n    auto[bsz,bva,bvi,bvl,bvr]=b;\n\n    int csz=asz+bsz;\n    int cva=ava+bva;\n    int cvi=max({avi,bvi,avr+bvl});\n    int cvl=max(avl,ava+bvl);\n    int cvr=max(bvr,avr+bva);\n    return T(csz,cva,cvi,cvl,cvr);\n  };\n\n  auto g=[&](T a,E p){\n    if(p==ei) return a;\n    auto[asz,ava,avi,avl,avr]=a;\n    auto[v,b]=p;\n    if(~v) asz=1;\n    if(b>=0) return T(asz,b*asz,b*asz,b*asz,b*asz);\n    return T(asz,b*asz,b,b,b);\n  };\n\n  auto h=[&](E,E b){return b;};\n  SegmentTree<T, E> seg(f,g,h,ti,ei);\n\n  vector<T> vt(n);\n  for(int i=0;i<n;i++) vt[hld.vid[i]]=g(ti,E(i,ws[i]));\n  seg.build(vt);\n\n  for(int i=0;i<q;i++){\n    int t,a,b,c;\n    cin>>t>>a>>b>>c;\n    a--;b--;\n    if(t==1){\n      hld.for_each(a,b,[&](int l,int r){seg.update(l,r,E(-1,c));});\n    }\n    if(t==2){\n      int c=hld.lca(a,b);\n      T x=ti,y=ti;\n      hld.for_each(c,a,[&](int l,int r){x=f(seg.query(l,r),x);});\n      hld.for_each_edge(c,b,[&](int l,int r){y=f(seg.query(l,r),y);});\n      auto&[xsz,xva,xvi,xvl,xvr]=x;\n      swap(xvl,xvr);\n      auto[vsz,vva,vvi,vvl,vvr]=f(x,y);\n      cout<<max({vva,vvi,vvl,vvr})<<'\\n';\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2488.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2488\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../algorithm/knuthyao.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n;\n  cin>>n;\n  vector<ll> xs(n),ys(n);\n  for(int i=0;i<n;i++) cin>>xs[i]>>ys[i];\n  auto calc=\n    [&](int i,int k,int j){\n      return (xs[k+1]-xs[i])+(ys[k]-ys[j]);\n    };\n  cout<<KnuthYao<ll>(n,calc)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2513.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2513\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../matching/bipartite.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  while(cin>>n,n){\n    vector<vector<int>> xss;\n    vector<vector<int>> yss;\n    for(int i=0;i<n;i++){\n      vector<int> xs(3),ys(3);\n      for(int j=0;j<3;j++) cin>>xs[j]>>ys[j];\n      xss.emplace_back(xs);\n      yss.emplace_back(ys);\n    }\n\n    const int T = 16;\n    int dx[T][4]={{ 0,-1, 1, 0},\n                  { 0, 1, 1, 2},\n                  { 0, 0, 1,-1},\n                  { 0,-1,-1,-2},\n\n                  { 0, 1, 2, 3},\n                  { 0,-2,-1, 1},\n\n                  {-1, 0, 1, 2},\n                  {-3,-2,-1, 0},\n\n                  { 0, 0,-1,-1},\n                  { 1, 1, 0, 0},\n\n                  { 0, 0, 1, 1},\n                  {-1,-1, 0, 0},\n\n                  {-1, 0, 0, 1},\n                  {-2,-1,-1, 0},\n\n                  { 1, 0, 0,-1},\n                  { 2, 1, 1, 0},\n\n    };\n    int dy[T][4]={{ 0, 0, 0,-1},\n                  { 0, 1, 0, 0},\n                  { 0,-1,-1,-1},\n                  { 0, 0, 1, 0},\n\n                  { 0, 0, 0, 0},\n                  { 0, 0, 0, 0},\n\n                  { 0, 0, 0, 0},\n                  { 0, 0, 0, 0},\n\n                  { 0,-1,-1,-2},\n                  { 1, 0, 0,-1},\n\n                  { 0,-1,-1,-2},\n                  { 1, 0, 0,-1},\n\n                  { 0, 0,-1,-1},\n                  { 1, 1, 0, 0},\n\n                  { 0, 0,-1,-1},\n                  { 1, 1, 0, 0},\n\n    };\n\n    using P = pair<int, int>;\n\n    int m=n;\n    map<P, int> mp;\n    vector<set<int>> G(n);\n\n    for(int i=0;i<n;i++){\n      auto &xs=xss[i];\n      auto &ys=yss[i];\n      for(int j=0;j<3;j++)\n        mp[P(xs[j],ys[j])]=m++;\n    }\n\n    vector<set<int> > H(n);\n    for(int i=0;i<n;i++){\n      auto &xs=xss[i];\n      auto &ys=yss[i];\n      set<P> tmp;\n      for(int j=0;j<3;j++)\n        tmp.emplace(xs[j],ys[j]);\n\n      int sy=((xs[0]+ys[0])%2==0?1:-1);\n\n      for(int j=0;j<T;j++){\n        set<P> res;\n        for(int k=0;k<4;k++)\n          res.emplace(xs[0]+dx[j][k],ys[0]+sy*dy[j][k]);\n\n        int cnt=0;\n        P uku;\n        for(auto p:res){\n          if(tmp.count(p)){\n            cnt++;\n            continue;\n          }\n          uku=p;\n        }\n        if(cnt!=3) continue;\n        if(!mp.count(uku)) mp[uku]=m++;\n        G[i].emplace(mp[uku]);\n      }\n    }\n\n    Bipartite bm(m);\n    for(int i=0;i<n;i++)\n      for(int j:G[i])\n        bm.add_edge(i,j);\n\n    for(int i=0;i<n;i++){\n      auto &xs=xss[i];\n      auto &ys=yss[i];\n      for(int j=0;j<3;j++)\n        bm.disable(mp[P(xs[j],ys[j])]);\n    }\n\n    int res=bm.build();\n\n    if(res==n){\n      cout<<\"Valid\"<<\"\\n\";\n      continue;\n    }\n\n    if(res+4<n){\n      cout<<\"Invalid\"<<\"\\n\";\n      continue;\n    }\n\n    set<int> ans;\n    for(int i=0;i<n;i++){\n      auto &xs=xss[i];\n      auto &ys=yss[i];\n      res+=bm.disable(i);\n\n      for(int j=0;j<3;j++)\n        res+=bm.enable(mp[P(xs[j],ys[j])]);\n\n      if(res+1==n) ans.emplace(i);\n\n      for(int j=0;j<3;j++)\n        res+=bm.disable(mp[P(xs[j],ys[j])]);\n\n      res+=bm.enable(i);\n    }\n\n    if(ans.empty()){\n      cout<<\"Invalid\"<<\"\\n\";\n    }else{\n      cout<<\"Remove\"<<\"\\n\";\n      for(int i:ans) cout<<i+1<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2560.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2560\n// verification-helper: ERROR 1e-8\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../convolution/convolution2D.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  cout<<fixed<<setprecision(12);\n  using ll = long long;\n  using D = double;\n\n  int n;\n  cin>>n;\n\n  vector< vector<int> > as(n,vector<int>(n));\n  auto bs(as);\n\n  int cnt=0;\n  for(int i=0;i<n;i++){\n    for(int j=0;j<n;j++){\n      cin>>as[i][j];\n      bs[n-(i+1)][n-(j+1)]=as[i][j];\n      cnt+=as[i][j];\n    }\n  }\n\n  NTT<1> ntt1;\n  NTT<2> ntt2;\n  using M1 = NTT<1>::M;\n  using M2 = NTT<2>::M;\n  auto tran1=[&](auto &as,bool f){ntt1.ntt(as,f);};\n  auto tran2=[&](auto &as,bool f){ntt2.ntt(as,f);};\n\n  Convolution2D<M1, decltype(tran1)> conv1(tran1);\n  Convolution2D<M2, decltype(tran2)> conv2(tran2);\n\n  vector< vector<M1> > as1(n,vector<M1>(n));\n  auto bs1(as1);\n  vector< vector<M2> > as2(n,vector<M2>(n));\n  auto bs2(as2);\n  for(int i=0;i<n;i++){\n    for(int j=0;j<n;j++){\n      as1[i][j]=M1(as[i][j]);\n      as2[i][j]=M2(as[i][j]);\n      bs1[i][j]=M1(bs[i][j]);\n      bs2[i][j]=M2(bs[i][j]);\n    }\n  }\n\n  auto cs1=conv1.multiply(as1,bs1);\n  auto cs2=conv2.multiply(as2,bs2);\n\n  D dom=(D)cnt*(cnt-1)/2;\n  D sum=0;\n  map<ll, ll> num;\n  const int S = 10000;\n\n  auto calc=\n    [&](ll a,ll b){\n      const ll r01 = M2(ntt1.md).inv().v;\n      b = (b - a) * r01 % ntt2.md;\n      if (b < 0) b += ntt2.md;\n      a = (a + b * ntt1.md);\n      return a;\n    };\n\n  for(int i=0;i<(int)cs1.size();i++){\n    for(int j=0;j<(int)cs1[i].size();j++){\n      ll dd=(ll)(i-(n-1))*(i-(n-1))+(ll)(j-(n-1))*(j-(n-1));\n      ll cc=calc(cs1[i][j].v,cs2[i][j].v);\n      if(dd==0) cc-=cnt;\n      if(cc==0) continue;\n      num[dd]+=cc;\n      sum+=sqrt(dd)*cc;\n      if((int)num.size()>S) num.erase(--num.end());\n    }\n  }\n\n  cout<<sum/dom/2<<endl;\n  for(auto p:num)\n    cout<<p.first<<\" \"<<p.second/2<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2563.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2563\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../vector/zip.cpp\"\n#include \"../../vector/fusion.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../algorithm/parallelbinarysearch.cpp\"\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n,m,q;\n  cin>>n>>m>>q;\n\n  vector<int> as(m),bs(m),vs(m);\n  for(int i=0;i<m;i++)\n    cin>>as[i]>>bs[i]>>vs[i],as[i]--;\n\n  {\n    auto vt=zip(vs,as,bs);\n    sort(vt.begin(),vt.end());\n    for(int i=0;i<m;i++) tie(vs[i],as[i],bs[i])=vt[i];\n  }\n\n  vector<int> xs(q),ys(q);\n  vector<ll> js(q);\n  for(int i=0;i<q;i++)\n    cin>>xs[i]>>ys[i]>>js[i],xs[i]--;\n\n  auto ps=compress(fusion(as,bs,xs,ys,vector<int>({0,1000000007})));\n  auto dc=dict(ps);\n\n  using P = pair<ll, int>;\n  auto f=[&](P a,P b){return P(a.first+b.first,a.second+b.second);};\n  auto g=[&](P a,int b){return P(a.first+(ll)b*a.second,a.second);};\n  auto h=[&](int a,int b){return a+b;};\n  SegmentTree<P, int> seg(f,g,h,P(0,0),0);\n\n  vector<P> vp(ps.size()-1);\n  for(int i=0;i+1<(int)ps.size();i++) vp[i]=P(0,ps[i+1]-ps[i]);\n\n  for(int &a:as) a=dc[a];\n  for(int &b:bs) b=dc[b];\n  for(int &x:xs) x=dc[x];\n  for(int &y:ys) y=dc[y];\n\n  auto init=[&](){\n    seg.build(vp);\n  };\n  auto apply=[&](int i){\n    seg.update(as[i],bs[i],1);\n  };\n  auto check=[&](int i){\n    return seg.query(xs[i],ys[i]).first>=js[i];\n  };\n\n  auto ans=parallel_binary_search(q,m,init,apply,check);\n  for(int i=0;i<q;i++) cout<<vs[ans[i]]<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2603.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2603\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../algorithm/monotoneminima.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int s,n,m;\n  cin>>s>>n>>m;\n  vector<int> xs(s);\n  for(int i=0;i<s;i++) cin>>xs[i];\n\n  vector<int> ts(n),ps(n);\n  for(int i=0;i<n;i++) cin>>ts[i]>>ps[i],ps[i]--;\n\n  vector<int> vs(n);\n  for(int i=0;i<n;i++) vs[i]=ts[i]-xs[ps[i]];\n  sort(vs.begin(),vs.end());\n\n  vector<int> sm(n+1,0);\n  for(int i=0;i<n;i++) sm[i+1]=sm[i]+vs[i];\n\n  const int INF = 1e9;\n  vector<int> dp(n+1,INF);\n  dp[0]=0;\n  for(int k=0;k<m;k++){\n    auto dist=\n      [&](int i,int j){\n        return i<j?INF:dp[j]+(i?vs[i-1]:0)*(i-j)-(sm[i]-sm[j]);\n      };\n    auto res=MonotoneMinima::args<int>(n+1,n+1,dist);\n    vector<int> nx(n+1);\n    for(int i=0;i<=n;i++) nx[i]=dist(i,res[i]);\n    swap(dp,nx);\n  }\n  cout<<dp[n]<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2624.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2624\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linearalgebra/binarymatrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  mat v(n,BS(0));\n  for(int i=0;i<n;i++){\n    for(int j=0;j<n;j++){\n      int k;\n      cin>>k;\n      v[i][j]=k;\n    }\n  }\n  BS w;\n  for(int i=0;i<n;i++){\n    int k;\n    cin>>k;\n    w[i]=k;\n  }\n  int t;\n  cin>>t;\n  v=mat_pow(v,t);\n\n  int a=mrank(v,n);\n  for(int i=0;i<n;i++) v[i][n]=w[i];\n  int b=mrank(v,n+1);\n\n  if(a!=b){\n    cout<<\"none\"<<endl;\n    return 0;\n  }\n\n  if(a!=n){\n    cout<<\"ambiguous\"<<endl;\n    return 0;\n  }\n\n  gauss(v);\n  for(int i=0;i<n;i++) cout<<v[i][n]<<\" \\n\"[i==n-1];\n\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2627.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2627\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../mincostflow/primaldual.cpp\"\n#include \"../../mincostflow/negativeedge.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  const ll INF = 1e9;\n\n  int n;\n  cin>>n;\n  NegativeEdge<int, ll> G(n+1);\n\n  for(int i=0;i<n;i++){\n    int k;\n    cin>>k;\n    map<int, int> dst;\n    for(int j=0;j<k;j++){\n      int t,c;\n      cin>>t>>c;\n      t--;\n      G.use_edge(i,t,1,c);\n      if(!dst.count(t)) dst[t]=c;\n      chmin(dst[t],c);\n    }\n\n    for(auto p:dst)\n      G.add_edge(i,p.first,INF,p.second);\n\n    G.add_edge(i,n,INF,0);\n  }\n\n  assert(G.build(0,n,INF));\n  cout<<G.get_cost()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2636.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2636\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../toptree/toptree.cpp\"\n#include \"../../toptree/distancesum.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n;\n  cin>>n;\n\n  using ll = long long;\n  const size_t N = 2e5;\n  using Cluster = DistanceSum<ll>;\n  TopTree<Vertex, Cluster, N> G;\n\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++) vs[i]=G.create(0);\n\n  for(int i=1;i<n;i++){\n    int p,d;\n    cin>>p>>d;\n    p--;\n    G.link(vs[p],d,vs[i]);\n  }\n\n  for(int i=0;i<n;i++){\n    G.set_vertex(vs[i],1);\n    cout<<G.get_subtree(centroid(G,vs[i])).ans<<newl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2644.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2644\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/suffixarray.cpp\"\n#include \"../../segtree/basic/ushi.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string s;\n  int m;\n  cin>>s>>m;\n  SuffixArray sa(s);\n\n  using P = pair<int, int>;\n  auto f=[](P a,P b){\n           return P(max(a.first,b.first),\n                    min(a.second,b.second));\n         };\n  int n=s.size()+1;\n  SegmentTree<P> seg(f,P(-1,n+1));\n\n  vector<P> vp;\n  for(int i=0;i<n;i++) vp.emplace_back(sa[i],sa[i]);\n  seg.build(vp);\n\n  for(int i=0;i<m;i++){\n    string x,y;cin>>x>>y;\n    int lx=sa.lower_bound(x);\n    int rx=sa.upper_bound(x);\n    int ly=sa.lower_bound(y);\n    int ry=sa.upper_bound(y);\n    int ans;\n    if(rx-lx<=0||ry-ly<=0) ans=0;\n    else{\n      int a=seg.query(ly,ry).first;\n      int b=seg.query(lx,rx).second;\n      if(b+(int)x.size()>a+(int)y.size()) ans=0;\n      else ans=a-b+y.size();\n    }\n    cout<<ans<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2646.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2646\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../tools/cc_hash.cpp\"\n#include \"../../datastructure/pb_ds_cc_hash_table.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n,m;\n  cin>>n>>m;\n\n  m++;\n  vector<int> as(m),bs(m);\n  for(int i=0;i<m;i++) cin>>as[i];\n  for(int i=1;i<m;i++) cin>>bs[i];\n\n  vector<ll> hs;\n  MFP([&](auto dfs,int l,int r)->void{\n        int x=lower_bound(as.begin(),as.end(),r)-as.begin();\n        if(as[x-1]<=l&&r<=as[x]) return;\n        hs.emplace_back(((ll)l<<31)|r);\n        int m=(l+r)>>1;\n        dfs(l,m);\n        dfs(m,r);\n      })(0,(1<<n));\n\n  sort(hs.begin(),hs.end());\n  hs.erase(unique(hs.begin(),hs.end()),hs.end());\n\n  gmap<ll, int, cc_hash<ll> > idx;\n  for(int i=0;i<(int)hs.size();i++) idx[hs[i]]=i;\n\n  vector< vector<int> > dp(n+1,vector<int>(hs.size(),-1));\n\n  int ans=(1<<n)-\n    MFP([&](auto dfs,int l,int r,int d,int k)->int{\n          int x=lower_bound(as.begin(),as.end(),r)-as.begin();\n          if(as[x-1]<=l&&r<=as[x]){\n            int v=bs[x],tmp=0;\n            tmp+=(k==v);\n            tmp+=(r-l)>>(n-v+1);\n            return tmp;\n          }\n\n          if(~dp[k][idx[((ll)l<<31)|r]]) return dp[k][idx[((ll)l<<31)|r]];\n          int &res=(dp[k][idx[((ll)l<<31)|r]]=0);\n\n          int m=(l+r)>>1;\n          res=max(res,dfs(l,m,d+1,d)+dfs(m,r,d+1,k));\n          res=max(res,dfs(l,m,d+1,k)+dfs(m,r,d+1,d));\n          return res;\n        })(0,1<<n,1,0);\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2647.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2647\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#include \"../../graph/arborescence_edmond.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  vector<vector<int>> G(n),R(n);\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    G[a].emplace_back(b);\n    R[b].emplace_back(a);\n  }\n\n  vector<int> vs;\n  for(int i=0;i<n;i++)\n    if(R[i].empty()) vs.emplace_back(i);\n\n  int sz=vs.size();\n  map<int, int> rev;\n  for(int i=0;i<sz;i++) rev[vs[i]]=i;\n\n  const int INF = 1e9;\n  vector<vector<int>> H;\n  for(int r:vs){\n    vector<int> dp(n,INF);\n\n    using P = pair<int, int>;\n    deque<P> deq;\n\n    dp[r]=0;\n    deq.emplace_back(r,0);\n\n    while(!deq.empty()){\n      int v,d;\n      tie(v,d)=deq.front();deq.pop_front();\n      if(dp[v]<d) continue;\n      for(int u:G[v]){\n        if(dp[u]<=dp[v]) continue;\n        dp[u]=dp[v];\n        deq.emplace_front(u,dp[u]);\n      }\n      for(int u:R[v]){\n        if(dp[u]<=dp[v]+1) continue;\n        dp[u]=dp[v]+1;\n        deq.emplace_back(u,dp[u]);\n      }\n    }\n\n    vector<int> di(sz);\n    for(int i=0;i<sz;i++) di[i]=dp[vs[i]];\n    H.emplace_back(di);\n  }\n\n  int cost=INF;\n  vector<int> ans;\n\n  for(int i=0;i<sz;i++){\n    Arborescence<int> arb(sz);\n    for(int j=0;j<sz;j++)\n      for(int k=0;k<sz;k++)\n        if(j!=k) arb.add_edge(j,k,H[j][k]);\n\n    int res=arb.build(i);\n    if(res<cost) cost=res,ans.clear();\n    if(res==cost) ans.emplace_back(vs[i]);\n  }\n\n  cout<<ans.size()<<\" \"<<cost<<endl;\n  for(int i=0;i<(int)ans.size();i++){\n    if(i) cout<<\" \";\n    cout<<ans[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2659.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2659\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/extgcd.cpp\"\n#include \"../../mod/inverse.cpp\"\n#include \"../../math/linearcongruence.cpp\"\n#undef call_from_test\n\nint r[111][111];\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,d;\n  cin>>n>>m>>d;\n  vector<int> a(m);\n  for(int i=0;i<m;i++) cin>>a[i];\n\n  for(int i=0;i<d;i++)\n    for(int j=0;j<m;j++)\n      cin>>r[i][j];\n\n  using ll = long long;\n  ll ans=n;\n\n  for(int i=0;i<d;i++){\n    vector<ll> A,B,M;\n\n    for(int j=0;j<m;j++){\n      if(r[i][j]<0) continue;\n      A.emplace_back(1);\n      B.emplace_back(r[i][j]);\n      M.emplace_back(a[j]);\n    }\n    auto p=linear_congruence(A,B,M);\n    if(p.second<0){\n      ans=-1;\n      break;\n    }\n    if(p.second<0) p.first+=p.second;\n    ans=(ans-p.first)/p.second*p.second+p.first;\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2667.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2667\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/heavylightdecomposition.cpp\"\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n,q;\n  cin>>n>>q;\n  HLD hld(n);\n  for(int i=1;i<n;i++){\n    int a,b;\n    cin>>a>>b;\n    hld.add_edge(a,b);\n  }\n  hld.build();\n\n  using P = pair<ll, ll>;\n  auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);};\n  auto g=[](P a,ll b){return P(a.first+b*a.second,a.second);};\n  auto h=[](ll a,ll b){return a+b;};\n  SegmentTree<P, ll> seg(f,g,h,P(0,0),0);\n  seg.build(vector<P>(n,P(0,1)));\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int u,v;\n      cin>>u>>v;\n      ll ans=0;\n      hld.for_each_edge(u,v,[&](int l,int r){ans+=seg.query(l,r).first;});\n      cout<<ans<<\"\\n\";\n    }\n    if(t==1){\n      int v,x;\n      cin>>v>>x;\n      seg.update(hld.vid[v]+1,hld.vid[v]+hld.sub[v],x);\n    }\n  }\n\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2674.count.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2674\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/count/static.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int d;\n  cin>>d;\n  vector<int> xs(d);\n  for(int i=0;i<d;i++) cin>>xs[i];\n\n  using P = pair<int, int>;\n  vector<P> vp;\n  for(int i=0;i<d;i++) vp.emplace_back(i,xs[i]);\n  SegmentTree<int> seg(d,vp);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int l,r,e;\n    cin>>l>>r>>e;\n    l--;\n    int a=min(xs[l],xs[r-1]);\n    int b=max(xs[l],xs[r-1]);\n    cout<<(r-l)-seg.query(l,r,a-e,b+e+1)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2674.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2674\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/waveletmatrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int d;\n  cin>>d;\n  vector<int> xs(d);\n  for(int i=0;i<d;i++) cin>>xs[i];\n\n  const int ofs = 2e8;\n  for(int &x:xs) x+=ofs;\n  WaveletMatrix<int, 30> wm(xs);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int l,r,e;\n    cin>>l>>r>>e;\n    l--;\n    int a=min(xs[l],xs[r-1]);\n    int b=max(xs[l],xs[r-1]);\n    cout<<(r-l)-wm.rangefreq(l,r,a-e,b+e+1)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2679.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2679\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mincostflow/primaldual.cpp\"\n#undef call_from_test\n\nconst int MAX = 52;\nstruct ARR{\n  array<int, MAX> val;\n  ARR(){fill(val.begin(),val.end(),0);}\n  ARR(int x){fill(val.begin(),val.end(),x);}\n  int& operator[](int k){return val[k];};\n  int operator[](int k)const{return val[k];};\n  ARR operator+(const ARR &oth) const{\n    ARR res;\n    for(int i=0;i<MAX;i++)\n      res[i]=val[i]+oth[i];\n    return res;\n  }\n  ARR operator-(const ARR &oth) const{\n    ARR res;\n    for(int i=0;i<MAX;i++)\n      res[i]=val[i]-oth[i];\n    return res;\n  }\n  ARR operator-() const{\n    ARR res;\n    for(int i=0;i<MAX;i++)\n      res[i]=-val[i];\n    return res;\n  }\n  ARR operator*(const int &k) const{\n    ARR res;\n    for(int i=0;i<MAX;i++)\n      res[i]=val[i]*k;\n    return res;\n  }\n  ARR operator/(const int &k) const{\n    ARR res;\n    for(int i=0;i<MAX;i++)\n      res[i]=val[i]/k;\n    return res;\n  }\n  bool operator< (const ARR &oth) const{\n    return val< oth.val;\n  }\n  bool operator> (const ARR &oth) const{\n    return val< oth.val;\n  }\n  bool operator==(const ARR &oth) const{\n    return val==oth.val;\n  }\n};\n\nnamespace std {\n  template<> class numeric_limits<ARR> {\n  public:\n    static ARR max() {return ARR(numeric_limits<int>::max());};\n  };\n}\n\nint main(){\n  int n;\n  cin>>n;\n  vector<string> vs(n);\n  for(int i=0;i<n;i++) cin>>vs[i];\n\n  auto enc=[&](char c){\n    if(isupper(c)) return c-'A';\n    return 26+c-'a';\n  };\n  auto dec=[&](int d){\n    if(d<26) return 'A'+d;\n    return 'a'+d-26;\n  };\n\n  int S=n*2,T=n*2+1;\n  PrimalDual<int, ARR> G(n*2+2);\n  for(int i=0;i<n;i++){\n    G.add_edge(S,i,1,ARR());\n    G.add_edge(n+i,T,1,ARR());\n  }\n\n  const int INF = 1e5;\n  for(int i=0;i<n;i++){\n    for(int j=0;j<n;j++){\n      ARR cost(INF);\n      cost[enc(vs[i][j])]=INF-1;\n      G.add_edge(i,n+j,1,cost);\n    }\n  }\n\n  assert(G.build(S,T,n));\n  auto res=G.get_cost();\n\n  string ans;\n  for(int i=0;i<MAX;i++)\n    for(int j=0;j<n*INF-res[i];j++)\n      ans+=dec(i);\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2687.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2687\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../datastructure/rotcev.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  string s;\n  cin>>s;\n\n  vector< vector<int> > G(n);\n  for(int i=1;i<n;i++){\n    int x,y;\n    cin>>x>>y;\n    x--;y--;\n    G[x].emplace_back(y);\n    G[y].emplace_back(x);\n  }\n\n  using ll = long long;\n  ll ans=0;\n  vector< Rotcev<int> > dp1(n),dp2(n);\n  MFP([&](auto dfs,int v,int p)->void{\n      int idx=v;\n      for(int u:G[v]){\n        if(u==p) continue;\n        dfs(u,v);\n        if(dp1[idx].size()+dp2[idx].size()<\n           dp1[u].size()+dp2[u].size()) idx=u;\n      }\n      auto &dx=dp1[v];\n      auto &dy=dp2[v];\n\n      if(idx!=v){\n        for(int u:G[v]){\n          if(u==p) continue;\n          if(u==idx) continue;\n          auto &py=dp2[u];\n          int sy=py.size();\n          if(s[v]=='('){\n            for(int i=0;i+1<sy;i++)\n              if(i<(int)dp1[idx].size())\n                ans+=(ll)dp1[idx][i]*py[i+1];\n          }else{\n            for(int i=0;i<sy;i++)\n              if(i+1<(int)dp1[idx].size())\n                ans+=(ll)dp1[idx][i+1]*py[i];\n          }\n        }\n        swap(dx,dp1[idx]);\n        swap(dy,dp2[idx]);\n      }else{\n        dx.assign(1,0);\n        dy.assign(1,0);\n      }\n\n      for(int u:G[v]){\n        if(u==p) continue;\n        if(u==idx) continue;\n        auto &px=dp1[u];\n        auto &py=dp2[u];\n        int sx=px.size();\n        int sy=py.size();\n\n        if((int)dx.size()<sx){\n          Rotcev<int> tmp(dx);\n          dx.assign(sx,0);\n          for(int j=0;j<(int)tmp.size();j++) dx[j]+=tmp[j];\n        }\n        for(int j=0;j<sx;j++) dx[j]+=px[j];\n\n        if((int)dy.size()<sy){\n          Rotcev<int> tmp(dy);\n          dy.assign(sy,0);\n          for(int j=0;j<(int)tmp.size();j++) dy[j]+=tmp[j];\n        }\n        for(int j=0;j<sy;j++) dy[j]+=py[j];\n      }\n\n      // top\n      if(s[v]=='('){\n        if(1<dy.size()) ans+=dy[1];\n      }else{\n        if(1<dx.size()) ans+=dx[1];\n      }\n\n      //lca\n      for(int u:G[v]){\n        if(u==p) continue;\n        if(u==idx) continue;\n        auto &px=dp1[u];\n        auto &py=dp2[u];\n        int sx=px.size();\n        int sy=py.size();\n        if(s[v]=='('){\n          for(int i=0;i<sx;i++){\n            if(i+1<(int)dy.size())\n              ans+=(ll)px[i]*dy[i+1];\n            if(i+1<sy)\n              ans-=(ll)px[i]*py[i+1];\n          }\n        }else{\n          for(int i=0;i+1<sx;i++){\n            if(i<(int)dy.size())\n              ans+=(ll)px[i+1]*dy[i];\n            if(i<sy)\n              ans-=(ll)px[i+1]*py[i];\n          }\n        }\n      }\n\n      for(int u:G[v]){\n        if(u==p) continue;\n        dp1[u].clear();\n        dp2[u].clear();\n      }\n\n      if(dx.empty()) dx.assign(1,0);\n      if(dy.empty()) dy.assign(1,0);\n      dx[0]+=1;\n      dy[0]+=1;\n\n      if(s[v]=='('){\n        dx.emplace_front(0);\n        dy.pop_front();\n      }else{\n        dx.pop_front();\n        dy.emplace_front(0);\n      }\n    })(0,-1);\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2711.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2711\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/suffixarray.cpp\"\n#include \"../../string/longestcommonprefix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string s;\n  cin>>s;\n  LongestCommonPrefix lcp(s);\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int l,r,t;\n    cin>>l>>r>>t;\n    l--;\n    int x=lcp.lcp(l,l+t);\n    if(l+t+x+1>=r){\n      cout<<\"Yes\\n\";\n      continue;\n    }\n    int y=lcp.lcp(l+x+1,l+t+x+1);\n    if(l+t+x+1+y>=r){\n      cout<<\"Yes\\n\";\n      continue;\n    }\n    if(l+x+1+y<l+t){\n      cout<<\"No\\n\";\n      continue;\n    }\n    int z=lcp.lcp(l+x+1+y+1,l+t+x+1+y+1);\n    if(l+t+x+1+y+1+z<r){\n      cout<<\"No\\n\";\n      continue;\n    }\n    if(x+t==x+1+y&&s[l+x]==s[l+x+t+t]) cout<<\"Yes\\n\";\n    else cout<<\"No\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2720.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2720\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/carmichael.cpp\"\n#undef call_from_test\n\n// x^n mod m\ntemplate<typename T>\nT mpow(T x,T n,T m){\n  T r=1;\n  x%=m;\n  while(n){\n    if(n&1) r=r*x%m;\n    x=x*x%m;\n    n>>=1;\n  }\n  return r;\n}\n\nsigned main(){\n  using ll = long long;\n  ll n;\n  cin>>n;\n  if(n==2){\n    cout<<1<<endl;\n    return 0;\n  }\n  for(ll i=2;i*i<=n;i++){\n    if(n%(i*i)==0){\n      cout<<-1<<endl;\n      return 0;\n    }\n  }\n\n  ll a=carmichael_lambda(n);\n  ll b=carmichael_lambda(a);\n  assert(n!=1);\n  assert(a!=1);\n  assert(b!=0);\n  {\n    ll x=mpow(n,b,a)!=1;\n    ll y=__gcd(n%a,a)!=1;\n    assert(x==y);\n  }\n  if(mpow(n,b,a)!=1){\n    assert(n%a!=1);\n    cout<<-1<<endl;\n    return 0;\n  }\n\n  if(n%a==1) b=1;\n  for(ll i=2;i*i<=b;i++){\n    if(b%i!=0) continue;\n    while(b%i==0){\n      if(mpow(n,b/i,a)==1) b/=i;\n      else break;\n    }\n    ll j=b/i;\n    if(j==1) continue;\n    while(b%j==0){\n      if(mpow(n,b/j,a)==1) b/=j;\n      else break;\n    }\n  }\n  cout<<b<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2725.linecontainer.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2725\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../vector/zip.cpp\"\n#include \"../../convexhulltrick/linecontainer.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n,x;\n  cin>>n>>x;\n  vector<ll> ts(n),ps(n),fs(n);\n  for(int i=0;i<n;i++) cin>>ts[i]>>ps[i]>>fs[i];\n\n  auto vt=zip(fs,ps,ts);\n  sort(vt.begin(),vt.end());\n  for(int i=0;i<n;i++) tie(fs[i],ps[i],ts[i])=vt[i];\n\n  vector<MaxLineContainer<ll>> vh(x+1);\n\n  ll ans=0;\n  for(int i=0;i<n;i++){\n    for(int j=x;j>ts[i];j--){\n      if(vh[j-ts[i]].empty()) continue;\n      ll val=vh[j-ts[i]].query(fs[i])+ps[i]-fs[i]*fs[i];\n      vh[j].add(2*fs[i],val-fs[i]*fs[i]);\n      chmax(ans,val);\n    }\n    vh[ts[i]].add(2*fs[i],ps[i]-fs[i]*fs[i]);\n    chmax(ans,ps[i]);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2725.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2725\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../vector/zip.cpp\"\n#include \"../../convexhulltrick/convexhulltrick.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n,x;\n  cin>>n>>x;\n  vector<ll> ts(n),ps(n),fs(n);\n  for(int i=0;i<n;i++) cin>>ts[i]>>ps[i]>>fs[i];\n\n  auto vt=zip(fs,ps,ts);\n  sort(vt.begin(),vt.end());\n  for(int i=0;i<n;i++) tie(fs[i],ps[i],ts[i])=vt[i];\n\n  vector<MaxConvexHullTrick<ll>> vh(x+1);\n\n  ll ans=0;\n  for(int i=0;i<n;i++){\n    for(int j=x;j>ts[i];j--){\n      if(vh[j-ts[i]].empty()) continue;\n      ll val=vh[j-ts[i]].queryMonotoneInc(fs[i])+ps[i]-fs[i]*fs[i];\n      vh[j].add(2*fs[i],val-fs[i]*fs[i]);\n      chmax(ans,val);\n    }\n    vh[ts[i]].add(2*fs[i],ps[i]-fs[i]*fs[i]);\n    chmax(ans,ps[i]);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2736.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2736\n// verification-helper: ERROR 1e-6\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../io/precision.cpp\"\n#include \"../../mincostflow/primaldual.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,p,s,t;\n  cin>>n>>m>>p>>s>>t;\n  s--;t--;\n  PrimalDual<int, int> G(n);\n  for(int i=0;i<m;i++){\n    int v,u,d,c;\n    cin>>v>>u>>d>>c;\n    v--;u--;\n    G.add_edge(v,u,c,d);\n  }\n\n  using D = double;\n  D ans=1e18;\n  D sum=0,cnt=0;\n  while(G.build(s,t,1)){\n    sum+=G.get_cost();\n    cnt+=1;\n    chmin(ans,(sum+p)/cnt);\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2790.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2790\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../tree/centroid.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<int> gs(n);\n  for(int i=0;i<n;i++) cin>>gs[i];\n  using P = pair<int, int>;\n  vector< vector<P> > G(n);\n  Centroid C(n);\n  for(int i=1;i<n;i++){\n    int a,b,d;\n    cin>>a>>b>>d;\n    a--;b--;\n    G[a].emplace_back(b,d);\n    G[b].emplace_back(a,d);\n    C.add_edge(a,b);\n  }\n\n  int ans=1;\n  queue<int> que;\n  que.emplace(0);\n  while(!que.empty()){\n    int rt=C.build(que.front())[0];\n    que.pop();\n    for(int uku=0;uku<2;uku++){\n      int len=0;\n      MFP([&](auto dfs,int v,int p,int d)->void{\n            chmax(len,d);\n            for(auto e:G[v]){\n              int u=e.first;\n              if(u==p||!C.alive(u)) continue;\n              dfs(u,v,d+1);\n            }\n          })(rt,-1,1);\n\n      const int INF = 1e9;\n      vector<int> dat(len+1,INF);\n      dat[0]=-INF;\n      for(auto e:G[rt]){\n        int ch=e.first,cost=e.second;\n        if(!C.alive(ch)) continue;\n        // calc path\n        MFP([&](auto dfs,int v,int p,int d,int sum,int val)->void{\n              if(val>=0) chmax(ans,d+1);\n              int k=--upper_bound(dat.begin(),dat.end(),val)-dat.begin();\n              if(k) chmax(ans,k+1+d);\n              for(auto e:G[v]){\n                int u=e.first,c=e.second;\n                if(u==p||!C.alive(u)) continue;\n                dfs(u,v,d+1,sum-c+gs[u],min(val,sum-c));\n              }\n            })(ch,rt,1,gs[rt]-cost+gs[ch],gs[rt]-cost);\n\n        // update dat\n        MFP([&](auto dfs,int v,int p,int d,int sum,int val)->void{\n              if(val>=0){\n                chmin(dat[d],-sum);\n                chmax(ans,d+1);\n              }\n              for(auto e:G[v]){\n                int u=e.first,c=e.second;\n                if(u==p||!C.alive(u)) continue;\n                dfs(u,v,d+1,sum+(gs[u]-c),(val>0?0:val)+(gs[u]-c));\n              }\n              chmin(dat[d],dat[d+1]);\n            })(ch,rt,1,gs[ch]-cost,gs[ch]-cost);\n      }\n\n      reverse(G[rt].begin(),G[rt].end());\n    }\n    C.disable(rt);\n    for(int u:C.G[rt])\n      if(C.alive(u)) que.emplace(u);\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2842.BIT2D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2842\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/BIT2D.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int h,w,t,q;\n  cin>>h>>w>>t>>q;\n  BIT2D<int> beet(h+100,w+100);\n  BIT2D<int> ushi(h+100,w+100);\n  using P = pair<int, int>;\n  using PP = pair<int, P>;\n  queue<PP> qq;\n  for(int i=0;i<q;i++){\n    int a,c,x1,y1;\n    cin>>a>>c>>x1>>y1;\n    while(!qq.empty()&&qq.front().first<=a){\n      P p=qq.front().second;qq.pop();\n      int x=p.first,y=p.second;\n      assert(beet.sum(x-1,y-1,x,y)==1);\n      beet.add(x,y,-1);\n      assert(ushi.sum(x-1,y-1,x,y)==0);\n      ushi.add(x,y,1);\n    }\n    if(c==0){\n      assert(beet.sum(x1-1,y1-1,x1,y1)==0);\n      beet.add(x1,y1,1);\n      qq.push(PP(a+t,P(x1,y1)));\n    }\n    if(c==1){\n      if(ushi.sum(x1-1,y1-1,x1,y1)==0) continue;\n      ushi.add(x1,y1,-1);\n    }\n    if(c==2){\n      int x2,y2;\n      cin>>x2>>y2;\n      x1--;y1--;\n      cout<<ushi.sum(x1,y1,x2,y2)<<\" \"<<beet.sum(x1,y1,x2,y2)<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2842.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2842\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/count/dynamic_offline.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  int h,w,t,q;\n  cin>>h>>w>>t>>q;\n\n  RangeCount<int, int> beet(h),ushi(h);\n\n  vector<int> ts(q),cs(q);\n  vector<int> y1(q),x1(q),y2(q),x2(q);\n\n  for(int i=0;i<q;i++){\n    cin>>ts[i]>>cs[i]>>y1[i]>>x1[i];\n    y1[i]--;x1[i]--;\n\n    if(cs[i]==0||cs[i]==1){\n      beet.preupdate(y1[i],x1[i]);\n      ushi.preupdate(y1[i],x1[i]);\n    }\n\n    if(cs[i]==2) cin>>y2[i]>>x2[i];\n  }\n  beet.build();\n  ushi.build();\n\n  using P = pair<int, int>;\n  queue<P> que;\n\n  for(int i=0;i<q;i++){\n    while(!que.empty()&&que.front().first<=ts[i]){\n      int k=que.front().second;que.pop();\n      beet.update(y1[k],x1[k],-1);\n      ushi.update(y1[k],x1[k],+1);\n    }\n    if(cs[i]==0){\n      beet.update(y1[i],x1[i],+1);\n      que.emplace(ts[i]+t,i);\n    }\n    if(cs[i]==1){\n      if(ushi.query(y1[i],y1[i]+1,x1[i],x1[i]+1)==0) continue;\n      ushi.update(y1[i],x1[i],-1);\n    }\n    if(cs[i]==2){\n      cout<<ushi.query(y1[i],y2[i],x1[i],x2[i])<<\" \";\n      cout<<beet.query(y1[i],y2[i],x1[i],x2[i])<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2871.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2871\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/eulertourforvertex.cpp\"\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  EulerTourForVertex et(n);\n  for(int i=1;i<n;i++){\n    int p;\n    cin>>p;\n    p--;\n    et.add_edge(p,i);\n  }\n  et.build();\n\n  vector<char> cs(n);\n  for(int i=0;i<n;i++) cin>>cs[i];\n\n  struct T{\n    int sum,one;\n    T(int sum,int one):sum(sum),one(one){}\n  };\n  using E = int;\n  auto f=[](T a,T b){return T(a.sum+b.sum,a.one+b.one);};\n  auto g=[](T a,E b){return T(a.sum,b?a.sum-a.one:a.one);};\n  auto h=[](E a,E b){return a^b;};\n  T ti(0,0);\n  E ei(0);\n\n  SegmentTree<T, E> seg(f,g,h,ti,ei);\n  vector<T> vs(n,ti);\n  for(int i=0;i<n;i++) vs[et.idx(i)]=T(1,cs[i]=='G');\n  seg.build(vs);\n\n  for(int i=0;i<q;i++){\n    int v;\n    cin>>v;\n    v--;\n    et.exec(v,[&](int l,int r){seg.update(l,r,1);});\n    auto res=seg.query(0,n);\n    cout<<(res.sum-res.one<res.one?\"broccoli\":\"cauliflower\")<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2872.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2872\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bflow/capacityscaling.cpp\"\n#include \"../../graph/bellmanford.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  const ll INF = 1<<30;\n\n  int n,m,s,t;\n  cin>>n>>m>>s>>t;\n  s--;t--;\n  MaxGainFlow<ll, ll> G(n);\n  BellmanFord<int> H(n);\n  for(int i=0;i<m;i++){\n    int u,v,d,c;\n    cin>>u>>v>>d>>c;\n    u--;v--;\n    G.add_edge(u,v,0,c,-d);\n    H.add_edge(u,v,d);\n  }\n  int neg_loop;\n  int len=H.shortest_path(s,t,neg_loop);\n  assert(!neg_loop);\n  G.add_edge(t,s,0,INF,len+1);\n\n  assert(G.build());\n  cout<<G.get_gain()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2890.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2890\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/array.cpp\"\n#include \"../../bbst/rbst/impl/basic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  using Data = Array<int>;\n  using Node = Data::Node;\n  const int LIM = 1e6;\n  Basic<Data, LIM> as;\n\n  Node* rt=nullptr;\n  vector<Node*> vs(n+1);\n  for(int i=0;i<n;i++){\n    int a;\n    cin>>a;\n    a--;\n    vs[a]=as.create(a+1);\n    rt=as.merge(rt,vs[a]);\n  }\n\n  for(int i=0;i<q;i++){\n    int p;\n    cin>>p;\n    p--;\n    int k=as.order_of_key(vs[p]);\n    auto s=as.split(rt,k);\n    auto t=as.split(s.second,1);\n    rt=as.merge(as.merge(t.second,t.first),s.first);\n  }\n\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<as.get_val(rt,i);\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2891.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2891\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/cycle.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  UndirectedCycle G(n);\n  for(int i=0;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    G.add_edge(u,v);\n  }\n\n  auto vs=G.build();\n  unordered_set<int> namori(vs.begin(),vs.end());\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    cout<<1+(namori.count(a) and namori.count(b))<<'\\n';\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2934.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2934\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/manacher.cpp\"\n#include \"../../tools/drop.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n;\n  cin>>n;\n  string t;\n  cin>>t;\n\n  auto ms=manacher(t);\n  for(int l=2;l<=n;l++){\n    int flg=1;\n    for(int i=l-1;i<n;i+=l-1)\n      flg&=ms[i]==min(i+1,n-i);\n    if(flg) drop(l);\n  }\n\n  assert(0);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2948.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2948\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/independentset.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  while(cin>>n>>m,n){\n    vector< vector<int> > as(n,vector<int>(m));\n    for(int i=0;i<n;i++)\n      for(int j=0;j<m;j++)\n        cin>>as[i][j];\n\n    IndependentSet G(m);\n    for(int a=0;a<m;a++){\n      for(int b=0;b<a;b++){\n        int ng=0;\n        for(int i=0;i<n;i++){\n          for(int j=0;j<i;j++){\n            if(as[i][a]==as[j][a]) continue;\n            if(as[i][b]==as[j][b]) continue;\n            if((as[i][a]>as[j][a])^(as[i][b]>as[j][b])) ng=1;\n            if(ng) break;\n          }\n          if(ng) break;\n        }\n\n        if(ng) G.add_edge(a,b);\n      }\n    }\n\n    cout<<G.build()<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2951.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2951\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../polynomial/lagrangeinterpolation.cpp\"\n#undef call_from_test\n\nusing M = Mint<int>;\nconst int MAX = 6060;\nM dp[2020][MAX]={};\nM ad[2020][MAX]={};\n\nsigned main(){\n  int n,m;\n  while(cin>>n>>m,n||m){\n    vector<int> as(m),bs(m),cs(m);\n    vector< vector<int> > G(n+1);\n    for(int i=0;i<m;i++){\n      cin>>as[i]>>bs[i]>>cs[i];\n      G[as[i]].emplace_back(i);\n    }\n    as.emplace_back(0);\n    bs.emplace_back(1);\n    cs.emplace_back(0);\n    G[0].emplace_back(m);\n\n    dp[0][0]=M(1);\n    for(int v=0;v<=n;v++){\n      for(int j=0;j<MAX;j++){\n        if(j) ad[v][j]+=ad[v][j-1];\n        dp[v][j]+=ad[v][j];\n      }\n\n      for(int i:G[v])\n        for(int j=0;j+cs[i]<MAX;j++)\n          ad[bs[i]][j+cs[i]]+=dp[as[i]][j];\n    }\n\n    int q;\n    cin>>q;\n    for(int i=0;i<q;i++){\n      int d,e;\n      cin>>d>>e;\n      vector<M> ys(dp[d]+n+n,dp[d]+n+n+n+1);\n      if(e<n+n+n) cout<<dp[d][e]<<\"\\n\";\n      else cout<<lagrange_interpolation(ys,M(e-n-n))<<\"\\n\";\n    }\n\n    for(int v=0;v<=n;v++)\n      for(int j=0;j<MAX;j++)\n        dp[v][j]=ad[v][j]=M(0);\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2959.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2959\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#undef call_from_test\n\nNTT<2> ntt;\nusing M = Mint<int, ntt.md>;\nvector<M> res;\n\nvoid dfs(vector<int> &as,vector<int> &bs,int l,int r){\n  if(r-l==1) return;\n  int m=(l+r)>>1;\n  vector<int> cs(m-l);\n  vector<int> ds(r-m);\n  for(int i=l;i<m;i++) cs[i-l]=as[i];\n  for(int i=m;i<r;i++) ds[i-m]=bs[i];\n  auto es=ntt.multiply(cs,ds);\n  for(int i=0;i<(int)es.size();i++)\n    res[l+m+i]+=M(es[i]);\n  dfs(as,bs,l,m);\n  dfs(as,bs,m,r);\n}\n\nsigned main(){\n  string s;\n  cin>>s;\n  int n=s.size();\n  vector<int> us(n),gs(n),qs(n);\n  int num=0;\n  for(int i=0;i<n;i++){\n    us[i]=s[i]=='U';\n    gs[i]=s[i]=='G';\n    qs[i]=s[i]=='?';\n\n    num+=qs[i];\n  }\n\n  M ans{0};\n  // U (M / ?) G\n  {\n    res.assign(2*n,0);\n    dfs(us,gs,0,n);\n    for(int i=0;i<n;i++){\n      if(s[i]=='M'){\n        ans+=res[i*2]*M(3).pow(num);\n      }\n      if(s[i]=='?'){\n        ans+=res[i*2]*M(3).pow(num-1);\n      }\n    }\n  }\n  // ? (M / ?) G\n  {\n    res.assign(2*n,0);\n    dfs(qs,gs,0,n);\n    for(int i=0;i<n;i++){\n      if(s[i]=='M'){\n        if(num>=1)\n          ans+=res[i*2]*M(3).pow(num-1);\n      }\n      if(s[i]=='?'){\n        if(num>=2)\n          ans+=res[i*2]*M(3).pow(num-2);\n      }\n    }\n  }\n\n  // U (M / ?) ?\n  {\n    res.assign(2*n,0);\n    dfs(us,qs,0,n);\n    for(int i=0;i<n;i++){\n      if(s[i]=='M'){\n        if(num>=1)\n          ans+=res[i*2]*M(3).pow(num-1);\n      }\n      if(s[i]=='?'){\n        if(num>=2)\n          ans+=res[i*2]*M(3).pow(num-2);\n      }\n    }\n  }\n\n  // ? (M / ?) ?\n  {\n    res.assign(2*n,0);\n    dfs(qs,qs,0,n);\n    for(int i=0;i<n;i++){\n      if(s[i]=='M'){\n        if(num>=2)\n          ans+=res[i*2]*M(3).pow(num-2);\n      }\n      if(s[i]=='?'){\n        if(num>=3)\n          ans+=res[i*2]*M(3).pow(num-3);\n      }\n    }\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2968.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2968\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../math/factorize.cpp\"\n#include \"../../vector/compress.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  auto as=read(n);\n\n  vector<int> ps;\n  for(auto a:as)\n    for(auto[p,_]:factorize(a))\n      ps.emplace_back(p);\n\n  long long ans=0;\n  for(int p:compress(ps)){\n    long long res=0;\n    for(int a:as)\n      if(a%p==0) res+=a;\n    chmax(ans,res);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2969.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2969\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../segtree/basic/ushi.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../vector/fusion.cpp\"\n#include \"../../vector/near.cpp\"\n#include \"../../vector/sorted.cpp\"\n#include \"../../vector/zip.cpp\"\n#undef call_from_test\n\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n;\n  ll lim;\n  cin>>n>>lim;\n  vector<ll> ls(n),rs(n);\n  for(int i=0;i<n;i++) cin>>ls[i]>>rs[i];\n\n  auto dc=dict(compress(fusion(near(ls,0,1),near(rs,-1,0))));\n  int m=dc.size();\n\n  auto f=[&](int a,int b){return min(a,b);};\n  SegmentTree<int> seg(f,n+3);\n  seg.build(vector<int>(m,n+2));\n  seg.set_val(dc[0],0);\n\n  int res=n;\n  for(auto[r,l]:sorted(zip(rs,ls))){\n    int val=seg.query(dc[l],dc[r])+1;\n    chmin(val,seg.query(dc[r],dc[r]+1));\n    seg.set_val(dc[r],val);\n    if(r==lim) chmin(res,val);\n  }\n  cout<<res<<' ';\n\n  vector<int> sm(m,0);\n  for(int i=0;i<n;i++){\n    sm[dc[ls[i]]]++;\n    sm[dc[rs[i]]]--;\n  }\n  for(int i=0;i+1<m;i++) sm[i+1]+=sm[i];\n\n  cout<<n-*min_element(sm.begin()+dc[0],sm.begin()+dc[lim])+1<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2970.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2970\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/drop.cpp\"\n#include \"../../math/extgcd.cpp\"\n#include \"../../mod/inverse.cpp\"\n#include \"../../math/linearcongruence.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<int> ps(n),qs(n);\n  for(int i=0;i<n;i++) cin>>ps[i],ps[i]--;\n  for(int i=0;i<n;i++) cin>>qs[i],qs[i]--;\n\n  using ll = long long;\n  vector<ll> A,B,M;\n\n  vector<int> used(n,0);\n  for(int i=0;i<n;i++){\n    if(used[i]) continue;\n    int pos=i;\n    vector<int> vs,ws;\n    while(!used[pos]){\n      vs.emplace_back(pos);\n      ws.emplace_back(ps[pos]);\n      used[pos]=1;\n      pos=qs[pos];\n    }\n    {\n      auto as=vs,bs=ws;\n      sort(as.begin(),as.end());\n      sort(bs.begin(),bs.end());\n      if(as!=bs) drop(-1);\n    }\n\n    int m=vs.size();\n    for(int j=0;j<m;j++)\n      ws.emplace_back(int(ws[j]));\n\n    for(int j=0;j<m;j++){\n      if(ws[j]!=vs[0]) continue;\n      for(int k=0;k<m;k++)\n        if(ws[j+k]!=vs[k]) drop(-1);\n\n      A.emplace_back(1);\n      B.emplace_back(j);\n      M.emplace_back(m);\n    }\n  }\n\n  auto res=linear_congruence(A,B,M);\n  if(res.second<0) drop(-1);\n  cout<<res.first<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2971.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2971\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/drop.cpp\"\n#include \"../../mod/mint.cpp\"\n#include \"../../polynomial/hash.cpp\"\n#undef call_from_test\n\nconst int MOD1 = 1e9+7;\nconst int MOD2 = 1e9+9;\nconst int MOD3 = 1e9+21;\n\nusing M1 = Mint<int, MOD1>;\nusing M2 = Mint<int, MOD2>;\nusing M3 = Mint<int, MOD3>;\n\nusing PH = PolynomialHash<int, M1, M2, M3>;\nPH ph(1);\n\nconst int MAX = 1e5+100;\nint used[MAX]={};\nvector<PH::V> vs(MAX,0);\n\nusing P = pair<int, int>;\nvector<P> G[MAX],R[MAX];\n\ntemplate<typename T> void check(T x,T y){if(x!=y) drop(\"No\");};\n\nvoid dfs(int v){\n  for(auto e:G[v]){\n    int u=e.first,x=e.second;\n    if(used[u]) continue;\n    used[u]=1;\n    vs[u]=vs[v]*PH::V(x);\n    dfs(u);\n  }\n  for(auto e:R[v]){\n    int u=e.first,x=e.second;\n    if(used[u]) continue;\n    used[u]=1;\n    vs[u]=vs[v]/PH::V(x);\n    dfs(u);\n  }\n\n  for(auto e:G[v]){\n    int u=e.first,x=e.second;\n    check(vs[u],vs[v]*PH::V(x));\n  }\n  for(auto e:R[v]){\n    int u=e.first,x=e.second;\n    check(vs[u],vs[v]/PH::V(x));\n  }\n}\n\nsigned main(){\n  int n,m;\n  cin>>n>>m;\n\n  for(int i=0;i<m;i++){\n    int a,b,x;\n    cin>>a>>b>>x;\n    a--;b--;\n    G[a].emplace_back(b,x);\n    R[b].emplace_back(a,x);\n  }\n\n  for(int i=0;i<n;i++){\n    if(used[i]) continue;\n    vs[i]=PH::V(1);\n    dfs(i);\n  }\n\n  cout<<\"Yes\"<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2975.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2975\n// verification-helper: ERROR 1e-9\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/precision.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../convexhulltrick/convexhulltrick.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  int zx,zv;\n  cin>>zx>>zv;\n\n  vector<int> xs(n),vs(n);\n  for(int i=0;i<n;i++) cin>>xs[i]>>vs[i];\n\n  for(int i=0;i<n;i++){\n    xs[i]-=zx;\n    vs[i]-=zv;\n  }\n\n  using D = double;\n  const D INF = 1e10;\n  vector<D> ans(n,INF);\n  for(int i=0;i<n;i++){\n    if(xs[i]==0) ans[i]=0;\n    if((D)xs[i]*(D)vs[i]<0) chmin(ans[i],-(D)xs[i]/(D)vs[i]);\n  }\n\n  for(int uku=0;uku<2;uku++){\n    for(int i=0;i<n;i++){\n      xs[i]*=-1;\n      vs[i]*=-1;\n    }\n\n    using P = pair<D, D>;\n    vector<P> vp;\n    int sp=0;\n    for(int i=0;i<n;i++){\n      if(xs[i]>=0) continue;\n      if(vs[i]<=0) continue;\n      vp.emplace_back(vs[i],xs[i]);\n      chmax(sp,vs[i]);\n    }\n    if(vp.empty()) continue;\n\n    sort(vp.begin(),vp.end());\n    MaxConvexHullTrick<D> cht;\n    for(auto p:vp) cht.add(p.first,p.second);\n\n    for(int i=0;i<n;i++){\n      if(xs[i]<=0) continue;\n      if(sp<=vs[i]) continue;\n      D L=0,R=INF;\n      for(int k=0;k<80;k++){\n        D M=(L+R)/2;\n        if(cht.query(M)>=(D)vs[i]*M+(D)xs[i]) R=M;\n        else L=M;\n      }\n      chmin(ans[i],R);\n    }\n  }\n\n  for(int i=0;i<n;i++){\n    if(ans[i]>=INF) cout<<-1<<\"\\n\";\n    else cout<<ans[i]<<\"\\n\";\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2977.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2977\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../convolution/convolution2D.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,k,l;\n  cin>>n>>m>>k>>l;\n  vector<string> bs(n);\n  for(int i=0;i<n;i++) cin>>bs[i];\n\n  string s;\n  cin>>s;\n\n  NTT<0> ntt;\n  using M = NTT<0>::M;\n  auto tran=[&](auto &as,bool f){ntt.ntt(as,f);};\n  Convolution2D<M, decltype(tran)> conv(tran);\n\n  using Matrix=Convolution2D<M, decltype(tran)>::Matrix;\n\n  Matrix A(n,vector<M>(n,0));\n  for(int i=0;i<n;i++)\n    for(int j=0;j<n;j++)\n      A[i][j]=M(bs[i][j]=='X');\n\n  Matrix B(m-n+1,vector<M>(m-n+1,0));\n  int cy=0,cx=0;\n  for(int i=0;i<l;i++){\n    if(s[i]=='L') cx--;\n    if(s[i]=='R') cx++;\n    if(s[i]=='U') cy--;\n    if(s[i]=='D') cy++;\n\n    B[cy][cx]+=M(1);\n  }\n\n  auto C=conv.multiply(A,B);\n  int ans=0;\n  for(int i=0;i<m;i++)\n    for(int j=0;j<m;j++)\n      if(C[i][j].v>=k) ans++;\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2979.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2979\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../maxflow/dinic.cpp\"\n#include \"../../maxflow/twocommodity.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,s,t,u,v;\n  cin>>n>>m>>s>>t>>u>>v;\n  s--;t--;u--;v--;\n\n  TwoCommodity<int, false> G(n);\n  for(int i=0;i<m;i++){\n    int x,y;\n    cin>>x>>y;\n    x--;y--;\n    G.add_edge(x,y,1);\n  }\n\n  cout<<G.build(s,t,u,v)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2981.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2981\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../tools/drop.cpp\"\n#include \"../../convolution/bitwise/fwht.cpp\"\n#include \"../../convolution/bitwise/and.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  int sz=1<<n;\n  auto as=read(sz);\n\n  auto dp(as);\n  fwht(dp,bitwise_and::zeta);\n\n  for(int i=0;i<sz;i++){\n    if(!as[i]) continue;\n    if(dp[i]!=(1<<(n-__builtin_popcount(i)))) drop(-1);\n  }\n\n  auto bs(as);\n  for(int i=1;i<sz;i<<=1)\n    for(int j=0;j<sz;j++)\n      if(i&j) if(as[i^j]) bs[j]=0;\n\n  cout<<accumulate(bs.begin(),bs.end(),0)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2983.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2983\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../matching/tutte.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  vector< vector<int> > L(m);\n  for(int i=0;i<m;i++){\n    int k;\n    cin>>k;\n    L[i].resize(k);\n    for(int j=0;j<k;j++) cin>>L[i][j],L[i][j]--;\n  }\n\n  vector< vector<int> > G(n);\n  for(int i=0;i<m;i++)\n    for(int v:L[i]) G[v].emplace_back(i);\n\n  int taken=0;\n  vector<int> dead(m,0);\n  for(int i=0;i<n;i++){\n    if(G[i].size()<=1u){\n      int flg=0;\n      for(int g:G[i]) if(dead[g]) flg=1;\n      if(flg) continue;\n      taken++;\n      for(int g:G[i]) dead[g]=1;\n    }\n  }\n\n  vector< vector<int> > H(m);\n  for(int i=0;i<n;i++){\n    if(G[i].size()<=1u) continue;\n    int x=G[i][0];\n    int y=G[i][1];\n    if(dead[x]||dead[y]) continue;\n    H[x].emplace_back(y);\n    H[y].emplace_back(x);\n  }\n\n  int ans=taken+maximal_matching(H);\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2985.garner.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2985\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../convolution/garner.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/diff.cpp\"\n#include \"../../formalpowerseries/integral.cpp\"\n#include \"../../formalpowerseries/log.cpp\"\n#include \"../../formalpowerseries/exp.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using M = Mint<int>;\n  Garner arb;\n  auto conv=[&](auto as,auto bs){return arb.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  vector<M> line(n+1,0),quad(n+1,0);\n  for(int i=1;i<=n;i++){\n    line[i]=M(i).pow(0);\n    quad[i]=M(i).pow(1);\n  }\n\n  M v1=FPS.exp(line,n+1)[n];\n  M v2=FPS.exp(quad,n+1)[n];\n\n  M ans=v2-v1*v1;\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2985.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2985\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/fastfouriertransform.cpp\"\n#include \"../../convolution/arbitrarymod.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/diff.cpp\"\n#include \"../../formalpowerseries/integral.cpp\"\n#include \"../../formalpowerseries/log.cpp\"\n#include \"../../formalpowerseries/exp.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using M = Mint<int>;\n  ArbitraryMod<M> arb;\n  auto conv=[&](auto as,auto bs){return arb.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  vector<M> line(n+1,0),quad(n+1,0);\n  for(int i=1;i<=n;i++){\n    line[i]=M(i).pow(0);\n    quad[i]=M(i).pow(1);\n  }\n\n  M v1=FPS.exp(line,n+1)[n];\n  M v2=FPS.exp(quad,n+1)[n];\n\n  M ans=v2-v1*v1;\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/2995.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2995\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/unionfind.cpp\"\n#include \"../../tree/sack.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,k;\n  cin>>n>>k;\n\n  vector<int> us(n),vs(n),cs(n),ds(n);\n  for(int i=1;i<n;i++) cin>>us[i]>>vs[i];\n  for(int i=0;i<n;i++) cin>>cs[i]>>ds[i];\n\n  int num=0;\n  vector<int> cnt(k,0);\n  UnionFind uf(k);\n\n  auto calc=[&](int c){return min(cnt[c],uf.size(c));};\n  auto expand=[&](int v){\n    int c=uf.find(cs[v]);\n    int d=uf.find(ds[v]);\n    int flg=uf.same(c,d);\n    if(flg){\n      num-=calc(c);\n\n      uf.unite(c,d);\n      cnt[c]++;\n\n      num+=calc(c);\n    }else{\n      num-=calc(c)+calc(d);\n\n      uf.unite(c,d);\n      if(uf.find(c)!=c) swap(c,d);\n      cnt[c]+=cnt[d]+1;\n\n      num+=calc(c);\n    }\n  };\n\n  auto shrink=[&](int v){\n    num=0;\n    cnt[cs[v]]=cnt[ds[v]]=0;\n    uf.ps[cs[v]]=cs[v];\n    uf.ps[ds[v]]=ds[v];\n    uf.rs[cs[v]]=uf.rs[ds[v]]=1;\n  };\n\n  vector<int> ans(n);\n  auto query=[&](int v){ans[v]=num;};\n  Sack S(n,expand,shrink,query);\n\n  for(int i=1;i<n;i++){\n    us[i]--;vs[i]--;\n    S.add_edge(us[i],vs[i]);\n  }\n\n  for(int i=0;i<n;i++){\n    cs[i]--,ds[i]--;\n    S.add_query(i,i);\n  }\n\n  S.build();\n  for(int i=0;i<n;i++) cout<<ans[i]<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3024.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3024\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/persistent/ushi.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<int> as(n),bs(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n  for(int i=0;i<n;i++) cin>>bs[i];\n\n  auto f=[](int a,int b){return min(a,b);};\n  int ti=INT_MAX;\n  SegmentTree<int> seg(f,ti);\n  auto ra=seg.build(as);\n  auto rb=seg.build(bs);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int x,y,z;\n    cin>>x>>y>>z;\n    y--;\n    if(x==1) ra=seg.set_val(ra,y,z);\n    if(x==2) rb=seg.set_val(rb,y,z);\n    if(x==3) cout<<seg.query(ra,y,z)<<\"\\n\";\n    if(x==4) cout<<seg.query(rb,y,z)<<\"\\n\";\n    if(x==5) ra=seg.clone(rb);\n    if(x==6) rb=seg.clone(ra);\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3033.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3033\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/suffixarray.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n;\n  ll k;\n  string s;\n  cin>>n>>k>>s;\n\n  auto calc=[](ll x){return x*(x+1)/2;};\n  ll zs=0;\n  vector<ll> cnt(n+1,1);\n  for(int i=0;i<n;i++){\n    if(s[i]=='0'){\n      if(i+1>=n||s[i+1]!='0') zs+=calc(cnt[i]);\n      if(i+1<n) cnt[i+1]+=cnt[i];\n      cnt[i]=0;\n    }\n  }\n\n  if(k<=zs){\n    cout<<0<<endl;\n    return 0;\n  }\n  k-=zs+1;\n\n  vector<ll> sum(n+1,0);\n  for(int i=0;i<n;i++) sum[i+1]=sum[i]+cnt[i];\n\n  int len=1;\n  while(k>=sum[n+1-len]&&len<n) k-=sum[n+1-(len++)];\n\n  SuffixArray sa(s);\n  int pos=0;\n  for(int i=1;i<=n;i++){\n    if(s[sa.sa[i]]=='0'||sa.sa[i]+len>n) continue;\n    if(k>=0) pos=sa.sa[i];\n    k-=cnt[sa.sa[i]];\n  }\n\n  cout<<s.substr(pos,len)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3035.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3035\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  struct T{\n    ll w,x,y,z;\n    T(ll w,ll x,ll y,ll z):w(w),x(x),y(y),z(z){}\n  };\n\n  auto f=\n    [](T a,T b){\n      ll cw=min(a.w,b.w);\n      ll cx=(a.w==b.w?a.x+b.x:(a.w<b.w?a.x:b.x));\n      ll cy=max(a.y,b.y);\n      ll cz=(a.y==b.y?a.z+b.z:(a.y>b.y?a.z:b.z));\n      return T(cw,cx,cy,cz);\n    };\n  auto g=\n    [](T a,ll b){\n      return T(a.w+b,a.x,a.y+b,a.z);\n    };\n  auto h=[](ll a,ll b){return a+b;};\n\n  int H,W,Q;\n  cin>>H>>W>>Q;\n  vector<T> A,B;\n  for(int i=0;i<H;i++){\n    int v;\n    cin>>v;\n    A.emplace_back(v,1,v,1);\n  }\n  for(int i=0;i<W;i++){\n    int v;\n    cin>>v;\n    B.emplace_back(v,1,v,1);\n  }\n\n  const ll INF = 1e17;\n  T ti(INF,0,-INF,0);\n  SegmentTree<T, ll> segY(f,g,h,ti,0);\n  SegmentTree<T, ll> segX(f,g,h,ti,0);\n  segY.build(A);\n  segX.build(B);\n\n  auto calc=\n    [](int t,T a,T b,ll p,ll q){\n      ll res=t==3?\n        min({a.w*b.w,a.w*b.y,a.y*b.w,a.y*b.y}):\n        max({a.w*b.w,a.w*b.y,a.y*b.w,a.y*b.y});\n      ll cnt=0;\n      ll n=p-(!a.w?a.x:!a.y?a.z:0ll);\n      ll m=q-(!b.w?b.x:!b.y?b.z:0ll);\n      if(res==0) cnt=p*q-n*m;\n      else{\n        if(a.w==a.y) a.z=0;\n        if(b.w==b.y) b.z=0;\n        if(res==a.w*b.w) cnt+=a.x*b.x;\n        if(res==a.w*b.y) cnt+=a.x*b.z;\n        if(res==a.y*b.w) cnt+=a.z*b.x;\n        if(res==a.y*b.y) cnt+=a.z*b.z;\n      }\n      cout<<res<<\" \"<<cnt<<\"\\n\";\n    };\n\n  for(int i=0;i<Q;i++){\n    int t;\n    cin>>t;\n    if(t==1){\n      int a,b,v;\n      cin>>a>>b>>v;\n      segY.update(--a,b,v);\n    }\n    if(t==2){\n      int c,d,v;\n      cin>>c>>d>>v;\n      segX.update(--c,d,v);\n    }\n    if(t==3||t==4){\n      int a,b,c,d;\n      cin>>a>>b>>c>>d;\n      T y=segY.query(--a,b);\n      T x=segX.query(--c,d);\n      calc(t,y,x,b-a,d-c);\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3037.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3037\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../toptree/toptree.cpp\"\n#undef call_from_test\n\nusing ll = long long;\nstruct Vertex{\n  void* handle;\n  ll val;\n  Vertex(ll val=0):handle(nullptr),val(val){}\n};\n\nstruct Cluster{\n  ll sm,md,chd,ma;\n  Cluster():sm(0),md(0),chd(0),ma(0){}\n  void toggle(){}\n  static Cluster compress(Cluster x,Vertex *v,Cluster y){\n    Cluster z;\n    z.sm=x.sm+(v->val)+y.sm;\n    z.md=max({x.md,x.chd,y.md});\n    z.ma=x.sm+(v->val)+y.sm;\n    return z;\n  }\n  static Cluster rake(Cluster x,Cluster y){\n    x.sm+=y.sm;\n    x.chd=max({x.chd,y.chd,y.ma});\n    return x;\n  }\n};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n;\n  cin>>n;\n  vector<int> ws(n);\n  for(int i=0;i<n;i++) cin>>ws[i];\n\n  const size_t N = 1e5 + 10;\n  TopTree<Vertex, Cluster, N> G;\n\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++) vs[i]=G.create(ws[i]);\n\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    G.link(vs[u],Cluster(),vs[v]);\n  }\n\n  Vertex* da=G.create(0);\n  Vertex* db=G.create(0);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n\n    G.link(da,Cluster(),vs[a]);\n    G.link(db,Cluster(),vs[b]);\n\n    cout<<G.get_path(da,db).md<<newl;\n\n    G.cut(da,vs[a]);\n    G.cut(db,vs[b]);\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3047.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3047\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../maxflow/dinic.cpp\"\n#undef call_from_test\n\nconst int K = 28;\nint cap[K][K];\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<string> s(n);\n  for(int i=0;i<n;i++) cin>>s[i];\n\n  for(int i=0;i<26;i++){\n    memset(cap,0,sizeof(cap));\n\n    int x=26,y=27,z=0,e=0;\n    Dinic<int, true> G(K);\n\n    for(int j=0;j<n;j++){\n      int u=s[j].front()-'a';\n      int v=s[j].back()-'a';\n      if(u==i) z++;\n      if(v==i) e++;\n      if(u==i) u=x;\n      if(v==i) v=y;\n      if(u!=v) cap[u][v]++;\n    }\n\n    for(int u=0;u<K;u++)\n      for(int v=0;v<K;v++)\n        if(cap[u][v]) G.add_edge(u,v,cap[u][v]);\n\n    if((e&&!z)||(z&&G.flow(x,y)==z)) cout<<char('a'+i)<<endl;\n  }\n\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3053.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3053\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/all_permutations.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  string s;\n  cin>>n>>s;\n\n  int c[10][10]={};\n  for(int i=0;i+1<n;i++){\n    int a=s[i]-'0',b=s[i+1]-'0';\n    c[a][b]++;\n  }\n\n  int ans=n*100;\n  vector<int> us;\n  auto f=\n    [&](auto vs){\n      int x[10],y[10];\n      for(int i=0;i<9;i++){\n        x[vs[i]+1]=i%3;\n        y[vs[i]+1]=i/3;\n      }\n\n      int res=0;\n      for(int i=1;i<=9;i++)\n        for(int j=1;j<=9;j++)\n          res+=c[i][j]*(abs(x[i]-x[j])+abs(y[i]-y[j]));\n\n      if(res<ans) ans=res,us=vs;\n    };\n  all_permutations(9,f);\n\n  for(int i=0;i<9;i++){\n    cout<<us[i]+1;\n    if(i%3==2) cout<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3058.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3058\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../maxflow/dinic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,m;\n  cin>>n>>m;\n  string s;\n  cin>>s;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  int S=n,T=n+1;\n  Dinic<int, true> G(n+2);\n\n  for(int i=0;i<m;i++){\n    int x,y,z;\n    cin>>x>>y>>z;\n    x--;y--;\n    if(x>y) swap(x,y);\n    G.add_edge(x,y,z);\n  }\n\n  for(int i=0;i<n;i++){\n    if(s[i]=='R') G.add_edge(S,i,as[i]);\n    if(s[i]=='L') G.add_edge(i,T,as[i]);\n  }\n\n  cout<<G.flow(S,T)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3062.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3062\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/pow.cpp\"\n#include \"../../mod/order.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int MOD;\n  cin>>MOD;\n\n  int T;\n  cin>>T;\n  while(T--){\n    int n;\n    cin>>n;\n\n    vector<int> gs(n);\n    for(int i=0;i<n;i++) cin>>gs[i];\n\n    int a;\n    cin>>a;\n\n    if(a==1){\n      cout<<1<<newl;\n      continue;\n    }\n\n    if(gs==vector<int>(n,1)){\n      cout<<0<<newl;\n      continue;\n    }\n    sort(gs.rbegin(),gs.rend());\n    while(gs.back()==1) gs.pop_back();\n\n    using ll = long long;\n    int res=order<ll>(gs[0],MOD);\n    for(int x:gs) res=lcm(res,order<ll>(x,MOD));\n\n    cout<<(res%order<ll>(a,MOD)==0?1:0)<<newl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3063.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3063\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/suffixarray.cpp\"\n#include \"../../string/longestcommonprefix.cpp\"\n#include \"../../datastructure/waveletmatrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  string s;\n  cin>>s;\n\n  LongestCommonPrefix lcp(s);\n  auto vs=lcp.sa.sa;\n  auto rev=lcp.sa.rev;\n  using WM = WaveletMatrix<int, 18>;\n  WM wm(vs);\n\n  auto calc=\n    [&](int a,int b)->int{\n      auto check=\n        [&](int x)->int{\n          int p=b-x;\n          int pos=rev[p];\n          int ll=-1,rr=-1;\n          {\n            int l=-1,r=pos;\n            while(l+1<r){\n              int m=(l+r)>>1;\n              if(vs[m]+x<=n&&lcp.lcp(vs[m],p)>=x) r=m;\n              else l=m;\n            }\n            ll=r;\n          }\n          {\n            int l=pos,r=n+1;\n            while(l+1<r){\n              int m=(l+r)>>1;\n              if(vs[m]+x<=n&&lcp.lcp(vs[m],p)>=x) l=m;\n              else r=m;\n            }\n            rr=r;\n          }\n          // [ll, rr)\n          int q=wm.pred(ll,rr,p-x);\n          if(q==WM::npos||q-x<0) return 0;\n          int k=wm.pred(ll,rr,q-x);\n          if(k==WM::npos) return 0;\n          return a<k;\n        };\n\n      int l=0,r=(b-a+2)/3;\n      while(l+1<r){\n        int m=(l+r)>>1;\n        if(check(m)) l=m;\n        else r=m;\n      }\n      return l;\n    };\n\n  for(int i=0;i<q;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;\n    cout<<calc(a,b)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3069.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3069\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../convexhulltrick/linecontainer.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n,m,q;\n  cin>>n>>m>>q;\n\n  vector<ll> ds(n);\n  for(int i=0;i<n;i++) cin>>ds[i];\n  for(int i=0;i<n;i++) ds.emplace_back(int(ds[i]));\n  for(int i=0;i<n;i++) ds.emplace_back(int(ds[i]));\n\n  vector<ll> sm(n*3+1,0);\n  for(int i=0;i<n*3;i++) sm[i+1]=sm[i]+ds[i];\n\n  vector<char> cs(m);\n  vector<int> bs(m),ts(m);\n  for(int i=0;i<m;i++) cin>>cs[i]>>bs[i]>>ts[i],bs[i]--;\n\n  vector< vector<ll> > G(n*3);\n  vector<ll> xs(q),ys(q);\n  for(int i=0;i<q;i++){\n    cin>>xs[i]>>ys[i];\n    xs[i]--,ys[i]--;\n    xs[i]+=n,ys[i]+=n;\n    G[xs[i]].emplace_back(i);\n  }\n\n  const ll INF = 1e18;\n  vector<ll> R(n*3,INF),L(n*3,INF);\n  int exR=0,exL=0;\n  for(int i=0;i<m;i++){\n    if(cs[i]=='R'){\n      exR=1;\n      chmin(R[bs[i]+n*0],ts[i]);\n      chmin(R[bs[i]+n*1],ts[i]);\n      chmin(R[bs[i]+n*2],ts[i]);\n    }\n    if(cs[i]=='L'){\n      exL=1;\n      chmin(L[bs[i]+n*0],ts[i]);\n      chmin(L[bs[i]+n*1],ts[i]);\n      chmin(L[bs[i]+n*2],ts[i]);\n    }\n  }\n\n  vector<ll> ans(q,INF);\n\n  // use R\n  if(exR){\n    MinLineContainer<ll> cht;\n    for(int x=0;x<n*2;x++){\n      if(R[x]!=INF) cht.add(R[x],-R[x]*sm[x]);\n      for(int i:G[x]){\n        int y=ys[i];\n        if(x>y) y+=n;\n        chmin(ans[i],cht.query(sm[y]));\n      }\n    }\n  }\n\n  // use L\n  if(exL){\n    MinLineContainer<ll> cht;\n    for(int x=n*3-1;x>=n;x--){\n      if(L[x]!=INF) cht.add(-L[x],L[x]*sm[x]);\n      for(int i:G[x]){\n        int y=ys[i];\n        if(x<y) y-=n;\n        chmin(ans[i],cht.query(sm[y]));\n      }\n    }\n  }\n\n  for(int i=0;i<q;i++) cout<<ans[i]<<'\\n';\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3072.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3072\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  int n,k,p100;\n  cin>>n>>k>>p100;\n\n  M p=M(p100)/M(100);\n\n  vector<M> as({M(n)/p});\n  vector<M> bs(n+1,-p);\n  bs[0]=n;\n\n  auto cs=FPS.mul(as,FPS.inv(bs,k));\n\n  M ans{1};\n  for(int i=1;i<k;i++) ans-=M(cs[i])*(M(1)-p);\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3073.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3073\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/trie.cpp\"\n#include \"../../string/ahocorasick.cpp\"\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  string s;\n  cin>>s;\n  int n,q;\n  cin>>n>>q;\n\n  AhoCorasick<26, false> aho('a');\n  aho.add(s,0);\n  aho.build();\n\n  using A = array<int, 32>;\n  A ti,ei;\n  fill(ti.begin(),ti.end(),0);\n  iota(ei.begin(),ei.end(),0);\n  auto f=[&](A a,A b){\n    A c;\n    for(int i=0;i<(int)a.size();i++) c[i]=a[i]+b[i];\n    return c;\n  };\n  auto g=[&](A a,A b){\n    A c(ti);\n    for(int i=0;i<(int)a.size();i++) c[b[i]]+=a[i];\n    return c;\n  };\n  auto h=[&](A a,A b){\n    A c;\n    for(int i=0;i<(int)a.size();i++) c[i]=b[a[i]];\n    return c;\n  };\n\n  SegmentTree<A, A> seg(f,g,h,ti,ei);\n  vector<A> va(n,ti);\n  for(int i=0;i<n;i++) va[i][0]=1;\n  seg.build(va);\n\n  vector<A> mv(26);\n  for(int x=0;x<26;x++)\n    for(int i=0;i<(int)mv[x].size();i++)\n      mv[x][i]=(i<(int)aho.size()?aho.move(i,char('a'+x)):i);\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n\n    if(t==1){\n      int l,r;\n      string c;\n      cin>>l>>r>>c;\n      l--;\n      A a=ei;\n      for(char x:c) a=h(a,mv[x-'a']);\n      seg.update(l,r,a);\n    }\n\n    if(t==2){\n      int l,r;\n      cin>>l>>r;\n      l--;\n      A res=seg.query(l,r);\n      int ans=0;\n      for(int j=0;j<(int)res.size();j++)\n        if(j<(int)aho.size()&&aho.count(j)) ans+=res[j];\n      cout<<ans<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3074.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3074\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../convolution/convolution2D.cpp\"\n#include \"../../linearalgebra/squarematrix.cpp\"\n#undef call_from_test\n\nNTT<2> ntt;\nusing M = NTT<2>::M;\nauto tran=[](auto &as,bool f){ntt.ntt(as,f);};\nConvolution2D<M, decltype(tran)> conv(tran);\n\nstruct Ring{\n  vector<M> dat;\n  Ring(){};\n  Ring(vector<M> dat):dat(dat){};\n  static Ring add_identity();\n  static Ring mul_identity();\n  Ring operator*(const Ring &a)const{\n    auto res=Ring(dat);\n    for(int i=0;i<(int)dat.size();i++) res.dat[i]*=a.dat[i];\n    return res;\n  }\n  Ring operator+(const Ring &a)const{\n    auto res=Ring(dat);\n    for(int i=0;i<(int)dat.size();i++) res.dat[i]+=a.dat[i];\n    return res;\n  }\n};\n\nRing add_id, mul_id;\nRing Ring::add_identity(){return add_id;};\nRing Ring::mul_identity(){return mul_id;};\n\nsigned main(){\n  int h,w,k;\n  cin>>h>>w>>k;\n  h=1<<h;\n  w=1<<w;\n\n  vector< vector<int> > tt(h,vector<int>(w));\n  vector< vector<int> > gg(h,vector<int>(w));\n  for(int i=0;i<h;i++)\n    for(int j=0;j<w;j++)\n      cin>>tt[i][j];\n  for(int i=0;i<h;i++)\n    for(int j=0;j<w;j++)\n      cin>>gg[i][j];\n\n  using Matrix = vector< vector<M> >;\n  Matrix T(h,vector<M>(w));\n  Matrix G(h,vector<M>(w));\n  Matrix W(h,vector<M>(w));\n  Matrix H(h,vector<M>(w));\n  for(int i=0;i<h;i++){\n    for(int j=0;j<w;j++){\n      T[i][j]=tt[i][j]>=0?tt[i][j]:0;\n      G[i][j]=gg[i][j]>=0?gg[i][j]:0;\n      W[i][j]=tt[i][j]>=0?1:0;\n      H[i][j]=T[i][j]*G[i][j];\n    }\n  }\n\n  auto flatten=\n    [&](Matrix A){\n      conv.transform(A,false);\n      vector<M> dat(h*w);\n      for(int i=0;i<h*w;i++) dat[i]=A[i/w][i%w];\n      return Ring(dat);\n    };\n\n  {\n    Matrix id(h,vector<M>(w,M(0)));\n    add_id=flatten(id);\n    id[0][0]=1;\n    mul_id=flatten(id);\n  }\n\n  using SM = SquareMatrix<Ring, 4>;\n  SM P;\n  P[0][0]=flatten(W);\n  P[1][0]=flatten(T);P[1][1]=flatten(W);\n  P[2][0]=flatten(H);P[2][1]=flatten(G);P[2][2]=flatten(W);\n  P[3][0]=flatten(H);P[3][1]=flatten(G);P[3][2]=flatten(W);\n  P[3][3]=Ring::mul_identity();\n\n  auto val=P.pow(k)[3][0];\n\n  Matrix res(h,vector<M>(w));\n  for(int i=0;i<h*w;i++) res[i/w][i%w]=val.dat[i];\n  conv.transform(res,true);\n\n  for(int i=0;i<h;i++){\n    for(int j=0;j<w;j++){\n      if(j) cout<<\" \";\n      cout<<res[i][j];\n    }\n    cout<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3081.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3081\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/zalgorithm.cpp\"\n#include \"../../string/run.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto run=Run::enumerate(as);\n  using ll = long long;\n  vector<ll> dp(n+1,0),sm(n+1,0);\n  for(ll i=1;i<=n;i++){\n    dp[i]=dp[i-1]+(i-1)*1;\n    sm[i]=sm[i-1]+(i-1)*i;\n  }\n\n  auto calc=[&](ll t,ll len)->ll{\n    return (len+1)*dp[len/t]-t*sm[len/t];\n  };\n\n  ll ans=(ll)n*(n+1)/2;\n  set<Run::P> used;\n  for(int t=1;t<=n;t++){\n    for(auto p:run[t]){\n      if(used.count(p)) continue;\n      used.emplace(p);\n      ans+=calc(t,p.second-p.first);\n    }\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3084.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3084\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/integral.cpp\"\n#include \"../../formalpowerseries/diff.cpp\"\n#include \"../../formalpowerseries/log.cpp\"\n#include \"../../formalpowerseries/exp.cpp\"\n#include \"../../formalpowerseries/pow.cpp\"\n#include \"../../tree/centroid.cpp\"\n#include \"../../tools/fixpoint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  NTT<2> ntt;\n  using M = decltype(ntt)::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n  using Poly = decltype(FPS)::Poly;\n\n  int n,m;\n  cin>>n>>m;\n\n  Poly as(n);\n  for(int i=0;i<n;i++) cin>>as[i].v;\n\n  Centroid G(n+1);\n  G.add_edge(n,0);\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    G.add_edge(u,v);\n  }\n\n  vector<int> par(n+1,-1);\n  {\n    queue<int> que;\n    que.emplace(n);\n    while(!que.empty()){\n      int v=que.front();que.pop();\n      for(int u:G.G[v]){\n        if(u==par[v]) continue;\n        par[u]=v;\n        que.emplace(u);\n      }\n    }\n  }\n\n  vector<int> dead(n+1,0);\n  auto disable=[&](int k){\n    dead[k]=1;\n    G.disable(k);\n  };\n  disable(n);\n\n  const int deg = 1<<18;\n  Poly ps(n,M(1));\n  ps=FPS.pow(ps,m,deg);\n\n  queue<int> que;\n  que.emplace(G.build(0)[0]);\n\n  Poly ans(n);\n  while(!que.empty()){\n    int r=que.front();que.pop();\n\n    Poly qs;\n    MFP([&](auto dfs,int v,int p,int h)->void{\n      while(!(h<(int)qs.size())) qs.emplace_back(0);\n      qs[h]+=as[v];\n      for(int u:G.G[v]){\n        if(u==p) continue;\n        if(dead[u]) continue;\n        dfs(u,v,h+1);\n      }\n    })(r,par[r],0);\n    reverse(qs.begin(),qs.end());\n\n    vector<int> bs;\n    int p=r;\n    while(~p&&!dead[p]){\n      bs.emplace_back(p);\n      p=par[p];\n    }\n\n    int len=qs.size()-1;\n    qs.resize(len+bs.size(),M(0));\n    auto rs=FPS.mul(FPS.pre(ps,qs.size()),qs);\n\n    for(int i=0;i<(int)bs.size();i++) ans[bs[i]]+=rs[len+i];\n\n    disable(r);\n    for(int u:G.G[r])\n      if(!dead[u]) que.emplace(G.build(u)[0]);\n  }\n\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<ans[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3086.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3086\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../algorithm/offlineonline.cpp\"\n#include \"../../datastructure/sparsetable.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,l;\n  cin>>n>>l;\n  auto as=read(n);\n\n  auto f=[](int a,int b){return max(a,b);};\n  SparseTable<int> st(f);\n  st.build(as);\n\n  using ll = long long;\n  const ll INF = 1e18;\n  auto dist=[&](int i,int j)->ll{\n    return j-i<l?INF-ll(2e9)*(j-i):-st.query(i,j);\n  };\n\n  cout<<-OfflineOnline::solve<ll>(n,dist)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3102.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3102\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#include \"../../graph/twosatisfiability.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,m;\n  cin>>n>>m;\n\n  TwoSat G(n);\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    G.add_if(a,b);\n  }\n  G.build();\n\n  for(int i=0;i<n;i++){\n    int flg=0;\n    for(int j=0;j<n;j++){\n      if(G.scc[i]!=G.scc[j]) continue;\n      if(flg) cout<<\" \";\n      flg=1;\n      cout<<j+1;\n    }\n    cout<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3112.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3112\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../string/suffixarray.cpp\"\n#include \"../../string/longestcommonprefix.cpp\"\n#include \"../../segtree/basic/dual.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string s,t;\n  cin>>s>>t;\n\n  string b=s+'%'+t;\n  LongestCommonPrefix lcp(b);\n\n  int n=s.size(),m=t.size();\n\n  set<int> ss;\n  for(int i=0;i<=n+1+m;i++){\n    if(!isalpha(b[lcp.sa[i]])) continue;\n    if(n<lcp.sa[i]) ss.emplace(i);\n  }\n\n  vector<int> nx(n+1,-1);\n  for(int i=0;i<=n+1+m;i++){\n    if(!isalpha(b[lcp.sa[i]])) continue;\n    int k=lcp.sa[i];\n    if(k>=n) continue;\n\n    auto it=ss.upper_bound(i);\n    if(it!=ss.end()) chmax(nx[k],lcp.query(i,*it));\n    if(it!=ss.begin()) it--;\n    if(it!=ss.end()) chmax(nx[k],lcp.query(i,*it));\n  }\n\n  int len;\n  cin>>len;\n\n  auto h=[&](int a,int b){return a||b;};\n  int ei=0;\n  SegmentTree<int> seg(h,ei);\n  seg.init(n+m+1000);\n\n  seg.set_val(0,1);\n  for(int i=0;i<n;i++){\n    if(!seg.get_val(i)) continue;\n    if(nx[i]<len) continue;\n    int nl=i+len;\n    int nr=i+nx[i]+1;\n    seg.update(nl,nr,1);\n  }\n\n  cout<<(seg.get_val(n)?\"Yes\":\"No\")<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3117.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3117\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/pb_ds_tree.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,k;\n  cin>>n>>k;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i],as[i]-=k;\n\n  using ll = long long;\n  using P = pair<ll, int>;\n  gtree<P> G;\n  ll sum=0,ans=0;\n  G.insert(P(sum,-1));\n  for(int i=0;i<n;i++){\n    sum+=as[i];\n    G.insert(P(sum,i));\n    ans+=G.order_of_key(P(sum,i));\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3120.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3120\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/subtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using Node = NodeBase<int>;\n  constexpr size_t LIM = 1e5+100;\n  using LCT = Subtree<Node, LIM>;\n  LCT lct;\n\n  int n,q;\n  cin>>n>>q;\n\n  for(int i=0;i<=n;i++) lct.create(1);\n  for(int i=1;i<n;i++){\n    int a,b;\n    cin>>a>>b;\n    lct.evert(lct[b]);\n    lct.link(lct[a],lct[b]);\n  }\n  lct.evert(lct[1]);\n  lct.link(lct[0],lct[1]);\n\n  vector<int> par(n+1);\n  for(int i=1;i<=n;i++) par[i]=lct.idx(lct.parent(lct[i]));\n\n  for(int i=0;i<q;i++){\n    int t,v;\n    cin>>t>>v;\n    if(t==1){\n      if(lct.root(lct[v])==lct[v]){\n        lct.link(lct[par[v]],lct[v]);\n      }else{\n        lct.cut(lct[v]);\n      }\n    }\n    if(t==2){\n      auto r=lct.root(lct[v]);\n      lct.evert(lct[v]);\n      auto u=lct.parent(r);\n      lct.evert(r);\n      lct.cut(u);\n      cout<<lct.query(u)<<\"\\n\";\n      lct.link(r,u);\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3138.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3138\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/dice.cpp\"\n#include \"../../tools/drop.cpp\"\n#undef call_from_test\n\nint dp[100][200][200];\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int h,w;\n  cin>>h>>w;\n  vector<string> ss(h);\n  for(int i=0;i<h;i++) cin>>ss[i];\n\n  Die d;\n  d.top()='1';\n  d.bottom()='6';\n  d.north()='5';\n  d.south()='2';\n  d.east()='3';\n  d.west()='4';\n\n  auto ds=makeDice(d);\n  map<array<int, 6>, int> idx;\n  for(int i=0;i<(int)ds.size();i++)\n    idx[ds[i].fs]=i;\n\n  memset(dp,0,sizeof(dp));\n  using T = tuple<int, int, int>;\n  queue<T> que;\n\n  dp[idx[d.fs]][0][0]=1;\n  que.emplace(idx[d.fs],0,0);\n\n  while(!que.empty()){\n    int k,i,j;\n    tie(k,i,j)=que.front();que.pop();\n    if(i==h-1 and j==w-1) drop(\"YES\");\n    d=ds[k];\n\n    if(i+1<h){\n      int ni=i+1,nj=j;\n      Die nd(d);\n      nd.roll('S');\n      if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.fs]][ni][nj]){\n        dp[idx[nd.fs]][ni][nj]=1;\n        que.emplace(idx[nd.fs],ni,nj);\n      }\n    }\n\n    if(i-1>=0){\n      int ni=i-1,nj=j;\n      Die nd(d);\n      nd.roll('N');\n      if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.fs]][ni][nj]){\n        dp[idx[nd.fs]][ni][nj]=1;\n        que.emplace(idx[nd.fs],ni,nj);\n      }\n    }\n\n    if(j+1<w){\n      int ni=i,nj=j+1;\n      Die nd(d);\n      nd.roll('E');\n      if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.fs]][ni][nj]){\n        dp[idx[nd.fs]][ni][nj]=1;\n        que.emplace(idx[nd.fs],ni,nj);\n      }\n    }\n\n    if(j-1>=0){\n      int ni=i,nj=j-1;\n      Die nd(d);\n      nd.roll('W');\n      if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.fs]][ni][nj]){\n        dp[idx[nd.fs]][ni][nj]=1;\n        que.emplace(idx[nd.fs],ni,nj);\n      }\n    }\n  }\n\n  drop(\"NO\");\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3142.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3142\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../tree/centroid.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n;\n  cin>>n;\n  Centroid G(n);\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    G.add_edge(u,v);\n  }\n\n  vector<ll> as(n),bs(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n  for(int i=0;i<n;i++) cin>>bs[i];\n\n  using P = pair<int, ll>;\n  vector<vector<P>> H(n);\n  MFP([&](auto dfs,int v,int p)->ll{\n    ll res=as[v]-bs[v];\n    for(int u:G[v]){\n      if(u==p) continue;\n      ll tmp=dfs(u,v);\n      H[u].emplace_back(v,-tmp);\n      H[v].emplace_back(u,+tmp);\n      res+=tmp;\n    }\n    return res;\n  })(0,-1);\n\n  vector<ll> dp(n,0);\n  queue<int> que;\n  que.emplace(G.build(0)[0]);\n\n  vector<ll> tmp(n);\n  while(!que.empty()){\n    int r=que.front();que.pop();\n\n    for(int t=0;t<2;t++){\n      ll res=0;\n      for(auto ch:H[r]){\n        int c=ch.first;\n        if(!G.alive(c)) continue;\n\n        // calc cost\n        MFP([&](auto dfs,int v,int p,ll d)->void{\n          chmin(dp[v],-d+res);\n          for(auto[u,w]:H[v]){\n            if(u==p) continue;\n            if(!G.alive(u)) continue;\n            dfs(u,v,d+w);\n          }\n        })(c,r,ch.second);\n\n        // update cost\n        MFP([&](auto dfs,int v,int p,ll d)->void{\n          chmin(res,d);\n          for(auto[u,w]:H[v]){\n            if(u==p) continue;\n            if(!G.alive(u)) continue;\n            dfs(u,v,d+w);\n          }\n        })(c,r,ch.second);\n      }\n      chmin(dp[r],res);\n      reverse(H[r].begin(),H[r].end());\n    }\n\n    G.disable(r);\n    for(int c:G.G[r])\n      if(G.alive(c))\n        que.emplace(G.build(c)[0]);\n  }\n\n  ll ans=0;\n  for(ll x:dp) ans+=x;\n  cout<<-ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3143.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3143\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../toptree/toptree.cpp\"\n#include \"../../toptree/farthest.cpp\"\n#undef call_from_test\n\nconst int MAX = 2e5+100;\nVertex* vs[MAX];\nint as[MAX],bs[MAX],ds[MAX];\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  const size_t N = MAX;\n  using Cluster = Farthest<long long>;\n  TopTree<Vertex, Cluster, N> G;\n\n  int n;\n  cin>>n;\n\n  for(int i=0;i<n;i++) vs[i]=G.create();\n\n  for(int i=1;i<n;i++){\n    cin>>as[i]>>bs[i]>>ds[i];\n    as[i]--;bs[i]--;\n    G.link(vs[as[i]],Cluster(ds[i],as[i],bs[i]),vs[bs[i]]);\n  }\n\n  auto cut=[&](int k)->void{\n    G.cut(vs[as[k]],vs[bs[k]]);\n  };\n  auto link=[&](int k)->void{\n    G.link(vs[as[k]],Cluster(ds[k],as[k],bs[k]),vs[bs[k]]);\n  };\n\n  int q;\n  cin>>q;\n\n  int cur=0;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n\n    if(t==1){\n      int x;\n      cin>>x;\n      x--;\n      cur=x;\n    }\n    if(t==2){\n      int y;\n      cin>>y;\n      cut(y);\n    }\n    if(t==3){\n      int z;\n      cin>>z;\n      link(z);\n    }\n\n    auto fs=get_all_farthests(G,vs[cur]);\n    if(fs.empty()){\n      cout<<1<<\" \"<<cur+1<<newl;\n      continue;\n    }\n\n    sort(fs.begin(),fs.end());\n    cout<<fs.size();\n    for(int f:fs) cout<<\" \"<<f+1;\n    cout<<newl;\n\n    // amortization\n    for(int f:fs) G.expose(vs[f]);\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3148.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3148\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../tools/drop.cpp\"\n#include \"../../tree/rerooting.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  struct T{\n    ll a,b,c;\n    T(ll a,ll b,ll c):a(a),b(b),c(c){}\n  };\n\n  const ll INF = 1e9;\n  auto fold=[&](T x,T y){\n    vector<ll> vs({x.a,x.b,x.c,y.a,y.b,y.c});\n    sort(vs.rbegin(),vs.rend());\n    return T(vs[0],vs[1],vs[2]);\n  };\n  auto lift=[&](T x,ll y){\n    chmax(x.a,0);\n    x.a+=y;\n    x.b=-INF;\n    x.c=-INF;\n    return x;\n  };\n\n  int n;\n  cin>>n;\n  if(n==1) drop(1);\n\n  ReRooting<T, ll> G(n,fold,lift,T(-INF,-INF,-INF));\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    G.add_edge(u,v,1);\n  }\n  auto res=G.build();\n\n  string ans(n+1,'1');\n\n  for(int i=0;i<n;i++){\n    if(G.G[i].size()<3) continue;\n    T v=res[i];\n    ans[v.a+min({v.a-1,v.b,v.c})]='0';\n  }\n\n  for(int i=n-1;i>=0;i--)\n    if(ans[i+1]=='0') ans[i]='0';\n\n  ans[1]='1';\n  ans[2]='1';\n  cout<<ans.substr(1)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3168.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3168\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../matching/bipartite.cpp\"\n#undef call_from_test\n\nconst int MAX = 303;\nint G[MAX][MAX]={};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,lim;\n  cin>>n>>m>>lim;\n\n  auto cs=read<char>(n);\n\n  const int INF = 1e9;\n  for(int i=0;i<n;i++)\n    for(int j=0;j<n;j++)\n      G[i][j]=INF;\n\n  for(int i=0;i<n;i++) G[i][i]=0;\n\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    G[a][b]=G[b][a]=1;\n  }\n\n  for(int k=0;k<n;k++)\n    for(int i=0;i<n;i++)\n      for(int j=0;j<n;j++)\n        chmin(G[i][j],G[i][k]+G[k][j]);\n\n  auto check=[&](int i,int j){\n    int x=cs[i]-'a';\n    int y=cs[j]-'a';\n    return (((x+1)%26==y or (y+1)%26==x) and G[i][j]<=lim);\n  };\n\n  Bipartite bm(n);\n  for(int i=0;i<n;i++)\n    for(int j=0;j<i;j++)\n      if(check(i,j)) bm.add_edge(i,j);\n\n  cout<<bm.build()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3179.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3179\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../toptree/toptree.cpp\"\n#undef call_from_test\nusing M = Mint<int, 998244353>;\n\nstruct Vertex{\n  M v;\n  void* handle;\n  Vertex():v(0),handle(nullptr){}\n  Vertex(M v):v(v),handle(nullptr){}\n};\n\nstruct Cluster{\n  M len;\n  M sum_v;\n  M sum_l,sum_r;\n  M rake_v,rake_d;\n  Cluster(M len=M(0)):len(len),sum_v(0),sum_l(0),sum_r(0),rake_v(0),rake_d(0){}\n  void toggle(){\n    swap(sum_l,sum_r);\n  }\n  static Cluster compress(Cluster x,Vertex *v,Cluster y){\n    Cluster nxt(x.len+y.len);\n    nxt.sum_v=x.sum_v+x.rake_v+(v->v)+y.sum_v;\n    nxt.sum_l=x.sum_l+x.rake_d+y.sum_l+(x.sum_v+(v->v)+x.rake_v)*y.len;\n    nxt.sum_r=x.sum_r+x.rake_d+y.sum_r+(y.sum_v+(v->v)+x.rake_v)*x.len;\n    return nxt;\n  }\n  static Cluster rake(Cluster x,Cluster y){\n    x.rake_v+=y.sum_v+y.rake_v;\n    x.rake_d+=y.sum_l+y.rake_d;\n    return x;\n  }\n};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl ='\\n';\n\n  int n;\n  cin>>n;\n\n  vector<M> vs(n);\n  for(int i=0;i<n;i++) cin>>vs[i].v;\n\n  vector<int> as(n),bs(n);\n  vector<M> ws(n);\n  for(int i=1;i<n;i++){\n    cin>>as[i]>>bs[i]>>ws[i].v;\n    as[i]--;bs[i]--;\n  }\n\n  const size_t N = 2e5+1;\n  TopTree<Vertex, Cluster, N> G;\n\n  vector<Vertex*> ptr(n);\n  for(int i=0;i<n;i++) ptr[i]=G.create(vs[i]);\n\n  for(int i=1;i<n;i++)\n    G.link(ptr[as[i]],Cluster(0),ptr[bs[i]]);\n\n  M ans{0};\n  for(int i=1;i<n;i++){\n    Cluster x=G.get_subtree(ptr[bs[i]],ptr[as[i]]);\n    Cluster y=G.get_subtree(ptr[as[i]],ptr[bs[i]]);\n    ans+=ws[i]*(x.sum_v+x.rake_v+vs[as[i]])*(y.sum_v+y.rake_v+vs[bs[i]]);\n    G.set_edge(ptr[as[i]],ptr[bs[i]],Cluster(ws[i]));\n  }\n  cout<<ans<<newl;\n\n  Vertex* rt=G.create(0);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==1){\n      int c,a;\n      cin>>c>>a;\n      c--;\n      G.link(rt,Cluster(0),ptr[c]);\n      Cluster x=G.get_subtree(rt,ptr[c]);\n      G.cut(rt,ptr[c]);\n      ans+=M(a)*(x.sum_l+x.rake_d);\n      vs[c]+=M(a);\n      G.set_vertex(ptr[c],Vertex(vs[c]));\n    }\n\n    if(t==2){\n      int e,a;\n      cin>>e>>a;\n\n      Cluster x=G.get_subtree(ptr[bs[e]],ptr[as[e]]);\n      Cluster y=G.get_subtree(ptr[as[e]],ptr[bs[e]]);\n      ans+=M(a)*(x.sum_v+x.rake_v+vs[as[e]])*(y.sum_v+y.rake_v+vs[bs[e]]);\n\n      ws[e]+=M(a);\n      G.set_edge(ptr[as[e]],ptr[bs[e]],Cluster(ws[e]));\n    }\n    cout<<ans<<newl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3183.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3183\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/drop.cpp\"\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#include \"../../graph/dijkstra.cpp\"\n#include \"../../maxflow/fordfulkerson.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nconst int MAX = 303;\nint G[MAX][MAX]={};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  SCC G(n);\n\n  int S=n,T=n+1;\n  Dijkstra<int> D(n+2);\n  FordFulkerson<int, true> F(n+2);\n  for(int i=0;i<m;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    G.add_edge(u,v);\n    D.add_edge(u,v,1);\n    F.add_edge(u,v,1);\n  }\n  int k=G.build();\n\n  vector<int> indeg(n,0);\n  vector<int> outdeg(n,0);\n\n  for(int i=0;i<k;i++)\n    for(int j:G.H[i])\n      outdeg[i]++,indeg[j]++;\n\n  for(int i=0;i<k;i++){\n    if(i!=0 and indeg[i]==0) drop(-1);\n    if(i!=k-1 and outdeg[i]==0) drop(-1);\n  }\n\n  for(int i=0;i<n;i++){\n    if(G.blg[i]==0){\n      D.add_edge(S,i,0);\n      F.add_edge(S,i,2);\n    }\n    if(G.blg[i]==k-1){\n      D.add_edge(i,T,0);\n      F.add_edge(i,T,2);\n    }\n  }\n\n  int res=F.flow(S,T,2);\n  if(res!=2) drop(-1);\n\n  D.build(S);\n  if(~D.bs[T]) drop(D[T]);\n  drop(-1);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3198.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3198\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../matching/bipartite.cpp\"\n#undef call_from_test\n\nconst int MAX = 5050;\nint ex[MAX][MAX]={};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  Bipartite G(n+n);\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    ex[a][b]=1;\n    G.add_edge(0+a,n+b);\n  }\n\n  int res=G.build();\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int x,y;\n    cin>>x>>y;\n    x--;y--;\n\n    if(ex[x][y])\n      res-=G.cut_edge(0+x,n+y);\n    else\n      G.add_edge(0+x,n+y);\n\n    ex[x][y]^=1;\n\n    res+=G.build();\n    cout<<(res==n?\"Yes\":\"No\")<<'\\n';\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3208.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3208\n// verification-helper: ERROR 1e-10\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/precision.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../graph/topologicalsort.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  while(cin>>n>>m,n){\n    TopologicalSort G(n);\n    for(int i=0;i<m;i++){\n      int a,b;\n      cin>>a>>b;\n      a--;b--;\n      G.add_edge(a,b);\n    }\n\n    auto ps=G.build();\n    if(ps.empty()){\n      cout<<0<<endl;\n      continue;\n    }\n\n    vector<int> dp(n,0);\n    for(int i=n-1;i>=0;i--){\n      int v=ps[i];\n      for(int u:G.G[v])\n        chmax(dp[v],dp[u]+1);\n    }\n\n    cout<<-1.0/accumulate(dp.begin(),dp.end(),0.0)<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3213.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3213\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../tools/defaultdict.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,m;\n  cin>>n>>m;\n  m++; // [0, m] -> [0, m)\n\n  auto as=read(n);\n  auto bs=read(n);\n\n  while(n<34){\n    as.emplace_back(0);\n    bs.emplace_back(0);\n    n++;\n  }\n  assert(n==34);\n  using ll = long long;\n\n  const int h = n/2;\n  const int sz = 1<<h;\n  using P = pair<ll, ll>;\n  vector<P> vp,vq;\n  for(int t=0;t<2;t++){\n    for(int bit=0;bit<sz;bit++){\n      ll x=0,y=0;\n      for(int i=0;i<h;i++){\n        if((bit>>i)&1){\n          x^=as[t*h+i];\n          y+=bs[t*h+i];\n        }\n      }\n      vp.emplace_back(x,y);\n    }\n    swap(vp,vq);\n  }\n\n  const ll INF = 1e18;\n  const int LOG = 30;\n\n  ll ans=0;\n  for(int t=LOG-1;t>=0;t--){\n    if((~m>>t)&1) continue;\n\n    DefaultDict<ll, ll> dp(-INF);\n    auto get_bit=[&](int b){return (b>>t)<<t;};\n    for(auto[x,y]:vp)\n      chmax(dp[get_bit(x)],y);\n\n    for(auto[x,y]:vq)\n      if(dp.count(get_bit(m^(1LL<<t)^x)))\n        chmax(ans,dp[get_bit(m^(1LL<<t)^x)]+y);\n  }\n\n  cout<<ans<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3506.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3506\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../graph/rangetorange.cpp\"\n#include \"../../graph/dijkstra.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<int> xs(n),ys(n);\n  for(int i=0;i<n;i++) cin>>xs[i]>>ys[i];\n\n  // [0n, 1n) : original\n  // [1n, 2n) : x-axis\n  // [2n, 3n) : y-axis\n  const int m = 3 * n;\n  RangeToRange R(m);\n  Dijkstra<int> D(m*3+4*n);\n\n  auto f0=[&](int u,int v){D.add_edge(u,v,0);};\n  auto f1=[&](int u,int v){D.add_edge(u,v,1);};\n  R.init(f0);\n\n  // swap(xs,ys);\n  for(int k=1;k<=2;k++){\n    auto cx=compress(xs);\n    auto dx=dict(cx);\n\n    vector<int> tx(n);\n    for(int i=0;i<n;i++) tx[i]=dx[xs[i]];\n\n    map<int, int> ls,rs;\n    for(int i=0;i<n;i++) ls[ys[i]]=rs[ys[i]]=tx[i];\n    for(int i=0;i<n;i++){\n      chmin(ls[ys[i]],tx[i]);\n      chmax(rs[ys[i]],tx[i]);\n    }\n\n    // connect\n    for(int i=0;i<n;i++){\n      D.add_edge(m+k*n+tx[i],m+i,0);\n      D.add_edge(m+i,m+k*n+tx[i],0);\n    }\n\n    // add point\n    for(int i=0;i<n;i++){\n      R.add_edge(i,i+1,k*n+ls[ys[i]],k*n+rs[ys[i]]+1,f0,f1);\n      R.add_edge(k*n+ls[ys[i]],k*n+rs[ys[i]]+1,i,i+1,f0,f1);\n    }\n\n    swap(xs,ys);\n  }\n\n  D.build(m);\n  cout<<(~D.bs[m+n-1]?D[m+n-1]:-1)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/3518.test.cpp",
    "content": "#define PROBLEM \"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3518\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/basic/ushi.cpp\"\n#include \"../../segtree/2d/ushi.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  map<pair<int, int>, int> mp;\n  for(int i=0;i<m;i++){\n    int y,x,a;\n    cin>>y>>x>>a;\n    mp[{y,x}]=a;\n  }\n\n  const int INF = 1e9+7;\n  using P = pair<int, int>;\n  auto f1=[&](int a,int b){return min(a,b);};\n  auto f2=[&](int a,int b){return a+b;};\n  auto f=[&](P a,P b){return P(f1(a.first,b.first),f2(a.second,b.second));};\n\n  SegmentTree2D<int, SegmentTree<P>> seg(f,P(INF,0));\n\n  for(auto[pos,a]:mp){\n    auto[y,x]=pos;\n    seg.preupdate(y,x);\n  }\n  seg.build();\n\n  for(auto[pos,a]:mp){\n    auto[y,x]=pos;\n    seg.update(y,x,P(a,1));\n  }\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    using ll = long long;\n    ll u,d,l,r;\n    cin>>u>>d>>l>>r;\n    d++;r++;\n    P res=seg.query(u,d,l,r);\n    ll num=(d-u)*(r-l);\n    if(res.second<num) chmin(res.first,0);\n    cout<<res.first<<'\\n';\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ALDS1_10_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/longestcommonsubstring.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int q;\n  cin>>q;\n  while(q--){\n    string s,t;\n    cin>>s>>t;\n    cout<<longest_common_substring(s,t).size()<<'\\n';\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ALDS1_14_B.knuthmorrispratt.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/knuthmorrispratt.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string t,p;\n  cin>>t>>p;\n\n  vector<int> res=pattern_match(p,t);\n  for(int x:res) cout<<x<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ALDS1_14_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/rollinghash.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string t,p;\n  cin>>t>>p;\n  using ll = long long;\n  const ll MOD = 1e9+7;\n  const ll B = 1777771;\n  using RH = RollingHash<ll, MOD, B>;\n\n  RH rt(t),rp(p);\n  for(int i=0;i<(int)t.size()-(int)p.size()+1;i++)\n    if(rt.find(i,i+p.size())==rp.find(0,p.size())) cout<<i<<\"\\n\";\n\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ALDS1_14_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_C\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/rollinghash.cpp\"\n#include \"../../string/rectanglehash.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int h,w;\n  cin>>h>>w;\n  vector<string> ss(h);\n  for(int i=0;i<h;i++) cin>>ss[i];\n\n  int r,c;\n  cin>>r>>c;\n  vector<string> ts(r);\n  for(int i=0;i<r;i++) cin>>ts[i];\n\n  const int MOD = 1e9+7;\n  const int B1 = 1777771;\n  const int B2 = 1e8+7;\n  auto srh=rectangle_hash<int, MOD, B1, B2>(ss,r,c);\n  auto trh=rectangle_hash<int, MOD, B1, B2>(ts,r,c);\n\n  for(int i=0;i<h-r+1;i++)\n    for(int j=0;j<w-c+1;j++)\n      if(srh[i][j]==trh[0][0]) cout<<i<<\" \"<<j<<\"\\n\";\n\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ALDS1_15_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_15_B\n// verification-helper: ERROR 1e-6\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/precision.cpp\"\n#undef call_from_test\n\nsigned main(){\n  using D = double;\n\n  int n,w;\n  cin>>n>>w;\n  vector<D> vs(n),ws(n);\n  for(int i=0;i<n;i++) cin>>vs[i]>>ws[i];\n\n  using P = pair<D, int>;\n  vector<P> vp;\n  for(int i=0;i<n;i++)\n    vp.emplace_back(vs[i]/ws[i],i);\n\n  sort(vp.rbegin(),vp.rend());\n\n  D ans=0,res=w;\n  for(auto p:vp){\n    D amount=min(ws[p.second],res);\n    res-=amount;\n    ans+=amount*p.first;\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ALDS1_1_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/isprime.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n;\n  cin>>n;\n  int ans=0;\n  for(int i=0;i<n;i++){\n    int x;\n    cin>>x;\n    ans+=isprime(x);\n  }\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ALDS1_5_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_D\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../vector/inversion.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  cout<<inversion(compressed(as))<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ALDS1_9_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_C\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/skewheap.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using Heap=SkewHeap<int, int>;\n  auto g=[](int a,int b){return a+b;};\n  auto c=[](int a,int b){return a<b;};\n  int INF = -1;\n  Heap heap(g,g,c,INF,0);\n  auto base=heap.push(0);\n\n  string s;\n  while(cin>>s,s!=\"end\"){\n    int x;\n    if(s==\"insert\"){\n      cin>>x;\n      base=heap.meld(base,heap.push(x));\n    }\n    if(s==\"extract\"){\n      x=heap.top(base);\n      base=heap.pop(base);\n      cout<<x<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_1_E.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_E\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../string/editdistance.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string s1,s2;\n  cin>>s1>>s2;\n  cout<<edit_distance(s1,s2)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_3_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_B\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../algorithm/largestrectangle.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int h,w;\n  cin>>h>>w;\n\n  vector< vector<int> > cs(h,vector<int>(w));\n  for(int i=0;i<h;i++)\n    for(int j=0;j<w;j++)\n      cin>>cs[i][j];\n\n  int res=0;\n  vector<int> dp(w,0);\n  for(int i=0;i<h;i++){\n    for(int j=0;j<w;j++)\n      dp[j]=cs[i][j]==0?dp[j]+1:0;\n    chmax(res,largestrectangle(dp));\n  }\n\n  cout<<res<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_3_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_C\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../algorithm/largestrectangle.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using ll = long long;\n  vector<ll> vs(n);\n  for(int i=0;i<n;i++) cin>>vs[i];\n\n  cout<<largestrectangle(vs)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_A\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n;\n  Mint<int> k;\n  scanf(\"%d %d\",&n,&k.v);\n  printf(\"%d\\n\",k.pow(n).v);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_B\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  printf(\"%d\\n\",Enumeration<Mint<int>>::P(k,n).v);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_C\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../combinatorics/surjection.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  printf(\"%d\\n\",surjection<Mint<int>>(n,k).v);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_D\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  printf(\"%d\\n\",Enumeration<Mint<int>>::H(n,k).v);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_E.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_E\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  printf(\"%d\\n\",Mint<int>::comb(k,n).v);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_F.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_F\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  printf(\"%d\\n\",Enumeration<Mint<int>>::C(n-1,k-1).v);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_G.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_G\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../combinatorics/bell.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  printf(\"%d\\n\",bell<Mint<int>>(n,k).v);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_H.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_H\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  printf(\"%d\\n\",(n<=k));\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_I.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_I\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../combinatorics/surjection.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  using M = Mint<int>;\n  M res=surjection<M>(n,k);\n  for(int i=1;i<=k;i++) res/=M(i);\n  printf(\"%d\\n\",res.v);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_J.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_J\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../combinatorics/partitiontable.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  printf(\"%d\\n\",PartitionTable<Mint<int>>(n,k)(n,k).v);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_K.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_K\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  printf(\"%d\\n\",(n<=k));\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DPL_5_L.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_L\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/partitiontable.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,k;\n  scanf(\"%d %d\",&n,&k);\n  PartitionTable<Mint<int>> P(n,k);\n  printf(\"%d\\n\",k<=n?P(n-k,k).v:0);\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_1_A.quickfind.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/quickfind.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  QuickFind qf(n);\n  for(int i=0;i<q;i++){\n    int c,x,y;\n    cin>>c>>x>>y;\n    if(c==0) qf.unite(x,y);\n    if(c==1) cout<<qf.same(x,y)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_1_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/unionfind.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  UnionFind uf(n);\n  for(int i=0;i<q;i++){\n    int c,x,y;\n    cin>>c>>x>>y;\n    if(c) cout<<uf.same(x,y)<<\"\\n\";\n    else uf.unite(x,y);\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_1_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_B\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/weightedunionfind.cpp\"\n#undef call_from_test\n\nint main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  WeightedUnionFind<int> wuf(n);\n\n  for(int i=0;i<q;i++){\n    int t,x,y,z;\n    cin>>t>>x>>y;\n    if(t){\n      if(wuf.same(x,y)) cout<<wuf.diff(x,y)<<\"\\n\";\n      else cout<<\"?\\n\";\n    }else{\n      cin>>z;\n      wuf.unite(x,y,z);\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/binarytrie.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  BinaryTrie<int, 30> bt;\n  for(int i=0;i<q;i++){\n    int c,x,y;\n    cin>>c>>x>>y;\n    if(c==0){\n      bt.add(x,y);\n    }\n    if(c==1){\n      int res=bt.order_of_key(y+1)-bt.order_of_key(x);\n      cout<<res<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_C\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/kdtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  KDTree<int> kd;\n  for(int i=0;i<n;i++) {\n    int x,y;\n    cin>>x>>y;\n    kd.add_point(i,x,y);\n  }\n  int root=kd.build();\n\n  int q;\n  cin>>q;\n  int sx,tx,sy,ty;\n  vector<decltype(kd)::Point> ans;\n  for(int i=0;i<q;i++){\n    cin>>sx>>tx>>sy>>ty;\n    ans.clear();\n    kd.find(root,sx,tx,sy,ty,0,ans);\n    sort(ans.begin(),ans.end());\n    for(auto p:ans) cout<<p.id<<\"\\n\";\n    cout<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_D\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/basic/dual.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  auto h=[](int a,int b){(void)a;return b;};\n  int ei=INT_MAX;\n  SegmentTree<int> seg(h,ei);\n  seg.init(n);\n\n  for(int i=0;i<q;i++){\n    int tp;\n    cin>>tp;\n    if(tp==0){\n      int s,t,x;\n      cin>>s>>t>>x;\n      seg.update(s,t+1,x);\n    }\n    if(tp==1){\n      int s;\n      cin>>s;\n      cout<<seg.get_val(s)<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_E.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/basic/dual.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  auto h=[](int a,int b){return a+b;};\n  int ei=0;\n  SegmentTree<int> seg(h,ei);\n  seg.init(n);\n\n  for(int i=0;i<q;i++){\n    int tp;\n    cin>>tp;\n    if(tp==0){\n      int s,t,x;\n      cin>>s>>t>>x;\n      s--;\n      seg.update(s,t,x);\n    }\n    if(tp==1){\n      int s;\n      cin>>s;\n      s--;\n      cout<<seg.get_val(s)<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_F.bbst.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/lazy.cpp\"\n#include \"../../bbst/rbst/impl/basic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n\n  auto f=[](int a,int b){return min(a,b);};\n  auto g=[](int  ,int b){return b;};\n  auto flip=[](int a){return a;};\n\n  using Data = decltype(Lazy(f,g,g,flip,INT_MAX,-1));\n  using Node = Data::Node;\n  constexpr size_t LIM = 1e6;\n  Basic<Data, LIM> G(f,g,g,flip,INT_MAX,-1);\n  auto rt=G.build(vector<Node>(n,Node(INT_MAX,-1)));\n\n  for(int i=0;i<q;i++){\n    int c;\n    cin>>c;\n    if(c==0){\n      int s,t,x;\n      cin>>s>>t>>x;\n      rt=G.update(rt,s,t+1,x);\n    }\n    if(c==1){\n      int s,t;\n      cin>>s>>t;\n      cout<<G.query(rt,s,t+1)<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_F.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  auto f=[](int a,int b){return min(a,b);};\n  auto g=[](int,int b){return b;};\n  SegmentTree<int, int> seg(f,g,g,INT_MAX,-1);\n  seg.build(vector<int>(n,INT_MAX));\n\n  for(int i=0;i<q;i++){\n    int c;\n    cin>>c;\n    if(c==0){\n      int s,t,x;\n      cin>>s>>t>>x;\n      seg.update(s,t+1,x);\n    }\n    if(c==1){\n      int s,t;\n      cin>>s>>t;\n      cout<<seg.query(s,t+1)<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_G.bbst.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/lazy.cpp\"\n#include \"../../bbst/rbst/impl/basic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n\n  using ll = long long;\n  using P = pair<ll, ll>;\n  auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);};\n  auto g=[](P a,ll b){return P(a.first+b*a.second,a.second);};\n  auto h=[](ll a,ll b){return a+b;};\n  auto flip=[](P a){return a;};\n\n  using Data = decltype(Lazy(f,g,h,flip,P(0,0),0));\n  using Node = Data::Node;\n  constexpr size_t LIM = 1e6;\n  Basic<Data, LIM> G(f,g,h,flip,P(0,0),0);\n  auto rt=G.build(vector<Node>(n,Node(P(0,1),0)));\n\n  for(int i=0;i<q;i++){\n    int c;\n    cin>>c;\n    if(c==0){\n      int s,t,x;\n      cin>>s>>t>>x;\n      s--;\n      rt=G.update(rt,s,t,x);\n    }\n    if(c==1){\n      int s,t;\n      cin>>s>>t;\n      s--;\n      cout<<G.query(rt,s,t).first<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_H.bbst.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_H\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/lazy.cpp\"\n#include \"../../bbst/rbst/impl/basic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n\n  auto f=[](int a,int b){return min(a,b);};\n  auto g=[](int a,int b){return a+b;};\n  auto flip=[](int a){return a;};\n\n  using Data = decltype(Lazy(f,g,g,flip,INT_MAX,0));\n  using Node = Data::Node;\n  constexpr size_t LIM = 1e6;\n  Basic<Data, LIM> G(f,g,g,flip,INT_MAX,0);\n  auto rt=G.build(vector<Node>(n,Node(0,0)));\n\n  for(int i=0;i<q;i++){\n    int c;\n    cin>>c;\n    if(c==0){\n      int s,t,x;\n      cin>>s>>t>>x;\n      rt=G.update(rt,s,t+1,x);\n    }\n    if(c==1){\n      int s,t;\n      cin>>s>>t;\n      cout<<G.query(rt,s,t+1)<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_H.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_H\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  auto f=[](int a,int b){return min(a,b);};\n  auto g=[](int a,int b){return a+b;};\n  SegmentTree<int, int> seg(f,g,g,INT_MAX,0);\n  seg.build(vector<int>(n,0));\n\n  for(int i=0;i<q;i++){\n    int c;\n    cin>>c;\n    if(c==0){\n      int s,t,x;\n      cin>>s>>t>>x;\n      seg.update(s,t+1,x);\n    }\n    if(c==1){\n      int s,t;\n      cin>>s>>t;\n      cout<<seg.query(s,t+1)<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_I.bbst.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_I\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/lazy.cpp\"\n#include \"../../bbst/rbst/impl/basic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n\n  using P = pair<int, int>;\n  auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);};\n  auto g=[](P a,int b){return P(a.second*b,a.second);};\n  auto h=[](int,int b){return b;};\n  auto flip=[](P a){return a;};\n\n  int ei=-1010;\n  using Data = decltype(Lazy(f,g,h,flip,P(0,0),ei));\n  using Node = Data::Node;\n  constexpr size_t LIM = 1e6;\n  Basic<Data, LIM> G(f,g,h,flip,P(0,0),ei);\n  auto rt=G.build(vector<Node>(n,Node(P(0,1),ei)));\n\n  for(int i=0;i<q;i++){\n    int c;\n    cin>>c;\n    if(c==0){\n      int s,t,x;\n      cin>>s>>t>>x;\n      rt=G.update(rt,s,t+1,x);\n    }\n    if(c==1){\n      int s,t;\n      cin>>s>>t;\n      cout<<G.query(rt,s,t+1).first<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_2_I.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_I\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  using P = pair<int, int>;\n  auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);};\n  auto g=[](P a,int b){return P(a.second*b,a.second);};\n  auto h=[](int,int b){return b;};\n\n  SegmentTree<P, int> seg(f,g,h,P(0,0),-1010);\n  seg.build(vector<P>(n,P(0,1)));\n\n  for(int i=0;i<q;i++){\n    int c;\n    cin>>c;\n    if(c==0){\n      int s,t,x;\n      cin>>s>>t>>x;\n      seg.update(s,t+1,x);\n    }\n    if(c==1){\n      int s,t;\n      cin>>s>>t;\n      cout<<seg.query(s,t+1).first<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_3_D.cartesiantree.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_D\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/cartesiantree.cpp\"\n#include \"../../tree/lca.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,l;\n  cin>>n>>l;\n\n  vector<int> vs(n);\n  for(int i=0;i<n;i++) cin>>vs[i];\n\n  auto ps=cartesian_tree(vs);\n\n  LCA lca(n);\n  int rt;\n  for(int i=0;i<n;i++){\n    if(~ps[i]) lca.add_edge(i,ps[i]);\n    else rt=i;\n  }\n  lca.build(rt);\n\n  for(int i=0;i+l<=n;i++){\n    if(i) cout<<\" \";\n    cout<<vs[lca.lca(i,i+l-1)];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_3_D.disjointsparsetable.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_D\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/disjointsparsetable.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,l;\n  cin>>n>>l;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto f=[](int a,int b){return min(a,b);};\n  DisjointSparseTable<int> st(f);\n  st.build(as);\n\n  for(int i=0;i+l<=n;i++){\n    if(i) cout<<\" \";\n    cout<<st.query(i,i+l);\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_3_D.slidingwindowaggregation.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_D\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/slidingwindowaggregation.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,l;\n  cin>>n>>l;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto f=[](int a,int b){return min(a,b);};\n  SWAG<int, int> swag(f,INT_MAX);\n\n  for(int i=0;i<l;i++) swag.push(as[i]);\n  for(int i=0;i+l<=n;i++){\n    if(i) cout<<\" \";\n    swag.fold([](int a,int b){cout<<min(a,b);});\n    if(i+l<n){\n      swag.pop();\n      swag.push(as[i+l]);\n    }\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_3_D.sparsetable.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_D\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/sparsetable.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,l;\n  cin>>n>>l;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto f=[](int a,int b){return min(a,b);};\n  SparseTable<int> st(f);\n  st.build(as);\n\n  for(int i=0;i+l<=n;i++){\n    if(i) cout<<\" \";\n    cout<<st.query(i,i+l);\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/DSL_3_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_D\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/rangeslide.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,l;\n  cin>>n>>l;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto cmp=[](int a,int b){return a<b;};\n  RangeSlide<int, decltype(cmp)> rs(as,cmp);\n\n  for(int i=0;i+l<=n;i++) rs.add_range(i,i+l);\n  auto res=rs.build();\n  for(int i=0;i+l<=n;i++){\n    if(i) cout<<\" \";\n    cout<<as[res[i]];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_1_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/radixheap.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,r;\n  cin>>n>>m>>r;\n\n  using P = pair<int, int>;\n  vector< vector<P> > G(n);\n  for(int i=0;i<m;i++){\n    int s,t,d;\n    cin>>s>>t>>d;\n    G[s].emplace_back(t,d);\n  }\n\n  const int INF = numeric_limits<int>::max();\n  RadixHeap<int, int> pq;\n  vector<int> dist(n,INF);\n  dist[r]=0;\n  pq.emplace(dist[r],r);\n  while(!pq.empty()){\n    P p=pq.pop();\n    int v=p.second;\n    if(dist[v]<p.first) continue;\n    for(auto& e:G[v]){\n      int u=e.first,c=e.second;\n      if(dist[u]>dist[v]+c){\n        dist[u]=dist[v]+c;\n        pq.emplace(dist[u],u);\n      }\n    }\n  }\n\n  for(int i=0;i<n;i++){\n    if(dist[i]==INF) cout<<\"INF\\n\";\n    else cout<<dist[i]<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_1_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/drop.cpp\"\n#include \"../../graph/bellmanford.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,r;\n  cin>>n>>m>>r;\n\n  BellmanFord<int> G(n);\n  for(int i=0;i<m;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    G.add_edge(a,b,c);\n  }\n\n  int neg_loop;\n  auto res=G.build(r,neg_loop);\n  if(neg_loop) drop(\"NEGATIVE CYCLE\");\n\n  for(int x:res){\n    if(x==numeric_limits<int>::max()) cout<<\"INF\\n\";\n    else cout<<x<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_2_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/unionfind.cpp\"\n#include \"../../graph/kruskal.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int V,E;\n  cin>>V>>E;\n\n  Kruskal<int> G(V);\n  for(int i=0;i<E;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    G.add_edge(a,b,c);\n  }\n\n  cout<<G.build()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_2_B.tarjan.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_B\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/arborescence_tarjan.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,r;\n  cin>>n>>m>>r;\n\n  Arborescence<int> G(n);\n  for(int i=0;i<m;i++){\n    int s,t,w;\n    cin>>s>>t>>w;\n    G.add_edge(s,t,w);\n  }\n\n  cout<<G.build(r)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_2_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_B\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#include \"../../graph/arborescence_edmond.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,r;\n  cin>>n>>m>>r;\n\n  Arborescence<int> G(n);\n  for(int i=0;i<m;i++){\n    int s,t,w;\n    cin>>s>>t>>w;\n    G.add_edge(s,t,w);\n  }\n\n  cout<<G.build(r)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_3_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/lowlink.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  LowLink G(n);\n  for(int i=0;i<m;i++){\n    int u,v;\n    cin>>u>>v;\n    G.add_edge(u,v);\n  }\n  G.build();\n\n  auto ap=G.ap;\n  sort(ap.begin(),ap.end());\n  for(int v:ap) cout<<v<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_3_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/lowlink.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  LowLink G(n);\n  for(int i=0;i<m;i++){\n    int u,v;\n    cin>>u>>v;\n    G.add_edge(u,v);\n  }\n  G.build();\n\n  auto bs=G.bs;\n  for(auto &e:bs)\n    if(e.first>e.second) swap(e.first, e.second);\n\n  sort(bs.begin(),bs.end());\n  for(auto e:bs) cout<<e.first<<\" \"<<e.second<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_4_B.ignore.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/topologicalsort.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,e;\n  cin>>n>>e;\n  TopologicalSort ts(n);\n  for(int i=0;i<e;i++){\n    int s,t;\n    cin>>s>>t;\n    ts.add_edge(s,t);\n  }\n\n  auto ps=ts.build();\n  for(int i:ps) cout<<i<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_5_A.linkcuttree.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_A\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/farthest.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using Node = NodeBase<int>;\n  constexpr size_t LIM = 2e6 + 200;\n  using LCT = Farthest<Node, LIM>;\n  LCT lct;\n\n  vector<LCT::Node*> vs(1e5+100);\n  vector<LCT::Node*> es(1e5+100);\n\n  int n;\n  cin>>n;\n  for(int i=0;i<n;i++) vs[i]=lct.create(0);\n\n  for(int i=1;i<n;i++){\n    int s,t,w;\n    cin>>s>>t>>w;\n    es[i]=lct.create(w);\n    lct.evert(vs[s]);\n    lct.evert(vs[t]);\n    lct.link(es[i],vs[s]);\n    lct.link(es[i],vs[t]);\n  }\n\n  int ans=0;\n  for(int i=0;i<n;i++){\n    lct.evert(vs[i]);\n    chmax(ans,vs[i]->ld);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_5_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_A\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/diameterforedge.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  DiameterForEdge<int> G(n);\n  for(int i=1;i<n;i++){\n    int s,t,w;\n    cin>>s>>t>>w;\n    G.add_edge(s,t,w);\n  }\n  cout<<G.build()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_5_C.lca.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/lca.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  LCA lca(n);\n  for(int i=0;i<n;i++){\n    int k;\n    cin>>k;\n    for(int j=0;j<k;j++){\n      int c;\n      cin>>c;\n      lca.add_edge(i,c);\n    }\n  }\n  lca.build();\n\n  int q;\n  cin>>q;\n  while(q--){\n    int u,v;\n    cin>>u>>v;\n    cout<<lca.lca(u,v)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_5_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/lowestcommonancestor.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  LowestCommonAncestor lca(n);\n  for(int i=0;i<n;i++){\n    int k;\n    cin>>k;\n    for(int j=0;j<k;j++){\n      int c;\n      cin>>c;\n      lca.add_edge(i,c);\n    }\n  }\n  lca.build();\n\n  int q;\n  cin>>q;\n  while(q--){\n    int u,v;\n    cin>>u>>v;\n    cout<<lca.lca(u,v)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_5_D.linkcuttree.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_D\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/path.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using Node = NodeBase<int, int>;\n  constexpr size_t LIM = 1e5+100;\n  using LCT = Path<Node, LIM>;\n\n  auto f=[](int a,int b){return a+b;};\n  LCT lct(f,f,f,0);\n\n  for(int i=0;i<n;i++) lct.create(0);\n  for(int i=0;i<n;i++){\n    int k;\n    cin>>k;\n    for(int j=0;j<k;j++){\n      int c;\n      cin>>c;\n      lct.link(lct[i],lct[c]);\n    }\n  }\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int a,b;\n      cin>>a>>b;\n      lct.expose(lct[a]);\n      lct[a]->val+=b;\n      lct.pushup(lct[a]);\n    }\n    if(t==1){\n      int a;\n      cin>>a;\n      cout<<lct.query(lct[a])<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_5_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_D\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/eulertourforedge.cpp\"\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  EulerTourForEdge et(n);\n  for(int i=0;i<n;i++){\n    int k;\n    cin>>k;\n    for(int j=0;j<k;j++){\n      int c;\n      cin>>c;\n      et.add_edge(i,c);\n    }\n  }\n  et.build();\n\n  BIT<int> bit(2*n);\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int v,w;\n      cin>>v>>w;\n      auto g=[&](int k,int d){bit.add(k,d);};\n      et.update(v,w,g);\n    }\n    if(t==1){\n      int u;\n      cin>>u;\n      int res=0;\n      et.query(0,u,[&](int l,int r){res+=bit.query(l,r);});\n      cout<<res<<\"\\n\";\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_5_E.linkcuttree.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_E\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/path.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n;\n  cin>>n;\n\n  using P = pair<ll, ll>;\n  using Node = NodeBase<P, ll>;\n  constexpr size_t LIM = 1e5+100;\n  using LCT = Path<Node, LIM>;\n\n  auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);};\n  auto g=[](P a,int b){return P(a.first+b*a.second,a.second);};\n  auto h=[](ll a,ll b){return a+b;};\n  LCT lct(f,g,h,0);\n\n  for(int i=0;i<n;i++) lct.create(P(0,1));\n  for(int i=0;i<n;i++){\n    int k;\n    cin>>k;\n    for(int j=0;j<k;j++){\n      int c;\n      cin>>c;\n      lct.link(lct[i],lct[c]);\n    }\n  }\n\n  int q;\n  cin>>q;\n  ll sum=0;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int a,b;\n      cin>>a>>b;\n      lct.update(lct[a],b);\n      sum+=b;\n    }\n    if(t==1){\n      int a;\n      cin>>a;\n      cout<<lct.query(lct[a]).first-sum<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_6_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../maxflow/fordfulkerson.cpp\"\n#undef call_from_test\n\nint main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int V,E;\n  cin>>V>>E;\n  FordFulkerson<int, true> G(V);\n  for(int i=0;i<E;i++){\n    int u,v,c;\n    cin>>u>>v>>c;\n    G.add_edge(u,v,c);\n  }\n  cout<<G.flow(0,V-1)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_6_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_B\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mincostflow/primaldual.cpp\"\n#undef call_from_test\n\nint main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int v,e,f;\n  cin>>v>>e>>f;\n\n  PrimalDual<int, int> G(v);\n  for(int i=0;i<e;i++){\n    int u,v,c,d;\n    cin>>u>>v>>c>>d;\n    G.add_edge(u,v,c,d);\n  }\n\n  if(!G.build(0,v-1,f))\n    cout<<-1<<endl;\n  else\n    cout<<G.get_cost()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/GRL_7_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_7_A\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../matching/bipartite.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int X,Y,E;\n  cin>>X>>Y>>E;\n  Bipartite bm(X+Y);\n  for(int i=0;i<E;i++){\n    int x,y;\n    cin>>x>>y;\n    bm.add_edge(x,X+y);\n  }\n  cout<<bm.build()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ITP1_11_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_A\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/dice.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  Die d;\n  for(int i=0;i<6;i++) cin>>d.fs[i];\n\n  string s;\n  cin>>s;\n\n  for(int i=0;i<(int)s.size();i++) d.roll(s[i]);\n\n  cout<<d.top()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ITP1_11_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_B\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/dice.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  Die d;\n  for(int i=0;i<6;i++) cin>>d.fs[i];\n\n  int n;\n  cin>>n;\n\n  while(n--){\n    int a,b;\n    cin>>a>>b;\n    if(d.west()==a) d.roll('E');\n    if(d.east()==a) d.roll('W');\n    while(d.top()!=a) d.roll('N');\n    while(d.south()!=b) d.roll('R');\n    cout<<d.east()<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ITP1_11_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_C\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/dice.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  Die<int> ds[2];\n  for(int j=0;j<2;j++)\n    for(int i=0;i<6;i++)\n      cin>>ds[j].fs[i];\n\n  bool f=false;\n  auto vd=makeDice(ds[1]);\n  for(auto e:vd) f|=ds[0]==e;\n  cout<<(f?\"Yes\":\"No\")<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/ITP1_11_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_D\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/dice.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  vector<Die<int>> ds(n);\n  for(int j=0;j<n;j++)\n    for(int i=0;i<6;i++)\n      cin>>ds[j].fs[i];\n\n  bool ff=true;\n  for(int i=0;i<n;i++){\n    auto vd=makeDice(ds[i]);\n    for(int j=0;j<i;j++){\n      bool f=false;\n      for(auto d:vd) f|=d==ds[j];\n      ff&=!f;\n    }\n  }\n\n  cout<<(ff?\"Yes\":\"No\")<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_1_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_A\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/factorize.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  auto mp=factorize(n);\n\n  cout<<n<<\":\";\n  for(auto p:mp)\n    for(int i=0;i<p.second;i++)\n      cout<<\" \"<<p.first;\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_1_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_B\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/pow.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  const int MOD = 1e9+7;\n  cout<<mod_pow(n,m,MOD)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_1_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_D\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/totient.cpp\"\n#undef call_from_test\n\nsigned main(){\n  using ll = long long;\n  ll n;\n  cin>>n;\n  cout<<totient(n)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_1_E.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_E\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/extgcd.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int a,b;\n  cin>>a>>b;\n  auto[x,y]=extgcd(a,b);\n  cout<<x<<\" \"<<y<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_2_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_2_A\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/bigint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  bigint a,b;\n  cin>>a>>b;\n  cout<<a+b<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_2_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_2_B\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/bigint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  bigint a,b;\n  cin>>a>>b;\n  cout<<a-b<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_2_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_2_C\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/bigint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  bigint a,b;\n  cin>>a>>b;\n  cout<<a*b<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_2_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_2_D\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/bigint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  bigint a,b;\n  cin>>a>>b;\n  cout<<a/b<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_2_E.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_2_E\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/bigint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  bigint a,b;\n  cin>>a>>b;\n  cout<<a%b<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/NTL_2_F.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_2_F\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/bigint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  bigint a,b;\n  cin>>a>>b;\n  cout<<a*b<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/2334.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2334\n// verification-helper: ERROR 1e-9\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#include \"../../../tools/chminmax.cpp\"\n#include \"../../../graph/dijkstra.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n,m;\n  cin>>n>>m;\n\n  Polygon ps(n),qs(m);\n  for(int i=0;i<n;i++) cin>>ps[i];\n  for(int i=0;i<m;i++) cin>>qs[i];\n\n  using D = double;\n  const D INF = 1e18;\n\n  Dijkstra<D> G(n),H(m);\n  for(int i=0;i<n;i++){\n    for(int j=0;j<n;j++){\n      if(i==j) continue;\n      Segment s(ps[i],ps[j]);\n      Segment t(qs[0],qs[1]);\n      if(getDistanceSS(s,t)<EPS) continue;\n      G.add_edge(i,j,abs(ps[i]-ps[j]));\n    }\n  }\n\n  for(int i=0;i<m;i++){\n    for(int j=0;j<m;j++){\n      if(i==j) continue;\n      Segment s(qs[i],qs[j]);\n      Segment t(ps[0],ps[1]);\n      if(getDistanceSS(s,t)<EPS) continue;\n      H.add_edge(i,j,abs(qs[i]-qs[j]));\n    }\n  }\n  G.build(0);\n  H.build(0);\n\n  D ans=INF;\n  chmin(ans,G[1]+abs(qs[0]-qs[1]));\n  chmin(ans,H[1]+abs(ps[0]-ps[1]));\n\n  if(ans==INF) cout<<-1<<endl;\n  else cout<<fixed<<setprecision(12)<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/2448.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2448\n// verification-helper: ERROR 1e-6\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#include \"../../../tools/fixpoint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon ps(n);\n  cin>>ps;\n  vector<Segment> ss(n-1);\n  for(int i=0;i+1<n;i++){\n    ss[i].p1=ps[i];\n    ss[i].p2=ps[i+1];\n  }\n  Polygon qs;\n  auto G=segmentArrangement(ss,qs);\n\n  int m=qs.size();\n  int s=0;\n  for(int i=0;i<m;i++)\n    if(qs[i]<qs[s]) s=i;\n\n\n  auto calc=[&](Vector a,Vector b){\n              double th=acos(max(-1.0,min(1.0,dot(a,b)/abs(a)/abs(b))));\n              if(cross(a,b)<-EPS) th=2*PI-th;\n              return th;\n            };\n  double ans=0;\n  for(int t:G[s]){\n\n    Polygon res;\n    res.emplace_back(qs[s]);\n\n    MFP([&](auto dfs,int v,int p)->void{\n          if(v==s) return;\n          int z=G[v][0];\n          for(int u:G[v]){\n            double a1=calc(qs[p]-qs[v],qs[z]-qs[v]);\n            if(z==p) a1=8;\n            double a2=calc(qs[p]-qs[v],qs[u]-qs[v]);\n            if(u==p) a2=8;\n            if(a1>a2) z=u;\n          }\n          res.emplace_back(qs[v]);\n          dfs(z,v);\n        })(t,s);\n\n    ans+=max(0.0,area(res));\n  }\n  cout<<fixed<<setprecision(12)<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/2454.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2454\n// verification-helper: ERROR 1e-6\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n// segmentArrangement\nsigned main(){\n  int n,m;\n  cin>>n>>m;\n  vector<Segment> ss(n);\n  Polygon ps(m);\n  for(int i=0;i<n;i++) cin>>ss[i];\n  for(int i=0;i<m;i++) cin>>ps[i];\n  map<Point, int> mp;\n  for(int i=0;i<m;i++) mp[ps[i]]=i;\n  Point s,g;\n  cin>>s>>g;\n  ps.emplace_back(s);\n  ps.emplace_back(g);\n\n  auto H=segmentArrangement(ss,ps);\n  vector< vector< pair<int, double> > > G(H.size());\n  for(int i=0;i<(int)H.size();i++)\n    for(int j:H[i]) G[i].emplace_back(j,abs(ps[i]-ps[j]));\n\n  double ans=0,tmp=0;\n  for(int i=0;i<n;i++) ans+=abs(ss[i].p1-ss[i].p2);\n\n  vector<int> used(G.size(),0);\n  queue<int> q;\n  for(int i=0;i<(int)G.size();i++)\n    if(ps[i]==g) {used[i]=1;q.emplace(i);}\n\n  while(!q.empty()){\n    int v=q.front();q.pop();\n    if(ps[v]==s){\n      cout<<(int)-1<<endl;\n      return 0;\n    }\n    if(mp.count(ps[v])) continue;\n    for(int u:H[v]){\n      if(!used[u]){\n        used[u]=1;\n        q.emplace(u);\n      }\n    }\n  }\n\n  for(int i=0;i<(int)G.size();i++)\n    if(ps[i]==s) q.emplace(i);\n\n  while(!q.empty()){\n    int v=q.front();q.pop();\n    for(auto &e:G[v]){\n      int u=e.first;\n      double &c=e.second;\n      if(used[v]&&used[u]) continue;\n      if(c==0) continue;\n      tmp+=c;c=0;\n      q.emplace(u);\n    }\n  }\n  tmp/=2;\n\n  cout<<fixed<<setprecision(12)<<ans-tmp<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/3049.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3049\n// verification-helper: ERROR 1e-5\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../tools/chminmax.cpp\"\n#include \"../../../io/precision.cpp\"\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon ps(n);\n  cin>>ps;\n  ps=andrewScan(ps);\n  n=ps.size();\n\n  int m;\n  cin>>m;\n  Polygon cs(m);\n  cin>>cs;\n\n  double ans=0;\n  for(int i=0;i<m;i++){\n    Polygon ts(ps);\n    for(int j=0;j<m;j++){\n      if(i==j) continue;\n      Line l=bisector(cs[i],cs[j]);\n      ts=convexCut(ts,l);\n    }\n    for(Point &x:ts) chmax(ans,abs(x-cs[i]));\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/3056.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3056\n// verification-helper: ERROR 1e-5\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#include \"../../../tools/chminmax.cpp\"\n#undef call_from_test\n\n\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon ps(n);\n  for(int i=0;i<n;i++) cin>>ps[i];\n  for(int i=0;i<n;i++) ps.emplace_back(Point(ps[i]));\n  for(int i=0;i<n;i++) ps.emplace_back(Point(ps[i]));\n\n  double ans=1e18;\n  int l=n,r=n+1;\n  for(int i=n;i<n+n;i++){\n    while(r<i+1) r++;\n    double th=arg(ps[i+1]-ps[i]);\n    Vector v1=polar(100,th+2*PI/3);\n    Vector v2=polar(100,th+4*PI/3);\n\n    Line b(ps[i],ps[i+1]);\n\n    auto calc=\n      [&](int k,Vector v,int w)->double{\n        Point p=getCrossPointLL(b,Line(ps[k],ps[k]+v));\n        if(abs(p-ps[i+w])<abs(p-ps[i+!w])) return -1;\n        return abs(p-ps[i+w]);\n      };\n\n    while(calc(l,v2,1)<0) l++;\n    while(calc(l,v2,1)<calc(l-1,v2,1)) l--;\n    while(calc(l,v2,1)<calc(l+1,v2,1)) l++;\n    while(calc(r,v1,0)<calc(r-1,v1,0)) r--;\n    while(calc(r,v1,0)<calc(r+1,v1,0)) r++;\n\n    Point p1=getCrossPointLL(b,Line(ps[r],ps[r]+v1));\n    Point p2=getCrossPointLL(b,Line(ps[l],ps[l]+v2));\n    chmin(ans,abs(p1-p2));\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_1_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A\n// verification-helper: ERROR 0.00000001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n\n// Projection\nsigned main(){\n  Point p1,p2;\n  cin>>p1>>p2;\n  int q;\n  cin>>q;\n  while(q--){\n    Point p;\n    cin>>p;\n    cout<<project(Line(p1,p2),p)<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_1_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B\n// verification-helper: ERROR 0.00000001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//Reflect\nsigned main(){\n  Point p1,p2;\n  cin>>p1>>p2;\n  int q;\n  cin>>q;\n  while(q--){\n    Point p;\n    cin>>p;\n    cout<<reflect(Line(p1,p2),p)<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_1_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//CCW\nsigned main(){\n  Point p0,p1;\n  cin>>p0>>p1;\n  int q;\n  cin>>q;\n  while(q--){\n    Point p2;\n    cin>>p2;\n    int t=ccw(p0,p1,p2);\n    if(t==CCW_COUNTER_CLOCKWISE) cout<<\"COUNTER_CLOCKWISE\"<<endl;\n    if(t==CCW_CLOCKWISE) cout<<\"CLOCKWISE\"<<endl;\n    if(t==CCW_ONLINE_BACK) cout<<\"ONLINE_BACK\"<<endl;\n    if(t==CCW_ONLINE_FRONT) cout<<\"ONLINE_FRONT\"<<endl;\n    if(t==CCW_ON_SEGMENT) cout<<\"ON_SEGMENT\"<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_2_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//Parallel / Orthogonal\nsigned main(){\n  int q;\n  cin>>q;\n  while(q--){\n    Point p0,p1,p2,p3;\n    cin>>p0>>p1>>p2>>p3;\n    if(isParallel(Line(p0,p1),Line(p2,p3))) cout<<2<<endl;\n    else if(isOrthogonal(Line(p0,p1),Line(p2,p3))) cout<<1<<endl;\n    else cout<<0<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_2_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_B\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//intersectSS\nsigned main(){\n  int q;\n  cin>>q;\n  while(q--){\n    Point p0,p1,p2,p3;\n    cin>>p0>>p1>>p2>>p3;\n    cout<<(intersectSS(Segment(p0,p1),Segment(p2,p3)))<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_2_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_C\n// verification-helper: ERROR 0.00000001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n\n//cross point\nsigned main(){\n  int q;\n  cin>>q;\n  while(q--){\n    Point p0,p1,p2,p3;\n    cin>>p0>>p1>>p2>>p3;\n    cout<<getCrossPointSS(Segment(p0,p1),Segment(p2,p3))<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_2_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_D\n// verification-helper: ERROR 0.00000001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#include \"../../../io/precision.cpp\"\n#undef call_from_test\n\n//distanceSS\nsigned main(){\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    Point p0,p1,p2,p3;\n    cin>>p0>>p1>>p2>>p3;\n    cout<<getDistanceSS(Segment(p0,p1),Segment(p2,p3))<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_3_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_A\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//Area of Polygon\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon ps(n);\n  cin>>ps;\n  cout<<fixed<<setprecision(1)<<area(ps)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_3_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_B\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//isConvex\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon ps(n);\n  cin>>ps;\n  cout<<isConvex(ps)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_3_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_C\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//contains\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon ps(n);\n  cin>>ps;\n  int q;\n  cin>>q;\n  while(q--){\n    Point r;\n    cin>>r;\n    cout<<contains(ps,r)<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_4_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//convex hull\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon ps(n);\n  cin>>ps;\n  Polygon qs=convex_hull(ps);\n  cout<<qs.size()<<endl;\n  for(Point v:qs) cout<<(int)v.x<<\" \"<<(int)v.y<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_4_B.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_B\n// verification-helper: ERROR 0.000001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n\n//diameter of Polygon\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon ps(n);\n  cin>>ps;\n  cout<<fixed<<setprecision(12)<<diameter(ps)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_4_C.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_C\n// verification-helper: ERROR 0.00001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//convexCut\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon gs(n);\n  cin>>gs;\n  Polygon ps=andrewScan(gs);\n  int q;\n  cin>>q;\n  while(q--){\n    Line l;\n    cin>>l.p1>>l.p2;\n    cout<<fixed<<setprecision(12)<<area(convexCut(ps,l))<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_5_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_5_A\n// verification-helper: ERROR 0.000001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n\n// closest_pair\nsigned main(){\n  int n;\n  cin>>n;\n  Polygon p(n);\n  for(int i=0;i<n;i++) cin>>p[i];\n  cout<<fixed<<setprecision(12)<<closest_pair(p)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_6_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_6_A\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n// manhattan_intersection\nsigned main(){\n  int n;\n  cin>>n;\n  vector<Segment> ss(n);\n  for(int i=0;i<n;i++) cin>>ss[i];\n  cout<<manhattan_intersection(ss,1e9+10)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_7_A.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_A\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//intersectCC\nsigned main(){\n  Circle c1,c2;\n  cin>>c1>>c2;\n  cout<<intersectCC(c1,c2)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_7_D.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_D\n// verification-helper: ERROR 0.000001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n\n//getCrossPointCL\nsigned main(){\n  Circle c;\n  int q;\n  cin>>c>>q;\n  while(q--){\n    Line l;\n    cin>>l;\n    auto pp=getCrossPointCL(c,l);\n    if(pp.size()==1u) pp.emplace_back(pp[0]);\n    if(pp[1]<pp[0]) swap(pp[0],pp[1]);\n    cout<<pp[0]<<\" \"<<pp[1]<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_7_E.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_E\n// verification-helper: ERROR 0.000001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n//intersectCC\nsigned main(){\n  Circle c1,c2;\n  cin>>c1>>c2;\n  auto pp=getCrossPointCC(c1,c2);\n  if(pp.size()==1u) pp.emplace_back(pp[0]);\n  if(pp[1]<pp[0]) swap(pp[0],pp[1]);\n  cout<<pp[0]<<\" \"<<pp[1]<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_7_F.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_F\n// verification-helper: ERROR 0.00001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n\n//tangent to a Circle\nsigned main(){\n  Point p;\n  Circle c;\n  cin>>p>>c;\n  auto pp=tangent(c,p);\n  for(auto p:pp) cout<<p<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_7_G.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_G\n// verification-helper: ERROR 0.00001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#undef call_from_test\n\n\n//Common Tangent\nsigned main(){\n  Circle c1,c2;\n  cin>>c1>>c2;\n  auto ls=tangent(c1,c2);\n  Polygon ps;\n  for(auto l:ls) ps.emplace_back(getCrossPointCL(c1,l)[0]);\n  sort(ps.begin(),ps.end());\n  for(auto p:ps) cout<<p<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_7_H.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_H\n// verification-helper: ERROR 0.00001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#include \"../../../io/precision.cpp\"\n#undef call_from_test\n\n\n// intersection of a circle and a polygon\nsigned main(){\n  int n;\n  double r;\n  cin>>n>>r;\n  Circle c(Point(0,0),r);\n  Polygon ps(n);\n  for(int i=0;i<n;i++) cin>>ps[i];\n  cout<<area(ps,c)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/aoj/geometry/CGL_7_I.test.cpp",
    "content": "// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_I\n// verification-helper: ERROR 0.000001\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../../geometry/geometry.cpp\"\n#include \"../../../io/precision.cpp\"\n#undef call_from_test\n\n// area of 2 circles' intersection\nsigned main(){\n  Circle c1,c2;\n  cin>>c1>>c2;\n  cout<<area(c1,c2)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/assignment.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/assignment\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bflow/capacityscaling.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n;\n  cin>>n;\n  MinCostFlow<ll, ll> G(n+n);\n\n  for(int i=0;i<n;i++){\n    G.add_supply(0+i,1);\n    G.add_demand(n+i,1);\n  }\n\n  vector<vector<decltype(G)::EdgePtr>> E(n);\n  for(int i=0;i<n;i++){\n    for(int j=0;j<n;j++){\n      int a;\n      cin>>a;\n      E[i].emplace_back(G.add_edge(i,n+j,0,1,a));\n    }\n  }\n\n  assert(G.build());\n  cout<<G.get_cost()<<endl;\n  for(int i=0;i<n;i++){\n    if(i) cout<<' ';\n    for(auto e:E[i])\n      if(G.get_edge(e).flow)\n        cout<<G.get_edge(e).dst-n;\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/associative_array.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/associative_array\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/cc_hash.cpp\"\n#include \"../../datastructure/pb_ds_cc_hash_table.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  using ll = long long;\n  gmap<ll, ll, cc_hash<ll>> mp;\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      ll k,v;\n      cin>>k>>v;\n      mp[k]=v;\n    }\n    if(t==1){\n      ll k;\n      cin>>k;\n      cout<<mp[k]<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/bernoulli_number.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/bernoulli_number\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../combinatorics/bernoulli.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  Bernoulli<M> bs(conv);\n\n  bs.build(n);\n  for(int i=0;i<=n;i++){\n    if(i) cout<<\" \";\n    cout<<bs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/bipartitematching.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/bipartitematching\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../matching/hopcroft_karp.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int L,R,M;\n  cin>>L>>R>>M;\n\n  HopcroftKarp G(L,R);\n  for(int i=0;i<M;i++){\n    int a,b;\n    cin>>a>>b;\n    G.add_edge(a,b);\n  }\n\n  cout<<G.build()<<endl;\n\n  for(int i=0;i<L;i++)\n    if(~G.match[i])\n      cout<<i<<\" \"<<G.match[i]-L<<\"\\n\";\n\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/bitwise_and_convolution.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/bitwise_and_convolution\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/bitwise/fwht.cpp\"\n#include \"../../convolution/bitwise/and.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using M = Mint<int, 998244353>;\n\n  int sz=1<<n;\n  vector<M> as(sz),bs(sz);\n  for(int i=0;i<sz;i++) cin>>as[i].v;\n  for(int i=0;i<sz;i++) cin>>bs[i].v;\n\n  fwht(as,bitwise_and::zeta);\n  fwht(bs,bitwise_and::zeta);\n\n  for(int i=0;i<sz;i++) as[i]*=bs[i];\n\n  fwht(as,bitwise_and::moebius);\n\n  for(int i=0;i<sz;i++){\n    if(i) cout<<' ';\n    cout<<as[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/bitwise_xor_convolution.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/bitwise_xor_convolution\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/bitwise/fwht.cpp\"\n#include \"../../convolution/bitwise/xor.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using M = Mint<int, 998244353>;\n\n  int sz=1<<n;\n  vector<M> as(sz),bs(sz);\n  for(int i=0;i<sz;i++) cin>>as[i].v;\n  for(int i=0;i<sz;i++) cin>>bs[i].v;\n\n  fwht(as,bitwise_xor::zeta);\n  fwht(bs,bitwise_xor::zeta);\n\n  for(int i=0;i<sz;i++) as[i]*=bs[i];\n\n  fwht(as,bitwise_xor::zeta);\n  M inv=M(sz).inv();\n  for(int i=0;i<sz;i++) as[i]*=inv;\n\n  for(int i=0;i<sz;i++){\n    if(i) cout<<' ';\n    cout<<as[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/cartesian_tree.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/cartesian_tree\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/cartesiantree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n;\n  cin>>n;\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto ps=cartesian_tree(as);\n  for(int i=0;i<n;i++){\n    if(i) cout<<' ';\n    cout<<(ps[i]<0?i:ps[i]);\n  }\n  cout<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/convolution_mod.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/convolution_mod\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  NTT<2> ntt;\n  using M = decltype(ntt)::M;\n  vector<M> as(n),bs(m);\n  for(int i=0;i<n;i++) cin>>as[i].v;\n  for(int i=0;i<m;i++) cin>>bs[i].v;\n  auto cs=ntt.multiply(as,bs);\n  for(int i=0;i<(int)cs.size();i++){\n    if(i) cout<<\" \";\n    cout<<cs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/convolution_mod_1000000007.garner.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/convolution_mod_1000000007\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../convolution/garner.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  vector<int> as(n),bs(m);\n  for(int i=0;i<n;i++) cin>>as[i];\n  for(int i=0;i<m;i++) cin>>bs[i];\n\n  const int MOD = 1e9+7;\n  Garner arb;\n  auto cs=arb.multiply(as,bs,MOD);\n  for(int i=0;i<(int)cs.size();i++){\n    if(i) cout<<\" \";\n    cout<<cs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/convolution_mod_1000000007.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/convolution_mod_1000000007\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#define double long double\n#include \"../../convolution/fastfouriertransform.cpp\"\n#undef double\n#include \"../../convolution/arbitrarymod.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  using M = Mint<int>;\n  ArbitraryMod<M> arb;\n\n  vector<M> as(n),bs(m);\n  for(int i=0;i<n;i++) cin>>as[i].v;\n  for(int i=0;i<m;i++) cin>>bs[i].v;\n  auto cs=arb.multiply(as,bs);\n  for(int i=0;i<(int)cs.size();i++){\n    if(i) cout<<\" \";\n    cout<<cs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/cycle_detection.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/cycle_detection\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/cycle.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  DirectedCycle G(n);\n  vector<map<int, int>> I(n);\n\n  for(int i=0;i<m;i++){\n    int u,v;\n    cin>>u>>v;\n    G.add_edge(u,v);\n    I[u][v]=i;\n  }\n\n  auto vs=G.build();\n\n  if(vs.empty()){\n    cout<<-1<<endl;\n    return 0;\n  }\n\n  int l=vs.size();\n  cout<<l<<endl;\n  for(int i=0;i<l;i++)\n    cout<<I[vs[i]][vs[(i+1)%l]]<<'\\n';\n\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/discrete_logarithm_mod.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/discrete_logarithm_mod\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/log.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int t;\n  cin>>t;\n  while(t--){\n    int x,y,m;\n    cin>>x>>y>>m;\n    int l=mod_log(x,y,m);\n    if(l==m) l=-1;\n    cout<<l<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/dominatortree.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/dominatortree\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/dominatortree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,s;\n  cin>>n>>m>>s;\n  DominatorTree G(n);\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    G.add_edge(a,b);\n  }\n  G.build(s);\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<G[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/dynamic_sequence_range_affine_range_sum.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/dynamic_sequence_range_affine_range_sum\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../math/affine.cpp\"\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/lazy.cpp\"\n#include \"../../bbst/rbst/impl/basic.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  using M = Mint<int, 998244353>;\n  using T = pair<M, M>;\n  using E = pair<M, M>;\n  auto [f,g,h,ti,ei]=Affine::params<T, E>();\n\n  auto flip=[](T a){return a;};\n  using Data = decltype(Lazy(f,g,h,flip,ti,ei));\n  using Node = Data::Node;\n  constexpr size_t LIM = 1e6;\n  Basic<Data, LIM> G(f,g,h,flip,ti,ei);\n\n  int n,q;\n  cin>>n>>q;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n  vector<Node> vt;\n  for(int i=0;i<n;i++) vt.emplace_back(T(as[i],1),ei);\n  auto rt=G.build(vt);\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int k,x;\n      cin>>k>>x;\n      rt=G.insert(rt,k,Node(T(x,1),ei));\n    }\n    if(t==1){\n      int k;\n      cin>>k;\n      rt=G.erase(rt,k);\n    }\n    if(t==2){\n      int l,r;\n      cin>>l>>r;\n      rt=G.toggle(rt,l,r);\n    }\n    if(t==3){\n      int l,r,b,c;\n      cin>>l>>r>>b>>c;\n      rt=G.update(rt,l,r,E(b,c));\n    }\n    if(t==4){\n      int l,r;\n      cin>>l>>r;\n      cout<<G.query(rt,l,r).first<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/dynamic_tree_vertex_add_path_sum.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/dynamic_tree_vertex_add_path_sum\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/path.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  using ll = long long;\n  using Node = NodeBase<ll, ll>;\n  auto f=[&](ll a,ll b){return a+b;};\n  constexpr size_t LIM = 2e5+100;\n  using LCT = Path<Node, LIM>;\n  LCT lct(f,f,f,0);\n\n  for(int i=0;i<n;i++) lct.create(as[i]);\n\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    lct.evert(lct[v]);\n    lct.link(lct[u],lct[v]);\n  }\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int u,v,w,x;\n      cin>>u>>v>>w>>x;\n\n      lct.evert(lct[u]);\n      lct.cut(lct[v]);\n\n      lct.evert(lct[x]);\n      lct.link(lct[w],lct[x]);\n    }\n\n    if(t==1){\n      int p,x;\n      cin>>p>>x;\n      lct.evert(lct[p]);\n      lct.update(lct[p],x);\n    }\n\n    if(t==2){\n      int u,v;\n      cin>>u>>v;\n      lct.evert(lct[u]);\n      cout<<lct.query(lct[v])<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/dynamic_tree_vertex_add_subtree_sum.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/dynamic_tree_vertex_add_subtree_sum\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/subtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  using ll = long long;\n\n  int n,q;\n  cin>>n>>q;\n  vector<ll> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  using Node = NodeBase<ll>;\n  constexpr size_t LIM = 2e5+100;\n  using LCT = Subtree<Node, LIM>;\n  LCT lct;\n\n  for(int i=0;i<n;i++) lct.create(as[i]);\n\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    lct.evert(lct[v]);\n    lct.link(lct[u],lct[v]);\n  }\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int u,v,w,x;\n      cin>>u>>v>>w>>x;\n\n      lct.evert(lct[u]);\n      lct.cut(lct[v]);\n\n      lct.evert(lct[x]);\n      lct.link(lct[w],lct[x]);\n    }\n\n    if(t==1){\n      int p,x;\n      cin>>p>>x;\n      as[p]+=x;\n      lct.set_val(lct[p],as[p]);\n    }\n\n    if(t==2){\n      int v,p;\n      cin>>v>>p;\n      lct.evert(lct[p]);\n      lct.cut(lct[v]);\n      cout<<lct.query(lct[v])<<newl;\n      lct.link(lct[p],lct[v]);\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/dynamic_tree_vertex_add_subtree_sum.toptree.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/dynamic_tree_vertex_add_subtree_sum\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../toptree/toptree.cpp\"\n#undef call_from_test\n\nusing ll = long long;\nstruct Vertex{\n  void* handle;\n  ll val;\n  Vertex(ll val=0):handle(nullptr),val(val){}\n};\n\nstruct Cluster{\n  ll res;\n  Cluster(ll res=0):res(res){}\n  void toggle(){}\n  static Cluster compress(Cluster x,Vertex* v,Cluster y){\n    return Cluster(x.res+v->val+y.res);\n  }\n  static Cluster rake(Cluster x,Cluster y){\n    return Cluster(x.res+y.res);\n  }\n};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  const size_t N = 2e5;\n  TopTree<Vertex, Cluster, N> G;\n\n  int n,q;\n  cin>>n>>q;\n  vector<ll> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++)\n    vs[i]=G.create(as[i]);\n\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    G.link(vs[u],Cluster(0),vs[v]);\n  }\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n\n    if(t==0){\n      int u,v,w,x;\n      cin>>u>>v>>w>>x;\n\n      G.cut(vs[u],vs[v]);\n      G.link(vs[w],Cluster(0),vs[x]);\n    }\n\n    if(t==1){\n      int p,x;\n      cin>>p>>x;\n      as[p]+=x;\n      G.set_vertex(vs[p],Vertex(as[p]));\n    }\n\n    if(t==2){\n      int v,p;\n      cin>>v>>p;\n      cout<<as[v]+G.get_subtree(vs[p],vs[v]).res<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/dynamic_tree_vertex_set_path_composite.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/dynamic_tree_vertex_set_path_composite\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../math/linearfunction.cpp\"\n#include \"../../math/dual.cpp\"\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/path.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n  vector<int> as(n),bs(n);\n  for(int i=0;i<n;i++) cin>>as[i]>>bs[i];\n\n  using M = Mint<int, 998244353>;\n  using LF = LinearFunction<M>;\n  using DL = Dual<LF>;\n\n  using P = pair<LF, DL>;\n  using Node = NodeBase<P, int>;\n  auto f=[&](P a,P b){return P(a.first*b.first,a.second*b.second);};\n  auto g=[&](P a,int){return a;};\n  auto h=[&](int a,int){return a;};\n  auto flip=[&](P a){return P(a.second.v,a.first);};\n\n  constexpr size_t LIM = 2e5+100;\n  using LCT = Path<Node, LIM>;\n  LCT lct(f,g,h,flip,0);\n\n  for(int i=0;i<n;i++) lct.create(P(LF(as[i],bs[i]),LF(as[i],bs[i])));\n\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    lct.evert(lct[v]);\n    lct.link(lct[u],lct[v]);\n  }\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n\n    if(t==0){\n      int u,v,w,x;\n      cin>>u>>v>>w>>x;\n\n      lct.evert(lct[u]);\n      lct.cut(lct[v]);\n\n      lct.evert(lct[x]);\n      lct.link(lct[w],lct[x]);\n    }\n\n    if(t==1){\n      int p,c,d;\n      cin>>p>>c>>d;\n      lct.set_val(lct[p],P(LF(c,d),LF(c,d)));\n    }\n\n    if(t==2){\n      int u,v,x;\n      cin>>u>>v>>x;\n      lct.evert(lct[u]);\n      cout<<lct.query(lct[v]).first(x)<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/dynamic_tree_vertex_set_path_composite.toptree.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/dynamic_tree_vertex_set_path_composite\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../math/linearfunction.cpp\"\n#include \"../../math/twoway.cpp\"\n#include \"../../toptree/toptree.cpp\"\n#undef call_from_test\n\nusing M = Mint<int, 998244353>;\nusing L = LinearFunction<M>;\nusing P = TwoWay<L>;\n\nstruct Vertex{\n  void* handle;\n  L val;\n  Vertex(L val=L()):handle(nullptr),val(val){}\n};\n\nstruct Cluster{\n  P res;\n  Cluster():res(L(1,0)){}\n  Cluster(L val):res(val){}\n  Cluster(P res):res(res){}\n  void toggle(){swap(res.x,res.y);}\n  static Cluster compress(Cluster x,Vertex* v,Cluster y){\n    return Cluster(x.res*P(v->val)*y.res);\n  }\n  static Cluster rake(Cluster x,Cluster){\n    return x;\n  }\n};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  const size_t N = 2e5 + 10;\n  TopTree<Vertex, Cluster, N> G;\n\n  int n,q;\n  cin>>n>>q;\n  vector<int> as(n),bs(n);\n  for(int i=0;i<n;i++) cin>>as[i]>>bs[i];\n\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++)\n    vs[i]=G.create(L(as[i],bs[i]));\n\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    G.link(vs[u],Cluster(L(1,0)),vs[v]);\n  }\n\n  Vertex* du=G.create(L(1,0));\n  Vertex* dv=G.create(L(1,0));\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n\n    if(t==0){\n      int u,v,w,x;\n      cin>>u>>v>>w>>x;\n\n      G.cut(vs[u],vs[v]);\n      G.link(vs[w],Cluster(L(1,0)),vs[x]);\n    }\n\n    if(t==1){\n      int p,c,d;\n      cin>>p>>c>>d;\n      G.set_vertex(vs[p],Vertex(L(c,d)));\n    }\n\n    if(t==2){\n      int u,v,x;\n      cin>>u>>v>>x;\n\n      G.link(du,Cluster(L(1,0)),vs[u]);\n      G.link(dv,Cluster(L(1,0)),vs[v]);\n\n      auto res=G.get_path(du,dv).res.x;\n      cout<<res(x)<<newl;\n\n      G.cut(du,vs[u]);\n      G.cut(dv,vs[v]);\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/enumerate_primes.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/enumerate_primes\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/enumerate_primes.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,a,b;\n  cin>>n>>a>>b;\n\n  auto ps=enumerate_primes(n);\n  vector<int> qs;\n  for(int i=b;i<(int)ps.size();i+=a)\n    qs.emplace_back(ps[i]);\n\n  cout<<ps.size()<<' '<<qs.size()<<endl;\n  for(int i=0;i<(int)qs.size();i++){\n    if(i) cout<<' ';\n    cout<<qs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/enumerate_triangles.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/enumerate_triangles\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/triangle.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  int n,m;\n  cin>>n>>m;\n  vector<ll> xs(n);\n  for(int i=0;i<n;i++) cin>>xs[i];\n\n  Triangle G(n);\n  for(int i=0;i<m;i++){\n    int u,v;\n    cin>>u>>v;\n    G.add_edge(u,v);\n  }\n\n  const ll mod = 998244353;\n  ll ans=0;\n  auto f=[&](int x,int y,int z){\n    ans+=xs[x]*xs[y]%mod*xs[z]%mod;\n    ans%=mod;\n  };\n  G.build(f);\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/exp_of_formal_power_series.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/exp_of_formal_power_series\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/integral.cpp\"\n#include \"../../formalpowerseries/diff.cpp\"\n#include \"../../formalpowerseries/log.cpp\"\n#include \"../../formalpowerseries/exp.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  vector<M> as(n);\n  for(int i=0;i<n;i++) cin>>as[i].v;\n\n  auto bs=FPS.exp(as,n);\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<bs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/find_linear_recurrence.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/find_linear_recurrence\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../polynomial/berlekampmassey.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using M = Mint<int, 998244353>;\n  vector<M> as(n);\n  for(int i=0;i<n;i++) cin>>as[i].v;\n\n  auto cs=berlekamp_massey(as);\n  cs.pop_back();\n  reverse(cs.begin(),cs.end());\n  cout<<cs.size()<<endl;\n  for(int i=0;i<(int)cs.size();i++){\n    if(i) cout<<\" \";\n    cout<<-cs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/frequency_table_of_tree_distance.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/frequency_table_of_tree_distance\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/centroid.cpp\"\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../convolution/fastfouriertransform.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  Centroid G(n);\n  for(int i=1;i<n;i++){\n    int a,b;\n    cin>>a>>b;\n    G.add_edge(a,b);\n  }\n\n  queue<int> que;\n  que.emplace(G.build(0)[0]);\n\n  using ll = long long;\n  vector<ll> ans(n,0);\n  while(!que.empty()){\n    int r=que.front();que.pop();\n\n    vector<ll> cnt;\n    cnt.emplace_back(1);\n    for(int c:G[r]){\n      if(!G.alive(c)) continue;\n      vector<ll> num;\n      MFP([&](auto dfs,int v,int p,int d)->void{\n        while((int)cnt.size()<=d)\n          cnt.emplace_back(0);\n        while((int)num.size()<=d)\n          num.emplace_back(0);\n        cnt[d]++;\n        num[d]++;\n        for(int u:G[v]){\n          if(u==p or !G.alive(u)) continue;\n          dfs(u,v,d+1);\n        }\n      })(c,r,1);\n      auto ns=FFT::multiply(num,num);\n      for(int i=0;i<(int)min(ans.size(),ns.size());i++) ans[i]-=ns[i];\n    }\n    auto cs=FFT::multiply(cnt,cnt);\n    for(int i=0;i<(int)min(ans.size(),cs.size());i++) ans[i]+=cs[i];\n\n    G.disable(r);\n    for(int c:G[r])\n      if(G.alive(c))\n        que.emplace(G.build(c)[0]);\n  }\n\n  for(int i=1;i<n;i++){\n    if(i!=1) cout<<' ';\n    cout<<ans[i]/2;\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/inv_of_formal_power_series.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/inv_of_formal_power_series\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  vector<M> as(n);\n  for(int i=0;i<n;i++) cin>>as[i].v;\n\n  auto bs=FPS.inv(as,n);\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<bs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/kth_root_integer.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/kth_root_integer\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/int128.cpp\"\n#undef call_from_test\n\n#ifdef __clang__\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int T;\n  cin>>T;\n\n  using ll = __int128_t;\n  for(int t=0;t<T;t++){\n    ll A,K;\n    cin>>A>>K;\n\n    ll L=0,R=A+1;\n    while(L+1<R){\n      ll M=(L+R)>>1;\n\n      ll res=1;\n      for(int i=0;i<K;i++){\n        res*=M;\n        if(res>A) break;\n      }\n\n      if(res<=A) L=M;\n      else R=M;\n    }\n\n    cout<<L<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/kth_term_of_linearly_recurrent_sequence.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/kth_term_of_linearly_recurrent_sequence\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../math/bostanmori.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  NTT<2> ntt;\n  using M = decltype(ntt)::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n\n  int d;\n  cin>>d;\n\n  long long k;\n  cin>>k;\n\n  vector<M> as(d),cs(d);\n  for(int i=0;i<d;i++) cin>>as[i].v;\n  for(int i=0;i<d;i++) cin>>cs[i].v;\n\n  reverse(cs.begin(),cs.end());\n  for(auto &c:cs) c=-c;\n  cs.emplace_back(1);\n\n  BostanMori<M> seq(conv);\n  cout<<seq.build(k,as,cs)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/lca.linkcuttree.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/lca\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../linkcuttree/base.cpp\"\n#include \"../../linkcuttree/path.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  using Node = NodeBase<int, int>;\n  constexpr size_t LIM = 1e6;\n  using LCT = Path<Node, LIM>;\n\n  auto f=[](int a,int b){return a+b;};\n  LCT lct(f,f,f,0);\n  for(int i=0;i<n;i++) lct.create(0);\n\n  for(int i=1;i<n;i++){\n    int p;\n    cin>>p;\n    lct.link(lct[p],lct[i]);\n  }\n\n  for(int i=0;i<q;i++){\n    int u,v;\n    cin>>u>>v;\n    cout<<lct.idx(lct.lca(lct[u],lct[v]))<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/lca.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/lca\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/lowestcommonancestor.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  LowestCommonAncestor G(n);\n  for(int i=1;i<n;i++){\n    int p;\n    cin>>p;\n    G.add_edge(p,i);\n  }\n  G.build();\n\n  for(int i=0;i<q;i++){\n    int u,v;\n    cin>>u>>v;\n    cout<<G.lca(u,v)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/line_add_get_min.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/line_add_get_min\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../convexhulltrick/segmentcontainer.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n,q;\n  cin>>n>>q;\n  vector<ll> as(n),bs(n);\n  for(int i=0;i<n;i++) cin>>as[i]>>bs[i];\n\n  vector<ll> ts(q),xs(q),ys(q);\n  vector<ll> ps;\n  for(int i=0;i<q;i++){\n    cin>>ts[i];\n    if(ts[i]==0) cin>>xs[i]>>ys[i];\n    if(ts[i]==1) cin>>xs[i];\n    ps.emplace_back(xs[i]);\n  }\n  int lb=-1e9,ub=+1e9;\n  ps.emplace_back(lb);\n  ps.emplace_back(ub);\n  MinSegmentContainer<ll> seg(ps);\n\n  for(int i=0;i<n;i++) seg.add(as[i],bs[i],lb,ub);\n  for(int i=0;i<q;i++){\n    if(ts[i]==0) seg.add(xs[i],ys[i],lb,ub);\n    if(ts[i]==1) cout<<seg.query(xs[i])<<\"\\n\";\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/log_of_formal_power_series.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/log_of_formal_power_series\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/integral.cpp\"\n#include \"../../formalpowerseries/diff.cpp\"\n#include \"../../formalpowerseries/log.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  vector<M> as(n);\n  for(int i=0;i<n;i++) cin>>as[i].v;\n\n  auto bs=FPS.log(as,n);\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<bs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/manhattanmst.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/manhattanmst\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/manhattanmst.cpp\"\n#include \"../../datastructure/unionfind.cpp\"\n#include \"../../graph/kruskal.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  using ll = long long;\n\n  int n;\n  cin>>n;\n  vector<ll> xs(n),ys(n);\n  for(int i=0;i<n;i++) cin>>xs[i]>>ys[i];\n\n  Kruskal<ll> mst(n);\n  for(auto[u,v]:manhattanmst(xs,ys))\n    mst.add_edge(u,v,abs(xs[u]-xs[v])+abs(ys[u]-ys[v]));\n\n  cout<<mst.build()<<newl;\n  for(auto e:mst.es)\n    if(e.used) cout<<e.src<<' '<<e.dst<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/many_aplusb.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/many_aplusb\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/fastio.cpp\"\n#undef call_from_test\n\nsigned main(){\n  const char newl = '\\n';\n  int t;\n  cin>>t;\n  for(int i=0;i<t;i++){\n    long long a,b;\n    cin>>a>>b;\n    cout<<a+b<<newl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/matrix_det.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/matrix_det\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../linearalgebra/matrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using M = Mint<int, 998244353>;\n  using Mat = Matrix<M>;\n  int n;\n  cin>>n;\n\n  Mat A(n,n);\n  for(int i=0;i<n;i++)\n    for(int j=0;j<n;j++)\n      cin>>A[i][j].v;\n\n  cout<<A.determinant()<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/maximum_independent_set.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/maximum_independent_set\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/independentset.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  IndependentSet G(n);\n  for(int i=0;i<m;i++){\n    int u,v;\n    cin>>u>>v;\n    G.add_edge(u,v);\n  }\n  int X=G.build();\n  cout<<X<<endl;\n  for(int i=0;i<X;i++){\n    if(i) cout<<\" \";\n    cout<<G.ans[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/min_cost_b_flow.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/min_cost_b_flow\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bflow/capacityscaling.cpp\"\n#undef call_from_test\n\n#ifdef __clang__\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  using ll = long long;\n  MinCostFlow<ll, ll> G(n);\n  for(int i=0;i<n;i++){\n    int b;\n    cin>>b;\n    if(b>0) G.add_supply(i,+b);\n    if(b<0) G.add_demand(i,-b);\n  }\n\n  vector<decltype(G)::EdgePtr> es;\n  for(int i=0;i<m;i++){\n    int s,t,l,u,c;\n    cin>>s>>t>>l>>u>>c;\n    auto e=G.add_edge(s,t,l,u,c);\n    es.emplace_back(e);\n  }\n\n  if(!G.build()){\n    cout<<\"infeasible\\n\";\n    return 0;\n  }\n\n  auto print=[&](auto res){\n    if(res==0){\n      cout<<0<<'\\n';\n      return;\n    }\n    if(res<0) cout<<'-',res*=-1;\n    string ans;\n    while(res){\n      ans+=char('0'+res%10);\n      res/=10;\n    }\n    reverse(ans.begin(),ans.end());\n    cout<<ans<<'\\n';\n  };\n  print(G.get_cost<__int128_t>());\n\n  auto p=G.get_potential();\n  for(int i=0;i<n;i++) cout<<p[i]<<'\\n';\n  for(auto e:es) cout<<G.get_edge(e).flow<<'\\n';\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/montmort_number_mod.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/montmort_number_mod\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/montmort.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  Montmort<int> mm(n,m);\n  for(int i=1;i<=n;i++){\n    if(i) cout<<\" \";\n    cout<<mm[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/multipoint_evaluation.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/multipoint_evaluation\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/div.cpp\"\n#include \"../../formalpowerseries/mod.cpp\"\n#include \"../../polynomial/multieval.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  MultiEval<M> me(conv);\n\n  vector<M> cs(n),ps(m);\n  for(int i=0;i<n;i++) cin>>cs[i].v;\n  for(int i=0;i<m;i++) cin>>ps[i].v;\n\n  auto ans=me.build(cs,ps);\n  for(int i=0;i<m;i++){\n    if(i) cout<<\" \";\n    cout<<ans[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/number_of_substrings.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/number_of_substrings\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/suffixarray.cpp\"\n#include \"../../string/longestcommonprefix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string s;\n  cin>>s;\n  LongestCommonPrefix lcp(s);\n\n  int n=s.size();\n  long long ans=0;\n  for(int i=0;i<n;i++)\n    ans+=(n-lcp.sa[i+1])-lcp.query(i,i+1);\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/partition_function.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/partition_function\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../combinatorics/partition.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  Partition<M> ps(conv);\n\n  ps.build(n);\n  for(int i=0;i<=n;i++){\n    if(i) cout<<\" \";\n    cout<<ps[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/persistent_queue.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/persistent_queue\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../bbst/rbst/rbst.cpp\"\n#include \"../../bbst/rbst/data/array.cpp\"\n#include \"../../bbst/rbst/impl/persistent.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  using Data = Array<int>;\n  using Node = Data::Node;\n  const int LIM = 2e7;\n  Persistent<Data, LIM> pa;\n  Node* rt=pa.create(0);\n\n  int q;\n  cin>>q;\n  vector<Node*> ss(q,nullptr);\n  for(int i=0;i<q;i++){\n    int a;\n    cin>>a;\n    if(a==0){\n      int t,x;\n      cin>>t>>x;\n      Node* p=~t?ss[t]:rt;\n      ss[i]=pa.insert(p,p->cnt,Node(x));\n    }\n    if(a==1){\n      int t;\n      cin>>t;\n      cout<<pa.get_val(ss[t],1)<<newl;\n      ss[i]=pa.erase(ss[t],1);\n    }\n  }\n\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/point_add_range_sum.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/point_add_range_sum\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  BIT<long long> bit(n);\n  for(int i=0;i<n;i++) bit.add(i,as[i]);\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int p,x;\n      cin>>p>>x;\n      bit.add(p,x);\n    }\n    if(t==1){\n      int l,r;\n      cin>>l>>r;\n      cout<<bit.query(l,r)<<'\\n';\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/point_add_rectangle_sum.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/point_add_rectangle_sum\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../vector/compress.cpp\"\n#include \"../../segtree/count/dynamic_offline.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  vector<int> xs(n+q),ys(n+q),ws(n+q);\n  for(int i=0;i<n;i++)\n    cin>>xs[i]>>ys[i]>>ws[i];\n\n  vector<int> ts(q);\n  vector<int> ls(q),ds(q),rs(q),us(q);\n  for(int i=0;i<q;i++){\n    cin>>ts[i];\n    if(ts[i]==0) cin>>xs[n+i]>>ys[n+i]>>ws[n+i];\n    if(ts[i]==1) cin>>ls[i]>>ds[i]>>rs[i]>>us[i];\n  }\n\n  auto vs=compress(xs);\n  auto idx=\n    [&](int x){return lower_bound(vs.begin(),vs.end(),x)-vs.begin();};\n\n  using ll = long long;\n  RangeCount<int, ll> seg(vs.size());\n\n  for(int i=0;i<n;i++)\n    seg.preupdate(idx(xs[i]),ys[i]);\n\n  for(int i=0;i<q;i++)\n    if(ts[i]==0) seg.preupdate(idx(xs[n+i]),ys[n+i]);\n\n  seg.build();\n\n  for(int i=0;i<n;i++)\n    seg.update(idx(xs[i]),ys[i],ws[i]);\n\n  for(int i=0;i<q;i++){\n    if(ts[i]==0) seg.update(idx(xs[n+i]),ys[n+i],ws[n+i]);\n    if(ts[i]==1) cout<<seg.query(idx(ls[i]),idx(rs[i]),ds[i],us[i])<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/point_set_range_composite.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/point_set_range_composite\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../math/linearfunction.cpp\"\n#include \"../../segtree/basic/ushi.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  vector<int> as(n),bs(n);\n  for(int i=0;i<n;i++) cin>>as[i]>>bs[i];\n\n  using M = Mint<int, 998244353>;\n  using T = LinearFunction<M>;\n  auto f=[&](T x,T y){return x*y;};\n  T ti=T::mul_identity();\n  SegmentTree<T> seg(f,ti);\n\n  vector<T> vt;\n  for(int i=0;i<n;i++) vt.emplace_back(as[i],bs[i]);\n  seg.build(vt);\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int p,c,d;\n      cin>>p>>c>>d;\n      seg.set_val(p,T(M(c),M(d)));\n    }\n    if(t==1){\n      int l,r,x;\n      cin>>l>>r>>x;\n      cout<<seg.query(l,r)(x)<<\"\\n\";\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/polynomial_interpolation.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/polynomial_interpolation\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/div.cpp\"\n#include \"../../formalpowerseries/mod.cpp\"\n#include \"../../formalpowerseries/diff.cpp\"\n#include \"../../polynomial/multieval.cpp\"\n#include \"../../polynomial/interpolate.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  Interpolate<M> ip(conv);\n\n  vector<M> xs(n),ys(n);\n  for(int i=0;i<n;i++) cin>>xs[i].v;\n  for(int i=0;i<n;i++) cin>>ys[i].v;\n\n  auto ans=ip.build(xs,ys);\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<ans[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/polynomial_taylor_shift.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/polynomial_taylor_shift\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/shift.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,c;\n  cin>>n>>c;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  vector<M> as(n);\n  for(int i=0;i<n;i++) cin>>as[i].v;\n\n  auto bs=FPS.shift(as,M(c));\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<bs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/pow_of_formal_power_series.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/pow_of_formal_power_series\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/integral.cpp\"\n#include \"../../formalpowerseries/diff.cpp\"\n#include \"../../formalpowerseries/log.cpp\"\n#include \"../../formalpowerseries/exp.cpp\"\n#include \"../../formalpowerseries/pow.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  vector<M> as(n);\n  for(int i=0;i<n;i++) cin>>as[i].v;\n\n  auto bs=FPS.pow(as,m,n);\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<bs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/queue_operate_all_composite.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/queue_operate_all_composite\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../math/linearfunction.cpp\"\n#include \"../../datastructure/slidingwindowaggregation.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using M = Mint<int, 998244353>;\n  using T = LinearFunction<M>;\n  auto f=[](T a,T b){return a*b;};\n  SWAG<T, T> swag(f,T::mul_identity());\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int a,b;\n      cin>>a>>b;\n      swag.push(T(M(a),M(b)));\n    }\n    if(t==1){\n      swag.pop();\n    }\n    if(t==2){\n      int x;\n      cin>>x;\n      swag.fold([&](T a,T b){cout<<f(a,b)(x)<<\"\\n\";});\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/range_affine_range_sum.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/range_affine_range_sum\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../math/affine.cpp\"\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  using M = Mint<int, 998244353>;\n  using T = pair<M, M>;\n  using E = pair<M, M>;\n  auto [f,g,h,ti,ei]=Affine::params<T, E>();\n  SegmentTree<T, E> seg(f,g,h,ti,ei);\n\n  int n,q;\n  cin>>n>>q;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n  vector<T> vt;\n  for(int i=0;i<n;i++) vt.emplace_back(as[i],1);\n  seg.build(vt);\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int l,r,b,c;\n      cin>>l>>r>>b>>c;\n      seg.update(l,r,T(M(b),M(c)));\n    }\n    if(t==1){\n      int l,r;\n      cin>>l>>r;\n      cout<<seg.query(l,r).first<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/range_kth_smallest.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/range_kth_smallest\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/waveletmatrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  WaveletMatrix<int, 30> wm(as);\n\n  for(int i=0;i<q;i++){\n    int l,r,k;\n    cin>>l>>r>>k;\n    cout<<wm.rquantile(l,r,k)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/rectangle_sum.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/rectangle_sum\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../vector/compress.cpp\"\n#include \"../../segtree/count/dynamic_offline.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  vector<int> xs(n),ys(n),ws(n);\n  for(int i=0;i<n;i++) cin>>xs[i]>>ys[i]>>ws[i];\n\n  auto vs=compress(xs);\n  auto idx=\n    [&](int x){return lower_bound(vs.begin(),vs.end(),x)-vs.begin();};\n\n  using ll = long long;\n  RangeCount<int, ll> seg(vs.size());\n\n  for(int i=0;i<n;i++)\n    seg.preupdate(idx(xs[i]),ys[i]);\n\n  seg.build();\n\n  for(int i=0;i<n;i++)\n    seg.update(idx(xs[i]),ys[i],ws[i]);\n\n  for(int i=0;i<q;i++){\n    int l,d,r,u;\n    cin>>l>>d>>r>>u;\n    cout<<seg.query(idx(l),idx(r),d,u)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/runenumerate.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/runenumerate\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/zalgorithm.cpp\"\n#include \"../../string/run.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string ss;\n  cin>>ss;\n  auto run=Run::enumerate(ss);\n\n  set<Run::P> vis;\n  vector<Run::T> ans;\n  for(int t=1;t<=(int)ss.size();t++){\n    for(auto lr:run[t]){\n      if(vis.count(lr)) continue;\n      vis.emplace(lr);\n      ans.emplace_back(t,lr.first,lr.second);\n    }\n  }\n\n  cout<<ans.size()<<endl;\n  for(auto tlr:ans){\n    int t,l,r;\n    tie(t,l,r)=tlr;\n    cout<<t<<\" \"<<l<<\" \"<<r<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/scc.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/scc\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  SCC G(n);\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    G.add_edge(a,b);\n  }\n  int k=G.build();\n  cout<<k<<endl;\n  for(int i=0;i<k;i++){\n    cout<<G.C[i].size();\n    for(int v:G.C[i]) cout<<\" \"<<v;\n    cout<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/segment_add_get_min.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/segment_add_get_min\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../convexhulltrick/segmentcontainer.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n,q;\n  cin>>n>>q;\n  vector<ll> ls(n),rs(n),as(n),bs(n);\n  for(int i=0;i<n;i++) cin>>ls[i]>>rs[i]>>as[i]>>bs[i];\n\n  vector<ll> ts(q),v0(q),v1(q),v2(q),v3(q);\n  for(int i=0;i<q;i++){\n    cin>>ts[i];\n    if(ts[i]==0) cin>>v0[i]>>v1[i]>>v2[i]>>v3[i];\n    if(ts[i]==1) cin>>v0[i];\n  }\n\n  vector<ll> ps;\n  for(int i=0;i<n;i++){\n    ps.emplace_back(ls[i]);\n    ps.emplace_back(rs[i]);\n  }\n  for(int i=0;i<q;i++){\n    ps.emplace_back(v0[i]);\n    ps.emplace_back(v1[i]);\n  }\n  MinSegmentContainer<ll> seg(ps);\n\n  for(int i=0;i<n;i++) seg.add(as[i],bs[i],ls[i],rs[i]);\n  for(int i=0;i<q;i++){\n    if(ts[i]==0) seg.add(v2[i],v3[i],v0[i],v1[i]);\n    if(ts[i]==1){\n      auto res=seg.query(v0[i]);\n      if(res>2e18) cout<<\"INFINITY\"<<'\\n';\n      else cout<<res<<\"\\n\";\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/set_xor_min.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/set_xor_min\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/binarytrie.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  BinaryTrie<int, 30> bt;\n\n  int q;\n  cin>>q;\n\n  for(int i=0;i<q;i++){\n    int t,x;\n    cin>>t>>x;\n    if(t==0){\n      if(bt.find(x)) continue;\n      bt.add(x,1);\n    }\n    if(t==1){\n      if(!bt.find(x)) continue;\n      bt.sub(bt.find(x),1);\n    }\n    if(t==2){\n      cout<<(x^bt.val(bt.xmin(x)))<<newl;\n    }\n  }\n\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/sharp_p_subset_sum.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/sharp_p_subset_sum\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/integral.cpp\"\n#include \"../../formalpowerseries/diff.cpp\"\n#include \"../../formalpowerseries/log.cpp\"\n#include \"../../formalpowerseries/exp.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,t;\n  cin>>n>>t;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n  decltype(FPS)::init(t+1);\n\n  vector<int> cnt(t+1,0);\n  for(int i=0;i<n;i++){\n    int s;\n    cin>>s;\n    cnt[s]++;\n  }\n\n  vector<M> as(t+1);\n  for(int s=1;s<=t;s++){\n    for(int k=1;s*k<=t;k++){\n      if(k&1) as[s*k]+=M(cnt[s])*decltype(FPS)::Invs(k);\n      else as[s*k]-=M(cnt[s])*decltype(FPS)::Invs(k);\n    }\n  }\n\n  auto bs=FPS.exp(as,t+1);\n  for(int i=1;i<=t;i++){\n    if(i>1) cout<<\" \";\n    cout<<bs[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/shortest_path.test.cpp",
    "content": "#define PROBLEM \"https://judge.yosupo.jp/problem/shortest_path\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/drop.cpp\"\n#include \"../../graph/dijkstra.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,m,s,t;\n  cin>>n>>m>>s>>t;\n\n  using ll = long long;\n  Dijkstra<ll> G(n);\n  for(int i=0;i<m;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    G.add_edge(a,b,c);\n  }\n\n  G.build(s);\n  auto ps=G.restore(t);\n  if(ps.empty()) drop(-1);\n\n  int y=ps.size()-1;\n  cout<<G[t]<<' '<<y<<newl;\n  for(int i=0;i<y;i++) cout<<ps[i]<<' '<<ps[i+1]<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/sort_points_by_argument.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/sort_points_by_argument\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../geometry/argsort.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using ll = long long;\n  struct Point{ll x,y;};\n  vector<Point> ps(n);\n  for(int i=0;i<n;i++) cin>>ps[i].x>>ps[i].y;\n\n  argsort(ps);\n\n  for(int i=0;i<n;i++) cout<<ps[i].x<<\" \"<<ps[i].y<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/sqrt_mod.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/sqrt_mod\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/sqrt.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int T;\n  cin>>T;\n  for(int t=0;t<T;t++){\n    int y,p;\n    cin>>y>>p;\n    auto res=mod_sqrt(y,p);\n    if(res.empty()) cout<<-1<<\"\\n\";\n    else cout<<res[0]<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/sqrt_of_formal_power_series.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/sqrt_of_formal_power_series\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/drop.cpp\"\n#include \"../../mod/sqrt.cpp\"\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/sqrt.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  deque<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  while(!as.empty()&&as.front()==0) as.pop_front();\n\n  if(as.empty()){\n    for(int i=0;i<n;i++){\n      if(i) cout<<\" \";\n      cout<<0;\n    }\n    cout<<endl;\n    return 0;\n  }\n\n  int m=as.size();\n  if((n-m)&1) drop(-1);\n\n  auto ss=mod_sqrt(as[0],ntt.md);\n  if(ss.empty()) drop(-1);\n\n  vector<M> ps(n,M(0));\n  for(int i=0;i<m;i++) ps[i]=M(as[i])/M(as[0]);\n\n  auto bs=FPS.sqrt(ps,n);\n  bs.insert(bs.begin(),(n-m)/2,M(0));\n  for(int i=0;i<n;i++){\n    if(i) cout<<\" \";\n    cout<<bs[i]*ss[0];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/static_range_frequency.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/static_range_frequency\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../datastructure/waveletmatrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  auto as=read(n);\n  WaveletMatrix<int, 30> wm(as);\n\n  for(int i=0;i<q;i++){\n    int l,r,x;\n    cin>>l>>r>>x;\n    cout<<wm.rank(x,r)-wm.rank(x,l)<<'\\n';\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/static_range_inversions_query.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/static_range_inversions_query\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../algorithm/mo.cpp\"\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  auto as=read(n);\n  auto dc=dict(compress(as));\n  vector<int> cs(n);\n  for(int i=0;i<n;i++) cs[i]=dc[as[i]];\n\n  using ll = long long;\n  ll res=0;\n  vector<ll> ans(q);\n  BIT<int> bit(n);\n  auto expandL=[&](int i){bit.add(cs[i],+1);res+=bit.query(0,cs[i]);};\n  auto expandR=[&](int i){bit.add(cs[i],+1);res+=bit.query(cs[i]+1,n);};\n  auto shrinkL=[&](int i){bit.add(cs[i],-1);res-=bit.query(0,cs[i]);};\n  auto shrinkR=[&](int i){bit.add(cs[i],-1);res-=bit.query(cs[i]+1,n);};\n\n  Mo mo(n,400,expandL,expandR,shrinkL,shrinkR);\n  for(int i=0;i<q;i++){\n    int l,r;\n    cin>>l>>r;\n    mo.add(l,r);\n  }\n  mo.build();\n\n  for(int i=0;i<q;i++){\n    int k=mo.process();\n    ans[k]=res;\n  }\n\n  for(auto a:ans) cout<<a<<'\\n';\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/static_range_sum.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/static_range_sum\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/cumulativesum.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  using ll = long long;\n\n  int n,q;\n  cin>>n>>q;\n  vector<ll> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  CumulativeSum cs(as);\n  for(int i=0;i<q;i++){\n    int l,r;\n    cin>>l>>r;\n    cout<<cs.query(l,r)<<newl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/staticrmq.disjointsparsetable.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/staticrmq\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/disjointsparsetable.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto f=[](int a,int b){return min(a,b);};\n  DisjointSparseTable<int> rmq(f);\n  rmq.build(as);\n\n  for(int i=0;i<q;i++){\n    int l,r;\n    cin>>l>>r;\n    cout<<rmq.query(l,r)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/staticrmq.sparsetable.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/staticrmq\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/sparsetable.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto f=[](int a,int b){return min(a,b);};\n  SparseTable<int> rmq(f);\n  rmq.build(as);\n\n  for(int i=0;i<q;i++){\n    int l,r;\n    cin>>l>>r;\n    cout<<rmq.query(l,r)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/stirling_number_of_the_first_kind.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/stirling_number_of_the_first_kind\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../combinatorics/stirling1st.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  Stirling1st<M> ss(conv);\n\n  ss.build(n);\n  for(int i=0;i<=n;i++){\n    if(i) cout<<\" \";\n    cout<<ss[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/stirling_number_of_the_second_kind.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/stirling_number_of_the_second_kind\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../combinatorics/stirling2nd.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  NTT<2> ntt;\n  using M = NTT<2>::M;\n  auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);};\n  Stirling2nd<M> ss(conv);\n\n  ss.build(n);\n  for(int i=0;i<=n;i++){\n    if(i) cout<<\" \";\n    cout<<ss[i];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/subset_convolution.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/subset_convolution\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/bitwise/fwht.cpp\"\n#include \"../../convolution/bitwise/or.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using M = Mint<int, 998244353>;\n  using V = valarray<M>;\n\n  int sz=1<<n;\n\n  vector<V> as(sz,V(n+1)),bs(sz,V(n+1));\n  for(int i=0;i<sz;i++) cin>>as[i][__builtin_popcount(i)].v;\n  for(int i=0;i<sz;i++) cin>>bs[i][__builtin_popcount(i)].v;\n\n  fwht(as,bitwise_or::zeta);\n  fwht(bs,bitwise_or::zeta);\n\n  vector<V> cs(sz,V(n+1));\n  for(int i=0;i<sz;i++)\n    for(int j=0;j<=n;j++)\n      for(int k=0;j+k<=n;k++)\n        cs[i][j+k]+=as[i][j]*bs[i][k];\n\n  fwht(cs,bitwise_or::moebius);\n\n  for(int i=0;i<sz;i++){\n    if(i) cout<<' ';\n    cout<<cs[i][__builtin_popcount(i)];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/suffixarray.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/suffixarray\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/suffixarray.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string s;\n  cin>>s;\n\n  SuffixArray sa(s);\n  for(int i=0;i<(int)s.size();i++){\n    if(i) cout<<\" \";\n    cout<<sa[i+1];\n  }\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/sum_of_floor_of_linear.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/sum_of_floor_of_linear\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/sum_of_floor.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int T;\n  cin>>T;\n  for(int t=0;t<T;t++){\n    long long n,m,a,b;\n    cin>>n>>m>>a>>b;\n    cout<<sum_of_floor(n,m,a,b)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/tetration_mod.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/tetration_mod\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/totient.cpp\"\n#include \"../../mod/tetration.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int T;\n  cin>>T;\n  for(int t=0;t<T;t++){\n    int a,b,m;\n    cin>>a>>b>>m;\n    cout<<tetration(a,b,m)<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/tree_decomposition_width_2.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/tree_decomposition_width_2\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/drop.cpp\"\n#include \"../../graph/nicetree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  {string s;cin>>s;}\n  {string s;cin>>s;}\n\n  int n,m;\n  cin>>n>>m;\n  NiceTree G(n);\n  for(int i=0;i<m;i++){\n    int u,v;\n    cin>>u>>v;\n    u--;v--;\n    G.add_edge(u,v);\n  }\n\n  G.build();\n  auto T=G.T;\n  if(T.empty()) drop(-1);\n\n  assert((int)T.size()<=3*n+m+10);\n  cout<<\"s td \"<<T.size()<<' '<<2<<' '<<n<<newl;\n\n  for(int i=0;i<(int)T.size();i++){\n    cout<<\"b \"<<i+1;\n    for(int v:T[i].bag) cout<<' '<<v+1;\n    cout<<newl;\n  }\n\n  for(int i=0;i<(int)T.size();i++)\n    for(int j:T[i].child) cout<<i+1<<' '<<j+1<<newl;\n\n  for(int i=1;i<(int)T.size();i++)\n    if(T[i].is_root) cout<<1<<' '<<i+1<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/tree_diameter.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/tree_diameter\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../tree/diameterforedge.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  using ll = long long;\n  int n;\n  cin>>n;\n  DiameterForEdge<ll> G(n);\n  for(int i=1;i<n;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    G.add_edge(a,b,c);\n  }\n\n  auto seq=G.restore();\n  cout<<G.build()<<' '<<seq.size()<<newl;\n  for(int i=0;i<(int)seq.size();i++){\n    if(i) cout<<' ';\n    cout<<seq[i];\n  }\n  cout<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/two_edge_connected_components.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/two_edge_connected_components\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/twoedgeconnectedcomponents.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  TwoEdgeConnectedComponents C(n);\n  for(int i=0;i<m;i++){\n    int a,b;\n    cin>>a>>b;\n    C.add_edge(a,b);\n  }\n\n  int k=C.build();\n  cout<<k<<endl;\n  for(int i=0;i<k;i++){\n    cout<<C[i].size();\n    for(int j=0;j<(int)C[i].size();j++) cout<<\" \"<<C[i][j];\n    cout<<\"\\n\";\n  }\n\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/two_sat.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/two_sat\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#include \"../../graph/twosatisfiability.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string s;\n  cin>>s;\n  cin>>s;\n\n  int n,m;\n  cin>>n>>m;\n\n  TwoSat ts(n+1);\n  for(int i=0;i<m;i++){\n    int a,b,c;\n    cin>>a>>b>>c;\n    if(a<0) a=ts.negate(abs(a));\n    if(b<0) b=ts.negate(abs(b));\n    ts.add_or(a,b);\n  }\n\n  auto res=ts.build();\n  if(res.empty()){\n    cout<<\"s UNSATISFIABLE\"<<endl;\n    return 0;\n  }\n\n  cout<<\"s SATISFIABLE\"<<endl;\n  cout<<\"v\";\n  for(int i=1;i<=n;i++)\n    cout<<\" \"<<(res[i]?i:-i);\n  cout<<\" \"<<0<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/unionfind.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/unionfind\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/unionfind.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n\n  UnionFind uf(n);\n  for(int i=0;i<q;i++){\n    int t,u,v;\n    cin>>t>>u>>v;\n    if(t==0) uf.unite(u,v);\n    if(t==1) cout<<uf.same(u,v)<<newl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/vertex_add_path_sum.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/vertex_add_path_sum\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/heavylightdecomposition.cpp\"\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  HLD G(n);\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    G.add_edge(u,v);\n  }\n  G.build();\n\n  using ll = long long;\n  BIT<ll> bit(n);\n  for(int i=0;i<n;i++)\n    bit.add(G.vid[i],as[i]);\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int p,x;\n      cin>>p>>x;\n      bit.add(G.vid[p],x);\n    }\n    if(t==1){\n      int u,v;\n      cin>>u>>v;\n      ll res=0;\n      auto f=[&](int l,int r){res+=bit.query(l,r);};\n      G.for_each(u,v,f);\n      cout<<res<<'\\n';\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/vertex_add_subtree_sum.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/vertex_add_subtree_sum\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/eulertourforvertex.cpp\"\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  EulerTourForVertex G(n);\n  for(int i=1;i<n;i++){\n    int p;\n    cin>>p;\n    G.add_edge(p,i);\n  }\n  G.build(0);\n\n  BIT<long long> bit(n);\n  for(int i=0;i<n;i++)\n    bit.add(G.idx(i),as[i]);\n\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==0){\n      int u,x;\n      cin>>u>>x;\n      bit.add(G.idx(u),x);\n    }\n    if(t==1){\n      int u;\n      cin>>u;\n      G.exec(u,[&](int l,int r){cout<<bit.query(l,r)<<\"\\n\";});\n    }\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yosupo/zalgorithm.test.cpp",
    "content": "// verification-helper: PROBLEM https://judge.yosupo.jp/problem/zalgorithm\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/space.cpp\"\n#include \"../../string/zalgorithm.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string s;\n  cin>>s;\n\n  auto zs=zalgorithm(s);\n  zs.pop_back();\n  space(zs);\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0022.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/22\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../polynomial/lagrangeinterpolation.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using M = Mint<int, int(1e9+9)>;\n  const int MAX = 666 * 6 + 10;\n  vector<M> dp(MAX,0);\n  dp[0]=M(1);\n\n  for(int x:{1,5,10,50,100,500})\n    for(int j=x;j<MAX;j++) dp[j]+=dp[j-x];\n\n  int T;\n  cin>>T;\n  while(T--){\n    using ll = long long;\n    ll m;\n    cin>>m;\n    vector<M> ys(6);\n    for(int i=0;i<6;i++) ys[i]=dp[(m%500)+(i*500)];\n    cout<<lagrange_interpolation(ys,M(m/500))<<\"\\n\";\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0104.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/104\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../polynomial/berlekampmassey.cpp\"\n#include \"../../convolution/naive.cpp\"\n#include \"../../math/bostanmori.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  long long n;\n  int p,c;\n  cin>>n>>p>>c;\n\n  using M = Mint<int>;\n  using Poly = vector<M>;\n\n  const int d = 1500;\n  const int MAX = p+c+1;\n  vector<Poly> cf(MAX,Poly(d,0));\n  cf[0][0]=M(1);\n\n  for(int v:{2,3,5,7,11,13}){\n    vector<Poly> nx(MAX,Poly(d,0));\n    for(int t=0;t<=p;t++)\n      for(int i=0;i<d;i++)\n        for(int j=0;t+j<=p&&i+v*j<d;j++)\n          nx[t+j][i+v*j]+=cf[t][i];\n    swap(cf,nx);\n  }\n\n  for(int v:{4,6,8,9,10,12}){\n    vector<Poly> nx(MAX,Poly(d,0));\n    for(int t=p;t<=p+c;t++)\n      for(int i=0;i<d;i++)\n        for(int j=0;t+j<=p+c&&i+v*j<d;j++)\n          nx[t+j][i+v*j]+=cf[t][i];\n    swap(cf,nx);\n  }\n\n  Poly dp(d*3,0),as(d*3,0);\n  dp[0]=M(1);\n  for(int i=0;i<(int)dp.size();i++){\n    for(int j=0;j<d&&i+j<(int)dp.size();j++)\n      dp[i+j]+=dp[i]*cf[p+c][j];\n\n    for(int j=1;i+j<(int)dp.size();j++)\n      as[i]+=dp[i+j];\n  }\n  as.resize(d*2);\n\n  BostanMori<M> bm(naive<M>());\n  cout<<bm.build(n-1,as,berlekamp_massey(as))<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0143.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/143\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/bigint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  bigint MOD = 1000000000;\n  ll n,m;\n  cin>>n>>m;\n  n/=1000;\n  n%=m;\n  bigint res(1);\n  for(int i=0;i<n;i++){\n    res*=m-i;\n    res/=i+1;\n  }\n  cout<<res%MOD<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0206.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/206\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/bitvector.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,s,x,y,z;\n  cin>>n>>s>>x>>y>>z;\n  int q;\n  cin>>q;\n  BitVector bv(n+1);\n  int a=s;\n  for(int i=1;i<=n;i++){\n    bv.set(i,a&1);\n    a=(1LL*x*a+y)%z;\n  }\n  for(int i=0;i<q;i++){\n    int s,t,u,v;\n    cin>>s>>t>>u>>v;\n    auto p=bv.get(s,t+1),q=bv.get(u,v+1);\n    for(int i=0;i<(int)p.dat.size();i++) p.dat[i]^=q.dat[i];\n    bv.set(u,v+1,p);\n  }\n  for(int i=1;i<=n;i++) cout<<(bv.get(i)?\"O\":\"E\");\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0222.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/222\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/iskado.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int w,h;\n  cin>>w>>h;\n  vector<vector<int>> st(h,vector<int>(w));\n  for(int i=0;i<h;i++)\n    for(int j=0;j<w;j++)\n      cin>>st[i][j];\n\n  using T = tuple<int, int, int, int>;\n  map<T, int> dp;\n  queue<T> qu;\n  if(st[0][0]!=st[0][1]){\n    dp[T(0,0,0,1)]=1;\n    qu.emplace(0,0,0,1);\n  }\n  if(st[0][0]!=st[1][0]){\n    dp[T(0,0,1,0)]=1;\n    qu.emplace(0,0,1,0);\n  }\n\n  int dy[]={0,0,1,-1};\n  int dx[]={1,-1,0,0};\n  auto in=[&](int y,int x){return 0<=y&&y<h&&0<=x&&x<w;};\n\n  int ans=-1;\n  while(!qu.empty()){\n    int py,px,cy,cx;\n    tie(py,px,cy,cx)=qu.front();qu.pop();\n    if(cy==h-1&&cx==w-1){\n      ans=dp[T(py,px,cy,cx)];\n      break;\n    }\n    for(int k=0;k<4;k++){\n      int ny=cy+dy[k],nx=cx+dx[k];\n      if(!in(ny,nx)) continue;\n      if(!is_kado(st[py][px],st[cy][cx],st[ny][nx])) continue;\n      if(dp.count(T(cy,cx,ny,nx))) continue;\n      dp[T(cy,cx,ny,nx)]=dp[T(py,px,cy,cx)]+1;\n      qu.emplace(cy,cx,ny,nx);\n    }\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0399.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/399\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../string/palindromictree.cpp\"\n#include \"../../string/rollinghash.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  string s,t;\n  cin>>s>>t;\n\n  PalindromicTree p1(s),p2(t);\n  const int MOD = 1e9+7;\n  const int BASE1 = 1777771;\n  const int BASE2 = 1e6+3;\n  RollingHash<int, MOD, BASE1> rs1(s),rt1(t);\n  RollingHash<int, MOD, BASE2> rs2(s),rt2(t);\n\n  const int MAX = 5e5+100;\n  map<pair<int, int>, int> m1[MAX];\n  for(int i=2;i<(int)p1.size();i++){\n    auto& u=p1.vs[i];\n    if(u.app<0) continue;\n    auto p=make_pair(rs1.find(u.app,u.app+u.len),\n                     rs2.find(u.app,u.app+u.len));\n    m1[u.len][p]=u.cnt;\n  }\n\n  ll ans=0;\n  for(int i=2;i<(int)p2.size();i++){\n    auto& u=p2.vs[i];\n    auto p=make_pair(rt1.find(u.app,u.app+u.len),\n                     rt2.find(u.app,u.app+u.len));\n    if(u.app<0||!m1[u.len].count(p)) continue;\n    ans+=(ll)m1[u.len][p]*u.cnt;\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0444.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/444\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/fastfouriertransform.cpp\"\n#include \"../../convolution/arbitrarymod.cpp\"\n#include \"../../polynomial/berlekampmassey.cpp\"\n#include \"../../math/bostanmori.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using M = Mint<int>;\n  using Poly = vector<M>;\n  ArbitraryMod<M> arb;\n  auto conv=[&](auto as,auto bs){return arb.multiply(as,bs);};\n\n  long long n;\n  cin>>n;\n  n--;\n\n  int p,c;\n  cin>>p>>c;\n\n  const int d = 606 * 13;\n  auto calc=[&](int l,vector<int> vs){\n    int m=vs.size();\n    vector<Poly> dp(m,Poly(d));\n    for(int i=0;i<m;i++) dp[i][0]=M(1);\n    for(int t=0;t<l;t++){\n      for(int i=0;i<m;i++){\n        for(int j=d-1;j>=0;j--){\n          dp[i][j]=0;\n          if(i) dp[i][j]+=dp[i-1][j];\n          if(j>=vs[i]) dp[i][j]+=dp[i][j-vs[i]];\n        }\n      }\n    }\n    return dp.back();\n  };\n\n  Poly cf({M(1)});\n  cf=conv(cf,calc(p,vector<int>({2,3,5,7,11,13})));\n  cf=conv(cf,calc(c,vector<int>({4,6,8,9,10,12})));\n  cf.resize(d,M(0));\n\n  Poly dp(d*3,0),as(d*3,0);\n  dp[0]=M(1);\n  for(int i=0;i<(int)dp.size();i++){\n    for(int j=0;j<d&&i+j<(int)dp.size();j++)\n      dp[i+j]+=dp[i]*cf[j];\n\n    for(int j=1;j<d&&i+j<(int)dp.size();j++)\n      as[i]+=dp[i+j];\n  }\n  as.resize(d*2);\n\n  BostanMori<M> seq(conv);\n  cout<<seq.build(n,as,berlekamp_massey(as))<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0472.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/472\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/totient.cpp\"\n#include \"../../mod/tetration.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int a,n,m;\n  cin>>a>>n>>m;\n  cout<<tetration(a,n,m)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0771.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/771\n// verification-helper: ERROR 1e-6\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../convexhulltrick/convexhulltrick.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using D = double;\n  D c,d;\n  cin>>c>>d;\n  vector<D> as{{3.0/4.0,1.0/4.0}};\n  vector<D> bs{{2.0/7.0,5.0/7.0}};\n  vector<D> cs{{c,d}};\n  D ans=solve_lp_max<D>(1000,2000,as,bs,cs);\n  cout<<fixed<<setprecision(12)<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/0831.test.cpp",
    "content": "#define PROBLEM \"https://yukicoder.me/problems/831\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/bigint.cpp\"\n#include \"../../linearalgebra/squarematrix.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  ll l;\n  cin>>l;\n\n  if(l==2){\n    cout<<3<<endl;\n    cout<<\"INF\"<<endl;\n    return 0;\n  }\n  cout<<l<<endl;\n\n  using M = SquareMatrix<bigint, 2>;\n  M A;\n  A[0][0]=1;A[0][1]=1;\n  A[1][0]=1;A[1][1]=0;\n  if(l&1) cout<<A.pow(l)[1][0]<<endl;\n  else{\n    auto B=A.pow(l/2);\n    auto X=(B*B)[1][0];\n    auto Y=B[1][0];\n    cout<<X-Y*Y<<endl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1013.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/1013\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../string/trie.cpp\"\n#include \"../../string/ahocorasick.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  AhoCorasick<26, false> aho('A');\n  string s;\n  cin>>s;\n  int m;\n  cin>>m;\n  auto cs=read<string>(m);\n  for(auto c:cs) aho.add(c,0);\n  aho.build();\n  cout<<aho.match(s)<<endl;\n\n  auto res=aho.frequency(s);\n  long long cnt=0;\n  for(auto c:cs) cnt+=res[aho.find(c)];\n  assert(cnt==aho.match(s));\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1504.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/1504\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../convolution/garner.cpp\"\n#include \"../../mod/rint.cpp\"\n#include \"../../mod/factorial.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  const int MOD = 1e9+7;\n  long long n;\n  cin>>n;\n  cout<<factorial(n,MOD)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1580.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/1580\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/convertbase.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  long long p;\n  cin>>p;\n  auto ans=convert_base(p,7LL);\n  for(auto x:ans) cout<<x;\n  cout<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1665.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/1665\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/totient_table.cpp\"\n#include \"../../mod/mint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  auto ts=totient_table(n/m+1);\n\n  using M = Mint<int>;\n\n  M ans{0};\n  for(int i=2;i<=n/m;i++) ans+=M(ts[i]*2);\n  for(int i=1;i<=n-2;i++) ans*=M(i);\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1732.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/1732\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../datastructure/waveletmatrix.cpp\"\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n,k;\n  cin>>n>>k;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto vx=compress(as);\n  auto mx=dict(vx);\n\n  BIT<ll> bit1(n),bit2(n);\n\n  ll ans=1e18,sum=0;\n  for(int i=0;i<k;i++){\n    bit1.add(mx[as[i]],1);\n    bit2.add(mx[as[i]],as[i]);\n    sum+=as[i];\n  }\n\n  WaveletMatrix<int, 30> wm(as);\n  for(int i=0;i+k<=n;i++){\n    int j=i+k;\n    int x=wm.quantile(i,j,k>>1);\n\n    ll p=bit1.query(0,mx[x]+1),q=k-p;\n    ll s=bit2.query(0,mx[x]+1);\n    chmin(ans,p*x-s+(sum-s)-q*x);\n\n    bit1.add(mx[as[i]],-1);\n    bit2.add(mx[as[i]],-as[i]);\n    sum-=as[i];\n\n    if(j==n) continue;\n    bit1.add(mx[as[j]],1);\n    bit2.add(mx[as[j]],as[j]);\n    sum+=as[j];\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1923.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/1923\n// verification-helper: ERROR 1e-6\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/precision.cpp\"\n#include \"../../datastructure/rangeslide.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,k;\n  cin>>n>>k;\n  string s;\n  cin>>s;\n  vector<int> a(n);\n  for(int i=0;i<n;i++) a[i]=s[i]-'0';\n\n  using D = double;\n  auto check=\n    [&](D x)->int{\n      vector<D> b(n);\n      for(int i=0;i<n;i++) b[i]=a[i]-x;\n\n      vector<D> sm(n*2+1,0);\n      for(int i=0;i<n*2;i++)\n        sm[i+1]=sm[i]+b[i%n];\n\n      auto cmp=[](D a,D b){return a<b;};\n      RangeSlide<D, decltype(cmp)> rs(sm,cmp);\n      for(int i=0;i<n;i++)\n        rs.add_range(i,i+n-k+1);\n\n      auto res=rs.build();\n      for(int i=0;i<n;i++)\n        if(sm[n+i]>sm[res[i]]) return 1;\n      return 0;\n    };\n\n  D L=0,R=1;\n  for(int k=0;k<20;k++){\n    D M=(L+R)/2;\n    if(check(M)) L=M;\n    else R=M;\n  }\n  cout<<L<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1937.test.cpp",
    "content": "#define PROBLEM \"https://yukicoder.me/problems/1937\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/waveletmatrix.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n;\n  cin>>n;\n\n  vector<ll> as(n),ls(n),rs(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n  for(int i=0;i<n;i++) cin>>ls[i]>>rs[i];\n\n  const ll OFS = 2e9;\n  vector<ll> bs(n),cs(n);\n  for(int i=0;i<n;i++){\n    as[i]+=OFS;\n    bs[i]=as[i]-ls[i];\n    cs[i]=as[i]+rs[i];\n  }\n  WaveletMatrix<ll, 40> wm1(bs),wm2(cs);\n\n  ll ans=0;\n  for(int i=0;i<n;i++){\n    int x=lower_bound(as.begin(),as.end(),as[i]-ls[i])-as.begin();\n    int y=upper_bound(as.begin(),as.end(),as[i]+rs[i])-as.begin();\n    ans+=wm2.rangefreq(x,i,as[i],OFS*2);\n    ans+=wm1.rangefreq(i+1,y,0,as[i]+1);\n  }\n\n  cout<<ans/2<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1948.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/1948\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../algorithm/offlineonline.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n;\n  cin>>n;\n  auto as=read<ll>(n);\n  auto xs=read<ll>(n);\n  auto ys=read<ll>(n);\n\n  auto dist=\n    [&](int i,int j)->ll{\n      ll s=abs(xs[i]-as[j-1]);\n      ll t=abs(ys[i]);\n      return s*s+t*t;\n    };\n\n  cout<<OfflineOnline::solve<ll>(n,dist)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1950.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/1950\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../algorithm/offlineonline.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n;\n  cin>>n;\n  auto as=read<ll>(n);\n  auto xs=read<ll>(n);\n  auto ys=read<ll>(n);\n\n  auto dist=\n    [&](int i,int j)->ll{\n      ll s=abs(xs[i]-as[j-1]);\n      ll t=abs(ys[i]);\n      return s+t;\n    };\n\n  cout<<OfflineOnline::solve<ll>(n,dist)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/1973.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/1973\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../math/kitamasa.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using M = Mint<int, 17>;\n  const int n = 4;\n  vector<M> as(n,0),cs(n,1);\n  as[n-1]=1;\n  Kitamasa<M> fib(cs);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    long long p;\n    cin>>p;\n    cout<<fib.calc(as,p-1)<<\"\\n\";\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2063.test.cpp",
    "content": "#define PROBLEM \"https://yukicoder.me/problems/2063\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../segtree/count/dynamic_offline.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,m;\n  cin>>n>>m;\n  vector<int> as(n),bs(n);\n  for(int i=0;i<n;i++) cin>>as[i]>>bs[i];\n\n  RangeCount<int, int> seg(m);\n  for(int i=0;i<n;i++){\n    if(as[i]>bs[i]) swap(as[i],bs[i]);\n    seg.preupdate(as[i],bs[i]);\n  }\n  seg.build();\n\n  long long ans=0;\n  for(int i=0;i<n;i++){\n    ans+=seg.query(0,as[i],as[i],bs[i]);\n    ans+=seg.query(as[i],bs[i],bs[i],m);\n    seg.update(as[i],bs[i],1);\n  }\n\n  cout<<ans<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2085.test.cpp",
    "content": "#define PROBLEM \"https://yukicoder.me/problems/2085\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/rerooting.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  auto fold=[](int a,int b){return max(a,0)+max(b,0);};\n  auto lift=[](int a,int d){return d-a;};\n  ReRooting<int, int> G(n,fold,lift,0);\n  for(int i=1;i<n;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    G.add_edge(a,b,1);\n  }\n  auto res=G.build();\n\n  vector<int> ans;\n  for(int i=0;i<n;i++)\n    if(1-res[i]>0) ans.emplace_back(i);\n\n  cout<<ans.size()<<\"\\n\";\n  for(int x:ans) cout<<x+1<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2113.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/2113\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../algorithm/offlineonline.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n;\n  cin>>n;\n  auto as=read<ll>(n);\n  auto xs=read<ll>(n);\n  auto ys=read<ll>(n);\n\n  auto dist=\n    [&](int i,int j)->ll{\n      ll s=abs(xs[i]-as[j-1]);\n      ll t=abs(ys[i]);\n      return s*s*s+t*t*t;\n    };\n\n  cout<<OfflineOnline::solve<ll>(n,dist)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2125.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/2125\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/bigint.cpp\"\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nusing ll = long long;\nconst int MAX = 1e5+100;\nll dp[MAX];\npair<bigint, bigint> dfs(int l,int r){\n  if(l+1>=r) return make_pair(bigint(dp[l]),bigint(l+1));\n  int m=(l+r)>>1;\n  auto v=dfs(l,m);\n  auto t=dfs(m,r);\n  t.first*=v.second;\n  t.first+=v.first;\n  t.second*=v.second;\n  return t;\n}\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<int> ps(n);\n  for(int i=0;i<n;i++) cin>>ps[i];\n  BIT<ll> bit(n);\n  for(int i=0;i<n;i++) bit.add(ps[i],1);\n  for(int i=0;i<n;i++){\n    dp[n-(i+1)]=bit.query(0,ps[i]);\n    bit.add(ps[i],-1);\n  }\n  cout<<bigint(dfs(0,n).first+1)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2147.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/2147\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/waveletmatrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<int> xs(n);\n  for(int i=0;i<n;i++) cin>>xs[i],xs[i]--;\n\n  WaveletMatrix<int, 20> wm(xs);\n\n  int ans=n*(n-1);\n  for(int i=0;i<n;i++){\n    ans-=wm.rangefreq(0,i,0,xs[i]);\n    ans-=wm.rangefreq(i+1,n,xs[i]+1,n*2);\n  }\n  cout<<ans/2<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2520.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/2520\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../math/sum_of_geometric_sequence.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using M = Mint<int>;\n  long long n;\n  cin>>n;\n  cout<<M(10).pow(n)+M(3)*sum_of_geometric_sequence(M(10),n)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2587.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/2587\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../toptree/toptree.cpp\"\n#include \"../../toptree/distancesum.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n\n  using ll = long long;\n  const size_t N = 1e5;\n  using Cluster = DistanceSum<ll>;\n  TopTree<Vertex, Cluster, N> G;\n\n  vector<int> xs(n,1);\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++) vs[i]=G.create(xs[i]);\n\n  ll pre=0;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n\n    if(t==1){\n      int a,b,c;\n      cin>>a>>b>>c;\n      a--;b--;\n      a+=pre;a%=n;\n      b+=pre;b%=n;\n      G.link(vs[a],c,vs[b]);\n    }\n\n    if(t==2){\n      int a,b;\n      cin>>a>>b;\n      a--;b--;\n      a+=pre;a%=n;\n      b+=pre;b%=n;\n      G.cut(vs[a],vs[b]);\n    }\n\n    if(t==3){\n      int a;\n      cin>>a;\n      a--;\n      a+=pre;a%=n;\n      xs[a]^=1;\n      G.set_vertex(vs[a],xs[a]);\n\n      auto cc=centroid(G,vs[a]);\n      ll res=G.get_subtree(cc).ans;\n      cout<<res<<newl;\n      pre+=res;pre%=n;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2600.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/2600\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/absolutesum.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n;\n  cin>>n;\n  vector<ll> ys(n);\n  for(int i=0;i<n;i++) cin>>ys[i];\n  sort(ys.begin(),ys.end());\n  if(ys.front()==ys.back()){\n    cout<<1<<endl;\n    return 0;\n  }\n\n  AbsoluteSum<ll> as;\n  vector<ll> dp(n,0);\n  for(int i=0;i<n;i++){\n    as.insert(ys[i]);\n    dp[i]+=as.value();\n  }\n  for(int i=0;i<n;i++){\n    as.erase(ys[i]);\n    dp[i]+=as.value();\n  }\n\n  cout<<*min_element(dp.begin(),dp.end())<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2744.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/2744\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/fastfouriertransform.cpp\"\n#include \"../../convolution/arbitrarymod.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int k,n;\n  cin>>k>>n;\n  vector<int> xs(n);\n  for(int i=0;i<n;i++) cin>>xs[i];\n\n  using M = Mint<int>;\n  ArbitraryMod<M> arb;\n  auto conv=[&](auto as,auto bs){return arb.multiply(as,bs);};\n  FormalPowerSeries<M> FPS(conv);\n\n  const int sz=1<<17;\n  vector<M> bs(sz,M(0));\n  bs[0]=1;\n  for(int x:xs) bs[x]-=M(1);\n  cout<<FPS.inv(bs,k+1)[k]<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/2772.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/2772\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../combinatorics/surjection.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n\n  using M = Mint<int>;\n  cout<<surjection<M>(n,m)<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3211.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3211\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../vector/reversed.cpp\"\n#include \"../../mod/mint.cpp\"\n#include \"../../polynomial/berlekampmassey.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using M = Mint<int>;\n  int p;\n  cin>>p;\n\n  const int n = 100;\n  vector<M> as(n);\n  as[0]=M(0);\n  as[1]=M(0);\n  as[2]=M(1);\n  for(int i=3;i<n;i++) as[i]=M(p)*as[i-1]+as[i-2];\n\n  vector<M> bs(n,M(0));\n  for(int s=0;s<n;s++)\n    for(int t=0;s+t<n;t++)\n      bs[s+t]+=as[s]*as[t];\n\n  auto cs=reversed(berlekamp_massey(bs));\n\n  const int MAX = 2e6 + 100;\n  vector<M> dp(MAX,0);\n  for(int i=0;i<n;i++) dp[i]=bs[i];\n  for(int i=n;i<MAX;i++)\n    for(int j=0;j<(int)cs.size();j++)\n      dp[i]-=dp[i-j]*cs[j];\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int k;\n    cin>>k;\n    cout<<dp[k]<<\"\\n\";\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3227.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3227\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../datastructure/waveletmatrix.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n;\n  cin>>n;\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  const int OFS = 1e9;\n  for(int &a:as) a+=OFS;\n\n  WaveletMatrix<int, 31> wm(as);\n\n  ll ans=0;\n  for(ll k=1;k<=n;k++){\n    int p=(k-1)/2;\n    vector<ll> ls,rs;\n    for(int i=0;i+k<=n;i+=k)\n      ls.emplace_back((wm.rquantile(i,i+k,p)-OFS)*k);\n    for(int i=n;i-k>=0;i-=k)\n      rs.emplace_back((wm.rquantile(i-k,i,p)-OFS)*k);\n\n    int sz=ls.size();\n    vector<ll> dp(sz+1,0),pd(sz+1,0);\n\n    for(ll i=0,sum=0;i<sz;i++){\n      sum+=ls[i];\n      chmax(dp[i+1],dp[i]);\n      chmax(dp[i+1],sum);\n    }\n    for(ll i=sz,sum=0;i>0;i--){\n      sum+=rs[sz-i];\n      chmax(pd[i-1],pd[i]);\n      chmax(pd[i-1],sum);\n    }\n\n    for(int i=0;i<=sz;i++)\n      chmax(ans,dp[i]+pd[i]);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3267.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3267\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/divisor.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  const int MAX = 3e6+100;\n  using M = Mint<int>;\n  vector<M> ys(MAX,0),xs(MAX,0);\n\n  int h,w;\n  cin>>h>>w;\n  for(int i=1;i<h;i++) ys[i]=h-i;\n  for(int j=1;j<w;j++) xs[j]=w-j;\n\n  GCDConvolution::zeta(ys);\n  GCDConvolution::zeta(xs);\n  for(int i=1;i<MAX;i++) ys[i]*=xs[i];\n  GCDConvolution::moebius(ys);\n\n  M ans{0};\n  ans+=ys[1]*M(2);\n  ans+=M(h-1)*M(w);\n  ans+=M(h)*M(w-1);\n  cout<<ans<<endl;\n\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3277.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3277\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../segtree/basic/ushi.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n  auto as=read(n);\n\n  auto f=[](int a,int b){return min(a,b);};\n  SegmentTree<int> seg(f,n+1);\n  seg.build(as);\n\n  for(int i=0;i<q;i++){\n    int t,l,r;\n    cin>>t>>l>>r;\n    if(t==1){\n      l--;r--;\n      swap(as[l],as[r]);\n      seg.set_val(l,as[l]);\n      seg.set_val(r,as[r]);\n    }\n    if(t==2){\n      l--;\n      int m=seg.query(l,r);\n      auto check=[&](int x){return x>m;};\n      cout<<seg.max_right(l,check)+1<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3354.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3354\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/yesno.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int a,b;\n  cin>>a>>b;\n\n  cout<<YESNO[a%b==0]<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3405.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3405\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/levelancestor.cpp\"\n#include \"../../tree/eulertourforbfs.cpp\"\n#include \"../../segtree/basic/lazy.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  EulerTourForBFS G(n);\n  for(int i=1;i<n;i++){\n    int u,v;\n    cin>>u>>v;\n    G.add_edge(u,v);\n  }\n  G.build();\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  using ll = long long;\n  auto f=[&](ll a,ll b){return a+b;};\n  auto g=[&](ll a,ll b){return a*b;};\n  SegmentTree<ll, ll> seg(f,g,g,0,1);\n\n  vector<ll> vs(n);\n  for(int i=0;i<n;i++)\n    vs[G.idx(i)]=as[i];\n  seg.build(vs);\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int x;\n    cin>>x;\n\n    ll sum=0;\n    auto apply=\n      [&](int l,int r){\n        sum+=seg.query(l,r);\n        seg.update(l,r,0);\n      };\n\n    int p=G.par[0][x];\n    if(~p){\n      int pp=G.par[0][p];\n      if(~pp) G.exec(pp,0,apply);\n\n      G.exec(p,0,apply);\n      G.exec(p,1,apply);\n    }\n\n    G.exec(x,0,apply);\n    G.exec(x,1,apply);\n    G.exec(x,2,apply);\n\n    seg.set_val(G.idx(x),sum);\n    cout<<sum<<\"\\n\";\n  }\n\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3407.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3407\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/lowestcommonancestor.cpp\"\n#include \"../../tree/auxiliarytree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  AuxiliaryTree G(n);\n  vector<map<int, int>> ws(n);\n  for(int i=1;i<n;i++){\n    int u,v,w;\n    cin>>u>>v>>w;\n    G.add_edge(u,v);\n    ws[u][v]=ws[v][u]=w;\n  }\n  G.build();\n\n  using ll = long long;\n  vector<ll> dep(n,-1);\n  queue<int> que;\n  dep[0]=0;\n  que.emplace(0);\n  while(!que.empty()){\n    int v=que.front();que.pop();\n    for(int u:G.G[v]){\n      if(~dep[u]) continue;\n      dep[u]=dep[v]+ws[v][u];\n      que.emplace(u);\n    }\n  }\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int k;\n    cin>>k;\n    vector<int> vs(k);\n    for(int j=0;j<k;j++) cin>>vs[j];\n\n    G.query(vs);\n\n    ll ans=0;\n    for(int v:vs)\n      for(int u:G.T[v])\n        ans+=max(dep[u]-dep[v],0LL);\n    cout<<ans<<\"\\n\";\n\n    G.clear(vs);\n  }\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3453.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3453\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../toptree/toptree.cpp\"\n#include \"../../toptree/steiner.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  const size_t N = 1e5;\n  using Cluster = SteinerTree<long long>;\n  TopTree<Vertex, Cluster, N> G;\n\n  int n;\n  cin>>n;\n\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++) vs[i]=G.create();\n\n  for(int i=1;i<n;i++){\n    int u,v,w;\n    cin>>u>>v>>w;\n    G.link(vs[u],Cluster(w),vs[v]);\n  }\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n\n    if(t==1){\n      int u,v,w,x;\n      cin>>u>>v>>w>>x;\n      G.cut(vs[u],vs[v]);\n      G.link(vs[v],Cluster(x),vs[w]);\n    }\n\n    if(t==2){\n      int k;\n      cin>>k;\n      vector<int> xs(k);\n      for(int j=0;j<k;j++) cin>>xs[j];\n\n      for(int x:xs) G.set_vertex(vs[x],Vertex(1));\n\n      cout<<G.get_subtree(vs[xs[0]]).ans<<newl;\n\n      for(int x:xs) G.set_vertex(vs[x],Vertex(0));\n    }\n  }\n\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3592.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3592\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/weightedunionfind.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n  WeightedUnionFind<int> uf(n);\n\n  vector<int> vs(n,0);\n  auto add=[&](int a,int b){\n    vs[uf.find(a)]+=b;\n  };\n  auto query=[&](int a){\n    int r=uf.find(a);\n    return uf.diff(a,r)+vs[r];\n  };\n  auto unite=[&](int a,int b){\n    a=uf.find(a);\n    b=uf.find(b);\n    if(a==b) return;\n    int x=query(a);\n    int y=query(b);\n    uf.unite(a,b,x-y);\n  };\n\n  for(int i=0;i<q;i++){\n    int t,a,b;\n    cin>>t>>a>>b;\n    if(t==1){\n      a--;b--;\n      unite(a,b);\n    }\n    if(t==2){\n      a--;\n      add(a,b);\n    }\n    if(t==3){\n      a--;\n      cout<<query(a)<<newl;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3912.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/3912\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/centroid.cpp\"\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#include \"../../segtree/basic/dual.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,q;\n  cin>>n>>q;\n\n  Centroid G(n);\n  for(int i=1;i<n;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    G.add_edge(a,b);\n  }\n\n  vector<int> xs(q),ys(q),zs(q);\n  for(int i=0;i<q;i++) cin>>xs[i]>>ys[i]>>zs[i];\n\n  vector<vector<int>> H(n);\n  for(int i=0;i<q;i++){\n    xs[i]--;\n    H[xs[i]].emplace_back(i);\n  }\n\n  vector<int> dep(n);\n\n  using ll = long long;\n  vector<ll> ans(q,0);\n  auto h=[&](ll a,ll b){return a+b;};\n  SegmentTree<ll> seg(h,0);\n  seg.init(n*2);\n\n  queue<int> que;\n  que.emplace(G.build(0)[0]);\n  while(!que.empty()){\n    int r=que.front();que.pop();\n    dep[r]=0;\n\n    // add for all\n    {\n      int len=1;\n      vector<int> qs(H[r]);\n      for(int t:G[r]){\n        if(!G.alive(t)) continue;\n        MFP([&](auto dfs,int v,int p,int d)->void{\n          dep[v]=d;\n          chmax(len,d+1);\n          for(int i:H[v]) qs.emplace_back(i);\n          for(int u:G[v]){\n            if(u==p) continue;\n            if(!G.alive(u)) continue;\n            dfs(u,v,d+1);\n          }\n        })(t,r,1);\n      }\n      seg.init(len);\n      sort(qs.begin(),qs.end());\n      for(int i:qs){\n        ans[i]+=seg.get_val(dep[xs[i]]);\n        if(ys[i]>=dep[xs[i]])\n          seg.update(0,min(len,ys[i]-dep[xs[i]]+1),zs[i]);\n      }\n    }\n\n    // sub for subtree\n    {\n      for(int t:G[r]){\n        if(!G.alive(t)) continue;\n        int len=1;\n        vector<int> qs;\n        MFP([&](auto dfs,int v,int p,int d)->void{\n          dep[v]=d;\n          chmax(len,d+1);\n          for(int i:H[v]) qs.emplace_back(i);\n          for(int u:G[v]){\n            if(u==p) continue;\n            if(!G.alive(u)) continue;\n            dfs(u,v,d+1);\n          }\n        })(t,r,1);\n        seg.init(len);\n        sort(qs.begin(),qs.end());\n        for(int i:qs){\n          ans[i]-=seg.get_val(dep[xs[i]]);\n          if(ys[i]>=dep[xs[i]])\n            seg.update(0,min(len,ys[i]-dep[xs[i]]+1),zs[i]);\n        }\n      }\n    }\n\n    G.disable(r);\n    for(int t:G[r])\n      if(G.alive(t))\n        que.emplace(G.build(t)[0]);\n  }\n\n  for(auto a:ans) cout<<a<<\"\\n\";\n  cout<<flush;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/3961.test.cpp",
    "content": "#define PROBLEM \"https://yukicoder.me/problems/3961\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tree/centroid.cpp\"\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../vector/compress.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n\n  int n,k;\n  cin>>n>>k;\n\n  using P = pair<int, int>;\n  vector< map<int, int> > col(n);\n  Centroid G(n);\n  for(int i=1;i<n;i++){\n    int x,y,z;\n    cin>>x>>y>>z;\n    x--;y--;z--;\n    G.add_edge(x,y);\n    col[x][y]=z;\n    col[y][x]=z;\n  }\n\n  queue<int> que;\n  que.emplace(G.build(0)[0]);\n\n  ll ans=0;\n  vector<int> cnt(k,0),uku(k,0);\n  vector<P> ps(n),vp(n);\n\n  while(!que.empty()){\n    int r=que.front();que.pop();\n    auto calc=\n      [&](P p,int q)->P{\n        assert(~p.first);\n        if(p.first==q||p.second==q) return p;\n        if(p.second==-1) return minmax({p.first,q});\n        return P(-1,-1);\n      };\n\n    vp.clear();\n    for(int t:G[r]){\n      if(!G.alive(t)) continue;\n\n      MFP([&](auto dfs,int v,int p,P st)->void{\n        ps[v]=st;\n        if(st.first<0) return;\n        for(int u:G[v]){\n          if(u==p) continue;\n          if(!G.alive(u)) continue;\n          dfs(u,v,calc(st,col[u][v]));\n        }\n        if(st.second!=-1)\n          vp.emplace_back(st);\n      })(t,r,P(col[r][t],-1));\n    }\n    vp=compress(vp);\n    auto idx=[&](P p){return lower_bound(vp.begin(),vp.end(),p)-vp.begin();};\n\n    vector<int> num(vp.size());\n    int all=0;\n    for(int t:G[r]){\n      if(!G.alive(t)) continue;\n\n      // count\n      MFP([&](auto dfs,int v,int p)->void{\n        P st=ps[v];\n        if(st.first<0) return;\n        for(int u:G[v]){\n          if(u==p) continue;\n          if(!G.alive(u)) continue;\n          dfs(u,v);\n        }\n        if(st.second==-1){\n          ans+=all-cnt[st.first];\n          ans+=uku[st.first];\n        }else{\n          ans+=1;\n          ans+=cnt[st.first];\n          ans+=cnt[st.second];\n          ans+=num[idx(st)];\n        }\n      })(t,r);\n\n      // paint\n      MFP([&](auto dfs,int v,int p)->void{\n        P st=ps[v];\n        if(st.first<0) return;\n        for(int u:G[v]){\n          if(u==p) continue;\n          if(!G.alive(u)) continue;\n          dfs(u,v);\n        }\n        if(st.second==-1){\n          cnt[st.first]++;\n          all++;\n        }else{\n          num[idx(st)]++;\n          uku[st.first]++;\n          uku[st.second]++;\n        }\n      })(t,r);\n    }\n\n    for(int t:G[r]){\n      if(!G.alive(t)) continue;\n\n      // clear\n      MFP([&](auto dfs,int v,int p)->void{\n        P st=ps[v];\n        if(st.first<0) return;\n        for(int u:G[v]){\n          if(u==p) continue;\n          if(!G.alive(u)) continue;\n          dfs(u,v);\n        }\n        if(st.second==-1){\n          cnt[st.first]--;\n        }else{\n          uku[st.first]--;\n          uku[st.second]--;\n        }\n      })(t,r);\n    }\n\n    G.disable(r);\n    for(int u:G[r])\n      if(G.alive(u))\n        que.emplace(G.build(u)[0]);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4072.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4072\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/disjointsparsetable.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  int n;\n  cin>>n;\n  vector<ll> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto f=[&](ll a,ll b){return gcd(a,b);};\n  DisjointSparseTable<ll> dst(f);\n  dst.build(as);\n\n  ll ans=0;\n  for(int l=0,r=0;l<n;l++){\n    if(as[l]==1){\n      ans+=n-l;\n      continue;\n    }\n    if(r<=l) r=l+1;\n    while(r<=n and dst.query(l,r)>1) r++;\n    ans+=n-r+1;\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4117.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4117\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/yesno.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  long long l,r,m,k;\n  cin>>l>>r>>m>>k;\n\n  long long x=l*k,y=r*k;\n  cout<<YesNo[x<=y/m*m]<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4271.avx2.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4271\n\n#define call_from_test\n#include \"../../tools/avx2.cpp\"\n#undef call_from_test\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nconst int MAX = 1e5;\nconst int MOD = 1e9+7;\nusing uint = unsigned int;\n\ninline uint add_mod(uint a, uint b) {\n  return (a += b) >= MOD ? a - MOD : a;\n}\n\nuint mul(uint x,uint y){\n  return 1ULL*x*y%MOD;\n}\n\nuint xs[MAX]={};\nuint as[MAX]={};\nuint cs[MAX]={};\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int k,n,m;\n  cin>>k>>n>>m;\n  for(int i=0;i<k;i++) cin>>as[i];\n  for(int i=0;i<k;i++) cin>>cs[i];\n\n  for(int i=k;i<n;i++)\n    for(int j=0;j<k;j++)\n      as[i]=add_mod(as[i],mul(cs[j],as[i-(j+1)]));\n\n  for(int i=0;i<m;i++){\n    int l,r;\n    cin>>l>>r;\n    for(int k=l;k<r;k++) xs[k]=add_mod(xs[k],as[k-l]);\n  }\n\n  for(int i=0;i<n;i++) cout<<xs[i]<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4271.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4271\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../polynomial/recursivesequence.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int k,n,m;\n  cin>>k>>n>>m;\n\n  using M = Mint<int>;\n  vector<M> as(k),cs(k);\n  for(int i=0;i<k;i++) cin>>as[i].v;\n  for(int i=0;i<k;i++) cin>>cs[i].v;\n\n  RecursiveSequence<M> rs(n);\n  for(int i=0;i<m;i++){\n    int l,r;\n    cin>>l>>r;\n    rs.query(l,r);\n  }\n\n  auto ss=rs.build(as,cs);\n  for(int i=0;i<n;i++) cout<<ss[i]<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4387.test.cpp",
    "content": "#define PROBLEM \"https://yukicoder.me/problems/4387\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../graph/rangetorange.cpp\"\n#include \"../../graph/stronglyconnectedcomponent.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,a,b;\n  cin>>n>>a>>b;\n\n  auto xs=read(n);\n\n  RangeToRange G(n);\n  SCC scc(G.size()+n+n);\n  auto f=[&](int u,int v){scc.add_edge(u,v);};\n  G.init(f);\n\n  for(int i=0;i<n;i++){\n    // [x - B, x - A]\n    {\n      int l=lower_bound(xs.begin(),xs.end(),xs[i]-b)-xs.begin();\n      int r=upper_bound(xs.begin(),xs.end(),xs[i]-a)-xs.begin();\n      G.add_edge(i,i+1,l,r,f,f);\n    }\n    // [x + A, x + B]\n    {\n      int l=lower_bound(xs.begin(),xs.end(),xs[i]+a)-xs.begin();\n      int r=upper_bound(xs.begin(),xs.end(),xs[i]+b)-xs.begin();\n      G.add_edge(i,i+1,l,r,f,f);\n    }\n  }\n\n  scc.build();\n  map<int, int> cnt;\n  for(int i=0;i<n;i++) cnt[scc[G.idx(i)]]++;\n  for(int i=0;i<n;i++) cout<<cnt[scc[G.idx(i)]]<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4474.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4474\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/pow.cpp\"\n#include \"../../mod/order.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int T;\n  cin>>T;\n  while(T--){\n    long long n;\n    cin>>n;\n    cout<<order(2LL,2*n-1)<<newl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4569.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4569\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../mod/rint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int p,n;\n  cin>>p>>n;\n  auto as=read(n);\n  string s;\n  cin>>s;\n\n  using R = Rint<int>;\n  R::set_mod(p);\n  R ans(as[0]);\n  for(int i=1;i<n;i++){\n    if(s[i-1]=='+') ans+=R(as[i]);\n    if(s[i-1]=='-') ans-=R(as[i]);\n    if(s[i-1]=='*') ans*=R(as[i]);\n    if(s[i-1]=='/') ans/=R(as[i]);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4706.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4706\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../tools/chminmax.cpp\"\n#include \"../../toptree/toptree.cpp\"\n#undef call_from_test\n\nstruct Vertex{\n  void* handle;\n  Vertex():handle(nullptr){}\n};\n\nusing ll = long long;\nconst ll INF = 1e9 + 10;\nstruct Cluster{\n  ll len;\n  ll lft,rgh,mid,ans;\n  Cluster(ll len=INF):len(len),lft(len),rgh(len),mid(INF),ans(INF){}\n  void toggle(){\n    swap(lft,rgh);\n  }\n  static Cluster compress(Cluster x,Vertex *,Cluster y){\n    Cluster nxt(x.len+y.len);\n    nxt.lft=y.lft;\n    nxt.rgh=x.rgh;\n    nxt.ans=min({x.ans,y.ans,x.mid});\n    return nxt;\n  }\n  static Cluster rake(Cluster x,Cluster y){\n    x.mid=min({x.mid,y.mid,y.lft});\n    return x;\n  }\n};\n\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  const size_t N = 1e5;\n  TopTree<Vertex, Cluster, N> T;\n\n  int n;\n  cin>>n;\n\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++) vs[i]=T.create();\n\n  for(int i=1;i<n;i++){\n    int u,v,w;\n    cin>>u>>v>>w;\n    u--;v--;\n    T.link(vs[u],Cluster(w),vs[v]);\n  }\n\n  int q;\n  cin>>q;\n  for(int i=0;i<q;i++){\n    int x,y;\n    cin>>x>>y;\n    x--;y--;\n    auto res=T.get_path(vs[x],vs[y]);\n    ll ans=res.ans;\n\n    chmin(ans,T.get_subtree(vs[x],vs[y]).lft);\n    chmin(ans,T.get_subtree(vs[x],vs[y]).mid);\n    chmin(ans,T.get_subtree(vs[y],vs[x]).lft);\n    chmin(ans,T.get_subtree(vs[y],vs[x]).mid);\n\n    if(ans==INF) cout<<-1<<newl;\n    else cout<<res.len+2*ans<<newl;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4778.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4778\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../vector/near.cpp\"\n#include \"../../vector/compress.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n;\n  cin>>n;\n  vector<int> xs(n),rs(n);\n  for(int i=0;i<n;i++) cin>>xs[i]>>rs[i];\n  xs=mul(xs,2);\n  rs=mul(rs,2);\n\n  auto vs=compress(near(near(xs,0,rs,mul(rs,-1)),-1,0,1));\n  auto dc=dict(vs);\n\n  vector<int> sm(vs.size(),0);\n  for(int i=0;i<n;i++){\n    sm[dc[xs[i]-rs[i]+1]]++;\n    sm[dc[xs[i]+rs[i]]]--;\n  }\n  for(int i=1;i<(int)vs.size();i++) sm[i]+=sm[i-1];\n\n  cout<<*max_element(sm.begin(),sm.end())<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4852.test.cpp",
    "content": "#define PROBLEM \"https://yukicoder.me/problems/4852\"\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#include \"../../io/tuple.cpp\"\n#include \"../../tools/fixpoint.cpp\"\n#include \"../../tree/lowestcommonancestor.cpp\"\n#include \"../../tree/auxiliarytree.cpp\"\n#include \"../../vector/compress.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n  using ll = long long;\n  using P = pair<int, ll>;\n\n  int n,q;\n  cin>>n>>q;\n  vector<vector<P>> G(n+1);\n  AuxiliaryTree H(n+1);\n  for(int i=1;i<n;i++){\n    int a,b;\n    ll c;\n    cin>>a>>b>>c;\n    G[a].emplace_back(b,c);\n    G[b].emplace_back(a,c);\n    H.add_edge(a,b);\n  }\n  // add 0 for root\n  H.add_edge(0,1);\n  H.build(0);\n\n  const ll INF = 1e15;\n  G[0].emplace_back(1,INF);\n\n  vector<ll> dep(n+1);\n  MFP([&](auto dfs,int v,int p,ll d)->void{\n    dep[v]=d;\n    for(auto [u,c]:G[v])\n      if(u!=p) dfs(u,v,d+c);\n  })(0,-1,0);\n\n  auto [type,vs,ts,ls]=read_tuple<int, int, ll, ll>(q);\n\n  // vanish vertices\n  vector<int> rs(q);\n  for(int i=0;i<q;i++){\n    if(type[i]!=0) continue;\n    int r=vs[i];\n    ll d=dep[vs[i]]-ls[i];\n    for(int k=H.h-1;k>=0;k--){\n      int p=H.par[k][r];\n      if(~p and d<=dep[p]) r=p;\n    }\n    rs[i]=H.par[0][r];\n  }\n\n  vector<ll> pos;\n  for(int i=0;i<q;i++)\n    pos.emplace_back(ts[i]+dep[vs[i]]);\n  pos=compress(pos);\n\n  BIT<int> bit(pos.size());\n  vector<int> cs(q);\n  for(int i=0;i<q;i++)\n    cs[i]=lower_bound(pos.begin(),pos.end(),ts[i]+dep[vs[i]])-pos.begin();\n\n  queue<P> que;\n  que.emplace(0,q);\n\n  vector<int> ans(q);\n  vector<vector<int>> add(n+1),sub(n+1),query(n+1);\n  while(!que.empty()){\n    auto [L,R]=que.front();que.pop();\n    if(L+1==R) continue;\n    int M=(L+R)>>1;\n\n    vector<int> ss;\n    for(int i=L;i<M;i++){\n      if(type[i]==0){\n        ss.emplace_back(vs[i]);\n        ss.emplace_back(rs[i]);\n        add[vs[i]].emplace_back(i);\n        sub[rs[i]].emplace_back(i);\n      }\n    }\n\n    for(int i=M;i<R;i++){\n      if(type[i]==1){\n        ss.emplace_back(vs[i]);\n        query[vs[i]].emplace_back(i);\n      }\n    }\n\n    ss.emplace_back(0);\n    H.query(ss);\n\n    auto expand=[&](int v){\n      for(int i:add[v]) bit.add(cs[i],+1);\n      for(int i:sub[v]) bit.add(cs[i],-1);\n    };\n\n    MFP([&](auto dfs,int v,int p)->void{\n      for(int i:query[v])\n        ans[i]-=bit.query(0,cs[i]+1);\n\n      for(int u:H.T[v])\n        if(u!=p) dfs(u,v);\n      expand(v);\n\n      for(int i:query[v])\n        ans[i]+=bit.query(0,cs[i]+1);\n    })(0,-1);\n\n    H.clear(ss);\n\n    for(int i=L;i<M;i++){\n      if(type[i]==0){\n        add[vs[i]].clear();\n        sub[rs[i]].clear();\n      }\n    }\n\n    for(int i=M;i<R;i++){\n      if(type[i]==1){\n        query[vs[i]].clear();\n      }\n    }\n\n    que.emplace(L,M);\n    que.emplace(M,R);\n  }\n\n  for(int i=0;i<q;i++)\n    if(type[i]==1) cout<<ans[i]<<newl;\n\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4862.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4862\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../toptree/toptree.cpp\"\n#include \"../../toptree/distancesum.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n  const char newl = '\\n';\n\n  int n,m,q;\n  cin>>n>>m>>q;\n\n  auto cs=read(m);\n  vector<ll> cnt(n,0);\n  for(int &c:cs) cnt[--c]++;\n\n  constexpr size_t N = 1e5;\n  using Cluster = DistanceSum<ll>;\n  TopTree<Vertex, Cluster, N> G;\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++) vs[i]=G.create(cnt[i]);\n\n  for(int i=1;i<n;i++){\n    int a,b;\n    cin>>a>>b;\n    a--;b--;\n    G.link(vs[a],1,vs[b]);\n  }\n\n  int flg=0;\n  for(int i=0;i<q;i++){\n    int t;\n    cin>>t;\n    if(t==1){\n      int p,d;\n      cin>>p>>d;\n      p--;d--;\n      G.set_vertex(vs[cs[p]],--cnt[cs[p]]);\n      cs[p]=d;\n      G.set_vertex(vs[cs[p]],++cnt[cs[p]]);\n    }\n    if(t==2){\n      int e;\n      cin>>e;\n      e--;\n      cout<<G.get_subtree(vs[e]).ans<<newl;\n      flg=1;\n    }\n  }\n  if(!flg) cout<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4872.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4872\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../vector/runlength.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  auto as=read(n);\n  auto bs=read(n);\n\n  vector<int> cs(n);\n  for(int i=0;i<n;i++) cs[i]=as[i]^bs[i];\n\n  int ans=0;\n  for(auto[v,_]:runlength(cs)) ans+=v;\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4918.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4918\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/tuple.cpp\"\n#include \"../../tools/chminmax.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m;\n  cin>>n>>m;\n  auto [as, bs]=read_tuple<int, int>(m);\n\n  vector G(n,vector(n,n));\n\n  for(int i=0;i<n;i++) G[i][i]=0;\n\n  for(int i=0;i<m;i++){\n    as[i]--;bs[i]--;\n    G[as[i]][bs[i]]=1;\n    G[bs[i]][as[i]]=1;\n  }\n\n  for(int k=0;k<n;k++)\n    for(int i=0;i<n;i++)\n      for(int j=0;j<n;j++)\n        chmin(G[i][j],G[i][k]+G[k][j]);\n\n  int ans=0;\n  for(int i=0;i<n;i++)\n    for(int j=0;j<i;j++)\n      for(int k=0;k<j;k++)\n        if(G[i][j]!=2 and G[i][k]!=2 and G[j][k]!=2) ans++;\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/4941.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/4941\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/fraction.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  string s,t;\n  cin>>s>>t;\n  int a=(s[0]-'0')*10+(s[1]-'0');\n  int b=(t[0]-'0')*10+(t[1]-'0');\n\n  using F = fraction<int>;\n  F c(a*60+b,1);\n  F d(720,11);\n  F x(0,1);\n  while(x<c) x=x+d;\n  x=x-c;\n  cout<<x.num*60/x.den<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/5011.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/5011\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../math/quotients.cpp\"\n#include \"../../mod/mint.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  using ll = long long;\n\n  ll n;\n  cin>>n;\n\n  using M = Mint<int>;\n  M ans{0};\n\n  for(auto[l,r]:quotients(n)){\n    if(l==1) continue;\n\n    ll d=n/l;\n    if(d<l){\n      ans+=M(n)*M(r-l+1);\n      ans-=M(d)*M(l-1+r-1)*M(r-l+1)/M(2);\n      continue;\n    }\n\n    for(ll i=l;i<=r;i++)\n      for(ll t=n;t;t/=i) ans+=M(t%i);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/5025.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/5025\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../convolution/bitwise/fwht.cpp\"\n#include \"../../convolution/bitwise/or.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n  vector<int> as(1<<n);\n  for(int &a:as) cin>>a;\n  int sum=0;\n  for(int a:as) sum+=a;\n\n  using M = Mint<int, 998244353>;\n  vector<M> dp(1<<n);\n  for(int i=0;i<(int)as.size();i++)\n    dp[i]=M(as[i])/M(sum);\n\n  fwht(dp,bitwise_or::zeta);\n  for(int i=0;i<(int)dp.size();i++)\n    dp[i]=M(1)/(M(1)-dp[i]);\n  fwht(dp,bitwise_or::moebius);\n\n  cout<<accumulate(dp.begin(),dp.end()-1,M(0))<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/5061.test.cpp",
    "content": "#define PROBLEM \"https://yukicoder.me/problems/5061\"\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../vector/fusion.cpp\"\n#include \"../../vector/compress.cpp\"\n#include \"../../datastructure/slope.cpp\"\n#undef call_from_test\n\n#ifdef SANITIZE\n#define IGNORE\n#endif\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int m,n;\n  cin>>m>>n;\n  auto as=read(m);\n  auto bs=read(n);\n\n  auto cs=compress(fusion(as,bs));\n  auto dc=dict(cs);\n  for(int &a:as) a=dc[a];\n  for(int &b:bs) b=dc[b];\n\n  const int sz = cs.size();\n  vector<int> num(sz,0);\n  for(int a:as) num[a]--;\n\n  using ll = long long;\n  for(int k=1;k<=m;k++){\n    for(int b:bs) num[b]++;\n\n    int pos=0;\n    Slope<ll> S;\n    S.add_a_minus_x(pos,1e9);\n    for(int i=0;i<sz;i++){\n      if(num[i]==0) continue;\n      S.add_a_minus_x(0,cs[i]-pos);\n      S.add_x_minus_a(0,cs[i]-pos);\n      pos=cs[i];\n      S.shift(-num[i]);\n      S.apply_cumulative_min();\n    }\n\n    cout<<S.get_val(0)<<'\\n';\n  }\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/5223.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/5223\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../algorithm/mo.cpp\"\n#include \"../../segtree/basic/lazy.cpp\"\n#include \"../../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n  const char newl = '\\n';\n\n  int n,q;\n  cin>>n>>q;\n\n  vector<int> as(n);\n  for(int i=0;i<n;i++) cin>>as[i];\n\n  auto f=[&](int a,int b){return min(a,b);};\n  auto g=[&](int a,int b){return a+b;};\n  int ti(1e9),ei(0);\n  SegmentTree<int, int> seg(f,g,g,ti,ei);\n  seg.build(vector<int>(n+2,0));\n\n  BIT<int> bitL(n+2),bitR(n+2);\n\n  using ll = long long;\n  ll res=0;\n  auto expandL=[&](int i){\n    res-=bitL.query(as[i]+1,n+2);\n    res-=bitR.query(0,as[i]);\n    bitL.add(as[i],-1);\n    seg.update(0,as[i],-1);\n  };\n  auto expandR=[&](int i){\n    res-=bitL.query(as[i]+1,n+2);\n    res-=bitR.query(0,as[i]);\n    bitR.add(as[i],-1);\n    seg.update(as[i]+1,n+2,-1);\n  };\n  auto shrinkL=[&](int i){\n    res+=bitL.query(as[i]+1,n+2);\n    res+=bitR.query(0,as[i]);\n    bitL.add(as[i],+1);\n    seg.update(0,as[i],+1);\n  };\n  auto shrinkR=[&](int i){\n    res+=bitL.query(as[i]+1,n+2);\n    res+=bitR.query(0,as[i]);\n    bitR.add(as[i],+1);\n    seg.update(as[i]+1,n+2,+1);\n  };\n\n  for(int i=n-1;i>=0;i--){\n    res+=bitR.query(0,as[i]);\n    bitR.add(as[i],+1);\n    seg.update(as[i]+1,n+2,+1);\n  }\n\n  Mo mo(n,200,expandL,expandR,shrinkL,shrinkR);\n\n  vector<int> ls,rs;\n  for(int i=0;i<q;i++){\n    int l,r;\n    cin>>l>>r;\n    l--;\n    ls.emplace_back(l);\n    rs.emplace_back(r);\n    mo.add(l,r);\n  }\n\n  mo.build();\n  vector<ll> ans(q,0);\n  for(int i=0;i<q;i++){\n    int k=mo.process();\n    ans[k]=(rs[k]-ls[k])*seg.query(0,n+2)+res;\n  }\n\n  for(int i=0;i<q;i++) cout<<ans[i]<<newl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/5633.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/5633\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../vector/powers.cpp\"\n#include \"../../convolution/numbertheoretictransform.cpp\"\n#include \"../../combinatorics/enumeration.cpp\"\n#include \"../../formalpowerseries/base.cpp\"\n#include \"../../formalpowerseries/inv.cpp\"\n#include \"../../formalpowerseries/diff.cpp\"\n#include \"../../formalpowerseries/integral.cpp\"\n#include \"../../formalpowerseries/log.cpp\"\n#include \"../../formalpowerseries/exp.cpp\"\n#include \"../../formalpowerseries/pow.cpp\"\n#include \"../../formalpowerseries/998244353.cpp\"\n#undef call_from_test\n\n//INSERT ABOVE HERE\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n,m,k;\n  cin>>n>>m>>k;\n\n  using namespace fps_998244353;\n  E::init(n+m);\n\n  auto ps=FPS.exp({M(0),M(1)},n+1);\n  ps[0]-=M(1);\n  auto qs=FPS.pow(ps,k,n+1);\n\n  auto po=powers(n,M(m));\n\n  M ans{0};\n  for(int l=k;l<=n;l++)\n    ans+=E::C(m,k)*E::C(n,l)*E::Fact(l)*qs[l]*po[n-l];\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/6680.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/6680\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../io/single.cpp\"\n#include \"../../graph/grid.cpp\"\n#include \"../../graph/dijkstra.cpp\"\n#undef call_from_test\n\nsigned main(){\n  using ll = long long;\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int h,w;\n  cin>>h>>w;\n  ll u,d,r,l,k,p;\n  cin>>u>>d>>r>>l>>k>>p;\n  int ys,xs,yt,xt;\n  cin>>ys>>xs>>yt>>xt;\n  ys--;xs--;yt--;xt--;\n\n  auto C=read<string>(h);\n\n  map<int, ll> cost;\n  cost[-w]=u;\n  cost[+w]=d;\n  cost[+1]=r;\n  cost[-1]=l;\n\n  Grid G(h,w,[&](int y,int x){return C[y][x];});\n  Dijkstra<ll> D(h*w);\n  for(auto[a,b]:G.edges()){\n    if(G[a]=='#' or G[b]=='#') continue;\n    D.add_edge(a,b,cost[b-a]+p*(G[b]=='@'));\n    D.add_edge(b,a,cost[a-b]+p*(G[a]=='@'));\n  }\n\n  D.build(G.idx(ys,xs));\n  cout<<(D[G.idx(yt,xt)]<=k?\"Yes\":\"No\")<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/7107.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/7107\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../mod/mint.cpp\"\n#include \"../../math/moebius.cpp\"\n#include \"../../convolution/divisor.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  int n;\n  cin>>n;\n\n  using M = Mint<int, 998244353>;\n  vector<M> emp(n+1,0),way(n+1,0);\n  M cnt{0};\n  M all{0};\n\n  auto sign=moebius(n);\n  using ll = long long;\n  for(int i=1;i<=n;i++){\n    emp[i]=M((ll)sign[i])*M(1).pow(n/i);\n    way[i]=M((ll)sign[i])*M(2).pow(n/i);\n    cnt+=emp[i];\n    all+=way[i];\n  }\n\n  LCMConvolution::zeta(way);\n  LCMConvolution::zeta(emp);\n\n  vector<M> dp0(n+1,0),dp1(n+1,0),dp2(n+1,0);\n  for(int i=1;i<=n;i++){\n    dp0[i]=emp[i]*emp[i];\n    dp1[i]=emp[i]*way[i];\n    dp2[i]=way[i]*way[i];\n  }\n\n  LCMConvolution::moebius(dp0);\n  LCMConvolution::moebius(dp1);\n  LCMConvolution::moebius(dp2);\n\n  M ans=(all-cnt)*(all-cnt);\n  M cof=M(3)/M(4);\n  for(int i=1;i<=n;i++){\n    ans+=dp0[i];\n    ans-=dp1[i]*M(2);\n    ans+=dp2[i]*cof.pow(n/i);\n\n    ans-=dp0[i];\n    ans+=dp1[i]*M(2);\n    ans-=dp2[i];\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n"
  },
  {
    "path": "test/yukicoder/9158.test.cpp",
    "content": "// verification-helper: PROBLEM https://yukicoder.me/problems/9158\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../../datastructure/unionfind.cpp\"\n#include \"../../toptree/toptree.cpp\"\n#include \"../../toptree/farthest.cpp\"\n#undef call_from_test\n\nsigned main(){\n  cin.tie(0);\n  ios::sync_with_stdio(0);\n\n  using ll = long long;\n  const char newl = '\\n';\n\n  const size_t N = 2e5+10;\n  using Cluster = Farthest<ll>;\n  TopTree<Vertex, Cluster, N> G;\n\n  int n;\n  ll x;\n  int q;\n  cin>>n>>x>>q;\n\n  vector<Vertex*> vs(n);\n  for(int i=0;i<n;i++) vs[i]=G.create();\n\n  UnionFind uf(n);\n  for(int t=0;t<q;t++){\n    int k;\n    cin>>k;\n    if(k==1){\n      int v;\n      ll w;\n      cin>>v>>w;\n      G.link(vs[v],Cluster(w,v,x),vs[x]);\n      uf.unite(v,x);\n    }\n    if(k==2){\n      int u,v;\n      cin>>u>>v;\n      if(uf.same(u,v)){\n        ll len=(u==v?0:G.get_path(vs[u],vs[v]).len);\n        cout<<len<<newl;\n        x+=len;\n        x%=n;\n      }else{\n        cout<<-1<<newl;\n      }\n    }\n    if(k==3){\n      int v;\n      cin>>v;\n      auto p=G.get_subtree(vs[v]).md;\n      if(p.dist==0){\n        cout<<0<<newl;\n      }else{\n        cout<<G.get_subtree(vs[p.idx]).md.dist<<newl;\n      }\n    }\n    if(k==4){\n      int value;\n      cin>>value;\n      x+=value;\n      x%=n;\n    }\n  }\n\n  return 0;\n}\n"
  },
  {
    "path": "tools/all_permutations.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename F>\nvoid all_permutations(int n,F f){\n  vector<int> vs(n);\n  iota(vs.begin(),vs.end(),0);\n  do f(vs); while(next_permutation(vs.begin(),vs.end()));\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/avx2.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n// https://beet-aizu.hatenablog.com/entry/2020/09/04/173522\n//BEGIN CUT HERE\n#pragma GCC optimize (\"O3\")\n#pragma GCC target (\"avx2\") // or sse4\n#pragma GCC optimize(\"unroll-loops\")\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/bigint.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../convolution/fastfouriertransform.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nstruct bigint {\n  using ll = long long;\n  using vll = vector<ll>;\n\n  inline static constexpr ll base_digits = 9;\n  inline static constexpr ll base = 1000000000;\n\n  vll a;\n  ll sign;\n\n  bigint():sign(1){}\n\n  bigint(ll v){*this=v;}\n\n  bigint(const string &s){read(s);}\n\n  static bigint add_identity(){return bigint(0);}\n  static bigint mul_identity(){return bigint(1);}\n\n  void operator=(ll v){\n    sign=1;\n    if(v<0) sign=-1,v=-v;\n    for(;v>0;v=v/base) a.emplace_back(v%base);\n  }\n\n  bigint operator+(const bigint &v) const{\n    if(sign==v.sign){\n      bigint res=v;\n      for(ll i=0,carry=0;i<(ll)max(a.size(),v.a.size()) or carry;++i){\n        if(i==(ll)res.a.size()) res.a.emplace_back(0);\n        res.a[i]+=carry+(i<(ll)a.size()?a[i]:0);\n        carry=res.a[i]>=base;\n        if(carry) res.a[i]-=base;\n      }\n      return res;\n    }\n    return *this-(-v);\n  }\n\n  bigint operator-(const bigint &v) const{\n    if(sign==v.sign){\n      if(abs()>=v.abs()){\n        bigint res=*this;\n        for(ll i=0,carry=0;i<(ll)v.a.size() or carry;++i){\n          res.a[i]-=carry+(i<(ll)v.a.size()?v.a[i]:0);\n          carry=res.a[i]<0;\n          if(carry) res.a[i]+=base;\n        }\n        res.trim();\n        return res;\n      }\n      return -(v-*this);\n    }\n    return *this+(-v);\n  }\n\n  void operator*=(ll v){\n    if(v<0) sign=-sign,v=-v;\n    for(ll i=0,carry=0;i<(ll)a.size() or  carry;++i){\n      if(i ==(ll)a.size()) a.emplace_back(0);\n      ll cur=a[i] *(ll)v+carry;\n      carry=(ll)(cur/base);\n      a[i]=(ll)(cur%base);\n      // asm(\"divl %%ecx\" : \"=a\"(carry),\"=d\"(a[i]) : \"A\"(cur),\"c\"(base));\n    }\n    trim();\n  }\n\n  bigint operator*(ll v) const{\n    bigint res=*this;\n    res*=v;\n    return res;\n  }\n\n  friend pair<bigint,bigint> divmod(const bigint &a1,const bigint &b1){\n    ll norm=base/(b1.a.back()+1);\n    bigint a=a1.abs()*norm;\n    bigint b=b1.abs()*norm;\n    bigint q,r;\n    q.a.resize(a.a.size());\n\n    for(ll i=a.a.size()-1;i>=0;i--){\n      r *=base;\n      r+=a.a[i];\n      ll s1=r.a.size()<=b.a.size() ? 0 : r.a[b.a.size()];\n      ll s2=r.a.size()<=b.a.size()-1 ? 0 : r.a[b.a.size()-1];\n      ll d=((ll)base*s1+s2)/b.a.back();\n      r-=b*d;\n      while(r<0) r+=b,--d;\n      q.a[i]=d;\n    }\n\n    q.sign=a1.sign*b1.sign;\n    r.sign=a1.sign;\n    q.trim();\n    r.trim();\n    return make_pair(q,r/norm);\n  }\n\n  bigint operator/(const bigint &v) const{\n    return divmod(*this,v).first;\n  }\n\n  bigint operator%(const bigint &v) const{\n    return divmod(*this,v).second;\n  }\n\n  void operator/=(ll v){\n    if(v<0) sign=-sign,v=-v;\n    for(ll i=(ll)a.size()-1,rem=0;i>=0;--i){\n      ll cur=a[i]+rem *(ll)base;\n      a[i]=(ll)(cur/v);\n      rem=(ll)(cur%v);\n    }\n    trim();\n  }\n\n  bigint operator/(ll v) const{\n    bigint res=*this;\n    res/=v;\n    return res;\n  }\n\n  ll operator%(ll v) const{\n    if(v<0) v=-v;\n    ll m=0;\n    for(ll i=a.size()-1;i>=0;--i) m=(a[i]+m*(ll)base)%v;\n    return m*sign;\n  }\n\n  void operator+=(const bigint &v){\n    *this=*this+v;\n  }\n\n  void operator-=(const bigint &v){\n    *this=*this-v;\n  }\n\n  void operator*=(const bigint &v){\n    *this=*this*v;\n  }\n\n  void operator/=(const bigint &v){\n    *this=*this/v;\n  }\n\n  bool operator<(const bigint &v) const{\n    if(sign!=v.sign) return sign<v.sign;\n    if(a.size()!=v.a.size()) return a.size()*sign<v.a.size()*v.sign;\n    for(ll i=a.size()-1;i>=0;i--)\n      if(a[i]!=v.a[i]) return a[i]*sign<v.a[i]*sign;\n    return false;\n  }\n\n  bool operator>(const bigint &v) const{\n    return v<*this;\n  }\n\n  bool operator<=(const bigint &v) const{\n    return !(v<*this);\n  }\n\n  bool operator>=(const bigint &v) const{\n    return !(*this<v);\n  }\n\n  bool operator==(const bigint &v) const{\n    return !(*this<v) and !(v<*this);\n  }\n\n  bool operator!=(const bigint &v) const{\n    return *this<v or v<*this;\n  }\n\n  void trim(){\n    while(!a.empty() and !a.back()) a.pop_back();\n    if(a.empty()) sign=1;\n  }\n\n  bool isZero() const{\n    return a.empty() or (a.size()==1 and !a[0]);\n  }\n\n  bigint operator-() const{\n    bigint res=*this;\n    res.sign=-sign;\n    return res;\n  }\n\n  bigint abs() const{\n    bigint res=*this;\n    res.sign*=res.sign;\n    return res;\n  }\n\n  ll longValue() const{\n    ll res=0;\n    for(ll i=a.size()-1;i>=0;i--) res=res*base+a[i];\n    return res*sign;\n  }\n\n  friend bigint gcd(const bigint &a,const bigint &b){\n    return b.isZero()?a:gcd(b,a%b);\n  }\n\n  friend bigint lcm(const bigint &a,const bigint &b){\n    return a/gcd(a,b)*b;\n  }\n\n  void read(const string &s){\n    sign=1;\n    a.clear();\n    ll pos=0;\n    while(pos<(ll)s.size() and (s[pos]=='-' or s[pos]=='+')){\n      if(s[pos]=='-') sign=-sign;\n      ++pos;\n    }\n    for(ll i=s.size()-1;i>=pos;i-=base_digits){\n      ll x=0;\n      for(ll j=max(pos,i-base_digits+1);j<=i;j++) x=x*10+s[j]-'0';\n      a.emplace_back(x);\n    }\n    trim();\n  }\n\n  friend istream &operator>>(istream &stream,bigint &v){\n    string s;\n    stream>>s;\n    v.read(s);\n    return stream;\n  }\n\n  friend ostream &operator<<(ostream &stream,const bigint &v){\n    if(v.sign==-1) stream<<'-';\n    stream<<(v.a.empty()?0:v.a.back());\n    for(ll i=(ll)v.a.size()-2;i>=0;--i)\n      stream<<setw(base_digits)<<setfill('0')<<v.a[i];\n    return stream;\n  }\n\n  static vll convert_base(const vll &a,ll old_digits,ll new_digits){\n    vll p(max(old_digits,new_digits)+1);\n    p[0]=1;\n    for(ll i=1;i<(ll)p.size();i++) p[i]=p[i-1]*10;\n    vll res;\n    ll cur=0;\n    ll cur_digits=0;\n    for(ll i=0;i<(ll)a.size();i++){\n      cur+=a[i]*p[cur_digits];\n      cur_digits+=old_digits;\n      while(cur_digits>=new_digits){\n        res.emplace_back(signed(cur%p[new_digits]));\n        cur/=p[new_digits];\n        cur_digits-=new_digits;\n      }\n    }\n    res.emplace_back((signed)cur);\n    while(!res.empty() and !res.back()) res.pop_back();\n    return res;\n  }\n\n  static vll karatsubaMultiply(vll &a,vll &b){\n    {\n      while(a.size()<b.size()) a.emplace_back(0);\n      while(b.size()<a.size()) b.emplace_back(0);\n      while(a.size()&(a.size()-1)) a.emplace_back(0),b.emplace_back(0);\n    }\n\n    ll n=a.size();\n    vll res(n+n);\n    if(n<=32){\n      for(ll i=0;i<n;i++)\n        for(ll j=0;j<n;j++)\n          res[i+j]+=a[i]*b[j];\n      return res;\n    }\n\n    ll k=n>>1;\n    vll a1(a.begin(),a.begin()+k);\n    vll a2(a.begin()+k,a.end());\n    vll b1(b.begin(),b.begin()+k);\n    vll b2(b.begin()+k,b.end());\n\n    vll a1b1=karatsubaMultiply(a1,b1);\n    vll a2b2=karatsubaMultiply(a2,b2);\n\n    for(ll i=0;i<k;i++) a2[i]+=a1[i];\n    for(ll i=0;i<k;i++) b2[i]+=b1[i];\n\n    vll r=karatsubaMultiply(a2,b2);\n    for(ll i=0;i<(ll)a1b1.size();i++) r[i]-=a1b1[i];\n    for(ll i=0;i<(ll)a2b2.size();i++) r[i]-=a2b2[i];\n\n    for(ll i=0;i<(ll)r.size();i++) res[i+k]+=r[i];\n    for(ll i=0;i<(ll)a1b1.size();i++) res[i]+=a1b1[i];\n    for(ll i=0;i<(ll)a2b2.size();i++) res[i+n]+=a2b2[i];\n    return res;\n  }\n\n  bigint operator*(const bigint &v) const{\n    constexpr static ll nbase = 10000;\n    constexpr static ll nbase_digits = 4;\n\n    vll a=convert_base(this->a,base_digits,nbase_digits);\n    vll b=convert_base(v.a,base_digits,nbase_digits);\n\n    if(a.empty() or b.empty()) return bigint(0);\n\n    vll c=karatsubaMultiply(a,b);\n    // vll c=FFT::multiply(a,b);\n\n    bigint res;\n    res.sign=sign*v.sign;\n    for(ll i=0,carry=0;i<(ll)c.size();i++){\n      ll cur=c[i]+carry;\n      res.a.emplace_back((ll)(cur%nbase));\n      carry=(ll)(cur/nbase);\n      if(i+1==(int)c.size() and carry>0) c.emplace_back(0);\n    }\n\n    res.a=convert_base(res.a,nbase_digits,base_digits);\n    res.trim();\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/cc_hash.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct cc_hash{\n  uint64_t operator()(T x) const{\n    uint64_t y(x);\n    y += 0x9e3779b97f4a7c15;\n    y = (y ^ (y >> 30)) * 0xbf58476d1ce4e5b9;\n    y = (y ^ (y >> 27)) * 0x94d049bb133111eb;\n    return y ^ (y >> 31);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/chminmax.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}\ntemplate<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/debug.cpp",
    "content": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define IGNORE\n\n//BEGIN CUT HERE\nconst int DEBUG = 1;\ntemplate<typename ...Ts>\nvoid debug(Ts... ts){\n  if(!DEBUG) return;\n  cout<<\"#:\";\n  auto print=[](auto v){cout<<v<<\" \";};\n  initializer_list<int>{(void(print(ts)),0)...};\n  cout<<endl;\n}\n//END CUT HERE\n//INSERT ABOVE HERE\nsigned main(){\n  int a=42;\n  string s=\"UKU\";\n  char c='$';\n  debug(a,100,s,c);\n  return 0;\n}\n"
  },
  {
    "path": "tools/defaultdict.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename Key,typename T>\nstruct DefaultDict : map<Key, T>{\n  using super = map<Key, T>;\n  const T val;\n  DefaultDict(T val_):val(val_){}\n  T& operator[](const Key& key){\n    if(!super::count(key))\n      super::operator[](key)=val;\n    return super::operator[](key);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/dice.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T=int>\nstruct Die{\n  array<T, 6> fs;\n  int &top()   {return fs[0];}\n  int &south() {return fs[1];}\n  int &east()  {return fs[2];}\n  int &west()  {return fs[3];}\n  int &north() {return fs[4];}\n  int &bottom(){return fs[5];}\n  void roll(char c){\n    //the view from above\n    // N\n    //W E\n    // S\n    string b(\"EWNSRL\");\n    int v[6][4]={{0,3,5,2},\n                 {0,2,5,3},\n                 {0,1,5,4},\n                 {0,4,5,1},\n                 {1,2,4,3},\n                 {1,3,4,2}};\n    for(int k=0;k<6;k++){\n      if(b[k]!=c) continue;\n      int t=fs[v[k][0]];\n      fs[v[k][0]]=fs[v[k][1]];\n      fs[v[k][1]]=fs[v[k][2]];\n      fs[v[k][2]]=fs[v[k][3]];\n      fs[v[k][3]]=t;\n    }\n  }\n  using ll = long long;\n  ll hash(){\n    ll res=0;\n    for(int i=0;i<6;i++) res=res*256+fs[i];\n    return res;\n  }\n  bool operator==(const Die &d) const{\n    for(int i=0;i<6;i++) if(fs[i]!=d.fs[i]) return 0;\n    return 1;\n  }\n};\n\ntemplate<typename T>\nvector<Die<T>> makeDice(Die<T> d){\n  vector<Die<T>> res;\n  for(int i=0;i<6;i++){\n    Die t(d);\n    if(i==1) t.roll('N');\n    if(i==2) t.roll('S');\n    if(i==3) t.roll('S'),t.roll('S');\n    if(i==4) t.roll('L');\n    if(i==5) t.roll('R');\n    for(int k=0;k<4;k++){\n      res.emplace_back(t);\n      t.roll('E');\n    }\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/drop.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/fastio.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct FastIO{\n  FastIO(){\n    cin.tie(0);\n    ios::sync_with_stdio(0);\n  }\n}fastio_beet;\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/fixpoint.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename F>\nstruct FixPoint : F{\n  FixPoint(F&& f):F(forward<F>(f)){}\n  template<typename... Args>\n  decltype(auto) operator()(Args&&... args) const{\n    return F::operator()(*this,forward<Args>(args)...);\n  }\n};\ntemplate<typename F>\ninline decltype(auto) MFP(F&& f){\n  return FixPoint<F>{forward<F>(f)};\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/gridbfs.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nvector< vector<int> >\ngridbfs(vector<string> &st,int sy,int sx,char wall,int dir){\n  int h=st.size(),w=st.front().size();\n  vector<vector<int> > dp(h,vector<int>(w,-1));\n  using P = pair<int, int>;\n  queue<P> qu;\n\n  dp[sy][sx]=0;\n  qu.emplace(sy,sx);\n\n  int dy[]={1,-1,0,0,1,1,-1,-1};\n  int dx[]={0,0,1,-1,1,-1,1,-1};\n  auto in=[&](int y,int x){return 0<=y and y<h and 0<=x and x<w;};\n\n  while(!qu.empty()){\n    int y,x;\n    tie(y,x)=qu.front();qu.pop();\n    for(int k=0;k<dir;k++){\n      int ny=y+dy[k],nx=x+dx[k];\n      if(!in(ny,nx) or st[ny][nx]==wall) continue;\n      if(~dp[ny][nx]) continue;\n      dp[ny][nx]=dp[y][x]+1;\n      qu.emplace(ny,nx);\n    }\n  }\n\n  return dp;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/int128.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n/*\n  multiprecision:\n  #include <boost/multiprecision/cpp_int.hpp>\n  using ll = boost::multiprecision::cpp_int;\n*/\n#endif\n//BEGIN CUT HERE\n__int128_t abs128(__int128_t val){return val<0?-val:val;}\n\nostream &operator<<(ostream &os,__int128_t val){\n  if(ostream::sentry(os)){\n    __uint128_t tmp=abs128(val);\n    char buf[64];\n    char *d=end(buf);\n    do{\n      --d;\n      *d=char(tmp%10+'0');\n      tmp/=10;\n    }while(tmp);\n    if(val<0) *--d='-';\n    int len=end(buf)-d;\n    if(os.rdbuf()->sputn(d,len)!=len){\n      os.setstate(ios_base::badbit);\n    }\n  }\n  return os;\n}\n\nistream &operator>>(istream &is,__int128_t &val){\n  string s;\n  is>>s;\n  val=0;\n  for(int i=0;i<(int)s.size();i++)\n    if(isdigit(s[i])) val=val*10+s[i]-'0';\n  if(s[0]=='-') val*=-1;\n  return is;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/iskado.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nbool is_kado(T a,T b,T c){\n  if(a==b or b==c or c==a) return 0;\n  if(a<b and b>c) return 1;\n  if(a>b and b<c) return 1;\n  return 0;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tools/trio.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T, typename U, typename V>\nstruct trio{\n  T first;\n  U second;\n  V third;\n  trio(T first,U second,V third):\n    first(first),second(second),third(third){}\n  operator tuple<T&, U&, V&>(){\n    return forward_as_tuple(first,second,third);\n  }\n  using X = tuple<T, U, V>;\n  operator X() const{return make_tuple(first,second,third);}\n  bool operator==(const trio&a) const{return (X)(*this)==(X)a;}\n  bool operator!=(const trio&a) const{return (X)(*this)!=(X)a;}\n  bool operator< (const trio&a) const{return (X)(*this)< (X)a;}\n  bool operator<=(const trio&a) const{return (X)(*this)<=(X)a;}\n  bool operator> (const trio&a) const{return (X)(*this)> (X)a;}\n  bool operator>=(const trio&a) const{return (X)(*this)>=(X)a;}\n};\ntemplate<typename T, typename U, typename V>\ntrio<T, U, V> make_trio(T first,U second,V third){\n  return trio<T, U, V>(first,second,third);\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "toptree/base.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct Vertex{\n  void* handle;\n  Vertex():handle(nullptr){}\n};\nstruct Cluster{\n  Cluster(){}\n  void toggle(){}\n  static Cluster compress(Cluster x,Vertex *v,Cluster y){}\n  static Cluster rake(Cluster x,Cluster y){}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "toptree/distancesum.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"toptree.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\n\nstruct Vertex{\n  void* handle;\n  // 0: dead, 1: alive\n  int color;\n  Vertex(int color=0):handle(nullptr),color(color){}\n};\n\ntemplate<typename T>\nstruct DistanceSum{\n  struct pi{\n    T cnt;\n    Vertex* ptr;\n    pi():cnt(-1),ptr(nullptr){}\n    pi(T cnt,Vertex* ptr):cnt(cnt),ptr(ptr){}\n    bool operator<(const pi &o)const{return cnt<o.cnt;}\n  };\n\n  T len,cnt,chd,ans;\n  T sum_l,sum_r;\n  pi md;\n\n  DistanceSum(T len=0):len(len),cnt(0),chd(0),ans(0),sum_l(0),sum_r(0){}\n\n  void toggle(){swap(sum_l,sum_r);}\n\n  static DistanceSum compress(\n    const DistanceSum& x,Vertex *v,const DistanceSum& y){\n    DistanceSum nxt;\n    nxt.len=x.len+y.len;\n    nxt.cnt=x.cnt+x.chd+(v->color)+y.cnt;\n    nxt.chd=0;\n    assert(y.chd==0);\n\n    nxt.ans=x.sum_l+y.sum_r;\n\n    nxt.sum_l+=x.sum_l;\n    nxt.sum_l+=y.sum_l;\n    nxt.sum_l+=(x.cnt+x.chd+(v->color))*y.len;\n\n    nxt.sum_r+=x.sum_r;\n    nxt.sum_r+=y.sum_r;\n    nxt.sum_r+=(x.chd+(v->color)+y.cnt)*x.len;\n\n    nxt.md=pi(nxt.cnt,v);\n\n    return nxt;\n  }\n\n  static DistanceSum rake(const DistanceSum& x,const DistanceSum& y){\n    DistanceSum nxt;\n    nxt.len=x.len;\n    nxt.cnt=x.cnt;\n    nxt.chd=x.chd+y.cnt+y.chd;\n\n    nxt.ans=x.sum_l+y.sum_l;\n\n    nxt.sum_l+=x.sum_l;\n    nxt.sum_l+=y.sum_l;\n\n    nxt.sum_r+=x.sum_r;\n    nxt.sum_r+=y.sum_l;\n\n    nxt.md=max(x.md,y.md);\n\n    return nxt;\n  }\n};\n\ntemplate<typename T, size_t N>\nVertex* centroid(TopTree<Vertex, DistanceSum<T>, N> &G, Vertex* v){\n  using TT = typename remove_reference<decltype(G)>::type;\n  using Node = typename TT::Node;\n  using Type = typename TT::Type;\n\n  Node* rt=G.expose(v);\n  if(rt->type==Type::Edge) return v;\n\n  Node* cc=rt;\n  Vertex* ctr=nullptr;\n\n  T lv=0,rv=0,sum=rt->dat.cnt;\n  while(cc->type==Type::Compress){\n    G.propagate(cc);\n\n    Node* ll=cc->ch[0];\n    if((ll->dat.cnt+lv)*2>sum){\n      assert(ll->type!=Type::Edge);\n      rv+=cc->dat.md.cnt-ll->dat.cnt;\n      cc=ll;\n      continue;\n    }\n\n    Node* rr=cc->ch[1];\n    if((rr->dat.cnt+rv)*2>sum){\n      assert(rr->type!=Type::Edge);\n      lv+=cc->dat.md.cnt-rr->dat.cnt;\n      cc=rr;\n      continue;\n    }\n\n    Node* mm=cc->q;\n    if(mm and mm->dat.md.cnt*2>sum){\n      assert(mm->type!=Type::Edge);\n      rv+=lv;lv=0;\n      rv+=cc->dat.md.cnt-mm->dat.md.cnt;\n      cc=(decltype(cc))mm->dat.md.ptr->handle;\n      continue;\n    }\n\n    ctr=cc->dat.md.ptr;\n    break;\n  }\n  return ctr;\n}\n\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "toptree/farthest.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"toptree.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nstruct Vertex{\n  void* handle;\n  Vertex():handle(nullptr){}\n};\n\ntemplate<typename T>\nstruct Farthest{\n  struct pi{\n    T dist;\n    int idx;\n    pi():dist(0),idx(-1){}\n    pi(T dist,int idx):dist(dist),idx(idx){}\n    bool operator<(const pi &o)const{return dist<o.dist;}\n    pi operator+(const T e)const{return pi(dist+e,idx);}\n  };\n  pi md,lf,rg;\n  T len;\n  Farthest():lf(0,-1),rg(0,-1),len(0){}\n  Farthest(T d,int f,int t):lf(d,t),rg(d,f),len(d){}\n  Farthest(pi md,pi lf,pi rg,T len):md(md),lf(lf),rg(rg),len(len){}\n  void toggle(){swap(lf,rg);}\n  static Farthest compress(Farthest &x,Vertex*,Farthest &y){\n    return Farthest(\n      max(x.rg,y.lf),\n      max(x.lf,y.lf+x.len),\n      max(y.rg,x.rg+y.len),\n      x.len+y.len);\n  }\n  static Farthest rake(Farthest &x,Farthest &y){\n    return Farthest(pi(),max(x.lf,y.rg+x.len),max(x.rg,y.rg),x.len);\n  }\n};\n\ntemplate<typename T, size_t N>\nvector<int> get_all_farthests(TopTree<Vertex, Farthest<T>, N> &G,Vertex* v){\n  using TT = typename remove_reference<decltype(G)>::type;\n  using Node = typename TT::Node;\n  using Type = typename TT::Type;\n  vector<int> fs;\n  auto dist=G.get_subtree(v).md.dist;\n  if(dist==T(0)) return {};\n  auto dfs=[&](auto dfs,Node* rt,T d,bool left)->void{\n    if(!rt) return;\n    G.propagate(rt);\n\n    auto cur=left?(rt->dat.lf):(rt->dat.rg);\n    if(d+cur.dist!=dist) return;\n\n    if(rt->type==Type::Edge){\n      if(~cur.idx) fs.emplace_back(cur.idx);\n      return;\n    }\n    if(rt->type==Type::Rake){\n      assert(!left);\n      dfs(dfs,rt->ch[0],d,false);\n      dfs(dfs,rt->ch[1],d,false);\n      return;\n    }\n    if(rt->type==Type::Compress){\n      T mid=rt->ch[left?0:1]->dat.len;\n      dfs(dfs,rt->ch[left?0:1],d,left);\n      dfs(dfs,rt->ch[left?1:0],d+mid,left);\n      dfs(dfs,rt->q,d+mid,false);\n      return;\n    }\n    abort();\n  };\n  auto rt=G.expose(v);\n  assert(rt->type==Type::Compress);\n  dfs(dfs,rt->ch[0],T(0),false);\n  dfs(dfs,rt->ch[1],T(0),true);\n  dfs(dfs,rt->q,T(0),false);\n  return fs;\n}\n\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "toptree/steiner.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct Vertex{\n  void* handle;\n  int color;\n  Vertex(int color=0):handle(nullptr),color(color){}\n};\n\ntemplate<typename T>\nstruct SteinerTree{\n  T con,len,lf,rg,md,chd,ans;\n  SteinerTree(T len=0):con(0),len(len),lf(0),rg(0),md(0),chd(0),ans(0){}\n  void toggle(){return swap(lf,rg);}\n  static SteinerTree compress(SteinerTree x,Vertex* v,SteinerTree y){\n    if(x.chd){\n      if(!x.con){\n        x.con=1;\n        x.lf=x.len;\n        x.rg=0;\n        x.md=x.chd;\n      }else{\n        x.ans+=x.md+x.rg+x.chd;\n        x.md=x.rg=x.chd=0;\n      }\n    }\n\n    if(!x.con and !(v->color) and !y.con)\n      return SteinerTree(x.len+y.len);\n\n    SteinerTree nxt;\n    nxt.con=1;\n    nxt.lf=x.con?x.lf:(v->color?x.len:x.len+y.lf);\n    nxt.rg=y.con?y.rg:(v->color?y.len:y.len+x.rg);\n    nxt.ans=x.ans+y.ans;\n    if(x.con and (v->color or y.con)){\n      nxt.ans+=x.md+x.rg;\n      x.md=0;\n    }\n    if(y.con and (v->color or x.con)){\n      nxt.ans+=y.md+y.lf;\n      y.md=0;\n    }\n    nxt.md=x.md+y.md;\n    return nxt;\n  }\n\n  static SteinerTree rake(SteinerTree x,SteinerTree y){\n    x.chd+=y.chd+y.rg+y.md;\n    x.ans+=y.ans;\n    return x;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "toptree/toptree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename Vertex, typename Cluster, size_t N>\nstruct TopTree{\n  enum Type { Compress, Rake, Edge };\n  struct Node{\n    Vertex* vs[2];\n    Cluster dat;\n    Node* p;\n    Node* q;\n    Node* ch[2];\n    bool rev,guard;\n    Type type;\n    Node(){p=q=nullptr;rev=guard=false;}\n  };\n\n  inline static array<Vertex, 2*N> pool_vertex;\n  inline static size_t ptr_vertex = 0;\n\n  inline static array<Node, 4*N> pool_node;\n  inline static size_t ptr_node = 0;\n\n  Cluster id;\n\n  template<typename ...Args>\n  inline Vertex* create(Args ...args){\n    auto t=&pool_vertex[ptr_vertex++];\n    auto dummy=&pool_vertex[ptr_vertex++];\n    *t=Vertex(forward<Args>(args)...);\n    link(t,id,dummy);\n    return t;\n  }\n\n  Node* recycle=nullptr;\n  inline void dispose_node(Node* t){\n    t->p=recycle;\n    recycle=t;\n  }\n\n  inline Node* get_new_node(){\n    if(recycle) return new(exchange(recycle,recycle->p)) Node;\n    return &(pool_node[ptr_node++]);\n  }\n\n  inline Node* edge(Vertex* u,Cluster w,Vertex* v){\n    auto t=get_new_node();\n    t->vs[0]=u;t->vs[1]=v;t->dat=w;\n    t->type=Type::Edge;\n    return pushup(t);\n  }\n\n  inline Node* compress(Node* l,Node* r){\n    auto t=get_new_node();\n    t->ch[0]=l;t->ch[1]=r;\n    t->type=Type::Compress;\n    return pushup(t);\n  }\n\n  inline Node* rake(Node* l,Node* r){\n    auto t=get_new_node();\n    t->ch[0]=l;t->ch[1]=r;\n    t->type=Type::Rake;\n    return pushup(t);\n  }\n\n  int parent_dir(Node* t){\n    Node* p=t->p;\n    if(!p) return -1;\n    if(p->guard) return -1;\n    if(p->ch[0]==t) return 0;\n    if(p->ch[1]==t) return 1;\n    return -1;\n  }\n\n  int parent_dir_ignore_guard(Node* t){\n    Node* p=t->p;\n    if(!p) return -1;\n    if(p->ch[0]==t) return 0;\n    if(p->ch[1]==t) return 1;\n    return -1;\n  }\n\n  inline Node* pushup(Node* const t){\n    Node* const l=t->ch[0];\n    Node* const r=t->ch[1];\n\n    if(t->type==Type::Compress){\n      assert(l->vs[1]==r->vs[0]);\n      t->vs[0]=l->vs[0];\n      t->vs[1]=r->vs[1];\n\n      Cluster lf=l->dat;\n      if(t->q){\n        assert(l->vs[1]==t->q->vs[1]);\n        lf=Cluster::rake(l->dat,t->q->dat);\n      }\n      t->dat=Cluster::compress(lf,r->vs[0],r->dat);\n\n      l->vs[1]->handle=t;\n    }\n\n    if(t->type==Type::Rake){\n      propagate(t);\n      assert(l->vs[1]==r->vs[1]);\n      t->vs[0]=l->vs[0];\n      t->vs[1]=l->vs[1];\n      t->dat=Cluster::rake(l->dat,r->dat);\n    }else{\n      if(!t->p){\n        t->vs[0]->handle=t;\n        t->vs[1]->handle=t;\n      }else if(t->p->type==Type::Compress){\n        if(parent_dir(t)==-1)\n          t->vs[0]->handle=t;\n      }else if(t->p->type==Type::Rake){\n        t->vs[0]->handle=t;\n      }\n    }\n    return t;\n  }\n\n  inline void toggle(Node* t){\n    if(t->type==Type::Edge){\n      swap(t->vs[0],t->vs[1]);\n      t->dat.toggle();\n    }else if(t->type==Type::Compress){\n      swap(t->vs[0],t->vs[1]);\n      t->dat.toggle();\n      t->rev^=true;\n    }else if(t->type==Type::Rake){\n    }else abort();\n  }\n\n  inline void propagate(Node* t){\n    if(t->type==Type::Compress){\n      if(t->rev){\n        assert(t->ch[0] and t->ch[1]);\n        swap(t->ch[0],t->ch[1]);\n        toggle(t->ch[0]);\n        toggle(t->ch[1]);\n        t->rev=false;\n      }\n    }\n  }\n\n  void set_toggle(Node* v){\n    toggle(v);propagate(v);\n  }\n\n  void pushdown(Node* t){\n    if(!t) return;\n    pushdown(t->p);\n    propagate(t);\n  }\n\n  void rotate(Node* t,Node* x,size_t dir){\n    Node* y=x->p;\n    int par=parent_dir_ignore_guard(x);\n    propagate(t->ch[dir]);\n    x->ch[dir^1]=t->ch[dir];\n    t->ch[dir]->p=x;\n    t->ch[dir]=x;\n    x->p=t;\n    t->p=y;\n    if(~par) y->ch[par]=t;\n    else if(y and y->type==Type::Compress) y->q=t;\n    pushup(x);pushup(t);\n    if(y and !y->guard) pushup(y);\n  }\n\n  void splay(Node* t){\n    assert(t->type!=Type::Edge);\n    propagate(t);\n\n    while(~parent_dir(t)){\n      Node* q=t->p;\n      if(q->type!=t->type) break;\n      if(~parent_dir(q) and q->p and q->p->type==q->type){\n        Node* r=q->p;\n        if(r->p) propagate(r->p);\n        propagate(r);propagate(q);propagate(t);\n        int qt_dir=parent_dir(t);\n        int rq_dir=parent_dir(q);\n        if(rq_dir==qt_dir){\n          rotate(q,r,rq_dir^1);\n          rotate(t,q,qt_dir^1);\n        }else{\n          rotate(t,q,qt_dir^1);\n          rotate(t,r,rq_dir^1);\n        }\n      }else{\n        if(q->p) propagate(q->p);\n        propagate(q);propagate(t);\n        int qt_dir=parent_dir(t);\n        rotate(t,q,qt_dir^1);\n      }\n    }\n  }\n\n  Node* expose(Node* t){\n    pushdown(t);\n    while(true){\n      assert(t->type!=Type::Rake);\n      if(t->type==Type::Compress) splay(t);\n      Node* n=nullptr;\n      {\n        Node* p=t->p;\n        if(!p) break;\n        if(p->type==Type::Rake){\n          propagate(p);\n          splay(p);\n          n=p->p;\n        }\n        if(p->type==Type::Compress){\n          propagate(p);\n          if(p->guard and ~parent_dir_ignore_guard(t)) break;\n          n=p;\n        }\n      }\n      splay(n);\n      int dir=parent_dir_ignore_guard(n);\n      if(dir==-1 or n->p->type==Type::Rake) dir=0;\n\n      Node* const c=n->ch[dir];\n      if(dir==1){\n        set_toggle(c);\n        set_toggle(t);\n      }\n      int n_dir=parent_dir(t);\n      if(~n_dir){\n        Node* const r=t->p;\n        propagate(c);\n        propagate(r);\n        r->ch[n_dir]=c;\n        c->p=r;\n        n->ch[dir]=t;\n        t->p=n;\n        pushup(c);pushup(r);\n        pushup(t);pushup(n);\n        splay(r);\n      }else{\n        propagate(c);\n        n->q=c;\n        c->p=n;\n        n->ch[dir]=t;\n        t->p=n;\n        pushup(c);pushup(t);pushup(n);\n      }\n      if(t->type==Type::Edge) t=n;\n    }\n    return t;\n  }\n\n  Node* expose(Vertex* v){\n    return expose((Node*)(v->handle));\n  }\n\n  void soft_expose(Vertex* u,Vertex* v){\n    pushdown((Node*)u->handle);\n    pushdown((Node*)v->handle);\n    Node* rt=expose(u);\n\n    if(u->handle==v->handle){\n      if(rt->vs[1]==u or rt->vs[0]==v)\n        set_toggle(rt);\n      return;\n    }\n\n    rt->guard=true;\n    Node* soft=expose(v);\n    rt->guard=false;\n\n    pushup(rt);\n    if(parent_dir(soft)==0) set_toggle(rt);\n  }\n\n  void bring(Node* rt){\n    Node* rk=rt->q;\n    if(!rk){\n      Node* ll=rt->ch[0];\n      dispose_node(ll->p);\n      ll->p=nullptr;\n      pushup(ll);\n    }else if(rk->type==Type::Compress or rk->type==Type::Edge){\n      Node* nr=rk;\n      set_toggle(nr);\n      rt->ch[1]=nr;\n      nr->p=rt;\n      rt->q=nullptr;\n\n      pushup(nr);pushup(rt);\n    }else if(rk->type==Type::Rake){\n      propagate(rk);\n      while(rk->ch[1]->type==Type::Rake){\n        propagate(rk->ch[1]);\n        rk=rk->ch[1];\n      }\n      pushdown(rk);\n\n      rt->guard=true;\n      splay(rk);\n      rt->guard=false;\n\n      Node* ll=rk->ch[0];\n      Node* rr=rk->ch[1];\n      propagate(ll);\n      set_toggle(rr);\n\n      rt->ch[1]=rr;\n      rr->p=rt;\n\n      rt->q=ll;\n      ll->p=rt;\n\n      dispose_node(rk);\n      pushup(ll);pushup(rr);pushup(rt);\n    }\n  }\n\n  Node* link(Vertex* u,Cluster w,Vertex* v){\n    if(!u->handle and !v->handle) return edge(u,w,v);\n\n    Node* nnu=(Node*)u->handle;\n    Node* nnv=(Node*)v->handle;\n    Node* ee=edge(u,w,v);\n    Node* ll=nullptr;\n\n    assert(nnv);\n    Node* vv=expose(nnv);\n    propagate(vv);\n    if(vv->vs[1]==v) set_toggle(vv);\n    if(vv->vs[0]==v){\n      Node* nv=compress(ee,vv);\n      ee->p=nv;\n      pushup(ee);\n      vv->p=nv;\n      pushup(vv);pushup(nv);\n      ll=nv;\n    }else{\n      Node* nv=vv;\n      Node* ch=nv->ch[0];\n      propagate(ch);\n      nv->ch[0]=ee;\n      ee->p=nv;\n      pushup(ee);\n\n      Node* bt=nv->q;\n      Node* rk=nullptr;\n      if(bt){\n        propagate(bt);\n        rk=rake(bt,ch);\n        bt->p=rk;\n        ch->p=rk;\n        pushup(bt);pushup(ch);\n      }else{\n        rk=ch;\n      }\n      nv->q=rk;\n      rk->p=nv;\n      pushup(rk);pushup(nv);\n      ll=nv;\n    }\n\n    assert(nnu);\n    Node* uu=expose(nnu);\n    propagate(uu);\n    if(uu->vs[0]==u) set_toggle(uu);\n    if(uu->vs[1]==u){\n      Node* tp=compress(uu,ll);\n      uu->p=tp;\n      ll->p=tp;\n      pushup(uu);pushup(ll);pushup(tp);\n    }else{\n      Node* nu=uu;\n      Node* ch=nu->ch[1];\n      toggle(ch);\n      propagate(ch);\n\n      nu->ch[1]=ll;\n      ll->p=nu;\n      pushup(ll);\n\n      Node* al=nu->q;\n      Node* rk=nullptr;\n      if(al){\n        propagate(al);\n        rk=rake(al,ch);\n        al->p=rk;\n        ch->p=rk;\n        pushup(al);pushup(ch);\n      }else{\n        rk=ch;\n      }\n      nu->q=rk;\n      rk->p=nu;\n      pushup(rk);pushup(nu);\n    }\n    return ee;\n  }\n\n  void cut(Vertex* u,Vertex *v){\n    soft_expose(u,v);\n    Node* rt=(Node*)u->handle;\n    propagate(rt);\n    Node* rr=rt->ch[1];\n    rr->p=nullptr;\n    set_toggle(rr);\n    assert(rr->ch[1]->type==Type::Edge);\n    dispose_node(rr->ch[1]);\n    bring(rr);bring(rt);\n  }\n\n  Node* path(Vertex* u,Vertex* v){\n    assert(u!=v);\n    soft_expose(u,v);\n    Node* rt=(Node*)u->handle;\n    propagate(rt);\n    propagate(rt->ch[1]);\n    return rt->ch[1]->ch[0];\n  }\n\n  void set_vertex(Vertex* u,Vertex v){\n    auto t=expose(u);\n    *u=v;\n    pushup(t);\n  }\n\n  void set_edge(Vertex* u,Vertex* v,const Cluster &w){\n    auto t=path(u,v);\n    assert(t->type==Type::Edge);\n    t->dat=w;\n    while(t) pushup(t),t=t->p;\n  }\n\n  Cluster get_path(Vertex* u,Vertex* v){\n    return path(u,v)->dat;\n  }\n\n  Cluster get_subtree(Vertex* v){\n    return expose(v)->dat;\n  }\n\n  // subtree of v when p is root\n  Cluster get_subtree(Vertex* p,Vertex* v){\n    Node* t=path(p,v);\n    Cluster res=t->p->ch[1]->dat;\n    res.toggle();\n    Node* rk=t->p->q;\n    if(t->p->q){\n      assert(rk->vs[1]==t->p->ch[1]->vs[0]);\n      res=Cluster::rake(res,rk->dat);\n    }\n    return res;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/ahu.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n// http://wwwmayr.in.tum.de/konferenzen/Jass08/courses/1/smal/Smal_Talk.pdf\n//BEGIN CUT HERE\nstruct AHU{\n  inline static map<vector<int>, int> I;\n  vector< vector<int> > G;\n  AHU(int n):G(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  int dfs(int v,int p){\n    vector<int> hs;\n    for(int u:G[v])\n      if(u!=p) hs.emplace_back(dfs(u,v));\n    sort(hs.begin(),hs.end());\n\n    int sz=I.size();\n    if(!I.count(hs)) I[hs]=sz;\n    return I[hs];\n  }\n\n  int build(int r=0){\n    return dfs(r,-1);\n  }\n};\n\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/auxiliarytree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"lowestcommonancestor.cpp\"\n#undef call_from_test\n\n#endif\n\n//BEGIN CUT HERE\nstruct AuxiliaryTree : LowestCommonAncestor{\n  using super = LowestCommonAncestor;\n\n  vector<int> idx;\n  vector<vector<int>> T;\n  AuxiliaryTree(int n):super(n),idx(n),T(n){}\n\n  void dfs(int v,int p,int &pos){\n    idx[v]=pos++;\n    for(int u:G[v])\n      if(u!=p) dfs(u,v,pos);\n  }\n\n  void build(int r=0){\n    super::build(r);\n    int pos=0;\n    dfs(r,-1,pos);\n  }\n\n  void add_aux_edge(int u,int v){\n    T[u].emplace_back(v);\n    T[v].emplace_back(u);\n  }\n\n  using super::lca, super::dep;\n  void query(vector<int> &vs){\n    assert(!vs.empty());\n    sort(vs.begin(),vs.end(),\n         [&](int a,int b){return idx[a]<idx[b];});\n    vs.erase(unique(vs.begin(),vs.end()),vs.end());\n\n    int k=vs.size();\n    stack<int> st;\n    st.emplace(vs[0]);\n    for(int i=0;i+1<k;i++){\n      int w=lca(vs[i],vs[i+1]);\n      if(w!=vs[i]){\n        int l=st.top();st.pop();\n        while(!st.empty() and dep[w]<dep[st.top()]){\n          add_aux_edge(st.top(),l);\n          l=st.top();st.pop();\n        }\n        if(st.empty() or st.top()!=w){\n          st.emplace(w);\n          vs.emplace_back(w);\n        }\n        add_aux_edge(w,l);\n      }\n      st.emplace(vs[i+1]);\n    }\n\n    while(st.size()>1){\n      int c=st.top();st.pop();\n      add_aux_edge(st.top(),c);\n    }\n  }\n\n  void clear(const vector<int> &ws){\n    for(int w:ws) T[w].clear();\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/centroid.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct Centroid{\n  vector<int> sz,dead;\n  vector< vector<int> > G;\n  Centroid(int n):sz(n,1),dead(n,0),G(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  int dfs(int v,int p){\n    sz[v]=1;\n    for(int u:G[v])\n      if(u!=p and !dead[u]) sz[v]+=dfs(u,v);\n    return sz[v];\n  }\n\n  void find(int v,int p,int tmp,vector<int> &cs) {\n    int ok=1;\n    for (int u:G[v]){\n      if(u==p or dead[u]) continue;\n      find(u,v,tmp,cs);\n      ok&=(sz[u]<=tmp/2);\n    }\n    ok&=(tmp-sz[v]<=tmp/2);\n    if(ok) cs.emplace_back(v);\n  }\n\n  vector<int> build(int r) {\n    int tmp=dfs(r,-1);\n    vector<int> cs;\n    find(r,-1,tmp,cs);\n    return cs;\n  }\n\n  const vector<int>& operator[](int k)const{return G[k];}\n  void disable(int v){dead[v]=1;}\n  void  enable(int v){dead[v]=0;}\n  int alive(int v){return !dead[v];}\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/construct_from_distances_to_farthest_vertex.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nvector< vector<int> >\nconstruct_from_distances_to_farthest_vertex(vector<int> ds){\n  int n=ds.size();\n  vector<vector<int>> G(n),NG;\n  for(int d:ds) if(d>=n) return NG;\n\n  vector<int> ts(n,0);\n  vector<queue<int>> qs(n);\n  for(int i=0;i<n;i++){\n    ts[ds[i]]++;\n    qs[ds[i]].emplace(i);\n  }\n\n  int dm=*max_element(ds.begin(),ds.end());\n\n  for(int i=0;i<(dm+1)/2;i++)\n    if(ts[dm-i]<2) return NG;\n\n  if(ts[dm/2+(dm&1)]!=1+(dm&1)) return NG;\n\n  for(int d:ds)\n    if(d<(dm+1)/2) return NG;\n\n  auto add_edge=\n    [&](int x,int y){\n      G[x].emplace_back(y);\n      G[y].emplace_back(x);\n    };\n\n  vector<int> xs(n),ys(n);\n  for(int i=0;i<(dm+1)/2;i++){\n    xs[dm-i]=qs[dm-i].front();qs[dm-i].pop();\n    ys[dm-i]=qs[dm-i].front();qs[dm-i].pop();\n    if(i){\n      add_edge(xs[dm-i+1],xs[dm-i]);\n      add_edge(ys[dm-i+1],ys[dm-i]);\n    }\n  }\n\n  if(dm&1){\n    add_edge(xs[dm/2+1],ys[dm/2+1]);\n  }else{\n    xs[dm/2]=qs[dm/2].front();qs[dm/2].pop();\n    add_edge(xs[dm/2+1],xs[dm/2]);\n    add_edge(ys[dm/2+1],xs[dm/2]);\n  }\n\n  for(int i=0;i<n;i++){\n    if(!G[i].empty()) continue;\n    add_edge(i,xs[ds[i]-1]);\n  }\n  return G;\n}\n//END CUT HERE\n#ifndef call_from_test\nclass TreeDistanceConstruction {\npublic:\n  vector<int> construct(vector<int> ds) {\n    auto G=construct_from_distances_to_farthest_vertex(ds);\n    if(G.empty()) return {};\n    vector<int> bs;\n    for(int i=0;i<(int)G.size();i++)\n      for(int j:G[i])\n        if(i<j) bs.emplace_back(i),bs.emplace_back(j);\n    return bs;\n  }\n};\n/*\n  verified on 2019/12/10\n  https://vjudge.net/problem/TopCoder-14468\n*/\n#endif\n"
  },
  {
    "path": "tree/diameterforedge.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct DiameterForEdge{\n  using Edge = pair<int, T>;\n  vector<T> dp,ps;\n  vector<vector<Edge> > G;\n  DiameterForEdge(int n):dp(n),ps(n),G(n){}\n  void add_edge(int u,int v,T c){\n    G[u].emplace_back(v,c);\n    G[v].emplace_back(u,c);\n  }\n  void dfs(int v,int p,int &s){\n    ps[v]=p;\n    if(p<0) dp[v]=T(0);\n    if(dp[s]<dp[v]) s=v;\n    for(Edge e:G[v]){\n      int u=e.first;\n      if(u==p) continue;\n      dp[u]=dp[v]+e.second;\n      dfs(u,v,s);\n    }\n  }\n  pair<int, int> endPoints(){\n    int s=0;\n    dfs(s,-1,s);\n    int t=s;\n    dfs(t,-1,t);\n    return make_pair(s,t);\n  }\n  T build(){\n    int t=endPoints().second;\n    return dp[t];\n  }\n  vector<int> restore(){\n    int t=endPoints().second;\n    vector<int> seq;\n    while(~t){\n      seq.emplace_back(t);\n      t=ps[t];\n    }\n    return seq;\n  }\n  vector<T> distance(int v){\n    dfs(v,-1,v);\n    return dp;\n  }\n  vector<T> farthest(){\n    int t=endPoints().second;\n    auto ds=dp;\n    auto dt=distance(t);\n    for(int i=0;i<(int)ds.size();i++)\n      if(ds[i]<dt[i]) ds[i]=dt[i];\n    return ds;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n#define call_from_test\n#include \"../tools/fastio.cpp\"\n#undef call_from_test\n\n// test farthest\nsigned YAHOO2019_FINAL_B(){\n  int n;\n  cin>>n;\n  DiameterForEdge<int> G(n);\n  for(int i=1;i<n;i++){\n    int x,y;\n    cin>>x>>y;\n    x--;y--;\n    G.add_edge(x,y,1);\n  }\n\n  int m;\n  cin>>m;\n  DiameterForEdge<int> H(m);\n  for(int i=1;i<m;i++){\n    int x,y;\n    cin>>x>>y;\n    x--;y--;\n    H.add_edge(x,y,1);\n  }\n\n  auto dp1=G.farthest();\n  auto dp2=H.farthest();\n  sort(dp1.begin(),dp1.end());\n  sort(dp2.begin(),dp2.end());\n\n  using ll = long long;\n  vector<ll> s(m+1,0);\n  for(int i=0;i<m;i++) s[i+1]=s[i]+dp2[i];\n\n  ll ans=0;\n  ll di=max(dp1.back(),dp2.back());\n\n  for(ll x:dp1){\n    ll y=lower_bound(dp2.begin(),dp2.end(),di-(x+1))-dp2.begin();\n    ans+=di*y;\n    ans+=(s[m]-s[y])+(m-y)*(x+1);\n  }\n\n  cout<<ans<<endl;\n  return 0;\n}\n/*\n  verified on 2019/12/17\n  https://atcoder.jp/contests/yahoo-procon2019-final/tasks/yahoo_procon2019_final_b\n*/\n\nsigned main(){\n  //YAHOO2019_FINAL_B();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/diameterforvertex.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nstruct DiameterForVertex{\n  vector<T> vs,dp;\n  vector<vector<int> > G;\n  DiameterForVertex(int n):dp(n),G(n){}\n  DiameterForVertex(vector<T> vs):vs(vs),dp(vs.size()),G(vs.size()){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void dfs(int v,int p,int &s){\n    if(p<0) dp[v]=T(0);\n    dp[v]+=vs[v];\n    if(dp[s]<dp[v]) s=v;\n    for(int u:G[v]){\n      if(u==p) continue;\n      dp[u]=dp[v];\n      dfs(u,v,s);\n    }\n  }\n\n  T build(){\n    assert(!vs.empty());\n    int s=0;\n    dfs(s,-1,s);\n    dfs(s,-1,s);\n    return dp[s];\n  }\n\n  T build(vector<T> us){\n    assert(us.size()==dp.size());\n    vs=us;\n    return build();\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n\n// test build with argument vector<T>\nsigned ARC097_F(){\n  int n;\n  cin>>n;\n  DiameterForVertex<int> G(n);\n  vector<int> deg(n,0);\n  for(int i=1;i<n;i++){\n    int x,y;\n    cin>>x>>y;\n    x--;y--;\n    G.add_edge(x,y);\n    deg[x]++;\n    deg[y]++;\n  }\n\n  string s;\n  cin>>s;\n\n  int cnt=(n-1)*2,num=0;\n  queue<int> que;\n  vector<int> dead(n,0);\n  for(int i=0;i<n;i++){\n    num+=(s[i]=='W');\n    if((deg[i]==1) and (s[i]=='B')){\n      dead[i]=1;\n      que.emplace(i);\n    }\n  }\n\n  while(!que.empty()){\n    int v=que.front();que.pop();\n    cnt-=2;\n    for(int u:G.G[v]){\n      if(dead[u]) continue;\n      deg[u]--;\n      if(deg[u]==1 and (s[u]=='B')){\n        dead[u]=1;\n        que.emplace(u);\n      }\n    }\n  }\n\n  if(num<=1){\n    cout<<num<<endl;\n    return 0;\n  }\n\n  vector<int> vs(n,0);\n  for(int i=0;i<n;i++){\n    if(dead[i]) continue;\n    vs[i]=deg[i]+(s[i]=='W');\n    vs[i]%=2;\n    cnt+=vs[i];\n  }\n\n  cout<<cnt-G.build(vs)*2<<endl;\n  return 0;\n}\n/*\n  verified on 2019/12/27\n  https://atcoder.jp/contests/arc097/tasks/arc097_d\n*/\n\nsigned main(){\n  //ARC097_F();\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/eulertourforbfs.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"levelancestor.cpp\"\n#undef call_from_test\n\n#endif\n\n//BEGIN CUT HERE\nstruct EulerTourForBFS : LevelAncestor{\n  using super = LevelAncestor;\n  vector<int> ls;\n  vector<vector<int>> H;\n  EulerTourForBFS(int n):super(n),ls(n),H(n){}\n\n  using super::par;\n  using super::dep;\n  void build(int r=0){\n    super::build(r);\n    int pos=0;\n    queue<int> que;\n    que.emplace(r);\n    while(!que.empty()){\n      int v=que.front();que.pop();\n      ls[v]=pos++;\n      H[dep[v]].emplace_back(v);\n      for(int u:super::G[v]){\n        if(u==par[0][v]) continue;\n        que.emplace(u);\n      }\n    }\n  }\n\n  int idx(int v){return ls[v];}\n\n  int find(int v,int d,int a){\n    int l=-1,r=H[d].size();\n    while(l+1<r){\n      int m=(l+r)>>1;\n      int p=super::up(H[d][m],d-dep[v]);\n      if(ls[v]+a<=ls[p]) r=m;\n      else l=m;\n    }\n    return ls[H[d][0]]+r;\n  }\n\n  template<typename F>\n  void exec(int v,int d,F f){\n    if(dep[v]+d>=(int)H.size()) return;\n    if(H[dep[v]+d].empty()) return;\n    int l=find(v,dep[v]+d,0);\n    int r=find(v,dep[v]+d,1);\n    if(l<r) f(l,r);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/eulertourforedge.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nclass EulerTourForEdge{\nprivate:\n  vector<int> ds,us,dep,btm;\n\n  void dfs(int v,int p,int d){\n    dep[v]=d;\n    for(int u:G[v]){\n      if(u==p) continue;\n      ds[u]=btm.size();\n      btm.emplace_back(u);\n      dfs(u,v,d+1);\n      us[u]=btm.size();\n      btm.emplace_back(u);\n    }\n  }\npublic:\n  vector< vector<int> > G;\n\n  EulerTourForEdge(int n):\n    ds(n),us(n),dep(n),G(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void build(int r=0){\n    btm.clear();\n    ds[r]=btm.size();\n    btm.emplace_back(r);\n    dfs(r,-1,0);\n    us[r]=btm.size();\n    btm.emplace_back(r);\n  }\n\n  int child(int u,int v){\n    return dep[u]<dep[v]?v:u;\n  }\n\n  int bottom(int e){\n    return btm[e];\n  }\n\n  // lca(u, v) must be u or v\n  template<typename F>\n  void query(int u,int v,F f){\n    if(dep[u]>dep[v]) swap(u,v);\n    f(ds[u]+1,ds[v]+1);\n  }\n\n  template<typename T,typename G>\n  void update(int v,T x,G g){\n    g(ds[v], x);\n    g(us[v],-x);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/eulertourforvertex.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nclass EulerTourForVertex{\nprivate:\n  vector<int> ls,rs;\n  int pos;\n\n  void dfs(int v,int p){\n    ls[v]=pos++;\n    for(int u:G[v])\n      if(u!=p) dfs(u,v);\n    rs[v]=pos;\n  }\n\npublic:\n  vector< vector<int> > G;\n  EulerTourForVertex(int n):ls(n),rs(n),G(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void build(int r=0){\n    pos=0;\n    dfs(r,-1);\n  }\n\n  int idx(int v){return ls[v];}\n\n  template<typename F>\n  void exec(int v,F f){\n    f(ls[v],rs[v]);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/heavylightdecomposition.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nclass HLD{\nprivate:\n  void dfs_sz(int v) {\n    auto &es=G[v];\n    if(~par[v]) es.erase(find(es.begin(),es.end(),par[v]));\n\n    for(int &u:es){\n      par[u]=v;\n      dfs_sz(u);\n      sub[v]+=sub[u];\n      if(sub[u]>sub[es[0]]) swap(u,es[0]);\n    }\n  }\n\n  void dfs_hld(int v,int &pos) {\n    vid[v]=pos++;\n    inv[vid[v]]=v;\n    for(int u:G[v]){\n      if(u==par[v]) continue;\n      nxt[u]=(u==G[v][0]?nxt[v]:u);\n      dfs_hld(u,pos);\n    }\n  }\n\npublic:\n  vector< vector<int> > G;\n\n  // vid: vertex -> idx\n  // inv: idx -> vertex\n  vector<int> vid,nxt,sub,par,inv;\n\n  HLD(int n):G(n),vid(n,-1),nxt(n),sub(n,1),par(n,-1),inv(n){}\n\n  void add_edge(int u,int v) {\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void build(int r=0) {\n    int pos=0;\n    dfs_sz(r);\n    nxt[r]=r;\n    dfs_hld(r,pos);\n  }\n\n  int lca(int u,int v){\n    while(1){\n      if(vid[u]>vid[v]) swap(u,v);\n      if(nxt[u]==nxt[v]) return u;\n      v=par[nxt[v]];\n    }\n  }\n\n  template<typename F>\n  void for_each(int u,int v,const F& f) {\n    while(1){\n      if(vid[u]>vid[v]) swap(u,v);\n      f(max(vid[nxt[v]],vid[u]),vid[v]+1);\n      if(nxt[u]!=nxt[v]) v=par[nxt[v]];\n      else break;\n    }\n  }\n\n  template<typename F>\n  void for_each_edge(int u,int v,const F& f) {\n    while(1){\n      if(vid[u]>vid[v]) swap(u,v);\n      if(nxt[u]!=nxt[v]){\n        f(vid[nxt[v]],vid[v]+1);\n        v=par[nxt[v]];\n      }else{\n        if(u!=v) f(vid[u]+1,vid[v]+1);\n        break;\n      }\n    }\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n};\n#endif\n"
  },
  {
    "path": "tree/lca.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct LCA{\n  const int lg = 12;\n  const int sz = 1<<lg;\n  const int ms = sz-1;\n  int n;\n  vector<int> P,D,E,A,B,T,ht;\n  vector<vector<int> > G,dat;\n  LCA(int n):\n    n(n),P(n,-1),D(n),E(n*2,0),A(n*2,-1),B(n*2/lg+1),T(sz,0),G(n){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void dfs(int v,int p,int d){\n    int k=0,u;\n    vector<int> iter(n,0);\n\n    using T = tuple<int, int, int>;\n    stack<T> st;\n\n  START:\n    D[v]=k;\n    A[k]=P[v]=p;\n    E[k++]=d;\n    for(;iter[v]<(int)G[v].size();iter[v]++){\n      u=G[v][iter[v]];\n      if(u==p) continue;\n      st.emplace(v,p,d);\n      p=v;v=u;d=d+1;\n      goto START;\n    END:\n      tie(v,p,d)=st.top();st.pop();\n    }\n\n    A[k]=P[v];\n    E[k++]=d-1;\n\n    if(!st.empty()) goto END;\n  }\n\n  // if it need leftmost, then add: if(E[i]==E[j]) return i<j?i:j;\n  inline int comp(int i,int j){return E[i]<E[j]?i:j;};\n  inline int comp(int i,int j,int k){return comp(comp(i,j),k);};\n\n  void build(int r=0){\n    dfs(r,-1,1);\n\n    B[0]=1;\n    for(int i=1;i<n*2;i++) B[i/lg]|=(E[i-1]<E[i])<<(i%lg);\n\n    for(int b=0;b<sz;b++){\n      int e=0,w=1,&x=T[b];\n      for(int i=0;i<lg;i++){\n        if((b>>i)&1) e++;\n        else e--;\n        if(e<w) e=w,x=i;\n      }\n    }\n\n    int m=(n*2+lg-1)/lg;\n    int h=1;\n    while((1<<h)<m) h++;\n    dat.assign(h,vector<int>(m,-1));\n    ht.assign(m+1,0);\n    for(int j=2;j<=m;j++) ht[j]=ht[j>>1]+1;\n\n    for(int j=0;j<n*2;j++){\n      if(dat[0][j/lg]<0) dat[0][j/lg]=j;\n      dat[0][j/lg]=comp(dat[0][j/lg],j);\n    }\n\n    for(int i=1,p=1;i<h;i++,p<<=1)\n      for(int j=0;j<m;j++)\n        dat[i][j]=comp(dat[i-1][j],dat[i-1][min(j+p,m-1)]);\n  }\n\n  inline int cs(int a,int b){\n    int l=b-a;\n    return comp(dat[ht[l]][a],dat[ht[l]][b-(1<<ht[l])]);\n  }\n\n  inline int es(int i,int l,int r){\n    int x=r-i*lg+1,y=l-i*lg;\n    int b=(((B[i]|(ms<<x))>>y)|(ms<<(lg-y)))&ms;\n    return l+T[b];\n  }\n\n  inline int ls(int i,int l){\n    int k=l-i*lg;\n    int b=((B[i]>>k)|(ms<<(lg-k)))&ms;\n    return l+T[b];\n  }\n\n  inline int rs(int j,int r){\n    int k=r-j*lg+1;\n    int b=(B[j]|(ms<<k))&ms;\n    return j*lg+T[b];\n  }\n\n  inline int rmq(int l,int r){\n    int i=l/lg,j=r/lg;\n    if(i==j) return es(i,l,r);\n    if(i+1==j) return comp(ls(i,l),rs(j,r));\n    return comp(ls(i,l),cs(i+1,j),rs(j,r));\n  }\n\n  int lca(int l,int r){\n    if(l==r) return l;\n    if(D[l]>D[r]) swap(l,r);\n    int x=D[l],y=D[r];\n    int m=rmq(x,y);\n    return m==x?l:A[m];\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/levelancestor.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct LevelAncestor{\n  vector<vector<int> > G,par,lad;\n  vector<int> dep,nxt,len,pth,ord,hs;\n  LevelAncestor(int n):\n    G(n),dep(n),nxt(n,-1),len(n),pth(n),ord(n),hs(n+1,0){\n    int h=1;\n    while((1<<h)<=n) h++;\n    par.assign(h,vector<int>(n,-1));\n    for(int i=2;i<=n;i++) hs[i]=hs[i>>1]+1;\n  }\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void dfs(int v,int p,int d,int f){\n    if(nxt[v]<0){\n      par[0][nxt[v]=v]=p;\n      len[v]=dep[v]=d;\n      for(int u:G[v]){\n        if(u==p) continue;\n        dfs(u,v,d+1,0);\n        if(len[v]<len[u]) nxt[v]=u,len[v]=len[u];\n      }\n    }\n    if(!f) return;\n    pth[v]=lad.size();\n    lad.emplace_back();\n    for(int k=v;;k=nxt[k]){\n      lad.back().emplace_back(k);\n      pth[k]=pth[v];\n      if(k==nxt[k]) break;\n    }\n    for(;;p=v,v=nxt[v]){\n      for(int u:G[v])\n        if(u!=p and u!=nxt[v]) dfs(u,v,d+1,1);\n      if(v==nxt[v]) break;\n    }\n  }\n\n  void build(int r=0){\n    int n=G.size();\n    dfs(r,-1,0,1);\n    for(int k=0;k+1<(int)par.size();k++){\n      for(int v=0;v<n;v++){\n        if(par[k][v]<0) par[k+1][v]=-1;\n        else par[k+1][v]=par[k][par[k][v]];\n      }\n    }\n    for(int i=0;i<(int)lad.size();i++){\n      int v=lad[i][0],p=par[0][v];\n      if(~p){\n        int k=pth[p],l=min(ord[p]+1,(int)lad[i].size());\n        lad[i].resize(l+lad[i].size());\n        for(int j=0,m=lad[i].size();j+l<m;j++)\n          lad[i][m-(j+1)]=lad[i][m-(j+l+1)];\n        for(int j=0;j<l;j++)\n          lad[i][j]=lad[k][ord[p]-l+j+1];\n      }\n      for(int j=0;j<(int)lad[i].size();j++)\n        if(pth[lad[i][j]]==i) ord[lad[i][j]]=j;\n    }\n  }\n\n  int lca(int u,int v){\n    int h=par.size();\n\n    if(dep[u]>dep[v]) swap(u,v);\n    for(int k=0;k<h;k++)\n      if((dep[v]-dep[u])>>k&1)\n        v=par[k][v];\n\n    if(u==v) return u;\n    for(int k=h-1;k>=0;k--){\n      if(par[k][u]==par[k][v]) continue;\n      u=par[k][u];\n      v=par[k][v];\n    }\n    return par[0][u];\n  }\n\n  int distance(int u,int v){\n    return dep[u]+dep[v]-dep[lca(u,v)]*2;\n  }\n\n  int up(int v,int d){\n    if(d==0) return v;\n    v=par[hs[d]][v];\n    d-=1<<hs[d];\n    return lad[pth[v]][ord[v]-d];\n  }\n\n  // from u to v\n  int next(int u,int v){\n    if(dep[u]>=dep[v]) return par[0][u];\n    int l=up(v,dep[v]-dep[u]-1);\n    return par[0][l]==u?l:par[0][u];\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/lowestcommonancestor.cpp",
    "content": "#ifndef call_from_test\n#include<bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\nstruct LowestCommonAncestor{\n  int h;\n  vector< vector<int> > G,par;\n  vector<int> dep;\n  LowestCommonAncestor(int n):G(n),dep(n){\n    h=1;\n    while((1<<h)<=n) h++;\n    par.assign(h,vector<int>(n,-1));\n  }\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void dfs(int v,int p,int d){\n    par[0][v]=p;\n    dep[v]=d;\n    for(int u:G[v])\n      if(u!=p) dfs(u,v,d+1);\n  }\n\n  void build(int r=0){\n    int n=G.size();\n    dfs(r,-1,0);\n    for(int k=0;k+1<h;k++)\n      for(int v=0;v<n;v++)\n        if(~par[k][v])\n          par[k+1][v]=par[k][par[k][v]];\n  }\n\n  int lca(int u,int v){\n    if(dep[u]>dep[v]) swap(u,v);\n    for(int k=0;k<h;k++)\n      if((dep[v]-dep[u])>>k&1)\n        v=par[k][v];\n\n    if(u==v) return u;\n\n    for(int k=h-1;k>=0;k--)\n      if(par[k][u]!=par[k][v])\n        u=par[k][u],v=par[k][v];\n\n    return par[0][u];\n  }\n\n  int distance(int u,int v){\n    return dep[u]+dep[v]-dep[lca(u,v)]*2;\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/mo_on_tree.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../algorithm/mo.cpp\"\n#include \"../tree/eulertourforedge.cpp\"\n#undef call_from_test\n\n#endif\n//BEGIN CUT HERE\nstruct MoOnTree{\n  Mo* mo;\n  using F = Mo::F;\n  EulerTourForEdge et;\n  vector<int> app,idx;\n  int width;\n  F expand,shrink;\n  MoOnTree(int n,int width,F expand,F shrink):\n    et(n),app(n,0),idx(n),width(width),expand(expand),shrink(shrink){}\n  vector<pair<int,int>> es,qs;\n  void add_edge(int u,int v){\n    es.emplace_back(u,v);\n    et.add_edge(u,v);\n  }\n  void add_query(int u,int v){\n    qs.emplace_back(u,v);\n  }\n  void build(){\n    et.build();\n    int num=0;\n    for(auto[u,v]:es) idx[et.child(u,v)]=num++;\n    F exec=[&](int k){\n      int v=et.bottom(k);\n      int e=idx[v];\n      app[v]^=1;\n      if(app[v]) expand(e);\n      else shrink(e);\n    };\n    int n=et.G.size();\n    mo=new Mo(2*n,width,exec,exec);\n    auto f=[&](int l,int r){mo->add(min(l,r),max(l,r));};\n    for(auto[u,v]:qs) et.query(u,v,f);\n    mo->build();\n  }\n  int process(){return mo->process();}\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/rerooting.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T, typename Edge>\nstruct ReRooting{\n  struct Node{\n    int to,rev;\n    Edge data;\n    Node(int to,Edge data):to(to),data(data){}\n    bool operator<(const Node &v)const{return to<v.to;};\n  };\n\n  using Fold = function<T(T, T)>;\n  using Lift = function<T(T, Edge)>;\n\n  vector< vector<Node> > G;\n  vector< vector<T> > ld,rd;\n  vector<int> lp,rp;\n\n  const Fold fold;\n  const Lift lift;\n  const T id;\n\n  ReRooting(int n,const Fold fold,const Lift lift,const T id):\n    G(n),ld(n),rd(n),lp(n),rp(n),fold(fold),lift(lift),id(id){}\n\n  void add_edge(int u,int v,Edge d,Edge e){\n    G[u].emplace_back(v,d);\n    G[v].emplace_back(u,e);\n  }\n\n  void add_edge(int u,int v,Edge d){add_edge(u,v,d,d);}\n\n  // k: idx for edge (not vertex)\n  T dfs(int v,int k){\n    while(lp[v]!=k and lp[v]<(int)G[v].size()){\n      auto &e=G[v][lp[v]];\n      ld[v][lp[v]+1]=fold(ld[v][lp[v]],lift(dfs(e.to,e.rev),e.data));\n      lp[v]++;\n    }\n    while(rp[v]!=k and rp[v]>=0){\n      auto &e=G[v][rp[v]];\n      rd[v][rp[v]]=fold(rd[v][rp[v]+1],lift(dfs(e.to,e.rev),e.data));\n      rp[v]--;\n    }\n    if(k<0) return rd[v][0];\n    return fold(ld[v][k],rd[v][k+1]);\n  }\n\n  int search(vector<Node> &vs,int idx){\n    return lower_bound(vs.begin(),vs.end(),Node(idx,vs[0].data))-vs.begin();\n  }\n\n  vector<T> build(){\n    int n=G.size();\n    for(int i=0;i<n;i++){\n      sort(G[i].begin(),G[i].end());\n      ld[i].assign((int)G[i].size()+1,id);\n      rd[i].assign((int)G[i].size()+1,id);\n      lp[i]=0;\n      rp[i]=(int)G[i].size()-1;\n    }\n\n    for(int i=0;i<n;i++)\n      for(Node &t:G[i])\n        t.rev=search(G[t.to],i);\n\n    vector<T> res;\n    for(int i=0;i<n;i++)\n      res.emplace_back(dfs(i,-1));\n\n    return res;\n  }\n\n  // p: idx for vertex\n  T subtree(int v,int p){\n    int k=search(G[p],v);\n    assert(k<(int)G[p].size() and G[p][k].to==v);\n    return lift(dfs(v,G[p][k].rev),G[p][k].data);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "tree/sack.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\nstruct Sack{\n  using F = function<void(int)>;\n\n  vector<int> sub,hvy,big;\n  vector< vector<int> > G,Q;\n  F expand,shrink,query;\n\n  Sack(int n,F expand,F shrink,F query):\n    sub(n,1),hvy(n,-1),big(n,0),G(n),Q(n),\n    expand(expand),shrink(shrink),query(query){}\n\n  void add_edge(int u,int v){\n    G[u].emplace_back(v);\n    G[v].emplace_back(u);\n  }\n\n  void add_query(int v,int k){\n    Q[v].emplace_back(k);\n  }\n\n  void add(int v,int p,int x){\n    if(x==1) expand(v);\n    else shrink(v);\n    for(int u:G[v])\n      if(u!=p and !big[u]) add(u,v,x);\n  }\n\n  void dfs(int v=0,int p=-1,bool k=0){\n    for(int u:G[v])\n      if(u!=p and u!=hvy[v]) dfs(u,v,0);\n    if(~hvy[v]){\n      dfs(hvy[v],v,1);\n      big[hvy[v]]=1;\n    }\n    add(v,p,1);\n    for(int k:Q[v]) query(k);\n    if(~hvy[v]) big[hvy[v]]=0;\n    if(!k) add(v,p,0);\n  }\n\n  void build(int v=0,int p=-1){\n    for(int u:G[v]){\n      if(u==p) continue;\n      build(u,v);\n      if(hvy[v]<0 or sub[hvy[v]]<sub[u]) hvy[v]=u;\n      sub[v]+=sub[u];\n    }\n    if(p==-1) dfs(v,p);\n  }\n};\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/compress.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename V>\nV compress(V vs){\n  sort(vs.begin(),vs.end());\n  vs.erase(unique(vs.begin(),vs.end()),vs.end());\n  return vs;\n}\ntemplate<typename T>\nmap<T, int> dict(const vector<T> &vs){\n  map<T, int> res;\n  for(int i=0;i<(int)vs.size();i++)\n    res[vs[i]]=i;\n  return res;\n}\nmap<char, int> dict(const string &s){\n  return dict(vector<char>(s.begin(),s.end()));\n}\ntemplate<typename T>\nvector<T> compressed(vector<T> vs){\n  auto dc=dict(compress(vs));\n  for(auto &v:vs) v=dc[v];\n  return vs;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/fusion.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T, typename ...Ts>\nvector<T> fusion(vector<T> bs,Ts... ts){\n  auto append=[&](auto vs){for(auto v:vs) bs.emplace_back(v);};\n  initializer_list<int>{(void(append(ts)),0)...};\n  return bs;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/identity.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\nvector<int> identity(int n){\n  vector<int> ord(n);\n  iota(ord.begin(),ord.end(),0);\n  return ord;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/inversion.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define call_from_test\n#include \"../datastructure/binaryindexedtree.cpp\"\n#undef call_from_test\n\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T>\nlong long inversion(vector<T> vs){\n  int n=vs.size();\n  long long res=0;\n  BIT<T> bit(n);\n  for(T v:vs){\n    assert(v<=n);\n    res+=bit.query(v+1,n+1);\n    bit.add(v,1);\n  }\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/multi.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nvector<T> make_v(size_t a){return vector<T>(a);}\n\ntemplate<typename T,typename... Ts>\nauto make_v(size_t a,Ts... ts){\n  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));\n}\n\ntemplate<typename T,typename U,typename... V>\ntypename enable_if<is_same<T, U>::value!=0>::type\nfill_v(U &u,const V... v){u=U(v...);}\n\ntemplate<typename T,typename U,typename... V>\ntypename enable_if<is_same<T, U>::value==0>::type\nfill_v(U &u,const V... v){\n  for(auto &e:u) fill_v<T>(e,v...);\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/near.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n\n#endif\n//BEGIN CUT HERE\ntemplate<typename T>\nvector<T> add(vector<T> vs,vector<T> as){\n  assert(vs.size()==as.size());\n  for(int i=0;i<(int)vs.size();i++) vs[i]+=as[i];\n  return vs;\n}\n\ntemplate<typename T, typename U>\nvector<T> add(vector<T> vs,U a){\n  return add(vs,vector<T>(vs.size(),a));\n}\n\ntemplate<typename T>\nvector<T> mul(vector<T> vs,vector<T> as){\n  assert(vs.size()==as.size());\n  for(int i=0;i<(int)vs.size();i++) vs[i]*=as[i];\n  return vs;\n}\n\ntemplate<typename T, typename U>\nvector<T> mul(vector<T> vs,U a){\n  return mul(vs,vector<T>(vs.size(),a));\n}\n\ntemplate<typename T, typename ...Ts>\nvector<T> near(vector<T> vs,Ts... ts){\n  vector<T> rs;\n  rs.reserve(vs.size()*sizeof...(ts));\n  auto append=[&](auto a){\n    for(auto w:add(vs,a)) rs.emplace_back(w);\n  };\n  initializer_list<int>{(void(append(ts)),0)...};\n  return rs;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/powers.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\n// [0, n]\ntemplate<typename T>\nvector<T> powers(int n,T x){\n  vector<T> po(n+1,T(1));\n  for(int i=0;i<n;i++) po[i+1]=po[i]*x;\n  return po;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/reversed.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T>\nvector<T> reversed(vector<T> vs){\n  reverse(vs.begin(),vs.end());\n  return vs;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/runlength.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T>\ndecltype(auto) runlength(vector<T> vs){\n  vector<pair<T, int>> es;\n  for(auto v:vs){\n    if(es.empty() or es.back().first!=v)\n      es.emplace_back(v,0);\n    es.back().second++;\n  }\n  return es;\n}\n//END CUT HERE\n#ifndef call_from_test\n//INSERT ABOVE HERE\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/sorted.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename T>\nvector<T> sorted(vector<T> vs){\n  sort(vs.begin(),vs.end());\n  return vs;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "vector/zip.cpp",
    "content": "#ifndef call_from_test\n#include <bits/stdc++.h>\nusing namespace std;\n#endif\n\n//BEGIN CUT HERE\ntemplate<typename ...Ts>\ndecltype(auto) zip(vector<Ts>... args){\n  vector<decltype(make_tuple(args[0]...))> res;\n  int n=min({args.size()...});\n  res.reserve(n);\n  for(int i=0;i<n;i++) res.emplace_back(args[i]...);\n  return res;\n}\n//END CUT HERE\n#ifndef call_from_test\nsigned main(){\n  return 0;\n}\n#endif\n"
  }
]