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ArIGNvc3QpIHsKICAgICAgICBkaXN0W254dF0gPSBkaXN0W3ZdICsgY29zdDsKICAgICAgICBwcS5lbXBsYWNlKGRpc3Rbbnh0XSwgbnh0KTsKICAgICAgfQogICAgfQogIH0KICByZXR1cm4gZGlzdDsKfQoKZGlncmFwaDxpbnQ+IGdyaWRfdG9fZGlncmFwaChjb25zdCBzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4mIHN2KSB7CiAgaW50IGggPSBzdi5zaXplKCksIHcgPSBzdlswXS5zaXplKCk7CiAgZGlncmFwaDxpbnQ+IGcoaCAqIHcpOwogIGNvbnN0ZXhwciBpbnQgZHhbNF0gPSB7MSwgMCwgLTEsIDB9LCBkeVs0XSA9IHswLCAxLCAwLCAtMX07CiAgYXV0byBPdXQgPSBbJl0oaW50IHgsIGludCB5KSB7IHJldHVybiAoeCA8IDAgfHwgeCA+PSBoIHx8IHkgPCAwIHx8IHkgPj0gdyk7IH07CiAgYXV0byBDb21wcmVzcyA9IFsmXShpbnQgeCwgaW50IHkpIHsgcmV0dXJuIHggKiB3ICsgeTsgfTsKICBmb3IgKGludCBpID0gMDsgaSA8IGg7ICsraSkgewogICAgZm9yIChpbnQgaiA9IDA7IGogPCB3OyArK2opIHsKICAgICAgZm9yIChpbnQgayA9IDA7IGsgPCA0OyArK2spIHsKICAgICAgICBpbnQgbnggPSBpICsgZHhba10sIG55ID0gaiArIGR5W2tdOwogICAgICAgIGlmIChPdXQobngsIG55KSkgY29udGludWU7CiAgICAgICAgaWYgKHN2W2ldW2pdID09ICcuJyAmJiBzdltueF1bbnldID09ICcuJykgewogICAgICAgICAgZy5hZGQoQ29tcHJlc3MoaSwgaiksIENvbXByZXNzKG54LCBueSksIDApOwogICAgICAgIH0KICAgICAgfQogICAgICBmb3IgKGludCBrID0gLTI7IGsgPD0gMjsgKytrKSB7CiAgICAgICAgZm9yIChpbnQgbCA9IC0yOyBsIDw9IDI7ICsrbCkgewogICAgICAgICAgaW50IG54ID0gaSArIGssI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