// File: /workspace/github_cpp_makefile_star2_O2/asd00012334[P]Abstract-Algebra-2018/main.cpp
// Function: main
int main(){
    using namespace std;
    using namespace prime;

    buildPrimeList();
    Polynomial<IntType,int> fint;
    Polynomial<quotient::FracType,quotient::fraction> fq;
    fint.canonicalType.scalar = &intType;
    fq.canonicalType.scalar = &quotient::fracType;

    cin>>fq;
    //fq = fq / gcd(fq.diff(),fq);
    fq.reduce();
    fint = fq.toIntCoef();
    std::cout << fint <<"\n";

    auto table = SplitDegree(fint,20000);
    for(auto e: table)
        cout<<e.first<<": "<<e.second<<"\n";

    int order = 0;
    for(auto &e: table) order += e.second;
    std::cout<<"Order: "<<order<<"\n";
    auto subS5List = loader();
    queue<int> orderMatch;
    int best = INT_MAX;
    for(int i=0;i<subS5List.size();++i){
        int dist = abs(order-subS5List[i].order);
        if(dist<best){
            while(orderMatch.size())
                orderMatch.pop();
            orderMatch.push(i);
            best = dist;
        } else if(dist==best){
            orderMatch.push(i);
        }
    }
    if(orderMatch.size()==1){
        std::cout<<subS5List[orderMatch.front()].name<<"\n";
    } else if(orderMatch.size()>1){
        auto mapDist = [](
            map<DegreeList,int> l,
            map<DegreeList,int>const& r)->int{

            for(auto &e: r){
                if(l.count(e.first))
                    l[e.first]-=e.second;
                else l[e.first] = e.second;
            }
            int out = 0;
            for(auto &e: l) out+=abs(e.second);
            return out;
        };
        int best = INT_MAX;
        int bestIdx=-1;
        for(;orderMatch.size();orderMatch.pop()){
            int idx = orderMatch.front();
            int dist = mapDist(table,subS5List[idx].cycle);
            if(dist<best) best = dist, bestIdx = idx;
        }
        std::cout<<subS5List[bestIdx].name<<"\n";
    } else puts("Unknown");

    //testMod();
    //testFraction();


    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
callq 0x23fc
leaq -0xd8(%rbp), %rax
movq %rax, 0x8(%rax)
leaq -0xc8(%rbp), %rcx
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rcx)
movups %xmm0, (%rcx)
leaq -0x100(%rbp), %rsi
movq %rsi, 0x8(%rsi)
leaq -0xf0(%rbp), %rdx
movups %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x10008d3a(%rip), %rax  # 0x1000c1a4
movq %rax, -0x10(%rcx)
leaq 0x10008d30(%rip), %rax  # 0x1000c1a5
movq %rax, -0x10(%rdx)
movq 0x8b50(%rip), %rdi      # 0xbfd0
callq 0x454b
leaq -0x100(%rbp), %rdi
callq 0x3a50
leaq -0xb0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x27fa
leaq -0xd8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x48c6
leaq -0xa0(%rbp), %rdi
callq 0x4b28
movq 0x8aee(%rip), %rdi      # 0xbfb8
leaq -0xd8(%rbp), %rsi
callq 0x48f0
leaq 0x4b79(%rip), %rsi      # 0x8056
movq %rax, %rdi
callq 0x2190
leaq -0x130(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
movl $0x4e20, %edx           # imm = 0x4E20
callq 0x2924
leaq -0x128(%rbp), %r12
movq 0x10(%r12), %rbx
leaq -0xb0(%rbp), %r15
leaq 0x4b6a(%rip), %r13      # 0x8081
leaq 0x4b38(%rip), %r14      # 0x8056
cmpq %r12, %rbx
je 0x3577
leaq 0x20(%rbx), %rsi
movq %r15, %rdi
callq 0x49d8
movq 0x8a82(%rip), %rdi      # 0xbfb8
movq %r15, %rsi
callq 0x49f6
movq %rax, %rdi
movq %r13, %rsi
callq 0x2190
movl -0x98(%rbp), %esi
movq %rax, %rdi
callq 0x22a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
movq %r15, %rdi
callq 0x4b28
movq %rbx, %rdi
callq 0x2120
movq %rax, %rbx
jmp 0x351e
xorl %r15d, %r15d
movq -0x118(%rbp), %rax
cmpq %r12, %rax
je 0x3594
addl 0x38(%rax), %r15d
movq %rax, %rdi
callq 0x2120
jmp 0x3581
movq 0x8a1d(%rip), %rdi      # 0xbfb8
leaq 0x4ada(%rip), %rsi      # 0x807c
callq 0x2190
movq %rax, %rdi
movl %r15d, %esi
callq 0x22a0
leaq 0x4a9d(%rip), %rsi      # 0x8056
movq %rax, %rdi
callq 0x2190
leaq -0x50(%rbp), %rdi
callq 0x3154
leaq -0xb0(%rbp), %rdi
callq 0x4a70
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %eax, %eax
pushq $0x58
popq %rbx
leaq -0xb0(%rbp), %r12
movl %eax, -0x2c(%rbp)
movslq %eax, %rsi
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
cqto
idivq %rbx
cmpq %rsi, %rax
jbe 0x3662
imulq $0x58, %rsi, %rax
movl %r15d, %edx
subl 0x20(%rcx,%rax), %edx
movl %edx, %r14d
negl %r14d
cmovsl %edx, %r14d
cmpl %r13d, %r14d
jge 0x3634
movq %r12, %rdi
callq 0x769c
testq %rax, %rax
je 0x3647
movq %r12, %rdi
callq 0x76ee
jmp 0x361d
jne 0x3655
movq %r12, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x7750
movl %r13d, %r14d
jmp 0x3658
movq %r12, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x7750
jmp 0x3658
movl %r13d, %r14d
movl -0x2c(%rbp), %eax
incl %eax
movl %r14d, %r13d
jmp 0x35e8
leaq -0xb0(%rbp), %rdi
callq 0x769c
cmpq $0x1, %rax
jne 0x36a6
movq -0xa0(%rbp), %rax
movslq (%rax), %rax
imulq $0x58, %rax, %rsi
addq -0x50(%rbp), %rsi
movq 0x892b(%rip), %rdi      # 0xbfb8
callq 0x2170
leaq 0x49bd(%rip), %rsi      # 0x8056
movq %rax, %rdi
callq 0x2190
jmp 0x37f4
leaq -0xb0(%rbp), %rdi
callq 0x769c
cmpq $0x2, %rax
jb 0x37c0
pushq $-0x1
popq %rbx
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
leaq -0xb0(%rbp), %r15
leaq -0x160(%rbp), %r12
movq %r15, %rdi
callq 0x769c
testq %rax, %rax
je 0x37ce
movl %r14d, -0x30(%rbp)
movl %ebx, -0x34(%rbp)
movq -0xa0(%rbp), %rax
movslq (%rax), %rbx
movq %r12, %rdi
leaq -0x130(%rbp), %rsi
callq 0x4c24
movq -0x50(%rbp), %rax
movq %rbx, -0x58(%rbp)
imulq $0x58, %rbx, %rcx
addq %rcx, %rax
addq $0x30, %rax
movq %rax, -0x60(%rbp)
movq 0x10(%rax), %rbx
cmpq -0x60(%rbp), %rbx
je 0x3767
leaq 0x20(%rbx), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x435c
movq %rax, %r14
movq %r12, %r15
movl 0x38(%rbx), %r12d
movq %r15, %rdi
movq %r13, %rsi
callq 0x4380
movl (%rax), %ecx
subl %r12d, %ecx
testq %r14, %r14
cmovel %r12d, %ecx
movl %ecx, (%rax)
movq %rbx, %rdi
callq 0x21c0
movq %rax, %rbx
movq %r15, %r12
jmp 0x371f
xorl %ebx, %ebx
movq -0x148(%rbp), %rax
movl -0x30(%rbp), %r14d
leaq -0x158(%rbp), %r15
cmpq %r15, %rax
je 0x3796
movl 0x38(%rax), %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
addl %edx, %ebx
movq %rax, %rdi
callq 0x2120
jmp 0x377b
movq %r12, %rdi
callq 0x4bac
cmpl %r14d, %ebx
cmovll %ebx, %r14d
movl -0x34(%rbp), %ebx
cmovll -0x58(%rbp), %ebx
leaq -0xb0(%rbp), %r15
movq %r15, %rdi
callq 0x76ee
jmp 0x36d3
leaq 0x48bd(%rip), %rdi      # 0x8084
callq 0x2250
jmp 0x37f4
movslq %ebx, %rax
imulq $0x58, %rax, %rsi
addq -0x50(%rbp), %rsi
movq 0x87d8(%rip), %rdi      # 0xbfb8
callq 0x2170
leaq 0x486a(%rip), %rsi      # 0x8056
movq %rax, %rdi
callq 0x2190
leaq -0xb0(%rbp), %rdi
callq 0x4ec4
leaq -0x50(%rbp), %rdi
callq 0x489a
leaq -0x130(%rbp), %rdi
callq 0x4bac
leaq -0xf0(%rbp), %rdi
callq 0x4b14
leaq -0xc8(%rbp), %rdi
callq 0x4b28
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x386a
jmp 0x386a
movq %rax, %r15
jmp 0x38a0
jmp 0x386f
jmp 0x3863
movq %rax, %r15
leaq -0xa0(%rbp), %rdi
callq 0x4b28
jmp 0x38b5
jmp 0x3863
jmp 0x386f
movq %rax, %r15
jmp 0x38b5
jmp 0x386a
movq %rax, %r15
jmp 0x3894
movq %rax, %r15
jmp 0x38a9
movq %rax, %r15
leaq -0xb0(%rbp), %rdi
callq 0x4b28
jmp 0x38a9
movq %rax, %r15
leaq -0x160(%rbp), %rdi
callq 0x4bac
leaq -0xb0(%rbp), %rdi
callq 0x4ec4
leaq -0x50(%rbp), %rdi
callq 0x489a
leaq -0x130(%rbp), %rdi
callq 0x4bac
leaq -0xf0(%rbp), %rdi
callq 0x4b14
leaq -0xc8(%rbp), %rdi
callq 0x4b28
movq %r15, %rdi
callq 0x22b0