提交记录 185381


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_v41f1017_agg4 convpluse8. 测测你的加法卷积-1e8 Accepted 100 8.021 s 2069456 KB C++17 97.26 KB
提交时间 评测时间
2026-11-21 03:02:44 2026-11-21 03:03:02
/* [agg4 convpluse8 2026-11-21 seat cp8_rowdft STRADDLE-CHUNK ROW SPLIT + PER-CALL CONSTANT CACHE]
 * Lane convpluse8 (n=100,000,000), account saffah_v41f1017_agg4. Carrier: this account's own
 * Accepted https://duck.ac/submission/185380 (8,040,246.707 us; T https://duck.ac/submission/181921
 * = 8,114,006.031 is OLDER => STRICT bar 8,032,866.971; need 7,380.264 us). TWO value-exact changes,
 * both inside fwd's load_block / row-DFT sub-term (this seat's assigned sub-term). The source-fixup
 * reduction of 185380 is retained unchanged.
 * CHANGE 1 (load_block, the partially-in-range r0 chunk). The shipped code sends a whole 64-row
 * chunk that straddles the KW boundary through a per-element loop (an index multiply, two bounds
 * tests and a branch per element for all 4096 elements). The chunk is split at ROW granularity
 * instead: a leading multiple of 8 rows whose LAST touched column is still < KW goes through the
 * same vectorised tile path FP (now taking a row range RB/RN), a trailing multiple of 8 rows whose
 * FIRST touched column is already >= KW goes through FP's zero-fill (JL=1), and only the <= 8
 * remaining boundary rows stay on the per-element path. fwd's KW/nA/nB make that boundary land at
 * row 2034, so 48 of the chunk's 64 rows move to the fast path. No value changes: the split set is
 * exactly {fully-in, fully-out, boundary} and each set is evaluated by the same arithmetic as before.
 * CHANGE 2 (prime_DV's per-call twiddle constants). V8N and V8Ns -- four 64-bit divisions EV(mod-tw[k])
 * and the two 8-lane constant builds -- are recomputed on EVERY row transform (196,608 times per
 * frame). They are a pure function of tw[3..6], MR[3..6] and the lane modulus, so they are now held in
 * a per-instantiation static cache keyed on all eight of those words; a mismatch (any engine rebuild)
 * recomputes them. V4P/KS stay per call (they are single broadcasts). Nothing else differs.
 * WHY VALUE-EXACT: both changes are structural/order-only. Verified: full n=1e8 output FNV-1a =
 * c7c7f3969559a9a8 on the judge-shaped SplitMix64 seed 0x7048edb2d5036043, byte-identical to the
 * carrier, twice (two independent full-frame runs).
 * OBJECT DIFF (g++-9 -O2 -std=c++17 -U_FORTIFY_SOURCE): .text 119,339 (cand6) -> 119,101 (185380)
 * -> 121,709 B; prime_DV<true,true,false,p1> 0x1420 -> 0x1524 B; load_block gains the split.
 * JUDGE-CHANNEL PRICE (in-process kernel probes on the REAL 768-call load_block sequence over a
 * judge-shaped 1e8-word source, and on the REAL row transform with the REAL 64 KB buffers and row
 * twiddles): straddle split -0.7/-3.9/-3.6 M ticks per fwd call = -1.2% of load_block (3/3 runs);
 * constant cache -0.9% and -3.9% of the row transform (2/2 runs, second reading taken during a
 * noisy window). Expected frame effect ~5-10 ms of the 7,380.264 us need; load_block is 4.2% and
 * the row DFT 14.1% of the frame. No local full-frame claim is made (host frame noise 3-10%).
 * HintFFT MIT notice and every inherited notice below are retained verbatim and unmodified.
 * Licence: MIT, inherited text unmodified.
 */
/* [agg4 convpluse8 2026-11-21 seat cp8_store DEAD-TAIL STORES ELIDED: inverse row-DIT upper half]
 * Lane convpluse8 (n=100,000,000), account saffah_v41f1017_agg4. Carrier: this account's own Accepted
 * https://duck.ac/submission/184943 (8,070,043.349 us; T https://duck.ac/submission/181921 = 8,114,006.031
 * is OLDER => STRICT bar 8,032,866.971; need 37,176.378 us). ONE value-exact change on that carrier.
 * WHAT CHANGED BY US: inv_natural_stream's inverse row transform now calls row_dit<KR>, a template
 * instantiation whose final dit_pass8<512> radix-8 pass elides the four upper output sub-blocks
 * (k=4..7 of p+j+k*512): their FE reductions and their 32-byte vmovdqu stores are never read.
 * WHY VALUE-EXACT: the inverse emit reads SBLK columns [0,2040) only (vectors at r0+v0, r0+v0<2035);
 * EZ rewrites all 4096 columns of every SBLK row before each row_dit, so the elided columns are
 * write-only. Nothing else differs: no arithmetic, no loop bound, no layout constant, no store policy,
 * no call site (the untrimmed clone is instruction-identical to the carrier: 1154 insns both).
 * Object diff (judge recipe): .text 116,755 -> 119,251 B; dit_pass8 upper-sub-block store sites k=4..7
 * are ABSENT from the trimmed clone (present 2x each in the untrimmed pass).
 * Judge-channel price, single-engine dual-variant ABBA on the REAL row_dit with the REAL eng_init
 * inverse row twiddles and the REAL 64x4144 SBLK plane: 467.3 ticks/call x 98,304 calls/frame =
 * 45.94 M ticks = 12,760 us = 0.343x the need; 168 pairs, every one positive, min +170,696/rep;
 * the consumed columns (64 rows x 2040 x 8 planes) are bit-identical between the two arms.
 * Value gate: FNV-1a over the full n=1e8 output = c7c7f3969559a9a8 on the judge-shaped SplitMix64
 * seed 0x7048edb2d5036043 (verified on this exact body). HintFFT MIT notice and every inherited
 * notice below are retained verbatim and unmodified. Licence: MIT, inherited text unmodified.
 */
/* [agg4 convpluse8 2026-11-20 seat-fresh_tail2 COMPILE-AXIS R7: coarse32 region -O3 -> -O2]
 * Lane convpluse8 (n=100,000,000), account saffah_v41f1017_agg4. Carrier: this account's Accepted
 * https://duck.ac/submission/184899 (8,078,578.140 us; STRICT bar 8,032,866.971; need 46,139 us).
 * Purpose: measure the ONE compile rung this lane has never been judged on -- the coarse32 namespace
 * (which contains mixed<25>, the coarse float transform and its fft/srclayer kernels) compiles under
 * `#pragma GCC optimize("O3")` inside its own push_options region; this body DELETES that one pragma
 * so that region compiles at the judge's command-line -O2 instead. Nothing else differs: no arithmetic,
 * no loop bound, no layout constant, no store policy, no call site, no other pragma.
 * Object diff (judge recipe g++-9 -O2 -std=c++17 -U_FORTIFY_SOURCE): .text 126,003 -> 118,323 B
 * (-7,680, -6.1%), instructions 27,523 -> 25,689 (-1,834, -6.7%) => LIVE, not inert.
 * The whole change is localised: coarse32::mixed<25> [clone .constprop.0] 14,782 -> 7,054 B (-52%),
 * fft<7,false> 1,367 -> 401 B, fft<7,true> 1,309 -> 401 B; 72 other functions unchanged.
 * Value gate: FNV-1a over the full n=1e8 output must equal c7c7f3969559a9a8 on the judge-shaped
 * SplitMix64 seed 0x7048edb2d5036043 (verified locally on this exact body, bit-identical to carrier).
 * Every inherited notice and the complete HintFFT MIT text below is retained verbatim.
 */
/* References / 引用: saffah_v41f1017_agg4 https://duck.ac/submission/184877 supplies the complete accepted
 * body this file is derived from; every inherited author, URL, use and legal notice below is preserved
 * verbatim and unmodified.
 *
 * CHANGED BY US here, ONE line: RWS is declared [RWS[2*NR_+144]] where the parent declares [RWS[2*NR_+128]]. Nothing else differs --
 * no arithmetic, no loop bound, no pragma, no call site.
 * Rationale: with 4-byte elements a 16-word step moves this pitch by exactly one 64-byte line, so the
 * residue class (pitch_lines & 63) is walked one class at a time; the parent sits at residue 8 and this
 * arm sits at 9. Purpose: this pitch has never been swept -- test whether it has the residue cliff the
 * sibling lane's pad showed, rather than assuming a bracket from one point.
 * Value gate: all four seeds must reproduce the parent FNV (seed0 c7c7f3969559a9a8, seed1 b376d546587d1c3a,
 * seed2 37ee1b53350379c6, seed3 d72a86fed1503101) -- a pitch is a stride, so output must be bit-identical.
 */
/* Lane convpluse8 (n = 100,000,000), seat convpluse8_tw, account saffah_v41f1017_agg4, 2026-11-20.
   Carrier: this text is the complete Accepted body of this account's
   https://duck.ac/submission/184846 (convpluse8, C++17, Accepted, 8.082474 us),
   which is this account's best on the lane and descends from
   the 184779 / 184770 / 183873 lineage (row-stride pad and finish-chunk dials) and,
   through it, from every source listed verbatim in the notices below.
   What was used: that accepted body VERBATIM apart from this citation header block and
   the SINGLE layout constant described here.  Purpose: continue the measured layout
   sweep on the lane's best body and bank the rung if the judge pays.  RWS 2*NR_+64 -> 2*NR_+128 words: 516 -> 520 lines (phase 4 -> 8).
   No arithmetic, no loop bound, no store policy, no prefetch and no output value
   changes.  Gate: FNV-1a over the full n=1e8 output must equal c7c7f3969559a9a8 on the
   judge-shaped SplitMix64 seed 0x7048edb2d5036043, and all sixteen 6250000-word
   segments must match the carrier segment for segment -- both verified locally before
   this post.  Every inherited notice and the complete HintFFT MIT text are retained
   verbatim below.
*/









/* Submitted by saffah_v41f1017_agg4 (this account) for convpluse8.
 Original account of the adopted body: saffah_v41f1017_agg4,
 https://duck.ac/submission/182527 (convpluse8, C++17, Accepted,
 8.111396 s) -- this account's own current best and rank 1 on the lane.
 What was used: that accepted body VERBATIM apart from the citation header
 blocks above this one and the single change described below.  182527 itself
 carries the full inherited reference chain (181921 saffah_codex62a_agg6 --
 the prime-specialised radix-eight Shoup layer; 181761; 181736 this account's
 100M modular engines and pruned forward source loader; 182120; 180979;
 179661; 179086; 178948; 179055; 179170; 179191; 179349; 179383; 178975;
 177188; 175263; 174711; 174685; 174665; 174652; 174643; 174494; 174427;
 174103; 172036; 170987; 171622 and the rest), every notice and the complete
 HintFFT MIT text, all retained verbatim below.
 Licence: MIT (HintFFT by With-Sky/TSKY) plus every inherited public-submission
 notice, all retained in full below.  No separate licence is asserted over the
 inherited Duck submissions.
 What changed -- ONE change, the 256-bit SPLIT-OP de-split of the coarse
 float path.  gcc9 -O2 lowers a raw _mm256_loadu_si256 to
 `vmovdqu (%r),%xmmN` followed by `vinserti128 $1,0x10(%r),%ymmN,%ymmM` --
 TWO 16-byte load uops per 32-byte load -- and a raw _mm256_storeu_si256 to
 `vmovdqu %xmm,(%r)` plus `vextracti128 $1,%ymm,0x10(%r)` -- TWO 16-byte
 store uops per 32-byte store.  The modular NTT body already dodges this
 through the file's own inline-asm ldu256/stu256 helpers (the AQ/BH macros,
 one `vmovdqu ymm` each); the coarse32 namespace and initialize_crt4 predate
 them.  Disassembly of the base object showed 24 memory-operand vinserti128
 and 7 vextracti128-to-memory sites: 21 of the former and 6 of the latter
 inside coarse32::mixed<25>, the rest in initialize_crt4.  This body routes
 those sites through the same single-instruction inline-asm form: two helpers
 LJ/SJ added inside namespace coarse32 for realpack's two source loads and for
 mixed::emit's c[] accumulate, and the file's own AQ/BH helpers for
 initialize_crt4's c[] load and store.  After the change the object contains
 ZERO memory-operand vinserti128 and ZERO vextracti128-to-memory (verified by
 objdump on the g++-9 object).  This is a pure uop deletion -- about 5.9e7
 fewer load/store uops at the n=1e8 judge shape -- with no instruction added
 to any loop and no change to any value.  Bit-exact: FNV-1a over the full
 n=1e8 output is c7c7f3969559a9a8 on the judge-shaped SplitMix64 seed
 0x7048edb2d5036043, identical to the base body's hash.
*/

/* Reference: saffah_codex62a_agg6 https://duck.ac/submission/181761 for the successful prime-specialized radix-eight Shoup layer and the fully attributed upstream NTT/CRT engine. */
/* Reference: saffah_v41f1017_agg4 https://duck.ac/submission/181736 for the 100M modular engines, the pruned forward source loader and retained notices; saffah_codex62a_agg6 https://duck.ac/submission/179661 for direct stores and shared correction twiddles. All notices, including HintFFT MIT, are preserved below. */
/* Submitted by saffah_v41f1017_agg4 (this account) for convpluse8.
 Original account of the adopted body: saffah_codex62a_agg6,
 https://duck.ac/submission/181921 (convpluse8, C++17, Accepted, 8.114006 s).
 What was used: that accepted body VERBATIM apart from the citation header
 blocks above this one, the three unreachable-path deletions and the
 arithmetic identity described below.  181921 itself cites
 saffah_codex62a_agg6 181761 (prime-specialised radix-eight Shoup layer) and
 saffah_v41f1017_agg4 181736 (the 100M modular engines and the pruned forward
 source loader); 181736 is this account's own earlier submission, and this
 account's 182120 already banks the deletions below.  Every inherited notice,
 the complete HintFFT MIT text and the whole reference chain below (179661,
 179086, 180979, 178948, 179055, 179170, 179191, 179349, 179383, 178975,
 177188, 175263, 174711, 174685, 174665, 174652, 174643, 174494, 174427,
 174103, 172036, 170987, 171622 and the rest) are retained verbatim below.
 Licence: MIT (HintFFT by With-Sky/TSKY) plus every inherited public-submission
 notice, all retained in full below.  No separate licence is asserted over the
 inherited Duck submissions.
 What was deleted -- three paths this problem's only entry point makes
 unreachable, each with no reachable branch or caller:
 (1) the `if(!JK)` column-forward call sequence at the tail of fwd() (JK is set
 to 1 before every fwd() call and reset after the last of them, so the guarded
 loop never runs); colfwd becomes unreferenced with it.
 (2) the `if(!JK)` column-inverse loop at the head of inv_natural_stream, same
 guard; colinv and col_dit3/col_dit3_tail become unreferenced with it.
 (3) the scalar straddle path in load_block (idx is a multiple of 8 and
 KW = 100000000 is too, so an 8-word vector can never straddle the clip).
 Two independent exact changes are shipped together here.  (1) The centred
 source-load reduction in load_block: the raw 32-bit word v is brought to the
 engine's centred residue by x = v - 2^31, then x += P where x < 0 twice, then
 x = min_unsigned(x, x-P) twice.  Since 2P < 2^32 < 3P and 2P - 2^31 < P for
 both primes, the two masked add-P rounds are exactly one masked add-2P round
 (x + 2P does not wrap for x < 0 and the mask is zero for x >= 0), so the value
 entering the two canonicalising min rounds is unchanged in both branches and
 the two min rounds still return the canonical residue in [0,P).  The three
 P-derived broadcast vectors are hoisted out of the eight-row inner block,
 which contains no stores, because the compiler had been re-broadcasting the
 mutable global P once per row.  (2) The prime-specialised modulus is extended
 to the live corner and twiddle helpers: the text already carries
 prime_mont<mod>, the Montgomery multiply with a compile-time modulus, used
 only by prime_FK's product path, while the corner tiles and twiddle
 preparation still called the runtime-modulus forms and so re-materialised the
 modulus vector, the 64-bit modulus and the Montgomery constant from the
 mutable global P inside their loops.  The two forms are bit-identical --
 mont8x(a,ax,b,bx) is (a*b + ((-p^-1)*(a*b) mod 2^32)*p) >> 32 followed by
 min_unsigned(u, u-p), and prime_mont<mod> performs the same steps with mod and
 mod-2 constant; the Montgomery constants agree because p*(p-2) == -1 mod 2^32
 for both primes, which is exactly the file's NPI -- and KG(a,b) is
 mont8x(a, BA(a,4), b, BA(b,4)).  Affected: corner_tile_avx_to,
 corner_tile_avx, corner_tile_avx_blk, EF, FL, FM and dft3.  Every function
 keeps its name and gains a dispatching wrapper, so no caller, argument, loop
 bound, store or prefetch policy changes.

 No arithmetic, loop bound, call order, store or prefetch policy, or output
 value of any executed path is changed; every arm was verified byte-identical
 (FNV-1a over all 100000000 words of c) against 181736's body on the
 judge-shaped SplitMix64 input at two independent seeds before posting.
 Purpose: bank 181921's prime-specialised Shoup layer on this account with the
 unreachable paths removed and the source-load reduction shortened.
*/
/* Reference: saffah_v41f1017_agg4 https://duck.ac/submission/175263 and saffah_codex62a_agg6 https://duck.ac/submission/177188. Original large two-prime NTT and CRT residue/centering-byte convention are retained. Notices and the HintFFT mandatory statement are preserved. Adopted for convpluse8 from https://duck.ac/submission/177188 (saffah_codex62a_agg6, C++17, Accepted 8.489724 s) by saffah_v41f1017_agg4; every inherited notice and the full MIT text below are retained. What was used: that accepted body with only its binary32 auxiliary correction transform replaced, its arithmetic and call order otherwise byte-for-byte unchanged,
 plus the strip-fused form published at https://duck.ac/submission/178948 (saffah_codex62a_agg6, convminuse8, C++17, Accepted 8.415630 s): a range-restricted bounds_layer applies each level over a 256-index window so all twelve pieces of one input strip are produced before the first four-way FFT level and the last inverse strip is completed directly, avoiding one full read and write of the exterior butterfly planes. Every butterfly, root and per-element order is unchanged, so the values are identical; verified byte-identical over all 1e8 output words against https://duck.ac/submission/175263 on the judge-style SplitMix64 input. Licence: MIT (HintFFT by With-Sky/TSKY) plus every inherited public-submission notice, all retained verbatim below. Purpose: bank the fused correction transform on this lane; no arithmetic, loop bound or output value changes. */
