def toggle_middle_bits(n):
    def set_middle_bits(n):  
        n |= n >> 1; 
        n |= n >> 2; 
        n |= n >> 4; 
        n |= n >> 8; 
        n |= n >> 16;  
        return (n >> 1) ^ 1
     
    if (n == 1): 
        return 1
    return n ^ set_middle_bits(n) 
def toggle_middle_bits(s):
    def set_middle_bits(s):
        s |= s >> 1
        s |= s >> 2
        s |= s >> 4
        s |= s >> 8
       
        s |= s >> 16
        return (s >> 1) ^ 1
    if s == 1:
        return 1
    return s ^ set_middle_bits(s)