import java.util.*;

public class RoomManager
{
	static Random r;
	
	public static void main(String argv[])
	{
		int noThreads = Integer.parseInt(argv[0]);
		
		r = new Random();
		Person[] threadObjects = new Person[noThreads];
		Thread[] threads = new Thread[noThreads];

		for (int i=0; i<noThreads; i++)
		{
			threadObjects[i] = new Person();
		} //for

		for (int i=0; i<noThreads; i++)
		{
			threads[i] = new Thread( threadObjects[i] );
			threads[i].start();
		} //for
	} //main()
	
	public synchronized static void visit()
	{
		System.out.println("thread named "+Thread.currentThread().getName()+" entered");
		try
		{
			Thread.sleep(r.nextInt(1000));
		} //try
		catch (InterruptedException ie)
		{
			System.out.println("An InterruptedException occured\n"+ie.getMessage());
			ie.printStackTrace();
			System.exit(1);
		} //catch()
		System.out.println("thread named "+Thread.currentThread().getName()+" left");
	} //visit()
} //class RoomManager
// --------------------------------------------------------
class Person implements Runnable
{
	public void run()
	{
		for(int i=0; i<10; i++)
		{
			RoomManager.visit();
		} //for
	} //run()
} //class Person
	

	