-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion-25.py
More file actions
30 lines (26 loc) · 694 Bytes
/
Question-25.py
File metadata and controls
30 lines (26 loc) · 694 Bytes
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
28
29
30
def sizeOfStr(s):
return len(s) <= 4 or s != s[::-1]
def iter(s):
checkQ = {i for i, x in enumerate(s) if x == '?'}
st = []
i = 0
while i < len(s):
if i in checkQ:
s[i] = '0'
st.append(i)
while not (sizeOfStr(s[i-4:i+1]) and sizeOfStr(s[i-5:i+1])):
if not st:
return False
i = st.pop()
s[i] = '1'
i += 1
return True
def pali():
n = int(input().strip())
a = list(input().strip())
return "POSSIBLE" if iter(a) else "IMPOSSIBLE"
def main():
for j in range(int(input())):
print('Case #%d: %s' % (j+1, pali()))
if __name__=='__main__':
main()