I2luY2x1ZGUgPHNvZnRhcF9hcGkuaD4NCiNpbmNsdWRlIDxlcnJuby5oPg0KI2luY2x1ZGUgPHdpZmkuaD4NCiNpbmNsdWRlICJ3bGFuX2ludGVyZmFjZS5oIg0KDQovKmNoYXIgdG8gaGV4Ki8NCmNoYXIgYzJ4KGNoYXIgYykNCnsNCiAgICBpZiAoKGMgPj0gJzAnKSAmJiAoYyA8PSAnOScpKQ0KICAgIHsNCiAgICAgICAgcmV0dXJuIGMgLSAnMCc7DQogICAgfQ0KICAgIGlmICgoYyA+PSAnYScpICYmIChjIDw9ICdmJykpDQogICAgew0KICAgICAgICByZXR1cm4gKGMgLSAnYScpICsgMTA7DQogICAgfQ0KICAgIGlmICgoYyA+PSAnQScpICYmIChjIDw9ICdGJykpDQogICAgew0KICAgICAgICByZXR1cm4gKGMgLSAnQScpICsgMTA7DQogICAgfQ0KICAgIHJldHVybiAwOw0KfQ0KDQovKnN0cmluZyB0byBoZXgqLw0KdW5zaWduZWQgY2hhciBzMngoY2hhciAqcykNCnsNCiAgICBpbnQgICAgIGk7DQogICAgY2hhciAgICBzdHJbM107DQogICAgdW5zaWduZWQgY2hhciByZXN1bHQ7DQoNCg0KICAgIGZvciAoaSA9IDA7IGkgPCAzOyBpKyspDQogICAgew0KICAgICAgICBzdHJbaV0gPSAqcysrOw0KICAgICAgICBpZiAoc3RyW2ldID09ICdcMCcpDQogICAgICAgIHsNCiAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICB9DQogICAgfQ0KDQogICAgcmVzdWx0ID0gMDsNCiAgICBmb3IgKGkgPSAwOyBpIDwgMzsgaSsrKQ0KICAgIHsNCiAgICAgICAgaWYgKHN0cltpXSA9PSAnXDAnKQ0KICAgICAgICB7DQogICAgICAgICAgICBicmVhazsNCiAgICAgICAgfQ0KICAgICAgICByZXN1bHQgPSAodW5zaWduZWQgY2hhcikoIGMyeChzdHJbaV0pICsgKHJlc3VsdCA8PCA0KSk7DQogICAgfQ0KDQogICAgcmV0dX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cmV0dXJuOw0KICAgIH0gDQogICAgbWVtc2V0KHJldCwgMCwgcmV0X2xlbik7IA0KICAgIGYgPSByZXQ7IA0KICAgIHdoaWxlICh0bXAgPCBkYXRhX2xlbikgDQogICAgeyANCiAgICAgICAgdGVtcCA9IDA7IA0KICAgICAgICBwcmVwYXJlID0gMDsgDQogICAgICAgIG1lbXNldChjaGFuZ2VkLCAnXDAnLCA0KTsgDQogICAgICAgIHdoaWxlICh0ZW1wIDwgMykgDQogICAgICAgIHsgDQogICAgICAgICAgICAvL3ByaW50ZigidG1wID0gJWRcbiIsIHRtcCk7IA0KICAgICAgICAgICAgaWYgKHRtcCA+PSBkYXRhX2xlbikgDQogICAgICAgICAgICB7IA0KICAgICAgICAgICAgICAgIGJyZWFrOyANCiAgICAgICAgICAgIH0gDQogICAgICAgICAgICBwcmVwYXJlID0gKChwcmVwYXJlIDw8IDgpIHwgKGRhdGFbdG1wXSAmIDB4RkYpKTsgDQogICAgICAgICAgICB0bXArKzsgDQogICAgICAgICAgICB0ZW1wKys7IA0KICAgICAgICB9IA0KICAgICAgICBwcmVwYXJlID0gKHByZXBhcmU8PCgoMy10ZW1wKSo4KSk7IA0KICAgICAgICAvL3ByaW50ZigiYmVmb3JlIGZvciA6IHRlbXAgPSAlZCwgcHJlcGFyZSA9ICVkXG4iLCB0ZW1wLCBwcmVwYXJlKTsgDQogICAgICAgIGZvciAoaSA9IDA7IGkgPCA0IDtpKysgKSANCiAgICAgICAgeyANCiAgICAgICAgICAgIGlmICh0ZW1wIDwgaSkgDQogICAgICAgICAgICB7IA0KICAgICAgICAgICAgICAgIGNoYW5nZWRbaV0gPSAweDQwOyANCiAgICAgICAgICAgIH0gDQogICAgICAgICAgICBlbHNlIA0KICAgICAgICAgICAgeyANCiAgICAgICAgICAgICAgICBjaGFuZ2VkW2ldID0gKHByZXBhcmU+PigoMy1pKSo2KSkgJiAweDNGOyANCiAgICAgICAgICAgIH0gDQogICAgICAgICAgICAqZiA9IGJhc2VbY2hh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