import java.util.Random;

public class Solution {
	/* You may need to define static semaphore or other variables here. */
	/* Declaring them static makes them globally accessible. */
	
  	public static void main (String args[]) {
		int arrivals = 0;
		
		try {
			arrivals = Integer.parseInt(args[0]);
		}
		catch (Exception e) {
			System.out.println("Usage: java Solution <number of arrivals>");
			System.exit(0);
		}
		
		/* You may need to define and initiate semaphores or other variables here. */
			
		/* A man or a woman is generated randomly after every 1 second. */
		for (int i=0; i<arrivals; i++) {
			Random rand = new Random();
			
			if (rand.nextFloat() < 0.7) {
				Man man = new Man("M" + i);
				System.out.println("Man "+i+" enters system.");
				man.start();
			}
			else {
				Woman woman = new Woman("W" + i);
				woman.start();
				System.out.println("Woman "+i+" enters system.");
			}
			
			try {
				Thread.sleep (1000);
			}
			catch (InterruptedException e) {
				System.out.println("Fatal Error. Exiting.......");
				System.exit(0);
			}
		}
	}
	
	/* The person occupies the shower for a random amount of time between 0 and 1.5 seconds. */
	public static void shower (int showerId, String personId) {
		System.out.println(personId + " enters shower " + showerId + ".");

		try {
			Random rand = new Random();
			Thread.sleep((long)(rand.nextFloat() * 1500));
		}
		catch (InterruptedException e) {
			System.out.println("Fatal Error. Exiting.......");
			System.exit(0);
		}		

		System.out.println(personId + " exits shower " + showerId + ".");
	}
}

class Man extends Thread {
	String id;
	
	public Man (String id) {
		this.id = new String(id);

		/* You may need to define and initiate semaphores or other variables here. */
	}
	
	public void run () {
		/* Your code for man goes here. */
		/* Solution.shower (int showerId, String personID) simulates the person occupying the shower whose number is showerID. */
	}
}

class Woman extends Thread {
	String id;
	
	public Woman (String id) {
		this.id = new String(id);

		/* You may need to define and initiate semaphores or other variables here. */
	}
	
	public void run () {
		/* Your code for woman goes here. */
		/* Solution.shower (int showerId, String personID) simulates the person occupying the shower whose number is showerID. */
	}
}