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

def validatepubkey(pub):
    '''
    Returns input key if it's a valid hex public key, or False
    otherwise.

    Input must be hex string, not bytes or integer/long or anything
    else.
    '''

    try:
        pub = hexstrlify(unhexlify(pub))
    except:
        return False
    if len(pub) == 130:
        if pub[:2] != '04':
            return False
        if uncompress(compress(pub)) != pub:
            return False
    elif len(pub) == 66:
        if pub[:2] != '02' and pub[:2] != '03':
            return False
    else:
        return False
    return pub