fn main [ var input := read_lazy(h[0]); var fs := true; var id := 0; var ids := empty(int); while len_greater_than(input, 0), input[0] >= '0', input[0] <= '9' do [ var num := input[0] - '0'; if fs then [ for i := 0 to num do ids +<= id; id += 1; ] else [ ids += fill(-1, num); ] fs := not fs; input := input[1 .. ]; ] var dest := 0; var src := len(ids) - 1; while dest < src do [ if ids[dest] >= 0 then [ dest += 1; continue; ] if ids[src] < 0 then [ src -= 1; continue; ] ids[dest], ids[src] := ids[src], -1; ] var sum := 0; for i := 0 to dest do sum += i * ids[i]; write(h[1], ntos(sum) + nl); xeval ids; ]