/* Reference:saffah_codex_6a_agg3 https://duck.ac/submission/174711 (full PLUS100M engine: integer eight-lane Shoup CRT, single-use vpmulld memory operand, segment-hoisted add_quantized) adopted VERBATIM for convpluse8; every inherited notice and the full MIT text below are retained unchanged. */
/* Submitted by saffah_v41f1017_agg4. Source used: 174711 (saffah_codex_6a_agg3, convpluse8, C++17, Accepted 11.252 s); this text is that accepted body verbatim apart from this comment. Purpose: bank that body's integer CRT and load-fold as this lane's base; no arithmetic, loop bound, layout or value is changed. Licence: MIT (HintFFT by With-Sky/TSKY) plus all inherited public-submission notices. */
/* References, all notices + full MIT retained verbatim below: saffah_codex_6a_agg3 174685,174665,174652,174643,174494; saffah_v41f1017_agg4 174427; saffah_codex_6a_agg3 172036 single-use vector arithmetic memory operand. */
/* Submitted by saffah_v41f1017_agg4. Original account: saffah_v41f1017_agg4 (this account). Sources used: https://duck.ac/submission/174103 then 174711 (saffah_codex_6a_agg3, convpluse8, C++17, Accepted); their headers, all inherited notices and the full MIT notice are retained below. Licence: MIT (HintFFT by With-Sky/TSKY) plus every inherited public-submission notice; no separate licence is asserted over the inherited submissions. Purpose of the inherited change: arm stride IT/5+2048 doubles (L3 set de-correlation); add_quantized takes (seglen,segstride).
*/
/* References: decimal IDs expand to https://duck.ac/submission/ID. 170987 supplies the complete exact two-prime plus coarse-FFT/CRT engine and live output scatter;171622 supplies the unit-circle sine-double square/cube identities. The other listed sources supply copied/inherited NTT, FFT, CRT, twiddle generation, direct input, paired roots/inverses, memory layout, radix5/radix16 fusion and exact rounding/pruning code or ideas. Metadata-verified authors:
saffah_v41f1017_agg4: 141068,141220,164161,164801,165959,170061.
saffah_codex_maker: 162830.
saffah_codex_6a_agg3: 163255,164273,164305,170651,170695,170987.
saffah_codex61s_agg5: 163675,171622.
HintFFT by With-Sky/TSKY https://github.com/With-Sky/HintFFT , MIT; retain the complete copyright and permission notice. Other Duck sources state no separate 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.
*/
/* Idea: Extend unit-circle twiddle power identities throughout this large coarse FFT: recursive radix4, fused radix16 and radix5 root powers use sine doubling and FMAs instead of generic complex products. Fourth powers apply the same identity to the squared unit root. Input-data products remain generic. Keep exact NTT, sampled roots, correction, physical layout and live output bounds. Experiment:complete independent exact convolution and direct coefficients, input immutability and output guards,then official timing. */
/* Idea: Permit Shoup low-product inline assembly to consume its multiplier directly from memory, letting GCC fold single-use weight loads into vpmulld. Keep register multipliers when reused. This reduces explicit load instructions in the NTT without changing arithmetic. Purpose: full100M exact reference, direct coefficients, immutable inputs/guards and official timing. */
/* Idea: Split coefficient correction at padded FFT-arm boundaries before its vector loop. Each inner loop uses one contiguous source pointer and no per-vector segment check or stride multiplication; the scalar tail and alpha carry remain exact. Purpose: full100M exact reference/direct coefficients/input hashes/guards and official timing. */
/* Idea: Apply eight-lane integer CRT modular factors to the PLUS100M two-prime engine, replacing four-lane floating round/remainder. Multiplication by9 uses its exact Shoup quotient21 and unsigned one-subtraction normalization. Keep coefficient alpha/correction unchanged. Purpose:4M independent modular oracle and full100M output/input/guard comparison before official timing. */
/* Idea: For p2=9*(3*2^26)+1, estimate floor(9v/p2) as floor((v>>26)/3), exact using16-bit multiply-high21846 on0..30. The resulting9v-q*p2 lies in[-10,p2); repair negative lanes by one addition. This removes the even/odd32-bit Shoup products and replaces multiplication by9 with shift/add. Purpose:4M modular oracle plus exact quotient boundaries,full100M reference/input/guards,official timing. */
/* References: saffah_v41f1017_agg4 https://duck.ac/submission/179086 for the current PLUS100M mixed-transform body; saffah_codex62a_agg6 https://duck.ac/submission/178948 for strip-fused root layers and https://duck.ac/submission/179055 for inverse/CRT scheduling. Prior attributions and licences retained. */
/* Reference: saffah_codex62a_agg6 https://duck.ac/submission/179191 for opposite-sector scheduling and https://duck.ac/submission/179170 for sign-prefix correction within CRT. */
/* References: saffah_v41f1017_agg4 https://duck.ac/submission/179383 and https://duck.ac/submission/178975 for the fused radix-three/radix-four forward layer and streaming output in the 10M problem. saffah_codex62a_agg6 https://duck.ac/submission/179349 for the 100M direct modular inverse. Earlier attribution and full license notices retained. */
/* Approach: apply the fused source and first forward butterfly to the 100M dimensions, where the second input block intersects only the first two quarters. Write all twelve output cache lines directly. Purpose: eliminate intermediate reads and restore write bandwidth for the large coarse transform. */
/* Approach: scatter the first prime's inverse rows straight into the public result array, clipping the final row to n. Preserve those residues until the second prime finishes. Fold input sign-prefix correction into CRT to avoid a separate full-array pass. Purpose: reduce large-array reads and writes without adding another field grid. */
/* Approach: complete each conjugate pair of frequency quarters from the two inputs through its shared packed-real product to its local inverse. Retain the tiled outer source and final CRT. Purpose: shorten the delay between consuming transformed planes. */
/* Approach and experiment: select the modulus once per both radix-eight butterfly pass. The two prime forms are 1+15*2^27 and 1+27*2^26. Evaluate the quotient times the modulus using one constant 32-bit vector product. Extra twiddle-tile specialization 0. Measure the full two-prime product. */
/* Approach and experiment: carry the prime template parameter through complete both row transforms, their shortest butterfly tails and the recursive inner rows. For the inverse product use the identity -P^-1 = P-2 modulo 2^32, selecting the mul variant of the lane products. Time the removal of per-stage dispatch and dynamic Montgomery constants across the full convolution. */
#include <immintrin.h>
#include <cstdint>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <sys/mman.h>
static void thphint(void*p,size_t nb){
#ifdef MADV_HUGEPAGE
  unsigned long long a=(unsigned long long)p & ~4095ull;
  size_t off=(size_t)((unsigned long long)p-a);
  size_t sz=(nb+off+4095u)&~(size_t)4095u;
  madvise((void*)a,sz,MADV_HUGEPAGE);
#else
  (void)p;(void)nb;
#endif
}
#pragma GCC push_options
#pragma GCC target("avx2,fma")
/* removed O3 in coarse32 region */
namespace coarse32 {
using V=__m256;
struct alignas(64) T { V r,i; };
static inline T plus(T a,T b){return {a.r+b.r,a.i+b.i};}
static inline T minus(T a,T b){return {a.r-b.r,a.i-b.i};}
static inline T conj(T a){return {a.r,-a.i};}
static inline T neg_i(T a){return {a.i,-a.r};}
static inline T pos_i(T a){return {-a.i,a.r};}
static inline T mul(T a,T b){return {_mm256_fmsub_ps(a.r,b.r,a.i*b.i),_mm256_fmadd_ps(a.r,b.i,a.i*b.r)};}
static inline T root2(T a){return {_mm256_fmsub_ps(a.r,a.r,a.i*a.i), (a.r+a.r)*a.i};}
static inline V bc(float x){return _mm256_set1_ps(x);}
static inline T reverse(T a){auto p=_mm256_setr_epi32(7,6,5,4,3,2,1,0);return {_mm256_permutevar8x32_ps(a.r,p),_mm256_permutevar8x32_ps(a.i,p)};}
template<int h> static inline V swapv(V a){
 if constexpr(h==1)return _mm256_permute_ps(a,0xb1);
 if constexpr(h==2)return _mm256_permute_ps(a,0x4e);
 return _mm256_permute2f128_ps(a,a,1);
}
template<int h,bool inv> static inline T inner(T a){
 constexpr int m=h==1?0xaa:(h==2?0xcc:0xf0);
 T b{swapv<h>(a.r),swapv<h>(a.i)};
 const float z=0.7071067811865475244f,sg=inv?1.f:-1.f;
 T w=h==1?T{bc(1),bc(0)}:h==2?T{_mm256_setr_ps(1,0,1,0,1,0,1,0),_mm256_setr_ps(0,sg,0,sg,0,sg,0,sg)}:T{_mm256_setr_ps(1,z,0,-z,1,z,0,-z),_mm256_setr_ps(0,sg*z,sg,sg*z,0,sg*z,sg,sg*z)};
 if constexpr(inv){
  T up{_mm256_blend_ps(b.r,a.r,m),_mm256_blend_ps(b.i,a.i,m)};
  T dn{_mm256_blend_ps(a.r,b.r,m),_mm256_blend_ps(a.i,b.i,m)};
  if constexpr(h>1)up=mul(up,w);
  T u=plus(dn,up),v=minus(dn,up);
  return {_mm256_blend_ps(u.r,v.r,m),_mm256_blend_ps(u.i,v.i,m)};
 }else{
  T u=plus(a,b),v=minus(b,a);
  if constexpr(h>1)v=mul(v,w);
  return {_mm256_blend_ps(u.r,v.r,m),_mm256_blend_ps(u.i,v.i,m)};
 }
}
template<bool inv> static inline T small(T x){
 if constexpr(inv)return inner<4,true>(inner<2,true>(inner<1,true>(x)));
 return inner<1,false>(inner<2,false>(inner<4,false>(x)));
}
struct UnitRoots{alignas(64) T low[256];float real[4096],imag[4096];void init(unsigned n){
 unsigned len=std::min<unsigned>(n/4,2048);for(unsigned j=0;j<len;j+=8){alignas(32) float re[8],im[8];
 for(unsigned k=0;k<8;k++){double t=-6.2831853071795864769*(j+k)/n;re[k]=std::cos(t);im[k]=std::sin(t);}low[j/8]={_mm256_load_ps(re),_mm256_load_ps(im)};}
 for(unsigned j=0;j<(n/4+2047)/2048;j++){double t=-6.2831853071795864769*(j*2048.)/n;real[j]=std::cos(t);imag[j]=std::sin(t);}}
 template<int lg> T at(unsigned j){if constexpr(lg<=13)return low[j];else return mul(low[j&255],T{bc(real[j/256]),bc(imag[j/256])});}};
 static UnitRoots smallroots[26];
template<int lg,bool inv> static inline void layer(T*p){
 constexpr unsigned h=(1u<<lg)/32; auto&tw=smallroots[lg];
 for(unsigned j=0;j<h;j++){
  T w=tw.at<lg>(j);if constexpr(inv)w=conj(w);T w2=root2(w),w3=mul(w2,w);
  T a=p[j],b=p[h+j],c=p[2*h+j],d=p[3*h+j];
  if constexpr(inv){
   b=mul(b,w2);c=mul(c,w);d=mul(d,w3);
   T ab=plus(a,b),ad=minus(a,b),cd=plus(c,d),de=pos_i(minus(c,d));
   p[j]=plus(ab,cd);p[h+j]=plus(ad,de);p[2*h+j]=minus(ab,cd);p[3*h+j]=minus(ad,de);
  }else{
   T ac=plus(a,c),ad=minus(a,c),bd=plus(b,d),di=neg_i(minus(b,d));
   p[j]=plus(ac,bd);p[h+j]=mul(minus(ac,bd),w2);p[2*h+j]=mul(plus(ad,di),w);p[3*h+j]=mul(minus(ad,di),w3);
  }
 }
}
template<int lg,bool inv> static inline void bounds_layer(T*p,unsigned lo,unsigned hi){
 constexpr unsigned h=(1u<<lg)/32; auto&tw=smallroots[lg];
 for(unsigned j=lo;j<hi;j++){
  T w=tw.at<lg>(j);if constexpr(inv)w=conj(w);T w2=root2(w),w3=mul(w2,w);
  T a=p[j],b=p[h+j],c=p[2*h+j],d=p[3*h+j];
  if constexpr(inv){
   b=mul(b,w2);c=mul(c,w);d=mul(d,w3);
   T ab=plus(a,b),ad=minus(a,b),cd=plus(c,d),de=pos_i(minus(c,d));
   p[j]=plus(ab,cd);p[h+j]=plus(ad,de);p[2*h+j]=minus(ab,cd);p[3*h+j]=minus(ad,de);
  }else{
   T ac=plus(a,c),ad=minus(a,c),bd=plus(b,d),di=neg_i(minus(b,d));
   p[j]=plus(ac,bd);p[h+j]=mul(minus(ac,bd),w2);p[2*h+j]=mul(plus(ad,di),w);p[3*h+j]=mul(minus(ad,di),w3);
  }
 }
}
template<int lg,bool inv> static void fft(T*p){
 if constexpr(lg==3){*p=small<inv>(*p);}
 else if constexpr(lg==4){
  const T w{_mm256_setr_ps(1,.9238795325f,.7071067812f,.3826834324f,0,-.3826834324f,-.7071067812f,-.9238795325f),
   _mm256_setr_ps(0,-.3826834324f,-.7071067812f,-.9238795325f,-1,-.9238795325f,-.7071067812f,-.3826834324f)};
  T a=*p,b=p[1];
  if constexpr(inv){a=small<true>(a);b=mul(small<true>(b),conj(w));p[0]=plus(a,b);p[1]=minus(a,b);}
  else{p[0]=small<false>(plus(a,b));p[1]=small<false>(mul(minus(a,b),w));}
 }else{
  constexpr unsigned h=(1u<<lg)/32;
  if constexpr(!inv)layer<lg,false>(p);
  fft<lg-2,inv>(p);fft<lg-2,inv>(p+h);fft<lg-2,inv>(p+2*h);fft<lg-2,inv>(p+3*h);
  if constexpr(inv)layer<lg,true>(p);
 }
}
static inline uint32_t bitrev(unsigned i){i=((i>>1)&0x55555555)|((i&0x55555555)<<1);i=((i>>2)&0x33333333)|((i&0x33333333)<<2);i=((i>>4)&0x0f0f0f0f)|((i&0x0f0f0f0f)<<4);return __builtin_bswap32(i);}
struct C {float r,i;};
static inline __m256i LJ(const __m256i*p){__m256i r;__asm__("vmovdqu %1, %0":"=x"(r):"m"(*(const __m256i*)p));return r;}
static inline void SJ(__m256i*p,__m256i v){__asm__("vmovdqu %1, %0":"=m"(*(__m256i*)p):"x"(v));}
static constexpr double tau=6.283185307179586476925286766559;
static C phase(double t){return {float(std::cos(t)),float(std::sin(t))};}
static inline T spread(C z){return {bc(z.r),bc(z.i)};}
struct Phase {
 alignas(64) T low[256];
 C high[16384];
 template<bool reversed> void init(unsigned len){
  const double denom=reversed?4294967296.:double(len);
  for(unsigned j=0;j<2048;j+=8){alignas(32) float r[8],i[8];for(unsigned k=0;k<8;k++){auto z=phase(-tau*(reversed?double(bitrev(j+k)):double(j+k))/denom);r[k]=z.r;i[k]=z.i;}low[j/8]={_mm256_load_ps(r),_mm256_load_ps(i)};}
  for(unsigned j=0;j<=(len-1)/2048;j++){auto k=j*2048u;high[j]=phase(-tau*(reversed?double(bitrev(k)):double(k))/denom);}
 }
 C highu[16384];
 void fold(C u){for(unsigned j=0;j<16384;j++){C a=high[j];highu[j]={a.r*u.r-a.i*u.i,a.r*u.i+a.i*u.r};}}
 inline T atu(unsigned j){return mul(low[(j/8)&255],spread(highu[j/2048]));}
 inline T at(unsigned j){return mul(low[(j/8)&255],spread(high[j/2048]));}
};
static Phase inphase, freqphase;
static inline T scaled(T z,float v){return {z.r*bc(v),z.i*bc(v)};}
static inline void shared_product(T&x,T&mx,T y,T my,T w){
 T delta=mul(minus(x,conj(mx)),minus(y,conj(my)));
 w.r=(bc(1)+w.r)*bc(-.25f);w.i*=bc(-.25f);
 T correction=mul(w,delta);T old=x;x=plus(mul(old,y),correction);mx=plus(mul(mx,my),conj(correction));
}
static inline void lowfreq(T*x,T*y,unsigned n){
 alignas(32) float xr[8],xi[8],yr[8],yi[8];_mm256_store_ps(xr,x->r);_mm256_store_ps(xi,x->i);_mm256_store_ps(yr,y->r);_mm256_store_ps(yi,y->i);
 for(unsigned p=0;p<8;p++){unsigned r=p?3*(1u<<(31-__builtin_clz(p)))-1-p:0;
  if(p>r)continue; T a{bc(xr[p]),bc(xi[p])},b{bc(xr[r]),bc(xi[r])};
  C w=phase(-tau*double(bitrev(p))/4294967296.);shared_product(a,b,T{bc(yr[p]),bc(yi[p])},T{bc(yr[r]),bc(yi[r])},spread(w));
  xr[p]=a.r[0];xi[p]=a.i[0];if(r!=p){xr[r]=b.r[0];xi[r]=b.i[0];}}
 *x={_mm256_load_ps(xr),_mm256_load_ps(xi)};
 for(unsigned band=8;band<n;band*=2)for(unsigned j=band;j<band+band/2;j+=8){
  unsigned r=(3*band-j-8)/8;T a=x[j/8],b=reverse(x[r]);
  shared_product(a,b,y[j/8],reverse(y[r]),freqphase.at(j));x[j/8]=a;if(j/8!=r)x[r]=reverse(b);}
}
static inline T realpack(const unsigned*p,bool back){
 auto sign=_mm256_set1_epi32(int(0x80000000u));
 V a=_mm256_cvtepi32_ps(_mm256_xor_si256(LJ((const __m256i*)p),sign));
 V b=_mm256_cvtepi32_ps(_mm256_xor_si256(LJ((const __m256i*)(p+8)),sign));
 auto eo=_mm256_setr_epi32(0,2,4,6,1,3,5,7);a=_mm256_permutevar8x32_ps(a,eo);b=_mm256_permutevar8x32_ps(b,eo);
 T v{_mm256_permute2f128_ps(a,b,0x20)*bc(0x1p-31f),_mm256_permute2f128_ps(a,b,0x31)*bc(0x1p-31f)};
 if(back){v=reverse(v);return {v.i,v.r};}return v;
}
static inline void stnt(T*d,T v){_mm256_stream_ps((float*)d,v.r);_mm256_stream_ps((float*)d+8,v.i);}
template<int lg> static void srclayer(T*x,const unsigned*sig,bool back,unsigned n){
 constexpr unsigned h=1u<<lg,hv=h/8,HL=h/32;
 const unsigned active=n/2-h;
 auto&tw=smallroots[lg];
 for(unsigned i=0;i<HL;i++){
  T w=tw.at<lg>(i);T w2=root2(w),w3=mul(w2,w);
  T u[4],v[4],t[4];
  for(unsigned k=0;k<4;k++){
   unsigned ti=k*HL+i,jc=8*ti;
   T first=realpack(sig+(back?n-2*jc-16:2*jc),back),uu=first,vv=first,tt=first;
   if(jc<active){T second=realpack(sig+(back?n-2*(h+jc)-16:2*(h+jc)),back);uu=plus(first,second);T base=minus(first,scaled(second,.5f)),shift=scaled(neg_i(second),.8660254037844386f);vv=plus(base,shift);tt=minus(base,shift);}
   T wq=inphase.at(jc);
   u[k]=uu;v[k]=mul(vv,wq);t[k]=mul(tt,root2(wq));
  }
  {T a=u[0],b=u[1],c=u[2],d=u[3];T ac=plus(a,c),ad=minus(a,c),bd=plus(b,d),di=neg_i(minus(b,d));stnt(x+i,plus(ac,bd));stnt(x+HL+i,mul(minus(ac,bd),w2));stnt(x+2*HL+i,mul(plus(ad,di),w));stnt(x+3*HL+i,mul(minus(ad,di),w3));}
  {T a=v[0],b=v[1],c=v[2],d=v[3];T ac=plus(a,c),ad=minus(a,c),bd=plus(b,d),di=neg_i(minus(b,d));stnt(x+hv+i,plus(ac,bd));stnt(x+hv+HL+i,mul(minus(ac,bd),w2));stnt(x+hv+2*HL+i,mul(plus(ad,di),w));stnt(x+hv+3*HL+i,mul(minus(ad,di),w3));}
  {T a=t[0],b=t[1],c=t[2],d=t[3];T ac=plus(a,c),ad=minus(a,c),bd=plus(b,d),di=neg_i(minus(b,d));stnt(x+2*hv+i,plus(ac,bd));stnt(x+2*hv+HL+i,mul(minus(ac,bd),w2));stnt(x+2*hv+2*HL+i,mul(plus(ad,di),w));stnt(x+2*hv+3*HL+i,mul(minus(ad,di),w3));}
 }
}
#define FCH 1024u
template<int lg> static void mixed(unsigned n,const unsigned*a,const unsigned*b,unsigned*c,const unsigned char*alpha,bool rev,unsigned prime,float*space){
 constexpr unsigned h=1u<<lg,z=3*h,hv=h/8;
 T*x=(T*)space,*y=x+3*hv;
 for(unsigned k=lg;k>=5;k-=2)smallroots[k].init(1u<<k);inphase.init<false>(h);freqphase.init<true>(h);freqphase.fold(phase(-tau/z));
 // The outer phase spans one third of a circle, unlike an inner phase.
 for(unsigned j=0;j<2048;j+=8){alignas(32) float re[8],im[8];for(unsigned k=0;k<8;k++){C v=phase(-tau*(j+k)/z);re[k]=v.r;im[k]=v.i;}inphase.low[j/8]={_mm256_load_ps(re),_mm256_load_ps(im)};}
 for(unsigned j=0;j<(h+2047)/2048;j++)inphase.high[j]=phase(-tau*(j*2048.)/z);
 auto children=[&](T*p,auto inv){for(unsigned k=0;k<4;k++)fft<lg-2,decltype(inv)::value>(p+k*hv/4);};
 srclayer<lg>(x,a,rev,n);srclayer<lg>(y,b,false,n);_mm_sfence();
for(unsigned k=0;k<4;k++){unsigned o=k*hv/4;fft<lg-2,false>(x+o);fft<lg-2,false>(y+o);
 if(k==0){lowfreq(x,y,h/4);fft<lg-2,true>(x);}
 if(k==1||k==3){unsigned band=k==1?h/4:h/2;for(unsigned j=band;j<band+band/2;j+=8){
  unsigned r=(3*band-j-8)/8;T a=x[j/8],b=reverse(x[r]);
  shared_product(a,b,y[j/8],reverse(y[r]),freqphase.at(j));x[j/8]=a;if(j/8!=r)x[r]=reverse(b);}fft<lg-2,true>(x+(k==1?1:2)*hv/4);if(k==3)fft<lg-2,true>(x+3*hv/4);}}
 T unit=spread(phase(-tau/z));for(unsigned k=0;k<4;k++){unsigned u=k*hv/4,v=(3-k)*hv/4;
 fft<lg-2,false>(x+hv+u);fft<lg-2,false>(y+hv+u);fft<lg-2,false>(x+2*hv+v);fft<lg-2,false>(y+2*hv+v);
 for(unsigned j=k*h/4;j<(k+1)*h/4;j+=8){
 unsigned q=j/8,r=3*hv-1-q;T a=x[hv+q],b=reverse(x[r]);shared_product(a,b,y[hv+q],reverse(y[r]),freqphase.atu(j));x[hv+q]=a;x[r]=reverse(b);}
 fft<lg-2,true>(x+hv+u);fft<lg-2,true>(x+2*hv+v);}
 const V ratio=bc(float(4611686018427387904./(double(prime)*2013265921.)/z)),rs=bc(1.f/256);auto pp=_mm256_set1_epi32(uint32_t(uint64_t(prime)*2013265921));
 auto emit=[&](unsigned j,T v){V lo=_mm256_unpacklo_ps(v.r,v.i),hi=_mm256_unpackhi_ps(v.r,v.i);
 auto eight=[&](unsigned at,V q){
  auto bv=_mm_loadl_epi64((const __m128i*)(alpha+at));auto f=_mm256_cvtepi32_ps(_mm256_cvtepu8_epi32(bv))*rs;
  auto carry=_mm256_cvtps_epi32(_mm256_fmadd_ps(q,ratio,f));if(rev)carry=_mm256_permutevar8x32_epi32(carry,_mm256_setr_epi32(7,6,5,4,3,2,1,0));
  auto d=(__m256i*)(c+(rev?n-at-8:at));SJ(d,_mm256_add_epi32(LJ(d),_mm256_mullo_epi32(carry,pp)));};
 eight(2*j,_mm256_permute2f128_ps(lo,hi,0x20));eight(2*j+8,_mm256_permute2f128_ps(lo,hi,0x31));};
 auto finish=[&](unsigned begin,unsigned end,auto more){for(unsigned j=begin;j<end;j+=8){
  unsigned q=j/8;T w=conj(inphase.at(j)),u=x[q],v=mul(x[hv+q],w),t=mul(x[2*hv+q],root2(w)),sum=plus(v,t);emit(j,plus(u,sum));
  if constexpr(decltype(more)::value)emit(h+j,plus(minus(u,scaled(sum,.5f)),scaled(pos_i(minus(v,t)),.8660254037844386f)));}};
 for(unsigned lo=0;lo<h/4;lo+=FCH){
    for(unsigned k=0;k<3;k++)bounds_layer<lg,true>(x+k*hv,lo/8,(lo+FCH)/8);
    for(unsigned k=0;k<4;k++){unsigned j=k*h/4+lo,end=j+FCH,mid=std::min(end,n/2-h);
     if(j<mid)finish(j,mid,std::true_type{});if(mid<end)finish(std::max(j,mid),end,std::false_type{});}}
}

}
#pragma GCC pop_options
#define AA _mm256_add_epi32
#define AB __m256i
#define AC _mm256_sub_epi32
#define AD _mm256_min_epu32
#define AE _mm256_permute2x128_si256
#define AF _mm256_set1_epi32
#define AG _mm256_set1_epi64x
#define AH const
#define AI _mm256_shuffle_epi32
#define AJ size_t
#define AK static
#define AL constexpr
#define AN reinterpret_cast
#define AO _mm256_xor_si256
#define AP _mm_prefetch
#define AQ ldu256
#define AR _mm256_mul_epu32
#define AS _mm256_unpackhi_epi64
#define AT _mm256_blend_epi32
#define AU stride
#define AV float_len
#define AW _MM_HINT_T0
#define AX unsigned
#define AY _mm256_setr_epi32
#define AZ __attribute__
#define BA _mm256_bsrli_epi128
#define BB _mm256_setzero_si256
#define BC C64X4
#define BD return
#define BE _mm256_permutevar8x32_epi32
#define BF _mm256_unpacklo_epi64
#define BG template
#define BH stu256
#define BI true_type
#define BJ in_out
#define BK always_inline
#define BL _mm256_permute2f128_pd
#define BM FFTSqrtTableC64X4
#define BN shoup_identity_odd8
#define BO transform2
#define BP _mm256_and_si256
#define BQ typename
#define BR inline
#define BS _mm256_set1_pd
#define BT mulConj
#define BU _mm256_stream_si256
#define BV NoInitTag
#define BW Float64
#define BX _mm256_srli_epi64
#define BY _mm256_slli_si256
#define BZ sqrt_table_1
#define CA fft_len
#define CB transpose64_4X4
#define CC BinRevTableC64X4HP
#define CD __m256d
#define CE transToI64
#define CF uint32_t
#define CG paired_leaf
#define CH _mm256_castsi256_ps
#define CI _mm256_castpd_si256
#define CJ FFTAVX
#define CK multi_table_2
#define CL FROM_RIRI_PERM
#define CM true
#define CN _mm256_cmpgt_epi32
#define CO store
#define CP initial_load
#define CQ F64X4
#define CR integral_constant
#define CS _mm256_or_si256
#define CT getBegin
#define CU shoup8_ptr
#define CV _mm256_mul_pd
#define CW hint_log2
#define CX _mm_set1_epi32
#define CY _mm256_unpacklo_epi32
#define CZ _mm256_unpackhi_epi32
#define DA dif_pass8
#define DB child
#define DC uint64_t
#define DE _mm256_add_pd
#define DF Complex64X4
#define DG factor
#define DH false
#define DI vaddm256
#define DJ _mm256_sub_epi64
#define DK LazyOutput
#define DL _mm256_add_epi64
#define DM namespace
#define DN operator
#define DO store_nt
#define DP _mm256_castsi256_pd
#define DQ shoup8
#define DR Float
#define DS int64_t
#define DT nullptr
#define DU source_load8
#define DV row_dif_avx
#define DW _mm256_unpacklo_pd
#define DX _mm256_unpackhi_pd
#define DY MAX_LOG_LEN
#define DZ certifiedRoot
#define EA CACHE_LOG_LEN
#define EB multi_table_3
#define EC double
#define ED false
#define EE dit_entry64_registers
#define EF scale_row_mont
#define EG Float64X4
#define EH iditRecLong
#define EI mullo256
#define EJ shoup8_broadcast
#define EK TO_RIRI_PERM
#define EL difRecLong
#define EM __m128i
#define EN shared_factor
#define EO _mm256_sub_pd
#define EP TableFixMulti
#define EQ multi_table_1
#define ER _mm_and_si128
#define ES first_input_ptr
#define ET prepare_shared_row_factors
#define EU begin
#define EV shoup_c
#define EW build_tab2
#define EX static_cast
#define EY factor_shoup
#define EZ inverse_twiddle_consumer
#define FA LOG_BEGIN
#define FB _mm256_slli_epi32
#define FC enabled
#define FD _mm_setzero_si128
#define FE vsubm256
#define FF _mm_sfence
#define FG AlignMem
#define FH omega1
#define FI unit_table
#define FJ real_dot_binrev4
#define FK row_dit_avx
#define FL twiddle_rows_prepared
#define FM corner_head_store_avx
#define FN dit_pass8_block
#define FO LazyOut
#define FP load_tile_avx_d
#define FQ log_len
#define FR butterflyCommon
#define FS _mm_loadu_si128
#define FT source_load1
#define FU shared_shoup
#define FV corner_head_tile_avx
#define FW fast_workspace_words
#define FX other
#define FY g_psumv
#define FZ split
#define GA uintptr_t
#define GB corner_generic
#define GC INV_STEP_SHOUP
#define GD fast_transform
#define GE using
#define GF table
#define GG SHORT_LEN
#define GH LOG_SHORT
#define GI shoup8_s
#define GJ shoup_of
#define GK strOut
#define GL g_inv_scale
#define GM g_skip_leaf
#define GN table1
#define GO load_tile_avx
#define GP aligned
#define GQ col_dit3_tail
#define GR alignas
#define GS static_assert
#define GT trans2MulNegI
#define GU forward_stage
#define GV _mm_add_epi32
#define GW memcpy
#define GX build_tab
#define GY idit_func
#define GZ cu64_plain
#define HC reverse
#define HD false_type
#define HE highPtr
#define HF FFTTableSqrt
#define HG omega2
#define HH TO_INT64
#define HI FloatTy
#define HJ dot_rfftX4
#define HK correction
#define HL shared
#define HM spread
#define HN mont1
#define HO offset
#define HP rowbase
#define HQ g_prep_done
#define HR g_prep_root
#define HS initOmegaX4
#define HT getBeginLog
#define HU TableMulti1
#define HV TableMulti2
#define HW TableMulti3
#define HX RI_DIFF
#define HY Complex
#define HZ immintrin
#define IA continue
#define IB transform
#define IC table_len
#define ID CACHE_LEN
#define IE TableLong
#define IF iditSplit
#define IG dif_func
#define IH difRecMid
#define II remaining
#define IJ typedef
#define IK block
#define IL lastidx
#define IN revbits
#define IO in_data
#define IP index
#define IQ LOG_MAX
#define IR inverse
#define IS strIn
#define IT total
#define IU alpha
#define IV volatile
#define IW HalfZero
#define IX firstidx
#define IY INV_STEP
#define IZ public
#define JA TableFix
#define JB log_rank
#define JC lowPtr
#define JD difSplit
#define JE omega
#define JF FromRIRI
#define JG dot_rfft
#define JH inout0
#define JI inout1
#define JJ cstdint
#define JK g_fuse4
#define JL allzero
#define JM complex
#define JN private
#define JO LOG_MID
#define JP parity
#define JQ sizeof
#define JR load1
#define JS struct
#define JT table2
#define JU table3
#define JV ToRIRI
#define JW BLOCK
#define JX while
#define JY carry
#define JZ dit2p
#define KA class
#define KB idit4
#define KC count
#define KD value
#define KE MASKV
#define KF roots
#define KG mont8
#define KH magic
#define KI long
#define KJ BROW
#define KK void
#define KL bool
#define KM TBUF
#define KN bits
#define KO auto
#define KP dit2
#define KQ ws1o
#define KR true
#define KS V4Ps
#define KT t8x8
#define KU tile
#define KV char
#define KW nsrc
#define KX TSUB
#define KY root
#define KZ base
#define LA rows
#define LB hint
#define LC row0
#define LD row1
#define LE data
#define LF load
#define LG real
#define LH imag
#define LI rank
#define LJ LOGV
#define LK dif4
#define LM zero
#define LN negI
#define LO turn
#define LP side
#define LQ part
#define LR cur
#define LS YMM
#define LT dst
#define LU ctr
#define LV inv
#define LW it3
#define LX C64
#define LY old
#define LZ off
#define MA R32
#define MB it2
#define MC vr1
#define MD vr3
#define ME vr5
#define MF vr7
#define MG it1
#define MH vr0
#define MI vr2
#define MJ vr4
#define MK vr6
#define MN it0
#define MO src
#define MP std
#define MQ len
#define MR tws
#define MS F64
#define MT mul
#define MU u64
#define MV for
#define MW u32
#define MX int
#include <x86intrin.h>
#include <cassert>
#define ENGINE_N 100000000
#define LGR_ 12
#define M3L_ 14
#pragma once
#include <cstdint>
#ifndef LGR_
#define LGR_ 12
#endif
#ifndef M3L_
#define M3L_ 14
#endif
#ifndef LGR2_
#define LGR2_ 13
#endif
#ifndef LGC2_
#define LGC2_ 13
#endif
#define EXACT 0
#define PADC_ 48
#define PADC2_ 16
#define N3_ 3
#define M3_ (1u << M3L_)
#define NR_ (1u << LGR_)
#define NC_ (N3_ * M3_)
#define N1_ ((MW)(NR_ * NC_))
#define CSX_ (NC_ + PADC_)
#define AOFF(k) (((KI)(k) / (KI)NC_) * CSX_ + ((KI)(k) % (KI)NC_))
#define NR2_ (1u << LGR2_)
#define NC2_ (1u << LGC2_)
#define N2_ (1u << (LGR2_ + LGC2_))
#define CSX2_ (NC2_ + PADC2_)
#include <cstdint>
#define NO_AVX2_UNUSED 0
#include <cstring>
#ifndef NO_AVX2
#include <immintrin.h>
#endif
IJ uint16_t u16;
IJ CF MW;
IJ DC MU;
IJ DS i64;
IJ int32_t i32;
IJ AX __int128 u128;
#ifndef BSTAIL_SPLIT
#define BSTAIL_SPLIT ((ENGINE_N / CSX_) * CSX_)
#endif
AK MW*g_B=0;
AK MW*g_BT=0;
AK BR MW*KJ(KI el){
BD(el<BSTAIL_SPLIT)?g_B+el:g_BT+(el-BSTAIL_SPLIT);
}
#pragma GCC push_options
#pragma GCC target("avx2,tune=skylake")
AK BR AZ((BK))AB AQ(AH KK*p){
AB r;__asm__("vmovdqu %1, %0":"=x"(r):"m"(*(AH AB*)p));BD r;
}
AK AH MW*ES=DT;
AK BR AZ((BK))AB DU(AH MW*MO,MU at){
if(DH&&MO==ES){
BD BE(AQ(MO+ENGINE_N-at-8),AY(7,6,5,4,3,2,1,0));
}
BD AQ(MO+at);
}
AK BR MW FT(AH MW*MO,MU at){if(DH&&MO==ES)at=ENGINE_N-1-at;
BD MO[at];
}
AK BR AZ((BK))KK BH(KK*p,AB v){
__asm__ IV("vmovdqu %1, %0":"=m"(*(AB*)p):"x"(v));
}
#define NT2(p,a,b) {BU((AB *)(p),(a));BU((AB *)(p)+1,(b));}
#define NTC(d,s) {BU((AB *)(d),AQ((AH KK *)(s)));BU((AB *)(d)+1,AQ((AH KK *)((s)+8)));}
AK BR AZ((BK))AB DI(AB a,AB b,AB Pv){
AB s=AA(a,b);
BD AD(s,AC(s,Pv));
}
AK BR AZ((BK))AB FE(AB a,AB b,AB Pv){
AB d=AC(a,b);
BD AD(d,AA(d,Pv));
}
#undef CMBSTEP
#pragma GCC pop_options
#pragma GCC optimize("O3","rename-registers","live-range-shrinkage","ira-loop-pressure","no-stack-protector")
#define TS 64
#define PADB_ 48
#define NRMAX_ NR_
#ifndef MODULUS
#define MODULUS 2013265921u
#endif
AK MW P=MODULUS;
#ifndef ROOT_GENERATOR
#define ROOT_GENERATOR 31u
#endif
AK MW G=ROOT_GENERATOR;
AK MW SHMAGIC;
AK MU IM;
AK MW KM[TS*TS];
AK MX JK=0;
AK MW TW[TS*TS+8];
AK BR MW mm(MW a,MW b){
MU z=(MU)a*b;
MU q=(MU)(((u128)z*IM)>>64);
MU r=z-q*(MU)P;
BD(MW)(r>=P?r-P:r);
}
AK BR MW EV(MW w){BD(MW)(((MU)w<<32)/(MU)P);}
AK MW pw(MW a,MW e){
MW r=1;
JX(e){if(e&1)r=mm(r,a);a=mm(a,a);e>>=1;}
BD r;
}
AK KK GX(MW*tw,MX L,MW w){
MX LZ=0;
MV(MX MQ=2;MQ<=L;MQ<<=1){
MW wl=pw(w,(MW)(L/MQ));
MW c=1;
MX h=MQ>>1;
MV(MX j=0;j<h;j++){tw[LZ+j]=c;c=mm(c,wl);}
LZ+=h;
}
}
AK KK build_br(u16*br,MX L){
MX KN=0;JX((1<<KN)<L)KN++;
MV(MX i=0;i<L;i++){
MX r=0;
MV(MX b=0;b<KN;b++)if(i&(1<<b))r|=1<<(KN-1-b);
br[i]=(u16)r;
}
}
#ifdef NO_AVX2
#define HAVE_AVX2 0
#else
#define HAVE_AVX2 1
#pragma GCC push_options
#pragma GCC target("avx2,tune=skylake")
AK BR AB vmulhi8(AB a,AB b){
AB e=AR(a,b);
AB o=AR(BA(a,4),BA(b,4));
e=BA(e,4);
BD AT(e,o,0xAA);
}
AK BR AZ((BK))AB EI(AB a,AB b){
AB r;__asm__("vpmulld %2, %1, %0":"=x"(r):"x"(a),"xm"(b));BD r;
}
template<unsigned mod=0>AK BR AB DQ(AB v,AB w,AB ws){
AH AB Pv=AF((MX)(mod?mod:P));
AB t=EI(v,w);
AB q=vmulhi8(v,ws);
AB r=AC(t,EI(q,AF(mod?mod:P)));
BD AD(r,AC(r,Pv));
}
AK BR AB vmulhi8x(AB a,AB b,AB bo){
AB e=AR(a,b);
AB o=AR(BA(a,4),bo);
BD AT(BA(e,4),o,0xAA);
}
template<unsigned mod=0>AK BR AB shoup8x(AB v,AB w,AB ws,AB wo){
AH AB Pv=AF((MX)(mod?mod:P));
AB t=EI(v,w);
AB q=vmulhi8x(v,ws,wo);
AB r=AC(t,EI(q,AF(mod?mod:P)));
BD AD(r,AC(r,Pv));
}
template<unsigned mod=0>AK BR AZ((BK))AB CU(AB v,AH MW*w,AH MW*ws){
AH AB pv=AF((MX)(mod?mod:P));
AB t,qe,qo;AH AB vo=BA(v,4);
asm("vpmulld %2,%1,%0":"=x"(t):"x"(v),"m"(*(AH AB*)w));
asm("vpmuludq %2,%1,%0":"=x"(qe):"x"(v),"m"(*(AH AB*)ws));
asm("vpmuludq %2,%1,%0":"=x"(qo):"x"(vo),"m"(*(AH AB*)(ws+1)));
AH AB q=AT(BA(qe,4),qo,0xaa);
AH AB r=AC(t,EI(q,AF(mod?mod:P)));
BD AD(r,AC(r,pv));
}
template<unsigned mod=0>AK BR AB GI(AB v,AB w,AB ws){
AH AB Pv=AF((MX)(mod?mod:P));
AB t=EI(v,w);
AB q=vmulhi8(v,ws);
AB r=AC(t,EI(q,AF(mod?mod:P)));
BD AD(r,AC(r,Pv));
}
template<unsigned mod=0>AK BR AB shoup8x_s(AB v,AB w,AB ws,AB wo){
AH AB Pv=AF((MX)(mod?mod:P));
AB t=EI(v,w);
AB q=vmulhi8x(v,ws,wo);
AB r=AC(t,EI(q,AF(mod?mod:P)));
BD AD(r,AC(r,Pv));
}
template<unsigned mod=0>AK BR AB EJ(AB v,AB w,AB ws){
AH AB Pv=AF((MX)(mod?mod:P));
AB t=EI(v,w);
AH AB qe=AR(v,ws);
AH AB qo=AR(BA(v,4),ws);
AB q=AT(BA(qe,4),qo,0xaa);
AB r=AC(t,EI(q,AF(mod?mod:P)));
BD AD(r,AC(r,Pv));
}
BG<KL Lazy,unsigned mod=0>AK BR AB BN(AB v,AB w,AB ws){
AH AB pv=AF((MX)(mod?mod:P));
AH AB p64=AG((KI KI)(mod?mod:P));
AH AB a=BA(v,4);
AH AB prod=AR(a,w);
AH AB quot=BA(AR(a,ws),4);
AB r=DJ(prod,AR(quot,p64));
AB mixed=AT(v,_mm256_bslli_epi128(r,4),0xaa);
BD AD(mixed,AC(mixed,pv));
}
#define SP(w, ws) BP(w,M32), BX(w,32), BP(ws,M32), BX(ws,32)
BG<MX H,KL DK,KL Trim=ED,unsigned mod=0>AK BR AZ((BK))KK prime_FN(MW*p,AH MW*tw,AH MW*MR){
AH AB Pv=AF((MX)mod);
AH MW*t1=tw+H-1,*s1=MR+H-1;
AH MW*t2=tw+2*H-1,*s2=MR+2*H-1;
AH MW*t3=tw+4*H-1,*s3=MR+4*H-1;
MV(MX j=0;j<H;j+=8){
AB v0=AQ(p+j),v1=AQ(p+j+H),
v2=AQ(p+j+2*H),v3=AQ(p+j+3*H),
v4=AQ(p+j+4*H),v5=AQ(p+j+5*H),
v6=AQ(p+j+6*H),v7=AQ(p+j+7*H);
KO KP=[&](AB&a,AB&b,AB w,AB ws,AB wo,KL lazy=ED){
AB bm=shoup8x_s<mod>(b,w,ws,wo),LY=a;
if(lazy){a=AA(LY,bm);b=AA(AC(LY,bm),Pv);}
else{a=DI(LY,bm,Pv);b=FE(LY,bm,Pv);}
};
KO JZ=[&](AB&a,AB&b,AH MW*w,AH MW*ws,KL lazy){
AB bm=CU<mod>(b,w,ws),LY=a;
if(lazy){a=AA(LY,bm);b=AA(AC(LY,bm),Pv);}
else{a=DI(LY,bm,Pv);if(!Trim)b=FE(LY,bm,Pv);}
};
AB w1=AQ(t1+j),ws1=AQ(s1+j),KQ=AQ(s1+j+1);
KP(v0,v1,w1,ws1,KQ);KP(v2,v3,w1,ws1,KQ,KR);
KP(v4,v5,w1,ws1,KQ);KP(v6,v7,w1,ws1,KQ,KR);
{
AH AB w20=AQ(t2+j),ws20=AQ(s2+j),ws20o=AQ(s2+j+1);
KP(v0,v2,w20,ws20,ws20o);KP(v4,v6,w20,ws20,ws20o,KR);
}
asm IV(""::"x"(v0),"x"(v2),"x"(v4),"x"(v6):"memory");
{
AH AB w21=AQ(t2+j+H),ws21=AQ(s2+j+H),ws21o=AQ(s2+j+H+1);
KP(v1,v3,w21,ws21,ws21o);KP(v5,v7,w21,ws21,ws21o,KR);
}
JZ(v0,v4,t3+j,s3+j,DK);
JZ(v1,v5,t3+j+H,s3+j+H,DK);
JZ(v2,v6,t3+j+2*H,s3+j+2*H,DK);
JZ(v3,v7,t3+j+3*H,s3+j+3*H,DK);
BH(p+j,v0);BH(p+j+H,v1);
BH(p+j+2*H,v2);BH(p+j+3*H,v3);
if(!Trim){BH(p+j+4*H,v4);BH(p+j+5*H,v5);
BH(p+j+6*H,v6);BH(p+j+7*H,v7);}
}
}
BG<MX H,KL DK,KL Trim=ED>AK BR AZ((BK))KK FN(MW*p,AH MW*tw,AH MW*MR){if(P==2013265921u)prime_FN<H,DK,Trim,2013265921u>(p,tw,MR);else prime_FN<H,DK,Trim,1811939329u>(p,tw,MR);}

