// File: 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
subq $0x260, %rsp            # imm = 0x260
movl $0x0, -0x4(%rbp)
callq 0x2440
leaq -0x30(%rbp), %rdi
callq 0x4c60
leaq -0x58(%rbp), %rdi
callq 0x49d0
jmp 0x3f3b
leaq 0x1001c282(%rip), %rax  # 0x100201c4
movq %rax, -0x30(%rbp)
leaq 0x1001c278(%rip), %rax  # 0x100201c5
movq %rax, -0x58(%rbp)
movq 0x1c078(%rip), %rdi     # 0x1ffd0
leaq -0x58(%rbp), %rsi
callq 0x6310
jmp 0x3f63
leaq -0x58(%rbp), %rdi
callq 0x4bb0
jmp 0x3f6e
leaq -0x90(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2af0
jmp 0x3f80
leaq -0x30(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x6930
jmp 0x3f92
leaq -0x90(%rbp), %rdi
callq 0x4e30
movq 0x1c013(%rip), %rdi     # 0x1ffb8
leaq -0x30(%rbp), %rsi
callq 0x6980
movq %rax, -0x1e0(%rbp)
jmp 0x3fb7
movq -0x1e0(%rbp), %rdi
leaq 0x11065(%rip), %rsi     # 0x1502a
callq 0x21c0
jmp 0x3fcc
leaq -0xc0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x4e20, %edx           # imm = 0x4E20
callq 0x2d80
jmp 0x3fe3
leaq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x60e0
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x6110
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x6140
testb $0x1, %al
jne 0x4033
jmp 0x4142
leaq -0xd0(%rbp), %rdi
callq 0x6170
movq %rax, %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6aa0
jmp 0x4050
movq 0x1bf61(%rip), %rdi     # 0x1ffb8
leaq -0xf8(%rbp), %rsi
callq 0x6ae0
movq %rax, -0x1e8(%rbp)
jmp 0x406c
movq -0x1e8(%rbp), %rdi
leaq 0x10fdb(%rip), %rsi     # 0x15055
callq 0x21c0
movq %rax, -0x1f0(%rbp)
jmp 0x4088
movq -0x1f0(%rbp), %rdi
movl -0xe0(%rbp), %esi
callq 0x22e0
movq %rax, -0x1f8(%rbp)
jmp 0x40a3
movq -0x1f8(%rbp), %rdi
leaq 0x10f79(%rip), %rsi     # 0x1502a
callq 0x21c0
jmp 0x40b8
leaq -0xf8(%rbp), %rdi
callq 0x6ba0
leaq -0xd0(%rbp), %rdi
callq 0x6190
jmp 0x4017
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x45fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x45f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4e30
jmp 0x45f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x45e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x6ba0
jmp 0x45e9
movl $0x0, -0xfc(%rbp)
leaq -0xc0(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rdi
callq 0x60e0
movq %rax, -0x110(%rbp)
movq -0x108(%rbp), %rdi
callq 0x6110
movq %rax, -0x118(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x6140
testb $0x1, %al
jne 0x4199
jmp 0x41d0
leaq -0x110(%rbp), %rdi
callq 0x6170
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
movl 0x18(%rax), %eax
addl -0xfc(%rbp), %eax
movl %eax, -0xfc(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x6190
jmp 0x4180
movq 0x1bde1(%rip), %rdi     # 0x1ffb8
leaq 0x10e72(%rip), %rsi     # 0x15050
callq 0x21c0
movq %rax, -0x200(%rbp)
jmp 0x41ec
movq -0x200(%rbp), %rdi
movl -0xfc(%rbp), %esi
callq 0x22e0
movq %rax, -0x208(%rbp)
jmp 0x4207
movq -0x208(%rbp), %rdi
leaq 0x10e15(%rip), %rsi     # 0x1502a
callq 0x21c0
jmp 0x421c
leaq -0x138(%rbp), %rdi
callq 0x3b00
jmp 0x422a
leaq -0x188(%rbp), %rdi
callq 0x6bc0
jmp 0x4238
movl $0x7fffffff, -0x18c(%rbp) # imm = 0x7FFFFFFF
movl $0x0, -0x190(%rbp)
movslq -0x190(%rbp), %rax
movq %rax, -0x210(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x6bf0
movq %rax, %rcx
movq -0x210(%rbp), %rax
cmpq %rcx, %rax
jae 0x4375
movl -0xfc(%rbp), %eax
movl %eax, -0x214(%rbp)
movslq -0x190(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x6c20
movq %rax, %rcx
movl -0x214(%rbp), %eax
subl 0x20(%rcx), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x194(%rbp)
movl -0x194(%rbp), %eax
cmpl -0x18c(%rbp), %eax
jge 0x4338
jmp 0x42c1
leaq -0x188(%rbp), %rdi
callq 0x6c40
movq %rax, -0x220(%rbp)
jmp 0x42d6
movq -0x220(%rbp), %rax
cmpq $0x0, %rax
je 0x4315
leaq -0x188(%rbp), %rdi
callq 0x6c60
jmp 0x42f1
jmp 0x42c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x45dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x45d1
leaq -0x188(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x6c80
jmp 0x432a
movl -0x194(%rbp), %eax
movl %eax, -0x18c(%rbp)
jmp 0x435f
movl -0x194(%rbp), %eax
cmpl -0x18c(%rbp), %eax
jne 0x435d
leaq -0x188(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x6c80
jmp 0x435b
jmp 0x435d
jmp 0x435f
jmp 0x4361
movl -0x190(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x190(%rbp)
jmp 0x424c
leaq -0x188(%rbp), %rdi
callq 0x6c40
movq %rax, -0x228(%rbp)
jmp 0x438a
movq -0x228(%rbp), %rax
cmpq $0x1, %rax
jne 0x43f4
leaq -0x188(%rbp), %rdi
callq 0x6cb0
movq %rax, -0x230(%rbp)
jmp 0x43ac
movq -0x230(%rbp), %rax
movslq (%rax), %rsi
leaq -0x138(%rbp), %rdi
callq 0x6c20
movq %rax, %rsi
movq 0x1bbec(%rip), %rdi     # 0x1ffb8
callq 0x21a0
movq %rax, -0x238(%rbp)
jmp 0x43da
movq -0x238(%rbp), %rdi
leaq 0x10c42(%rip), %rsi     # 0x1502a
callq 0x21c0
jmp 0x43ef
jmp 0x4588
leaq -0x188(%rbp), %rdi
callq 0x6c40
movq %rax, -0x240(%rbp)
jmp 0x4409
movq -0x240(%rbp), %rax
cmpq $0x1, %rax
jbe 0x4576
movl $0x7fffffff, -0x19c(%rbp) # imm = 0x7FFFFFFF
movl $0xffffffff, -0x1a0(%rbp) # imm = 0xFFFFFFFF
leaq -0x188(%rbp), %rdi
callq 0x6c40
movq %rax, -0x248(%rbp)
jmp 0x4443
movq -0x248(%rbp), %rax
cmpq $0x0, %rax
je 0x4534
leaq -0x188(%rbp), %rdi
callq 0x6cb0
movq %rax, -0x250(%rbp)
jmp 0x4469
movq -0x250(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1a4(%rbp)
leaq -0x1d8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x6cd0
jmp 0x448d
movslq -0x1a4(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x6c20
movq %rax, %rdx
addq $0x28, %rdx
leaq -0x195(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x4610
movl %eax, -0x254(%rbp)
jmp 0x44c2
leaq -0x1d8(%rbp), %rdi
callq 0x61c0
movl -0x254(%rbp), %eax
movl %eax, -0x1a8(%rbp)
movl -0x1a8(%rbp), %eax
cmpl -0x19c(%rbp), %eax
jge 0x451f
movl -0x1a8(%rbp), %eax
movl %eax, -0x19c(%rbp)
movl -0x1a4(%rbp), %eax
movl %eax, -0x1a0(%rbp)
jmp 0x451f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x61c0
jmp 0x45d1
jmp 0x4521
leaq -0x188(%rbp), %rdi
callq 0x6c60
jmp 0x452f
jmp 0x442e
movslq -0x1a0(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x6c20
movq %rax, %rsi
movq 0x1ba67(%rip), %rdi     # 0x1ffb8
callq 0x21a0
movq %rax, -0x260(%rbp)
jmp 0x455f
movq -0x260(%rbp), %rdi
leaq 0x10abd(%rip), %rsi     # 0x1502a
callq 0x21c0
jmp 0x4574
jmp 0x4586
leaq 0x10adb(%rip), %rdi     # 0x15058
callq 0x2290
jmp 0x4584
jmp 0x4586
jmp 0x4588
movl $0x0, -0x4(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x6d00
leaq -0x138(%rbp), %rdi
callq 0x68d0
leaq -0xc0(%rbp), %rdi
callq 0x61c0
leaq -0x58(%rbp), %rdi
callq 0x4c40
leaq -0x30(%rbp), %rdi
callq 0x4e30
movl -0x4(%rbp), %eax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
leaq -0x188(%rbp), %rdi
callq 0x6d00
leaq -0x138(%rbp), %rdi
callq 0x68d0
leaq -0xc0(%rbp), %rdi
callq 0x61c0
leaq -0x58(%rbp), %rdi
callq 0x4c40
leaq -0x30(%rbp), %rdi
callq 0x4e30
movq -0x60(%rbp), %rdi
callq 0x22f0