// File: asd00012334[P]Abstract-Algebra-2018/main.cpp
// Function: SplitDegree(Polynomial<prime::IntType, int> const&, int)
std::map<DegreeList,int> SplitDegree(Polynomial<prime::IntType, int> const& f,int N){
    using namespace std;
    using namespace prime;
	
	if(f.degree()==0) throw std::exception();
    
	std::map<DegreeList, int> out;
    IntType intType;
    Polynomial<prime::IntType, int> x(&intType,vector<int>{0,1});
    for(int i=0;i<N;++i){
        int p = primeList[i];
        Zp zp(p);
        Polynomial<Zp,ZpElement> g = f % zp, xp = x % zp;
        Polynomial<Zp,ZpElement> nonDeterminant = x % zp;
        DegreeList a;
        int gdegree = g.degree(), totalDegree=0;
        for(int deg=1;totalDegree<gdegree;++deg){
            /// Distinct degree factorization
            /// x^p^deg mod g
            nonDeterminant = powerMod(nonDeterminant,p,g);
            a.push_back(0);
            while(totalDegree<gdegree){
                auto factor = gcd(nonDeterminant-xp,g);
                //std::cout<<"gcd( "<<nonDeterminant-xp<<", "<<g<<" ) = "<<factor<<"\n";
                g = g / factor;
                int partDegree = factor.degree();
                //std::cout<<partDegree<<"partDegree\n";
                if(partDegree == 0) break;
                totalDegree += partDegree;
                a.back()+=partDegree/deg;
            }
        }
		if(a.size()==0) a.push_back(0);
		a[0] += f.degree() - gdegree;
        if(out.count(a)) out[a]+=1; else out[a] = 0;
    }
    int id = out[std::vector<int>{f.degree()}];
    for(auto &e: out) e.second=round((double)e.second/id);
    return out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x2b8(%rbp)
movq %rdi, %rax
movq %rax, -0x2b0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4e50
cmpl $0x0, %eax
jne 0x2de8
movl $0x8, %edi
callq 0x20d0
movq %rax, %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x4ed0
movq -0x2c0(%rbp), %rdi
movq 0x1d1fc(%rip), %rsi     # 0x1ffd8
movq 0x1d20d(%rip), %rdx     # 0x1fff0
callq 0x22d0
movq -0x2b8(%rbp), %rdi
movb $0x0, -0x15(%rbp)
callq 0x4ef0
movl $0x0, -0x70(%rbp)
movl $0x1, -0x6c(%rbp)
leaq -0x70(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x2, -0x60(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x4f10
movq -0x2c8(%rbp), %rcx
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x4f30
jmp 0x2e40
leaq -0x40(%rbp), %rdi
leaq -0x16(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x4fb0
jmp 0x2e53
leaq -0x58(%rbp), %rdi
callq 0x5020
leaq -0x71(%rbp), %rdi
callq 0x5080
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3402
movslq -0x88(%rbp), %rcx
leaq 0x801d334(%rip), %rax   # 0x80201c0
movl (%rax,%rcx,4), %eax
movl %eax, -0x8c(%rbp)
movslq -0x8c(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x2550
jmp 0x2eaa
movq -0x10(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
leaq -0x98(%rbp), %rdx
callq 0x2840
jmp 0x2ec3
leaq -0xe8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x2840
jmp 0x2edc
leaq -0x110(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x2840
jmp 0x2ef5
leaq -0x128(%rbp), %rdi
callq 0x50a0
jmp 0x2f03
leaq -0xc0(%rbp), %rdi
callq 0x50d0
movl %eax, -0x2cc(%rbp)
jmp 0x2f17
movl -0x2cc(%rbp), %eax
movl %eax, -0x12c(%rbp)
movl $0x0, -0x130(%rbp)
movl $0x1, -0x134(%rbp)
movl -0x130(%rbp), %eax
cmpl -0x12c(%rbp), %eax
jge 0x3290
leaq -0x188(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x5450
jmp 0x2f5e
movslq -0x8c(%rbp), %rdx
leaq -0x160(%rbp), %rdi
leaq -0x188(%rbp), %rsi
leaq -0xc0(%rbp), %rcx
callq 0x5160
jmp 0x2f81
leaq -0x110(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x54c0
jmp 0x2f96
leaq -0x160(%rbp), %rdi
callq 0x49b0
leaq -0x188(%rbp), %rdi
callq 0x49b0
movl $0x0, -0x18c(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x18c(%rbp), %rsi
callq 0x5510
jmp 0x2fcd
jmp 0x2fcf
movl -0x130(%rbp), %eax
cmpl -0x12c(%rbp), %eax
jge 0x327a
leaq -0x1e0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x56a0
jmp 0x2ffd
leaq -0x1b8(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x5540
jmp 0x3019
leaq -0x1e0(%rbp), %rdi
callq 0x49b0
leaq -0x230(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x5450
jmp 0x303a
leaq -0x208(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x230(%rbp), %rdx
callq 0x5930
jmp 0x3056
leaq -0xc0(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x54c0
jmp 0x306b
leaq -0x208(%rbp), %rdi
callq 0x49b0
leaq -0x230(%rbp), %rdi
callq 0x49b0
leaq -0x1b8(%rbp), %rdi
callq 0x50d0
movl %eax, -0x2d0(%rbp)
jmp 0x3097
movl -0x2d0(%rbp), %eax
movl %eax, -0x234(%rbp)
cmpl $0x0, -0x234(%rbp)
jne 0x3205
movl $0x9, -0x238(%rbp)
jmp 0x324a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x30e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5020
leaq -0x71(%rbp), %rdi
callq 0x5080
jmp 0x3617
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x35f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x33f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x33e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x33d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x33cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x3186
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x49b0
leaq -0x188(%rbp), %rdi
callq 0x49b0
jmp 0x33cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x49b0
jmp 0x33cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x3269
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x31f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x49b0
leaq -0x230(%rbp), %rdi
callq 0x49b0
jmp 0x3269
movl -0x234(%rbp), %eax
addl -0x130(%rbp), %eax
movl %eax, -0x130(%rbp)
movl -0x234(%rbp), %eax
cltd
idivl -0x134(%rbp)
movl %eax, -0x2d4(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x5e30
movl -0x2d4(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
movl $0x0, -0x238(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x49b0
movl -0x238(%rbp), %eax
testl %eax, %eax
je 0x3264
jmp 0x3262
jmp 0x327a
jmp 0x2fcf
leaq -0x1b8(%rbp), %rdi
callq 0x49b0
jmp 0x33cd
jmp 0x327c
movl -0x134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x134(%rbp)
jmp 0x2f37
leaq -0x128(%rbp), %rdi
callq 0x48b0
cmpq $0x0, %rax
jne 0x32c3
movl $0x0, -0x23c(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x23c(%rbp), %rsi
callq 0x5510
jmp 0x32c1
jmp 0x32c3
movq -0x10(%rbp), %rdi
callq 0x4e50
movl %eax, -0x2d8(%rbp)
jmp 0x32d4
movl -0x2d8(%rbp), %eax
movl -0x12c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x2ec(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x128(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x4d90
movl -0x2ec(%rbp), %edx
movq -0x2b8(%rbp), %rdi
movq -0x2e8(%rbp), %rsi
movl (%rax), %ecx
addl %edx, %ecx
movl %ecx, (%rax)
callq 0x5e70
movq %rax, -0x2e0(%rbp)
jmp 0x3327
movq -0x2e0(%rbp), %rax
cmpq $0x0, %rax
je 0x3360
movq -0x2b8(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x5ed0
movq %rax, -0x2f8(%rbp)
jmp 0x3350
movq -0x2f8(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x3389
movq -0x2b8(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x5ed0
movq %rax, -0x300(%rbp)
jmp 0x337c
movq -0x300(%rbp), %rax
movl $0x0, (%rax)
leaq -0x128(%rbp), %rdi
callq 0x5fb0
leaq -0x110(%rbp), %rdi
callq 0x49b0
leaq -0xe8(%rbp), %rdi
callq 0x49b0
leaq -0xc0(%rbp), %rdi
callq 0x49b0
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x2e6f
leaq -0x128(%rbp), %rdi
callq 0x5fb0
leaq -0x110(%rbp), %rdi
callq 0x49b0
leaq -0xe8(%rbp), %rdi
callq 0x49b0
leaq -0xc0(%rbp), %rdi
callq 0x49b0
jmp 0x35f0
movq -0x10(%rbp), %rdi
callq 0x4e50
movl %eax, -0x304(%rbp)
jmp 0x3413
movl -0x304(%rbp), %eax
movl %eax, -0x284(%rbp)
leaq -0x284(%rbp), %rax
movq %rax, -0x280(%rbp)
movq $0x1, -0x278(%rbp)
leaq -0x285(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x4f10
movq -0x310(%rbp), %rcx
movq -0x280(%rbp), %rsi
movq -0x278(%rbp), %rdx
leaq -0x270(%rbp), %rdi
callq 0x4f30
jmp 0x346e
leaq -0x258(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x60b0
jmp 0x3483
movq -0x2b8(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x5fd0
movq %rax, -0x318(%rbp)
jmp 0x349f
movq -0x318(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x31c(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x5fb0
leaq -0x270(%rbp), %rdi
callq 0x5020
leaq -0x285(%rbp), %rdi
callq 0x5080
movl -0x31c(%rbp), %ecx
movq -0x2b8(%rbp), %rax
movl %ecx, -0x240(%rbp)
movq %rax, -0x290(%rbp)
movq -0x290(%rbp), %rdi
callq 0x60e0
movq %rax, -0x298(%rbp)
movq -0x290(%rbp), %rdi
callq 0x6110
movq %rax, -0x2a0(%rbp)
leaq -0x298(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x6140
testb $0x1, %al
jne 0x352e
jmp 0x35d1
leaq -0x298(%rbp), %rdi
callq 0x6170
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rax
cvtsi2sdl 0x18(%rax), %xmm0
cvtsi2sdl -0x240(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x20b0
cvttsd2si %xmm0, %ecx
movq -0x2a8(%rbp), %rax
movl %ecx, 0x18(%rax)
leaq -0x298(%rbp), %rdi
callq 0x6190
jmp 0x3512
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x35c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x35b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x5fb0
leaq -0x270(%rbp), %rdi
callq 0x5020
leaq -0x285(%rbp), %rdi
callq 0x5080
jmp 0x35f0
movb $0x1, -0x15(%rbp)
movl $0x1, -0x238(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4e30
testb $0x1, -0x15(%rbp)
jne 0x3607
jmp 0x35fb
leaq -0x40(%rbp), %rdi
callq 0x4e30
jmp 0x3617
movq -0x2b8(%rbp), %rdi
callq 0x61c0
movq -0x2b0(%rbp), %rax
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
movq -0x2b8(%rbp), %rdi
callq 0x61c0
movq -0x80(%rbp), %rdi
callq 0x22f0
nopl (%rax)