BG<MX H,unsigned mod=0,KL Trim=ED>AK KK dit_pass8(MW*x,MX L,AH MW*tw,AH MW*MR){
MV(MX i=0;i<L;i+=16*H){
if constexpr(mod)prime_FN<H,ED,Trim,mod>(x+i,tw,MR);else FN<H,ED,Trim>(x+i,tw,MR);
if(i+8*H<L)if constexpr(mod)prime_FN<H,KR,Trim,mod>(x+i+8*H,tw,MR);else FN<H,KR,Trim>(x+i+8*H,tw,MR);
}
}
BG<KL DK,unsigned mod=0>AK BR AZ((BK))KK EE(
AB&v0,AB&v1,AB&v2,AB&v3,AB&v4,AB&v5,AB&v6,AB&v7,AH MW*tw,AH MW*MR){
AL MX H=8,j=0;
AH AB Pv=AF((MX)(mod?mod:P));
AH MW*t1=tw+7,*s1=MR+7,*t2=tw+15,*s2=MR+15,*t3=tw+31,*s3=MR+31;
KO KP=[&](AB&a,AB&b,AB w,AB ws,AB wo,KL lazy=ED){
AB bm=shoup8x_s<mod>(b,w,ws,wo),LY=a;
if(lazy){a=AA(LY,bm);b=AA(AC(LY,bm),Pv);}
else{a=DI(LY,bm,Pv);b=FE(LY,bm,Pv);}
};
KO JZ=[&](AB&a,AB&b,AH MW*w,AH MW*ws,KL lazy){
AB bm=CU<mod>(b,w,ws),LY=a;
if(lazy){a=AA(LY,bm);b=AA(AC(LY,bm),Pv);}
else{a=DI(LY,bm,Pv);b=FE(LY,bm,Pv);}
};
AB w1=AQ(t1+j),ws1=AQ(s1+j),KQ=AQ(s1+j+1);
KP(v0,v1,w1,ws1,KQ);KP(v2,v3,w1,ws1,KQ,KR);
KP(v4,v5,w1,ws1,KQ);KP(v6,v7,w1,ws1,KQ,KR);
AB w20=AQ(t2+j),ws20=AQ(s2+j),ws20o=AQ(s2+j+1);
AB w21=AQ(t2+j+H),ws21=AQ(s2+j+H),ws21o=AQ(s2+j+H+1);
KP(v0,v2,w20,ws20,ws20o);KP(v4,v6,w20,ws20,ws20o,KR);
KP(v1,v3,w21,ws21,ws21o);KP(v5,v7,w21,ws21,ws21o,KR);
JZ(v0,v4,t3+j,s3+j,DK);
JZ(v1,v5,t3+j+H,s3+j+H,DK);
JZ(v2,v6,t3+j+2*H,s3+j+2*H,DK);
JZ(v3,v7,t3+j+3*H,s3+j+3*H,DK);
}
AK BR AB GJ(AB w);
AK BR AB KG(AB a,AB b);
template<unsigned mod>AK BR AB prime_mont(AB a,AB ax,AB b,AB bx){AB e=AR(a,b),o=AR(ax,bx);auto reduce=[](AB x){constexpr unsigned neg=mod-2;
 AB low=AR(x,AG(neg));
 AB mp=AR(low,AG(mod));
 return DL(x,mp);};AB u=CS(BA(reduce(e),4),reduce(o));return AD(u,AC(u,AF(mod)));}
