import re


def camel_to_snake_case(s):
    """Converts a camel cased to a snake cased string.

    :param s: a camel cased string
    :return: a snake cased string
    """
    snake_cased = re.sub('([a-z0-9])([A-Z])', r'\1_\2', re.sub('(.)([A-Z][a-z]+)', r'\1_\2',
                                                               s)).lower()
    return snake_cased.replace('__', '_')