# The Kata
Your task is to transform an input nested list into an hypercube list, which is a special kind of nested list where each level must have the very same size,
This Kata is an exercise on recursion and algorithms. You will need to visualize many aspects of this question to be able to solve it efficiently, as such there is a section on definitions of the terms that will be used in the Kata, make sure to fully understand them before attempting. A naive brute-force-ish answer will most likely fail the tests. There will be tests on  nested lists of dimension and size up to 10. Good luck.


# Definitions
### Nested List
A nested list is a list that may contain either non-list items or more nested lists as items in the list. Here are a few examples of nested lists.

    [[2, 3], 4, 5, 6, [2, [2, 3, 4, 5], 2, 1, 2], [[[[1]]]], []]
    [[[]]]
    [1, 2]
    [[], []]
    [4, 5, 6, 7, [], 2]
    []


- A *basic element* refers to any non-list element of a nested list.


- A nested list's *dimension* is defined as the deepest the list goes.  


- A nested list's *size* is defined as the longest the list or any of its sublists go.  

For example, the *dimension* and *size* of the above nested lists is as follows.

    [[2, 3], 4, 5, 6, [2, [2, 3, 4, 5], 2, 1, 2], [[[[1]]]], []]  # dimension: 5, size: 7
    [[[]]]                                                        # dimension: 3, size: 1
    [1, 2]                                                        # dimension: 1, size: 2
    [[], []]                                                      # dimension: 2, size: 2
    [4, 5, 6, 7, [], 2]                                           # dimension: 2, size: 6
    []                                                            # dimension: 1, size: 0


### Hypercube List
- A `1`-dimensional **hypercube list** of size `n` is a nested list of dimension `1` and size `n`.  


- A `d`-dimensional hypercube list of size `n` is a nested list of dimension `d` and size `n` such that the nested list has `n` elements each of which is a `d - 1`-dimensional hypercube list of size `n`.  


Here are some examples of hypercube lists.

    [1]                                                       # dimension: 1, size: 1
    [[1, 2], [3, 4]]                                          # dimension: 2, size: 2
    [[1, 2, 3], [4, 5, 6], [7, 8, 9]]                         # dimension: 2, size: 3
    [[0]]                                                     # dimension: 2, size: 1
    [[[0, 0], [1, 1]], [[2, 2], [3, 3]]]                      # dimension: 3, size: 2
    [1, 2, 3, 4]                                              # dimension: 1, size: 4
    [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]  # dimension: 2, size: 4


# The Task
Your task is to implement `normalize` which converts any given `nested_list` to be in hypercube format with the same dimension and size as the given nested list, extending and growing with the given `growing_value`. The default growing value is the integer `0`.

### The Algorithm
In most scenarios you will encounter a nested list that does not have the same size throughout. When working on such a list the algorithm should behave as follows.

 * If a hypercube list of dimension 1 needs extra elements, append the required number of growing value elements.
 * If a hypercube list of dimension greater than 1 has a direct basic element as a child, replace it with the required hypercube list with its basic elements all being the replaced item.
 * If a hypercube list of dimension greater than 1 needs extra elements, append the required hypercube list with its basic elements all being the growing value.


Take note of the given example, it will be very helpful in understanding the intricacies of the algorithm.

    >>> normalize(
            [
                [
                    [2, 3, 4],
                    [1, 2],
                    2,
                    [1]
                ],
                [
                    2,
                    [2, 3],
                    1,
                    4,
                    [2, 2, 6, 7]
                ],
                5
            ]
        )
        
Gives the following result.

    [
        [
            [2, 3, 4, 0, 0],
            [1, 2, 0, 0, 0],
            [2, 2, 2, 2, 2],
            [1, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ],
        [
            [2, 2, 2, 2, 2],
            [2, 3, 0, 0, 0],
            [1, 1, 1, 1, 1],
            [4, 4, 4, 4, 4],
            [2, 2, 6, 7, 0]
        ],
        [
            [5, 5, 5, 5, 5],
            [5, 5, 5, 5, 5],
            [5, 5, 5, 5, 5],
            [5, 5, 5, 5, 5],
            [5, 5, 5, 5, 5]
        ],
        [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ],
        [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ]
    ]


Good luck!

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'def normalize(nested_list, growing_value=0):\n    """Convert the given nested list to hypercube format with the given growing value and return it.\n    """\n    [dimension, size] = get_dimension_and_size(nested_list)\n    return do_normalize(nested_list, dimension, size, growing_value)\n\n\ndef do_normalize(current_elem, dimension, size, growing_value):\n    """Convert the given current element to hypercube format with the given dimension, size\n        and growing value in a recursive manner.\n    """\n    is_basic = is_basic_element(current_elem)\n    missing_element_count = size - len(current_elem) if not is_basic else size\n    current_items = [] if is_basic else current_elem\n    fill_value = current_elem if is_basic else growing_value\n\n    return_elem = []\n    if dimension > 1:\n        for item in current_items:\n            return_elem.append(do_normalize(item, dimension - 1, size, growing_value))\n        for _ in range(missing_element_count):\n            return_elem.append(\n                do_normalize(fill_value, dimension - 1, size, growing_value)\n            )\n    else:  # dimension == 1\n        return_elem = list(current_items)\n        return_elem.extend(repeat_value(fill_value, missing_element_count))\n\n    return return_elem\n\n\ndef get_dimension_and_size(nested_list, dimension=1):\n    """Find out dimension and size for the given nested list\n       * A nested list\'s dimension is defined as the deepest the list goes.\n       * A nested list\'s size is defined as the longest the list or any of its sublists go.\n    """\n    dimensions = [dimension]\n    sizes = [len(nested_list)]\n    for list_item in nested_list:\n        if not isinstance(list_item, list):\n            continue\n        [dim, size] = get_dimension_and_size(list_item, dimension + 1)\n        dimensions.append(dim)\n        sizes.append(size)\n    return [max(dimensions), max(sizes)]\n\n\ndef is_basic_element(elem):\n    return isinstance(elem, int)\n\n\ndef repeat_value(value, count):\n    return [value for _ in range(count)]\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'normalize'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 6678