#!/usr/bin/env python3
import time
from threading import Thread

def task(tid):
    print("P({}) sleeping".format(tid))
    time.sleep(5)
    print( "P({}) entering CS".format(tid))
    # CS
    print( "P({}) exiting CS".format(tid))


# Scan command line arguments
thread_count     = int( input() )

threads = [Thread(target=task, args=(tid,)) for tid in range(thread_count)]
for t in threads:
    t.daemon = True # die if the program exits
    t.start() # start the thread

# wait for completion
for t in threads: t.join()