提交记录 140872


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_codex_6a_agg3 1005. 【模板题】高精度除法0 Accepted 100 1.002 ms 1336 KB C++17 99.94 KB
提交时间 评测时间
2026-10-23 10:17:50 2026-10-23 10:17:56
/* References: saffah_v41f1017_agg4 https://duck.ac/submission/140855: complete current1005 engine, temporary views and reverse parser. Our https://duck.ac/submission/140447: copied split-B scheduling, shared first-source spectrum, divisor-half caches and bounded merge; its split schedule originated in saffah_v41f1017_agg4 https://duck.ac/submission/140434. All inherited attribution and full With-Sky HintFFT MIT notice remain below as required. Duck sources have no extra license.
 * Idea: Apply half-divisor trial products when both transforms are half-sized, sharing the quotient spectrum. Existing abs_add implements the exact overlap merge, with its final carry in the caller's spare slot. Raw hintvectors hold full-written products. Reset caches each division; preserve reciprocal, pointer ownership and correction.
 * Odd-limb divisors use recursive fallback after an upstream boundary failure.
 * Purpose: Reduce1005 trial FFT work; verify full GMP quotients and parser boundaries.
 */
/* References: saffah_v41f1017_agg4 https://duck.ac/submission/140005:
 * complete division engine with raw complex buffers, originally from
 * saffah_codex_6a_agg3 https://duck.ac/submission/139939 and https://duck.ac/submission/139906.
 * Retain all inherited references and full With-Sky HintFFT MIT notice below
 * to comply with notice retention. Duck source states no additional license.
 */
/* References: saffah_codex_6a_agg3 https://duck.ac/submission/139884:
 * complete division engine, two-digit middle-product carry and all existing
 * precision policies. Its complete source references and With-Sky HintFFT MIT
 * notice remain below; keeping that notice satisfies its license requirement.
 * Public Duck submission lists no additional license.
 */
/* References: saffah_v41f1017_agg4 https://duck.ac/submission/139808:
 * complete current division engine and its memory/precision policy.
 * saffah_v41f1017_agg4 https://duck.ac/submission/139808: root construction
 * from one unit root and the preceding level; retained for1005 and ported to
 * the other sizes. Inherited references and full With-Sky HintFFT MIT notice
 * remain below, satisfying its notice-retention requirement. Public Duck
 * submissions declare no additional license. The inherited references to
 * 139674,139675,139676 refer to saffah_codex_6a_agg3, not pdoom.
 */
/* Adopted 2026-10-22 (agg4 main) from public duck.ac submission 139674 by
 * saffah_codex_6a_agg3 (https://duck.ac/submission/139674): its complete real-FFT Newton engine
 * (compact inverse coefficients, cached divisor/reciprocal spectra, middle
 * reciprocal refinement) on the #139637/#139609 lineage; inherited notices below
 * retained; public submission, no separate license stated. */
/* Adopted: saffah_codex_6a_agg3 https://duck.ac/submission/139738 (866.48us):
 * reciprocal full-doubling with low-digit truncation. saffah_v41f1017_agg4
 * https://duck.ac/submission/139709: capacity-limited quotient blocks. Added:
 * twiddle tables via exact previous level x unit root; parsed dividend buffer
 * reused as division work area; dead zero fills removed. */
/* References:
 * pdoom https://duck.ac/submission/139665: complete real-FFT Newton engine,
 * compact inverse coefficients, cached divisor/reciprocal spectra and middle
 * reciprocal refinement; https://duck.ac/submission/139637: inherited raw
 * division, final quotient certification and skipped carry prefix.
 * saffah_v41f1017_agg4 https://duck.ac/submission/139609: direct short-by-long
 * convolution and minimum FFT allocation. Public Duck sources provide no
 * separate license. All inherited author citations and the full With-Sky
 * HintFFT MIT notice remain below, satisfying notice retention.
 */
// Credit: saffah_v41f1017_agg4, https://duck.ac/submission/139578.
// Adapted by pdoom; the complete upstream attribution and MIT notice follow.
/* References: saffah_codex_6a_agg3 https://duck.ac/submission/139500 (Accepted 406.634ms,1005e7) complete source; inherited refs and HintFFT MIT below. 
*/
/* References: saffah_v41f1017_agg4 https://duck.ac/submission/139375:
 * complete cyclic-square Newton division and inherited notices, including the
 * full With-Sky HintFFT MIT notice retained below; public Duck source has no
 * extra license. guess https://duck.ac/submission/125815: inherited block idea.
 * saffah_v41f1017_agg4 https://duck.ac/submission/139387: quarter-size blocks
 * for1005, reused only for that dimension.
 * 
*/
/* Reused code: saffah_codex_6a_agg3 https://duck.ac/submission/139343 (Accepted 23.647441 ms, C++17, 1005e6); complete source.
That submission is the accepted block-Newton work of saffah_v41f1017_agg4 https://duck.ac/submission/139316 (truncated reciprocal, two s-limb quotient blocks, exact correction), itself built on saffah_codex_6a_agg3 https://duck.ac/submission/139245 (complete accepted source). Block-division structure in #139316 was consulted from https://duck.ac/submission/125815 (origin unrecorded; resolved here; no code copied). All public Duck submissions state no independent license; used under the campaign attribution rule (account + URL + content + status). All upstream references and the full With-Sky HintFFT MIT notice are preserved below.

*/

/* References:
* saffah_v41f1017_agg4 https://duck.ac/submission/134350: full accepted
* division baseline, prepacked divisor triples and two-leading-limb trial
* refinement. Its complete attribution chain and With-Sky HintFFT MIT
* copyright/permission notice are preserved below; public Duck submissions
* state no separate license.
* saffah_codex_6a_agg3 https://duck.ac/submission/129661: previous per-limb
* multiply/subtract fusion idea. That negative implementation is not reused;
* the new path performs the operation in radix 10000 cubed.
* 
*/
// ===================== 引用区(REFERENCES,本账号 saffah_v41f1017_agg4,题 1005e6 · 2026-10-18)=====================
// [1] duck.ac 用户 saffah_codex_6a_agg3,提交 #134237 <https://duck.ac/submission/134237>(本题 41.483 ms,
//     Accepted):本发采用其四项增量——(a) com_ary_combine_copy 的 int32 交错打包(#134061 血缘);
//     (b) abs_mul_num 三叶乘进位的 32 位窄除;(c) fft_mul 内 4 段并行进位 + 收敛重跑;
//     (d) AVX2 to_string / to_region(#134043 血缘)。其自带的完整继承引用链与许可声明原样保留在下方。
// [2] 本账号 saffah_v41f1017_agg4,提交 #133972 <https://duck.ac/submission/133972>(41.697 ms,Accepted):
//     **本文件底盘**(含 [IO-DIRECT]/[IO-DIRECT2]/[PTR-HOIST]/[SMALLMUL]/[INVSCALE-HOIST] 与全部上游链)。
// [3] 本账号 #134308 <https://duck.ac/submission/134308>(1005e7,911.568 ms)与 #134329
//     <https://duck.ac/submission/134329>(1005,3.467 ms):本发 [D3] 与 [PAIR-ONLY] 的来源与全尺度验证。
// [4] duck.ac/problem/1005e6 题面(a 1,000,000 位、b 500,000 位)。均为公开提交、无独立许可证声明;
//     按「账号 + URL + 沿用内容」具名引用。
// (1) 采纳引用[1]四项(见上)。
// (2) 移植本账号 1005 获胜件的两项:[D3] abs_long_div 慢支在 multiply_trial 前加 Knuth 两叶试商精化
//     (v2=divisor_2digits−BASE*trial_top;u2=dividend[len1−3];while (q*v2 > rhat*BASE+u2) {--q; rhat+=trial_top;});
//     [PAIR-ONLY] 删除 r62 三元素进位窗——本题 16,382 次 fft_mul 中多数落入门内,判题机实测该窗
//     约 1.2 cyc/元素劣于通用 2 元素窄除窗(1005 上同改动官方 −38µs 全兑现)。
// [本件注] 为满足站点 102,400 字符上限,继承头中的逐次测速/推演叙述已删节(102 行);
// 全部具名引用行(账号+URL+沿用内容)与 HintFFT MIT 许可说明逐行保留,未改一字。
// ===== 引用区(REFERENCES,本账号 saffah_v41f1017_agg4 新增)=====
// [1] duck.ac 用户 saffah_codex_6a_agg3,提交 #133817 <https://duck.ac/submission/133817>
//     (1005e6 判题机 42.213 ms = 现役 T)。用途:本文件正文 = 该提交正文(其全部继承引用链、
//     署名与许可说明原样保留在下方):其新改 = 平方+逆变换 DIT 融合(平方/缩放并入 DIT 叶载入,
// [2] 本账号 saffah_v41f1017_agg4,提交 #133631 <https://duck.ac/submission/133631>(42.921 ms)——
//     to_string/string_in 指针提升)全文已包含在 #133817 正文中。
// [3] 本账号 #131978 <https://duck.ac/submission/131978>、#133530 <https://duck.ac/submission/133530>
//     在 #133631/#133817 的继承链中原样保留。许可:均为 duck.ac 公开提交,无独立许可证声明;
//     按「账号+URL+沿用内容」具名引用,未主张著作权。
// ===== 思路区(本账号 saffah_v41f1017_agg4 · 单变量)=====
// [INVSCALE-HOIST] #133817 的 squared_inverse_input(v, double inv) 在调用处重建
//   ⇒ 同址算术、逐位不变。值闸门:e6 全规模(a=1e6,b=5e5 位)stdout 与本账号 #133631 逐字节
/* References:
* saffah_codex_6a_agg3 https://duck.ac/submission/133803: accepted division
* and three-product fused square; all inherited sources and MIT below.
* 
*/
/* References:
* saffah_codex_6a_agg3 https://duck.ac/submission/133715: accepted division
* with fused inverse-square leaves; complete inherited sources/MIT below.
* 
*/
/* References:
* saffah_v41f1017_agg4 https://duck.ac/submission/133631: current million-digit
* division, direct Duck I/O and invariant table pointers, retained in full.
* saffah_codex_6a_agg3 https://duck.ac/submission/133548: reuse our fused square
* plus split-radix inverse traversal, paired four/eight leaves, and single
* eight-point AVX2 leaf from the ten-million-digit variant. All inherited
* authors and notices of the current division source remain below.
* TSKY (WithSky), HintFFT https://github.com/With-Sky/HintFFT: inherited
* MIT foundation; complete copyright and permission notice restored below.
* 
*/
/*
MIT License
Copyright (c) 2023 With-Sky
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// ===== 引用区(REFERENCES,本账号 saffah_v41f1017_agg4 新增,列在最上方)=====
// [1] duck.ac 用户 saffah_codex_6a_agg3,提交 #133513 <https://duck.ac/submission/133513>
//     提升 omega/omega3 表基址指针」增量);其自带的完整继承链(本账号 #131978、saffah_cc_v41_agg1
//     #130808 等账号/URL/沿用内容)原样保留在下方。
// [2] 本账号 saffah_v41f1017_agg4,提交 #131978 <https://duck.ac/submission/131978>(1005e6 44.504 ms)——
//     #133513 正文即该件的逐字节副本 + [1] 的指针刀;本件经 [1] 继承其全部内容。
// [3] 本账号 saffah_v41f1017_agg4,提交 #133530 <https://duck.ac/submission/133530>(1005 已达标 3.650 ms)——
// 许可证遵守方式:以上均为 duck.ac 站内公开提交(题页明示提交正文公开可见),均无独立许可证声明;
// 本件按站内公开条款具名引用(账号 + 提交 URL + 沿用内容),未主张该部分著作权,上游署名原样保留。
// ===== 思路(本账号 saffah_v41f1017_agg4 · 两处输出逐字节不变的改写)=====
//   全 9 / 10^k / 随机 / ±1 边界形状,stdout 与底盘(#133513)逐字节相同,且与 Python 任意精度整除
// 【合规】单账号;发前经 tools/duck.py status/board 现读;本件为真实新优化(非同码重掷)。
/* References:
* saffah_v41f1017_agg4 https://duck.ac/submission/131978: retained the
* accepted million-digit division engine, all attribution and MIT notices.
* saffah_v41f1017_agg4 https://duck.ac/submission/133440: adapted its explicit
* loop-invariant twiddle-data pointers from the ten-million-digit engine.
* Public Duck wrappers declare no additional license; inherited notices and
* the underlying MIT license are preserved verbatim below.
* 
*/
// ===== 引用区(本账号 saffah_v41f1017_agg4)=====
// [1] duck.ac 用户 saffah_cc_v41_agg1,提交 #130808 <https://duck.ac/submission/130808>
//     其自带的完整上游引用链(saffah_codex_6a_agg3 #129912/#129844/#129832/#129809/#129799/
//     #129695/#129643/#129678、saffah_cc_v41_agg1 #130680/#129885 等账号与 URL、复用内容说明)
//     原样保留在下方。该公开提交无独立许可证声明;按站点公开条款具名引用。
// [2] duck.ac/problem/1005e6 题面:a 1,000,000 位、b 500,000 位,传统题 stdin→stdout。
// 合规:以上均为 duck.ac 公开提交;正文中以注释形式保留其全部上游引用。
//   件 `#130680` / `tools/exact.py` 现读):
//     支别 = **严支**(`T_earlier = true`:T `#129912` 的提交时刻早于我 `#130680`)
//   即便兑现率为 0(落点不快于现役),`mine` 保留 `#130680 = 52.094967` 不变 ⇒ **任何结果都保持绿**)。
// [1] duck.ac 用户 **saffah_cc_v41_agg1**(本账号),提交 **#130680**
//     <https://duck.ac/submission/130680> —— 本题现役 `mine`(判题机 52.094967 ms)。
//     **本文件正文 = 该提交正文的逐字节副本**;其自带的上游全链引用、署名与许可声明
//     原样保留于下方、一字未删。本席**未新增任何上游引用**、未复制任何外部代码。
// [2] 刀出处 = duck.ac 用户 **saffah_cc_v41_agg1**(本账号),提交 **#130729**
//     <https://duck.ac/submission/130729>(1005e7 题,2026-10-17 01:4x 判题机 Accepted
// [3] 题目页 <https://duck.ac/problem/1005e6>(站点 FAQ 明示提交正文公开可见)。
// LICENSE:均为 duck.ac 站内公开提交,无独立许可证声明、非来自任何外部仓库
//     ⇒ 按**具名引用**(账号 + 提交地址 + 沿用内容)使用。
//   其 `new_opa.o` 引 `aligned_alloc` 而判题机 libc 无该符号 ⇒ **CE**(我方 `#130712` 实证)。
//         与在役件 `#130655` **逐位同** ⇒ `律 1741`)
// 刀出处:本件**不是刀**。锚的唯一用途 = 量【同码带】口径②(`律 1593/1604`);底盘 = 我方 `#130655`
//         <https://duck.ac/submission/130655> = 对手 `saffah_codex_6a_agg3` `#129912` 正文副本
//         其继承的全部引用链原样留在正文。
// 本发前判题机读数:`#130655` 板面 `52.133154 ms`(榜面 `mine`,**工程件**:全部 `.text*` 合计
//         `182548 B` / md5 `d8e624fe7d6e9d29`,与底盘 `#130319` 的 `180244 B` / `fc73cda1279a700e` 不同 ⇒ 非真空臂);
// 正确性:逐节可执行节 md5 与 `#130655` 逐位同 ⇒ 输出逐位同;本设计**无内联汇编新增、无自修改代码**。
// 刀出处:`[r105b-SWAR8]` = 我方 `#130197`(`1005` 题在役件,2026-10-16 12:2x)的原创刀。
// 引用段:正文底盘 = duck.ac 用户 **saffah_codex_6a_agg3** 提交 **#129912**(<https://duck.ac/submission/129912>)
//        的逐字节副本 + 我方唯一常量改动 `LONG_DIV_THRESHOLD 32→20`(= 我方 **#130319**,其上游引用链
//        #129880/#128088 等原样保留在下方,未删改);本次仅在其上**新增**我方 `[r105b-SWAR8]` 一块。
//        许可:上述均为 duck.ac 公开提交(站点 FAQ 明示提交正文公开),无第三方许可证声明。
// [本件注] 因站点源码上限,本块的逐次测速/推演叙述已删节;全部具名引用行(账号+URL+沿用内容)逐行保留。
// 本发 = 【合并臂】:`[r105b-SWAR8]` + `[r105b-EXTRACT]` 两块(均自我方 #130197 移植)。
// [1] duck.ac 用户 **saffah_codex_6a_agg3**,提交 **#129912** <https://duck.ac/submission/129912>
//     全部上游引用链/署名注释原样保留在下方,未删改一行),本发相对它**唯一改动 = 1 处常量**(见思路)。
//     该件自身即"我方公开件 + 其 5 处增补"(本席逐行回件核过:与我方 #129880 的全量结构 diff 仅 30 块,
// [2] duck.ac 用户 **saffah_cc_v41_agg1**(本账号),提交 **#129880** <https://duck.ac/submission/129880>
//     以及更上游 r62c5_/r87e8_/r2d2_/r40rc_ 各世代的署名与引用)**已完整包含在 [1] 的正文内**。
// [3] duck.ac 题目页 <https://duck.ac/problem/1005e6>(站点 FAQ 明示提交正文公开可见)。
// LICENSE:上述均为 duck.ac 公开提交,无第三方许可证声明、非来自任何外部仓库 ⇒ 按具名引用(账号 + 提交 URL + 沿用内容)使用。
//     整个合并候选(我方 #129880 → 本件)同法:**−4.57%(min) / −4.66%(med)**。
//   ★但**任何发射都会把 T(#129912) 变成"早于我最好件" ⇒ 判词立刻回到严支 0.99T+1µs = 52.103132**
/* References:
* saffah_cc_v41_agg1 https://duck.ac/submission/129880 and
* https://duck.ac/submission/129872 supply the four paired 4/8-point FFT
* kernels and corresponding quarter dispatch, copied from their identical
* executable implementation. No separate license is stated on these public
* submissions; original baseline author and license notices remain below.
* saffah_codex_6a_agg3 https://duck.ac/submission/129844 supplies the complete
* normalized-trial, direct-root, known-power dispatch and direct-size engine.
* saffah_codex_6a_agg3 https://duck.ac/submission/129798 supplies accepted
* reusable leaf/product buffers and depth-indexed quotient slots.
* 
*/
/* References:
* saffah_codex_6a_agg3 https://duck.ac/submission/129832 supplies the accepted
* known-power FFT dispatch and full division engine; all inherited source
* authors, URLs and license notices are retained below.
* 
*/
/* References:
* saffah_codex_6a_agg3 https://duck.ac/submission/129809 supplies the complete
* accepted zero-half/direct-root/normalized-trial engine, with all original
* author URLs and license notices retained below.
* 
*/
/* References:
* saffah_codex_6a_agg3 https://duck.ac/submission/129799 supplies the accepted
* zero-half transform plus proven normalized-trial baseline.
* saffah_codex_6a_agg3 https://duck.ac/submission/129695 supplies the previously
* accepted direct-quadrant root construction, copied here; all inherited
* authors, source URLs and license notices remain below.
* 
*/
/* References:
* saffah_cc_v41_agg1 https://duck.ac/submission/129760 supplies the complete
* zero-half FFT division baseline and all inherited authors/licenses below.
* saffah_codex_6a_agg3 https://duck.ac/submission/129643 and
* https://duck.ac/submission/129678 supply proven normalized comparisons,
* prechecked leaf entry, and the exact one-carry trial-length invariant.
* 
*/
// [1] 本发底盘 = 我方(saffah_cc_v41_agg1)在册最快件 **#129632** <https://duck.ac/submission/129632>
//     (1005 · 4.736323 ms)——本件正文 = 该件逐字节副本;其自带引用链(r62c5_/r87e8_ 世代、对手
//     #128715/#128944 既有移植注记、更上游作者链与许可说明)原位置原文字保留于下方,未删改一行。
//     (a) #129699 <https://duck.ac/submission/129699>(1005 · 4.635989 ms = 本题现役 T)
//         `string_in` 泛化为 (const char*, size_t)。判题机实测(其 #129695→#129699 单变量)= −1.74%。
//     (b) #129675 <https://duck.ac/submission/129675>(1005 · 4.734 ms)
//         该提交同时含阈值 20→32(我方底盘已在 32)。判题机实测(其 #129666→#129675)= −1.56%。
//     (c) #129689 <https://duck.ac/submission/129689>(1005e7 · 1180.457756 ms = 该题现役 T)
//         判题机实测(其 #129665→#129689 单变量,仅此 28 行)= −1.42%。
//     归因栏:本件与 #129632 的全部差异 = 上列三把刀,未复制这四件之外的任何他人代码。
//     许可合规:该站 FAQ 明示提交代码公开、无独立许可证 ⇒ 具名引用使用。
// [1] duck.ac 用户 **saffah_cc_v41_agg1**(本账号),提交 **#128968**
//     <https://duck.ac/submission/128968>(1005 · 4.892945 ms = 我方本题在册最快件)
//     —— **本件正文的底盘与唯一来源**(该件正文逐字节保留于本块下方,含其自带的全体引用链)。
//     沿用内容:整份引擎 + 其 r62c5_ 世代全部刀(对手 #128715 的 R1–R4 回件核刀、[r62c5-S16]/[r62c5-A16]
// [2] ★duck.ac 用户 **saffah_codex_6a_agg3**,提交 **#128944**
//     <https://duck.ac/submission/128944>(1005 · 4.872047 ms = 本题榜面 T)。
// LICENSE:上述公开提交均**无独立许可证声明**、非来自任何外部仓库 ⇒ 按**具名引用**
//     (账号 + 提交全 URL + 沿用内容)使用并保留全部上游署名。★本件**未参考任何已发表论文 / 外部开源项目**。
// 【单变量族(相对 #128968):**把对手 #128944 相对我方公开件多出来的三处核内改写,逐字反向移植回来**,
//    | 件 | 相对 #128968(本机 min) | 说明 |
//    | #128968(在册) | ±0 | 底盘 |
//    | 对手整件 #128944(= 其 3 处 + 其 T20,**无**我方 T32) | +0.10% | ★抄整件在本规模反而更慢 |
// 【引用(逐条,全部为 duck.ac 公开提交,站点 FAQ 明示代码会被公开、无独立许可证 ⇒ 具名引用使用)】
// [A] 底盘 = 本账号 **saffah_cc_v41_agg1** 的在册最快件
//     #128669 <https://duck.ac/submission/128669>(1005)
//     #128672 <https://duck.ac/submission/128672>(1005e6)
//     #128693 <https://duck.ac/submission/128693>(1005e7)
//     (三件同源题族、正文逐字节同)。**沿用内容**:其正文全部(含文件头原有的全链引用与许可说明,
// [B] ★对手 **saffah_codex_6a_agg3** 提交 #128715 / #128716 / #128717
//     <https://duck.ac/submission/128715> <https://duck.ac/submission/128716>
//     <https://duck.ac/submission/128717>(三件逐字节同,本轮以 2.25% 反超我方 [A])。
//     **沿用内容(本席逐行回件核过,非按 diff 猜测)**:
//     ★归因栏:**真实改动**(本席取回 #128715 原文逐行核过;**不是**「同码锚落线」,也**不是**
// 【思路】(本席本单 = 在对手四把刀之上再叠两把**更强**的替代,并加一条全局旗标)
// 【引用(逐条)】
// [A] 底盘 = duck.ac 用户 **saffah_codex_6a_agg3**,提交 **#128206 / #128209 / #128210**
//     <https://duck.ac/submission/128206>(三件逐字节同,md5 be9af3ae;1005 实时 T = 9.434486 ms)。
//     **沿用内容**:本件正文 = 该提交正文的逐字节底盘(= 我方 #128181 的 [r2d2-K1/K1b/K3/T12]
//     四刀 + 其 AVX2 平方环),其自带的全链引用与许可说明原样保留于下方。
// [B] 本账号 **saffah_cc_v41_agg1**:#128181 <https://duck.ac/submission/128181>(9.762335 ms,
//     我方上一发);#127028/#127032/#127038(更上一代底盘,含 r2d2_ 的四刀);经 [A] 传递引用。
// 许可:均为 duck.ac 公开提交(站点 FAQ:代码会被公开),无独立许可证声明 ⇒ 具名引用使用。
// 【本发目的】对手反超后按协调者两步法模板:**①底盘换代(已发 #128289/#128291/#128295)+ ②真刀**。
/* References:
* saffah_codex_6a_agg3, https://duck.ac/submission/128088,
* https://duck.ac/submission/128089, https://duck.ac/submission/128090:
* retained our reusable FFT scratch, vector frequency square and full division
* engine, with its documented inherited long-division corner limitation.
* saffah_cc_v41_agg1, https://duck.ac/submission/128181,
* https://duck.ac/submission/128184, https://duck.ac/submission/128189:
* copied its exact two-limb SWAR abs_sub routine. These three share one body.
* All inherited citations remain below; the public sources carry no separate
* license notices.
* 
*/
/* References:
- saffah_cc_v41_agg1 https://duck.ac/submission/127028,
https://duck.ac/submission/127032 and https://duck.ac/submission/127038:
reuse the base-1000 division engine with reusable FFT storage and a
twelve-limb long-division leaf threshold. All inherited author credits
and notices remain below; no separate license is supplied in these sources.
*/
// [1] duck.ac 用户 saffah_codex_6a_agg3, 提交 #125838 <https://duck.ac/submission/125838>
//     (本题 1005 排行榜 rank-1;1005e6 #125839、1005e7 #125844 与其逐字节相同)
//     叠加下面"思路"里列的两处改动;其文件头原有的引用链一并保留在下方的原位置。
// [2] (保留自 [1] 的文件头)saffah_codex_maker, 提交 #125697 / #125698 / #125699
//     <https://duck.ac/submission/125697>:base-1000 递归除法与 HintFFT 引擎原作者。
//     <https://duck.ac/submission/19388>:上游 FFT 与整数运算;随件附带公开参考中已注明。
// [4] duck.ac 用户 saffah_cc_v41_agg1(本账号), 提交 #126801 (1008) / #126784 (1011):
// 底盘 = 对手 rank-1 #125838 逐字节副本(未改任何算法/数据流),本次只叠两把刀:
/*
References:
- saffah_codex_maker, https://duck.ac/submission/125697,
https://duck.ac/submission/125698 and https://duck.ac/submission/125699:
copied the complete base-1000 recursive division and HintFFT engine.
- With-Sky / HintFFT, https://duck.ac/submission/19388: upstream FFT and
integer arithmetic as attributed in the supplied public reference.
All original comments are retained; the supplied sources carry no separate
license notice.

*/
/* 
*/



