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DE2KSAmIDB4ZmYpOwogICAgbGVkX3dyaXRlYihvcGFxdWUsIGFkZHIgKyAzLCAodmFsID4+IDI0KSAmIDB4ZmYpOwojZW5kaWYKfQoKc3RhdGljIENQVVJlYWRNZW1vcnlGdW5jICogY29uc3QgbGVkX3JlYWRbM10gPSB7CiAgICBsZWRfcmVhZGIsCiAgICBsZWRfcmVhZHcsCiAgICBsZWRfcmVhZGwsCn07CgpzdGF0aWMgQ1BVV3JpdGVNZW1vcnlGdW5jICogY29uc3QgbGVkX3dyaXRlWzNdID0gewogICAgbGVkX3dyaXRlYiwKICAgIGxlZF93cml0ZXcsCiAgICBsZWRfd3JpdGVsLAp9OwoKLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKiBqYXp6X2xlZCBkaXNwbGF5ICovCgpzdGF0aWMgdm9pZCBkcmF3X2hvcml6b250YWxfbGluZShEaXNwbGF5U3RhdGUgKmRzLCBpbnQgcG9zeSwgaW50IHBvc3gxLCBpbnQgcG9zeDIsIHVpbnQzMl90IGNvbG9yKQp7CiAgICB1aW50OF90ICpkOwogICAgaW50IHgsIGJwcDsKCiAgICBicHAgPSAoZHNfZ2V0X2JpdHNfcGVyX3BpeGVsKGRzKSArIDcpID4+IDM7CiAgICBkID0gZHNfZ2V0X2RhdGEoZHMpICsgZHNfZ2V0X2xpbmVzaXplKGRzKSAqIHBvc3kgKyBicHAgKiBwb3N4MTsKICAgIHN3aXRjaChicHApIHsKICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgIGZvciAoeCA9IHBvc3gxOyB4IDw9IHBvc3gyOyB4KyspIHsKICAgICAgICAgICAgICAgICooKHVpbnQ4X3QgKilkKSA9IGNvbG9yOwogICAgICAgICAgICAgICAgZCsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgZm9yICh4ID0gcG9zeDE7IHggPD0gcG9zeDI7IHgrKykgewogICAgICAgICAgICAgICAgKigodWludDE2X3QgKilkKSA9IGNvbG9yOwogICAgICAgICAgICAgICAgZCArPSAyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgZm9yICh4ID0gcG9zeDE7IHggPD0gcG9zeDI7IHgrKykgewogICAgICAgICAgICAgICAgKigodWludDMyX3QgKilkKSA9IGNvbG9yOwogICAgICAgICAgICAgICAgZCArPSA0OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgfQp9CgpzdGF0aWMgdm9pZCBkcmF3X3ZlcnRpY2FsX2xpbmUoRGlzcGxheVN0YXRlICpkcywgaW50IHBvc3gsIGludCBwb3N5MSwgaW50IHBvc3kyLCB1aW50MzJfdCBjb2xvcikKewogICAgdWludDhfdCAqZDsKICAgIGludCB5LCBicHA7CgogICAgYnBwID0gKGRzX2dldF9iaXRzX3Blcl9waXhlbChkcykgKyA3KSA+PiAzOwogICAgZCA9IGRzX2dldF9kYXRhKGRzKSArIGRzX2dldF9saW5lc2l6ZShkcykgKiBwb3N5MSArIGJwcCAqIHBvc3g7CiAgICBzd2l0Y2goYnBwKSB7CiAgICAgICAgY2FzZSAxOgogICAgICAgICAgICBmb3IgKHkgPSBwb3N5MTsgeSA8PSBwb3N5MjsgeSsrKSB7CiAgICAgICAgICAgICAgICAqKCh1aW50OF90ICopZCkgPSBjb2xvcjsKICAgICAgICAgICAgICAgIGQgKz0gZHNfZ2V0X2xpbmVzaXplKGRzKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgIGZvciAoeSA9IHBvc3kxOyB5IDw9IHBvc3kyOyB5KyspIHsKICAgICAgICAgICAgICAgICooKHVpbnQxNl90ICopZCkgPSBjb2xvcjsKICAgICAgICAgICAgICAgIGQgKz0gZHNfZ2V0X2xpbmVzaXplKGRzKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgIGZvciAoeSA9IHBvc3kxOyB5IDw9IHBvc3kyOyB5KyspIHsKICAgICAgICAgICAgICAgICooKHVpbnQzMl90ICopZCkgPSBjb2xvcjsKICAgICAgICAgICAgICAgIGQgKz0gZHNfZ2V0X2xpbmVzaXplKGRzKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgIH0KfQoKc3RhdGljIHZvaWQgamF6el9sZWRfdXBkYXRlX2Rpc3BsYXkodm9pZCAqb3BhcXVlKQp7CiAgICBMZWRTdGF0ZSAqcyA9IG9wYXF1ZTsKICAgIERpc3BsYXlTdGF0ZSAqZHMgPSBzLT5kczsKICAgIHVpbnQ4X3QgKmQxOwogICAgdWludDMyX3QgY29sb3Jfc2VnbWVudCwgY29sb3JfbGVkOwogICAgaW50IHksIGJwcDsKCiAgICBpZiAocy0+c3RhdGUgJiBSRURSQVdfQkFDS0dST1VORCkgewogICAgICAgIC8qIGNsZWFyIHNjcmVlbiAqLwogICAgICAgIGJwcCA9IChkc19nZXRfYml0c19wZXJfcGl4ZWwoZHMpICsgNykgPj4gMzsKICAgICAgICBkMSA9IGRzX2dldF9kYXRhKGRzKTsKICAgICAgICBmb3IgKHkgPSAwOyB5IDwgZHNfZ2V0X2hlaWdodChkcyk7IHkrKykgewogICAgICAgICAgICBtZW1zZXQoZDEsIDB4MDAsIGRzX2dldF93aWR0aChkcykgKiBicHApOwogICAgICAgICAgICBkMSArPSBkc19nZXRfbGluZXNpemUoZHMpOwogICAgICAgIH0KICAgIH0KCiAgICBpZiAocy0+c3RhdGUgJiBSRURSQVdfU0VHTUVOVFMpIHsKICAgICAgICAvKiBzZXQgY29sb3JzIGFjY29yZGluZyB0byBicHAgKi8KICAgICAgICBzd2l0Y2ggKGRzX2dldF9iaXRzX3Blcl9waXhlbChkcykpIHsKICAgICAgICAgICAgY2FzZSA4OgogICAgICAgICAgICAgICAgY29sb3Jfc2VnbWVudCA9IHJnYl90b19waXhlbDgoMHhhYSwgMHhhYSwgMHhhYSk7CiAgICAgICAgICAgICAgICBjb2xvcl9sZWQgPSByZ2JfdG9fcGl4ZWw4KDB4MDAsIDB4ZmYsIDB4MDApOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMTU6CiAgICAgICAgICAgICAgICBjb2xvcl9zZWdtZW50ID0gcmdiX3RvX3BpeGVsMTUoMHhhYSwgMHhhYSwgMHhhYSk7CiAgICAgICAgICAgICAgICBjb2xvcl9sZWQgPSByZ2JfdG9fcGl4ZWwxNSgweDAwLCAweGZmLCAweDAwKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDE2OgogICAgICAgICAgICAgICAgY29sb3Jfc2VnbWVudCA9IHJnYl90b19waXhlbDE2KDB4YWEsIDB4YWEsIDB4YWEpOwogICAgICAgICAgICAgICAgY29sb3JfbGVkID0gcmdiX3RvX3BpeGVsMTYoMHgwMCwgMHhmZiwgMHgwMCk7CiAgICAgICAgICAgIGNhc2UgMjQ6CiAgICAgICAgICAgICAgICBjb2xvcl9zZWdtZW50ID0gcmdiX3RvX3BpeGVsMjQoMHhhYSwgMHhhYSwgMHhhYSk7CiAgICAgICAgICAgICAgICBjb2xvcl9sZWQgPSByZ2JfdG9fcGl4ZWwyNCgweDAwLCAweGZmLCAweDAwKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDMyOgogICAgICAgICAgICAgICAgY29sb3Jfc2VnbWVudCA9IHJnYl90b19waXhlbDMyKDB4YWEsIDB4YWEsIDB4YWEpOwogICAgICAgICAgICAgICAgY29sb3JfbGVkID0gcmdiX3RvX3BpeGVsMzIoMHgwMCwgMHhmZiwgMHgwMCk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CgogICAgICAgIC8qIGRpc3BsYXkg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