
'''simple docstring'''
import os







def 		A_(     A						:		Optional[Any] = "matrix.txt"):
							with open(os.path.join(os.path.dirname(UpperCamelCase__)		,     UpperCamelCase__)) as in_file:
														UpperCamelCase   			=     in_file.read()

							UpperCamelCase   			=     [[int(UpperCamelCase__) for cell in row.split(',')] for row in data.strip().splitlines()]
							UpperCamelCase   			=     [[0 for cell in row] for row in grid]
							UpperCamelCase   			=     len(grid[0])

							UpperCamelCase   			=     [[0 for i in range(UpperCamelCase__)] for j in range(UpperCamelCase__)]
							UpperCamelCase   			=     grid[0][0]
							for i in range(1		,     UpperCamelCase__):
														UpperCamelCase   			=     grid[0][i] + dp[0][i - 1]
							for i in range(1		,     UpperCamelCase__):
														UpperCamelCase   			=     grid[i][0] + dp[i - 1][0]

							for i in range(1		,     UpperCamelCase__):
														for j in range(1		,     UpperCamelCase__):
																					UpperCamelCase   			=     grid[i][j] + min(dp[i - 1][j]		,     dp[i][j - 1])

							return dp[-1][-1]


if __name__ == "__main__":
						print(f"""{solution() = }""")





'''simple docstring'''




import re

from flax.core.frozen_dict import freeze
from flax.traverse_util import flatten_dict, unflatten_dict
from jax.experimental import PartitionSpec as P


# Sentinels
__UpperCAmelCase					=object()

# For specifying empty leaf dict `{}`
__UpperCAmelCase					=object()






def __lowerCAmelCase					(				UpperCamelCase__							,    UpperCamelCase__							)      ->       List[Any]:
    __lowerCamelCase            =    tuple((re.compile(x + '''$'''							) for x in qs)							)
    for i in range(len(UpperCamelCase__							) - len(UpperCamelCase__							) + 1							):
        __lowerCamelCase            =    [x.match(UpperCamelCase__							) for x, y in zip(UpperCamelCase__							,    ks[i:]							)]
        if matches and all(UpperCamelCase__							):
            return True
    return False






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       Optional[int]:
    def replace(UpperCamelCase__							,    UpperCamelCase__							):
        for rule, replacement in rules:
            if _match(UpperCamelCase__							,    UpperCamelCase__							):
                return replacement
        return val

    return replace






def __lowerCAmelCase					(				)      ->       Dict:
    return [
        # embeddings
        (("transformer", "wpe", "embedding"), P('''mp'''							,    UpperCamelCase__							)),
        (("transformer", "wte", "embedding"), P('''mp'''							,    UpperCamelCase__							)),
        # atention
        (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(UpperCamelCase__							,    '''mp'''							)),
        (("attention", "out_proj", "kernel"), P('''mp'''							,    UpperCamelCase__							)),
        (("attention", "out_proj", "bias"), None),
        # mlp
        (("mlp", "c_fc", "kernel"), P(UpperCamelCase__							,    '''mp'''							)),
        (("mlp", "c_fc", "bias"), P('''mp'''							)),
        (("mlp", "c_proj", "kernel"), P('''mp'''							,    UpperCamelCase__							)),
        (("mlp", "c_proj", "bias"), None),
        # layer norms
        ((r"ln_\d+", "bias"), None),
        ((r"\d+", r"ln_\d+", "scale"), None),
        (("ln_f", "bias"), None),
        (("ln_f", "scale"), None),
    ]






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       int:
    __lowerCamelCase            =    _get_partition_rules()
    __lowerCamelCase            =    _replacement_rules(UpperCamelCase__							)
    __lowerCamelCase            =    {k: _unmatched for k in flatten_dict(UpperCamelCase__							)}
    __lowerCamelCase            =    {k: replace(UpperCamelCase__							,    UpperCamelCase__							) for k, v in initd.items()}
    assert _unmatched not in result.values(), "Incomplete partition spec."
    return freeze(unflatten_dict(UpperCamelCase__							)							)