AK BR AB mont8x(AB a,AB ax,AB b,AB bx);
template<unsigned mod>AK BR AB prime_KG(AB a,AB b){BD prime_mont<mod>(a,BA(a,4),b,BA(b,4));}
BG<KL Product=ED,KL LazyTail=ED,KL Trim=ED,unsigned mod=0>
AK KK prime_FK(MW*x,MX L,AH MW*tw,AH MW*MR,AH MW*FX=DT){
KO CP=[&](MX HO){
AB v=AQ(x+HO);
if AL(Product){AB y=AQ(FX+HO);
v=prime_mont<mod>(v,AQ(x+HO+1),y,AQ(FX+HO+1));}
BD v;
};
if AL(Product){if(L<8)MV(MX i=0;i<L;++i)x[i]=mm(x[i],FX[i]);}
AB Pv=AF((MX)mod),M1=AF(-1),Z=BB();
MX LZ=0;
if(L>=8){
AH AB V4=AY((MX)tw[1],(MX)tw[2],1,1,(MX)tw[1],(MX)tw[2],1,1);
AH AB V4s=AY((MX)MR[1],(MX)MR[2],2,2,(MX)MR[1],(MX)MR[2],2,2);
AH AB V8=AY((MX)tw[3],(MX)tw[4],(MX)tw[5],(MX)tw[6],1,1,1,1);
AH AB V8s=AY((MX)MR[3],(MX)MR[4],(MX)MR[5],(MX)MR[6],2,2,2,2);
AH AB V8Q=AY((MX)tw[3],(MX)tw[4],(MX)tw[5],(MX)tw[6],
(MX)tw[3],(MX)tw[4],(MX)tw[5],(MX)tw[6]);
AH AB V8Qs=AY((MX)MR[3],(MX)MR[4],(MX)MR[5],(MX)MR[6],
(MX)MR[3],(MX)MR[4],(MX)MR[5],(MX)MR[6]);
AH AB V4P=AG((KI KI)tw[2]);
AH AB KS=AG((KI KI)MR[2]);
AH AB IDX8=AY(4,5,6,7,0,1,2,3);
AH AB IDXQ4=AY(0,1,0,1,4,5,4,5);
AH AB IDXQ8=AY(0,1,2,3,0,1,2,3);
MX i4=0;
MV(;i4+64<=L;i4+=64){
AB MH=CP(i4+0);
AB MC=CP(i4+8);
AB MI=CP(i4+16);
AB MD=CP(i4+24);
AB MJ=CP(i4+32);
AB ME=CP(i4+40);
AB MK=CP(i4+48);
AB MF=CP(i4+56);
{
{
AB y=AI(MH,0xB1);
MH=AA(AA(AO(MH,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
MH=AD(MH,AC(MH,Pv));
}
}
{
{
AB y=AI(MC,0xB1);
MC=AA(AA(AO(MC,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
MC=AD(MC,AC(MC,Pv));
}
}
{
{
AB y=AI(MI,0xB1);
MI=AA(AA(AO(MI,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
MI=AD(MI,AC(MI,Pv));
}
}
{
{
AB y=AI(MD,0xB1);
MD=AA(AA(AO(MD,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
MD=AD(MD,AC(MD,Pv));
}
}
{
{
AB y=AI(MJ,0xB1);
MJ=AA(AA(AO(MJ,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
MJ=AD(MJ,AC(MJ,Pv));
}
}
{
{
AB y=AI(ME,0xB1);
ME=AA(AA(AO(ME,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
ME=AD(ME,AC(ME,Pv));
}
}
{
{
AB y=AI(MK,0xB1);
MK=AA(AA(AO(MK,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
MK=AD(MK,AC(MK,Pv));
}
}
{
{
AB y=AI(MF,0xB1);
MF=AA(AA(AO(MF,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
MF=AD(MF,AC(MF,Pv));
}
}
{
{
AB PP=AS(MH,MC);
AB MM=BN<ED,mod>(PP,V4P,KS);
AB LL=BF(MH,MC);
AB SS=AD(AA(LL,MM),AC(AA(LL,MM),Pv));
AB DD=AD(AC(LL,MM),AA(AC(LL,MM),Pv));
MH=BF(SS,DD);
MC=AS(SS,DD);
}
}
{
{
AB PP=AS(MI,MD);
AB MM=BN<ED,mod>(PP,V4P,KS);
AB LL=BF(MI,MD);
AB SS=AD(AA(LL,MM),AC(AA(LL,MM),Pv));
AB DD=AD(AC(LL,MM),AA(AC(LL,MM),Pv));
MI=BF(SS,DD);
MD=AS(SS,DD);
}
}
{
{
AB PP=AS(MJ,ME);
AB MM=BN<ED,mod>(PP,V4P,KS);
AB LL=BF(MJ,ME);
AB SS=AD(AA(LL,MM),AC(AA(LL,MM),Pv));
AB DD=AD(AC(LL,MM),AA(AC(LL,MM),Pv));
MJ=BF(SS,DD);
ME=AS(SS,DD);
}
}
{
{
AB PP=AS(MK,MF);
AB MM=BN<ED,mod>(PP,V4P,KS);
AB LL=BF(MK,MF);
AB SS=AD(AA(LL,MM),AC(AA(LL,MM),Pv));
AB DD=AD(AC(LL,MM),AA(AC(LL,MM),Pv));
MK=BF(SS,DD);
MF=AS(SS,DD);
}
}
{
{
AB YX=AE(MH,MC,0x31);
AB MM=GI<mod>(YX,V8Q,V8Qs);
AB XY=AE(MH,MC,0x20);
AB SS=AA(XY,MM);
AB DD=AA(AC(XY,MM),Pv);
MH=AE(SS,DD,0x20);
MH=AD(MH,AC(MH,Pv));
MC=AE(SS,DD,0x31);
}
}
{
{
AB YX=AE(MI,MD,0x31);
AB MM=GI<mod>(YX,V8Q,V8Qs);
AB XY=AE(MI,MD,0x20);
AB SS=AA(XY,MM);
AB DD=AA(AC(XY,MM),Pv);
MI=AE(SS,DD,0x20);
MI=AD(MI,AC(MI,Pv));
MD=AE(SS,DD,0x31);
}
}
{
{
AB YX=AE(MJ,ME,0x31);
AB MM=GI<mod>(YX,V8Q,V8Qs);
AB XY=AE(MJ,ME,0x20);
AB SS=AA(XY,MM);
AB DD=AA(AC(XY,MM),Pv);
MJ=AE(SS,DD,0x20);
MJ=AD(MJ,AC(MJ,Pv));
ME=AE(SS,DD,0x31);
}
}
{
{
AB YX=AE(MK,MF,0x31);
AB MM=GI<mod>(YX,V8Q,V8Qs);
AB XY=AE(MK,MF,0x20);
AB SS=AA(XY,MM);
AB DD=AA(AC(XY,MM),Pv);
MK=AE(SS,DD,0x20);
MK=AD(MK,AC(MK,Pv));
MF=AE(SS,DD,0x31);
}
}
if(L==4096||L==8192||L==16384){
if(i4&64)EE<KR,mod>(MH,MC,MI,MD,MJ,ME,MK,MF,tw,MR);
else EE<ED,mod>(MH,MC,MI,MD,MJ,ME,MK,MF,tw,MR);
}
BH((KK*)((x+i4+0)),MH);
BH((KK*)((x+i4+8)),MC);
BH((KK*)((x+i4+16)),MI);
BH((KK*)((x+i4+24)),MD);
BH((KK*)((x+i4+32)),MJ);
BH((KK*)((x+i4+40)),ME);
BH((KK*)((x+i4+48)),MK);
BH((KK*)((x+i4+56)),MF);
}
MV(;i4<L;i4+=8){
AB v=CP(i4);
{
AB y=AI(v,0xB1);
v=AA(AA(AO(v,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
v=AD(v,AC(v,Pv));
}
{
AB y=AI(v,0x4E);
y=DQ<mod>(y,V4,V4s);
AB sa=AD(AA(v,y),AC(AA(v,y),Pv));
AB d=AD(AC(v,y),AA(AC(v,y),Pv));
d=BE(d,IDXQ4);
v=AT(sa,d,0xCC);
}
{
AB y=BE(v,IDX8);
y=DQ<mod>(y,V8,V8s);
AB sa=AD(AA(v,y),AC(AA(v,y),Pv));
AB d=AD(AC(v,y),AA(AC(v,y),Pv));
d=BE(d,IDXQ8);
v=AT(sa,d,0xF0);
}
BH((KK*)((x+i4)),v);
}
LZ=7;
MX MQ=16;
if(L==4096||L==8192||L==16384){
dit_pass8<64,mod>(x,L,tw,MR);
if constexpr(Trim){if(L==4096)dit_pass8<512,mod,KR>(x,L,tw,MR);else dit_pass8<512,mod>(x,L,tw,MR);}
else dit_pass8<512,mod>(x,L,tw,MR);
MQ=8192;LZ=4095;
}
MV(;(MQ<<1)<=L;MQ<<=2){
MX h=MQ>>1;
AH MW*t1=tw+LZ,*ts1=MR+LZ;
AH MW*t2=t1+h,*ts2=ts1+h;
AH MW*t3=t2+h,*ts3=ts2+h;
LZ+=3*h;
MV(MX i=0;i<L;i+=(MQ<<1)){
MW*p=x+i;
MV(MX j=0;j<h;j+=8){
AB WV1=AQ((AH KK*)((t1+j))),WS1=AQ((AH KK*)((ts1+j)));
AB WV2=AQ((AH KK*)((t2+j))),WS2=AQ((AH KK*)((ts2+j)));
AB WV3=AQ((AH KK*)((t3+j))),WS3=AQ((AH KK*)((ts3+j)));
AB A=AQ((AH KK*)(p+j));
AB B=AQ((AH KK*)(p+j+h));
AB C=AQ((AH KK*)(p+j+2*h));
AB D=AQ((AH KK*)(p+j+3*h));
AB Bm=DQ<mod>(B,WV1,WS1),Dm=DQ<mod>(D,WV1,WS1);
AB Ap=DI(A,Bm,Pv),Bp=FE(A,Bm,Pv);
AB Cp=AA(C,Dm),Dp=AA(AC(C,Dm),Pv);
AB Cm=DQ<mod>(Cp,WV2,WS2),Dn=DQ<mod>(Dp,WV3,WS3);
if(LazyTail&&(MQ<<1)==L){
BH(p+j,AA(Ap,Cm));
BH(p+j+2*h,AA(AC(Ap,Cm),Pv));
BH(p+j+h,AA(Bp,Dn));
BH(p+j+3*h,AA(AC(Bp,Dn),Pv));
}else{
BH((KK*)(p+j),DI(Ap,Cm,Pv));
BH((KK*)(p+j+2*h),FE(Ap,Cm,Pv));
BH((KK*)(p+j+h),DI(Bp,Dn,Pv));
BH((KK*)(p+j+3*h),FE(Bp,Dn,Pv));
}
}
}
}
if(MQ<=L){
MX h=MQ>>1;
AH MW*t=tw+LZ,*ts=MR+LZ;LZ+=h;
MV(MX i=0;i<L;i+=MQ){
MW*p=x+i,*q=x+i+h;
MV(MX j=0;j<h;j+=8){
AB u=AQ((AH KK*)(p+j));
AB v=GI<mod>(AQ((AH KK*)(q+j)),
AQ((AH KK*)(t+j)),AQ((AH KK*)(ts+j)));
BH((KK*)(p+j),DI(u,v,Pv));
BH((KK*)(q+j),FE(u,v,Pv));
}
}
}
}else{
MV(MX MQ=2;MQ<=L;MQ<<=1){
MX h=MQ>>1;
AH MW*t=tw+LZ;LZ+=h;
MV(MX i=0;i<L;i+=MQ){
MW*p=x+i,*q=x+i+h;
MV(MX j=0;j<h;j++){
MW u=p[j],v=mm(q[j],t[j]);
MW sa=u+v;if(sa>=mod)sa-=mod;
MW d=u+mod-v;if(d>=mod)d-=mod;
p[j]=sa;q[j]=d;
}
}
}
}
}
BG<KL Product=ED,KL LazyTail=ED,KL Trim=ED>
AK KK FK(MW*x,MX L,AH MW*tw,AH MW*MR,AH MW*FX=DT){if(P==2013265921u)prime_FK<Product,LazyTail,Trim,2013265921u>(x,L,tw,MR,FX);else prime_FK<Product,LazyTail,Trim,1811939329u>(x,L,tw,MR,FX);}

BG<MX H3,KL IW=ED,unsigned mod=0>AK KK prime_DA(MW*x,MX L,AH MW*tw,AH MW*MR){
AH AB Pv=AF((MX)mod);
AH MX MQ=H3<<3;
AH MW*t1=tw+(MQ>>1)-1,*s1=MR+(MQ>>1)-1;
AH MW*t2=tw+(MQ>>2)-1,*s2=MR+(MQ>>2)-1;
AH MW*t3=tw+H3-1,*s3=MR+H3-1;
MV(MX i=0;i<L;i+=MQ){
MW*p=x+i;
MV(MX j=0;j<H3;j+=8){
AB v0=AQ(p+j),v1=AQ(p+j+H3),
v2=AQ(p+j+2*H3),v3=AQ(p+j+3*H3);
AB v4,v5,v6,v7;
KO dif2=[&](AB&a,AB&b,AB w,AB ws,AB wo){
AB sm=DI(a,b,Pv),df=AA(AC(a,b),Pv);
a=sm;b=shoup8x<mod>(df,w,ws,wo);
};
KO dif2p=[&](AB&a,AB&b,AH MW*w,AH MW*ws){
AB sm=DI(a,b,Pv),df=AA(AC(a,b),Pv);
a=sm;b=CU<mod>(df,w,ws);
};
if AL(IW){
v4=CU<mod>(v0,t1+j,s1+j);
v5=CU<mod>(v1,t1+j+H3,s1+j+H3);
v6=CU<mod>(v2,t1+j+2*H3,s1+j+2*H3);
v7=CU<mod>(v3,t1+j+3*H3,s1+j+3*H3);
}else{
v4=AQ(p+j+4*H3);v5=AQ(p+j+5*H3);
v6=AQ(p+j+6*H3);v7=AQ(p+j+7*H3);
dif2p(v0,v4,t1+j,s1+j);
dif2p(v1,v5,t1+j+H3,s1+j+H3);
dif2p(v2,v6,t1+j+2*H3,s1+j+2*H3);
dif2p(v3,v7,t1+j+3*H3,s1+j+3*H3);
}
{
AH AB w20=AQ(t2+j),s20=AQ(s2+j),s20o=AQ(s2+j+1);
dif2(v0,v2,w20,s20,s20o);dif2(v4,v6,w20,s20,s20o);
}
asm IV(""::"x"(v0),"x"(v2),"x"(v4),"x"(v6):"memory");
{
AH AB w21=AQ(t2+j+H3),s21=AQ(s2+j+H3),s21o=AQ(s2+j+H3+1);
dif2(v1,v3,w21,s21,s21o);dif2(v5,v7,w21,s21,s21o);
}
asm IV(""::"x"(v1),"x"(v3),"x"(v5),"x"(v7):"memory");
AB w3=AQ(t3+j),ws3=AQ(s3+j),ws3o=AQ(s3+j+1);
dif2(v0,v1,w3,ws3,ws3o);
BH(p+j,v0);BH(p+j+H3,v1);
dif2(v2,v3,w3,ws3,ws3o);
BH(p+j+2*H3,v2);BH(p+j+3*H3,v3);
dif2(v4,v5,w3,ws3,ws3o);
BH(p+j+4*H3,v4);BH(p+j+5*H3,v5);
dif2(v6,v7,w3,ws3,ws3o);
BH(p+j+6*H3,v6);BH(p+j+7*H3,v7);
}
}
}
BG<MX H3,KL IW=ED>AK KK DA(MW*x,MX L,AH MW*tw,AH MW*MR){if(P==2013265921u)prime_DA<H3,IW,2013265921u>(x,L,tw,MR);else prime_DA<H3,IW,1811939329u>(x,L,tw,MR);}

BG<KL IW=ED,KL FO=ED,KL ResidentInner=ED,unsigned mod=0>
AK KK prime_DV(MW*x,MX L,AH MW*tw,AH MW*MR){
AB Pv=AF((MX)mod),M1=AF(-1),Z=BB();
if(L>=8){
MX MQ=L;
if AL(ResidentInner){
prime_DA<256,ED,mod>(x,L,tw,MR);prime_DA<32,ED,mod>(x,L,tw,MR);MQ=32;
}else{
if(L==16384){
prime_DA<2048,ED,mod>(x,L,tw,MR);
MV(MX IK=0;IK<L;IK+=2048)prime_DV<ED,FO,KR,mod>(x+IK,2048,tw,MR);
BD;
}
if(L==4096){
prime_DA<512,IW,mod>(x,L,tw,MR);prime_DA<64,ED,mod>(x,L,tw,MR);prime_DA<8,ED,mod>(x,L,tw,MR);
MQ=8;
}else if(L==8192){
prime_DA<1024,ED,mod>(x,L,tw,MR);prime_DA<128,ED,mod>(x,L,tw,MR);prime_DA<16,ED,mod>(x,L,tw,MR);
MQ=16;
}
if(L==16384){
prime_DA<2048,ED,mod>(x,L,tw,MR);prime_DA<256,ED,mod>(x,L,tw,MR);prime_DA<32,ED,mod>(x,L,tw,MR);
MQ=32;
}
}
AH KL Fuse32=(MQ==32&&(L&63)==0);
if(!Fuse32&&L!=4096&&L!=8192)
MV(;MQ>=32;MQ>>=2){
MX h=MQ>>1,h2=MQ>>2;
AH MW*t1=tw+h-1,*ts1=MR+h-1;
AH MW*t2=t1+h2,*ts2=ts1+h2;
AH MW*t3=tw+h2-1,*ts3=MR+h2-1;
MV(MX i=0;i<L;i+=MQ){
MW*p=x+i;
MV(MX j=0;j<h2;j+=8){
AB WV1=AQ((AH KK*)((t1+j))),WS1=AQ((AH KK*)((ts1+j)));
AB WV2=AQ((AH KK*)((t2+j))),WS2=AQ((AH KK*)((ts2+j)));
AB WV3=AQ((AH KK*)((t3+j))),WS3=AQ((AH KK*)((ts3+j)));
AB v0=AQ((AH KK*)((p+j)));
AB v1=AQ((AH KK*)((p+j+h2)));
AB v2=AQ((AH KK*)((p+j+h)));
AB v3=AQ((AH KK*)((p+j+h+h2)));
AB s02=AD(AA(v0,v2),AC(AA(v0,v2),Pv));
AB d02=AC(v0,v2);
AB s13=AD(AA(v1,v3),AC(AA(v1,v3),Pv));
AB d13=AC(v1,v3);
d02=AA(d02,Pv);
d13=AA(d13,Pv);
d02=DQ<mod>(d02,WV1,WS1);
d13=DQ<mod>(d13,WV2,WS2);
AB ra=AD(AA(s02,s13),AC(AA(s02,s13),Pv));
AB rb=AA(AC(s02,s13),Pv);
rb=DQ<mod>(rb,WV3,WS3);
AB rc=AD(AA(d02,d13),AC(AA(d02,d13),Pv));
AB rd=AA(AC(d02,d13),Pv);
rd=DQ<mod>(rd,WV3,WS3);
BH((KK*)((p+j)),ra);
BH((KK*)((p+j+h2)),rb);
BH((KK*)((p+j+h)),rc);
BH((KK*)((p+j+h+h2)),rd);
}
}
}
if(Fuse32)MQ=8;
if(MQ>=16){
MX h=MQ>>1;
AH MW*t=tw+h-1,*ts=MR+h-1;
MV(MX i=0;i<L;i+=MQ){
MW*p=x+i,*q=x+i+h;
MV(MX j=0;j<h;j+=8){
AB u=AQ((AH KK*)((p+j)));
AB v=AQ((AH KK*)((q+j)));
AB w=AQ((AH KK*)((t+j)));
AB ws=AQ((AH KK*)((ts+j)));
AB sa=AD(AA(u,v),AC(AA(u,v),Pv));
AB d=AA(AC(u,v),Pv);
d=GI<mod>(d,w,ws);
BH((KK*)((p+j)),sa);
BH((KK*)((q+j)),d);
}
}
}
AH AB V8=AY(1,1,1,1,(MX)tw[3],(MX)tw[4],(MX)tw[5],(MX)tw[6]);
AH AB V8s=AY(2,2,2,2,(MX)MR[3],(MX)MR[4],(MX)MR[5],(MX)MR[6]);
AB V8N,V8Ns;
{
static AB cN,cNs;static MW kk[8];static KL cok=ED;
AH MW a3=tw[3],a4=tw[4],a5=tw[5],a6=tw[6],b3=MR[3],b4=MR[4],b5=MR[5],b6=MR[6];
if(!cok||kk[0]!=a3||kk[1]!=a4||kk[2]!=a5||kk[3]!=a6||kk[4]!=b3||kk[5]!=b4||kk[6]!=b5||kk[7]!=b6){
cok=KR;kk[0]=a3;kk[1]=a4;kk[2]=a5;kk[3]=a6;kk[4]=b3;kk[5]=b4;kk[6]=b5;kk[7]=b6;
cN=AY((MX)a3,(MX)a4,(MX)a5,(MX)a6,(MX)(mod-a3),(MX)(mod-a4),(MX)(mod-a5),(MX)(mod-a6));
cNs=AY((MX)b3,(MX)b4,(MX)b5,(MX)b6,(MX)EV(mod-a3),(MX)EV(mod-a4),(MX)EV(mod-a5),(MX)EV(mod-a6));
}
V8N=cN;V8Ns=cNs;
}
AH AB V4=AY(1,1,(MX)tw[1],(MX)tw[2],1,1,(MX)tw[1],(MX)tw[2]);
AH AB V4s=AY(2,2,(MX)MR[1],(MX)MR[2],2,2,(MX)MR[1],(MX)MR[2]);
AH AB V4P=AG((KI KI)tw[2]);
AH AB KS=AG((KI KI)MR[2]);
AH AB IDX8=AY(4,5,6,7,0,1,2,3);
KO finish32=[&](AB&v0,AB&v1,AB&v2,AB&v3){
AB s02=DI(v0,v2,Pv),s13=DI(v1,v3,Pv);
AB d02=CU<mod>(AA(AC(v0,v2),Pv),tw+15,MR+15);
AB d13=CU<mod>(AA(AC(v1,v3),Pv),tw+23,MR+23);
AB ra=DI(s02,s13,Pv),rc=DI(d02,d13,Pv);
AB rb=CU<mod>(AA(AC(s02,s13),Pv),tw+7,MR+7);
AB rd=CU<mod>(AA(AC(d02,d13),Pv),tw+7,MR+7);
v0=ra;v1=rb;v2=rc;v3=rd;
};
MX i4=0;
MV(;i4+64<=L;i4+=64){
AB MH=AQ((AH KK*)((x+i4+0)));
AB MC=AQ((AH KK*)((x+i4+8)));
AB MI=AQ((AH KK*)((x+i4+16)));
AB MD=AQ((AH KK*)((x+i4+24)));
AB MJ=AQ((AH KK*)((x+i4+32)));
AB ME=AQ((AH KK*)((x+i4+40)));
AB MK=AQ((AH KK*)((x+i4+48)));
AB MF=AQ((AH KK*)((x+i4+56)));
if(Fuse32){finish32(MH,MC,MI,MD);finish32(MJ,ME,MK,MF);}
{
{
AB X=AE(MH,MC,0x21);
AB Y=AE(MH,MC,0x30);
AB S=AD(AA(X,Y),AC(AA(X,Y),Pv));
AB D=AA(AC(Y,X),Pv);
D=DQ<mod>(D,V8N,V8Ns);
MH=AE(S,D,0x20);
MC=AE(S,D,0x31);
}
}
{
{
AB X=AE(MI,MD,0x21);
AB Y=AE(MI,MD,0x30);
AB S=AD(AA(X,Y),AC(AA(X,Y),Pv));
AB D=AA(AC(Y,X),Pv);
D=DQ<mod>(D,V8N,V8Ns);
MI=AE(S,D,0x20);
MD=AE(S,D,0x31);
}
}
{
{
AB X=AE(MJ,ME,0x21);
AB Y=AE(MJ,ME,0x30);
AB S=AD(AA(X,Y),AC(AA(X,Y),Pv));
AB D=AA(AC(Y,X),Pv);
D=DQ<mod>(D,V8N,V8Ns);
MJ=AE(S,D,0x20);
ME=AE(S,D,0x31);
}
}
{
{
AB X=AE(MK,MF,0x21);
AB Y=AE(MK,MF,0x30);
AB S=AD(AA(X,Y),AC(AA(X,Y),Pv));
AB D=AA(AC(Y,X),Pv);
D=DQ<mod>(D,V8N,V8Ns);
MK=AE(S,D,0x20);
MF=AE(S,D,0x31);
}
}
{
{
AB yu=AI(MH,0x4E);
AB saU=AD(AA(MH,yu),AC(AA(MH,yu),Pv));
AB du=AC(yu,MH);
du=AA(du,Pv);
AB yv=AI(MC,0x4E);
AB saV=AD(AA(MC,yv),AC(AA(MC,yv),Pv));
AB dv=AC(yv,MC);
dv=AA(dv,Pv);
AB PP=AS(du,dv);
AB MM=BN<KR,mod>(PP,V4P,KS);
MH=AT(saU,BY(MM,8),0xCC);
MC=AT(saV,MM,0xCC);
}
}
{
{
AB yu=AI(MI,0x4E);
AB saU=AD(AA(MI,yu),AC(AA(MI,yu),Pv));
AB du=AC(yu,MI);
du=AA(du,Pv);
AB yv=AI(MD,0x4E);
AB saV=AD(AA(MD,yv),AC(AA(MD,yv),Pv));
AB dv=AC(yv,MD);
dv=AA(dv,Pv);
AB PP=AS(du,dv);
AB MM=BN<KR,mod>(PP,V4P,KS);
MI=AT(saU,BY(MM,8),0xCC);
MD=AT(saV,MM,0xCC);
}
}
{
{
AB yu=AI(MJ,0x4E);
AB saU=AD(AA(MJ,yu),AC(AA(MJ,yu),Pv));
AB du=AC(yu,MJ);
du=AA(du,Pv);
AB yv=AI(ME,0x4E);
AB saV=AD(AA(ME,yv),AC(AA(ME,yv),Pv));
AB dv=AC(yv,ME);
dv=AA(dv,Pv);
AB PP=AS(du,dv);
AB MM=BN<KR,mod>(PP,V4P,KS);
MJ=AT(saU,BY(MM,8),0xCC);
ME=AT(saV,MM,0xCC);
}
}
{
{
AB yu=AI(MK,0x4E);
AB saU=AD(AA(MK,yu),AC(AA(MK,yu),Pv));
AB du=AC(yu,MK);
du=AA(du,Pv);
AB yv=AI(MF,0x4E);
AB saV=AD(AA(MF,yv),AC(AA(MF,yv),Pv));
AB dv=AC(yv,MF);
dv=AA(dv,Pv);
AB PP=AS(du,dv);
AB MM=BN<KR,mod>(PP,V4P,KS);
MK=AT(saU,BY(MM,8),0xCC);
MF=AT(saV,MM,0xCC);
}
}
{
{
AB y=AI(MH,0xB1);
MH=AA(AA(AO(MH,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
if AL(!FO)MH=AD(MH,AC(MH,Pv));
}
}
{
{
AB y=AI(MC,0xB1);
MC=AA(AA(AO(MC,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
if AL(!FO)MC=AD(MC,AC(MC,Pv));
}
}
{
{
AB y=AI(MI,0xB1);
MI=AA(AA(AO(MI,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
if AL(!FO)MI=AD(MI,AC(MI,Pv));
}
}
{
{
AB y=AI(MD,0xB1);
MD=AA(AA(AO(MD,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
if AL(!FO)MD=AD(MD,AC(MD,Pv));
}
}
{
{
AB y=AI(MJ,0xB1);
MJ=AA(AA(AO(MJ,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
if AL(!FO)MJ=AD(MJ,AC(MJ,Pv));
}
}
{
{
AB y=AI(ME,0xB1);
ME=AA(AA(AO(ME,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
if AL(!FO)ME=AD(ME,AC(ME,Pv));
}
}
{
{
AB y=AI(MK,0xB1);
MK=AA(AA(AO(MK,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
if AL(!FO)MK=AD(MK,AC(MK,Pv));
}
}
{
{
AB y=AI(MF,0xB1);
MF=AA(AA(AO(MF,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
if AL(!FO)MF=AD(MF,AC(MF,Pv));
}
}
BH((KK*)((x+i4+0)),MH);
BH((KK*)((x+i4+8)),MC);
BH((KK*)((x+i4+16)),MI);
BH((KK*)((x+i4+24)),MD);
BH((KK*)((x+i4+32)),MJ);
BH((KK*)((x+i4+40)),ME);
BH((KK*)((x+i4+48)),MK);
BH((KK*)((x+i4+56)),MF);
}
MV(;i4<L;i4+=8){
AB v=AQ((AH KK*)((x+i4)));
{
AB y=BE(v,IDX8);
AB sa=AD(AA(v,y),AC(AA(v,y),Pv));
AB d0=AC(y,v);
d0=AA(d0,Pv);
AB d=DQ<mod>(d0,V8,V8s);
v=AT(sa,d,0xF0);
}
{
AB y=AI(v,0x4E);
AB sa=AD(AA(v,y),AC(AA(v,y),Pv));
AB d=AC(y,v);
d=AA(d,Pv);
d=DQ<mod>(d,V4,V4s);
v=AT(sa,d,0xCC);
}
{
AB y=AI(v,0xB1);
v=AA(AA(AO(v,AG((KI KI)0xffffffff00000000ull)),y),
AG((KI KI)((MU)(mod+1)<<32)));
if AL(!FO)v=AD(v,AC(v,Pv));
}
BH((KK*)((x+i4)),v);
}
}else{
MV(MX MQ=L;MQ>=2;MQ>>=1){
MX h=MQ>>1;
AH MW*t=tw+h-1;
MV(MX i=0;i<L;i+=MQ){
MW*p=x+i,*q=x+i+h;
MV(MX j=0;j<h;j++){
MW u=p[j],v=q[j];
MW sa=u+v;if(sa>=mod)sa-=mod;
MW d=u+mod-v;if(d>=mod)d-=mod;
p[j]=sa;q[j]=mm(d,t[j]);
}
}
}
}
}
BG<KL IW=ED,KL FO=ED,KL ResidentInner=ED>
AK KK DV(MW*x,MX L,AH MW*tw,AH MW*MR){if(P==2013265921u)prime_DV<IW,FO,ResidentInner,2013265921u>(x,L,tw,MR);else prime_DV<IW,FO,ResidentInner,1811939329u>(x,L,tw,MR);}

AK BR AB GJ(AB w){
AH AB ML=AF(SHMAGIC);
AB lo=AR(w,ML);
AB hi=AR(BX(w,32),ML);
AB m=AT(BX(lo,32),_mm256_slli_epi64(BX(hi,32),32),0xAA);
BD AA(AA(w,w),m);
}
AK BR KK KT(AB*r){
AB t0=CY(r[0],r[1]),t1=CZ(r[0],r[1]);
AB t2=CY(r[2],r[3]),t3=CZ(r[2],r[3]);
AB t4=CY(r[4],r[5]),t5=CZ(r[4],r[5]);
AB t6=CY(r[6],r[7]),t7=CZ(r[6],r[7]);
AB u0=BF(t0,t2),u1=AS(t0,t2);
AB u2=BF(t1,t3),u3=AS(t1,t3);
AB u4=BF(t4,t6),u5=AS(t4,t6);
AB u6=BF(t5,t7),u7=AS(t5,t7);
r[0]=AE(u0,u4,0x20);r[1]=AE(u1,u5,0x20);
r[2]=AE(u2,u6,0x20);r[3]=AE(u3,u7,0x20);
r[4]=AE(u0,u4,0x31);r[5]=AE(u1,u5,0x31);
r[6]=AE(u2,u6,0x31);r[7]=AE(u3,u7,0x31);
}
AK KK pointwise_mul_avx(MW*A,AH MW*B,MW n,MW sc,MW sx){
(KK)sc;
KI k=0;
MV(MX r=0;k<(KI)n;r++){
KI lim=(KI)sx-PADC_;
if(lim>(KI)n-k)lim=(KI)n-k;
MW*a=A+(KI)r*sx;
AH MW*b=KJ((KI)r*sx);
KI i=0;
MV(;i+8<=lim;i+=8){
AB x=AQ((AH KK*)(a+i));
AB y=AQ((AH KK*)(b+i));
BH((KK*)(a+i),DQ(x,y,GJ(y)));
}
MV(;i<lim;i++)a[i]=mm(a[i],b[i]);
k+=lim;
}
}
AK MW NPI=0;
AK MW MA;
AK BR MW HN(MW a,MW b){
MU z=(MU)a*(MU)b;
MW m=(MW)((MU)(MW)z*(MU)NPI);
MU t=(z+(MU)m*(MU)P)>>32;
BD(MW)(t>=P?t-P:t);
}
AK BR AB mont8x(AB a,AB ax,AB b,AB bx){
AB P64=AG((KI KI)P),NP=AG((KI KI)NPI);
AB Pv=AF((MX)P);
AB tlo=AR(a,b),thi=AR(ax,bx);
AB e2=AR(tlo,NP),o2=AR(thi,NP);
AB e4=AR(e2,P64),o4=AR(o2,P64);
AB e5=DL(tlo,e4),o5=DL(thi,o4);
AB u=CS(BA(e5,4),o5);
BD AD(u,AC(u,Pv));
}
AK BR AB KG(AB a,AB b){
AB P64=AG((KI KI)P),NP=AG((KI KI)NPI);
AB Pv=AF((MX)P);
AB ahi=BA(a,4),bhi=BA(b,4);
AB tlo=AR(a,b),thi=AR(ahi,bhi);
AB e2=AR(tlo,NP),o2=AR(thi,NP);
AB e4=AR(e2,P64),o4=AR(o2,P64);
AB e5=DL(tlo,e4),o5=DL(thi,o4);
AB u=CS(BA(e5,4),o5);
BD AD(u,AC(u,Pv));
}
AK KK scale_row_prepared(MW*LT,AH MW*MO,MW k,MW ks){
AH AB kv=AF((MX)k);
AH AB ksv=AF((MX)ks);
MV(MX v=0;v<TS;v+=8)
BH(LT+v,DQ(AQ(MO+v),kv,ksv));
}
template<unsigned mod=0>AK KK  prime_EF(MW*LT,AH MW*MO,MW kM){
AH MW k=HN(kM,1u);
AH AB kv=AF((MX)k);
AH AB ks=AF((MX)EV(k));
MV(MX v=0;v<TS;v+=8)
BH(LT+v,DQ<mod>(AQ(MO+v),kv,ks));
}
AK KK EF(MW*LT,AH MW*MO,MW kM){if(P==2013265921u)prime_EF<2013265921u>(LT, MO, kM);else prime_EF<1811939329u>(LT, MO, kM);}
AK KK twiddle_rows_mont(MW*TW,AH MW*RVM){
AB DG[TS/8],EY[TS/8];
AH AB one=AF(1);
MV(MX v=0;v<TS;v+=8){
DG[v/8]=KG(AQ(RVM+v),one);
EY[v/8]=GJ(DG[v/8]);
}
MV(MX u=1;u<TS;++u){
AH MW*prev=TW+(u-1)*TS;
MW*LR=TW+u*TS;
MV(MX v=0;v<TS;v+=8)
BH(LR+v,DQ(AQ(prev+v),
DG[v/8],EY[v/8]));
}
}
AK KK ET(AH MW*RV,AB*EN,AB*FU){
MV(MX v=0;v<TS;v+=8){
EN[v/8]=KG(AQ(RV+v),AF(1));
FU[v/8]=GJ(EN[v/8]);
}
}
template<unsigned mod=0>AK KK  prime_FL(MW*TW,AH AB*DG,AH AB*EY){
MV(MX u=1;u<TS;++u){
AH MW*prev=TW+(u-1)*TS;
MW*LR=TW+u*TS;
MV(MX v=0;v<TS;v+=8)
BH(LR+v,DQ<mod>(AQ(prev+v),
DG[v/8],EY[v/8]));
}
}
AK KK FL(MW*TW,AH AB*DG,AH AB*EY){if(P==2013265921u)prime_FL<2013265921u>(TW, DG, EY);else prime_FL<1811939329u>(TW, DG, EY);}
AK KK scale_row_avx(MW*LT,AH MW*MO,MW k){
AH AB kv=AF((MX)k),ks=AF((MX)EV(k));
MV(MX v=0;v<TS;v+=8)
BH((KK*)((LT+v)),DQ(AQ((AH KK*)((MO+v))),kv,ks));
}
AK KK twiddle_rows_avx(MW*TW,AH MW*RV){
AB RVS[TS/8];
MV(MX v=0;v<TS;v+=8)RVS[v>>3]=GJ(AQ((AH KK*)((RV+v))));
MV(MX u=1;u<TS;u++){
AH MW*prv=TW+(u-1)*TS;
MW*LR=TW+u*TS;
MV(MX v=0;v<TS;v+=8){
AB r=AQ((AH KK*)((RV+v)));
BH((KK*)((LR+v)),DQ(AQ((AH KK*)((prv+v))),r,RVS[v>>3]));
}
}
}
template<unsigned mod=0>AK KK  prime_corner_tile_avx(AH MW*in,MW*out,MX A0,MX B0,MX IS,MX GK,MX FZ){
MV(MX u0=0;u0<TS;u0+=8){
MV(MX v0=0;v0<TS;v0+=8){
AB r[8];
MV(MX k=0;k<8;k++){
AH MW*s=in+(MU)(A0+u0+k)*IS+B0+v0;
AH MW*tw=TW+(u0+k)*TS+v0;
AB x=AQ((AH KK*)(s));
AB w=AQ((AH KK*)(tw));
r[k]=prime_KG<mod>(x,w);
}
KT(r);
MV(MX k=0;k<8;k++)
BH((KK*)(KM+(v0+k)*TS+u0),r[k]);
}
}
MV(MX v=0;v<TS;v++){
MW*d=FZ?KJ((KI)(B0+v)*GK+A0):out+(MU)(B0+v)*GK+A0;
AH MW*s=KM+v*TS;
if((((GA)d)&63u)==0u){
MV(MX u=0;u<TS;u+=16)NTC(d+u,s+u);
}else{
MV(MX u=0;u<TS;u+=8)BH((KK*)(d+u),AQ((AH KK*)(s+u)));
}
}
}
AK KK corner_tile_avx(AH MW*in,MW*out,MX A0,MX B0,MX IS,MX GK,MX FZ){if(P==2013265921u)prime_corner_tile_avx<2013265921u>(in, out, A0, B0, IS, GK, FZ);else prime_corner_tile_avx<1811939329u>(in, out, A0, B0, IS, GK, FZ);}
template<unsigned mod=0>AK KK  prime_corner_tile_avx_blk(AH MW*in,MW*out,MX A0c,MX B0,MX IS,MX GK,MX FZ){
MV(MX u0=0;u0<TS;u0+=8){
MV(MX v0=0;v0<TS;v0+=8){
AB r[8];
MV(MX k=0;k<8;k++){
AH MW*s=in+(MU)(u0+k)*IS+B0+v0;
AH MW*tw=TW+(u0+k)*TS+v0;
r[k]=prime_KG<mod>(AQ((AH KK*)(s)),AQ((AH KK*)(tw)));
}
KT(r);
MV(MX k=0;k<8;k++)
BH((KK*)(KM+(v0+k)*TS+u0),r[k]);
}
}
MV(MX v=0;v<TS;v++){
MW*d=FZ?KJ((KI)(B0+v)*GK+A0c):out+(MU)(B0+v)*GK+A0c;
AH MW*s=KM+v*TS;
if((((GA)d)&63u)==0u){
MV(MX u=0;u<TS;u+=16)NTC(d+u,s+u);
}else{
MV(MX u=0;u<TS;u+=8)BH((KK*)(d+u),AQ((AH KK*)(s+u)));
}
}
}
AK KK corner_tile_avx_blk(AH MW*in,MW*out,MX A0c,MX B0,MX IS,MX GK,MX FZ){if(P==2013265921u)prime_corner_tile_avx_blk<2013265921u>(in, out, A0c, B0, IS, GK, FZ);else prime_corner_tile_avx_blk<1811939329u>(in, out, A0c, B0, IS, GK, FZ);}
template<unsigned mod=0>AK KK  prime_corner_tile_avx_to(AH MW*in,MW*KU,MX B0,MX IS){
(KK)IS;
AH KI SRF_=(KI)(NR_+PADB_);
MV(MX u0=0;u0<TS;u0+=8){
MV(MX v0=0;v0<TS;v0+=8){
AB r[8];
{
{AH MW*pf=in+B0+v0+(MU)(u0+8)*SRF_;
MV(MX k=0;k<8;k++)AP((AH KV*)(pf+(MU)k*SRF_),AW);}
AH MW*sb=in+B0+v0+(MU)u0*SRF_;
AH MW*tb=TW+(MU)u0*TS+v0;
MV(MX k=0;k<8;k++)
r[k]=prime_mont<mod>(AQ((AH KK*)(sb+(MU)k*SRF_)),AQ((AH KK*)(sb+(MU)k*SRF_+1)),
AQ((AH KK*)(tb+(KI)k*TS)),AQ((AH KK*)(tb+(KI)k*TS+1)));
}
KT(r);
MV(MX k=0;k<8;k++)
BH((KK*)(KU+(v0+k)*TS+u0),r[k]);
}
}
}
AK KK corner_tile_avx_to(AH MW*in,MW*KU,MX B0,MX IS){if(P==2013265921u)prime_corner_tile_avx_to<2013265921u>(in, KU, B0, IS);else prime_corner_tile_avx_to<1811939329u>(in, KU, B0, IS);}
AK KK GO(AH MW*MO,MW*S,MX r0,MX c0,MX R,MX C,MX LU,MX JL){
MV(MX rb0=0;rb0<TS;rb0+=8){
MV(MX cb0=0;cb0<TS;cb0+=16){
AB r[8];
if(JL){
MV(MX k=0;k<8;k++)r[k]=BB();
}else{
MV(MX k=0;k<8;k++){
AH MW*s=MO+(MU)(r0+rb0+k)*C+c0+cb0;
AB x=DU(MO,(MU)(s-MO));
if(LU){
AB y=AC(x,AF(4));
AB z=AA(x,AF((MX)(P-4)));
x=AD(y,z);
}
if(CM){AH AB zz=BB(),q2=AF((MX)(2u*P));x=AC(x,AF((MX)0x80000000u));x=AA(x,BP(CN(zz,x),q2));}x=AD(x,AC(x,AF(P)));r[k]=x;
}
}
KT(r);
MV(MX j=0;j<8;j++)
BH((KK*)(KM+(cb0+j)*TS+rb0),r[j]);
{
MX cb0b=cb0+8;
AB r2[8];
if(JL){
MV(MX k=0;k<8;k++)r2[k]=BB();
}else{
MV(MX k=0;k<8;k++){
AH MW*s=MO+(MU)(r0+rb0+k)*C+c0+cb0b;
AB x=DU(MO,(MU)(s-MO));
if(LU){
AB y=AC(x,AF(4));
AB z=AA(x,AF((MX)(P-4)));
x=AD(y,z);
}
r2[k]=x;
}
}
KT(r2);
MV(MX j=0;j<8;j++)
BH((KK*)(KM+(cb0b+j)*TS+rb0),r2[j]);
}
}
}
MV(MX cb=0;cb<TS;cb++){
MW*d=S+(MU)(c0+cb)*R+r0;
AH MW*s=KM+cb*TS;
MV(MX rb=0;rb<TS;rb+=8)BH((KK*)(d+rb),AQ((AH KK*)(s+rb)));
}
}
AK KK FP(AH MW*MO,MW*S,MX r0,MX c0,MX C,MX dstr,MX LU,MX JL,MX RB=0,MX RN=TS){
(KK)C;(KK)dstr;
AH KI CF_=(KI)NC_,DF_=(KI)(NR_+PADB_);
MV(MX rb0=RB;rb0<RB+RN;rb0+=8){
MV(MX cb0=0;cb0<TS;cb0+=8){
{AH MW*pf=MO+c0+cb0+(MU)(r0+rb0+8)*CF_;
MV(MX k=0;k<8;k++)AP((AH KV*)(pf+(MU)k*CF_),AW);}
AB r[8];
if(JL){
MV(MX k=0;k<8;k++)r[k]=BB();
}else{
AH MW*sb=MO+(MU)(r0+rb0)*CF_+c0+cb0;
MV(MX k=0;k<8;k++){
AB x=DU(MO,(MU)(sb+(MU)k*CF_-MO));
if(LU){
AB y=AC(x,AF(4));
AB z=AA(x,AF((MX)(P-4)));
x=AD(y,z);
}
if(CM){AH AB zz=BB(),q2=AF((MX)(2u*P));x=AC(x,AF((MX)0x80000000u));x=AA(x,BP(CN(zz,x),q2));}x=AD(x,AC(x,AF(P)));r[k]=x;
}
}
KT(r);
{
AH MW*db=S+(MU)r0+rb0;
MV(MX j=0;j<8;j++)
BH((KK*)(db+(KI)(cb0+j)*DF_),r[j]);
}
}
}
}
AK KK load_block(AH MW*MO,MW KW,MW*S,MX c0,MX R,MX C,MX dstr,MX LU){
MV(MX r0=0;r0<R;r0+=TS){
MU IX=(MU)r0*C+c0;
MU IL=(MU)(r0+TS-1)*C+c0+TS-1;
if(IL<KW){FP(MO,S,r0,c0,C,dstr,LU,0);IA;}
if(IX>=KW){FP(MO,S,r0,c0,C,dstr,LU,1);IA;}
AH AB c4=AF(4),c4p=AF((MX)(P-4));
MX rl=0,rz=TS;
{
MU KWu=(MU)KW,c0u=(MU)c0,Cu=(MU)C,TOP=0x3fffffffu;
MU lastin = KWu > c0u+(MU)TS ? (KWu - c0u - (MU)TS)/Cu : 0u;
MX rlast = (MX)(lastin<TOP?lastin:TOP);
rl = rlast + 1 - (MX)r0; if(rl<0)rl=0; if(rl>TS)rl=TS; rl = rl & ~7;
MU firstout = KWu > c0u ? ((KWu - c0u) + Cu - 1u)/Cu : 0u;
MX rf = (MX)(firstout<TOP?firstout:TOP);
rz = rf - (MX)r0; if(rz<0)rz=0; if(rz>TS)rz=TS; rz = (rz+7) & ~7; if(rz<rl)rz=rl;
if(rl>0)FP(MO,S,r0,c0,C,dstr,LU,0,0,rl);
if(rz<TS)FP(MO,S,r0,c0,C,dstr,LU,1,rz,TS-rz);
}
if(rz<=rl)IA;
MV(MX rb=rl;rb<rz;rb+=8){
MV(MX cb0=0;cb0<TS;cb0+=8){
AB r[8];AH AB pp=AF(P),p2=AF((MX)(2u*P)),c31=AF((MX)0x80000000u),zz=BB();
MV(MX k=0;k<8;k++){
MU idx=(MU)(r0+rb+k)*C+c0+cb0;
if(idx+8<=(MU)KW){
AB x=DU(MO,idx);
if(LU)x=AD(AC(x,c4),AA(x,c4p));
x=AC(x,c31);x=AA(x,BP(CN(zz,x),p2));x=AD(x,AC(x,pp));r[k]=x;
}else if(idx>=(MU)KW){
r[k]=BB();
}
}
KT(r);
AH MW*db=S+(MU)r0+rb;
MV(MX j=0;j<8;j++)BH((KK*)(db+(KI)(cb0+j)*dstr),r[j]);
}
}
}
}
AK KK copy_u32_avx(MW*LT,AH MW*MO,KI n){
KI i=0;
MV(;i+8<=n;i+=8)BH((KK*)(LT+i),AQ((AH KK*)(MO+i)));
MV(;i<n;i++)LT[i]=MO[i];
}
AK KK copy_u32_nt(MW*LT,AH MW*MO,KI n){
KI i=0;
KI ka=((-(KI)(((GA)LT)>>2))&15);
MV(;i<ka&&i<n;i++)LT[i]=MO[i];
MV(;i+16<=n;i+=16)NTC(LT+i,MO+i);
MV(;i+8<=n;i+=8){
AB v=AQ((AH KK*)(MO+i));
BU((AB*)(LT+i),v);
}
MV(;i<n;i++)LT[i]=MO[i];
FF();
}
AK KK untr_tile_avx(AH MW*in,MW*out,MX A0,MX B0,MX IS,MX GK){
MV(MX u0=0;u0<TS;u0+=8){
MV(MX v0=0;v0<TS;v0+=16){
AB r[8];
MV(MX k=0;k<8;k++)
r[k]=AQ((AH KK*)(KJ((KI)(A0+u0+k)*IS+B0+v0)));
KT(r);
MV(MX k=0;k<8;k++)
BH((KK*)(KM+(v0+k)*TS+u0),r[k]);
{
MX v0b=v0+8;
AB r2[8];
MV(MX k=0;k<8;k++)
r2[k]=AQ((AH KK*)(KJ((KI)(A0+u0+k)*IS+B0+v0b)));
KT(r2);
MV(MX k=0;k<8;k++)
BH((KK*)(KM+(v0b+k)*TS+u0),r2[k]);
}
}
}
MV(MX v=0;v<TS;v++){
MW*d=out+(MU)(B0+v)*GK+A0;
AH MW*s=KM+v*TS;
MV(MX u=0;u<TS;u+=16)NTC(d+u,s+u);
}
}
AK KK EW(MW*tw,MW*MR,MX L,MW w){
MX LZ=0;
MV(MX MQ=2;MQ<=L;MQ<<=1){
MW wl=pw(w,(MW)(L/MQ));
MW c=1;
MX h=MQ>>1;
MV(MX j=0;j<h;j++){tw[LZ+j]=c;MR[LZ+j]=EV(c);c=mm(c,wl);}
LZ+=h;
}
}
#pragma GCC pop_options
#endif
AK MW R3F[2],R3FS[2];
AK MW R3I[2],R3IS[2];
AK MW T3F_[2][M3_+16],T3FS_[2][M3_+16];
#define T3F T3F_[0]
#define T3FS T3FS_[0]
AK MW T3I[2*M3_],T3IS[2*M3_];
AK MW tsubFw[M3_+8],tsubFsw[M3_+8],tsubIw[M3_+8],tsubIsw[M3_+8];
AK MW KX[4][M3_+64]AZ((GP(64)));
AK MW TT3I[2*M3_+128]AZ((GP(64))),TT3IS[2*M3_+128]AZ((GP(64)));
AK MW RTF[NR_+80]AZ((GP(64))),RTI[NR_+64]AZ((GP(64))),RWS[2*NR_+144]AZ((GP(64)));
AK KK build_radix3(MW KY){
AH MW H2=(P+1u)/2u;
MW w3=pw(KY,(MW)(NC_/3));
MW w32=mm(w3,w3);
MW cA=(MW)(P-H2);
MW cP=mm((MW)(((MU)w3+P-w32)%P),H2);
R3F[0]=cA;R3F[1]=cP;
R3I[0]=cA;R3I[1]=(cP?P-cP:0);
MV(MX i=0;i<2;i++){R3FS[i]=EV(R3F[i]);R3IS[i]=EV(R3I[i]);}
MV(MX s=1;s<3;s++){
MW g=pw(KY,(MW)s),gi=pw(g,P-2u),c=1,ci=1;
MW*pf=T3F_[s-1],*pf2=T3FS_[s-1];
MW*pi=T3I+(s-1)*M3_,*pi2=T3IS+(s-1)*M3_;
MV(MX j=0;j<(MX)M3_;j++){pf[j]=c;pf2[j]=EV(c);c=mm(c,g);
pi[j]=ci;pi2[j]=EV(ci);ci=mm(ci,gi);}
}
EW(tsubFw,tsubFsw,(MX)M3_,pw(KY,3));
EW(tsubIw,tsubIsw,(MX)M3_,pw(pw(KY,3),P-2u));
}
#pragma GCC push_options
#pragma GCC target("avx2,tune=skylake")
AK BR AZ((BK))AB vaddm(AB a,AB b,AB Pv){
AB s=AA(a,b);
BD AD(s,AC(s,Pv));
}
AK BR AZ((BK))AB vsubm(AB a,AB b,AB Pv){
AB d=AC(a,b);
BD AD(d,AA(d,Pv));
}
template<unsigned mod=0>AK BR AZ((BK))KK  prime_dft3(AB*v,AH AB*c,
AH AB*cs,AB Pv){
AB A=vaddm(v[1],v[2],Pv);
AB B=AA(AC(v[1],v[2]),Pv);
AH AB JP=FB(A,31);
AH AB KZ=_mm256_castps_si256(_mm256_blendv_ps(CH(Pv),
CH(AF((MX)((mod-1u)/2u))),CH(JP)));
AB T=AC(KZ,_mm256_srli_epi32(A,1));
AB U=EJ(B,c[1],cs[1]);
AB X0=vaddm(v[0],A,Pv);
AB Z=vaddm(v[0],T,Pv);
v[0]=X0;v[1]=AA(Z,U);v[2]=AA(AC(Z,U),Pv);
}
AK BR AZ((BK))KK dft3(AB*v,AH AB*c,
AH AB*cs,AB Pv){if(P==2013265921u)prime_dft3<2013265921u>(v, c, cs, Pv);else prime_dft3<1811939329u>(v, c, cs, Pv);}
AK KK col_dif3_head(MW*x){
AH AB Pv=AF((MX)P);
AB c[2],cs[2];
MV(MX i=0;i<2;i++){c[i]=AF((MX)R3F[i]);cs[i]=AF((MX)R3FS[i]);}
MV(MX j=0;j<(MX)M3_;j+=8){
AB v[3];
MV(MX i=0;i<3;i++)v[i]=AQ((AH KK*)(x+(MU)i*M3_+j));
dft3(v,c,cs,Pv);
BH((KK*)(x+j),v[0]);
MV(MX s=1;s<3;s++){
AB w=AQ((AH KK*)(T3F_[s-1]+j));
AB ws=AQ((AH KK*)(T3FS_[s-1]+j));
BH((KK*)(x+(MU)s*M3_+j),DQ(v[s],w,ws));
}
}
}
AK KK col_dif3(MW*x){
col_dif3_head(x);
MV(MX s=0;s<3;s++)DV(x+(MU)s*M3_,(MX)M3_,KX[0]+16,KX[1]+16);
}
AK BR AZ((BK))KK dft3z(AB*v,AH AB*c,
AH AB*cs,AB Pv){
AB A=vaddm(v[1],v[2],Pv);
AB B=AA(AC(v[1],v[2]),Pv);
AH AB JP=FB(A,31);
AH AB KZ=_mm256_castps_si256(_mm256_blendv_ps(CH(Pv),
CH(AF((MX)((P-1u)/2u))),CH(JP)));
AB T=AC(KZ,_mm256_srli_epi32(A,1));
AB U=EJ(B,c[1],cs[1]);
AH AB v0=v[0];
v[0]=AA(v0,A);
AB Z=vaddm(v0,T,Pv);
v[1]=AA(Z,U);
v[2]=AA(AC(Z,U),Pv);
}
#define N02Q_TAILROW(J) do { \
AB v[3],w,ws; \
v[0] = AQ((AH KK *)(x + (J))); \
MV (MX s = 1; s < 3; s++) { \
w = AQ((AH KK *)(TT3I + 16 + (s - 1) * M3_ + (J))); \
ws = AQ((AH KK *)(TT3IS + 16 + (s - 1) * M3_ + (J))); \
v[s] = DQ(AQ((AH KK *)(x + (MU)s * M3_ + (J))), w, ws); \
} \
dft3z(v, c, cs, Pv); \
MV (MX i = 0; i < 3; i++) BH((KK *)(x + (MU)i * M3_ + (J)), v[i]); \
} JX (0)
AK KK GQ(MW*x){
AH AB Pv=AF((MX)P);
AB c[2],cs[2];
MV(MX i=0;i<2;i++){c[i]=AF((MX)R3I[i]);cs[i]=AF((MX)R3IS[i]);}
MV(MX j=0;j<(MX)M3_;j+=16){
N02Q_TAILROW(j);
N02Q_TAILROW(j+8);
}
}
AK KK col_dit3(MW*x){
MV(MX s=0;s<3;s++)FK(x+(MU)s*M3_,(MX)M3_,KX[2]+16,KX[3]+16);
GQ(x);
}
template<unsigned mod=0>AK BR AZ((BK))KK  prime_FM(AH MW*t0,AH MW*t1,AH MW*t2,
MW*d0,MW*d1,MW*d2,MX Ab,AH AB*hc,AH AB*hcs){
AH AB Pvh=AF((MX)mod);
KO hf=[&](MX u,AB&o0,AB&o1,AB&o2){
AB vv[3];
vv[0]=AQ((AH KK*)(t0+u));vv[1]=AQ((AH KK*)(t1+u));vv[2]=AQ((AH KK*)(t2+u));
prime_dft3<mod>(vv,hc,hcs,Pvh);
o0=vv[0];
o1=DQ<mod>(vv[1],AQ((AH KK*)(T3F+Ab+u)),AQ((AH KK*)(T3FS+Ab+u)));
o2=DQ<mod>(vv[2],AQ((AH KK*)(T3F_[1]+Ab+u)),AQ((AH KK*)(T3FS_[1]+Ab+u)));
};
MV(MX u=0;u<TS;u+=16){
AB p0,p1,p2,q0,q1,q2;hf(u,p0,p1,p2);hf(u+8,q0,q1,q2);
if((((GA)d0|(GA)d1|(GA)d2)&63u)==0u){
NT2(d0+u,p0,q0);NT2(d1+u,p1,q1);NT2(d2+u,p2,q2);
}else{
BH(d0+u,p0);BH(d0+u+8,q0);BH(d1+u,p1);
BH(d1+u+8,q1);BH(d2+u,p2);BH(d2+u+8,q2);
}
}
}
AK BR AZ((BK))KK FM(AH MW*t0,AH MW*t1,AH MW*t2,
MW*d0,MW*d1,MW*d2,MX Ab,AH AB*hc,AH AB*hcs){if(P==2013265921u)prime_FM<2013265921u>(t0, t1, t2, d0, d1, d2, Ab, hc, hcs);else prime_FM<1811939329u>(t0, t1, t2, d0, d1, d2, Ab, hc, hcs);}
template<unsigned mod=0>AK KK  prime_FV(AH MW*tile0,AH MW*tile1,AH MW*tile2,MW*X,MX B0,MX Ab,MX FZ){
AH MX AM=NC_/3,GK=CSX_;
AB hc[2],hcs[2];
MV(MX i=0;i<2;++i){hc[i]=AF((MX)R3F[i]);hcs[i]=AF((MX)R3FS[i]);}
MV(MX v=0;v<TS;v++){
AH MW*t0=tile0+v*TS,*t1=tile1+v*TS,*t2=tile2+v*TS;
AH MU HP=(MU)(B0+v)*GK+Ab;
MW*d0=FZ?KJ((KI)HP):X+HP;
MW*d1=FZ?KJ((KI)(HP+AM)):X+HP+AM;
MW*d2=FZ?KJ((KI)(HP+2*(KI)AM)):X+HP+2*AM;
prime_FM<mod>(t0,t1,t2,d0,d1,d2,Ab,hc,hcs);
}
}
AK KK FV(AH MW*tile0,AH MW*tile1,AH MW*tile2,MW*X,MX B0,MX Ab,MX FZ){if(P==2013265921u)prime_FV<2013265921u>(tile0, tile1, tile2, X, B0, Ab, FZ);else prime_FV<1811939329u>(tile0, tile1, tile2, X, B0, Ab, FZ);}
AK KK col_convolve3(MW*a,MW*b){
MV(MX arm=0;arm<3;++arm){
MW*pa=a+(MU)arm*M3_,*pb=b+(MU)arm*M3_;
DV<ED,KR>(pa,(MX)M3_,KX[0]+16,KX[1]+16);
DV(pb,(MX)M3_,KX[0]+16,KX[1]+16);
if(arm==0)FK<KR>(pa,(MX)M3_,KX[2]+16,KX[3]+16,pb);
else FK<KR,KR>(pa,(MX)M3_,KX[2]+16,KX[3]+16,pb);
}
GQ(a);
}
#pragma GCC pop_options
BG<KL Trim=ED>AK KK row_dit(MW*x,MX L,AH MW*tw,AH MW*MR){
#if HAVE_AVX2
FK<ED,ED,Trim>(x,L,tw,MR);
BD;
#else
(KK)MR;
#endif
MX LZ=0;
MV(MX MQ=2;MQ<=L;MQ<<=1){
MX h=MQ>>1;
AH MW*t=tw+LZ;LZ+=h;
MV(MX i=0;i<L;i+=MQ){
MW*p=x+i,*q=x+i+h;
MV(MX j=0;j<h;j++){
MW u=p[j],v=mm(q[j],t[j]);
MW s=u+v;if(s>=P)s-=P;
MW d=u+P-v;if(d>=P)d-=P;
p[j]=s;q[j]=d;
}
}
}
}
AK KK pointwise(MW*A,AH MW*B,MW n,MW sc,MW sx){
#if HAVE_AVX2
pointwise_mul_avx(A,B,n,sc,sx);
BD;
#else
MV(KI i=0;i<(KI)n;i++){KI o=(i/(KI)(sx-PADC_))*sx+(i%(KI)(sx-PADC_));A[o]=mm(mm(A[o],B[o]),sc);}
#endif
}
AK KK row_dif(MW*x,MX L,AH MW*tw,AH MW*MR){
#if HAVE_AVX2
DV(x,L,tw,MR);
BD;
#else
(KK)MR;
#endif
MV(MX MQ=L;MQ>=2;MQ>>=1){
MX h=MQ>>1;
AH MW*t=tw+h-1;
MV(MX i=0;i<L;i+=MQ){
MW*p=x+i,*q=x+i+h;
MV(MX j=0;j<h;j++){
MW u=p[j],v=q[j];
MW s=u+v;if(s>=P)s-=P;
MW d=u+P-v;if(d>=P)d-=P;
p[j]=s;q[j]=mm(d,t[j]);
}
}
}
}
AK BR KK bitrev_pass(MW*x,MX L,AH u16*br){
MV(MX i=0;i<L;i++){
MX k=br[i];
if(i<k){MW t=x[i];x[i]=x[k];x[k]=t;}
}
}
JS Eng{
MX R,C,N,sx;
MX blkr;
MX r5;
MW w;
MW*tfR;MW*tiR;MW*tfC;MW*tiC;
MW*wsR;MW*wsC;
u16*brR;u16*brC;
};
AK KK col_dif3_arms(MW*x){
MV(MX s=0;s<3;s++)DV(x+(MU)s*M3_,(MX)M3_,KX[0]+16,KX[1]+16);
}
AK KK colfwd(Eng&e,MW*row){
#if HAVE_AVX2
if(e.r5){col_dif3_arms(row);BD;}
#endif
row_dif(row,e.C,e.tfC,e.wsC);
}
AK KK colinv(Eng&e,MW*row){
#if HAVE_AVX2
if(e.r5){col_dit3(row);BD;}
#endif
row_dit(row,e.C,e.tiC,e.wsC+e.C);
}
AK KK load_T(Eng&e,AH MW*MO,MW KW,MW*S,MX LU){
AH MX R=e.R,C=e.C;
#if HAVE_AVX2
if(KW<=(MW)R*(MW)C){
MV(MX r0=0;r0<R;r0+=TS){
MU tilerow=(MU)r0*C;
MV(MX c0=0;c0<C;c0+=TS){
MU IX=tilerow+c0;
MU IL=(MU)(r0+TS-1)*C+c0+TS-1;
if(IL<KW){GO(MO,S,r0,c0,R,C,LU,0);IA;}
if(IX>=KW){GO(MO,S,r0,c0,R,C,LU,1);IA;}
MV(MX rb=0;rb<TS;rb++){
MU KZ=(MU)(r0+rb)*C+c0;
MV(MX cb=0;cb<TS;cb++){
MU id=KZ+cb;
MW v=0;
if(id<KW){v=FT(MO,id);if(CM){DS z=DS(v)-2147483648ll;z%=P;if(z<0)z+=P;v=AX(z);}else{if(v>=P)v-=P;if(v>=P)v-=P;}if(LU)v=(v>=4u)?(v-4u):(v+(P-4u));}
KM[cb*TS+rb]=v;
}
}
MV(MX cb=0;cb<TS;cb++){
MW*d=S+(MU)(c0+cb)*R+r0;
AH MW*s=KM+cb*TS;
MV(MX rb=0;rb<TS;rb++)d[rb]=s[rb];
}
}
}
BD;
}
#endif
MV(MX r0=0;r0<R;r0+=TS){
MV(MX c0=0;c0<C;c0+=TS){
MU IL=(MU)(r0+TS-1)*C+(c0+TS-1);
if(IL<KW){
MV(MX rb=0;rb<TS;rb++){
AH MW*s=MO+(MU)(r0+rb)*C+c0;
MV(MX cb=0;cb<TS;cb++){
MW v=s[cb];
if(LU)v=(v>=4u)?(v-4u):(v+(P-4u));
KM[cb*TS+rb]=v;
}
}
}else{
MV(MX rb=0;rb<TS;rb++){
MU KZ=(MU)(r0+rb)*C+c0;
MV(MX cb=0;cb<TS;cb++){
MU id=KZ+cb;
MW v=0;
if(id<KW){v=FT(MO,id);if(CM){DS z=DS(v)-2147483648ll;z%=P;if(z<0)z+=P;v=AX(z);}else{if(v>=P)v-=P;if(v>=P)v-=P;}if(LU)v=(v>=4u)?(v-4u):(v+(P-4u));}
KM[cb*TS+rb]=v;
}
}
}
MV(MX cb=0;cb<TS;cb++){
MW*d=S+(MU)(c0+cb)*R+r0;
AH MW*s=KM+cb*TS;
MV(MX rb=0;rb<TS;rb++)d[rb]=s[rb];
}
}
}
}
AK MW REV6[TS];
AK MW GL=1u;
AK MW POWT[1024],POWT64[1024];
AK KK build_rev6(KK){
MV(MX i=0;i<TS;i++){
MX r=0;
MV(MX b=0;b<6;b++)if(i&(1<<b))r|=1<<(5-b);
REV6[i]=(MW)r;
}
}
AK BR MW IN(MW x,MX lg){
MW r=0;
MV(MX b=0;b<lg;b++)if(x&(1u<<b))r|=1u<<(lg-1-b);
BD r;
}
BG<MX perm>
AK KK GB(AH MW*in,MW*out,MX nA,MX nB,MX IS,MX GK,MW KY,MX FZ){
MW wv[TS];
{MW c=1;MV(MX v=0;v<TS;v++){wv[v]=c;c=mm(c,KY);}}
AH MW w64=pw(KY,TS);
MX lgB=0,lgA=0;
JX((1<<lgB)<nB)lgB++;
JX((1<<lgA)<nA)lgA++;
AH MX S1=nB/TS,S2=nA/TS;
AH MX HB=lgB-6,HA=lgA-6;
MW RV2[TS],RV2b[TS],PW2[TS],cu[TS],cu64[TS],KZ[TS];
MW GZ[TS],cu64_shoup[TS];
if(perm==1){
MW g=pw(KY,(MW)S1);
{MW gM=mm(g,MA),c=MA;MV(MX t=0;t<TS;t++){RV2[REV6[t]]=c;c=HN(c,gM);}}
{MW rootM=mm(KY,MA),p=MA;MV(MX t=0;t<S1;t++){POWT[t]=p;p=HN(p,rootM);}}
}else if(perm==2){
MW g=pw(KY,(MW)S2),g64=pw(g,64);
AH MW rootM2=mm(KY,MA),gM=mm(g,MA),g64M=mm(g64,MA);
{MW c=MA,c64=MA;
MV(MX t=0;t<TS;t++){RV2[REV6[t]]=c;RV2b[REV6[t]]=c64;c=HN(c,gM);c64=HN(c64,g64M);}}
{MW p=MA;MV(MX t=0;t<S2;t++){POWT[t]=p;p=HN(p,rootM2);}}
{MW q=pw(KY,64),qM=mm(q,MA),p=MA;MV(MX t=0;t<S2;t++){POWT64[t]=p;p=HN(p,qM);}}
}
MW wr=1;
AH MW INVSCALE=GL;
MV(MX A0=0;A0<nA;A0+=TS){
MW wr64=pw(wr,TS);
if(perm==1){
MW g=pw(wr,(MW)S1),gM2=mm(g,MA),c=MA;
MV(MX t=0;t<TS;t++){PW2[REV6[t]]=c;c=HN(c,gM2);}
}else if(perm==2){
MX hi=A0/TS;
MW rH=POWT[IN((MW)hi,HA)],r64H=POWT64[IN((MW)hi,HA)];
AH MW INVSCALE_M=mm(INVSCALE,MA);
MV(MX u=0;u<TS;u++){
cu[u]=HN(RV2[u],rH);cu64[u]=HN(RV2b[u],r64H);KZ[u]=INVSCALE_M;
GZ[u]=HN(cu64[u],1u);cu64_shoup[u]=EV(GZ[u]);
}
}else{
MW c=1;MV(MX v=0;v<TS;v++){PW2[v]=c;c=mm(c,wr);}
}
MW Vloc=1;
MW Vr=1;
MV(MX B0=0;B0<nB;B0+=TS){
if(perm==1){
MW H=IN((MW)(B0/TS),HB);
MW wrH=pw(wr,H),rootH=POWT[H];
MW RV[TS];
#if HAVE_AVX2
EF(RV,RV2,rootH);
EF(TW,PW2,mm(wrH,MA));
twiddle_rows_mont(TW,RV);
#else
MV(MX v=0;v<TS;v++)RV[v]=HN(RV2[v],rootH);
MV(MX v=0;v<TS;v++)TW[v]=HN(PW2[v],mm(wrH,MA));
MV(MX u=1;u<TS;u++){
AH MW*prv=TW+(u-1)*TS;
MW*LR=TW+u*TS;
MV(MX v=0;v<TS;v++)LR[v]=HN(prv[v],RV[v]);
}
#endif
}else if(perm==2){
if(B0==0){
MV(MX u=0;u<TS;u++){
MW*LR=TW+u*TS;
LR[0]=KZ[u];
MV(MX v=1;v<TS;v++)LR[v]=HN(LR[v-1],cu[u]);
}
}else{
MV(MX u=0;u<TS;u++){
MW*LR=TW+u*TS;
#if HAVE_AVX2
scale_row_prepared(LR,LR,GZ[u],cu64_shoup[u]);
#else
MW d=cu64[u];
MV(MX v=0;v<TS;v++)LR[v]=HN(LR[v],d);
#endif
}
}
}else{
MW RV[TS];
MV(MX v=0;v<TS;v++)RV[v]=mm(Vloc,wv[v]);
MV(MX v=0;v<TS;v++)TW[v]=mm(Vr,PW2[v]);
MV(MX u=1;u<TS;u++){
AH MW*prv=TW+(u-1)*TS;
MW*LR=TW+u*TS;
MV(MX v=0;v<TS;v++)LR[v]=mm(prv[v],RV[v]);
}
}
#if HAVE_AVX2
corner_tile_avx(in,out,A0,B0,IS,GK,FZ);
#else
MV(MX u=0;u<TS;u++){
AH MW*s=in+(MU)(A0+u)*IS+B0;
AH MW*tw=TW+u*TS;
MV(MX v=0;v<TS;v++)KM[u*TS+v]=HN(s[v],tw[v]);
}
MV(MX v=0;v<TS;v++){
MW*d=out+(MU)(B0+v)*GK+A0;
MV(MX u=0;u<TS;u++)d[u]=KM[u*TS+v];
}
#endif
Vr=mm(Vr,wr64);
Vloc=mm(Vloc,w64);
}
wr=mm(wr,w64);
}
}
AK BR KK corner_fwd(Eng&e,AH MW*S,MW*X,MW KY){
GB<1>(S,X,e.C,e.R,e.R,e.sx,KY,0);
}
AK BR KK corner_inv(Eng&e,AH MW*X,MW*S,MW KY){
GB<2>(X,S,e.R,e.C,e.sx,e.R,KY,1);
}
AK KK untranspose(Eng&e,AH MW*S,MW*LT){
AH MX R=e.R,C=e.C;
#if HAVE_AVX2
MV(MX c0=0;c0<C;c0+=TS)
MV(MX r0=0;r0<R;r0+=TS)
untr_tile_avx(S,LT,c0,r0,R,e.sx);
BD;
#endif
MV(MX c0=0;c0<C;c0+=TS){
MV(MX r0=0;r0<R;r0+=TS){
MV(MX u=0;u<TS;u++){
AH MW*s=S+(MU)(c0+u)*R+r0;
MW*d=KM+u*TS;
MV(MX v=0;v<TS;v++)d[v]=s[v];
}
MV(MX v=0;v<TS;v++){
MW*d=LT+(MU)(r0+v)*e.sx+c0;
MV(MX u=0;u<TS;u++)d[u]=KM[u*TS+v];
}
}
}
}
#define N02I_SB (TS * (NRMAX_ + PADB_) + 16)
AK MW SBLK[3*N02I_SB]AZ((GP(64)));
AK MW TILE3[3][TS*TS+32]AZ((GP(64)));
#pragma GCC push_options
#pragma GCC target("avx2,tune=skylake")
AK MW GRV2[TS],GPOWT[NR_/TS];
AK MW GRV[TS][TS];
AK AB GSF[TS][TS/8],GSS[TS][TS/8];
AK MW GWRHM[256][3][NR_/TS],GPW2[256][3][TS];
AK MX HQ=0;AK MW HR=0;
AK KK fwd_prep1(MW KY){
if(HQ&&HR==KY)BD;
HQ=1;HR=KY;
AH MX S1=NR_/TS;
{MW g=pw(KY,(MW)S1),gM=mm(g,MA),c=MA;
MV(MX t=0;t<TS;t++){GRV2[REV6[t]]=c;c=HN(c,gM);}}
{MW rootM=mm(KY,MA),p=MA;
MV(MX t=0;t<S1;t++){GPOWT[t]=p;p=HN(p,rootM);}}
MV(MX H=0;H<S1;++H){EF(GRV[H],GRV2,GPOWT[H]);ET(GRV[H],GSF[H],GSS[H]);}
AH MX AM=NC_/3;
MV(MX Ai=0,Ab=0;Ab<AM;Ab+=TS,++Ai){
MV(MX p=0;p<3;p++){
AH MX A0=Ab+p*AM;AH MW wr=pw(KY,(MW)A0);
{AH MW wrM=mm(wr,MA);MW val=MA;MV(MX h=0;h<S1;++h){GWRHM[Ai][p][h]=val;val=HN(val,wrM);}}
{MW g=pw(wr,(MW)S1),gM2=mm(g,MA),c=MA;MV(MX t=0;t<TS;t++){GPW2[Ai][p][REV6[t]]=c;c=HN(c,gM2);}}
}
}
}
#pragma GCC pop_options
AK KK corner_fwd_stream(Eng&e,AH MW*MO,MW KW,MW*X,MX FZ,MX LU){
AH MX nA=(MX)NC_,nB=(MX)NR_,IS=(MX)(NR_+PADB_),GK=(MX)CSX_;
AH MW KY=e.w;
MX lgB=0;JX((1<<lgB)<nB)lgB++;
AH MX S1=nB/TS,HB=lgB-6;
fwd_prep1(KY);
AH KL halfzero=(nB==4096&&(MU)KW<=(MU)(nB/2)*nA);
AH MX AM=nA/3;
MV(MX Ab=0;Ab<AM;Ab+=TS){
AH MX Ai=Ab/TS;
MV(MX p=0;p<3;p++){
MW*S=SBLK+(MU)p*N02I_SB;
AH MX A0=Ab+p*AM;
load_block(MO,KW,S,A0,halfzero?nB/2:nB,nA,IS,LU);
MV(MX u=0;u<TS;++u){
if(halfzero)DV<KR,KR>(S+(MU)u*IS,nB,e.tfR,e.wsR);
else row_dif(S+(MU)u*IS,nB,e.tfR,e.wsR);
}
}
MV(MX B0=0;B0<nB;B0+=TS){
MW H=IN((MW)(B0/TS),HB);
AH AB*EN=GSF[H];AH AB*FU=GSS[H];
MV(MX p=0;p<3;p++){
EF(TW,GPW2[Ai][p],GWRHM[Ai][p][H]);
FL(TW,EN,FU);
corner_tile_avx_to(SBLK+(MU)p*N02I_SB,TILE3[p],B0,IS);
}
FV(TILE3[0],TILE3[1],TILE3[2],X,B0,Ab,FZ);
}
}
}
AK KK fwd(Eng&e,AH MW*MO,MW KW,MW*S,MW*X,MX FZ,MX LU){
#ifdef OLD_FWD
load_T(e,MO,KW,S,LU);
MV(MX j0=0;j0<e.C;j0++){
MW*row=S+(MU)j0*e.R;
row_dif(row,e.R,e.tfR,e.wsR);
}
corner_fwd(e,S,X,e.w);
#else
(KK)S;
{corner_fwd_stream(e,MO,KW,X,FZ,LU);}
#endif

}
AK KK LV(Eng&e,MW*X,MW*S){MV(MX k0=0;k0<e.R;k0++)colinv(e,X+(MU)k0*e.sx);
corner_inv(e,X,S,pw(e.w,P-2u));
MV(MX j0=0;j0<e.C;j0++){
MW*row=KJ((KI)j0*e.R);
row_dit(row,e.R,e.tiR,e.wsR+e.R);
}
}
AK MW INV_TW[NRMAX_*TS]AZ((GP(64)));
AK MW IY[NRMAX_],GC[NRMAX_];
#pragma GCC push_options
#pragma GCC target("avx2,tune=skylake")
BG<KL Advance>
AK BR AZ((BK))KK EZ(Eng&e,MW*X,MX r0,MX c0){
(KK)e;
AH KI SXF_=(KI)CSX_,BLF_=(KI)(NR_+PADB_);
MV(MX u0=0;u0<TS;u0+=8){
MV(MX v0=0;v0<TS;v0+=8){
{AH MW*pf=X+(MU)(r0+u0+8)*SXF_+c0+v0;
MV(MX k=0;k<8;k++)AP((AH KV*)(pf+(MU)k*SXF_),AW);}
AB LA[8];
{
AH MW*sbase=X+(MU)(r0+u0)*SXF_+c0+v0;
MW*tbase=INV_TW+(r0+u0)*(KI)TS+v0;
MW*sblkbase=SBLK+(MU)v0*BLF_+r0+u0;
MV(MX k=0;k<8;++k){
AH MW*MO=sbase+(MU)k*SXF_;
MW*tw=tbase+(KI)k*TS;
AB w=AQ(tw);
if AL(Advance){
AH MX j=r0+u0+k;
BH(tw,EJ(w,AF((MX)IY[j]),
AF((MX)GC[j])));
}
LA[k]=KG(AQ(MO),w);
}
KT(LA);
MV(MX k=0;k<8;++k)
BH(sblkbase+(MU)k*BLF_,LA[k]);
}
}
}
}
template<bool emit>AK KK inv_natural_stream(Eng&e,MW*X,MW*out){

AH MW KY=pw(e.w,P-2u);
AH MW seed=mm(mm(GL,MA),MA);
MX lg=0;JX((1<<lg)<e.R)++lg;
MV(MX k=0;k<e.R;++k){
AH MW DG=pw(KY,IN(k,lg));
AH MW factorM=mm(DG,MA);
IY[k]=pw(DG,TS);
GC[k]=EV(IY[k]);
MW*tw=INV_TW+k*TS;
MW f8=factorM;MV(MX q=0;q<3;++q)f8=HN(f8,f8);MW b0=seed;MV(MX r=0;r<8;++r){MW b=b0;MV(MX m=0;m<8;++m){tw[m*8+r]=b;b=HN(b,f8);}b0=HN(b0,factorM);}
}
MV(MX c0=0;c0<e.C;c0+=TS){
MV(MX r0=0;r0<e.R;r0+=TS){
EZ<KR>(e,X,r0,c0);
}
MV(MX v=0;v<TS;++v)
row_dit<KR>(SBLK+(MU)v*e.blkr,e.R,e.tiR,e.wsR+e.R);
{
AH KI SXF_=emit?(KI)NC_:(KI)CSX_,BLF_=(KI)(NR_+PADB_);
MV(MX r0=0;r0<2040;r0+=TS){
MV(MX v0=0;v0<TS&&r0+v0<2035;v0+=8){
{
AH MW*sbase=SBLK+(MU)(r0+v0);
MW*dbase=(emit?out:X)+(MU)(r0+v0)*SXF_+c0;
MV(MX u0=0;u0<TS;u0+=16){
AH MW*sp=sbase+(MU)u0*BLF_;
AB LA[8];
MV(MX k=0;k<8;++k)
LA[k]=AQ(sp+(MU)k*BLF_);
KT(LA);
MV(MX k=0;k<8;++k)BH(KM+k*8,LA[k]);
MV(MX k=0;k<8;++k)
LA[k]=AQ(sp+(MU)(8+k)*BLF_);
KT(LA);
MV(MX k=0;k<8;++k){
MW*LT=dbase+(MU)k*SXF_+u0;
if constexpr(emit){if((MU)(r0+v0+k)*NC_+c0+u0<ENGINE_N){BU((AB*)LT,AQ(KM+k*8));BU((AB*)(LT+8),LA[k]);}}else{BU((AB*)LT,AQ(KM+k*8));
BU((AB*)(LT+8),LA[k]);}
}
}
}
}
}
}
}
FF();
}
AK KK fuse4_row_avx(MW*pa,AH MW*pb,MX n){
MX i=0;
MV(;i+8<=n;i+=8){
AB x=AQ((AH KK*)(pa+i));
AB y=AQ((AH KK*)(pb+i));
BH((KK*)(pa+i),DQ(x,y,GJ(y)));
}
MV(;i<n;i++)pa[i]=mm(pa[i],pb[i]);
}
#pragma GCC pop_options
AK KK eng_init(Eng&e,MX lgR,MX nC,MW w,MX sx,
MW*tfR,MW*tiR,MW*tfC,MW*tiC,u16*brR,u16*brC,
MW*wsR,MW*wsC){
e.R=1<<lgR;e.C=nC;e.N=e.R*e.C;e.w=w;e.sx=sx;
e.blkr=e.R+PADB_;
e.r5=(nC==(MX)NC_);
e.tfR=tfR;e.tiR=tiR;e.tfC=tfC;e.tiC=tiC;e.brR=brR;e.brC=brC;
e.wsR=wsR;e.wsC=wsC;
MW wR=pw(w,(MW)e.C),wC=pw(w,(MW)e.R);
#if HAVE_AVX2
EW(tfR,e.wsR,e.R,wR);EW(tiR,e.wsR+e.R,e.R,pw(wR,P-2u));
if(!e.r5){EW(tfC,e.wsC,e.C,wC);EW(tiC,e.wsC+e.C,e.C,pw(wC,P-2u));}
#else
GX(tfR,e.R,wR);GX(tiR,e.R,pw(wR,P-2u));
GX(tfC,e.C,wC);GX(tiC,e.C,pw(wC,P-2u));
#endif
build_br(brR,e.R);
if(!e.r5)build_br(brC,e.C);
build_rev6();
}
#pragma GCC push_options
#pragma GCC target("avx2,tune=skylake")
AK BR AZ((BK))AB scan8(AB v,AB&JY){
v=AA(v,BY(v,4));
v=AA(v,BY(v,8));
AB t=AE(BB(),v,0x20);
t=AI(t,0xFF);
v=AA(v,t);
v=AA(v,JY);
JY=BE(v,AF(7));
BD v;
}
AK MW*Aarr;
#if (NR_ * CSX_) > BSTAIL_SPLIT
#define BTAILN_ ((MX)((NR_ * CSX_) - BSTAIL_SPLIT))
#else
#define BTAILN_ 1
#endif
AK MW*BTAIL;
AK AL AJ FW=2ull*NR_*CSX_;AK AL AJ ARMPAD_=2048;AK AJ g_AS=0;
AK Eng E1,E2;
AK MW t1fR[NR_],t1iR[NR_],t1fC[1],t1iC[1];
AK u16 b1R[NR_],b1C[1];
AK MW w1R[2*NR_],w1C[2];
AK MW t2fR[NR2_],t2iR[NR2_],t2fC[NC2_],t2iC[NC2_];
AK u16 b2R[NR2_],b2C[NC2_];
AK MW w2R[2*NR2_],w2C[2*NC2_];
AK MX inited=0;
AK KK GD(AH AX*a,AH AX*b,AX*c,AX*workspace,AX modulus,AX generator,KL borrow_C,KL balanced,KL reverse_first=ED){
ES=a;Aarr=workspace;BTAIL=workspace+AJ(NR_)*CSX_;P=modulus;G=generator;MA=(1ull<<32)%P;IM=~0ull/(MU)P;SHMAGIC=MW(IM-(2ull<<32));
{MU LV=1;MV(MX i=0;i<5;i++)LV=LV*(2-(MU)P*LV);NPI=(MW)(-(MU)LV);
MW w1=pw(G,(MW)((P-1)/N1_));eng_init(E1,LGR_,(MX)NC_,w1,(MX)CSX_,t1fR,t1iR,t1fC,t1iC,b1R,b1C,w1R,w1C);
GW(RTF+16,t1fR,(AJ)NR_*4);GW(RTI+16,t1iR,(AJ)NR_*4);GW(RWS+16,w1R,(AJ)(2*NR_)*4);E1 .tfR=RTF+16;E1 .tiR=RTI+16;E1 .wsR=RWS+16;E1 .r5=1;
build_radix3(pw(w1,(MW)E1 .R));GW(TT3I+16,T3I,(AJ)(2*M3_)*4);GW(TT3IS+16,T3IS,(AJ)(2*M3_)*4);GW(KX[0]+16,tsubFw,(AJ)M3_*4);GW(KX[1]+16,tsubFsw,(AJ)M3_*4);GW(KX[2]+16,tsubIw,(AJ)M3_*4);GW(KX[3]+16,tsubIsw,(AJ)M3_*4);}
g_B=borrow_C?c:BTAIL;g_BT=borrow_C?BTAIL:BTAIL+BSTAIL_SPLIT;GL=pw(N1_%P,P-2u);JK=1;fwd(E1,a,ENGINE_N,c,Aarr,0,0);fwd(E1,b,ENGINE_N,c,c,1,0);
MV(AX r=0;r<NR_;++r)col_convolve3(Aarr+(MU)r*CSX_,KJ((KI)r*CSX_));if(borrow_C)inv_natural_stream<true>(E1,Aarr,c);else inv_natural_stream<false>(E1,Aarr,nullptr);JK=0;
FF();
}
AK BR AX fast_residue(AX k){BD Aarr[AOFF(k)];}
#pragma GCC pop_options
#undef TS
#pragma once
AL KO statement="Do NOT modify this statement! "
"https://github.com/With-Sky/HintFFT "
"TSKY (WithSky)";
#pragma GCC target("avx2,fma")
#include <immintrin.h>
#include <cstdint>
#include <cstring>
static inline __m256i ar_crt_mod8(__m256i r1,__m256i r2){const __m256i p=_mm256_set1_epi32(1811939329);__m256i v=_mm256_sub_epi32(_mm256_and_si256(r1,_mm256_set1_epi32(0x7fffffff)),r2);v=_mm256_add_epi32(v,_mm256_and_si256(_mm256_srai_epi32(v,31),p));__m256i q=_mm256_mulhi_epu16(_mm256_srli_epi32(v,26),_mm256_set1_epi16(21846));__m256i t=_mm256_sub_epi32(_mm256_add_epi32(v,_mm256_slli_epi32(v,3)),_mm256_mullo_epi32(q,p));return _mm256_add_epi32(t,_mm256_and_si256(_mm256_srai_epi32(t,31),p));}
static inline __m256i ar_alpha8(__m256i r,__m256i t){__m256i h=_mm256_srli_epi32(_mm256_add_epi32(t,_mm256_set1_epi32(3538943)),18),q=_mm256_srli_epi16(_mm256_mulhi_epu16(h,_mm256_set1_epi16(4855)),1);unsigned m=_mm256_movemask_ps(_mm256_castsi256_ps(_mm256_cmpeq_epi32(_mm256_and_si256(t,_mm256_set1_epi32(131071)),_mm256_setzero_si256())));if(m){alignas(32)uint32_t rr[8],tt[8],qq[8];_mm256_store_si256((__m256i*)rr,r);_mm256_store_si256((__m256i*)tt,t);_mm256_store_si256((__m256i*)qq,q);while(m){unsigned i=__builtin_ctz(m);m&=m-1;qq[i]=((uint64_t(tt[i])<<9)+1811939329ull+((uint64_t(rr[i])<<9)/2013265921ull))/(2ull*1811939329);}q=_mm256_load_si256((const __m256i*)qq);}return q;}
BR KK initialize_crt4(AX n,AX*c,AX KV*IU,AH AX*grid,AX rowLength,AX AU,const AX*a,const AX*b){AB JP=BB();const __m256i zero=_mm256_setzero_si256(),p1=_mm256_set1_epi32(2013265921),prod=_mm256_set1_epi32(uint32_t(2013265921ull*1811939329)),high=_mm256_set1_epi32(0x80000000u);const AX*gp=grid;AX cl=0;for(AX k=0;k<n;k+=8){AB x=AO(DU(a,k),DU(b,k));
x=AO(x,BY(x,4));x=AO(x,BY(x,8));
AB lower=BE(x,AF(3));
x=AO(x,AT(BB(),lower,0xf0));x=AO(x,JP);
JP=BE(x,AF(7));
__m256i orig=CS(AQ((const __m256i*)(c+k)),FB(x,31)),r=_mm256_andnot_si256(high,orig),t=ar_crt_mod8(orig,AQ((const __m256i*)(gp+cl))),q=ar_alpha8(r,t);__m256i o=_mm256_add_epi32(r,_mm256_mullo_epi32(t,p1));o=_mm256_sub_epi32(o,_mm256_and_si256(_mm256_cmpgt_epi32(q,zero),prod));o=_mm256_add_epi32(o,_mm256_and_si256(orig,high));BH((__m256i*)(c+k),o);q=_mm256_and_si256(_mm256_sub_epi32(zero,q),_mm256_set1_epi32(255));__m128i p=_mm_packus_epi32(_mm256_castsi256_si128(q),_mm256_extracti128_si256(q,1));p=_mm_packus_epi16(p,_mm_setzero_si128());_mm_storel_epi64((__m128i*)(IU+k),p);cl+=8;if(cl==rowLength){cl=0;gp+=AU;}}}
AK KK exact_convolution(AH AX*a,AH AX*b,AX*c,KL minus){
AL AX n=ENGINE_N;
AL AX p1=2013265921,p2=1811939329;
KO va=[&](AX i)->AX{
BD a[minus?n-1-i:i];
};
KO vb=[&](AX i)->AX{
BD b[i];
};
AX*w=DT;AX KV*IU=DT;
if(posix_memalign((KK**)&w,64,FW*4)||posix_memalign((KK**)&IU,64,n))__builtin_trap();thphint(w,(size_t)FW*4);thphint(IU,(size_t)n);
GD(a,b,c,w,p1,31,KR,KR,minus);
GD(a,b,c,w,p2,13,ED,KR,minus);
initialize_crt4(n,c,IU,Aarr,NC_,CSX_,a,b);
coarse32::mixed<25>(n,a,b,c,IU,minus,1811939329,(float*)w);
free(w);
if(minus)MP::HC(c,c+n);
free(IU);
}
KK convolution(AX n,AH AX*a,AH AX*b,AX*c){assert(n==ENGINE_N);exact_convolution(a,b,c,ED);}

CompilationN/AN/ACompile OKScore: N/A

Testcase #18.021 s2020 MB + 976 KBAcceptedScore: 100


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