<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def managed(name, **kwargs):
    '''
    Manage user account

    login : string
        login name
    password : string
        password
    password_hashed : boolean
        set if password is a nt hash instead of plain text
    domain : string
        users domain
    profile : string
        profile path
    script : string
        logon script
    drive : string
        home drive
    homedir : string
        home directory
    fullname : string
        full name
    account_desc : string
        account description
    machine_sid : string
        specify the machines new primary group SID or rid
    user_sid : string
        specify the users new primary group SID or rid
    account_control : string
        specify user account control properties

        .. note::
            Only the following can be set:
            - N: No password required
            - D: Account disabled
            - H: Home directory required
            - L: Automatic Locking
            - X: Password does not expire
    reset_login_hours : boolean
        reset the users allowed logon hours
    reset_bad_password_count : boolean
        reset the stored bad login counter
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': ''}

    # save state
    saved = __salt__['pdbedit.list'](hashes=True)
    saved = saved[name] if name in saved else {}

    # call pdbedit.modify
    kwargs['login'] = name
    res = __salt__['pdbedit.modify'](**kwargs)

    # calculate changes
    if res[name] in ['created']:
        ret['changes'] = res
    elif res[name] in ['updated']:
        ret['changes'][name] = salt.utils.data.compare_dicts(
            saved,
            __salt__['pdbedit.list'](hashes=True)[name],
        )
    elif res[name] not in ['unchanged']:
        ret['result'] = False
        ret['comment'] = res[name]

    return ret