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9uIGRpc2sgICAgICAgICAgICAgICVkXG4iLAoJICAgIF9fbGUxNl90b19jcHUgKGJvb3QgLT4gcHNlY3QpKTsKICAgIFBSSU5URiAoIk1lZGlhIGRlc2NyaXB0b3I9Zmlyc3QgYnl0ZSBvZiBGQVQgJWRcbiIsCgkgICAgYm9vdCAtPiBkZXNjcik7CiAgICBQUklOVEYgKCJTZWN0b3JzIGluIEZBVCAgICAgICAgICAgICAgICAgICAgICVkXG4iLAoJICAgIF9fbGUxNl90b19jcHUgKGJvb3QgLT4gZmF0bGVuKSk7CiAgICBQUklOVEYgKCJTZWN0b3JzL3RyYWNrICAgICAgICAgICAgICAgICAgICAgICVkXG4iLAoJICAgIF9fbGUxNl90b19jcHUgKGJvb3QgLT4gbnNlY3QpKTsKICAgIFBSSU5URiAoIkhlYWRzICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJWRcbiIsCgkgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBuaGVhZHMpKTsKICAgIFBSSU5URiAoIm51bWJlciBvZiBoaWRkZW4gc2VjdG9ycyAgICAgICAgICAgJWRcbiIsCgkgICAgX19sZTMyX3RvX2NwdSAoYm9vdCAtPiBuaHMpKTsKICAgIFBSSU5URiAoImJpZyB0b3RhbCBzZWN0b3JzICAgICAgICAgICAgICAgICAgJWRcbiIsCgkgICAgX19sZTMyX3RvX2NwdSAoYm9vdCAtPiBiaWdzZWN0KSk7CiAgICBQUklOVEYgKCJwaHlzaWNhbCBkcml2ZSA/ICAgICAgICAgICAgICAgICAgICVkXG4iLAoJICAgIGJvb3QgLT4gcGh5c2RyaXZlKTsKICAgIFBSSU5URiAoInJlc2VydmVkICAgICAgICAgICAgICAgICAgICAgICAgICAgJWRcbiIsCgkgICAgYm9vdCAtPiByZXNlcnZlZCk7CiAgICBQUklOVEYgKCJkb3MgPiA0LjAgZGlza2V0dGUgICAgICAgICAgICAgICAgICVkXG4iLAoJICAgIGJvb3QgLT4gZG9zNCk7CiAgICBQUklOVEYgKCJzZXJpYWwgbnVtYmVyICAgICAgICAgICAgICAgICAgICAgICVkXG4iLAoJICAgIF9fbGUzMl90b19jcHUgKGJvb3QgLT4gc2VyaWFsKSk7CiAgICBQUklOVEYgKCJkaXNrIGxhYmVsICAgICAgICAgICAgICAgICAgICAgICAgICUqLipzXG4iLAoJICAgIExBQkVMX0xHLCBMQUJFTF9MRywgYm9vdCAtPiBsYWJlbCk7CiAgICBQUklOVEYgKCJGQVQgdHlwZSAgICAgICAgICAgICAgICAgICAgICAgICAgICU4LjhzXG4iLAoJICAgIGJvb3QgLT4gZmF0X3R5cGUpOwogICAgUFJJTlRGICgicmVzZXJ2ZWQgYnkgMk0gICAgICAgICAgICAgICAgICAgICAlZFxuIiwKCSAgICBib290IC0+IHJlc18ybSk7CiAgICBQUklOVEYgKCIyTSBjaGVja3N1bSAobm90IHVzZWQpICAgICAgICAgICAgICVkXG4iLAoJICAgIGJvb3QgLT4gQ2hlY2tTdW0pOwogICAgUFJJTlRGICgiMk1GIGZvcm1hdCB2ZXJzaW9uICAgICAgICAgICAgICAgICAlZFxuIiwKCSAgICBib290IC0+IGZtdF8ybWYpOwogICAgUFJJTlRGICgiMSBpZiB3cml0ZSB0cmFjayBhZnRlciBmb3JtYXQgICAgICAlZFxuIiwKCSAgICBib290IC0+IHd0KTsKICAgIFBSSU5URiAoImRhdGEgdHJhbnNmZXIgcmF0ZSBvbiB0cmFjayAwICAgICAgJWRcbiIsCgkgICAgYm9vdCAtPiByYXRlXzApOwogICAgUFJJTlRGICgiZGF0YSB0cmFuc2ZlciByYXRlIG9uIHRyYWNrPD4wICAgICAlZFxuIiwKCSAgICBib290IC0+IHJhdGVfYW55KTsKICAgIFBSSU5URiAoIm9mZnNldCB0byBib290IHByb2dyYW0gICAgICAgICAgICAgJWRcbiIsCgkgICAgX19sZTE2X3RvX2NwdSAoYm9vdCAtPiBCb290UCkpOwogICAgUFJJTlRGICgiVDE6IGluZm9ybWF0aW9uIGZvciB0cmFjayAwICAgICAg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