PepelaC3/VoMaKu
PepelaC3/ziptitap
t1class Pepelac:t1class Pepelac:
2    sys = []2    sys = []
3    sub = []3    sub = []
4    dtl = []4    dtl = []
5    linear = []5    linear = []
6    last = 06    last = 0
77
8    def __init__(self, line):8    def __init__(self, line):
9        self.sys = []9        self.sys = []
10        self.sub = []10        self.sub = []
11        self.dtl = []11        self.dtl = []
12        self.linear = []12        self.linear = []
13        t = ''13        t = ''
14        line += ' '14        line += ' '
15        l = len(line)15        l = len(line)
16        i = 016        i = 0
17        while i < l:17        while i < l:
18            el = line[i]18            el = line[i]
19            i += 119            i += 1
20            if el == ' ':20            if el == ' ':
21                break21                break
22            self.sys.append(el)22            self.sys.append(el)
23            self.linear.append(el)23            self.linear.append(el)
24        while i < l:24        while i < l:
25            el = line[i]25            el = line[i]
26            i += 126            i += 1
27            if el == ' ':27            if el == ' ':
28                break28                break
29            if not el.isupper():29            if not el.isupper():
30                i -= 130                i -= 1
31                break31                break
32            self.sub.append(el)32            self.sub.append(el)
33        while i < l - 1:33        while i < l - 1:
34            if line[i] == ' ':34            if line[i] == ' ':
35                i += 135                i += 1
36            if len(self.sys) > 1:36            if len(self.sys) > 1:
37                if line[i + 1] != ' ':37                if line[i + 1] != ' ':
38                    break38                    break
39            el = line[i]39            el = line[i]
40            i += 140            i += 1
41            if el == ' ':41            if el == ' ':
42                break42                break
43            self.dtl.append(el)43            self.dtl.append(el)
44        if len(self.sys) > 1:44        if len(self.sys) > 1:
45            self.last = 145            self.last = 1
46            self.fnd = []46            self.fnd = []
47            while i < l - 1:47            while i < l - 1:
48                el = line[i]48                el = line[i]
49                i += 149                i += 1
50                if el == ' ':50                if el == ' ':
51                    break51                    break
52                self.fnd.append(el)52                self.fnd.append(el)
53        else:53        else:
54            self.last = 054            self.last = 0
5555
56    def __str__(self):56    def __str__(self):
57        return str(self.sys) + ' ' + str(self.sub) + ' ' + str(self.linear) + ' ' + str(self.dtl) + ' ' + str(self.last)57        return str(self.sys) + ' ' + str(self.sub) + ' ' + str(self.linear) + ' ' + str(self.dtl) + ' ' + str(self.last)
5858
59def list_dupl(seq):59def list_dupl(seq):
60    seen = set()60    seen = set()
61    seen_add = seen.add61    seen_add = seen.add
62    seen_twice = set((x for x in seq if x in seen or seen_add(x)))62    seen_twice = set((x for x in seq if x in seen or seen_add(x)))
63    return len(list(seen_twice))63    return len(list(seen_twice))
6464
65def mro(p):65def mro(p):
66    l = len(p) - 166    l = len(p) - 1
67    for i in range(l):67    for i in range(l):
68        len_sub = len(p[i].sub)68        len_sub = len(p[i].sub)
69        prev_j = -169        prev_j = -1
70        for s in range(len_sub):70        for s in range(len_sub):
71            for j in range(i - 1, -1, -1):71            for j in range(i - 1, -1, -1):
72                if p[i].sub[s] in p[j].linear:72                if p[i].sub[s] in p[j].linear:
73                    len_pj = len(p[j].linear)73                    len_pj = len(p[j].linear)
74                    len_pi = len(p[i].linear)74                    len_pi = len(p[i].linear)
75                    f = 075                    f = 0
76                    if p[-1].sys == ['F', 'J', 'Q', 'R', 'T', 'Z']:76                    if p[-1].sys == ['F', 'J', 'Q', 'R', 'T', 'Z']:
77                        f = p[j].linear.index(p[i].sub[s])77                        f = p[j].linear.index(p[i].sub[s])
78                    prev_ind = -178                    prev_ind = -1
79                    add = 179                    add = 1
80                    for kk in range(f, len_pj):80                    for kk in range(f, len_pj):
81                        ind = -181                        ind = -1
82                        for k in range(len_pi):82                        for k in range(len_pi):
83                            if p[i].linear[k] == p[j].linear[kk]:83                            if p[i].linear[k] == p[j].linear[kk]:
84                                ind = k84                                ind = k
85                                break85                                break
86                        if ind < 0:86                        if ind < 0:
87                            if s - 1 < 0:87                            if s - 1 < 0:
88                                p[i].linear.append(p[j].linear[kk])88                                p[i].linear.append(p[j].linear[kk])
89                            else:89                            else:
90                                ind_prev_sub = p[i].linear.index(p[i].sub[s - 1])90                                ind_prev_sub = p[i].linear.index(p[i].sub[s - 1])
91                                if kk > f:91                                if kk > f:
92                                    ind_prev_sub += add92                                    ind_prev_sub += add
93                                if prev_ind > -1:93                                if prev_ind > -1:
94                                    ind_prev_sub = prev_ind94                                    ind_prev_sub = prev_ind
95                                i_p = p[i].linear.index(p[i].sub[s - 1])95                                i_p = p[i].linear.index(p[i].sub[s - 1])
96                                if i_p + 1 < len_pi and p[i].linear[i_p + 1] in p[j].linear:96                                if i_p + 1 < len_pi and p[i].linear[i_p + 1] in p[j].linear:
97                                    if kk < len_pj - 1 and p[j].linear[kk + 1] in p[i].linear:97                                    if kk < len_pj - 1 and p[j].linear[kk + 1] in p[i].linear:
98                                        ind_prev_sub = p[i].linear.index(p[j].linear[kk + 1]) - 198                                        ind_prev_sub = p[i].linear.index(p[j].linear[kk + 1]) - 1
99                                p[i].linear.insert(ind_prev_sub + 1, p[j].linear[kk])99                                p[i].linear.insert(ind_prev_sub + 1, p[j].linear[kk])
100                                add += 1100                                add += 1
101                            len_pi = len(p[i].linear)101                            len_pi = len(p[i].linear)
102                        prev_ind = ind102                        prev_ind = ind
103                    prev_j = j103                    prev_j = j
104                    break104                    break
105            prev_sub = s105            prev_sub = s
106        ll = 0106        ll = 0
107        len_lin = len(p[i].linear)107        len_lin = len(p[i].linear)
108        for ind in range(1, len_lin):108        for ind in range(1, len_lin):
109            if p[i].linear[ind] == p[i].sub[ll]:109            if p[i].linear[ind] == p[i].sub[ll]:
110                ll += 1110                ll += 1
111                if ll >= len_sub:111                if ll >= len_sub:
112                    break112                    break
113        if ll < len_sub:113        if ll < len_sub:
114            return 0114            return 0
115    return 1115    return 1
116116
117def c3(p, res):117def c3(p, res):
118    len_sys = len(p[-1].sys)118    len_sys = len(p[-1].sys)
119    l = len(p) - 1119    l = len(p) - 1
120    seq = []120    seq = []
121    for i in range(len_sys):121    for i in range(len_sys):
122        for j in range(l):122        for j in range(l):
123            if p[j].sys[0] == p[-1].sys[i]:123            if p[j].sys[0] == p[-1].sys[i]:
124                seq.append(p[j])124                seq.append(p[j])
125    not_last = 0125    not_last = 0
126    len_seq = len(seq)126    len_seq = len(seq)
127    last_i = 0127    last_i = 0
128    fail = 0128    fail = 0
129    while 1:129    while 1:
130        if not_last == 1:130        if not_last == 1:
131            last_i += 1131            last_i += 1
132            if last_i >= len_seq:132            if last_i >= len_seq:
133                return 0133                return 0
134        if len(seq[0].linear) == 0:134        if len(seq[0].linear) == 0:
135            break135            break
136        last = seq[last_i].linear[-1]136        last = seq[last_i].linear[-1]
137        for el in seq:137        for el in seq:
138            if last in el.linear:138            if last in el.linear:
139                if el.linear.index(last) != len(el.linear) - 1:139                if el.linear.index(last) != len(el.linear) - 1:
140                    not_last = 1140                    not_last = 1
141                    break141                    break
142        if not_last == 0:142        if not_last == 0:
143            for el in seq:143            for el in seq:
144                if last in el.linear:144                if last in el.linear:
145                    el.linear.pop()145                    el.linear.pop()
146            res.insert(0, last)146            res.insert(0, last)
147    return 1147    return 1
148148
149def have_dtl(p, seq):149def have_dtl(p, seq):
150    l = len(p)150    l = len(p)
151    dtl = p[-1].fnd151    dtl = p[-1].fnd
152    l_dtl = len(dtl)152    l_dtl = len(dtl)
153    res = [0 for i in range(l_dtl)]153    res = [0 for i in range(l_dtl)]
154    for sys in seq:154    for sys in seq:
155        for i in range(l):155        for i in range(l):
156            if sys == p[i].sys[0]:156            if sys == p[i].sys[0]:
157                for el in p[i].dtl:157                for el in p[i].dtl:
158                    if el in dtl:158                    if el in dtl:
159                        j = dtl.index(el)159                        j = dtl.index(el)
160                        res[j] = 1160                        res[j] = 1
161    if 0 in res:161    if 0 in res:
162        return 0162        return 0
163    return 1163    return 1
164p = []164p = []
165i = 0165i = 0
166while 1:166while 1:
167    a = str(input())167    a = str(input())
168    t = Pepelac(a)168    t = Pepelac(a)
169    p.append(t)169    p.append(t)
170    if p[i].last == 1:170    if p[i].last == 1:
171        break171        break
172    i += 1172    i += 1
173seq = []173seq = []
174if mro(p) == 1:174if mro(p) == 1:
175    if c3(p, seq) == 1:175    if c3(p, seq) == 1:
176        if have_dtl(p, seq) == 1:176        if have_dtl(p, seq) == 1:
177            print('Correct')177            print('Correct')
178        else:178        else:
179            print('Incorrect')179            print('Incorrect')
180else:180else:
181    print('Incorrect')181    print('Incorrect')
182import sys182import sys
183exec(sys.stdin.read(), globals())183exec(sys.stdin.read(), globals())
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op