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ldHVybiAtMTsKCX0KI2VuZGlmICAgIAp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKKiC6r8r9w/uzxqO6IHNvY19zZW5kX2NvbmRpdGlvbl9jaGVjawoqILmmxNzD6Mr2o7ogvOyy4srHt/HC+tfjU09Dz/vPoreiy83M9bz+o6zI57n7yse000FQt6LLzbW9Q1CjrNTyc3JjX2lksdjQ686qQVCy4LXEbW9kdWxlaWSjrGRzdF9pZLHY0OvOqgoqICAgICAgICAgICAgICAgICAgICAgICAgICAgbW9kdWxlaWQ7ICDI57n7yse000NQt6LLzbW9QVCjrNTyc3JjX2lksdjQ686qQ1Cy4LXEbW9kdWxlaWSjrGRzdF9pZLHY0OvOqkFQsuC1xG1vZHVsZWlkLgoqILLOyv3LtcP3o7pzcmNfaWQ6z/vPoreiy83Eo7/pSUQgICBkZXN0X2lkOs/7z6K908rVxKO/6UlECiogt7Ugu9gg1rWjuiAxOrf7us/M9bz+MDqyu7f7us/M9bz+CiogxuTL/Mu1w/ejugoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8Kc3RhdGljIGludCBzb2Nfc2VuZF9jb25kaXRpb25fY2hlY2soaW50IHNyY19pZCwgaW50IGRzdF9pZCkKewojaWYgKEFQUF9PU19UWVBFID09IEFQUF9PU19UT1MpCglpZiAoKHNyY19pZCA8PSBNT0RVTEVfSURfQ1BCQVNFKSB8fCAoc3JjX2lkID49IE1PRFVMRV9JRF9NQVgpKSB7IC8vvOyy4nNyY19pZMrHt/HOqkNQusvEo7/pusUKCQlyZXR1cm4gMDsKCX0gZWxzZSBpZiAoKGRzdF9pZCA8PSBNT0RVTEVfSURfQVBCQVNFKSB8fCAoZHN0X2lkID49IE1PRFVMRV9JRF9DUEJBU0UpKSB7IC8vvOyy4mRzdF9pZMrHt/HOqkFQusvEo7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