import java.util.*;
import java.io.*;
import java.net.*;
import java.lang.*;

public class sortwrk
{
   public static void main(String args[]) throws Exception
   {
      int job_id = 1;
      int task_id = Integer.parseInt(args[0]);

      String main_pt_name;
      int main_pt_no;
      String gp_name;
      int gp_no;
      String pt_name;
      int pt_no;

      int i, status, temp;

      JMPF def_obj;
 
      pt_name = String.valueOf(task_id);
      main_pt_name = "main";
      def_obj = new JMPF(job_id, task_id);
      pt_no = def_obj.CreatePort(pt_name);

// waits for the data.
      String string = def_obj.BlockReceiveString(pt_no);

      StringTokenizer st = new StringTokenizer(string);
      int no_of_ele = Integer.parseInt(st.nextToken());

		int a[] = new int[no_of_ele];
		for (i = 0; i < no_of_ele; i++)
	      a[i]= Integer.parseInt(st.nextToken());

// does the sorting.
		for (i = no_of_ele - 1; i > 0; i--)
			for (int j = 0;j < i; j++) 
				if (a[j] > a[j+1])
				{
					temp = a[j];
					a[j] = a[j+1];
					a[j+1] = temp;
				}


      main_pt_no = def_obj.LocatePort(main_pt_name);

      synchronized(def_obj)
      {
			String str = "";
			for ( i = 0; i < no_of_ele; i++)
				str = str + String.valueOf(a[i]) + " ";
        	status = def_obj.Send(main_pt_no, str);
      }
      def_obj.ClosePorts();
   }
}


