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gICAgICBjYXNlICd0JzoKICAgICAgICAgICAgZ0ZzU2F2ZVBhcmFtLnRNYXhMb2dzaXplID0gYXRvaShvcHRhcmcpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlICdlJzoKICAgICAgICAgICAgaXNkYWVtb24gPSAxOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlICdtJzoKICAgICAgICAgICAgbWF4Q29ubmVjdHMgPSBhdG9pKG9wdGFyZyk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgJ3AnOgogICAgICAgICAgICBwb3J0ID0gYXRvaShvcHRhcmcpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlICdyJzoKICAgICAgICAgICAgbWFjaGluZW5hbWUgPSBvcHRhcmc7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgJ3MnOgogICAgICAgICAgICBzdHR5cGFybXMgPSBvcHRhcmc7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgJ2wnOgogICAgICAgICAgICBsaW5rbmFtZSA9IG9wdGFyZzsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSAneCc6CiAgICAgICAgICAgIGRlYnVnID0gYXRvaShvcHRhcmcpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlICd3JzoKICAgICAgICAgICAgd3JpdGVvbmx5ID0gMTsKICAgICAgICAgICAgYnJlYWs7ICAgIAogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHB1c2FnZShhcmd2WzBdKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQp9CgpzdGF0aWMgdm9pZCBwdXNhZ2UoY2hhciAqcHJvZ25hbWUpIAp7CiAgICBwcmludGYoImxvZyB0cmFjZSBzZXJpYWwgdmVyc2lvbiAxLjMuICBVc2FnZTpcbiIpOwogICAgcHJpbnRmKCJsb2NhbCBzYXZlOlstZCBkZXZpY2VwYXRoXSBbLWYgXCJsb2cgc2F2ZSB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