-
Notifications
You must be signed in to change notification settings - Fork 0
/
14891.py
105 lines (94 loc) · 2.1 KB
/
14891.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import sys
input = sys.stdin.readline
from collections import deque
a1 = input().rstrip()
a2 = input().rstrip()
a3 = input().rstrip()
a4 = input().rstrip()
t1 = deque([i for i in a1])
t2 = deque([i for i in a2])
t3 = deque([i for i in a3])
t4 = deque([i for i in a4])
def rotation(dir, ch):
if dir == 1:
ch.appendleft(ch.pop())
elif dir == -1:
ch.append(ch.popleft())
r = int(input())
for i in range(r):
t, dir = map(int, input().split())
if t == 1:
ch = t1
x = ch[2]
y = t2[6]
x2 = t2[2]
y2 = t3[6]
x3 = t3[2]
y3 = t4[6]
rotation(dir, ch)
if x != y:
rotation(-dir, t2)
if x2 != y2:
rotation(dir, t3)
if x3 != y3:
rotation(-dir, t4)
# elif x == y:
# continue
elif t == 2:
ch = t2
right = ch[2]
right2 = t3[6]
left = ch[6]
left2 = t1[2]
tr3 = t3[2]
tl4 = t4[6]
rotation(dir, ch)
if right != right2:
rotation(-dir, t3)
if tr3 != tl4:
rotation(dir, t4)
if left != left2:
rotation(-dir, t1)
elif t == 3:
ch = t3
rrrr = ch[2]
r2 = t4[6]
l = ch[6]
l2 = t2[2]
tl2 = t2[6]
tr1 = t1[2]
rotation(dir, ch)
if rrrr != r2:
rotation(-dir, t4)
if l != l2:
rotation(-dir, t2)
if tl2 != tr1:
rotation(dir, t1)
elif t == 4:
ch = t4
ll = ch[6]
ll2 = t3[2]
t3l = t3[6]
t2r = t2[2]
t2l = t2[6]
t1r = t1[2]
rotation(dir, ch)
if ll != ll2:
rotation(-dir, t3)
if t3l != t2r:
rotation(dir, t2)
if t2l != t1r:
rotation(-dir, t1)
# else:
# continue
# print(t3)
ans = 0
if t1[0] == '1':
ans +=1
if t2[0] == '1':
ans += 2
if t3[0] == '1':
ans += 4
if t4[0] == '1':
ans += 8
print(ans)