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WYpOwoJfSBlbHNlIHsKCQljbG9zZShmZCk7CgkJcmV0dXJuIC0xOwoJfQojZW5kaWYgICAgCn0KCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgoqILqvyv3D+7PGo7ogc29jX3NlbmRfY29uZGl0aW9uX2NoZWNrCioguabE3MPoyvajuiC87LLiyse38cL61+NTT0PP+8+it6LLzcz1vP6jrMjnufvKx7TTQVC3osvNtb1DUKOs1PJzcmNfaWSx2NDrzqpBULLgtcRtb2R1bGVpZKOsZHN0X2lksdjQ686qCiogICAgICAgICAgICAgICAgICAgICAgICAgICBtb2R1bGVpZDsgIMjnufvKx7TTQ1C3osvNtb1BUKOs1PJzcmNfaWSx2NDrzqpDULLgtcRtb2R1bGVpZKOsZHN0X2lksdjQ686qQVCy4LXEbW9kdWxlaWQuCiogss7K/cu1w/ejunNyY19pZDrP+8+it6LLzcSjv+lJRCAgIGRlc3RfaWQ6z/vPor3TytXEo7/pSUQKKiC3tSC72CDWtaO6IDE6t/u6z8z1vP4wOrK7t/u6z8z1vP4KKiDG5Mv8y7XD96O6CioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpzdGF0aWMgaW50IHNvY19zZW5kX2NvbmRpdGlvbl9jaGVjayhpbnQgc3JjX2lkLCBpbnQgZHN0X2lkKQp7CiNpZiAoQVBQX09TX1RZUEUgPT0gQVBQX09TX1RPUykKCWlmICgoc3JjX2lkIDw9IE1PRFVMRV9JRF9DUEJBU0UpIHx8IChzcmNfaWQgPj0gTU9EVUxFX0lEX01BWCkpIHsgLy+87LLic3JjX2lkyse38c6qQ1C6y8Sjv+m6xQoJCXJldHVybiAwOwoJfSBlbHNlIGlmICgoZHN0X2lkIDw9IE1PRFVMRV9JRF9BUEJBU0UpIHx8IChkc3RfaWQgPj0gTU9EVUxFX0lEX0NQQkF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