2022-12-05 09:39:58 +00:00
|
|
|
import sys
|
2022-12-05 16:57:08 +00:00
|
|
|
import numpy
|
2022-12-05 09:17:50 +00:00
|
|
|
|
|
|
|
|
2022-12-24 14:59:27 +00:00
|
|
|
def main():
|
|
|
|
inp_stacks, inp_moves = (x.split("\n") for x in sys.stdin.read().split("\n\n", 1))
|
2022-12-05 16:57:08 +00:00
|
|
|
|
2022-12-24 14:59:27 +00:00
|
|
|
rows = (line[1::4] for line in inp_stacks[::-1] if "[" in line)
|
|
|
|
stacks = [
|
|
|
|
numpy.array([ord(c) for c in x if c != " "], dtype=numpy.int8)
|
|
|
|
for x in zip(*rows)
|
|
|
|
]
|
|
|
|
stacks1 = numpy.array(stacks)
|
|
|
|
stacks2 = numpy.ndarray.copy(stacks1)
|
2022-12-05 09:17:50 +00:00
|
|
|
|
2022-12-24 14:59:27 +00:00
|
|
|
for i, line in enumerate(inp_moves):
|
|
|
|
if i % 10000 == 0:
|
|
|
|
print(i, len(inp_moves), end="\r")
|
|
|
|
if not line:
|
|
|
|
continue
|
2022-12-05 09:17:50 +00:00
|
|
|
|
2022-12-24 14:59:27 +00:00
|
|
|
_, a, _, b, _, c = line.split()
|
|
|
|
n, f, t = int(a), int(b) - 1, int(c) - 1
|
2022-12-05 09:17:50 +00:00
|
|
|
|
2022-12-24 14:59:27 +00:00
|
|
|
stacks1[t] = numpy.concatenate((stacks1[t], stacks1[f][-n:][::-1]))
|
|
|
|
stacks1[f] = stacks1[f][:-n]
|
2022-12-05 09:17:50 +00:00
|
|
|
|
2022-12-24 14:59:27 +00:00
|
|
|
stacks2[t] = numpy.concatenate((stacks2[t], stacks2[f][-n:]))
|
|
|
|
stacks2[f] = stacks2[f][:-n]
|
|
|
|
|
|
|
|
print("".join(chr(s[-1]) for s in stacks1), "".join(chr(s[-1]) for s in stacks2))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|