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gKl9fcmVzdWx0Ll9fc2VnXyB8PSBfX2IgPDwgKF9fcmVzdWx0Ll9fY3R6XyAtIF9fZmlyc3QuX19jdHpfKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyB8PSBfX2IgPj4gKF9fZmlyc3QuX19jdHpfIC0gX19yZXN1bHQuX19jdHpfKTsKICAgICAgICAgICAgX19yZXN1bHQuX19zZWdfICs9IChfX2RkbiArIF9fcmVzdWx0Ll9fY3R6XykgLyBfX2JpdHNfcGVyX3dvcmQ7CiAgICAgICAgICAgIF9fcmVzdWx0Ll9fY3R6XyA9IHN0YXRpY19jYXN0PHVuc2lnbmVkPigoX19kZG4gKyBfX3Jlc3VsdC5fX2N0el8pICAlIF9fYml0c19wZXJfd29yZCk7CiAgICAgICAgICAgIF9fZG4gLT0gX19kZG47CiAgICAgICAgICAgIGlmIChfX2RuID4gMCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgX19tID0gfl9fc3RvcmFnZV90eXBlKDApID4+IChfX2JpdHNfcGVyX3dvcmQgLSBfX2RuKTsKICAgICAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gJj0gfl9fbTsKICAgICAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gfD0gX19iID4+IChfX2ZpcnN0Ll9fY3R6XyArIF9fZGRuKTsKICAgICAgICAgICAgICAgIF9fcmVzdWx0Ll9fY3R6XyA9IHN0YXRpY19jYXN0PHVuc2lnbmVkPihfX2RuKTsKICAgICAgICAgICAgfQogICAgICAgICAgICArK19fZmlyc3QuX19zZWdfOwogICAgICAgICAgICAvLyBfX2ZpcnN0Ll9fY3R6XyA9IDA7CiAgICAgICAgfQogICAgICAgIC8vIF9fZmlyc3QuX19jdHpfID09IDA7CiAgICAgICAgLy8gZG8gbWlkZGxlIHdvcmRzCiAgICAgICAgdW5zaWduZWQgX19jbHpfciA9IF9fYml0c19wZXJfd29yZCAtIF9fcmVzdWx0Ll9fY3R6XzsKICAgICAgICBfX3N0b3JhZ2VfdHlwZSBfX20gPSB+X19zdG9yYWdlX3R5cGUoMCkgPDwgX19yZXN1bHQuX19jdHpfOwogICAgICAgIGZvciAoOyBfX24gPj0gX19iaXRzX3Blcl93b3JkOyBfX24gLT0gX19iaXRzX3Blcl93b3JkLCArK19fZmlyc3QuX19zZWdfKQogICAgICAgIHsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19iID0gKl9fZmlyc3QuX19zZWdfOwogICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfICY9IH5fX207CiAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gfD0gX19iIDw8IF9fcmVzdWx0Ll9fY3R6XzsKICAgICAgICAgICAgKytfX3Jlc3VsdC5fX3NlZ187CiAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gJj0gX19tOwogICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfIHw9IF9fYiA+PiBfX2Nsel9yOwogICAgICAgIH0KICAgICAgICAvLyBkbyBsYXN0IHdvcmQKICAgICAgICBpZiAoX19uID4gMCkKICAgICAgICB7CiAgICAgICAgICAgIF9fbSA9IH5fX3N0b3JhZ2VfdHlwZSgwKSA+PiAoX19iaXRzX3Blcl93b3JkIC0gX19uKTsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19iID0gKl9fZmlyc3QuX19zZWdfICYgX19tOwogICAgICAgICAgICBfX3N0b3JhZ2VfdHlwZSBfX2RuID0gX1NURDo6bWluKF9fbiwgc3RhdGljX2Nhc3Q8ZGlmZmVyZW5jZV90eXBlPihfX2Nsel9yKSk7CiAgICAgICAgICAgIF9fbSA9ICh+X19zdG9yYWdlX3R5cGUoMCkgPDwgX19yZXN1bHQuX19jdHpfKSAmICh+X19zdG9yYWdlX3R5cGUoMCkgPj4gKF9fY2x6X3IgLSBfX2RuKSk7CiAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gJj0gfl9fbTsKICAgICAg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3R6XyksIF9fbik7CiAgICAgICAgICAgIF9fbiAtPSBfX2RuOwogICAgICAgICAgICB1bnNpZ25lZCBfX2NseiA9IF9fYml0c19wZXJfd29yZCAtIF9fbGFzdC5fX2N0el87CiAgICAgICAgICAgIF9fc3RvcmFnZV90eXBlIF9fbSA9ICh+X19zdG9yYWdlX3R5cGUoMCkgPDwgKF9fbGFzdC5fX2N0el8gLSBfX2RuKSkgJiAofl9fc3RvcmFnZV90eXBlKDApID4+IF9fY2x6KTsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19iID0gKl9fbGFzdC5fX3NlZ18gJiBfX207CiAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gJj0gfl9fbTsKICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyB8PSBfX2I7CiAgICAgICAgICAgIF9fcmVzdWx0Ll9fY3R6XyA9IHN0YXRpY19jYXN0PHVuc2lnbmVkPigoKC1fX2RuICYgKF9fYml0c19wZXJfd29yZCAtIDEpKSArCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX3Jlc3VsdC5fX2N0el8pICAlIF9fYml0c19wZXJfd29yZCk7CiAgICAgICAgICAgIC8vIF9fbGFzdC5fX2N0el8gPSAwCiAgICAgICAgIH0KICAgICAgICAvLyBfX2xhc3QuX19jdHpfID09IDAgfHwgX19uID09IDAKICAgICAgICAvLyBfX3Jlc3VsdC5fX2N0el8gPT0gMCB8fCBfX24gPT0gMAogICAgICAgIC8vIGRvIG1pZGRsZSB3b3JkcwogICAgICAgIF9fc3RvcmFnZV90eXBlIF9fbncgPSBfX24gLyBfX2JpdHNfcGVyX3dvcmQ7CiAgICAgICAgX19yZXN1bHQuX19zZWdfIC09IF9fbnc7CiAgICAgICAgX19sYXN0Ll9fc2VnXyAtPSBfX253OwogICAgICAgIF9TVEQ6Om1lbW1vdmUoX19yZXN1bHQuX19zZWdfLCBfX2xhc3QuX19zZWdfLCBfX253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5cGUoMCkgPDwgKF9fcmVzdWx0Ll9fY3R6XyAtIF9fZGRuKSkgJiAofl9fc3RvcmFnZV90eXBlKDApID4+IF9fY2x6X3IpOwogICAgICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyAmPSB+X19tOwogICAgICAgICAgICAgICAgaWYgKF9fcmVzdWx0Ll9fY3R6XyA+IF9fbGFzdC5fX2N0el8pCiAgICAgICAgICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyB8PSBfX2IgPDwgKF9fcmVzdWx0Ll9fY3R6XyAtIF9fbGFzdC5fX2N0el8pOwogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gfD0gX19iID4+IChfX2xhc3QuX19jdHpfIC0gX19yZXN1bHQuX19jdHpfKTsKICAgICAgICAgICAgICAgIF9fcmVzdWx0Ll9fY3R6XyA9IHN0YXRpY19jYXN0PHVuc2lnbmVkPigoKC1fX2RkbiAmIChfX2JpdHNfcGVyX3dvcmQgLSAxKSkgKwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX3Jlc3VsdC5fX2N0el8pICAlIF9fYml0c19wZXJfd29yZCk7CiAgICAgICAgICAgICAgICBfX2RuIC09IF9fZGRuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChfX2RuID4gMCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgLy8gX19yZXN1bHQuX19jdHpfID09IDAKICAgICAgICAgICAgICAgIC0tX19yZXN1bHQuX19zZWdfOwogICAgICAgICAgICAgICAgX19yZXN1bHQuX19jdHpfID0gc3RhdGljX2Nhc3Q8dW5zaWduZWQ+KC1fX2RuICYgKF9fYml0c19wZXJfd29yZCAtIDEpKTsKICAgICAgICAgICAgICAgIF9fbSA9IH5fX3N0b3JhZ2VfdHlwZSgwKSA8PCBfX3Jlc3VsdC5fX2N0el87CiAgICAgICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfICY9IH5fX207CiAgICAgICAgICAgICAgICBfX2xhc3QuX19jdHpfIC09IF9fZG4gKyBfX2RkbjsKICAgICAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gfD0gX19iIDw8IChfX3Jlc3VsdC5fX2N0el8gLSBfX2xhc3QuX19jdHpfKTsKICAgICAgICAgICAgfQogICAgICAgICAgICAvLyBfX2xhc3QuX19jdHpfID0gMAogICAgICAgICB9CiAgICAgICAgLy8gX19sYXN0Ll9fY3R6XyA9PSAwIHx8IF9fbiA9PSAwCiAgICAgICAgLy8gX19yZXN1bHQuX19jdHpfICE9IDAgfHwgX19uID09IDAKICAgICAgICAvLyBkbyBtaWRkbGUgd29yZHMKICAgICAgICB1bnNpZ25lZCBfX2Nsel9yID0gX19iaXRzX3Blcl93b3JkIC0gX19yZXN1bHQuX19jdHpfOwogICAgICAgIF9fc3RvcmFnZV90eXBlIF9fbSA9IH5fX3N0b3JhZ2VfdHlwZSgwKSA+PiBfX2Nsel9yOwogICAgICAgIGZvciAoOyBfX24gPj0gX19iaXRzX3Blcl93b3JkOyBfX24gLT0gX19iaXRzX3Blcl93b3JkKQogICAgICAgIHsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19iID0gKi0tX19sYXN0Ll9fc2VnXzsKICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyAmPSB+X19tOwogICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfIHw9IF9fYiA+PiBfX2Nsel9yOwogICAgICAgICAgICAqLS1fX3Jlc3VsdC5fX3NlZ18gJj0gX19tOwogICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfIHw9IF9fYiA8PCBfX3Jlc3VsdC5fX2N0el87CiAgICAgICAgfQogICAgICAgIC8vIGRvIGxhc3Qgd29yZAogICAgICAgIGlmIChfX24gPiAwKQogICAgICAgIHsKICAgICAgICAgICAgX19tID0gfl9fc3RvcmFnZV90eXBlKDApIDw8IChfX2JpdHNfcGVyX3dvcmQgLSBfX24pOwogICAgICAgICAgICBfX3N0b3JhZ2VfdHlwZSBfX2IgPSAqLS1fX2xhc3QuX19zZWdfICYgX19tOwogICAgICAgICAgICB1bnNpZ25lZCBfX2Nsel9yID0gX19iaXRzX3Blcl93b3JkIC0gX19yZXN1bHQuX19jdHpfOwogICAgICAgICAgICBfX3N0b3JhZ2VfdHlwZSBfX2RuID0gX1NURDo6bWluKF9fbiwgc3RhdGljX2Nhc3Q8ZGlmZmVyZW5jZV90eXBlPihfX3Jlc3VsdC5fX2N0el8pKTsKICAgICAgICAgICAgX19tID0gKH5fX3N0b3JhZ2VfdHlwZSgwKSA8PCAoX19yZXN1bHQuX19jdHpfIC0gX19kbikpICYgKH5fX3N0b3JhZ2VfdHlwZSgwKSA+PiBfX2Nsel9yKTsKICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyAmPSB+X19tOwogICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfIHw9IF9fYiA+PiAoX19iaXRzX3Blcl93b3JkIC0gX19yZXN1bHQuX19jdHpfKTsKICAgICAgICAgICAgX19yZXN1bHQuX19jdHpfID0gc3RhdGljX2Nhc3Q8dW5zaWduZWQ+KCgoLV9fZG4gJiAoX19iaXRzX3Blcl93b3JkIC0gMSkpICsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX3Jlc3VsdC5fX2N0el8pICAlIF9fYml0c19wZXJfd29yZCk7CiAgICAgICAgICAgIF9fbiAtPSBfX2RuOwogICAgICAgICAgICBpZiAoX19uID4gMCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgLy8gX19yZXN1bHQuX19jdHpfID09IDAKICAgICAgICAgICAgICAgIC0tX19yZXN1bHQuX19zZWdfOwogICAgICAgICAgICAgICAgX19yZXN1bHQuX19jdHpfID0gc3RhdGljX2Nhc3Q8dW5zaWduZWQ+KC1fX24gJiAoX19iaXRzX3Blcl93b3JkIC0gMSkpOwogICAgICAgIC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gICAgICAgICAgIF9fcmVzdWx0Ll9fY3R6XyA9IHN0YXRpY19jYXN0PHVuc2lnbmVkPigoX19kbiArIF9fcmVzdWx0Ll9fY3R6XykgICUgX19iaXRzX3Blcl93b3JkKTsKICAgICAgICAgICAgKytfX2ZpcnN0Ll9fc2VnXzsKICAgICAgICAgICAgLy8gX19maXJzdC5fX2N0el8gPSAwOwogICAgICAgIH0KICAgICAgICAvLyBfX2ZpcnN0Ll9fY3R6XyA9PSAwOwogICAgICAgIC8vIGRvIG1pZGRsZSB3b3JkcwogICAgICAgIGZvciAoOyBfX24gPj0gX19iaXRzX3Blcl93b3JkOyBfX24gLT0gX19iaXRzX3Blcl93b3JkLCArK19fZmlyc3QuX19zZWdfLCArK19fcmVzdWx0Ll9fc2VnXykKICAgICAgICAgICAgc3dhcCgqX19maXJzdC5fX3NlZ18sICpfX3Jlc3VsdC5fX3NlZ18pOwogICAgICAgIC8vIGRvIGxhc3Qgd29yZAogICAgICAgIGlmIChfX24gPiAwKQogICAgICAgIHsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19tID0gfl9fc3RvcmFnZV90eXBlKDApID4+IChfX2JpdHNfcGVyX3dvcmQgLSBfX24pOwogICAgICAgICAgICBfX3N0b3JhZ2VfdHlwZSBfX2IxID0gKl9fZmlyc3QuX19zZWdfICYgX19tOwogICAgICAgICAgICAqX19maXJzdC5fX3NlZ18gJj0gfl9fbTsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19iMiA9ICpfX3Jlc3VsdC5fX3NlZ18gJiBfX207CiAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gJj0gfl9fbTsKICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyB8PSBfX2IxOwogICAgICAgICAgICAqX19maXJzdC5fX3NlZ18gIHw9IF9fYjI7CiAgICAgICAgICAgIF9fcmVzdWx0Ll9fY3R6XyA9IHN0YXRpY19jYXN0PHVuc2lnbmVkPihfX24pOwogICAgICAgIH0K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lX3R5cGUgX19tID0gKH5fX3N0b3JhZ2VfdHlwZSgwKSA8PCBfX2ZpcnN0Ll9fY3R6XykgJiAofl9fc3RvcmFnZV90eXBlKDApID4+IChfX2Nsel9mIC0gX19kbikpOwogICAgICAgICAgICBfX3N0b3JhZ2VfdHlwZSBfX2IxID0gKl9fZmlyc3QuX19zZWdfICYgX19tOwogICAgICAgICAgICAqX19maXJzdC5fX3NlZ18gJj0gfl9fbTsKICAgICAgICAgICAgdW5zaWduZWQgX19jbHpfciA9IF9fYml0c19wZXJfd29yZCAtIF9fcmVzdWx0Ll9fY3R6XzsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19kZG4gPSBfU1REOjptaW48X19zdG9yYWdlX3R5cGU+KF9fZG4sIF9fY2x6X3IpOwogICAgICAgICAgICBfX20gPSAofl9fc3RvcmFnZV90eXBlKDApIDw8IF9fcmVzdWx0Ll9fY3R6XykgJiAofl9fc3RvcmFnZV90eXBlKDApID4+IChfX2Nsel9yIC0gX19kZG4pKTsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19iMiA9ICpfX3Jlc3VsdC5fX3NlZ18gJiBfX207CiAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gJj0gfl9fbTsKICAgICAgICAgICAgaWYgKF9fcmVzdWx0Ll9fY3R6XyA+IF9fZmlyc3QuX19jdHpfKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB1bnNpZ25lZCBfX3MgPSBfX3Jlc3VsdC5fX2N0el8gLSBfX2ZpcnN0Ll9fY3R6XzsKICAgICAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gfD0gX19iMSA8PCBfX3M7CiAgICAgICAgICAgICAgICAqX19maXJzdC5fX3NlZ18gIHw9IF9fYjIgPj4gX19zOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdW5zaWduZWQgX19zID0gX19maXJzdC5fX2N0el8gLSBfX3Jlc3VsdC5fX2N0el87CiAgICAgICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfIHw9IF9fYjEgPj4gX19zOwogICAgICAgICAgICAgICAgKl9fZmlyc3QuX19zZWdfICB8PSBfX2IyIDw8IF9fczsKICAgICAgICAgICAgfQogICAgICAgICAgICBfX3Jlc3VsdC5fX3NlZ18gKz0gKF9fZGRuICsgX19yZXN1bHQuX19jdHpfKSAvIF9fYml0c19wZXJfd29yZDsKICAgICAgICAgICAgX19yZXN1bHQuX19jdHpfID0gc3RhdGljX2Nhc3Q8dW5zaWduZWQ+KChfX2RkbiArIF9fcmVzdWx0Ll9fY3R6XykgICUgX19iaXRzX3Blcl93b3JkKTsKICAgICAgICAgICAgX19kbiAtPSBfX2RkbjsKICAgICAgICAgICAgaWYgKF9fZG4gPiAwKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBfX20gPSB+X19zdG9yYWdlX3R5cGUoMCkgPj4gKF9fYml0c19wZXJfd29yZCAtIF9fZG4pOwogICAgICAgICAgICAgICAgX19iMiA9ICpfX3Jlc3VsdC5fX3NlZ18gJiBfX207CiAgICAgICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfICY9IH5fX207CiAgICAgICAgICAgICAgICB1bnNpZ25lZCBfX3MgPSBfX2ZpcnN0Ll9fY3R6XyArIF9fZGRuOwogICAgICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyB8PSBfX2IxID4+IF9fczsKICAgICAgICAgICAgICAgICpfX2ZpcnN0Ll9fc2VnXyAgfD0gX19iMiA8PCBfX3M7CiAgICAgICAgICAgICAgICBfX3Jlc3VsdC5fX2N0el8gPSBzdGF0aWNfY2FzdDx1bnNpZ25lZD4oX19kbik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgKytfX2ZpcnN0Ll9fc2VnXzsKICAgICAgICAgICAgLy8gX19maXJzdC5fX2N0el8gPSAwOwogICAgICAgIH0KICAgICAgICAvLyBfX2ZpcnN0Ll9fY3R6XyA9PSAwOwogICAgICAgIC8vIGRvIG1pZGRsZSB3b3JkcwogICAgICAgIF9fc3RvcmFnZV90eXBlIF9fbSA9IH5fX3N0b3JhZ2VfdHlwZSgwKSA8PCBfX3Jlc3VsdC5fX2N0el87CiAgICAgICAgdW5zaWduZWQgX19jbHpfciA9IF9fYml0c19wZXJfd29yZCAtIF9fcmVzdWx0Ll9fY3R6XzsKICAgICAgICBmb3IgKDsgX19uID49IF9fYml0c19wZXJfd29yZDsgX19uIC09IF9fYml0c19wZXJfd29yZCwgKytfX2ZpcnN0Ll9fc2VnXykKICAgICAgICB7CiAgICAgICAgICAgIF9fc3RvcmFnZV90eXBlIF9fYjEgPSAqX19maXJzdC5fX3NlZ187CiAgICAgICAgICAgIF9fc3RvcmFnZV90eXBlIF9fYjIgPSAqX19yZXN1bHQuX19zZWdfICYgX19tOwogICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfICY9IH5fX207CiAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gfD0gX19iMSA8PCBfX3Jlc3VsdC5fX2N0el87CiAgICAgICAgICAgICpfX2ZpcnN0Ll9fc2VnXyAgPSBfX2IyID4+IF9fcmVzdWx0Ll9fY3R6XzsKICAgICAgICAgICAgKytfX3Jlc3VsdC5fX3NlZ187CiAgICAgICAgICAgIF9fYjIgPSAqX19yZXN1bHQuX19zZWdfICYgfl9fbTsKICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyAmPSBfX207CiAgICAgICAgICAgICpfX3Jlc3VsdC5fX3NlZ18gfD0gX19iMSA+PiBfX2Nsel9yOwogICAgICAgICAgICAqX19maXJzdC5fX3NlZ18gIHw9IF9fYjIgPDwgX19jbHpfcjsKICAgICAgICB9CiAgICAgICAgLy8gZG8gbGFzdCB3b3JkCiAgICAgICAgaWYgKF9fbiA+IDApCiAgICAgICAgewogICAgICAgICAgICBfX20gPSB+X19zdG9yYWdlX3R5cGUoMCkgPj4gKF9fYml0c19wZXJfd29yZCAtIF9fbik7CiAgICAgICAgICAgIF9fc3RvcmFnZV90eXBlIF9fYjEgPSAqX19maXJzdC5fX3NlZ18gJiBfX207CiAgICAgICAgICAgICpfX2ZpcnN0Ll9fc2VnXyAmPSB+X19tOwogICAgICAgICAgICBfX3N0b3JhZ2VfdHlwZSBfX2RuID0gX1NURDo6bWluPF9fc3RvcmFnZV90eXBlPihfX24sIF9fY2x6X3IpOwogICAgICAgICAgICBfX20gPSAofl9fc3RvcmFnZV90eXBlKDApIDw8IF9fcmVzdWx0Ll9fY3R6XykgJiAofl9fc3RvcmFnZV90eXBlKDApID4+IChfX2Nsel9yIC0gX19kbikpOwogICAgICAgICAgICBfX3N0b3JhZ2VfdHlwZSBfX2IyID0gKl9fcmVzdWx0Ll9fc2VnXyAmIF9fbTsKICAgICAgICAgICAgKl9fcmVzdWx0Ll9fc2VnXyAmPSB+X19tOwogICAgICAgICAgICAqX19yZXN1bHQuX19zZWdfIHw9IF9fYjEgPDwgX19yZXN1bHQuX19jdHpfOwogICAgICAgICAgICAqX19maXJzdC5fX3NlZ18gIHw9IF9fYjIgPj4gX19yZXN1bHQuX19jdHpfOwogICAgICAgICAgICBfX3Jlc3VsdC5fX3NlZ18gKz0gKF9fZG4gKyBfX3Jlc3VsdC5fX2N0el8pIC8gX19iaXRzX3Blcl93b3JkOwogICAgICAgICAgICBfX3Jlc3VsdC5fX2N0el8gPSBzdGF0aWNfY2FzdDx1bnNpZ25lZD4oKF9fZG4gKyBfX3Jlc3VsdC5fX2N0el8pICAlIF9fYml0c19wZXJfd29yZCk7CiAgICAgICAgICAgIF9fbiAtPSBfX2RuOwogICAgICAgICAgICBpZiAoX19uID4gMCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgX19tID0gfl9fc3RvcmFnZV90eXBlKDApID4+IChfX2JpdHNfcGVyX3dvcmQgLSBfX24pOwogICAgICAgICAgICAgICAgX19iMiA9ICpfX3Jlc3VsdC5fX3NlZ18gJiBfX207CiAgICAgICAgICAgICAgICAqX19yZXN1bHQuX19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xzZT4gX19tcCA9IF9TVEQ6OnN3YXBfcmFuZ2VzKF9fZmlyc3QsIF9fbWlkZGxlLCBfX21pZGRsZSk7CiAgICAgICAgICAgICAgICBfX2ZpcnN0ID0gX19taWRkbGU7CiAgICAgICAgICAgICAgICBfX21pZGRsZSA9IF9fbXA7CiAgICAgICAgICAgICAgICBfX2QyIC09IF9fZDE7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgaWYgKF9fZDIgPD0gX19iaXRfYXJyYXk8X0M+OjpjYXBhY2l0eSgpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBfX2JpdF9hcnJheTxfQz4gX19iKF9fZDIpOwogICAgICAgICAgICAgICAgX1NURDo6Y29weShfX21pZGRsZSwgX19sYXN0LCBfX2IuYmVnaW4oKSk7CiAgICAgICAgICAgICAgICBfU1REOjpjb3B5X2JhY2t3YXJkKF9fYi5iZWdpbigpLCBfX2IuZW5kKCksIF9TVEQ6OmNvcHlfYmFja3dhcmQoX19maXJzdCwgX19taWRkbGUsIF9fbGFzdCkpOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfQywgZmFsc2U+IF9fbXAgPSBfX2ZpcnN0ICsgX19kMjsKICAgICAgICAgICAgICAgIF9TVEQ6OnN3YXBfcmFuZ2VzKF9fZmlyc3QsIF9fbXAsIF9fbWlkZGxlKTsKICAgICAgICAgICAgICAgIF9fZmlyc3QgPSBfX21wOwogICAgICAgICAgICAgICAgX19kMSAtPSBfX2QyOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIF9fcjsKfQoKLy8gZXF1YWwKCnRlbXBsYXRlIDxjbGFzcyBfQz4KYm9vbApfX2VxdWFsX3VuYWxpZ25lZChfX2JpdF9pdGVyYXRvcjxfQywgd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0b3JhZ2VfdHlwZSgwKSA+PiAoX19iaXRzX3Blcl93b3JkIC0gX19kbik7CiAgICAgICAgICAgICAgICBpZiAoKCpfX2ZpcnN0Mi5fX3NlZ18gJiBfX20pICE9IChfX2IgPj4gKF9fZmlyc3QxLl9fY3R6XyArIF9fZGRuKSkpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICAgICAgX19maXJzdDIuX19jdHpfID0gc3RhdGljX2Nhc3Q8dW5zaWduZWQ+KF9fZG4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgICsrX19maXJzdDEuX19zZWdfOwogICAgICAgICAgICAvLyBfX2ZpcnN0MS5fX2N0el8gPSAwOwogICAgICAgIH0KICAgICAgICAvLyBfX2ZpcnN0MS5fX2N0el8gPT0gMDsKICAgICAgICAvLyBkbyBtaWRkbGUgd29yZHMKICAgICAgICB1bnNpZ25lZCBfX2Nsel9yID0gX19iaXRzX3Blcl93b3JkIC0gX19maXJzdDIuX19jdHpfOwogICAgICAgIF9fc3RvcmFnZV90eXBlIF9fbSA9IH5fX3N0b3JhZ2VfdHlwZSgwKSA8PCBfX2ZpcnN0Mi5fX2N0el87CiAgICAgICAgZm9yICg7IF9fbiA+PSBfX2JpdHNfcGVyX3dvcmQ7IF9fbiAtPSBfX2JpdHNfcGVyX3dvcmQsICsrX19maXJzdDEuX19zZWdfKQogICAgICAgIHsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19iID0gKl9fZmlyc3QxLl9fc2VnXzsKICAgICAgICAgICAgaWYgKCgqX19maXJzdDIuX19zZWdfICYgX19tKSAhPSAoX19iIDw8IF9fZmlyc3QyLl9fY3R6XykpCiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgICsrX19maXJzdDIuX19zZWdfOwogICAgICAgICAgICBpZiAoKCpfX2ZpcnN0Mi5fX3NlZ18gJiB+X19tKSAhPSAoX19iID4+IF9fY2x6X3IpKQogICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICAvLyBkbyBsYXN0IHdvcmQKICAgICAgICBpZiAoX19uID4gMCkKICAgICAgICB7CiAgICAgICAgICAgIF9fbSA9IH5fX3N0b3JhZ2VfdHlwZSgwKSA+PiAoX19iaXRzX3Blcl93b3JkIC0gX19uKTsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19iID0gKl9fZmlyc3QxLl9fc2VnXyAmIF9fbTsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19kbiA9IF9TVEQ6Om1pbihfX24sIHN0YXRpY19jYXN0PGRpZmZlcmVuY2VfdHlwZT4oX19jbHpfcikpOwogICAgICAgICAgICBfX20gPSAofl9fc3RvcmFnZV90eXBlKDApIDw8IF9fZmlyc3QyLl9fY3R6XykgJiAofl9fc3RvcmFnZV90eXBlKDApID4+IChfX2Nsel9yIC0gX19kbikpOwogICAgICAgICAgICBpZiAoKCpfX2ZpcnN0Mi5fX3NlZ18gJiBfX20pICE9IChfX2IgPDwgX19maXJzdDIuX19jdHpfKSkKICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgX19maXJzdDIuX19zZWdfICs9IChfX2RuICsgX19maXJzdDIuX19jdHpfKSAvIF9fYml0c19wZXJfd29yZDsKICAgICAgICAgICAgX19maXJzdDIuX19jdHpfID0gc3RhdGljX2Nhc3Q8dW5zaWduZWQ+KChfX2RuICsgX19maXJzdDIuX19jdHpfKSAgJSBfX2JpdHNfcGVyX3dvcmQpOwogICAgICAgICAgICBfX24gLT0gX19kbjsKICAgICAgICAgICAgaWYgKF9fbiA+IDApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIF9fbSA9IH5fX3N0b3JhZ2VfdHlwZSgwKSA+PiAoX19iaXRzX3Blcl93b3JkIC0gX19uKTsKICAgICAgICAgICAgICAgIGlmICgoKl9fZmlyc3QyLl9fc2VnXyAmIF9fbSkgIT0gKF9fYiA+PiBfX2Ru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dG9yYWdlX3R5cGUoMCkgPDwgX19maXJzdDEuX19jdHpfKSAmICh+X19zdG9yYWdlX3R5cGUoMCkgPj4gKF9fY2x6IC0gX19kbikpOwogICAgICAgICAgICBpZiAoKCpfX2ZpcnN0Mi5fX3NlZ18gJiBfX20pICE9ICgqX19maXJzdDEuX19zZWdfICYgX19tKSkKICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgKytfX2ZpcnN0Mi5fX3NlZ187CiAgICAgICAgICAgICsrX19maXJzdDEuX19zZWdfOwogICAgICAgICAgICAvLyBfX2ZpcnN0MS5fX2N0el8gPSAwOwogICAgICAgICAgICAvLyBfX2ZpcnN0Mi5fX2N0el8gPSAwOwogICAgICAgIH0KICAgICAgICAvLyBfX2ZpcnN0MS5fX2N0el8gPT0gMDsKICAgICAgICAvLyBfX2ZpcnN0Mi5fX2N0el8gPT0gMDsKICAgICAgICAvLyBkbyBtaWRkbGUgd29yZHMKICAgICAgICBmb3IgKDsgX19uID49IF9fYml0c19wZXJfd29yZDsgX19uIC09IF9fYml0c19wZXJfd29yZCwgKytfX2ZpcnN0MS5fX3NlZ18sICsrX19maXJzdDIuX19zZWdfKQogICAgICAgICAgICBpZiAoKl9fZmlyc3QyLl9fc2VnXyAhPSAqX19maXJzdDEuX19zZWdfKQogICAgICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIC8vIGRvIGxhc3Qgd29yZAogICAgICAgIGlmIChfX24gPiAwKQogICAgICAgIHsKICAgICAgICAgICAgX19zdG9yYWdlX3R5cGUgX19tID0gfl9fc3RvcmFnZV90eXBlKDApID4+IChfX2JpdHNfcGVyX3dvcmQgLSBfX24pOwogICAgICAgICAgICBpZiAoKCpfX2ZpcnN0Mi5fX3NlZ18gJiBfX20pICE9ICgqX19maXJzdDEuX19zZWdfICYgX19tKSkKICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKfQoKdGVtcGxhdGUgPGNsYXNzIF9DLCBib29sIF9JQzEsIGJvb2wgX0lDMj4KYm9vbAplcXVhbChfX2JpdF9pdGVyYXRvcjxfQywgX0lDMT4gX19maXJzdDEsIF9fYml0X2l0ZXJhdG9yPF9DLCBfSUMxPiBfX2xhc3QxLCBfX2JpdF9pdGVyYXRvcjxfQywgX0lDMj4gX19maXJzdDIpCnsKICAgIGlmIChfX2ZpcnN0MS5fX2N0el8gPT0gX19maXJzdDIuX19jdHpfKQogICAgICAgIHJldHVybiBfX2VxdWFsX2FsaWduZWQoX19maXJzdDEsIF9fbGFzdDEsIF9fZmlyc3QyKTsKICAgIHJldHVybiBfX2VxdWFsX3VuYWxpZ25lZChfX2ZpcnN0MSwgX19sYXN0MSwgX19maXJzdDIpOwp9Cgp0ZW1wbGF0ZSA8Y2xhc3MgX0MsIGJvb2wgX0lzQ29uc3Q+CmNsYXNzIF9fYml0X2l0ZXJhdG9yCnsKcHVibGljOgogICAgdHlwZWRlZiB0eXBlbmFtZSBfQzo6ZGlmZmVyZW5jZV90eXBlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRpZmZlcmVuY2VfdHlwZTsKICAgIHR5cGVkZWYgYm9vbCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YWx1ZV90eXBlOwogICAgdHlwZWRlZiBfX2JpdF9pdGVyYXRvciAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvaW50ZXI7CiAgICB0eXBlZGVmIHR5cGVuYW1lIGNvbmRpdGlvbmFsPF9Jc0NvbnN0LCBfX2JpdF9jb25zdF9yZWZlcmVuY2U8X0M+LCBfX2JpdF9yZWZlcmVuY2U8X0M+ID46OnR5cGUgcmVmZXJlbmNlOwogICAgdHlwZWRlZ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ElCQ1BQX0lOTElORV9WSVNJQklMSVRZIF9fYml0X2l0ZXJhdG9yJiBvcGVyYXRvcisrKCkKICAgIHsKICAgICAgICBpZiAoX19jdHpfICE9IF9fYml0c19wZXJfd29yZC0xKQogICAgICAgICAgICArK19fY3R6XzsKICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBfX2N0el8gPSAwOwogICAgICAgICAgICArK19fc2VnXzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICp0aGlzOwogICAgfQogICAgCiAgICBfTElCQ1BQX0lOTElORV9WSVNJQklMSVRZIF9fYml0X2l0ZXJhdG9yIG9wZXJhdG9yKysoaW50KQogICAgewogICAgICAgIF9fYml0X2l0ZXJhdG9yIF9fdG1wID0gKnRoaXM7CiAgICAgICAgKysoKnRoaXMpOwogICAgICAgIHJldHVybiBfX3RtcDsKICAgIH0KICAgIAogICAgX0xJQkNQUF9JTkxJTkVfVklTSUJJTElUWSBfX2JpdF9pdGVyYXRvciYgb3BlcmF0b3ItLSgpCiAgICB7CiAgICAgICAgaWYgKF9fY3R6XyAhPSAwKQogICAgICAgICAgICAtLV9fY3R6XzsKICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBfX2N0el8gPSBfX2JpdHNfcGVyX3dvcmQgLSAxOwogICAgICAgICAgICAtLV9fc2VnXzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICp0aGlzOwogICAgfQogICAgCiAgICBfTElCQ1BQX0lOTElORV9WSVNJQklMSVRZIF9fYml0X2l0ZXJhdG9yIG9wZXJhdG9yLS0oaW50KQogICAgewogICAgICAgIF9fYml0X2l0ZXJhdG9yIF9fdG1wID0gKnRoaXM7CiAgICAgICAgLS0oKnRoaXMpOwogICAgICAgIHJldHVybiBfX3RtcDsKICAgIH0KICAgIAogICAgX0xJQkNQUF9JTkxJTkVfVklTSUJJTElUWSBfX2JpdF9pdGVyYXRvciYgb3BlcmF0b3IrPShkaWZmZXJlbmNlX3R5cGUgX19uKQogICAgewogICAgICAgIGlmIChfX24gPj0gMCkKICAgICAgICAgICAgX19zZWdfICs9IChfX24gKyBfX2N0el8pIC8gX19iaXRzX3Blcl93b3JkOwogICAgICAgIGVsc2UKICAgICAgICAgICAgX19zZWdfICs9IHN0YXRpY19jYXN0PGRpZmZlcmVuY2VfdHlwZT4oX19uIC0gX19iaXRzX3Blcl93b3JkICsgX19jdHpfICsgMSkKICAgICAgICAgICAgICAgICAgICAvIHN0YXRpY19jYXN0PGRpZmZlcmVuY2VfdHlwZT4oX19iaXRzX3Blcl93b3JkKTsKICAgICAgICBfX24gJj0gKF9fYml0c19wZXJfd29yZCAtIDEpOwogICAgICAgIF9fY3R6XyA9IHN0YXRpY19jYXN0PHVuc2lnbmVkPigoX19uICsgX19jdHpfKSAgJSBfX2JpdHNfcGVyX3dvcmQpOwogICAgICAgIHJldHVybiAqdGhpczsKICAgIH0KICAgIAogICAgX0xJQkNQUF9JTkxJTkVfVklTSUJJTElUWSBfX2JpdF9pdGVyYXRvciYgb3BlcmF0b3ItPShkaWZmZXJlbmNlX3R5cGUgX19uKQogICAgewogICAgICAgIHJldHVybiAqdGhpcyArPSAtX19uOwogICAgfQogICAgCiAgICBfTElCQ1BQX0lOTElORV9WSVNJQklMSVRZIF9fYml0X2l0ZXJhdG9yIG9wZXJhdG9yKyhkaWZmZXJlbmNlX3R5cGUgX19uKSBjb25zdAogICAgewogICAgICAgIF9fYml0X2l0ZXJhdG9yIF9fdCgqdGhpcyk7CiAgICAgICAgX190ICs9IF9fbjsKICAgICAgICByZXR1cm4gX190OwogICAgfQogICAgCiAgICBfTElCQ1BQX0lOTElORV9WSVNJQklMSVRZIF9fYml0X2l0ZXJhdG9yIG9wZXJhdG9yLShkaWZmZXJlbmNlX3R5cGUgX19uKSBjb25zdAogICAgewogICAgICAgIF9fYml0X2l0ZXJhdG9yIF9fdCgqdGhpcyk7CiAgICAgICAgX190IC09IF9fbjsKICAgICAgICByZXR1cm4gX190OwogICAgfQoKICAgIF9MSUJDUFB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gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfRCwgX0lDPiBfX2xhc3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gX19yZXN1bHQpOwogICAgdGVtcGxhdGUgPGNsYXNzIF9ELCBib29sIF9JQz4gZnJpZW5kIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gY29weShfX2JpdF9pdGVyYXRvcjxfRCwgX0lDPiBfX2ZpcnN0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfRCwgX0lDPiBfX2xhc3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gX19yZXN1bHQpOwogICAgdGVtcGxhdGUgPGNsYXNzIF9ELCBib29sIF9JQz4gZnJpZW5kIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gX19jb3B5X2JhY2t3YXJkX2FsaWduZWQoX19iaXRfaXRlcmF0b3I8X0QsIF9JQz4gX19maXJzdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9ELCBfSUM+IF9fbGFzdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gX19yZXN1bHQpOwogICAgdGVtcGxhdGUgPGNsYXNzIF9ELCBib29sIF9JQz4gZnJpZW5kIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gX19jb3B5X2JhY2t3YXJkX3VuYWxpZ25lZChfX2JpdF9pdGVyYXRvcjxfRCwgX0lDPiBfX2ZpcnN0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfRCwgX0lDPiBfX2xhc3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gX19yZXN1bHQpOwogICAgdGVtcGxhdGUgPGNsYXNzIF9ELCBib29sIF9JQz4gZnJpZW5kIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gY29weV9iYWNrd2FyZChfX2JpdF9pdGVyYXRvcjxfRCwgX0lDPiBfX2ZpcnN0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfRCwgX0lDPiBfX2xhc3QsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gX19yZXN1bHQpOwogICAgdGVtcGxhdGUgPGNsYXNzIF9DMSwgY2xhc3MgX0MyPmZyaWVuZCBfX2JpdF9pdGVyYXRvcjxfQzIsIGZhbHNlPiBfX3N3YXBfcmFuZ2VzX2FsaWduZWQoX19iaXRfaXRlcmF0b3I8X0MxLCBmYWxzZT4sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfQzEsIGZhbHNlPiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9DMiwgZmFsc2U+KTsKICAgIHRlbXBsYXRlIDxjbGFzcyBfQzEsIGNsYXNzIF9DMj5mcmllbmQgX19iaXRfaXRlcmF0b3I8X0MyLCBmYWxzZT4gX19zd2FwX3Jhbmdlc191bmFsaWduZWQoX19iaXRfaXRlcmF0b3I8X0MxLCBmYWxzZT4sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9DMSwgZmFsc2U+LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfQzIsIGZhbHNlPik7CiAgICB0ZW1wbGF0ZSA8Y2xhc3MgX0MxLCBjbGFzcyBfQzI+ZnJpZW5kIF9fYml0X2l0ZXJhdG9yPF9DMiwgZmFsc2U+IHN3YXBfcmFuZ2VzKF9fYml0X2l0ZXJhdG9yPF9DMSwgZmFsc2U+LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfQzEsIGZhbHNlPiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX19iaXRfaXRlcmF0b3I8X0MyLCBmYWxzZT4pOwogICAgdGVtcGxhdGUgPGNsYXNzIF9EPiBmcmllbmQgX19iaXRfaXRlcmF0b3I8X0QsIGZhbHNlPiByb3RhdGUoX19iaXRfaXRlcmF0b3I8X0QsIGZhbHNlPiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfRCwgZmFsc2U+KTsKICAgIHRlbXBsYXRlIDxjbGFzcyBfRD4gZnJpZW5kIGJvb2wgX19lcXVhbF9hbGlnbmVkKF9fYml0X2l0ZXJhdG9yPF9ELCB0cnVlPiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9ELCB0cnVlPiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF9fYml0X2l0ZXJhdG9yPF9ELCB0cnVlPik7CiAgICB0ZW1wbGF0ZSA8Y2xhc3MgX0Q+IGZyaWVuZCBib29sIF9fZXF1YWxfdW5hbGlnbmVkKF9fYml0X2l0ZXJhdG9yPF9ELCB0cnVlPiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX19iaXRfaXRlcmF0b3I8X0QsIHRydWU+LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX2JpdF9pdGVyYXRvcjxfRCwgdHJ1ZT4pOwogICAgdGVtcGxhdGUgPGNsYXNzIF9ELCBib29sIF9JQzEsIGJvb2wgX0lDMj4gZnJpZW5kIGJvb2wgZXF1YWwoX19iaXRfaXRlcmF0b3I8X0QsIF9JQzE+LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX19iaXRfaXRlcmF0b3I8X0QsIF9JQzE+LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX19iaXRfaXRlcmF0b3I8X0QsIF9JQzI+KTsKICAgIHRlbXBsYXRlIDxjbGFzcyBfRD4gZnJpZW5kIF9fYml0X2l0ZXJhdG9yPF9ELCBmYWxzZT4gX19maW5kX2Jvb2xfdHJ1ZShfX2JpdF9pdGVyYXRvcjxfRCwgZmFsc2U+LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHR5cGVuYW1lIF9EOjpzaXplX3R5cGUpOwogICAgdGVtcGxhdGUgPGNsYXNzIF9EPiBmcmllbmQgX19iaXRfaXRlcmF0b3I8X0QsIGZhbHNlPiBfX2ZpbmRfYm9vbF9mYWxzZShfX2JpdF9pdGVyYXRvcjxfRCwgZmFsc2U+LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0eXBlbmFtZSBfRDo6c2l6ZV90eXBlKTsKfTsKCl9MSUJDUFBfRU5EX05BTUVTUEFDRV9TVEQKCiNlbmRpZiAgLy8gX0xJQkNQUF9fX0JJVF9SRUZFUkVOQ0UK