// File: /workspace/github_cpp_makefile_star2_O2/ttalvitie[P]traveling-santa/optimize.cpp
// Function: initialPaths(long long)
vector<Path> initialPaths(Z wtLimit) {
    vector<Point> points;
	ifstream fp("nicelist.txt");
    if(!fp.good()) throw 0;
	while(true) {
		string item;
		fp >> item;
		if(!fp.good()) {
			break;
		}
		for(char& c : item) {
			if(c == ';') c = ' ';
		}
		item.push_back('\n');
		stringstream ss(item);
		ss.exceptions(ss.failbit | ss.badbit | ss.eofbit);
        Point point;
		double la, lo;
		ss >> point.child >> la >> lo >> point.wt;
        if(point.child == -1) throw 0;
		point.pos = Vec3::fromLatLong(la, lo);
        points.push_back(point);
    }

    Path path;
    path.points.push_back(Korvatunturi);

    while(!points.empty()) {
        double bestDist = Infty;
        int bestPi = -1;
        for(int pi = 0; pi < len(points); ++pi) {
            double dist = sphereDist(path.points.back().pos, points[pi].pos);
            if(dist < bestDist) {
                bestDist = dist;
                bestPi = pi;
            }
        }
        if(bestPi == -1) throw 0;
        swap(points[bestPi], points.back());
        path.points.push_back(points.back());
        points.pop_back();
    }

    path.points.push_back(Korvatunturi);

    while(true) {
        bool progress = false;
        for(int i = 1; i < len(path.points); ++i) {
            for(int j = i + 2; j < len(path.points); ++j) {
                double costDiff = 0.0;
                costDiff -= sphereDist(path.points[i - 1].pos, path.points[i].pos);
                costDiff -= sphereDist(path.points[j - 1].pos, path.points[j].pos);
                costDiff += sphereDist(path.points[i - 1].pos, path.points[j - 1].pos);
                costDiff += sphereDist(path.points[i].pos, path.points[j].pos);
                if(costDiff < 0.0) {
                    reverse(path.points.begin() + i, path.points.begin() + j);
                    progress = true;
                }
            }
        }
        if(!progress) break;
    }

    vector<Path> paths;
    int i = 1;
    while(i != len(path.points) - 1) {
        int j = i;
        Z wt = 0;
        while(j != len(path.points) - 1 && (j == i || wt + path.points[j].wt <= wtLimit)) {
            wt += path.points[j].wt;
            ++j;
        }
        Path sub;
        sub.points.push_back(Korvatunturi);
        sub.points.insert(sub.points.end(), path.points.begin() + i, path.points.begin() + j);
        sub.points.push_back(Korvatunturi);
        sub.finalize();
        paths.push_back(move(sub));
        i = j;
    }

    return paths;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
movq %rsi, 0xd8(%rsp)
movq %rdi, %r14
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
leaq 0x39de(%rip), %rsi      # 0x60ac
leaq 0x2b0(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2360
movq 0x2b0(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x2d0(%rsp,%rax)
jne 0x2d7f
leaq 0x80(%rsp), %r15
leaq 0xa0(%rsp), %r13
leaq 0x120(%rsp), %rbx
leaq 0x60(%rsp), %r12
leaq 0x40(%rsp), %rbp
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
andq $0x0, 0xa8(%rsp)
movb $0x0, 0xb0(%rsp)
leaq 0x2b0(%rsp), %rdi
movq %r13, %rsi
callq 0x2230
movq 0x2b0(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x2d0(%rsp,%rax)
jne 0x2856
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rcx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x278b
cmpb $0x3b, (%rax,%rdx)
jne 0x2786
movb $0x20, (%rax,%rdx)
incq %rdx
jmp 0x2777
movq %r13, %rdi
pushq $0xa
popq %rsi
callq 0x21b0
movq %rbx, %rdi
movq %r13, %rsi
pushq $0x18
popq %rdx
callq 0x22b0
movq 0x120(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
pushq $0x7
popq %rsi
callq 0x2060
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2110
movq %rax, %rdi
leaq 0xe8(%rsp), %rsi
callq 0x2120
movq %rax, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x2120
movq %rax, %rdi
movq %r15, %rsi
callq 0x2240
cmpl $-0x1, 0x60(%rsp)
je 0x2d43
movsd 0xe8(%rsp), %xmm0
movsd 0xe0(%rsp), %xmm1
leaq 0x108(%rsp), %rdi
callq 0x4920
movq 0x118(%rsp), %rax
movq %rax, -0x8(%r15)
movupd 0x108(%rsp), %xmm0
movupd %xmm0, -0x18(%r15)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x49bc
movq %rbx, %rdi
callq 0x2170
movq %r13, %rdi
callq 0x20c0
jmp 0x271a
movq %r14, 0x58(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x20c0
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x6977(%rip), %rsi      # 0x91f8
callq 0x49bc
movq 0x48(%rsp), %rcx
pushq $0x8
popq %r14
pushq $0x38
popq %r13
leaq 0x60(%rsp), %rbx
movq 0x40(%rsp), %rdi
cmpq %rcx, %rdi
je 0x29df
movq %r14, %r12
xorl %ebp, %ebp
pushq $-0x1
popq %r15
movsd 0x3759(%rip), %xmm0     # 0x6010
movq %rcx, %rax
subq %rdi, %rax
cqto
idivq %r13
cltq
cmpq %rax, %rbp
jge 0x2925
movq 0x68(%rsp), %rax
movq 0x10(%rdi,%r12), %rcx
movq %rcx, 0x28(%rsp)
movsd %xmm0, 0x30(%rsp)
movups (%rdi,%r12), %xmm0
movups %xmm0, 0x18(%rsp)
movq -0x20(%rax), %rcx
movq %rcx, 0x10(%rsp)
movupd -0x30(%rax), %xmm0
movupd %xmm0, (%rsp)
callq 0x25e6
movsd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
cmoval %ebp, %r15d
minsd %xmm1, %xmm0
incq %rbp
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rcx
addq $0x38, %r12
jmp 0x28b7
cmpl $-0x1, %r15d
je 0x2d61
movslq %r15d, %rax
imulq $0x38, %rax, %rax
leaq -0x38(%rcx), %rsi
movq 0x30(%rdi,%rax), %rdx
movq %rdx, 0x150(%rsp)
movups (%rdi,%rax), %xmm0
movups 0x10(%rdi,%rax), %xmm1
movups 0x20(%rdi,%rax), %xmm2
movaps %xmm2, 0x140(%rsp)
movaps %xmm1, 0x130(%rsp)
movaps %xmm0, 0x120(%rsp)
movq -0x8(%rcx), %rdx
movq %rdx, 0x30(%rdi,%rax)
movups -0x38(%rcx), %xmm0
movups -0x28(%rcx), %xmm1
movups -0x18(%rcx), %xmm2
movups %xmm2, 0x20(%rdi,%rax)
movups %xmm1, 0x10(%rdi,%rax)
movups %xmm0, (%rdi,%rax)
movq 0x150(%rsp), %rax
movq %rax, -0x8(%rcx)
movapd 0x120(%rsp), %xmm0
movapd 0x130(%rsp), %xmm1
movaps 0x140(%rsp), %xmm2
movups %xmm2, -0x18(%rcx)
movupd %xmm1, -0x28(%rcx)
movupd %xmm0, -0x38(%rcx)
movq %rbx, %rdi
callq 0x49bc
movq 0x48(%rsp), %rcx
addq $-0x38, %rcx
movq %rcx, 0x48(%rsp)
jmp 0x2898
leaq 0x6812(%rip), %rsi      # 0x91f8
leaq 0x60(%rsp), %rdi
callq 0x49bc
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %r8
pushq $0x3
popq %r9
pushq $0x1
popq %r10
xorl %ebp, %ebp
movq %rdi, %rsi
movq %r8, %rcx
movq %r10, %r12
movl %r9d, %r11d
movq 0x58(%rsp), %r14
movq %rsi, %rax
movq %rcx, %rdx
movq %rdx, %rcx
movq %rax, %rsi
movq %rdx, %rax
subq %rsi, %rax
cqto
idivq %r13
cltq
cmpq %rax, %r12
jl 0x2a4f
movq %rdi, %rax
movq %r8, %rdx
movq %r10, %r12
movl %r9d, %r11d
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x2a1b
jmp 0x2c0a
movl %r11d, 0x3c(%rsp)
movslq %r11d, %r9
leaq -0x1(%r12), %rax
imulq $0x38, %r9, %r14
addq $-0x30, %r14
imulq $0x38, %rax, %rbx
imulq $0x38, %r12, %r15
movq %rcx, %rax
subq %rsi, %rax
cqto
idivq %r13
cltq
cmpq %rax, %r9
jge 0x2bed
movq %r9, 0xc0(%rsp)
movq 0x18(%rsi,%rbx), %rax
movq %rax, 0x100(%rsp)
movups 0x8(%rsi,%rbx), %xmm0
movaps %xmm0, 0xf0(%rsp)
movq 0x18(%rsi,%r15), %rax
movq %rax, 0x28(%rsp)
movups 0x8(%rsi,%r15), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0xf0(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x25e6
movsd %xmm0, 0x30(%rsp)
movq 0x60(%rsp), %rax
movq 0x48(%rax,%r14), %rcx
movq %rcx, 0x28(%rsp)
movups 0x38(%rax,%r14), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x10(%rax,%r14), %rcx
movq %rcx, 0x10(%rsp)
movups (%rax,%r14), %xmm0
movups %xmm0, (%rsp)
callq 0x25e6
movsd %xmm0, 0xd0(%rsp)
movq 0x60(%rsp), %rax
movq 0x10(%rax,%r14), %rcx
movq %rcx, 0x28(%rsp)
movups (%rax,%r14), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x18(%rax,%rbx), %rcx
movq %rcx, 0x10(%rsp)
movups 0x8(%rax,%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x25e6
movsd %xmm0, 0xc8(%rsp)
movq 0x60(%rsp), %rax
movq 0x48(%rax,%r14), %rcx
movq %rcx, 0x28(%rsp)
movups 0x38(%rax,%r14), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x18(%rax,%r15), %rcx
movq %rcx, 0x10(%rsp)
movupd 0x8(%rax,%r15), %xmm0
movupd %xmm0, (%rsp)
callq 0x25e6
xorpd %xmm1, %xmm1
subsd 0x30(%rsp), %xmm1
subsd 0xd0(%rsp), %xmm1
addsd 0xc8(%rsp), %xmm1
addsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2bc9
movq 0x60(%rsp), %rdi
leaq (%rdi,%r14), %rsi
addq $0x30, %rsi
addq %r15, %rdi
movb $0x1, %bpl
callq 0x4f73
movq 0xc0(%rsp), %r9
incq %r9
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %r8
addq $0x38, %r14
movq %rdi, %rsi
movq %r8, %rcx
jmp 0x2a6c
incq %r12
movl 0x3c(%rsp), %r11d
incl %r11d
movq 0x58(%rsp), %r14
pushq $0x3
popq %r9
pushq $0x1
popq %r10
jmp 0x2a15
xorpd %xmm0, %xmm0
andq $0x0, 0x10(%r14)
movupd %xmm0, (%r14)
pushq $0x1
popq %rbp
leaq 0x65d6(%rip), %rbx      # 0x91f8
leaq 0x120(%rsp), %r15
subq %rsi, %rcx
movq %rcx, %rax
cqto
idivq %r13
leal -0x1(%rax), %ecx
cmpl %ecx, %ebp
je 0x2d0d
movslq %ebp, %rdi
imulq $0x38, %rdi, %r12
leaq (%rsi,%r12), %rdx
addq $0x20, %rdx
cltq
negq %rax
addq %rdi, %rax
incq %rax
movq %rdx, %rsi
xorl %r8d, %r8d
xorl %edi, %edi
cmpq %r8, %rax
je 0x2c8b
movq %r8, %r9
subq $0x1, %r9
jae 0x2c75
addq (%rdx), %rdi
jmp 0x2c82
addq (%rsi), %rdi
cmpq 0xd8(%rsp), %rdi
jg 0x2c8f
addq $0x38, %rsi
movq %r9, %r8
jmp 0x2c62
movl %ecx, %ebp
jmp 0x2c92
subl %r8d, %ebp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x120(%rsp)
andq $0x0, 0x130(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x49bc
movq 0x128(%rsp), %rsi
movq 0x60(%rsp), %rax
addq %rax, %r12
movslq %ebp, %rcx
imulq $0x38, %rcx, %rcx
addq %rax, %rcx
movq %r15, %rdi
movq %r12, %rdx
callq 0x49f2
movq %r15, %rdi
movq %rbx, %rsi
callq 0x49bc
movq %r15, %rdi
callq 0x4a12
movq %r14, %rdi
movq %r15, %rsi
callq 0x52c2
movq %r15, %rdi
callq 0x4d92
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rcx
jmp 0x2c2a
leaq 0x60(%rsp), %rdi
callq 0x4d92
leaq 0x2b0(%rsp), %rdi
callq 0x2040
leaq 0x40(%rsp), %rdi
callq 0x4d92
movq %r14, %rax
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x4
popq %rdi
callq 0x20e0
andl $0x0, (%rax)
movq 0x626b(%rip), %rsi      # 0x8fc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2310
jmp 0x2d9b
pushq $0x4
popq %rdi
callq 0x20e0
andl $0x0, (%rax)
movq 0x624d(%rip), %rsi      # 0x8fc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2310
jmp 0x2d9b
pushq $0x4
popq %rdi
callq 0x20e0
andl $0x0, (%rax)
movq 0x622f(%rip), %rsi      # 0x8fc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2310
movq %rax, %rbx
jmp 0x2e00
movq %rax, %rbx
jmp 0x2e0d
jmp 0x2dad
jmp 0x2dad
jmp 0x2dbf
jmp 0x2dad
movq %rax, %rbx
jmp 0x2dd7
jmp 0x2dba
jmp 0x2de3
jmp 0x2de3
jmp 0x2de3
movq %rax, %rbx
jmp 0x2df3
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x4d92
movq %r14, %rdi
callq 0x4b4a
leaq 0x60(%rsp), %rdi
callq 0x4d92
jmp 0x2e00
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x2170
leaq 0xa0(%rsp), %rdi
callq 0x20c0
leaq 0x2b0(%rsp), %rdi
callq 0x2040
leaq 0x40(%rsp), %rdi
callq 0x4d92
movq %rbx, %rdi
callq 0x2330