import java.util.Hashtable;
import java.util.Scanner;
public class Env {
Scanner scanner
= new Scanner
(System.
in); int x = -1;
int num;
boolean turn;
Hashtable
<String, String
> msg
= new Hashtable
<String, String
>(); public Env
(int num,
boolean turn, Hashtable
<String, String
> msg
) { this.num = num;
this.turn = turn;
this.msg = msg;
}
Env read(){
if (this.turn) {
while (true) {
System.
out.
printf(this.
msg.
get("take"),
this.
num > 3 ? 3: this.
num); this.x = scanner.nextInt();
if (this.x > 0 && ((this.num > 3 && this.x < 4) || this.x < this.num + 1)) {
break;
}
}
}
return this;
}
Env eval() {
if (!this.turn) {
switch (this.num % 4) {
case 0:
this.x = 3;
break;
case 1:
if (this.num == 1) {
this.x = 1;
} else {
switch (this.x) {
case 1:
this.x = 3;
break;
case 2:
this.x = 2;
break;
case 3:
this.x = 1;
break;
}
}
case 2:
this.x = 1;
break;
case 3:
this.x = 2;
break;
}
}
this.num -= this.x;
this.turn = !this.turn;
return this;
}
Env print() {
if (this.turn) {
System.
out.
printf(this.
msg.
get("took"),
this.
msg.
get("comp"),
this.
x); }
System.
out.
printf(this.
msg.
get("cond"),
this.
num); return this;
}
}
aW1wb3J0IGphdmEudXRpbC5IYXNodGFibGU7CmltcG9ydCBqYXZhLnV0aWwuU2Nhbm5lcjsKCnB1YmxpYyBjbGFzcyBFbnYgewogICAgU2Nhbm5lciBzY2FubmVyID0gbmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKICAgIGludCB4ID0gLTE7CiAgICBpbnQgbnVtOwogICAgYm9vbGVhbiB0dXJuOwogICAgSGFzaHRhYmxlPFN0cmluZywgU3RyaW5nPiBtc2cgPSBuZXcgSGFzaHRhYmxlPFN0cmluZywgU3RyaW5nPigpOwogICAgcHVibGljIEVudihpbnQgbnVtLCBib29sZWFuIHR1cm4sIEhhc2h0YWJsZTxTdHJpbmcsIFN0cmluZz4gbXNnKSB7CiAgICAgICAgdGhpcy5udW0gPSBudW07CiAgICAgICAgdGhpcy50dXJuID0gdHVybjsKICAgICAgICB0aGlzLm1zZyA9IG1zZzsKICAgIH0KICAgIEVudiByZWFkKCl7CiAgICAgICAgaWYgKHRoaXMudHVybikgewogICAgICAgICAgICB3aGlsZSAodHJ1ZSkgewogICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGYodGhpcy5tc2cuZ2V0KCJ0YWtlIiksIHRoaXMubnVtID4gMyA/IDM6IHRoaXMubnVtKTsKICAgICAgICAgICAgICAgIHRoaXMueCA9IHNjYW5uZXIubmV4dEludCgpOwogICAgICAgICAgICAgICAgaWYgKHRoaXMueCA+IDAgJiYgKCh0aGlzLm51bSA+IDMgJiYgdGhpcy54IDwgNCkgfHwgdGhpcy54IDwgdGhpcy5udW0gKyAxKSkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgfQogICAgRW52IGV2YWwoKSB7CiAgICAgICAgaWYgKCF0aGlzLnR1cm4pIHsKICAgICAgICAgICAgc3dpdGNoICh0aGlzLm51bSAlIDQpIHsKICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgdGhpcy54ID0gMzsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgICAgICBpZiAodGhpcy5udW0gPT0gMSkgewogICAgICAgICAgICAgICAgICAgIHRoaXMueCA9IDE7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHN3aXRjaCAodGhpcy54KSB7CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnggPSAzOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMueCA9IDI7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy54ID0gMTsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICB0aGlzLnggPSAxOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgIHRoaXMueCA9IDI7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLm51bSAtPSB0aGlzLng7CiAgICAgICAgdGhpcy50dXJuID0gIXRoaXMudHVybjsKICAgICAgICByZXR1cm4gdGhpczsKICAgIH0KICAgIEVudiBwcmludCgpIHsKICAgICAgICBpZiAodGhpcy50dXJuKSB7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRmKHRoaXMubXNnLmdldCgidG9vayIpLCB0aGlzLm1zZy5nZXQoImNvbXAiKSwgdGhpcy54KTsKICAgICAgICB9CiAgICAgICAgU3lzdGVtLm91dC5wcmludGYodGhpcy5tc2cuZ2V0KCJjb25kIiksIHRoaXMubnVtKTsKICAgICAgICByZXR1cm4gdGhpczsKICAgIH0KfQo=