import java.io.*;
import java.util.List;
import java.util.ArrayList;

// Receiver class
abstract class Light {

	boolean status;

	abstract public void turnOn();

	abstract public void turnOff();

	abstract public void display();
}

class BinaryLight extends Light {

	public BinaryLight() {
		this.status = false;
	}

	public void turnOn() {
		status = true;
	}

	public void turnOff() {
		status = false;
	}

	public void display() {
		System.out.print(status?"+":"-");
	}
}

class Bulb extends Light {

	static String patternOff =
"           _()_           \n" +
"          {____}          \n" +
"          {____}          \n" +
"          | || |          \n" +
"          / || \\         \n" +
"        /`  ~~  `\\       \n" +
"       |          |       \n" +
"       \\          /      \n" +
"        '._    _.'        \n" +
"           ````           \n" +
"                          \n";

	static String patternOn =
"           _()_           	\n" +
"          {____}          	\n" +
"      \\   {____}   /      \n" +
"       \\  | || |  /       \n" +
"          / || \\          \n" +
"        /`  ~~  `\\        \n" +
"  ---  |   / |\\   |  ---  \n" +
"       \\  /  | \\  /      \n" +
"        '._    _.'        	\n" +
"        /  ````  \\        \n" +
"       /          \\       \n";

	public Bulb() {
		this.status = false;
	}

	public void turnOn() {
		status = true;
	}

	public void turnOff() {
		status = false;
	}

	public void display() {
		System.out.print("\033[H\033[2J");  
    	System.out.flush();
		System.out.print(status?patternOn:patternOff);
	}
}

// Command interface
abstract class Command {

	Light light;

	public Command(Light light) {
		this.light = light;
	}

	abstract public void execute();
}

// Command to turn on light
class LightCommandFlipUp extends Command {

	public LightCommandFlipUp(Light light) {super(light);}

	public void execute() {
		this.light.turnOn();
		this.light.display();
		try {Thread.sleep(100);}
		catch(Exception e) {System.out.println(e);}
	}
}

// Command to turn off light
class LightCommandFlipDown extends Command {

	public LightCommandFlipDown(Light light) {super(light);}

	public void execute() {
		this.light.turnOff();
		this.light.display();
		try {Thread.sleep(100);}
		catch(Exception e) {System.out.println(e);}
	}
}

// Command to turn off light
class LightCommandStrobe extends Command {

	int strobe_times;

	public LightCommandStrobe(Light light, int n) {
		super(light);
		strobe_times = n;
	}

	public void execute() {
		Command c0 = new LightCommandFlipDown(this.light);
		Command c1 = new LightCommandFlipUp(this.light);
		for (int i=0; i<strobe_times; i++) {
			c0.execute();
			c1.execute();
		}
	}
}

// Invoker class
class Switch {

	List<Command> commands = new ArrayList<Command> ();

	public void addCmdAndExec(Command cmd) {
		this.commands.add(cmd);
		cmd.execute();
	}

	public void addCmdsAndExec(Command [] cmds) {
		for (int i=0; i<cmds.length; i++) {
			this.commands.add(cmds[i]);
			cmds[i].execute();
		}
	}
}

public class PressSwitch {
	
	public static void main(String[] args) {
		
		Light	lamp = new Bulb(); // receiver
		//Light 	lamp = new BinaryLight();
		Command	switchUp = new LightCommandFlipUp(lamp);
		Command	switchDown = new LightCommandFlipDown(lamp);
		Command switchStrobe = new LightCommandStrobe(lamp, 10);
		Switch	mySwitch = new Switch(); // invoker

		for (int i=0; i<args.length; i++) {
			switch(args[i]) {
				case "1":
					mySwitch.addCmdAndExec(switchUp);
					break;
				case "0":
					mySwitch.addCmdAndExec(switchDown);
					break;
				case "2":
					mySwitch.addCmdAndExec(switchStrobe);
					break;
				default:
					break;
			}
		}

		System.out.println("");
	}
}
