#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
 #define MAX 1000
 struct task{
     int id;
     int p;
 };
  struct task heap[MAX];
 int size = 0;
 void swap(struct task*a,struct task*b){
     struct task temp = *a;
     *a = *b;
     *b = temp;
 }
 void heapify_up(int index){
     if(index<=0)
    return;
     int parent=(index-1)/2;
         if(heap[index].p<heap[parent].p){
         swap (&heap[index],&heap[parent]);
         heapify_up(parent);
     }
 }
 void heapify_down(int index) {
     int left=2*index+1;
     int right=2*index+2;
     int smallest=index;
     if(left<size&&heap[left].p<heap[smallest].p)
 smallest=left;
 if(right<size&&heap[right].p<heap[smallest].p)
 smallest=right;
 if(smallest=index)
 {
    swap(&heap[index],&heap[smallest]);
    heapify_down(smallest);
 }
 }
 void insert(int id,int p){
     heap[size].id=id;
     heap[size].p=p;
     heapify_up(size);
     size++;
     printf("Task Added:%d\n",id);
 }
  struct task extract_task(){
  struct task min_task = heap[0];
  heap[0]= heap[size-1];
  size--;
  heapify_down(0);
  return min_task;
  }
  int main(){
      int n;
      scanf("%d",&n);
      for(int i = 0 ;i < n ; i++){
          int id,p;
          scanf("%d%d",&id,&p);
          if(id< 0 || p < 0){
              printf("invalid Input\n");
              continue;
          }
          insert(id,p);
  }
  if(size > 0)
  printf("Task with Highest Priyority:%d\n",heap[0].id);
  else
  printf("no valid task\n");
  while (size > 0){
      struct task t = extract task();
      printf("Task ID:%d,Priyority:%d\n",t.id, t.p);
  return 0;
  }
  }