## 格雷编码


```
def grayCode( n: int):
        num = "0" * n
        res = [0]
        c = 2 ** n
        while len(res) < c:
            if num[-1] == "0":
                num = num[:-1] + "1"
                res.append(int(num, 2))
            else:
                num = num[:-1] + "0"
                res.append(int(num, 2))
            print(num)

            if len(res) == c:
                break
            idx = num.rfind("1")
            if num[idx - 1] == "0":
                num = num[:idx - 1] + "1" + num[idx:]
            else:
                num = num[:idx - 1] + "0" + num[idx:]
            print(num)
            res.append(int(num, 2))

        return res
grayCode(4)
```

    0001
    0011
    0010
    0110
    0111
    0101
    0100
    1100
    1101
    1111
    1110
    1010
    1011
    1001
    1000





    [0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8]




```
a=[1,2,1,3]

# a=sorted(a,reverse=True)
# a.index(1)
a.sort(reverse=True)
a
```




    [3, 2, 1, 1]




```

```


```

```


```
'NUM 1024'.split()
```




    ['NUM', '1024']




```
'ADD'.split()
```




    ['ADD']




```
def change(num,k):
    
n=int(input())
num=''
for i in range(n):
    temp=input().split()
    
```

    5





    int




```
n=int(input())
num=list(map(int ,input().strip().split()))
re=0
for i in range(n-1):
    index=num.index(min(num))
    re+=num[index]*num[index-1]*num[(index+1)%(n-i)]
    del num[index]
print(re)
```

    4 
    2 3 5 10
    710
