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

def get_all_used_vars(section):
    '''Get variables which are variables used by input statement and statements before it'''
    all_used_vars = set()
    for statement in section.statements:
        if statement[0] == '=':
            all_used_vars |= accessed_vars('='.join(statement[1:3]))
        elif statement[0] == '!':
            all_used_vars |= accessed_vars(statement[1])
        elif statement[0] == ':':
            all_used_vars |= accessed_vars(statement[2], mode='eval')
            if statement[1] != 'input':
                continue
            if 'paired_with' in statement[2]:
                try:
                    pws = get_names_of_param(
                        'paired_with',
                        statement[2],
                        extra_dict=env.sos_dict.dict())
                    all_used_vars |= set(pws)
                except Exception as e:
                    raise ValueError(
                        f'Failed to parse parameter paired_with: {e}')
            if 'group_with' in statement[2]:
                try:
                    pws = get_names_of_param(
                        'group_with',
                        statement[2],
                        extra_dict=env.sos_dict.dict())
                    all_used_vars |= set(pws)
                except Exception as e:
                    raise ValueError(
                        f'Failed to parse parameter group_with: {e}')
            if 'for_each' in statement[2]:
                try:
                    pws = get_names_of_param(
                        'for_each',
                        statement[2],
                        extra_dict=env.sos_dict.dict())
                    for pw in pws:
                        all_used_vars |= set(pw.split(','))
                except Exception as e:
                    raise ValueError(f'Failed to parse parameter for_each: {e}')
    if section.task:
        all_used_vars |= accessed_vars(section.task)

    # now we have a list of global variables that are actually used in the functions
    # this is specifically designed to handle the last case in #1225
    func_with_vars = [
        y for x, y in used_in_func(section.global_stmts).items()
        if x in all_used_vars
    ]
    return set.union(all_used_vars, *func_with_vars)