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aXJzdCBsaW5lIGFuZCB0aGUgZmlyc3QgZW1wdHkgbGluZSBhZnRlciBjdXJzb3IgICAgICAgICAgICAgKi8KICAgIGZvciAoaSA9IDAsIHBhdHRlcm4gPSAwOyBpIDwgNjQ7IGkrKykgewogICAgICAgIGlmIChpIDwgZm9udF93aWR0aCkgewogICAgICAgICAgICAvKiBJbnZlcnQgYmFja2dyb3VuZCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovCiAgICAgICAgICAgIHBhdHRlcm4gfD0gMHgzOwogICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIC8qIEJhY2tncm91bmQgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKi8KICAgICAgICAgICAgcGF0dGVybiB8PSAweDI7CiAgICAgICAgfQogICAgICAgIGlmICgoaSAmIDMpID09IDMpIHsKICAgICAgICAgICAgKnB0ciA9IHBhdHRlcm47CiAgICAgICAgICAgICoocHRyICsgZm9udF9oZWlnaHQgKiAxNikgPSAweGFhOwogICAgICAgICAgICBwdHIgKys7CiAgICAgICAgICAgIHBhdHRlcm4gPSAwOwogICAgICAgIH0KICAgICAgICBwYXR0ZXJuIDw8PSAyOwogICAgfQoKICAgIC8qIER1cGxpY2F0ZSB0aGlzIGxpbmUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqLwogICAgZm9yIChpID0gMTsgaSA8IGZvbnRfaGVpZ2h0OyBpKyspIHsKICAgICAgICBtZW1jcHkgKCh2b2lkICopcHRyLCAodm9pZCAqKShwdHIgLSAxNiksIDE2KTsKICAgICAgICBwdHIgKz0gMTY7CiAgICB9CiAgICAKICAgIGZvciAoOyBpIDwgNjQ7IGkrKykgewogICAgICAgIG1lbWNweSAoKHZvaWQgKikocHRyICsgMTYpLCAodm9pZCAqKXB0ciwgMTYpOwogICAgICAgIHB0ciArPSAxNjsKICAgIH0KCiAgICAvKiBTZWxlY3QgY3Vyc29yIG1vZGUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKi8KICAgIHdyaXRlQnl0ZSAoTENEX0NVUlNPUl9DTlRMLCAxKTsKfQojZW5kaWYKI2VuZGlmCg==