1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| n = int(input())
s=[]
def isBadSequence(addStr):
temp = "".join(s) + addStr
for i in range(1, len(temp) // 2 + 1):
if temp[-2 * i : -1 * i] == temp[-1 * i :]:
return True
return False
def dfs():
global s
if len(s) == n:
print("".join(s))
exit()
for j in range(1,4):
if isBadSequence(str(j)):
continue
s.append(str(j))
dfs()
s.pop()
dfs()
|