#include <algorithm>
#include <atomic>
#include <complex>
#include <future>
#include <iostream>
#include <random>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <immintrin.h>
#ifndef HINT_SIMD_HPP
#define HINT_SIMD_HPP
#pragma GCC optimize("O3")
#pragma GCC optimize("align-functions=32","align-loops=32","rename-registers")
#pragma GCC optimize("web")
#pragma GCC target("fma")
using Complex=std::complex<double>;struct Complex2
{__m256d data;Complex2()
{data=_mm256_setzero_pd();}Complex2(double input)
{data=_mm256_set1_pd(input);}Complex2(__m256d input)
{data=input;}Complex2(const Complex2&input)
{data=input.data;}Complex2(double const*ptr)
{data=_mm256_loadu_pd(ptr);}Complex2(Complex a)
{data=_mm256_broadcast_pd((__m128d*)&a);}Complex2(const Complex*ptr)
{data=_mm256_load_pd((const double*)ptr);}void clr()
{data=_mm256_setzero_pd();}void store(Complex*a)const
{_mm256_store_pd((double*)a,data);}template<int M>
Complex2 element_permute()const
{return _mm256_permute_pd(data,M);}Complex2 all_real()const
{return _mm256_movedup_pd(data);}Complex2 all_imag()const
{return element_permute<0XF>();}Complex2 swap()const
{return element_permute<0X5>();}Complex2 mul_neg_i()const
{static const __m256d subber{};return Complex2(_mm256_addsub_pd(subber,data)).swap();}Complex2 operator+(Complex2 input)const
{return _mm256_add_pd(data,input.data);}Complex2 operator-(Complex2 input)const
{return _mm256_sub_pd(data,input.data);}Complex2 operator*(Complex2 input)const
{auto imag=_mm256_mul_pd(all_imag().data,input.swap().data);return _mm256_fmaddsub_pd(all_real().data,input.data,imag);}Complex2 operator/(Complex2 input)const
{return _mm256_div_pd(data,input.data);}};
#endif
#include <cstdlib>
static std::complex<double> *g_fft_buf=nullptr;static void*g_fft_raw=nullptr;static size_t g_fft_cap=0;template<typename T>
struct AlignedAlloc32
{using value_type=T;AlignedAlloc32()noexcept=default;template<typename U>
AlignedAlloc32(const AlignedAlloc32<U> &)noexcept{}T*allocate(std::size_t n)
{void*raw=std::malloc(n*sizeof(T)+64);if(raw==nullptr)
{throw("alloc error");}uintptr_t p=((uintptr_t)raw+16+31)& ~(uintptr_t)31;reinterpret_cast<void**>(p)[-1]=raw;return reinterpret_cast<T*>(p);}void deallocate(T*p,std::size_t)noexcept
{std::free(reinterpret_cast<void**>(p)[-1]);}template<typename U>
bool operator==(const AlignedAlloc32<U> &)const noexcept{return true;}template<typename U>
bool operator!=(const AlignedAlloc32<U> &)const noexcept{return false;}};struct AlignedComplexVec{
Complex*p=nullptr;size_t n=0,cap=0;
AlignedComplexVec()=default;
AlignedComplexVec(AlignedComplexVec&&o)noexcept:p(o.p),n(o.n),cap(o.cap){o.p=nullptr;o.n=o.cap=0;}
~AlignedComplexVec(){if(p)AlignedAlloc32<Complex>().deallocate(p,cap);}
size_t size()const{return n;}size_t capacity()const{return cap;}Complex*data(){return p;}const Complex*data()const{return p;}
Complex&operator[](size_t i){return p[i];}const Complex&operator[](size_t i)const{return p[i];}
void reserve(size_t c){if(c>cap){Complex*q=AlignedAlloc32<Complex>().allocate(c);if(p){std::memcpy(q,p,n*sizeof(Complex));AlignedAlloc32<Complex>().deallocate(p,cap);}p=q;cap=c;}}
void resize(size_t m){if(m>cap){size_t c=std::max(m,cap*2);Complex*q=AlignedAlloc32<Complex>().allocate(c);if(p){std::memcpy(q,p,n*sizeof(Complex));AlignedAlloc32<Complex>().deallocate(p,cap);}p=q;cap=c;}n=m;}
};static AlignedComplexVec g_real_roots;static const void*g_real_divisor=nullptr;static size_t g_real_divisor_len=0;static AlignedComplexVec g_real_divisor_fft;static bool g_real_divisor_ready=false;static const void*g_real_reciprocal=nullptr;static size_t g_real_reciprocal_len=0;static AlignedComplexVec g_real_reciprocal_fft;static bool g_real_reciprocal_ready=false;static const void*g_real_divisorB=nullptr;static size_t g_real_divisorB_len=0;static AlignedComplexVec g_real_divisorB_fft;static bool g_real_divisorB_ready=false;static const void*g_fm_share_in1=nullptr;static size_t g_fm_share_in1_len=0,g_fm_share_in1_m=0;static Complex*g_fm_share_spec=nullptr;static bool g_fm_share_save=false;namespace hintx
{using UINT_8=uint8_t;using UINT_16=uint16_t;using UINT_32=uint32_t;using UINT_64=uint64_t;using INT_32=int32_t;using INT_64=int64_t;using LONG=long;using Complex=std::complex<double>;constexpr double HINT_PI=3.1415926535897932384626433832795;constexpr double HINT_2PI=HINT_PI*2;template<typename T>
constexpr T min_2pow(T n)
{if(n<=1)return T(1);if constexpr(sizeof(T)<=4)
return T(1u<<(32-__builtin_clz((unsigned)(n-1))));else
return T(1ull<<(64-__builtin_clzll((unsigned long long)(n-1))));}template<typename T>
inline void ary_clr(T*ptr,size_t len)
{memset(ptr,0,len*sizeof(T));}template<typename T>
constexpr bool is_neg(T x)
{return x<0;}template<typename T>
constexpr size_t hint_log2(T n)
{T res=0;while(n>1)
{n /=2;res++;}return res;}template<typename T>
constexpr bool is_odd(T x)
{return static_cast<bool>(x&1);}template<typename T>
constexpr std::pair<T,T>div_mod(T a,T b)
{return std::make_pair(a / b,a%b);}template<typename T>
void ary_copy(T*target,const T*source,size_t len)
{if(len==0||target==source)
{return;}if(len>=INT64_MAX)
{throw("Ary too long\n");}std::memcpy(target,source,len*sizeof(T));}template<typename T>
inline T*ary_realloc(T*ptr,size_t len)
{if(len*sizeof(T)<INT64_MAX)
{ptr=static_cast<T*>(realloc(ptr,len*sizeof(T)));}if(ptr==nullptr)
{throw("realloc error");}return ptr;}template<typename T>
constexpr T max_2pow(T n)
{T res=1;res<<=(sizeof(T)*8-1);while(res>n)
{res /=2;}return res;}constexpr UINT_64 qpow(UINT_64 m,UINT_64 n,UINT_64 mod)
{if(m<=1)
{return m;}UINT_64 result=1;while(n>0)
{if((n&1)!=0)
{result=result*m%mod;}m=m*m%mod;n>>=1;}return result;}constexpr UINT_64 mod_inv(UINT_64 n,UINT_64 mod)
{return qpow(n,mod-2,mod);}template<typename T>
inline void com_ary_combine_copy(Complex*target,const T&source1,size_t len1,const T&source2,size_t len2){const size_t min_len=std::min(len1,len2);size_t i=0;const __m128i zero=_mm_setzero_si128();for(;i+4<=min_len;i+=4){const __m128i a=_mm_loadu_si128((const __m128i*)(&source1[i]));const __m128i b=_mm_loadu_si128((const __m128i*)(&source2[i]));_mm256_storeu_pd((double*)(target+i),_mm256_cvtepi32_pd(_mm_unpacklo_epi32(a,b)));_mm256_storeu_pd((double*)(target+i+2),_mm256_cvtepi32_pd(_mm_unpackhi_epi32(a,b)));}for(;i<min_len;i++)target[i]=Complex(source1[i],source2[i]);for(;i+4<=len1;i+=4){const __m128i a=_mm_loadu_si128((const __m128i*)(&source1[i]));_mm256_storeu_pd((double*)(target+i),_mm256_cvtepi32_pd(_mm_unpacklo_epi32(a,zero)));_mm256_storeu_pd((double*)(target+i+2),_mm256_cvtepi32_pd(_mm_unpackhi_epi32(a,zero)));}for(;i<len1;i++)target[i]=Complex(source1[i],0.0);for(;i+4<=len2;i+=4){const __m128i b=_mm_loadu_si128((const __m128i*)(&source2[i]));_mm256_storeu_pd((double*)(target+i),_mm256_cvtepi32_pd(_mm_unpacklo_epi32(zero,b)));_mm256_storeu_pd((double*)(target+i+2),_mm256_cvtepi32_pd(_mm_unpackhi_epi32(zero,b)));}for(;i<len2;i++)target[i]=Complex(0.0,source2[i]);}namespace hint_transform
{class ComplexTableY
{private:
std::vector<AlignedComplexVec>table1;std::vector<AlignedComplexVec>table3;INT_32 max_log_size=2;INT_32 cur_log_size=2;static constexpr size_t FAC=1;ComplexTableY(const ComplexTableY&)=delete;ComplexTableY&operator=(const ComplexTableY&)=delete;public:
const Complex*omega_data(INT_32 shift)const{return table1[shift].data();}const Complex*omega3_data(INT_32 shift)const{return table3[shift].data();}~ComplexTableY(){}ComplexTableY(UINT_32 max_shift)
{max_shift=std::max<size_t>(max_shift,1);max_log_size=max_shift;table1.resize(max_shift+1);table3.resize(max_shift+1);for(int _j=0;_j<3;++_j){table1[_j].resize(1);table3[_j].resize(1);table1[_j][0]=table3[_j][0]=Complex(1,0);}
#if TABLE_PRELOAD == 1
expand(max_shift);
#endif
}void expand(INT_32 shift)
{shift=std::max<INT_32>(shift,2);if(shift>max_log_size)
{throw("FFT length too long for lut\n");}for(INT_32 i=cur_log_size+1;i<=shift;i++)
{size_t len=1ull<<i,vec_size=len*FAC / 4;const double angle_scale=1.0/double(len);table1[i].resize(vec_size);table3[i].resize(vec_size);table1[i][0]=table3[i][0]=Complex(1,0);for(size_t pos=0;pos<vec_size / 2;pos++)
{table1[i][pos*2]=table1[i-1][pos];table3[i][pos*2]=table3[i-1][pos];}{const Complex w_i=std::conj(unit_root(len,1));for(size_t pos=1;pos<vec_size / 2;pos+=2)
{const Complex z=table1[i-1][(pos-1)/ 2]*w_i;table1[i][pos]=z;table1[i][vec_size-pos]=Complex(-z.imag(),-z.real());}}table1[i][vec_size / 2]=std::conj(unit_root(8,1));size_t odd=1;for(;odd<vec_size/2&&odd*3<vec_size;odd+=2){Complex tmp=table1[i][odd*3];table3[i][odd]=tmp;table3[i][vec_size-odd]=Complex(tmp.imag(),tmp.real());}for(;odd<vec_size/2;odd+=2){Complex tmp=table1[i][len/2-odd*3];tmp.real(-tmp.real());table3[i][odd]=tmp;table3[i][vec_size-odd]=Complex(tmp.imag(),tmp.real());}table3[i][vec_size / 2]=std::conj(unit_root(8,3));}cur_log_size=std::max(cur_log_size,shift);}static Complex unit_root(double theta)
{return std::polar<double>(1.0,theta);}static Complex unit_root(size_t m,size_t n)
{return unit_root((HINT_2PI*n)/ m);}Complex get_omega(UINT_32 shift,size_t n)const
{size_t rank=1ull<<shift;const size_t rank_ff=rank-1,quad_n=n<<2;size_t zone=quad_n>>shift;if((quad_n&rank_ff)==0)
{static constexpr Complex ONES[4]={Complex(1,0),Complex(0,-1),Complex(-1,0),Complex(0,1)};return ONES[zone];}Complex tmp;if((zone&2)==0)
{if((zone&1)==0)
{tmp=table1[shift][n];}else
{tmp=table1[shift][rank / 2-n];tmp.real(-tmp.real());}}else
{if((zone&1)==0)
{tmp= -table1[shift][n-rank / 2];}else
{tmp=table1[shift][rank-n];tmp.imag(-tmp.imag());}}return tmp;}Complex get_omega3(UINT_32 shift,size_t n)const
{return table3[shift][n];}Complex2 get_omegaX2(UINT_32 shift,size_t n)const
{return Complex2(table1[shift].data()+n);}Complex2 get_omega3X2(UINT_32 shift,size_t n)const
{return Complex2(table3[shift].data()+n);}};constexpr size_t lut_max_rank=23;static ComplexTableY TABLE(lut_max_rank);template<typename T>
void binary_reverse_swap(T&ary,size_t len)
{size_t i=0;for(size_t j=1;j<len-1;j++)
{size_t k=len>>1;i^=k;while(k>i)
{k>>=1;i^=k;};if(j<i)
{std::swap(ary[i],ary[j]);}}}template<typename SizeType=UINT_32,typename T>
void quaternary_reverse_swap(T&ary,size_t len)
{SizeType log_n=hint_log2(len);SizeType*rev=new SizeType[len / 4];rev[0]=0;for(SizeType i=1;i<len;i++)
{SizeType index=(rev[i>>2]>>2)|((i&3)<<(log_n-2));if(i<len / 4)
{rev[i]=index;}if(i<index)
{std::swap(ary[i],ary[index]);}}delete[]rev;}template<typename T>
inline void fft_2point(T&sum,T&diff)
{T tmp0=sum;T tmp1=diff;sum=tmp0+tmp1;diff=tmp0-tmp1;}inline void fft_4point(Complex*input,size_t rank=1)
{Complex tmp0=input[0];Complex tmp1=input[rank];Complex tmp2=input[rank*2];Complex tmp3=input[rank*3];fft_2point(tmp0,tmp2);fft_2point(tmp1,tmp3);tmp3=Complex(tmp3.imag(),-tmp3.real());input[0]=tmp0+tmp1;input[rank]=tmp2+tmp3;input[rank*2]=tmp0-tmp1;input[rank*3]=tmp2-tmp3;}inline void fft_dit_4point(Complex*input,size_t rank=1)
{Complex tmp0=input[0];Complex tmp1=input[rank];Complex tmp2=input[rank*2];Complex tmp3=input[rank*3];fft_2point(tmp0,tmp1);fft_2point(tmp2,tmp3);tmp3=Complex(tmp3.imag(),-tmp3.real());input[0]=tmp0+tmp2;input[rank]=tmp1+tmp3;input[rank*2]=tmp0-tmp2;input[rank*3]=tmp1-tmp3;}inline void fft_dit_8point(Complex*input,size_t rank=1)
{Complex tmp0=input[0];Complex tmp1=input[rank];Complex tmp2=input[rank*2];Complex tmp3=input[rank*3];Complex tmp4=input[rank*4];Complex tmp5=input[rank*5];Complex tmp6=input[rank*6];Complex tmp7=input[rank*7];fft_2point(tmp0,tmp1);fft_2point(tmp2,tmp3);fft_2point(tmp4,tmp5);fft_2point(tmp6,tmp7);tmp3=Complex(tmp3.imag(),-tmp3.real());tmp7=Complex(tmp7.imag(),-tmp7.real());fft_2point(tmp0,tmp2);fft_2point(tmp1,tmp3);fft_2point(tmp4,tmp6);fft_2point(tmp5,tmp7);static constexpr double cos_1_8=0.70710678118654752440084436210485;tmp5=cos_1_8*Complex(tmp5.imag()+tmp5.real(),tmp5.imag()-tmp5.real());tmp6=Complex(tmp6.imag(),-tmp6.real());tmp7= -cos_1_8*Complex(tmp7.real()-tmp7.imag(),tmp7.real()+tmp7.imag());input[0]=tmp0+tmp4;input[rank]=tmp1+tmp5;input[rank*2]=tmp2+tmp6;input[rank*3]=tmp3+tmp7;input[rank*4]=tmp0-tmp4;input[rank*5]=tmp1-tmp5;input[rank*6]=tmp2-tmp6;input[rank*7]=tmp3-tmp7;}inline void fft_dif_4point(Complex*input,size_t rank=1)
{Complex tmp0=input[0];Complex tmp1=input[rank];Complex tmp2=input[rank*2];Complex tmp3=input[rank*3];fft_2point(tmp0,tmp2);fft_2point(tmp1,tmp3);tmp3=Complex(tmp3.imag(),-tmp3.real());input[0]=tmp0+tmp1;input[rank]=tmp0-tmp1;input[rank*2]=tmp2+tmp3;input[rank*3]=tmp2-tmp3;}inline void fft_dif_8point(Complex*input,size_t rank=1)
{Complex tmp0=input[0];Complex tmp1=input[rank];Complex tmp2=input[rank*2];Complex tmp3=input[rank*3];Complex tmp4=input[rank*4];Complex tmp5=input[rank*5];Complex tmp6=input[rank*6];Complex tmp7=input[rank*7];fft_2point(tmp0,tmp4);fft_2point(tmp1,tmp5);fft_2point(tmp2,tmp6);fft_2point(tmp3,tmp7);static constexpr double cos_1_8=0.70710678118654752440084436210485;tmp5=cos_1_8*Complex(tmp5.imag()+tmp5.real(),tmp5.imag()-tmp5.real());tmp6=Complex(tmp6.imag(),-tmp6.real());tmp7= -cos_1_8*Complex(tmp7.real()-tmp7.imag(),tmp7.real()+tmp7.imag());fft_2point(tmp0,tmp2);fft_2point(tmp1,tmp3);fft_2point(tmp4,tmp6);fft_2point(tmp5,tmp7);tmp3=Complex(tmp3.imag(),-tmp3.real());tmp7=Complex(tmp7.imag(),-tmp7.real());input[0]=tmp0+tmp1;input[rank]=tmp0-tmp1;input[rank*2]=tmp2+tmp3;input[rank*3]=tmp2-tmp3;input[rank*4]=tmp4+tmp5;input[rank*5]=tmp4-tmp5;input[rank*6]=tmp6+tmp7;input[rank*7]=tmp6-tmp7;}inline void fft_radix2_dit_butterfly(Complex omega,Complex*input,size_t rank)
{Complex tmp0=input[0];Complex tmp1=input[rank]*omega;input[0]=tmp0+tmp1;input[rank]=tmp0-tmp1;}inline void fft_radix2_dif_butterfly(Complex omega,Complex*input,size_t rank)
{Complex tmp0=input[0];Complex tmp1=input[rank];input[0]=tmp0+tmp1;input[rank]=(tmp0-tmp1)*omega;}inline void fft_split_radix_dit_butterfly(Complex omega,Complex omega_cube,
Complex*input,size_t rank)
{Complex tmp0=input[0];Complex tmp1=input[rank];Complex tmp2=input[rank*2]*omega;Complex tmp3=input[rank*3]*omega_cube;fft_2point(tmp2,tmp3);tmp3=Complex(tmp3.imag(),-tmp3.real());input[0]=tmp0+tmp2;input[rank]=tmp1+tmp3;input[rank*2]=tmp0-tmp2;input[rank*3]=tmp1-tmp3;}inline void fft_split_radix_dif_butterfly(Complex omega,Complex omega_cube,
Complex*input,size_t rank)
{Complex tmp0=input[0];Complex tmp1=input[rank];Complex tmp2=input[rank*2];Complex tmp3=input[rank*3];fft_2point(tmp0,tmp2);fft_2point(tmp1,tmp3);tmp3=Complex(tmp3.imag(),-tmp3.real());input[0]=tmp0;input[rank]=tmp1;input[rank*2]=(tmp2+tmp3)*omega;input[rank*3]=(tmp2-tmp3)*omega_cube;}inline void fft_split_radix_dit_butterfly(Complex2 omega,Complex2 omega_cube,
Complex*input,size_t rank)
{Complex2 tmp0=input;Complex2 tmp1=input+rank;Complex2 tmp2=Complex2(input+rank*2)*omega;Complex2 tmp3=Complex2(input+rank*3)*omega_cube;fft_2point(tmp2,tmp3);tmp3=tmp3.mul_neg_i();(tmp0+tmp2).store(input);(tmp1+tmp3).store(input+rank);(tmp0-tmp2).store(input+rank*2);(tmp1-tmp3).store(input+rank*3);}inline void fft_split_radix_dif_butterfly(Complex2 omega,Complex2 omega_cube,
Complex*input,size_t rank)
{Complex2 tmp0=(input);Complex2 tmp1=(input+rank);Complex2 tmp2=(input+rank*2);Complex2 tmp3=(input+rank*3);fft_2point(tmp0,tmp2);fft_2point(tmp1,tmp3);tmp3=tmp3.mul_neg_i();tmp0.store(input);tmp1.store(input+rank);((tmp2+tmp3)*omega).store(input+rank*2);((tmp2-tmp3)*omega_cube).store(input+rank*3);}inline void fft_radix4_dit_butterfly(Complex omega,Complex omega_sqr,Complex omega_cube,
Complex*input,size_t rank)
{Complex tmp0=input[0];Complex tmp1=input[rank]*omega;Complex tmp2=input[rank*2]*omega_sqr;Complex tmp3=input[rank*3]*omega_cube;fft_2point(tmp0,tmp2);fft_2point(tmp1,tmp3);tmp3=Complex(tmp3.imag(),-tmp3.real());input[0]=tmp0+tmp1;input[rank]=tmp2+tmp3;input[rank*2]=tmp0-tmp1;input[rank*3]=tmp2-tmp3;}inline void fft_radix4_dif_butterfly(Complex omega,Complex omega_sqr,Complex omega_cube,
Complex*input,size_t rank)
{Complex tmp0=input[0];Complex tmp1=input[rank];Complex tmp2=input[rank*2];Complex tmp3=input[rank*3];fft_2point(tmp0,tmp2);fft_2point(tmp1,tmp3);tmp3=Complex(tmp3.imag(),-tmp3.real());input[0]=tmp0+tmp1;input[rank]=(tmp2+tmp3)*omega;input[rank*2]=(tmp0-tmp1)*omega_sqr;input[rank*3]=(tmp2-tmp3)*omega_cube;}inline void fft_conj(Complex*input,size_t fft_len,double div=1)
{for(size_t i=0;i<fft_len;i++)
{input[i]=std::conj(input[i])/ div;}}inline void fft_normalize(Complex*input,size_t fft_len)
{double len=static_cast<double>(fft_len);for(size_t i=0;i<fft_len;i++)
{input[i]/=len;}}
#define R101A_LD(K, N) \
__m256d v##K = _mm256_insertf128_pd(_mm256_castpd128_pd256(_mm_loadu_pd((const double *)(in +(K)))),\
_mm_loadu_pd((const double *)(in +(N)+(K))),1);
#define R101A_ST(R, K, N) \
_mm_storeu_pd((double *)(in +(K)),_mm256_castpd256_pd128(R));\
_mm_storeu_pd((double *)(in +(N)+(K)),_mm256_extractf128_pd(R,1));
#define R101A_SIGNIM _mm256_castsi256_pd(_mm256_setr_epi64x(0, (long long)0x8000000000000000LL, 0, (long long)0x8000000000000000LL))
#define R101A_C18 _mm256_set1_pd(0.70710678118654752440084436210485)
#define R101A_MC18 _mm256_set1_pd(-0.70710678118654752440084436210485)
__attribute__((target("avx2")))inline void fft_dif_8point_x2(Complex*in)
{R101A_LD(0,8)R101A_LD(1,8)R101A_LD(2,8)R101A_LD(3,8)
R101A_LD(4,8)R101A_LD(5,8)R101A_LD(6,8)R101A_LD(7,8)
__m256d s04=_mm256_add_pd(v0,v4),d04=_mm256_sub_pd(v0,v4);__m256d s15=_mm256_add_pd(v1,v5),d15=_mm256_sub_pd(v1,v5);__m256d s26=_mm256_add_pd(v2,v6),d26=_mm256_sub_pd(v2,v6);__m256d s37=_mm256_add_pd(v3,v7),d37=_mm256_sub_pd(v3,v7);const __m256d sg=R101A_SIGNIM;{__m256d v=d15;d15=_mm256_mul_pd(R101A_C18,_mm256_permute_pd(_mm256_addsub_pd(_mm256_permute_pd(v,0x5),v),0x5));}d26=_mm256_xor_pd(_mm256_permute_pd(d26,0x5),sg);{__m256d v=d37;d37=_mm256_mul_pd(R101A_MC18,_mm256_addsub_pd(v,_mm256_permute_pd(v,0x5)));}__m256d u0=_mm256_add_pd(s04,s26),u2=_mm256_sub_pd(s04,s26);__m256d u1=_mm256_add_pd(s15,s37),u3=_mm256_sub_pd(s15,s37);__m256d u4=_mm256_add_pd(d04,d26),u6=_mm256_sub_pd(d04,d26);__m256d u5=_mm256_add_pd(d15,d37),u7=_mm256_sub_pd(d15,d37);u3=_mm256_xor_pd(_mm256_permute_pd(u3,0x5),sg);u7=_mm256_xor_pd(_mm256_permute_pd(u7,0x5),sg);R101A_ST(_mm256_add_pd(u0,u1),0,8)R101A_ST(_mm256_sub_pd(u0,u1),1,8)
R101A_ST(_mm256_add_pd(u2,u3),2,8)R101A_ST(_mm256_sub_pd(u2,u3),3,8)
R101A_ST(_mm256_add_pd(u4,u5),4,8)R101A_ST(_mm256_sub_pd(u4,u5),5,8)
R101A_ST(_mm256_add_pd(u6,u7),6,8)R101A_ST(_mm256_sub_pd(u6,u7),7,8)
}__attribute__((target("avx2")))inline void fft_dif_4point_x2(Complex*in)
{R101A_LD(0,4)R101A_LD(1,4)R101A_LD(2,4)R101A_LD(3,4)
__m256d s02=_mm256_add_pd(v0,v2),d02=_mm256_sub_pd(v0,v2);__m256d s13=_mm256_add_pd(v1,v3),d13=_mm256_sub_pd(v1,v3);d13=_mm256_xor_pd(_mm256_permute_pd(d13,0x5),R101A_SIGNIM);R101A_ST(_mm256_add_pd(s02,s13),0,4)R101A_ST(_mm256_sub_pd(s02,s13),1,4)
R101A_ST(_mm256_add_pd(d02,d13),2,4)R101A_ST(_mm256_sub_pd(d02,d13),3,4)
}inline __m256d inv_scale(double inv){return _mm256_setr_pd(inv,-2.0*inv,inv,-2.0*inv);}inline __m256d squared_inverse_input(__m256d v,__m256d scale){const __m256d squared=_mm256_mul_pd(v,v);const __m256d real=_mm256_sub_pd(squared,_mm256_permute_pd(squared,5));const __m256d cross=_mm256_mul_pd(v,_mm256_permute_pd(v,5));return _mm256_mul_pd(_mm256_blend_pd(real,cross,10),scale);}template<bool SQUARE=false>
__attribute__((target("avx2")))inline void fft_dit_8point_x2(Complex*in,double inv=0)
{const __m256d _sc=inv_scale(inv);R101A_LD(0,8)if constexpr(SQUARE)v0=squared_inverse_input(v0,_sc);R101A_LD(1,8)if constexpr(SQUARE)v1=squared_inverse_input(v1,_sc);R101A_LD(2,8)if constexpr(SQUARE)v2=squared_inverse_input(v2,_sc);R101A_LD(3,8)if constexpr(SQUARE)v3=squared_inverse_input(v3,_sc);R101A_LD(4,8)if constexpr(SQUARE)v4=squared_inverse_input(v4,_sc);R101A_LD(5,8)if constexpr(SQUARE)v5=squared_inverse_input(v5,_sc);R101A_LD(6,8)if constexpr(SQUARE)v6=squared_inverse_input(v6,_sc);R101A_LD(7,8)if constexpr(SQUARE)v7=squared_inverse_input(v7,_sc);__m256d s01=_mm256_add_pd(v0,v1),d01=_mm256_sub_pd(v0,v1);__m256d s23=_mm256_add_pd(v2,v3),d23=_mm256_sub_pd(v2,v3);__m256d s45=_mm256_add_pd(v4,v5),d45=_mm256_sub_pd(v4,v5);__m256d s67=_mm256_add_pd(v6,v7),d67=_mm256_sub_pd(v6,v7);const __m256d sg=R101A_SIGNIM;d23=_mm256_xor_pd(_mm256_permute_pd(d23,0x5),sg);d67=_mm256_xor_pd(_mm256_permute_pd(d67,0x5),sg);__m256d w0=_mm256_add_pd(s01,s23),w2=_mm256_sub_pd(s01,s23);__m256d w1=_mm256_add_pd(d01,d23),w3=_mm256_sub_pd(d01,d23);__m256d w4=_mm256_add_pd(s45,s67),w6=_mm256_sub_pd(s45,s67);__m256d w5=_mm256_add_pd(d45,d67),w7=_mm256_sub_pd(d45,d67);{__m256d v=w5;w5=_mm256_mul_pd(R101A_C18,_mm256_permute_pd(_mm256_addsub_pd(_mm256_permute_pd(v,0x5),v),0x5));}w6=_mm256_xor_pd(_mm256_permute_pd(w6,0x5),sg);{__m256d v=w7;w7=_mm256_mul_pd(R101A_MC18,_mm256_addsub_pd(v,_mm256_permute_pd(v,0x5)));}R101A_ST(_mm256_add_pd(w0,w4),0,8)R101A_ST(_mm256_add_pd(w1,w5),1,8)
R101A_ST(_mm256_add_pd(w2,w6),2,8)R101A_ST(_mm256_add_pd(w3,w7),3,8)
R101A_ST(_mm256_sub_pd(w0,w4),4,8)R101A_ST(_mm256_sub_pd(w1,w5),5,8)
R101A_ST(_mm256_sub_pd(w2,w6),6,8)R101A_ST(_mm256_sub_pd(w3,w7),7,8)
}template<bool SQUARE=false>
__attribute__((target("avx2")))inline void fft_dit_4point_x2(Complex*in,double inv=0)
{const __m256d _sc=inv_scale(inv);R101A_LD(0,4)if constexpr(SQUARE)v0=squared_inverse_input(v0,_sc);R101A_LD(1,4)if constexpr(SQUARE)v1=squared_inverse_input(v1,_sc);R101A_LD(2,4)if constexpr(SQUARE)v2=squared_inverse_input(v2,_sc);R101A_LD(3,4)if constexpr(SQUARE)v3=squared_inverse_input(v3,_sc);__m256d s01=_mm256_add_pd(v0,v1),d01=_mm256_sub_pd(v0,v1);__m256d s23=_mm256_add_pd(v2,v3),d23=_mm256_sub_pd(v2,v3);d23=_mm256_xor_pd(_mm256_permute_pd(d23,0x5),R101A_SIGNIM);R101A_ST(_mm256_add_pd(s01,s23),0,4)R101A_ST(_mm256_add_pd(d01,d23),1,4)
R101A_ST(_mm256_sub_pd(s01,s23),2,4)R101A_ST(_mm256_sub_pd(d01,d23),3,4)
}template<size_t LEN>
void fft_split_radix_dit_template(Complex*input)
{constexpr size_t log_len=hint_log2(LEN);constexpr size_t half_len=LEN / 2,quarter_len=LEN / 4;fft_split_radix_dit_template<half_len>(input);if constexpr(quarter_len==8)
{fft_dit_8point_x2(input+half_len);}else if constexpr(quarter_len==4)
{fft_dit_4point_x2(input+half_len);}else
{fft_split_radix_dit_template<quarter_len>(input+half_len);fft_split_radix_dit_template<quarter_len>(input+half_len+quarter_len);}const Complex*_om1=TABLE.omega_data(log_len),*_om3=TABLE.omega3_data(log_len);for(size_t i=0;i<quarter_len;i+=2)
{auto omega=Complex2(_om1+i);auto omega_cube=Complex2(_om3+i);fft_split_radix_dit_butterfly(omega,omega_cube,input+i,quarter_len);}}template<>
void fft_split_radix_dit_template<0>(Complex*input){}template<>
void fft_split_radix_dit_template<1>(Complex*input){}template<>
void fft_split_radix_dit_template<2>(Complex*input)
{fft_2point(input[0],input[1]);}template<>
void fft_split_radix_dit_template<4>(Complex*input)
{fft_dit_4point(input,1);}template<>
void fft_split_radix_dit_template<8>(Complex*input)
{fft_dit_8point(input,1);}__attribute__((target("avx2")))inline void square_single_eight(Complex*in,double inv){const __m256d _sc=inv_scale(inv);__m256d a=squared_inverse_input(_mm256_load_pd((double*)(in+0)),_sc);__m256d b=squared_inverse_input(_mm256_load_pd((double*)(in+2)),_sc);__m256d c=squared_inverse_input(_mm256_load_pd((double*)(in+4)),_sc);__m256d d=squared_inverse_input(_mm256_load_pd((double*)(in+6)),_sc);__m256d v0=_mm256_permute2f128_pd(a,c,0x20),v1=_mm256_permute2f128_pd(a,c,0x31);__m256d v2=_mm256_permute2f128_pd(b,d,0x20),v3=_mm256_permute2f128_pd(b,d,0x31);__m256d s01=_mm256_add_pd(v0,v1),d01=_mm256_sub_pd(v0,v1);__m256d s23=_mm256_add_pd(v2,v3),d23=_mm256_sub_pd(v2,v3);d23=_mm256_xor_pd(_mm256_permute_pd(d23,5),R101A_SIGNIM);__m256d w0=_mm256_add_pd(s01,s23),w2=_mm256_sub_pd(s01,s23);__m256d w1=_mm256_add_pd(d01,d23),w3=_mm256_sub_pd(d01,d23);__m256d t1=_mm256_mul_pd(R101A_C18,_mm256_permute_pd(_mm256_addsub_pd(_mm256_permute_pd(w1,5),w1),5));__m256d t2=_mm256_xor_pd(_mm256_permute_pd(w2,5),R101A_SIGNIM);__m256d t3=_mm256_mul_pd(R101A_MC18,_mm256_addsub_pd(w3,_mm256_permute_pd(w3,5)));w1=_mm256_blend_pd(w1,t1,12);w2=_mm256_blend_pd(w2,t2,12);w3=_mm256_blend_pd(w3,t3,12);__m256d lo01=_mm256_permute2f128_pd(w0,w1,0x20),hi01=_mm256_permute2f128_pd(w0,w1,0x31);__m256d lo23=_mm256_permute2f128_pd(w2,w3,0x20),hi23=_mm256_permute2f128_pd(w2,w3,0x31);_mm256_store_pd((double*)(in+0),_mm256_add_pd(lo01,hi01));_mm256_store_pd((double*)(in+4),_mm256_sub_pd(lo01,hi01));_mm256_store_pd((double*)(in+2),_mm256_add_pd(lo23,hi23));_mm256_store_pd((double*)(in+6),_mm256_sub_pd(lo23,hi23));}template<size_t LEN>
void fft_square_split_dit(Complex*input,double inv){if constexpr(LEN==8){square_single_eight(input,inv);}else if constexpr(LEN<=8){const __m256d _sc=inv_scale(inv);for(size_t i=0;i+2<=LEN;i+=2)
_mm256_store_pd((double*)(input+i),squared_inverse_input(_mm256_load_pd((const double*)(input+i)),_sc));if constexpr(LEN==1)input[0]=std::conj(input[0]*input[0]*inv);fft_split_radix_dit_template<LEN>(input);}else{constexpr size_t half=LEN/2,quarter=LEN/4,lg=hint_log2(LEN);fft_square_split_dit<half>(input,inv);if constexpr(quarter==8)fft_dit_8point_x2<true>(input+half,inv);else if constexpr(quarter==4)fft_dit_4point_x2<true>(input+half,inv);else{fft_square_split_dit<quarter>(input+half,inv);fft_square_split_dit<quarter>(input+half+quarter,inv);}const Complex*_om1=TABLE.omega_data((INT_32)lg);const Complex*_om3=TABLE.omega3_data((INT_32)lg);for(size_t i=0;i<quarter;i+=2)
fft_split_radix_dit_butterfly(Complex2(_om1+i),Complex2(_om3+i),input+i,quarter);}}template<size_t LEN=1>
void fft_square_dit_dispatch(Complex*input,size_t length,double inv){if constexpr(LEN<(1u<<24)){if(length>LEN){fft_square_dit_dispatch<LEN*2>(input,length,inv);return;}TABLE.expand(hint_log2(LEN));fft_square_split_dit<LEN>(input,inv);}}template<size_t LEN>
void fft_split_radix_dif_template(Complex*input)
{constexpr size_t log_len=hint_log2(LEN);constexpr size_t half_len=LEN / 2,quarter_len=LEN / 4;const Complex*_om1=TABLE.omega_data(log_len),*_om3=TABLE.omega3_data(log_len);for(size_t i=0;i<quarter_len;i+=2)
{auto omega=Complex2(_om1+i);auto omega_cube=Complex2(_om3+i);fft_split_radix_dif_butterfly(omega,omega_cube,input+i,quarter_len);}fft_split_radix_dif_template<half_len>(input);if constexpr(quarter_len==8)
{fft_dif_8point_x2(input+half_len);}else if constexpr(quarter_len==4)
{fft_dif_4point_x2(input+half_len);}else
{fft_split_radix_dif_template<quarter_len>(input+half_len);fft_split_radix_dif_template<quarter_len>(input+half_len+quarter_len);}}template<>
void fft_split_radix_dif_template<0>(Complex*input){}template<>
void fft_split_radix_dif_template<1>(Complex*input){}template<>
void fft_split_radix_dif_template<2>(Complex*input)
{fft_2point(input[0],input[1]);}template<>
void fft_split_radix_dif_template<4>(Complex*input)
{fft_dif_4point(input,1);}template<>
void fft_split_radix_dif_template<8>(Complex*input)
{fft_dif_8point(input,1);}template<size_t LEN=1>
void fft_dit_template(Complex*input,size_t fft_len)
{if(fft_len>LEN)
{fft_dit_template<LEN*2>(input,fft_len);return;}TABLE.expand(hint_log2(LEN));fft_split_radix_dit_template<LEN>(input);}template<>
void fft_dit_template<1<<24>(Complex*input,size_t fft_len){}template<size_t LEN=1>
void fft_dif_template(Complex*input,size_t fft_len)
{if(fft_len>LEN)
{fft_dif_template<LEN*2>(input,fft_len);return;}TABLE.expand(hint_log2(LEN));fft_split_radix_dif_template<LEN>(input);}template<>
void fft_dif_template<1<<24>(Complex*input,size_t fft_len){}template<size_t LEN=16>
void fft_dif_zero_half(Complex*input,size_t fft_len)
{if constexpr(LEN<(1u<<24))
{if(fft_len>LEN)
{fft_dif_zero_half<LEN*2>(input,fft_len);return;}constexpr size_t half=LEN / 2,quarter=LEN / 4,lg=hint_log2(LEN);TABLE.expand(lg);const Complex*_om1=TABLE.omega_data(lg),*_om3=TABLE.omega3_data(lg);for(size_t i=0;i<quarter;i+=2)
{const Complex2 a(input+i),b(input+quarter+i);const Complex2 bi=b.mul_neg_i();((a+bi)*Complex2(_om1+i)).store(input+half+i);((a-bi)*Complex2(_om3+i)).store(input+half+quarter+i);}fft_split_radix_dif_template<half>(input);if constexpr(quarter==8)
{fft_dif_8point_x2(input+half);}else if constexpr(quarter==4)
{fft_dif_4point_x2(input+half);}else
{fft_split_radix_dif_template<quarter>(input+half);fft_split_radix_dif_template<quarter>(input+half+quarter);}}}inline void fft_dit(Complex*input,size_t fft_len,bool bit_rev=true)
{fft_len=max_2pow(fft_len);if(bit_rev)
{binary_reverse_swap(input,fft_len);}fft_dit_template<1>(input,fft_len);}inline void fft_dif(Complex*input,size_t fft_len,bool bit_rev=true)
{fft_len=max_2pow(fft_len);fft_dif_template<1>(input,fft_len);if(bit_rev)
{binary_reverse_swap(input,fft_len);}}}template<UINT_64 BASE_x,typename T>
constexpr void save_num_to_ary(T ary[],UINT_64 num,size_t digit)
{size_t i=digit;while(i>0)
{i--;ary[i]=num%BASE_x;num /=BASE_x;}}UINT_64 stoui64(const std::string::const_iterator&begin,
const std::string::const_iterator&end,const UINT_32 base=10)
{UINT_64 result=0;for(auto it=begin;it<end&&it-begin<19;++it)
{result*=base;char c=tolower(*it);UINT_64 n=0;if(isalnum(c))
{if(isalpha(c))
{n=c- 'a' +10;}else
{n=c- '0';}}if(n<base)
{result+=n;}}return result;}UINT_64 stoui64(const std::string&str,const UINT_32 base=10)
{return stoui64(str.begin(),str.end(),base);}std::string ui64to_string(UINT_64 input,UINT_8 digits)
{std::string result(digits,'0');for(UINT_8 i=0;i<digits;i++)
{result[digits-i-1]=static_cast<char>(input%10+ '0');input /=10;}return result;}template<typename T=UINT_32,typename SIZE_TYPE=UINT_32>
class HintVector
{private:
T*ary_ptr=nullptr;SIZE_TYPE sign_n_len=0;SIZE_TYPE size=0;public:
~HintVector()
{if(ary_ptr!=nullptr)
{delete[]ary_ptr;ary_ptr=nullptr;}}HintVector()
{ary_ptr=nullptr;}HintVector(SIZE_TYPE ele_size)
{if(ele_size>0)
{resize(ele_size);}}HintVector(SIZE_TYPE ele_size,T ele)
{if(ele_size>0)
{resize(ele_size);change_length(ele_size);fill_element(ele,ele_size);}}HintVector(const T*ary,SIZE_TYPE len)
{if(ary==nullptr)
{throw("Can't copy from nullptr\n");}if(len>0)
{resize(len);change_length(len);ary_copy(ary_ptr,ary,len);}}HintVector(const HintVector&input)
{if(input.ary_ptr!=nullptr)
{if(ary_ptr!=nullptr)
{delete[]ary_ptr;}ary_ptr=nullptr;size_t len=input.length();resize(len);change_length(len);change_sign(input.sign());ary_copy(ary_ptr,input.ary_ptr,len);}}HintVector(HintVector&&input)
{if(input.ary_ptr!=nullptr)
{size=input.size;change_length(input.length());change_sign(input.sign());if(ary_ptr!=nullptr)
{delete[]ary_ptr;}ary_ptr=input.ary_ptr;input.ary_ptr=nullptr;}}HintVector&operator=(const HintVector&input)
{if(this!= &input)
{if(ary_ptr!=nullptr)
{delete[]ary_ptr;}ary_ptr=nullptr;size_t len=input.length();resize(len);change_length(len);change_sign(input.sign());ary_copy(ary_ptr,input.ary_ptr,len);}return*this;}HintVector&operator=(HintVector&&input)
{if(this!= &input)
{size=input.size;change_length(input.length());change_sign(input.sign());if(ary_ptr!=nullptr)
{delete[]ary_ptr;}ary_ptr=input.ary_ptr;input.ary_ptr=nullptr;}return*this;}T&operator[](SIZE_TYPE index)const
{return ary_ptr[index];}T*data()const
{return ary_ptr;}static SIZE_TYPE size_generator(SIZE_TYPE new_size)
{constexpr SIZE_TYPE SIZE_TYPE_BITS=sizeof(SIZE_TYPE)*8;constexpr SIZE_TYPE SIZE_80=(1ull<<(SIZE_TYPE_BITS-1));constexpr SIZE_TYPE LEN_MAX=SIZE_80-1;new_size=std::min<SIZE_TYPE>(new_size,LEN_MAX);if(new_size<=2)
{return 2;}else if(new_size<=4)
{return 4;}SIZE_TYPE size1=min_2pow(new_size);SIZE_TYPE size2=size1 / 2;size2=size2+size2 / 2;if(new_size<=size2)
{return size2;}else
{return size1;}}SIZE_TYPE length()const
{constexpr SIZE_TYPE SIZE_TYPE_BITS=sizeof(SIZE_TYPE)*8;constexpr SIZE_TYPE SIZE_80=(1ull<<(SIZE_TYPE_BITS-1));constexpr SIZE_TYPE LEN_MAX=SIZE_80-1;return sign_n_len&LEN_MAX;}bool sign()const
{constexpr SIZE_TYPE SIZE_TYPE_BITS=sizeof(SIZE_TYPE)*8;constexpr SIZE_TYPE SIZE_80=(1ull<<(SIZE_TYPE_BITS-1));return(SIZE_80&sign_n_len)!=0;}SIZE_TYPE capacity()const
{return size;}constexpr void resize(SIZE_TYPE new_size,SIZE_TYPE(size_func)(SIZE_TYPE)=size_generator)
{new_size=size_func(new_size);if(ary_ptr==nullptr)
{size=new_size;ary_ptr=new T[size];change_length(0);}else if(size!=new_size)
{size=new_size;ary_ptr=ary_realloc(ary_ptr,size);change_length(length());}}void change_length(SIZE_TYPE new_length)
{constexpr SIZE_TYPE SIZE_TYPE_BITS=sizeof(SIZE_TYPE)*8;constexpr SIZE_TYPE SIZE_80=(1ull<<(SIZE_TYPE_BITS-1));constexpr SIZE_TYPE LEN_MAX=SIZE_80-1;if(new_length>LEN_MAX)
{throw("Length too long\n");}new_length=std::min(new_length,size);bool sign_tmp=sign();sign_n_len=new_length;change_sign(sign_tmp);}void change_sign(bool is_sign)
{constexpr SIZE_TYPE SIZE_TYPE_BITS=sizeof(SIZE_TYPE)*8;constexpr SIZE_TYPE SIZE_80=(1ull<<(SIZE_TYPE_BITS-1));constexpr SIZE_TYPE LEN_MAX=SIZE_80-1;if((!is_sign)||length()==0)
{sign_n_len=sign_n_len&LEN_MAX;}else
{sign_n_len=sign_n_len|SIZE_80;}}SIZE_TYPE set_true_len()
{if(ary_ptr==nullptr)
{return 0;}SIZE_TYPE t_len=length();while(t_len>0&&ary_ptr[t_len-1]==0)
{t_len--;}change_length(t_len);return length();}void fill_element(T ele,SIZE_TYPE count,SIZE_TYPE begin=0)
{if(begin>=size||ary_ptr==nullptr)
{return;}if(begin+count>=size)
{count=size-begin;}std::fill(ary_ptr+begin,ary_ptr+begin+count,ele);}};}namespace hint_arithm
{using namespace hintx;using SIZE_TYPE=UINT_32;template<typename T>
using hintvector=HintVector<T,SIZE_TYPE>;template<typename T>
constexpr size_t ary_true_len(const T&ary,size_t len)
{while(len>0&&ary[len-1]==0)
{len--;}return len;}template<typename T>
constexpr INT_32 abs_compare(const T ary1[],const T ary2[],size_t len1,size_t len2)
{len1=ary_true_len(ary1,len1);len2=ary_true_len(ary2,len2);if(len1!=len2)
{return len1>len2?1: -1;}if(ary1==ary2)
{return 0;}while(len1>0)
{len1--;T num1=ary1[len1],num2=ary2[len1];if(num1!=num2)
{return num1>num2?1: -1;}}return 0;}template<typename T>
constexpr INT_32 abs_compare_normalized(const T ary1[],const T ary2[],size_t len1,size_t len2)
{if(len1!=len2)
{return len1>len2?1: -1;}if(ary1==ary2)
{return 0;}while(len1>0)
{len1--;T num1=ary1[len1],num2=ary2[len1];if(num1!=num2)
{return num1>num2?1: -1;}}return 0;}template<UINT_64 BASE_x,bool is_carry=true,typename T>
constexpr void abs_mul_num(const T in[],T num,T out[],size_t len)
{len=ary_true_len(in,len);num%=BASE_x;UINT_64 prod=0;if(num==1)
{ary_copy(out,in,len);}else
{size_t i=0;if constexpr(BASE_x<=10000)
{constexpr UINT_64 B2=BASE_x*BASE_x,B3=B2*BASE_x;for(;i+3<=len;i+=3)
{const UINT_64 packed=UINT_64(in[i])+BASE_x*in[i+1]+B2*in[i+2];const UINT_64 value=packed*num+prod;const UINT_64 upper=value/B3;const UINT_64 remainder=value-upper*B3;const UINT_64 high=remainder/B2;const UINT_32 low=(UINT_32)(remainder-high*B2);const UINT_32 middle=low/(UINT_32)BASE_x;out[i]=T(low-middle*(UINT_32)BASE_x);out[i+1]=T(middle);out[i+2]=T(high);prod=upper;}}for(;i<len;i++)
{prod+=static_cast<UINT_64>(in[i])*num;std::tie(prod,out[i])=div_mod<UINT_64>(prod,BASE_x);}}if(is_carry)
{out[len]=prod;}}template<UINT_64 BASE_x,typename T>
constexpr INT_64 abs_div_num(const T in[],T num,T out[],size_t len)
{size_t pos=ary_true_len(in,len);num%=BASE_x;if(num==1)
{ary_copy(out,in,len);return 0;}UINT_64 last_rem=0;if constexpr(BASE_x<=10000)
{constexpr UINT_64 B2=BASE_x*BASE_x,B3=B2*BASE_x;while(pos>=3)
{pos-=3;const UINT_64 value=last_rem*B3+UINT_64(in[pos+2])*B2
+UINT_64(in[pos+1])*BASE_x+in[pos];const UINT_64 q=value / num;last_rem=value-q*num;out[pos]=T(q%BASE_x);out[pos+1]=T((q / BASE_x)%BASE_x);out[pos+2]=T(q / B2);}}while(pos>0)
{pos--;last_rem=last_rem*BASE_x+in[pos];std::tie(out[pos],last_rem)=div_mod<UINT_64>(last_rem,num);}return last_rem;}template<INT_64 BASE_x,bool is_carry=true,typename T>
constexpr void abs_add(const T in1[],const T in2[],T out[],
size_t len1,size_t len2)
{if(len1<len2)
{std::swap(in1,in2);std::swap(len1,len2);}size_t pos=0;UINT_64 carry=0;if constexpr(sizeof(T)==4&&BASE_x<=32768)
{constexpr unsigned long long bias=0x10000ull-(unsigned long long)BASE_x;const unsigned long long biasq=bias*0x0001000100010001ull;const __m128i ones=_mm_set1_epi32(-1);while(pos+4<=len2)
{const __m128i a4=_mm_loadu_si128((const __m128i*)(const void*)(in1+pos));const __m128i b4=_mm_loadu_si128((const __m128i*)(const void*)(in2+pos));const unsigned long long va=(unsigned long long)_mm_cvtsi128_si64(_mm_packus_epi32(a4,ones));const unsigned long long vb=(unsigned long long)_mm_cvtsi128_si64(_mm_packus_epi32(b4,ones));const unsigned long long v=va+vb+(unsigned long long)carry+biasq;const unsigned long long m=(v>>15)&0x0001000100010001ull;const unsigned long long r=v-m*bias;_mm_storeu_si128((__m128i*)(void*)(out+pos),
_mm_cvtepu16_epi32(_mm_cvtsi64_si128((long long)r)));carry=1ull-(v>>63);pos+=4;}}while(pos<len2)
{carry+=(in1[pos]+in2[pos]);out[pos]=carry<BASE_x?carry:carry-BASE_x;carry=carry<BASE_x?0:1;pos++;}while(pos<len1&&carry>0)
{carry+=in1[pos];out[pos]=carry<BASE_x?carry:carry-BASE_x;carry=carry<BASE_x?0:1;pos++;}ary_copy(out+pos,in1+pos,len1-pos);if(is_carry)
{out[len1]=carry%BASE_x;}}template<INT_64 BASE_x,typename T>
constexpr void abs_sub(const T in1[],const T in2[],T out[],
size_t len1,size_t len2)
{if(len1<len2)
{return;}size_t pos=0;INT_64 borrow=0;if(sizeof(T)==4&&BASE_x<=32768)
{constexpr unsigned long long bias=0x10000ull-(unsigned long long)BASE_x;const __m128i ones=_mm_set1_epi32(-1);while(pos+8<=len2)
{const __m128i a4=_mm_loadu_si128((const __m128i*)(const void*)(in1+pos));const __m128i b4=_mm_loadu_si128((const __m128i*)(const void*)(in2+pos));const __m128i a4b=_mm_loadu_si128((const __m128i*)(const void*)(in1+pos+4));const __m128i b4b=_mm_loadu_si128((const __m128i*)(const void*)(in2+pos+4));const unsigned long long va=(unsigned long long)_mm_cvtsi128_si64(_mm_packus_epi32(a4,ones));const unsigned long long vb=(unsigned long long)_mm_cvtsi128_si64(_mm_packus_epi32(b4,ones));const unsigned long long va2=(unsigned long long)_mm_cvtsi128_si64(_mm_packus_epi32(a4b,ones));const unsigned long long vb2=(unsigned long long)_mm_cvtsi128_si64(_mm_packus_epi32(b4b,ones));const unsigned long long d0=va-vb-(unsigned long long)borrow;const unsigned long long m=(d0>>15)&0x0001000100010001ull;const unsigned long long d=d0-m*bias;_mm_storeu_si128((__m128i*)(void*)(out+pos),
_mm_cvtepu16_epi32(_mm_cvtsi64_si128((long long)d)));const unsigned long long carry1=(d0>>63)&1ull;const unsigned long long d0b=va2-vb2-carry1;const unsigned long long mb=(d0b>>15)&0x0001000100010001ull;const unsigned long long db=d0b-mb*bias;_mm_storeu_si128((__m128i*)(void*)(out+pos+4),
_mm_cvtepu16_epi32(_mm_cvtsi64_si128((long long)db)));borrow=(INT_64)((d0b>>63)&1ull);pos+=8;}while(pos+4<=len2)
{const __m128i a4=_mm_loadu_si128((const __m128i*)(const void*)(in1+pos));const __m128i b4=_mm_loadu_si128((const __m128i*)(const void*)(in2+pos));unsigned long long va=(unsigned long long)_mm_cvtsi128_si64(_mm_packus_epi32(a4,ones));unsigned long long vb=(unsigned long long)_mm_cvtsi128_si64(_mm_packus_epi32(b4,ones));const unsigned long long d0=va-vb-(unsigned long long)borrow;const unsigned long long m=(d0>>15)&0x0001000100010001ull;const unsigned long long d=d0-m*bias;_mm_storeu_si128((__m128i*)(void*)(out+pos),
_mm_cvtepu16_epi32(_mm_cvtsi64_si128((long long)d)));borrow=(INT_64)((d0>>63)&1ull);pos+=4;}borrow=borrow? -1:0;}while(pos<len2)
{borrow+=(static_cast<INT_64>(in1[pos])-in2[pos]);out[pos]=(T)(borrow<0?borrow+BASE_x:borrow);borrow=borrow<0? -1:0;pos++;}while(pos<len1&&borrow<0)
{borrow+=in1[pos];out[pos]=borrow<0?borrow+BASE_x:borrow;borrow=borrow<0? -1:0;pos++;}ary_copy(out+pos,in1+pos,len1-pos);}template<UINT_64 BASE_x,typename T>
void fft_mul(const T in1[],const T in2[],T out[],
size_t len1,size_t len2,size_t skip=0)
{using namespace hint_transform;if(len1==0||len2==0||in1==nullptr||in2==nullptr)
{return;}const size_t conv_res_len=len1+len2-1;if(len1<=32&&len2<=32)
{hintx::UINT_64 acc[64];for(size_t i=0;i<conv_res_len;++i)acc[i]=0;for(size_t i=0;i<len1;++i)
{const hintx::UINT_64 a=(hintx::UINT_64)in1[i];if(!a)continue;for(size_t j=0;j<len2;++j)acc[i+j]+=a*(hintx::UINT_64)in2[j];}hintx::UINT_64 carry=0;for(size_t i=0;i<conv_res_len;++i)
{const hintx::UINT_64 t=carry+acc[i];out[i]=(T)(t%(hintx::UINT_64)BASE_x);carry=t /(hintx::UINT_64)BASE_x;}out[conv_res_len]=(T)(carry%(hintx::UINT_64)BASE_x);return;}if((len1<=4||len2<=4)&&(hintx::UINT_64)len1*(hintx::UINT_64)len2<=65536){const T*sm=len1<=len2?in1:in2;const T*lg=len1<=len2?in2:in1;const size_t m=len1<=len2?len1:len2,L=len1<=len2?len2:len1;hintx::UINT_64 cy=0;for(size_t i=0;i<conv_res_len;i++){hintx::UINT_64 v=cy;const size_t j0=i<L?0:i-(L-1),j1=i<m?i+1:m;for(size_t j=j0;j<j1;j++)v+=(hintx::UINT_64)sm[j]*(hintx::UINT_64)lg[i-j];out[i]=(T)(v%(hintx::UINT_64)BASE_x);cy=v/(hintx::UINT_64)BASE_x;}out[conv_res_len]=(T)(cy%(hintx::UINT_64)BASE_x);return;}size_t fft_len=min_2pow(conv_res_len);size_t wrap=0;if constexpr(BASE_x<=10000){const size_t half=fft_len/2;if(half>=64&&conv_res_len-half<=8&&len1<=half&&len2<=half){wrap=conv_res_len-half;fft_len=half;}}const size_t fft_capacity=std::max(size_t(16385),std::max(fft_len+1,conv_res_len));if(fft_capacity>g_fft_cap)
{std::free(g_fft_raw);g_fft_raw=std::malloc(sizeof(Complex)*fft_capacity+64);if(g_fft_raw==nullptr)
{throw("alloc error");}g_fft_buf=(Complex*)(((uintptr_t)g_fft_raw+16+31)& ~(uintptr_t)31);g_fft_cap=fft_capacity;}Complex*fft_ary=g_fft_buf;if(in1==in2&&len1==len2){const size_t m=fft_len / 2;const size_t packed_len=(len1+1)/ 2;size_t si=0;if constexpr(sizeof(T)==4&&BASE_x<=0x7fffffffu){for(;si+4<=len1;si+=4)
_mm256_store_pd(reinterpret_cast<double*>(fft_ary)+si,
_mm256_cvtepi32_pd(_mm_loadu_si128(reinterpret_cast<const __m128i*>(in1+si))));}for(;si+2<=len1;si+=2)fft_ary[si/2]=Complex((double)in1[si],(double)in1[si+1]);if(si<len1)fft_ary[si/2]=Complex((double)in1[si],0.0);std::memset((void*)(fft_ary+packed_len),0,(m-packed_len)*sizeof(Complex));fft_dif_template<1>(fft_ary,m);const double scale=1.0 /(double)m;{const double a=fft_ary[0].real(),b=fft_ary[0].imag();fft_ary[0]=Complex((a*a+b*b)*scale,(-2*a*b)*scale);const double c=fft_ary[1].real(),d=fft_ary[1].imag();fft_ary[1]=Complex((c*c-d*d)*scale,(-2*c*d)*scale);}const unsigned lg=hint_log2(m);auto reverse_index=[lg](unsigned x){x=((x&0x55555555u)<<1)|((x>>1)&0x55555555u);x=((x&0x33333333u)<<2)|((x>>2)&0x33333333u);x=((x&0x0f0f0f0fu)<<4)|((x>>4)&0x0f0f0f0fu);x=__builtin_bswap32(x);return x>>(32-lg);};AlignedComplexVec&roots=g_real_roots;const size_t old_roots=roots.size();if(old_roots<m){if(roots.capacity()<m)roots.reserve(m<16385?16385:m);roots.resize(m);for(size_t h=old_roots<2?2:old_roots;h<m;h*=2)
for(size_t r=h;r<h+h/2;++r)
roots[r]=TABLE.get_omega(lg,reverse_index((unsigned)r));}for(size_t h=2;h<4;h*=2){for(size_t r=h;r<h+h/2;++r){const size_t j=3*h-1-r;const Complex w=TABLE.get_omega(lg,reverse_index((unsigned)r));const double a=fft_ary[r].real(),b=fft_ary[r].imag();const double c=fft_ary[j].real(),d=fft_ary[j].imag();const double er=(a+c)*0.5,ei=(b-d)*0.5;const double or_=(b+d)*0.5,oi=(c-a)*0.5;const double osr=or_*or_-oi*oi,osi=2*or_*oi;const double vr=er*er-ei*ei+w.real()*osr-w.imag()*osi;const double vi=2*er*ei+w.real()*osi+w.imag()*osr;const double ur=2*(er*or_-ei*oi),ui=2*(er*oi+ei*or_);fft_ary[r]=Complex((vr-ui)*scale,-(vi+ur)*scale);fft_ary[j]=Complex((vr+ui)*scale,(vi-ur)*scale);}}const __m256d half_v=_mm256_set1_pd(0.5);const __m256d two_v=_mm256_set1_pd(2.0);const __m256d scale_v=_mm256_set1_pd(scale);const __m256d sq_scale=_mm256_setr_pd(1.0,2.0,1.0,2.0);const __m256d im_sign=_mm256_setr_pd(0.0,-0.0,0.0,-0.0);const __m256d re_sign=_mm256_setr_pd(-0.0,0.0,-0.0,0.0);for(size_t h=4;h<m;h*=2){for(size_t r=h;r<h+h/2;r+=2){const size_t j=3*h-1-r;const __m256d y=_mm256_load_pd((const double*)(fft_ary+r));__m256d v=_mm256_load_pd((const double*)(fft_ary+j-1));v=_mm256_xor_pd(_mm256_permute2f128_pd(v,v,1),im_sign);const __m256d e=_mm256_mul_pd(_mm256_add_pd(y,v),half_v);const __m256d diff=_mm256_sub_pd(y,v);const __m256d o=_mm256_mul_pd(_mm256_xor_pd(_mm256_permute_pd(diff,5),im_sign),half_v);const Complex2 esq(squared_inverse_input(e,sq_scale));const Complex2 osq(squared_inverse_input(o,sq_scale));const __m256d ev=(esq+Complex2(roots.data()+r)*osq).data;const __m256d ov=_mm256_mul_pd((Complex2(e)*Complex2(o)).data,two_v);const __m256d iov=_mm256_xor_pd(_mm256_permute_pd(ov,5),re_sign);const __m256d zr=_mm256_mul_pd(_mm256_xor_pd(_mm256_add_pd(ev,iov),im_sign),scale_v);__m256d zj=_mm256_mul_pd(_mm256_sub_pd(ev,iov),scale_v);zj=_mm256_permute2f128_pd(zj,zj,1);_mm256_store_pd((double*)(fft_ary+r),zr);_mm256_store_pd((double*)(fft_ary+j-1),zj);}}fft_dit_template<1>(fft_ary,m);}else{const size_t m=fft_len / 2;const bool cache_divisor=static_cast<const void*>(in2)==g_real_divisor&&len2==g_real_divisor_len;const bool cache_divisorB=static_cast<const void*>(in2)==g_real_divisorB&&len2==g_real_divisorB_len;const bool cache_reciprocal=static_cast<const void*>(in2)==g_real_reciprocal&&len2==g_real_reciprocal_len;const bool cache_b=cache_divisor||cache_divisorB||cache_reciprocal;AlignedComplexVec&cache_fft=cache_divisor?g_real_divisor_fft:(cache_divisorB?g_real_divisorB_fft:g_real_reciprocal_fft);bool&cache_ready=cache_divisor?g_real_divisor_ready:(cache_divisorB?g_real_divisorB_ready:g_real_reciprocal_ready);Complex*fb=fft_ary+m;if(cache_b){if(cache_fft.size()!=m){cache_fft.resize(m);cache_ready=false;}fb=cache_fft.data();}auto pack_forward=[&](Complex*dst,const T*src,size_t len){const size_t packed_len=(len+1)/ 2;size_t si=0;if constexpr(sizeof(T)==4&&BASE_x<=0x7fffffffu){for(;si+4<=len;si+=4)
_mm256_store_pd(reinterpret_cast<double*>(dst)+si,
_mm256_cvtepi32_pd(_mm_loadu_si128(reinterpret_cast<const __m128i*>(src+si))));}for(;si+2<=len;si+=2)dst[si/2]=Complex((double)src[si],(double)src[si+1]);if(si<len)dst[si/2]=Complex((double)src[si],0.0);const bool zh=m>=16&&packed_len<=m/2;std::memset((void*)(dst+packed_len),0,((zh?m/2:m)-packed_len)*sizeof(Complex));if(zh)fft_dif_zero_half(dst,m);else fft_dif_template<1>(dst,m);};const bool sh=(g_fm_share_spec!=nullptr)&&(g_fm_share_in1==static_cast<const void*>(in1))&&(g_fm_share_in1_len==len1)&&(g_fm_share_in1_m==m);if(sh&&!g_fm_share_save)std::memcpy(fft_ary,g_fm_share_spec,m*sizeof(Complex));else{pack_forward(fft_ary,in1,len1);if(sh&&g_fm_share_save)std::memcpy(g_fm_share_spec,fft_ary,m*sizeof(Complex));}if(!cache_b|| !cache_ready){pack_forward(fb,in2,len2);if(cache_b)cache_ready=true;}const double scale=1.0 /(double)m;{const double a=fft_ary[0].real(),b=fft_ary[0].imag();const double c=fb[0].real(),d=fb[0].imag();fft_ary[0]=Complex((a*c+b*d)*scale,-(a*d+b*c)*scale);const double e=fft_ary[1].real(),f=fft_ary[1].imag();const double g=fb[1].real(),h=fb[1].imag();fft_ary[1]=Complex((e*g-f*h)*scale,-(e*h+f*g)*scale);}const unsigned lg=hint_log2(m);auto reverse_index=[lg](unsigned x){x=((x&0x55555555u)<<1)|((x>>1)&0x55555555u);x=((x&0x33333333u)<<2)|((x>>2)&0x33333333u);x=((x&0x0f0f0f0fu)<<4)|((x>>4)&0x0f0f0f0fu);x=__builtin_bswap32(x);return x>>(32-lg);};AlignedComplexVec&roots=g_real_roots;const size_t old_roots=roots.size();if(old_roots<m){if(roots.capacity()<m)roots.reserve(m<16385?16385:m);roots.resize(m);for(size_t h=old_roots<2?2:old_roots;h<m;h*=2)
for(size_t r=h;r<h+h/2;++r)
roots[r]=TABLE.get_omega(lg,reverse_index((unsigned)r));}for(size_t h=2;h<4;h*=2){for(size_t r=h;r<h+h/2;++r){const size_t j=3*h-1-r;const Complex w=TABLE.get_omega(lg,reverse_index((unsigned)r));const double a=fft_ary[r].real(),b=fft_ary[r].imag();const double c=fft_ary[j].real(),d=fft_ary[j].imag();const double er=(a+c)*0.5,ei=(b-d)*0.5;const double or_=(b+d)*0.5,oi=(c-a)*0.5;const double a2=fb[r].real(),b2=fb[r].imag();const double c2=fb[j].real(),d2=fb[j].imag();const double er2=(a2+c2)*0.5,ei2=(b2-d2)*0.5;const double or2=(b2+d2)*0.5,oi2=(c2-a2)*0.5;const double osr=or_*or2-oi*oi2,osi=or_*oi2+oi*or2;const double vr=er*er2-ei*ei2+w.real()*osr-w.imag()*osi;const double vi=er*ei2+ei*er2+w.real()*osi+w.imag()*osr;const double ur=er*or2-ei*oi2+or_*er2-oi*ei2;const double ui=er*oi2+ei*or2+or_*ei2+oi*er2;fft_ary[r]=Complex((vr-ui)*scale,-(vi+ur)*scale);fft_ary[j]=Complex((vr+ui)*scale,(vi-ur)*scale);}}const __m256d half_v=_mm256_set1_pd(0.5);const __m256d two_v=_mm256_set1_pd(2.0);const __m256d scale_v=_mm256_set1_pd(scale);const __m256d sq_scale=_mm256_setr_pd(1.0,2.0,1.0,2.0);const __m256d im_sign=_mm256_setr_pd(0.0,-0.0,0.0,-0.0);const __m256d re_sign=_mm256_setr_pd(-0.0,0.0,-0.0,0.0);for(size_t h=4;h<m;h*=2){for(size_t r=h;r<h+h/2;r+=2){const size_t j=3*h-1-r;const __m256d y=_mm256_load_pd((const double*)(fft_ary+r));__m256d v=_mm256_load_pd((const double*)(fft_ary+j-1));v=_mm256_xor_pd(_mm256_permute2f128_pd(v,v,1),im_sign);const __m256d e=_mm256_mul_pd(_mm256_add_pd(y,v),half_v);const __m256d diff=_mm256_sub_pd(y,v);const __m256d o=_mm256_mul_pd(_mm256_xor_pd(_mm256_permute_pd(diff,5),im_sign),half_v);const __m256d y2=_mm256_load_pd((const double*)(fb+r));__m256d v2=_mm256_load_pd((const double*)(fb+j-1));v2=_mm256_xor_pd(_mm256_permute2f128_pd(v2,v2,1),im_sign);const __m256d e2=_mm256_mul_pd(_mm256_add_pd(y2,v2),half_v);const __m256d diff2=_mm256_sub_pd(y2,v2);const __m256d o2=_mm256_mul_pd(_mm256_xor_pd(_mm256_permute_pd(diff2,5),im_sign),half_v);const Complex2 ee=Complex2(e)*Complex2(e2);const Complex2 oo=Complex2(o)*Complex2(o2);const __m256d ev=(ee+Complex2(roots.data()+r)*oo).data;const __m256d ov=(Complex2(_mm256_add_pd(e,o))*Complex2(_mm256_add_pd(e2,o2))-ee-oo).data;const __m256d iov=_mm256_xor_pd(_mm256_permute_pd(ov,5),re_sign);const __m256d zr=_mm256_mul_pd(_mm256_xor_pd(_mm256_add_pd(ev,iov),im_sign),scale_v);__m256d zj=_mm256_mul_pd(_mm256_sub_pd(ev,iov),scale_v);zj=_mm256_permute2f128_pd(zj,zj,1);_mm256_store_pd((double*)(fft_ary+r),zr);_mm256_store_pd((double*)(fft_ary+j-1),zj);}}fft_dit_template<1>(fft_ary,m);}double*const packed_coeff=reinterpret_cast<double*>(fft_ary);auto coefficient=[&](size_t at){const double v=packed_coeff[at];return(at&1)? -v:v;};for(size_t t=0;t<wrap;t++){const size_t k=fft_len+t;hintx::UINT_64 exact=0;for(size_t i=k-(len2-1);i<len1;i++)exact+=(hintx::UINT_64)in1[i]*in2[k-i];const double v=(t&1)? -(double)exact:(double)exact;packed_coeff[t]-=v;packed_coeff[k]=v;}hintx::UINT_64 carry=0;size_t ic=0;if(skip>=8){hintx::UINT_64 low=0,high=(hintx::UINT_64)std::min(len1,len2)*(BASE_x-1);for(size_t j=skip-8;j<skip;++j){const hintx::UINT_64 c=static_cast<hintx::INT_64>(coefficient(j)+0.5);low=(c+low)/BASE_x;high=(c+high)/BASE_x;}if(low==high){carry=low;ic=skip;}}{const hintx::UINT_64 pair_per=(hintx::UINT_64)(BASE_x-1)*(BASE_x-1)
*(hintx::UINT_64)(BASE_x+2);if((hintx::UINT_64)((conv_res_len+1)/ 2)<=(~0ull)/ pair_per)
{if constexpr((hintx::UINT_64)BASE_x*BASE_x<=0xffffffffULL){const size_t each=(conv_res_len-ic)/8;if(each>=32){constexpr hintx::UINT_64 B=(hintx::UINT_64)BASE_x,B2=B*B;const size_t starts[4]={ic,ic+2*each,ic+4*each,ic+6*each};hintx::UINT_64 chains[4]={carry,0,0,0};auto pair_step=[&](size_t at,hintx::UINT_64&cy){const hintx::UINT_64 c0=static_cast<hintx::INT_64>(coefficient(at)+0.5);const hintx::UINT_64 c1=static_cast<hintx::INT_64>(coefficient(at+1)+0.5);const hintx::UINT_64 value=cy+c0+B*c1;cy=value/B2;const UINT_32 rem=(UINT_32)(value-cy*B2),hi=rem/(UINT_32)B;out[at]=(T)(rem-hi*(UINT_32)B);out[at+1]=(T)hi;};for(size_t j=0;j<each;j++){pair_step(starts[0]+2*j,chains[0]);pair_step(starts[1]+2*j,chains[1]);pair_step(starts[2]+2*j,chains[2]);pair_step(starts[3]+2*j,chains[3]);}for(int part=1;part<4;part++){hintx::UINT_64 actual=chains[part-1],assumed=0;size_t j=0;for(;j<each;j++){const size_t at=starts[part]+2*j;const hintx::UINT_64 c0=static_cast<hintx::INT_64>(coefficient(at)+0.5);const hintx::UINT_64 c1=static_cast<hintx::INT_64>(coefficient(at+1)+0.5);assumed=(assumed+c0+B*c1)/B2;pair_step(at,actual);if(actual==assumed)break;}if(j==each)chains[part]=actual;}carry=chains[3];ic+=8*each;}}for(;ic+2<=conv_res_len;ic+=2)
{const hintx::UINT_64 c0=static_cast<hintx::INT_64>(coefficient(ic)+0.5);const hintx::UINT_64 c1=static_cast<hintx::INT_64>(coefficient(ic+1)+0.5);const hintx::UINT_64 s0=carry+c0;const hintx::UINT_64 pair=s0+(hintx::UINT_64)BASE_x*c1;if constexpr((hintx::UINT_64)BASE_x*BASE_x<=0xffffffffULL){constexpr hintx::UINT_64 B2=(hintx::UINT_64)BASE_x*BASE_x;carry=pair/B2;const UINT_32 rest=(UINT_32)(pair-carry*B2);const UINT_32 hi=rest/(UINT_32)BASE_x;out[ic]=(T)(rest-hi*(UINT_32)BASE_x);out[ic+1]=(T)hi;}else{out[ic]=(T)(s0%BASE_x);out[ic+1]=(T)((pair/BASE_x)%BASE_x);carry=pair/((hintx::UINT_64)BASE_x*BASE_x);}}}}for(;ic<conv_res_len;ic++)
{carry+=static_cast<hintx::INT_64>(coefficient(ic)+0.5);std::tie(carry,out[ic])=div_mod<UINT_64>(carry,BASE_x);}out[conv_res_len]=carry%BASE_x;}template<UINT_64 BASE_x,typename T>
static bool merge_shifted_products(const T*a,const T*b,T*out,size_t overlap,size_t shift){std::copy_n(a,shift,out);abs_add<BASE_x>(b,a+shift,out+shift,overlap+shift,overlap);return out[overlap+2*shift]==0;}
template<UINT_64 BASE_x,typename T>
static bool fft_mul_split_b(const T in1[],size_t len1,const T in2[],size_t n,T out[]){using namespace hint_transform;if((n&1)||n<128||len1<33)return false;const size_t h=n/2,n2=n-h,conv1=len1+h-1,conv2=len1+n2-1,conv=len1+n-1;const size_t full=min_2pow(conv),half=min_2pow(conv1>conv2?conv1:conv2);if(half*2>full)return false;const size_t m=half/2;static AlignedComplexVec qspec;static hintvector<T>o0,o1;if(qspec.size()!=m)qspec.resize(m);if(g_real_divisor!=static_cast<const void*>(in2)||g_real_divisor_len!=h){g_real_divisor=static_cast<const void*>(in2);g_real_divisor_len=h;g_real_divisor_ready=false;}if(g_real_divisorB!=static_cast<const void*>(in2+h)||g_real_divisorB_len!=n2){g_real_divisorB=static_cast<const void*>(in2+h);g_real_divisorB_len=n2;g_real_divisorB_ready=false;}o0.resize(conv1+1);o1.resize(conv2+1);g_fm_share_in1=static_cast<const void*>(in1);g_fm_share_in1_len=len1;g_fm_share_in1_m=m;g_fm_share_spec=qspec.data();g_fm_share_save=true;fft_mul<BASE_x,T>(in1,in2,o0.data(),len1,h);g_fm_share_save=false;fft_mul<BASE_x,T>(in1,in2+h,o1.data(),len1,n2);g_fm_share_in1=nullptr;g_fm_share_spec=nullptr;return merge_shifted_products<BASE_x>(o0.data(),o1.data(),out,len1,h);}template<UINT_64 BASE_x,typename T>
static __attribute__((target("avx2"))) bool newton_middle_step(const T*b,size_t n,std::vector<T>&x,size_t p){using namespace hint_transform;constexpr size_t G=4,C=8;const size_t N=2*p;if(p<16||n<N+G||x.size()!=p+1)return false;const T*a=b+n-N-G;if(N+1>g_fft_cap){std::free(g_fft_raw);g_fft_raw=std::malloc(sizeof(Complex)*(N+1)+64);if(!g_fft_raw)throw("alloc error");g_fft_buf=(Complex*)(((uintptr_t)g_fft_raw+16+31)&~(uintptr_t)31);g_fft_cap=N+1;}Complex*f=g_fft_buf;com_ary_combine_copy(f,a,N,(const T*)x.data(),p+1);for(size_t i=0;i<G;++i)f[i].real(f[i].real()+a[N+i]);fft_dif_template<1>(f,N);fft_square_dit_dispatch(f,N,-1.0/(2.0*N));UINT_64 low=0,high=(UINT_64)(p+1)*(BASE_x-1);for(size_t j=p-C;j<p;++j){const size_t k=N+j;UINT_64 tail=0;for(size_t i=k-p;i<N+G;++i)tail+=(UINT_64)a[i]*x[k-i];const INT_64 coeff=static_cast<INT_64>(f[j].imag()+0.5)-(INT_64)tail;if(coeff<0)return false;low=((UINT_64)coeff+low)/BASE_x;high=((UINT_64)coeff+high)/BASE_x;}if(low!=high)return false;static hintvector<T>residue_buf,product_buf;residue_buf.resize(p+G+1);residue_buf.change_length(p+G+1);product_buf.resize(2*p+G+2);product_buf.change_length(2*p+G+2);hintvector<T> &residue=residue_buf;hintvector<T> &product=product_buf;std::vector<T>next(2*p+2,0);UINT_64 carry=low;for(size_t j=p;j<=N+G;++j){if constexpr(BASE_x<=10000){if(j==p+G&&p<=524288){constexpr UINT_64 B2=BASE_x*BASE_x;for(;j+1<N;j+=2){const INT_64 c0=static_cast<INT_64>(f[j].imag()+0.5);const INT_64 c1=static_cast<INT_64>(f[j+1].imag()+0.5);if(c0<0||c1<0)return false;const UINT_64 v=carry+(UINT_64)c0+BASE_x*(UINT_64)c1;carry=v/B2;const UINT_32 rem=(UINT_32)(v-carry*B2),hi=rem/(UINT_32)BASE_x;residue[j-p]=(T)(rem-hi*(UINT_32)BASE_x);residue[j-p+1]=(T)hi;}}}INT_64 coeff;if(j<N){coeff=static_cast<INT_64>(f[j].imag()+0.5);if(j<p+G){const size_t k=N+j;UINT_64 tail=0;for(size_t i=k-p;i<N+G;++i)tail+=(UINT_64)a[i]*x[k-i];coeff-=(INT_64)tail;}}else{const size_t k=j-N;UINT_64 bottom=0;for(size_t i=0;i<=k;++i)bottom+=(UINT_64)a[i]*x[k-i];coeff=static_cast<INT_64>(f[k].imag()+0.5)-(INT_64)bottom;}if(coeff<0)return false;const UINT_64 value=(UINT_64)coeff+carry;residue[j-p]=(T)(value%BASE_x);carry=value/BASE_x;}const bool subtract=residue[p+G]<BASE_x/2;if(!subtract){size_t i=0;while(i<=p+G&&residue[i]==0)++i;if(i<=p+G){residue[i]=(T)(BASE_x-residue[i]);++i;}if constexpr(sizeof(T)==4&&BASE_x<=0x7fffffff){const __m256i bm=_mm256_set1_epi32((int)(BASE_x-1));for(;i+7<=p+G;i+=8){const __m256i v=_mm256_loadu_si256((const __m256i*)(residue.data()+i));_mm256_storeu_si256((__m256i*)(residue.data()+i),_mm256_sub_epi32(bm,v));}}for(;i<=p+G;++i)residue[i]=(T)(BASE_x-1-residue[i]);}const size_t er=ary_true_len(residue.data(),residue.length());for(size_t i=0;i<=p;++i)next[p+i]=x[i];if(er){const size_t shift=p+G,plen=p+1+er;fft_mul<BASE_x>(x.data(),residue.data(),product.data(),p+1,er,shift<plen?shift:0);const size_t ql=plen>shift?plen-shift:0;if(subtract){if(ql)abs_sub<BASE_x>(next.data(),product.data()+shift,next.data(),next.size(),ql);}else{if(ql)abs_add<BASE_x,false>(next.data(),product.data()+shift,next.data(),next.size(),ql);for(size_t i=0;i<next.size();++i){if(++next[i]<BASE_x)break;next[i]=0;}}}next.resize(ary_true_len(next.data(),next.size()));if(next.size()!=N+1)return false;x.swap(next);return true;}template<UINT_64 BASE_x,typename T>
constexpr T divisor_normalize(const T in[],T out[],size_t len)
{if(in==out)
{throw("In can't be same as out\n");}T multiplier=1;if(len==1)
{multiplier=(BASE_x-1)/ in[0];out[0]=in[0]*multiplier;}else if(in[len-1]>=(BASE_x / 2))
{ary_copy(out,in,len);}else
{multiplier=(BASE_x-1)*BASE_x /(BASE_x*in[len-1]+in[len-2]);abs_mul_num<BASE_x,false>(in,multiplier,out,len);if(out[len-1]<(BASE_x / 2))
{multiplier++;abs_add<BASE_x,false>(out,in,out,len,len);}}return multiplier;}template<UINT_64 BASE_x,bool Prechecked=false,typename T>
void abs_long_div(T dividend[],const T divisor[],T quot[],
size_t len1,size_t len2)
{if constexpr(!Prechecked){len1=ary_true_len(dividend,len1);len2=ary_true_len(divisor,len2);if(divisor==nullptr||len2==0)
{throw("Can't divide by zero\n");}if(dividend==nullptr||len1==0)
{return;}if(abs_compare_normalized(dividend,divisor,len1,len2)<0)
{return;}}if(len2==1)
{T rem=abs_div_num<BASE_x>(dividend,divisor[0],quot,len1);dividend[0]=rem;return;}if(!Prechecked&&divisor[len2-1]<(BASE_x / 2))
{throw("Can't call this proc before normalize the divisor\n");}quot[len1-len2]=0;const UINT_64 divisor_2digits=BASE_x*divisor[len2-1]+divisor[len2-2];const UINT_64 trial_top=divisor[len2-1];const UINT_64 trial_recip=(BASE_x<=65536)?UINT_32(0xffffffffu)/ UINT_32(trial_top):0;(void)trial_top;(void)trial_recip;static hintvector<T>sub_cache;if(sub_cache.capacity()<(SIZE_TYPE)(len2+1)){sub_cache.resize((SIZE_TYPE)(len2+1));sub_cache.fill_element(0,sub_cache.capacity());}hintvector<T>&sub=sub_cache;static hintvector<UINT_64>triple_cache;const size_t groups=(BASE_x<=10000)?len2 / 3:0;if(triple_cache.capacity()<(SIZE_TYPE)groups)
{triple_cache.resize((SIZE_TYPE)groups);}UINT_64*packed=triple_cache.data();if constexpr(BASE_x<=10000)
{for(size_t g=0;g<groups;g++)
{packed[g]=UINT_64(divisor[3*g])+BASE_x*divisor[3*g+1]
+BASE_x*BASE_x*divisor[3*g+2];}}auto multiply_trial=[&](T num)
{if constexpr(BASE_x<=10000)
{constexpr UINT_64 B2=BASE_x*BASE_x,B3=B2*BASE_x;T*out=sub.data();UINT_64 carry=0;if(num==1)
{ary_copy(out,divisor,len2);}else
{size_t i=0;for(size_t g=0;g<groups;g++,i+=3)
{const UINT_64 value=packed[g]*num+carry;const UINT_64 q2=value / B3;const UINT_64 r2=value-q2*B3;const UINT_64 q1=r2 / B2;const UINT_64 r1=r2-q1*B2;const UINT_64 q0=r1 / BASE_x;out[i]=T(r1-q0*BASE_x);out[i+1]=T(q0);out[i+2]=T(q1);carry=q2;}for(;i<len2;i++)
{const UINT_64 value=UINT_64(divisor[i])*num+carry;carry=value / BASE_x;out[i]=T(value-carry*BASE_x);}}out[len2]=T(carry);}else
{abs_mul_num<BASE_x,true,true>(divisor,num,sub.data(),len2);}};while(abs_compare_normalized(dividend,divisor,len1,len2)>=0)
{sub.change_length(len2+1);UINT_64 dividend_2digits=dividend[len1-1]*BASE_x+dividend[len1-2];T quo_digit=0;size_t shift=len1-len2;if(dividend_2digits>divisor_2digits)
{if constexpr(BASE_x%2==0)
{sub.data()[len2]=0;abs_sub<BASE_x>(dividend+shift,divisor,dividend+shift,len1-shift,len2);len1=ary_true_len(dividend,len1);quot[shift]=1;continue;}quo_digit=dividend_2digits / divisor_2digits;multiply_trial(quo_digit);sub.change_length(len2+(sub.data()[len2]!=0));size_t sub_len=sub.length();if(abs_compare_normalized(dividend+shift,sub.data(),len1-shift,sub_len)<0)
{quo_digit--;abs_sub<BASE_x>(sub.data(),divisor,sub.data(),sub_len,len2);}}else if(dividend_2digits==divisor_2digits)
{if(abs_compare_normalized(dividend+shift,divisor,len1-shift,len2)<0)
{quo_digit=BASE_x-1;shift--;multiply_trial(quo_digit);}else
{quo_digit=1;ary_copy(sub.data(),divisor,len2);sub.set_true_len();}}else
{if constexpr(BASE_x<=65536)
{const UINT_64 approx=(dividend_2digits*trial_recip)>>32;const UINT_64 rem=dividend_2digits-approx*trial_top;quo_digit=T(approx+(rem>=trial_top));}else quo_digit=dividend_2digits /(divisor_2digits / BASE_x);if(quo_digit>=BASE_x)
{quo_digit=BASE_x-1;}{const UINT_64 v2=divisor_2digits-(UINT_64)BASE_x*trial_top;const UINT_64 u2=(len1>=3)?(UINT_64)dividend[len1-3]:0;UINT_64 rhat=dividend_2digits-(UINT_64)quo_digit*trial_top;while((UINT_64)quo_digit*v2>rhat*(UINT_64)BASE_x+u2)
{--quo_digit;rhat+=trial_top;}}shift--;if constexpr(BASE_x==10000){constexpr UINT_64 B=BASE_x,B2=B*B,B3=B2*B;T*d=dividend+shift;UINT_64 borrow=0;size_t i=0;for(size_t g=0;g<groups;g++,i+=3){const UINT_64 product=packed[g]*(UINT_64)quo_digit+borrow;borrow=product/B3;const UINT_64 low=product-borrow*B3;const UINT_64 old=(UINT_64)d[i]+B*d[i+1]+B2*d[i+2];const bool under=old<low;const UINT_64 rest=old-low+(under?B3:0);borrow+=under;const UINT_64 high=rest/B2;const UINT_32 small=(UINT_32)(rest-high*B2),mid=small/(UINT_32)B;d[i]=(T)(small-mid*(UINT_32)B);d[i+1]=(T)mid;d[i+2]=(T)high;}for(;i<len2;i++){const UINT_32 product=(UINT_32)divisor[i]*(UINT_32)quo_digit+(UINT_32)borrow;const UINT_32 high=product/(UINT_32)B,low=product-high*(UINT_32)B;const bool under=d[i]<low;d[i]=(T)((UINT_32)d[i]-low+(under?(UINT_32)B:0));borrow=(UINT_64)high+under;}INT_64 top=(INT_64)d[len2]-(INT_64)borrow;if(top<0){--quo_digit;UINT_32 carry_add=0;for(size_t k=0;k<len2;k++){const UINT_32 value=(UINT_32)d[k]+(UINT_32)divisor[k]+carry_add;carry_add=value>=(UINT_32)B;d[k]=(T)(value-carry_add*(UINT_32)B);}top+=carry_add;}d[len2]=(T)top;len1=ary_true_len(dividend,len1);quot[shift]=quo_digit;continue;}multiply_trial(quo_digit);sub.change_length(len2+(sub.data()[len2]!=0));size_t sub_len=sub.length();if(abs_compare_normalized(dividend+shift,sub.data(),len1-shift,sub_len)<0)
{quo_digit--;abs_sub<BASE_x>(sub.data(),divisor,sub.data(),sub_len,len2);if(abs_compare(dividend+shift,sub.data(),len1-shift,sub_len)<0)
{quo_digit--;abs_sub<BASE_x>(sub.data(),divisor,sub.data(),sub_len,len2);}}}abs_sub<BASE_x>(dividend+shift,sub.data(),dividend+shift,len1-shift,sub.length());len1=ary_true_len(dividend,len1);quot[shift]=quo_digit;}}template<UINT_64 BASE_x,typename T>
void abs_rec_div(T dividend[],T divisor[],hintvector<T> &quot,
size_t len1,size_t len2,size_t depth=0)
{len1=ary_true_len(dividend,len1);len2=ary_true_len(divisor,len2);if(divisor==nullptr||len2==0)
{throw("Can't divide by zero\n");}if(dividend==nullptr||len1==0)
{return;}if(abs_compare_normalized(dividend,divisor,len1,len2)<0)
{return;}if(divisor[len2-1]<(BASE_x / 2))
{throw("Can't call this proc before normalize the divisor\n");}size_t quot_len=len1-len2+1;quot.change_length(quot_len);constexpr size_t LONG_DIV_THRESHOLD=20;if(len2<=LONG_DIV_THRESHOLD)
{abs_long_div<BASE_x,true>(dividend,divisor,quot.data(),len1,len2);}else if(len1>=len2*2||len1>((len2+1)/ 2)*3)
{size_t base_len=(len1+3)/ 4;size_t quot_tmp_len=base_len*3-len2+2;static hintvector<T>quotient_slots[128];hintvector<T>fallback;hintvector<T>&quot_tmp=depth<128?quotient_slots[depth]:fallback;if(quot_tmp.capacity()<quot_tmp_len){hintvector<T>fresh(quot_tmp_len);quot_tmp=std::move(fresh);}quot_tmp.change_length(quot_tmp_len);quot_tmp.fill_element(0,quot_tmp_len);abs_rec_div<BASE_x>(dividend+base_len,divisor,quot_tmp,len1-base_len,len2,depth+1);quot_tmp_len=quot_tmp.set_true_len();size_t dividend_len=ary_true_len(dividend,len1);abs_rec_div<BASE_x>(dividend,divisor,quot,dividend_len,len2,depth+1);quot.change_length(quot_len);quot_len=quot.set_true_len();abs_add<BASE_x>(quot.data()+base_len,quot_tmp.data(),quot.data()+base_len,quot_len-base_len,quot_tmp_len);quot.change_length(len1-len2+1);}else
{size_t base_len=len2 / 2;abs_rec_div<BASE_x>(dividend+base_len,divisor+base_len,quot,len1-base_len,len2-base_len,depth+1);constexpr T ONE[1]={1};quot_len=quot.set_true_len();static hintvector<T>prod_cache;const SIZE_TYPE product_need=SIZE_TYPE(base_len+quot_len);if(prod_cache.capacity()<product_need){hintvector<T>fresh(product_need);prod_cache=std::move(fresh);}hintvector<T>&prod=prod_cache;prod.change_length(product_need);fft_mul<BASE_x>(divisor,quot.data(),prod.data(),base_len,quot_len);size_t prod_len=prod.set_true_len();len1=ary_true_len(dividend,len1);while(abs_compare_normalized(prod.data(),dividend,prod_len,len1)>0)
{abs_sub<BASE_x>(quot.data(),ONE,quot.data(),quot_len,1);abs_sub<BASE_x>(prod.data(),divisor,prod.data(),prod_len,base_len);abs_add<BASE_x>(dividend+base_len,divisor+base_len,dividend+base_len,len1-base_len,len2-base_len);quot_len=quot.set_true_len();prod_len=prod.set_true_len();len1=ary_true_len(dividend,std::max(len1,len2)+1);}abs_sub<BASE_x>(dividend,prod.data(),dividend,len1,prod_len);}}template<UINT_64 BASE_x,typename T>
static bool newton_divq(const T*a,size_t la,const T*b,size_t lb,T*quot,size_t qlen,size_t s,T*wbuf=nullptr)
{const size_t n=lb;g_real_divisor=b;g_real_divisor_len=lb;g_real_divisor_ready=false;g_real_divisorB_ready=false;g_real_reciprocal=nullptr;struct ReciprocalScope{~ReciprocalScope(){g_real_reciprocal=nullptr;}}reciprocal_scope;if(n<8||s<2||la<n+s||(n&1))return false;std::vector<T>xb,U,qe,Tt;static hintvector<T>Pb_buf,x2_buf,twox_buf;std::vector<T>work_owned;T*work;unsigned long long top2=(unsigned long long)b[n-1]*BASE_x+b[n-2];if(!top2)return false;unsigned long long x0=(unsigned long long)BASE_x*BASE_x*BASE_x / top2;xb.resize(2);xb[0]=(T)(x0%BASE_x);xb[1]=(T)(x0 / BASE_x);size_t p=1;auto trunc_top=[&](const T*A,size_t la_,const T*B,size_t lb_,size_t need,std::vector<T>&out)->T*{if(need==0){out.clear();return nullptr;}size_t sA=la_<need+2?la_:need+2;size_t sB=lb_<need+2?lb_:need+2;if(sA+sB<=need)return nullptr;Pb_buf.resize(sA+sB+2);Pb_buf.change_length(sA+sB+2);fft_mul<BASE_x>(A+la_-sA,B+lb_-sB,Pb_buf.data(),sA,sB,sA+sB-need);size_t sh=sA+sB-need;return Pb_buf.data()+sh;};while(p<s){size_t k=(s<=4096&&n>=2*p+4)?p:(p<(s-p)?p:(s-p));if(k==p&&newton_middle_step<BASE_x>(b,n,xb,p)){p+=k;continue;}size_t need=p+k+2;x2_buf.resize(2*p+2);x2_buf.change_length(2*p+2);T*x2=x2_buf.data();fft_mul<BASE_x>(xb.data(),xb.data(),x2,p+1,p+1);x2[2*p+1]=0;T*tp=trunc_top(b,n,x2,2*p+2,need,Tt);if(!tp)return false;twox_buf.resize(p+2);twox_buf.change_length(p+2);T*twox=twox_buf.data();unsigned cy=0;for(size_t i=0;i<=p;i++){unsigned v=(unsigned)xb[i]*2u+cy;twox[i]=(T)(v%BASE_x);cy=v / BASE_x;}twox[p+1]=(T)cy;U.assign(need,0);for(size_t i=0;i<p+2&&i+k<need;i++)U[i+k]=twox[i];if(abs_compare_normalized(U.data(),tp,need,need)<0)return false;abs_sub<BASE_x>(U.data(),tp,U.data(),need,need);size_t dl=ary_true_len(U.data(),need);U.resize(dl);xb.swap(U);p+=k;}if(p>s){if(xb.size()!=p+1)return false;xb.erase(xb.begin(),xb.begin()+(p-s));p=s;}if(xb.size()!=s+1)return false;g_real_reciprocal=xb.data();g_real_reciprocal_len=xb.size();g_real_reciprocal_ready=false;size_t L=n+s;if(wbuf){work=wbuf;work[la]=0;work[la+1]=0;}else{work_owned.assign(a,a+la);work_owned.resize(la+2,0);work=work_owned.data();}size_t pos=la>L?la-L:0;size_t untouched=qlen;int guard=0;for(;;){size_t lc=ary_true_len(work+pos,la-pos);size_t need=lc>n?lc-n+1:0;T*qp;size_t qn;if(!need){qe.assign(1,0);qp=qe.data();qn=1;}bool final_certified=false;if(need){constexpr size_t tail_guard=4;if(pos==0&&s<=524288&&(UINT_64)b[n-1]*10>=BASE_x&&
need<=s&&s-need>=tail_guard+3){qp=trunc_top(work,lc,xb.data(),s+1,need+tail_guard,qe);if(!qp)return false;bool all_zero=true,all_max=true;for(size_t i=0;i<tail_guard;++i){all_zero&=qp[i]==0;all_max&=qp[i]==BASE_x-1;}final_certified= !all_zero&& !all_max;for(size_t i=0;i<need;++i)qp[i]=qp[i+tail_guard];qn=need;}else{qp=trunc_top(work+pos,lc,xb.data(),s+1,need,qe);if(!qp)return false;qn=need;}}if(!final_certified){static hintvector<T>pv_buf;pv_buf.resize(need+n+2);pv_buf.change_length(need+n+2);T*const pv=pv_buf.data();if(!need)memset((void*)pv,0,sizeof(T)*(size_t)(n+2));if(need){if(!fft_mul_split_b<BASE_x,T>(qp,need,b,n,pv))fft_mul<BASE_x>(qp,b,pv,need,n);}auto qe_inc=[&]()->bool{unsigned c=1;for(size_t x=0;x<qn&&c;x++){unsigned v=(unsigned)qp[x]+c;qp[x]=(T)(v%BASE_x);c=v / BASE_x;}return c==0;};auto qe_dec=[&]()->bool{for(size_t x=0;x<qn;x++)if(qp[x]){qp[x]--;for(size_t y=0;y<x;y++)qp[y]=(T)(BASE_x-1);return true;}return false;};int it=0;for(;;){size_t pl=ary_true_len(pv,need+n);if(abs_compare_normalized(pv,work+pos,pl,lc)<=0)break;if(++it>64)return false;if(!qe_dec())return false;size_t bl=ary_true_len(b,n);pl=ary_true_len(pv,need+n);if(abs_compare_normalized(pv,b,pl,bl)<0)return false;abs_sub<BASE_x>(pv,b,pv,pl,bl);}T*const rv=work+pos;{size_t pl=ary_true_len(pv,need+n);if(pl)abs_sub<BASE_x>(rv,pv,rv,lc,pl);}for(;;){size_t rl=ary_true_len(rv,lc);if(abs_compare_normalized(rv,b,rl,n)<0)break;if(++it>64)return false;if(!qe_inc())return false;abs_sub<BASE_x>(rv,b,rv,rl,n);}}const size_t copied=std::min(qn,untouched-pos);std::copy_n(qp,copied,quot+pos);untouched=pos;unsigned carry=0;for(size_t i=copied;i<qn;i++){unsigned v=(unsigned)quot[pos+i]+(unsigned)qp[i]+carry;quot[pos+i]=(T)(v%BASE_x);carry=v / BASE_x;}size_t j=pos+qn;while(carry){if(j>=qlen)return false;unsigned v=(unsigned)quot[j]+carry;quot[j]=(T)(v%BASE_x);carry=v / BASE_x;j++;}if(pos==0)break;pos=pos>s?pos-s:0;}if(++guard>1)return false;return true;}template<UINT_64 BASE_x,typename T>
hintvector<T>abs_div(const T dividend[],T divisor[],hintvector<T> &quot,
size_t len1,size_t len2,bool ret_rem=true,T*wbuf=nullptr)
{if(!ret_rem&&len2>=4096&&len1>=len2+(len2>>1)){const size_t s_=(len2>=4096&&len2<=16383)?(16385-len2):(size_t(1)<<(63-__builtin_clzll(len2 / 2)));quot=hintvector<T>(len1-len2+2,0);if(newton_divq<BASE_x>(dividend,len1,divisor,len2,quot.data(),len1-len2+1,s_,wbuf)){quot.set_true_len();
#ifdef NEWTONDBG
fprintf(stderr,"RAW NEWTON OK la=%zu lb=%zu s=%zu\n",len1,len2,s_);
#endif
return hintvector<T>();}}hintvector<T>normalized_divisor(len2);normalized_divisor.change_length(len2);hintvector<T>normalized_dividend(len1+1);normalized_dividend.change_length(len1+1);T*divisor_ptr=normalized_divisor.data();T*dividend_ptr=normalized_dividend.data();T multiplier=divisor_normalize<BASE_x>(divisor,divisor_ptr,len2);abs_mul_num<BASE_x>(dividend,multiplier,dividend_ptr,len1);len1=normalized_dividend.set_true_len();quot=hintvector<T>(len1-len2+2,0);if((!ret_rem)&&(len1+2<len2*2))
{size_t shift=len2*2-len1-2;abs_rec_div<BASE_x>(dividend_ptr+shift,divisor_ptr+shift,quot,len1-shift,len2-shift);quot.set_true_len();return normalized_dividend;}if(!ret_rem&&len2>=4096&&len1>=len2+(len2>>1)){size_t s_=(len2>=4096&&len2<=16383)?(16385-len2):(size_t(1)<<(63-__builtin_clzll(len2 / 2)));std::vector<T>qtmp(len1-len2+2,0);if(newton_divq<BASE_x>(dividend_ptr,len1,divisor_ptr,len2,qtmp.data(),len1-len2+1,s_)){for(size_t i=0;i<len1-len2+1;i++)quot[i]=qtmp[i];quot.set_true_len();
#ifdef NEWTONDBG
fprintf(stderr,"NEWTON OK la=%zu lb=%zu s=%zu\n",(size_t)len1,(size_t)len2,s_);
#endif
return normalized_dividend;}
#ifdef NEWTONDBG
fprintf(stderr,"NEWTON FALLBACK la=%zu lb=%zu s=%zu\n",(size_t)len1,(size_t)len2,s_);
#endif
}abs_rec_div<BASE_x>(dividend_ptr,divisor_ptr,quot,len1,len2);quot.set_true_len();if(ret_rem)
{len1=normalized_dividend.set_true_len();abs_div_num<BASE_x>(dividend_ptr,multiplier,dividend_ptr,len1);normalized_dividend.set_true_len();}return normalized_dividend;}}struct DecimalLookup{char digits[10000][4]{};constexpr DecimalLookup(){for(unsigned i=0;i<10000;++i){digits[i][0]='0'+i/1000%10;digits[i][1]='0'+i/100%10;digits[i][2]='0'+i/10%10;digits[i][3]='0'+i/1%10;}}};static constexpr DecimalLookup DECIMAL_LU{};class Integer
{public:
using DataType=hintx::UINT_32;using SizeType=hintx::UINT_32;using DataVec=hintx::HintVector<DataType,SizeType>;private:
DataVec data;public:
static constexpr hintx::UINT_32 DIGIT=4;static constexpr hintx::UINT_64 BASE_x=10000;Integer()
{data=DataVec();}Integer(const Integer&input)
{if(this!= &input)
{data=input.data;}}Integer(Integer&&input)noexcept
{if(this!= &input)
{data=std::move(input.data);}}Integer&operator=(const Integer&input)
{if(this!= &input)
{data=input.data;}return*this;}Integer&operator=(Integer&&input)noexcept
{if(this!= &input)
{data=std::move(input.data);}return*this;}Integer&operator=(const std::string&input)
{string_in(input);return*this;}Integer&operator=(const char input[])
{string_in(input);return*this;}DataType first_num()const
{if(length()==0)
{return 0;}return data[length()-1];}void change_sign(bool is_neg)
{data.change_sign(is_neg);}bool is_neg()const
{return data.sign();}SizeType length()const
{return data.length();}SizeType length_base10()const
{size_t len=data.length();if(len==0)
{return 1;}return(len-1)*DIGIT+std::ceil(std::log10(first_num()+1));}void string_in(const std::string&str){string_in(str.data(),str.size());}__attribute__((target("avx2")))void string_in(const char*str,size_t str_size)
{if(str_size==0){data=DataVec();return;}const size_t begin=str[0]=='-'?1u:0u;const size_t limbs=(str_size-begin+3)/4;data=DataVec(limbs);data.change_length(limbs);size_t pos=str_size,i=0;const __m256i ascii0=_mm256_set1_epi8('0');const __m256i tens=_mm256_set1_epi16(0x010a);const __m256i hundreds=_mm256_set1_epi32(0x00010064);const __m256i reverse=_mm256_setr_epi32(7,6,5,4,3,2,1,0);unsigned*const dp=data.data();while(pos-begin>=32){const __m256i bytes=_mm256_sub_epi8(_mm256_loadu_si256((const __m256i*)(str+pos-32)),ascii0);const __m256i pairs=_mm256_maddubs_epi16(bytes,tens);const __m256i limbs8=_mm256_madd_epi16(pairs,hundreds);_mm256_storeu_si256((__m256i*)(dp+i),_mm256_permutevar8x32_epi32(limbs8,reverse));pos-=32;i+=8;}while(pos-begin>=4){const char*p=str+pos-4;data[i++]=(unsigned)(p[0]-'0')*1000u+(unsigned)(p[1]-'0')*100u+(unsigned)(p[2]-'0')*10u+(unsigned)(p[3]-'0')*1u;pos-=4;}if(pos>begin){unsigned v=0;for(size_t k=begin;k<pos;++k)v=v*10u+(unsigned)(str[k]-'0');data[i]=v;}change_sign(begin!=0);data.set_true_len();}__attribute__((target("avx2")))const char*string_in_until(const char*lo,const char*hi)
{const char*p=hi;data=DataVec((size_t)(hi-lo)/4+1);unsigned*const dp=data.data();size_t i=0;const __m256i ascii0=_mm256_set1_epi8('0'),dthr=_mm256_set1_epi8(47),tens=_mm256_set1_epi16(0x010a),hundreds=_mm256_set1_epi32(0x00010064),reverse=_mm256_setr_epi32(7,6,5,4,3,2,1,0);while(p-lo>=32){const __m256i bytes=_mm256_loadu_si256((const __m256i*)(const void*)(p-32));if((unsigned)_mm256_movemask_epi8(_mm256_cmpgt_epi8(bytes,dthr))!=~0u)break;const __m256i d=_mm256_sub_epi8(bytes,ascii0);const __m256i limbs8=_mm256_madd_epi16(_mm256_maddubs_epi16(d,tens),hundreds);_mm256_storeu_si256((__m256i*)(void*)(dp+i),_mm256_permutevar8x32_epi32(limbs8,reverse));p-=32;i+=8;}while(p-lo>=4){const char*c=p-4;if((unsigned char)c[0]<=47||(unsigned char)c[1]<=47||(unsigned char)c[2]<=47||(unsigned char)c[3]<=47)break;dp[i++]=(unsigned)(c[0]-'0')*1000u+(unsigned)(c[1]-'0')*100u+(unsigned)(c[2]-'0')*10u+(unsigned)(c[3]-'0');p-=4;}size_t ex=0;while(p>lo&&ex<3&&(unsigned char)p[-1]>47){--p;++ex;}if(ex){unsigned v=0;for(const char*c=p;c<p+ex;++c)v=v*10u+(unsigned)(*c-'0');dp[i++]=v;}const bool neg=p>lo&&p[-1]=='-';data.change_length(i);data.set_true_len();change_sign(neg);return neg?p-1:p;}__attribute__((target("avx2")))std::string to_string()const
{size_t pos=length();if(!pos)return "0";std::string result=is_neg()?"-":"";result+=std::to_string(first_num());const size_t prefix=result.size();result.resize(prefix+4*(pos-1));char*dst=result.data()+prefix;--pos;const __m256i hundred_recip=_mm256_set1_epi16(5243),hundred=_mm256_set1_epi16(100);const __m256i ten_recip=_mm256_set1_epi16(6554),pair_coefficient=_mm256_set1_epi16(-2559);const __m256i ascii=_mm256_set1_epi16(0x3030);const unsigned*const dsrc=data.data();while(pos>=16){const __m256i high=_mm256_permutevar8x32_epi32(_mm256_loadu_si256((const __m256i*)(dsrc+pos-8)),_mm256_setr_epi32(7,6,5,4,3,2,1,0));const __m256i low=_mm256_permutevar8x32_epi32(_mm256_loadu_si256((const __m256i*)(dsrc+pos-16)),_mm256_setr_epi32(7,6,5,4,3,2,1,0));const __m256i value=_mm256_packus_epi32(high,low);const __m256i q=_mm256_srli_epi16(_mm256_mulhi_epu16(value,hundred_recip),3);const __m256i r=_mm256_sub_epi16(value,_mm256_mullo_epi16(q,hundred));const __m256i qt=_mm256_mulhi_epu16(q,ten_recip);const __m256i rt=_mm256_mulhi_epu16(r,ten_recip);const __m256i qp=_mm256_add_epi16(_mm256_add_epi16(_mm256_slli_epi16(q,8),_mm256_mullo_epi16(qt,pair_coefficient)),ascii);const __m256i rp=_mm256_add_epi16(_mm256_add_epi16(_mm256_slli_epi16(r,8),_mm256_mullo_epi16(rt,pair_coefficient)),ascii);_mm256_storeu_si256((__m256i*)dst,_mm256_unpacklo_epi16(qp,rp));_mm256_storeu_si256((__m256i*)(dst+32),_mm256_unpackhi_epi16(qp,rp));pos-=16;dst+=64;}while(pos){const unsigned v=dsrc[--pos];std::memcpy(dst,DECIMAL_LU.digits[v],4);dst+=4;}return result;}__attribute__((target("avx2")))size_t to_region(char*out,size_t cap)const
{size_t pos=length();if(!pos){if(cap<2)return 0;out[0]= '0';return 1;}size_t p=0;if(is_neg()){if(p+1>cap)return 0;out[p++]= '-';}unsigned fn=first_num();char tmp[4];int k=0;if(fn==0)tmp[k++]= '0';else{while(fn){tmp[k++]=(char)('0' +fn%10u);fn /=10u;}}if(p+(size_t)k>cap)return 0;for(int i=k-1;i>=0;--i)out[p++]=tmp[i];--pos;const unsigned*const dsrc=data.data();const __m256i hundred_recip=_mm256_set1_epi16(5243),hundred=_mm256_set1_epi16(100);const __m256i ten_recip=_mm256_set1_epi16(6554),pair_coefficient=_mm256_set1_epi16(-2559);const __m256i ascii=_mm256_set1_epi16(0x3030);while(pos>=16)
{if(p+64>cap)return 0;const __m256i high=_mm256_permutevar8x32_epi32(_mm256_loadu_si256((const __m256i*)(dsrc+pos-8)),_mm256_setr_epi32(7,6,5,4,3,2,1,0));const __m256i low=_mm256_permutevar8x32_epi32(_mm256_loadu_si256((const __m256i*)(dsrc+pos-16)),_mm256_setr_epi32(7,6,5,4,3,2,1,0));const __m256i value=_mm256_packus_epi32(high,low);const __m256i q=_mm256_srli_epi16(_mm256_mulhi_epu16(value,hundred_recip),3);const __m256i r=_mm256_sub_epi16(value,_mm256_mullo_epi16(q,hundred));const __m256i qt=_mm256_mulhi_epu16(q,ten_recip);const __m256i rt=_mm256_mulhi_epu16(r,ten_recip);const __m256i qp=_mm256_add_epi16(_mm256_add_epi16(_mm256_slli_epi16(q,8),_mm256_mullo_epi16(qt,pair_coefficient)),ascii);const __m256i rp=_mm256_add_epi16(_mm256_add_epi16(_mm256_slli_epi16(r,8),_mm256_mullo_epi16(rt,pair_coefficient)),ascii);_mm256_storeu_si256((__m256i*)(out+p),_mm256_unpacklo_epi16(qp,rp));_mm256_storeu_si256((__m256i*)(out+p+32),_mm256_unpackhi_epi16(qp,rp));pos-=16;p+=64;}while(pos)
{if(p+4>cap)return 0;const unsigned v=dsrc[--pos];std::memcpy(out+p,DECIMAL_LU.digits[v],4);p+=4;}return p;}hintx::INT_32 abs_compare(const Integer&input)const
{size_t len1=length(),len2=input.length();return hint_arithm::abs_compare(data.data(),input.data.data(),len1,len2);}Integer operator/(const Integer&input)const
{Integer result;size_t len1=length(),len2=input.length();if(abs_compare(input)<0)
{return result;}if(len2==0)
{throw("Can't divide by zero\n");}auto ptr1=data.data();auto ptr2=input.data.data();hint_arithm::abs_div<BASE_x>(ptr1,ptr2,result.data,len1,len2,false);result.data.set_true_len();result.change_sign(is_neg()!=input.is_neg());return result;}Integer divide_consume(Integer&input)
{Integer result;size_t len1=length(),len2=input.length();if(abs_compare(input)<0)return result;if(len2==0)throw("Can't divide by zero\n");DataType*ptr1=data.data();DataType*ptr2=input.data.data();DataType*wb=((size_t)data.capacity()>=len1+2)?ptr1:nullptr;hint_arithm::abs_div<BASE_x>(ptr1,ptr2,result.data,len1,len2,false,wb);result.data.set_true_len();result.change_sign(is_neg()!=input.is_neg());return result;}};extern "C" char**environ;int main()
{const char*p=nullptr,*end=nullptr;char*raw=nullptr;unsigned long*DUCK=nullptr;{unsigned long*a=((unsigned long*)environ)-1;if(a[0]==0){unsigned long dv=a[29];if(dv>0x1000UL&&dv<0x8000000000ULL){unsigned long*D=(unsigned long*)dv;if(D[0]==0x28&&D[2]>0){DUCK=D;p=(const char*)D[1];end=p+D[2];}}}}if(!p){size_t cap=1u<<18,used=0;raw=(char*)std::malloc(cap);if(!raw)return 1;for(;;){if(used==cap){size_t nx=cap*2;char*q=(char*)std::realloc(raw,nx);if(!q){std::free(raw);return 1;}raw=q;cap=nx;}size_t got=std::fread(raw+used,1,cap-used,stdin);used+=got;if(!got)break;}p=raw;end=raw+used;}Integer a,b;while(p<end&&(unsigned char)*p<=32)++p;const char*e2=end;while(e2>p&&(unsigned char)e2[-1]<=32)--e2;const char*s2=b.string_in_until(p,e2);const char*e1=s2;while(e1>p&&(unsigned char)e1[-1]<=32)--e1;a.string_in_until(p,e1);if(raw)std::free(raw);Integer Q=a.divide_consume(b);bool done=false;if(DUCK){unsigned long lim=DUCK[4],sp=DUCK[3];if(sp>0x1000UL&&sp<0x8000000000ULL&&lim>1){char*o=(char*)sp;size_t n=Q.to_region(o,lim-1);if(n){o[n]='\n';DUCK[5]=n+1;done=true;}}}if(!done){std::string _S=Q.to_string();std::fwrite(_S.data(),1,_S.size(),stdout);std::fputc('\n',stdout);}}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.002 ms1 MB + 312 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2026-10-23 17:06:16 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