import java.io.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList

public class R260_Div2_C
{
	FastReader in;
	PrintWriter out;

	public static void main(String[] args)  {
		new R260_Div2_C().run();
	}

	void run()
	{
		in = new FastReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	void solve()
	{
		int n = in.nextInt();

		int[] a = new int[n];
		int[] c = new int[100_001];
		for (int i = 0; i < n; i++)
		{
			a[i] = in.nextInt();
			c[a[i]]++;
		}

		Arrays.sort(a);
		long sum = 0;

		for (int i = 100_000; i > 0; i--)
		{
			if (c[i] > 0)
			{
				long cnt1 = c[i] * i - c[i-1] * (i-1);
				if (i > 2) cnt1 += c[i-2] * (i-2);
				long cnt2 = c[i-1] * (i-1) - c[i]*i;
				if (i > 2) cnt2 -= c[i-2] * (i-2);
				if (cnt1 > cnt2)
				{
					sum += c[i] * i;
					c[i] = 0; c[i-1] = 0;
				}
				else
				{
					sum += c[i-1] * (i-1);
					c[i] = 0; c[i-1] = 0;
					if (i > 2) c[i-2] = 0;
				}
			}
		}

		out.println(sum);
	}

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}

	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;

	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

	    private String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens())
	            try {
	            	tokenizer = new StringTokenizer(br.readLine());
	            }
	            catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        return tokenizer.nextToken();
	    }
		public String nextLine() {
			try	{
				return br.readLine();
			}
			catch(Exception e) {
				throw(new RuntimeException());
			}
		}

	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    BigInteger nextBigInteger() {
	        return new BigInteger(next());
	    }
	    BigDecimal nextBigDecimal() {
	        return new BigDecimal(next());
	    }
	}
}


import java.io.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList

public class R260_Div2_C
{
	FastReader in;
	PrintWriter out;

	public static void main(String[] args)  {
		new R260_Div2_C().run();
	}

	void run()
	{
		in = new FastReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	void solve()
	{
		int n = in.nextInt();

		int[] a = new int[n];
		long[] c = new long[100_001];
		for (int i = 0; i < n; i++)
		{
			a[i] = in.nextInt();
			c[a[i]]++;
		}

		//Arrays.sort(a);
		long sum = 0;

		for (int i = 100_000; i > 0; i--)
		{
			if (c[i] > 0)
			{
				long cnt1 = c[i] * i - c[i-1] * (i-1);
				if (i > 2) cnt1 += c[i-2] * (i-2);
				long cnt2 = c[i-1] * (i-1) - c[i]*i;
				if (i > 2) cnt2 -= c[i-2] * (i-2);
				if (cnt1 > cnt2)
				{
					sum += c[i] * i;
					c[i] = 0; c[i-1] = 0;
				}
				else
				{
					sum += c[i-1] * (i-1);
					c[i] = 0; c[i-1] = 0;
					if (i > 2) c[i-2] = 0;
				}
			}
		}

		out.println(sum);
	}

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}

	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;

	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

	    private String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens())
	            try {
	            	tokenizer = new StringTokenizer(br.readLine());
	            }
	            catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        return tokenizer.nextToken();
	    }
		public String nextLine() {
			try	{
				return br.readLine();
			}
			catch(Exception e) {
				throw(new RuntimeException());
			}
		}

	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    BigInteger nextBigInteger() {
	        return new BigInteger(next());
	    }
	    BigDecimal nextBigDecimal() {
	        return new BigDecimal(next());
	    }
	}
}


import java.util.*;

public class B {

static int len=0,n;
static String[] a = new String[1001];
static int[] b = new int[1001];
	static void add(String st,int z){
		int k=0;
		for (int i=1;i<=len;i++)
			if(a[i].equals(st)) k=i;
		if (k==0) {len++;a[len]=st;b[len]=z;} else
			if 	(z>b[k]) b[k]=z;
	}

	static double lose(int i){
		int k=0;
		for (int j=1;j<=len;j++)
		if (b[i]>b[j]) k++;
		return (double)k*100/len;
	}

	static double better(int i){
		int k=0;
		for (int j=1;j<=len;j++)
		if (b[i]<b[j]) k++;
		return (double)k*100.0/len;
	}
public static void main(String args[]) {
  Scanner in = new Scanner(System.in);
  n=in.nextInt();
  for (int i=1;i<=n;i++) {
	String st=in.next();int yed=in.nextInt();
	add(st,yed);
  }

  System.out.println(len);
  for (int i=1;i<=len;i++) {
	  double k1 = lose(i),k2=better(i);
	  String ans="";
	if (k2>50) ans = "noob"; else
		if (k1<50 && k2>20) ans="random"; else
			if (k1>20 && k2>10) ans = "average"; else
				if (k1<10 && k2>1) ans="hardcore"; else
					ans = "pro";

	System.out.println(a[i]+" "+ans);

  }

 }
}


import java.util.*;

public class B {

static int len=0,n;
static String[] a = new String[1001];
static int[] b = new int[1001];
	static void add(String st,int z){
		int k=0;
		for (int i=1;i<=len;i++)
			if(a[i].equals(st)) k=i;
		if (k==0) {len++;a[len]=st;b[len]=z;} else
			if 	(z>b[k]) b[k]=z;
	}

	static double lose(int i){
		int k=0;
		for (int j=1;j<=len;j++)
		if (b[i]>b[j]) k++;
		return (double)k*100/len;
	}

	static double better(int i){
		int k=0;
		for (int j=1;j<=len;j++)
		if (b[i]<b[j]) k++;
		return (double)k*100.0/len;
	}
public static void main(String args[]) {
  Scanner in = new Scanner(System.in);
  n=in.nextInt();
  for (int i=1;i<=n;i++) {
	String st=in.next();int yed=in.nextInt();
	add(st,yed);
  }

  System.out.println(len);
  for (int i=1;i<=len;i++) {
	  double k1 = lose(i),k2=better(i);
	  String ans="";
	if (k2>50) ans = "noob"; else
		if (k1<50 && k2>20) ans="random"; else
			if (k1>20 && k2>10) ans = "average"; else
				if (k1>=10 && k2>1) ans="hardcore"; else
					ans = "pro";

	System.out.println(a[i]+" "+ans);

  }

 }
}


import java.util.*;

public class Main {
	class B{
		void run(){
			int n = sc.nextInt();
			ArrayList<String> name = new ArrayList<String>();
			ArrayList<Integer> score = new ArrayList<Integer>();
			for(int i = 0; i < n; i++){
				String in = sc.next();
				int s = sc.nextInt();
				boolean ok = false;
				for(int j = 0; j < name.size(); j++) if(name.get(j).equals(in)){
					score.set(j, Math.max(score.get(j), s));
					ok = true;
				}
				if(!ok){
					name.add(in);
					score.add(s);
				}
			}
			int all = name.size();
			for(int i = 0; i < name.size(); i++){
				int better = 0;
				for(int j = 0; j < name.size(); j++) if(score.get(j) > score.get(i))
					better++;
				System.out.print(name.get(i) +" ");
				if(all * 0.01 >= better) System.out.println("pro");
				else if(all * 0.1 >= better) System.out.println("hardcore");
				else if(all * 0.2 >= better) System.out.println("average");
				else if(all * 0.5 >= better) System.out.println("random");
				else System.out.println("noob");
			}

		}
	}
	class A{
		void run(){
			String in = sc.next();
			int n = in.length(), ans = -1;
			for(int i = 0; i < 1; i++) for(int j = i+1; j < n; j++)
				for(int k = j+1; k < n; k++	){
					String a = in.substring(i, j);
					String b = in.substring(j, k);
					String c = in.substring(k);
					if(a.length() > 8 || b.length() > 8 || c.length() > 8) continue;
					if(a.charAt(0) == '0' && a.length() > 1  ||
							b.charAt(0) == '0' && b.length() > 1 ||
							c.charAt(0) == '0' && c.length() > 1) continue;
					int na = Integer.parseInt(a), nb = Integer.parseInt(b), nc = Integer.parseInt(c);
					if(na > 1000000 || nb > 1000000 || nc > 1000000) continue;
					ans = Math.max(ans,  na + nb + nc);
				}
			System.out.println(ans);
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		sc = new Scanner(System.in);
		new Main().new B().run();
	}
	static Scanner sc;
}


import java.util.*;

public class Main {
	class B{
		void run(){
			int n = sc.nextInt();
			ArrayList<String> name = new ArrayList<String>();
			ArrayList<Integer> score = new ArrayList<Integer>();
			for(int i = 0; i < n; i++){
				String in = sc.next();
				int s = sc.nextInt();
				boolean ok = false;
				for(int j = 0; j < name.size(); j++) if(name.get(j).equals(in)){
					score.set(j, Math.max(score.get(j), s));
					ok = true;
				}
				if(!ok){
					name.add(in);
					score.add(s);
				}
			}
			int all = name.size();
			System.out.println(all);
			for(int i = 0; i < name.size(); i++){
				int better = 0;
				for(int j = 0; j < name.size(); j++) if(score.get(j) > score.get(i))
					better++;
				System.out.print(name.get(i) +" ");
				if(all * 0.01 >= better) System.out.println("pro");
				else if(all * 0.1 >= better) System.out.println("hardcore");
				else if(all * 0.2 >= better) System.out.println("average");
				else if(all * 0.5 >= better) System.out.println("random");
				else System.out.println("noob");
			}

		}
	}
	/*
	class A{
		void run(){
			String in = sc.next();
			int n = in.length(), ans = -1;
			for(int i = 0; i < 1; i++) for(int j = i+1; j < n; j++)
				for(int k = j+1; k < n; k++	){
					String a = in.substring(i, j);
					String b = in.substring(j, k);
					String c = in.substring(k);
					if(a.length() > 8 || b.length() > 8 || c.length() > 8) continue;
					if(a.charAt(0) == '0' && a.length() > 1  ||
							b.charAt(0) == '0' && b.length() > 1 ||
							c.charAt(0) == '0' && c.length() > 1) continue;
					int na = Integer.parseInt(a), nb = Integer.parseInt(b), nc = Integer.parseInt(c);
					if(na > 1000000 || nb > 1000000 || nc > 1000000) continue;
					ans = Math.max(ans,  na + nb + nc);
				}
			System.out.println(ans);
		}
	}
	*/
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		sc = new Scanner(System.in);
		new Main().new B().run();
	}
	static Scanner sc;
}


import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.math.*;

public class B
{
        String line;
        StringTokenizer inputParser;
        BufferedReader is;
        FileInputStream fstream;
        DataInputStream in;
        String FInput="";

        void openInput(String file)
        {

                if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
                else
                {
                        try{

                        fstream = new FileInputStream(file);
                        in = new DataInputStream(fstream);
                        is = new BufferedReader(new InputStreamReader(in));
                        }catch(Exception e)
                        {
                                System.err.println(e);
                        }
                }

        }

        void readNextLine()
    	{
    		try {
    			line = is.readLine();
    			inputParser = new StringTokenizer(line, " ");
    			//System.err.println("Input: " + line);
    		} catch (IOException e) {
    			System.err.println("Unexpected IO ERROR: " + e);
    		}
    		catch (NullPointerException e)
    		{
    			line=null;

    		}

    	}

        long NextLong()
        {
                String n = inputParser.nextToken();

                long val = Long.parseLong(n);

                 return val;
        }

        int NextInt()
        {
                String n = inputParser.nextToken();
                int val = Integer.parseInt(n);

                //System.out.println("I read this number: " + val);
                return val;
        }

        String NextString()
        {
                String n = inputParser.nextToken();
                return n;
        }

        void closeInput()
        {
                try {
                        is.close();
                } catch (IOException e) {
                        System.err.println("Unexpected IO ERROR: " + e);
                }

        }

        public static void main(String [] argv)
        {
                String filePath=null;
                if(argv.length>0)filePath=argv[0];
                new B(filePath);
        }

        public void readFInput()
    	{
    		for(;;)
    		{
    			try
    			{
    				readNextLine();
    				FInput+=line+" ";
    			}
    			catch(Exception e)
    			{
    				break;
    			}
    		}
    		inputParser = new StringTokenizer(FInput, " ");
    	}

        public B(String inputFile)
        {
        	openInput(inputFile);
    		readNextLine();
    		HashMap<String, Integer>map=new HashMap<String, Integer>();
    		int N=NextInt();
    		for(int i=0; i<N; i++)
    		{
    			readNextLine();
    			String name=NextString();
    			int score=NextInt();
    			if(map.containsKey(name)){
    				map.put(name, Math.max(map.get(name),score));
    			}
    			else map.put(name, score);
    		}

    		for(String s: map.keySet())
    		{
    			System.out.print(s+" ");
    			System.out.println(getCat(map.get(s), map));
    		}

            closeInput();
    	}

		private String getCat(Integer m, HashMap<String, Integer> map) {
			int N=map.size();
			int better=0;
			int nwt=0;
			for(int a:map.values())
			{
				if(a>m)better++;
				else nwt++;
			}

			if(better*2>N)return"noob";

			if(nwt*2>N&&better*5>N)return"random";
			if(nwt*5>N*4&&better*10>N)return"average";
			if(nwt*10>N*9&&better*100>N)return"hardcore";
			if(nwt*100>N*99)return"pro";
			return"undefined";
		}

}


import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.math.*;

public class B
{
        String line;
        StringTokenizer inputParser;
        BufferedReader is;
        FileInputStream fstream;
        DataInputStream in;
        String FInput="";

        void openInput(String file)
        {

                if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
                else
                {
                        try{

                        fstream = new FileInputStream(file);
                        in = new DataInputStream(fstream);
                        is = new BufferedReader(new InputStreamReader(in));
                        }catch(Exception e)
                        {
                                System.err.println(e);
                        }
                }

        }

        void readNextLine()
    	{
    		try {
    			line = is.readLine();
    			inputParser = new StringTokenizer(line, " ");
    			//System.err.println("Input: " + line);
    		} catch (IOException e) {
    			System.err.println("Unexpected IO ERROR: " + e);
    		}
    		catch (NullPointerException e)
    		{
    			line=null;

    		}

    	}

        long NextLong()
        {
                String n = inputParser.nextToken();

                long val = Long.parseLong(n);

                 return val;
        }

        int NextInt()
        {
                String n = inputParser.nextToken();
                int val = Integer.parseInt(n);

                //System.out.println("I read this number: " + val);
                return val;
        }

        String NextString()
        {
                String n = inputParser.nextToken();
                return n;
        }

        void closeInput()
        {
                try {
                        is.close();
                } catch (IOException e) {
                        System.err.println("Unexpected IO ERROR: " + e);
                }

        }

        public static void main(String [] argv)
        {
                String filePath=null;
                if(argv.length>0)filePath=argv[0];
                new B(filePath);
        }

        public void readFInput()
    	{
    		for(;;)
    		{
    			try
    			{
    				readNextLine();
    				FInput+=line+" ";
    			}
    			catch(Exception e)
    			{
    				break;
    			}
    		}
    		inputParser = new StringTokenizer(FInput, " ");
    	}

        public B(String inputFile)
        {
        	openInput(inputFile);
    		readNextLine();
    		HashMap<String, Integer>map=new HashMap<String, Integer>();
    		int N=NextInt();
    		for(int i=0; i<N; i++)
    		{
    			readNextLine();
    			String name=NextString();
    			int score=NextInt();
    			if(map.containsKey(name)){
    				map.put(name, Math.max(map.get(name),score));
    			}
    			else map.put(name, score);
    		}
    		System.out.println(map.size());
    		for(String s: map.keySet())
    		{
    			System.out.print(s+" ");
    			System.out.println(getCat(map.get(s), map));
    		}

            closeInput();
    	}

		private String getCat(Integer m, HashMap<String, Integer> map) {
			int N=map.size();
			int better=0;
			int nwt=0;
			for(int a:map.values())
			{
				if(a>m)better++;
				else nwt++;
			}

			if(better*2>N)return"noob";

			if(nwt*2>N&&better*5>N)return"random";
			if(nwt*5>N*4&&better*10>N)return"average";
			if(nwt*10>N*9&&better*100>N)return"hardcore";
			if(nwt*100>N*99)return"pro";
			return"undefined";
		}

}


import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.math.*;

public class B
{
        String line;
        StringTokenizer inputParser;
        BufferedReader is;
        FileInputStream fstream;
        DataInputStream in;
        String FInput="";

        void openInput(String file)
        {

                if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
                else
                {
                        try{

                        fstream = new FileInputStream(file);
                        in = new DataInputStream(fstream);
                        is = new BufferedReader(new InputStreamReader(in));
                        }catch(Exception e)
                        {
                                System.err.println(e);
                        }
                }

        }

        void readNextLine()
    	{
    		try {
    			line = is.readLine();
    			inputParser = new StringTokenizer(line, " ");
    			//System.err.println("Input: " + line);
    		} catch (IOException e) {
    			System.err.println("Unexpected IO ERROR: " + e);
    		}
    		catch (NullPointerException e)
    		{
    			line=null;

    		}

    	}

        long NextLong()
        {
                String n = inputParser.nextToken();

                long val = Long.parseLong(n);

                 return val;
        }

        int NextInt()
        {
                String n = inputParser.nextToken();
                int val = Integer.parseInt(n);

                //System.out.println("I read this number: " + val);
                return val;
        }

        String NextString()
        {
                String n = inputParser.nextToken();
                return n;
        }

        void closeInput()
        {
                try {
                        is.close();
                } catch (IOException e) {
                        System.err.println("Unexpected IO ERROR: " + e);
                }

        }

        public static void main(String [] argv)
        {
                String filePath=null;
                if(argv.length>0)filePath=argv[0];
                new B(filePath);
        }

        public void readFInput()
    	{
    		for(;;)
    		{
    			try
    			{
    				readNextLine();
    				FInput+=line+" ";
    			}
    			catch(Exception e)
    			{
    				break;
    			}
    		}
    		inputParser = new StringTokenizer(FInput, " ");
    	}

        public B(String inputFile)
        {
        	openInput(inputFile);
    		readNextLine();
    		HashMap<String, Integer>map=new HashMap<String, Integer>();
    		int N=NextInt();
    		for(int i=0; i<N; i++)
    		{
    			readNextLine();
    			String name=NextString();
    			int score=NextInt();
    			if(map.containsKey(name)){
    				map.put(name, Math.max(map.get(name),score));
    			}
    			else map.put(name, score);
    		}
    		System.out.println(map.size());
    		for(String s: map.keySet())
    		{
    			System.out.print(s+" ");
    			System.out.println(getCat(map.get(s), map));
    		}

            closeInput();
    	}

		private String getCat(Integer m, HashMap<String, Integer> map) {
			int N=map.size();
			int better=0;
			int nwt=0;
			for(int a:map.values())
			{
				if(a>m)better++;
				else nwt++;
			}

			if(better*2>N)return"noob";

			if(nwt*2>=N&&better*5>N)return"random";
			if(nwt*5>=N*4&&better*10>N)return"average";
			if(nwt*10>=N*9&&better*100>N)return"hardcore";
			if(nwt*100>=N*99)return"pro";
			return"undefined";
		}

}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;

public class B {

	private void solve() throws IOException {
		int n = nextInt();
		Map<String, Integer> map = new HashMap<String, Integer>();

		for (int i = 0; i < n; i++) {
			String s = nextToken();
			int p = nextInt();
			if (map.get(s) == null || map.get(s) < p) {
				map.put(s, p);
			}
		}

		String[] s = new String[map.size()];
		int[] p = new int[map.size()];
		int k = 0;
		for (Entry<String, Integer> e : map.entrySet()) {
			s[k] = e.getKey();
			p[k] = e.getValue();
			k++;
		}

		println(map.size());
		for (int i = 0; i < s.length; i++) {
			int better = 0;
			for (int j = 0; j < s.length; j++) {
				if (i != j && p[j] > p[i]) {
					better++;
				}
			}

			if (better * 2 > s.length) {
				println(s[i] + " noob");
			} else if (better * 5 > s.length) {
				println(s[i] + " random");
			} else if (better * 10 > s.length) {
				println(s[i] + " average");
			} else if (better * 100 > s.length) {
				println(s[i] + " hardcore");
			} else {
				println(s[i] + " pro");
			}
		}
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	private double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new B().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}


import java.util.*;

import  static java.lang.Math.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<String,Integer> mp = new HashMap<String,Integer>();
        for (int i = 0; i < n; i++) {
            String name = in.next();
            int score = in.nextInt();
            if( mp.get(name)!=null)
            {
                if(score > mp.get(name) )
                    mp.put(name,score);
            }
            else
                mp.put(name,score);
        }
        System.out.println(mp.keySet().size());
        for (String string : mp.keySet()) {
            int most = 0;
            int equals = 0;
            int less = 0;
            for (String string2 :  mp.keySet()) {
                if(mp.get(string2)>mp.get(string))
                    most++;
                else if ((int)mp.get(string2)==(int)mp.get(string))
                    equals++;
                else
                    less++;
            }

            double rank1 = most*1.0/mp.keySet().size();
            double rank2 = (less+equals)*1.0/mp.keySet().size();
            if(rank1 > 0.5)
                 System.out.println(string + " " + "noob");
            else if(rank2 >= 0.5 && rank1 > 0.2 )
                System.out.println(string + " " + "random");
            else if(rank2 >= 0.8 && rank1 > 0.1 )
                System.out.println(string + " " + "average");
            else if(rank2 >= 0.9 && rank1 > 0.01 )
                System.out.println(string + " " + "hardcore");
            else if(rank2 >= 0.99)
                System.out.println(string + " " + "pro");
        }

    }
}


import java.util.*;

import  static java.lang.Math.*;

public class Main {
    public static boolean OK(String s)
    {
        if(s.length()>=2 && s.charAt(0)=='0')
            return false;
        if(s.length()>=8)
            return false;
        return Integer.parseInt(s)<=1000000;

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int ans = -1;
        if(s.length()<3)
        {
            System.out.println(-1);
            return;
        }

        for (int i = 1; i <= s.length()-2; i++) {
            String temp1 = s.substring(0, i);
            int n1,n2,n3;
            if(!OK(temp1))
                continue;
            n1 = Integer.parseInt(temp1);
            for (int j = i+1; j <= s.length()-1; j++)
            {
                String temp2 = s.substring(i, j);
                if(!OK(temp2))
                    continue;
                n2 = Integer.parseInt(temp2);

                String temp3 = s.substring(j);
                if(!OK(temp3))
                    continue;
                n3 = Integer.parseInt(temp3);
                ans = max(ans,n1+n2+n3);
            }
        }
        System.out.printf("%d\n",ans);
    }
}


import java.util.*;

import  static java.lang.Math.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<String,Integer> mp = new HashMap<String,Integer>();
        for (int i = 0; i < n; i++) {
            String name = in.next();
            int score = in.nextInt();
            if( mp.get(name)!=null && score > mp.get(name) )
                    mp.put(name,score);
            else
                mp.put(name,score);
        }
        System.out.println(mp.keySet().size());
        for (String string : mp.keySet()) {
            int most = 0;
            int equals = 0;
            int less = 0;
            for (String string2 :  mp.keySet()) {
                if(mp.get(string2)>mp.get(string))
                    most++;
                else if ((int)mp.get(string2)==(int)mp.get(string))
                    equals++;
                else
                    less++;
            }

            double rank1 = most*1.0/mp.keySet().size();
            double rank2 = (less+equals)*1.0/mp.keySet().size();
            if(rank1 > 0.5)
                 System.out.println(string + " " + "noob");
            else if(rank2 >= 0.5 && rank1 >= 0.2 )
                System.out.println(string + " " + "random");
            else if(rank2 >= 0.8 && rank1 >= 0.1 )
                System.out.println(string + " " + "average");
            else if(rank2 >= 0.9 && rank1 >= 0.01 )
                System.out.println(string + " " + "hardcore");
            else if(rank2 >= 0.99)
                System.out.println(string + " " + "pro");
        }

    }
}


import java.util.*;

import  static java.lang.Math.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<String,Integer> mp = new HashMap<String,Integer>();
        for (int i = 0; i < n; i++) {
            String name = in.next();
            int score = in.nextInt();
            if( mp.get(name)!=null)
            {
                if(score > mp.get(name) )
                    mp.put(name,score);
            }
            else
                mp.put(name,score);
        }
        System.out.println(mp.keySet().size());
        for (String string : mp.keySet()) {
            int most = 0;
            int equals = 0;
            int less = 0;
            for (String string2 :  mp.keySet()) {
                if(mp.get(string2)>mp.get(string))
                    most++;
                else if ((int)mp.get(string2)==(int)mp.get(string))
                    equals++;
                else
                    less++;
            }

            double rank1 = most*1.0/mp.keySet().size();
            double rank2 = (less+equals)*1.0/mp.keySet().size();
            if(rank1 > 0.5)
                 System.out.println(string + " " + "noob");
            else if(rank2 >= 0.5 && rank1 >= 0.2 )
                System.out.println(string + " " + "random");
            else if(rank2 >= 0.8 && rank1 >= 0.1 )
                System.out.println(string + " " + "average");
            else if(rank2 >= 0.9 && rank1 >= 0.01 )
                System.out.println(string + " " + "hardcore");
            else if(rank2 >= 0.99)
                System.out.println(string + " " + "pro");
        }

    }
}


import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskB {

    String getOrder(int lesser, int equal, int greater) {
        int total = lesser + equal + greater;
        if (greater * 2 >= total) return "noob";
        if ((lesser + equal) * 2 >= total && greater * 5 >= total) return "random";
        if ((lesser + equal) * 10 >= total * 8 && greater * 10 >= total) return "average";
        if ((lesser + equal) * 10 >= total * 9 && greater * 100 >= total) return "hardcore";
        if ((lesser + equal) * 100 >= total * 99) return "pro";

        return "";
    }

    void run() {
        int n = nextInt();

        HashMap<String, Integer> map = new HashMap<String, Integer>();
        for (int i = 0; i < n; i++) {
            String s = next();
            int x = nextInt();

            if (!map.containsKey(s)) map.put(s, 0);
            map.put(s, Math.max(map.get(s), x));
        }

        int M = map.size();
        String[] name = new String[M];
        int[] score = new int[M];
        int ix = 0;
        for (String x : map.keySet()) {
            name[ix] = x;
            score[ix++] = map.get(x);
        }

        System.out.println(M);
        for (int i = 0; i < M; i++) {
            int lesser = 0, equal = 0, greater = 0;
            for (int j = 0; j < M; j++) {
                if (score[i] < score[j]) greater++;
                else if (score[i] == score[j]) equal++;
                else lesser++;
            }
            System.out.println(name[i] + " " + getOrder(lesser, equal, greater));
        }
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskB().run();
    }
}


import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskB {

    String getOrder(int notWorse, int better) {
        if (better >= notWorse) return "noob";
        if (better < notWorse && better * 4 >= notWorse) return "random";
        if (better * 4 < notWorse && better * 9 >= notWorse) return "average";
        if (better * 9 < notWorse && better * 99 >= notWorse) return "hardcore";
        return "pro";
    }

    void run() {
        int n = nextInt();

        HashMap<String, Integer> map = new HashMap<String, Integer>();
        for (int i = 0; i < n; i++) {
            String s = next();
            int x = nextInt();

            if (!map.containsKey(s)) map.put(s, 0);
            map.put(s, Math.max(map.get(s), x));
        }

        int M = map.size();
        String[] name = new String[M];
        int[] score = new int[M];
        int ix = 0;
        for (String x : map.keySet()) {
            name[ix] = x;
            score[ix++] = map.get(x);
        }

        System.out.println(M);
        for (int i = 0; i < M; i++) {
            int notWorse = 0, better = 0;
            for (int j = 0; j < M; j++) {
                if (score[i] < score[j]) better++;
                else notWorse++;
            }
            System.out.println(name[i] + " " + getOrder(notWorse, better));
        }
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskB().run();
    }
}


import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskB {

    String getOrder(int notWorse, int better) {
        if (better > notWorse) return "noob";
        if (better * 4 > notWorse) return "random";
        if (better * 9 > notWorse) return "average";
        if (better * 99 > notWorse) return "hardcore";
        return "pro";
    }

    void run() {
        int n = nextInt();

        TreeMap<String, Integer> map = new TreeMap<String, Integer>();
        for (int i = 0; i < n; i++) {
            String s = next();
            int x = nextInt();

            if (!map.containsKey(s)) {
                map.put(s, x);
            } else {
                map.put(s, Math.max(map.get(s), x));
            }
        }

        int M = map.size();
        String[] name = new String[M];
        int[] score = new int[M];
        int ix = 0;
        for (String x : map.keySet()) {
            name[ix] = x;
            score[ix++] = map.get(x);
        }

        System.out.println(M);
        for (int i = 0; i < M; i++) {
            int notWorse = 0, better = 0;
            for (int j = 0; j < M; j++) {
                if (score[i] < score[j]) better++;
                else notWorse++;
            }
            System.out.println(name[i] + " " + getOrder(notWorse, better));
        }
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskB().run();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    StringTokenizer str = null;
    BufferedReader in;
    PrintWriter out;

    void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
        out.close();
    }

    String nextString() throws IOException {
        return in.readLine();
    }

    String nextToken() throws IOException {
        if (str == null || !str.hasMoreElements()) {
            str = new StringTokenizer(nextString());
        }
        return str.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    void solve() throws IOException {
        Map<String, Integer> map = new HashMap<String, Integer>();
        int n = nextInt();
        List<String> names = new ArrayList<String>();
        for (int i = 0; i < n; i++) {
            String name = nextToken();
            int v = nextInt();
            if (!map.containsKey(name)) {
                names.add(name);
                map.put(name, v);
            } else {
                int m = map.get(name);
                if (m < v)
                    map.put(name, v);
            }
        }
        List<Integer> values = new ArrayList<Integer>();
        for (String name : names) {
            int v = map.get(name);
            values.add(v);
        }
        int t = values.size();
        for (String name : names) {
            int v = map.get(name);
            int k = get(values, v);
            double p = ((double) t - (double) k) / (double) t * 100.0;
            out.println(name + " " + getR(p));
        }
    }

    private String getR(double p) {
        if (p < 50.0)
            return "noob";
        if (p < 80.0)
            return "random";
        if (p < 90.0)
            return "average";
        if (p < 99.0)
            return "hardcore";

        return "pro";
    }

    private int get(List<Integer> values, int v) {
        int r = 0;
        for (Integer m : values) {
            if (m > v)
                r++;
        }
        return r;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    StringTokenizer str = null;
    BufferedReader in;
    PrintWriter out;

    void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
        out.close();
    }

    String nextString() throws IOException {
        return in.readLine();
    }

    String nextToken() throws IOException {
        if (str == null || !str.hasMoreElements()) {
            str = new StringTokenizer(nextString());
        }
        return str.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    void solve() throws IOException {
        Map<String, Integer> map = new HashMap<String, Integer>();
        int n = nextInt();
        List<String> names = new ArrayList<String>();
        for (int i = 0; i < n; i++) {
            String name = nextToken();
            int v = nextInt();
            if (!map.containsKey(name)) {
                names.add(name);
                map.put(name, v);
            } else {
                int m = map.get(name);
                if (m < v)
                    map.put(name, v);
            }
        }
        List<Integer> values = new ArrayList<Integer>();
        for (String name : names) {
            int v = map.get(name);
            values.add(v);
        }
        int t = values.size();

        out.println(t);
        for (String name : names) {
            int v = map.get(name);
            int k = get(values, v);
            double p = ((double) t - (double) k) / (double) t * 100.0;
            out.println(name + " " + getR(p));
        }
    }

    private String getR(double p) {
        if (p < 50.0)
            return "noob";
        if (p < 80.0)
            return "random";
        if (p < 90.0)
            return "average";
        if (p < 99.0)
            return "hardcore";

        return "pro";
    }

    private int get(List<Integer> values, int v) {
        int r = 0;
        for (Integer m : values) {
            if (m > v)
                r++;
        }
        return r;
    }
}


import java.util.Map;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.HashMap;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		StreamInputReader in = new StreamInputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, StreamInputReader in, OutputWriter out) {
        int n = in.readInt();
        Map<String, Integer> nameId = new HashMap<String, Integer>();
        for (int i = 0; i < n; ++i) {
            String[] input = in.readLine().split(" +");
            if (!nameId.containsKey(input[0])) {
                nameId.put(input[0], Integer.parseInt(input[1]));
            } else {
                nameId.put(input[0], Math.max(nameId.get(input[0]), Integer.parseInt(input[1])));
            }
        }
        int m = nameId.size();
        for (Map.Entry<String, Integer> entry : nameId.entrySet()) {
            int k = 0;
            for (Map.Entry<String, Integer> e : nameId.entrySet()) {
                if (e.getKey().equals(entry.getKey())) continue;
                if (e.getValue() > entry.getValue()) ++k;
            }
            if (2 * k > m) {
                out.printLine(entry.getKey() + " noob");
                continue;
            }

            if (5 * k > m && 2 * k <= m) {
                out.printLine(entry.getKey() + " random");
                continue;
            }

            if (5 * k <= 4 * m && 10 * k > m) {
                out.printLine(entry.getKey() + " average");
                continue;
            }

            if (10 * k <= 9 * m && 100 * k > m) {
                out.printLine(entry.getKey() + " hardcore");
                continue;
            }

            if (100 * k <= 99 * m) {
                out.printLine(entry.getKey() + " pro");
            }
            else {
                throw new RuntimeException();
            }
        }
    }
}

class StreamInputReader extends InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public StreamInputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    }

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(outputStream);
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}
}

abstract class InputReader {

	public abstract int read();

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private String readLine0() {
        StringBuffer buf = new StringBuffer();
        int c = read();
        while (c != '\n' && c != -1) {
            if (c != '\r')
                buf.appendCodePoint(c);
            c = read();
        }
        return buf.toString();
    }

    public String readLine() {
        String s = readLine0();
        while (s.trim().length() == 0)
            s = readLine0();
        return s;
    }

    protected boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }


import java.util.Map;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.HashMap;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		StreamInputReader in = new StreamInputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, StreamInputReader in, OutputWriter out) {
        int n = in.readInt();
        Map<String, Integer> nameId = new HashMap<String, Integer>();
        for (int i = 0; i < n; ++i) {
            String[] input = in.readLine().split(" +");
            if (!nameId.containsKey(input[0])) {
                nameId.put(input[0], Integer.parseInt(input[1]));
            } else {
                nameId.put(input[0], Math.max(nameId.get(input[0]), Integer.parseInt(input[1])));
            }
        }
        int m = nameId.size();
        out.printLine(m);
        for (Map.Entry<String, Integer> entry : nameId.entrySet()) {
            int k = 0;
            for (Map.Entry<String, Integer> e : nameId.entrySet()) {
                if (e.getKey().equals(entry.getKey())) continue;
                if (e.getValue() > entry.getValue()) ++k;
            }
            if (2 * k > m) {
                out.printLine(entry.getKey() + " noob");
                continue;
            }

            if (5 * k > m && 2 * k <= m) {
                out.printLine(entry.getKey() + " random");
                continue;
            }

            if (5 * k <= 4 * m && 10 * k > m) {
                out.printLine(entry.getKey() + " average");
                continue;
            }

            if (10 * k <= 9 * m && 100 * k > m) {
                out.printLine(entry.getKey() + " hardcore");
                continue;
            }

            if (100 * k <= 99 * m) {
                out.printLine(entry.getKey() + " pro");
            }
            else {
                throw new RuntimeException();
            }
        }
    }
}

class StreamInputReader extends InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public StreamInputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    }

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(outputStream);
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}
}

abstract class InputReader {

	public abstract int read();

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private String readLine0() {
        StringBuffer buf = new StringBuffer();
        int c = read();
        while (c != '\n' && c != -1) {
            if (c != '\r')
                buf.appendCodePoint(c);
            c = read();
        }
        return buf.toString();
    }

    public String readLine() {
        String s = readLine0();
        while (s.trim().length() == 0)
            s = readLine0();
        return s;
    }

    protected boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }


import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		StreamInputReader in = new StreamInputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	public void solve(int testNumber, StreamInputReader in, OutputWriter out) {
        int n = in.readInt();
        int[] nums = new int[n];
        final int[] cost = new int[n];
        for(int i = 0; i < n; ++i) {
            int k = in.readInt(), c = in.readInt();
            nums[i] = k;
            cost[i] = c;
        }
        int t = in.readInt();
        long[] p = IOUtils.readLongArray(in, t);
        long last = p[0];
        for(int i = 1; i < t; ++i) {
            long nlast = p[i];
            p[i] -= last;
            last = nlast;
        }
        Integer[] order = new Integer[n];
        for(int i = 0; i < n; ++i) {
            order[i] = i;
        }
        Arrays.sort(order, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return cost[o1] - cost[o2];
            }
        });
        long res = 0;
        int a = 0;
        for(int i = 1; i <= t; ++i) {
            while (a < n) {
                long destroy = Math.min(p[i-1], nums[order[a]]);
                res += destroy * i * cost[order[a]];
                p[i-1] -= destroy;
                nums[order[a]] -= (int)destroy;
                if (p[i-1] == 0) break;
                else if (nums[order[a]] == 0) ++a;
                else throw new RuntimeException();
            }
        }
        while (a < n) {
            res += nums[order[a]] * (t+1) * cost[order[a]];
            ++a;
        }
        out.printLine(res);
	}
}

class StreamInputReader extends InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public StreamInputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    }

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(outputStream);
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}
}

abstract class InputReader {

	public abstract int read();

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    protected boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }

class IOUtils {

	public static long[] readLongArray(InputReader in, int size) {
		long[] array = new long[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readLong();
		return array;
	}

	}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class B {
    private void solve() {
        while(sc.hasNext()) {
            int n = sc.nextInt();
            sc.nextLine();
            Map<String, Player> map = new HashMap<String, Player>();
            ArrayList<Player> ps = new ArrayList<Player>();
            for(int i=0;i<n;i++) {
                String[] str = sc.nextLine().split(" ");
                String name = str[0];
                int points = Integer.valueOf(str[1]);
                Player p;
                if(!map.containsKey(name)) {
                    p = new Player(name, points);
                    ps.add(p);

                    map.put(name, p);
                } else if(map.get(name).points<points) {
                    p = map.get(name);
                    p.points = points;

                    map.put(name, p);
                }
            }
            Collections.sort(ps);
            n = ps.size();

            System.out.println(n);
            for(int i=0;i<ps.size();i++) {
                int more = i;
                while(more<ps.size() && ps.get(more).points==ps.get(i).points) more++;
                more = ps.size() - more;
                double better = (double)more / (double)ps.size();
                String res;
//              System.out.println(i+" "+better+" "+ps.get(i));
                if(better>=0.5) {
                    res = "noob";
                } else if(better<=0.5 && better>=0.2) {
                    res = "random";
                } else if(better<=0.8 && better>=0.1) {
                    res = "average";
                } else if(better<=0.9 && better>=0.01) {
                    res = "hardcore";
                } else {
                    res = "pro";
                }
                System.out.println(ps.get(i).name+" "+res);
            }
        }
    }

    class Player implements Comparable<Player>{
        public String name;
        public int points;
        public Player(String name, int points) {
            this.name = name;
            this.points = points;
        }
        @Override
        public int compareTo(Player arg0) {
            return points - arg0.points;
        }
        @Override
        public String toString() {
            return name+" "+points;
        }
    }

    private Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
        new B().solve();
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class B {
    private void solve() {
        while(sc.hasNext()) {
            int n = sc.nextInt();
            sc.nextLine();
            Map<String, Player> map = new HashMap<String, Player>();
            ArrayList<Player> ps = new ArrayList<Player>();
            for(int i=0;i<n;i++) {
                String[] str = sc.nextLine().split(" ");
                String name = str[0];
                int points = Integer.valueOf(str[1]);
                Player p;
                if(!map.containsKey(name)) {
                    p = new Player(name, points);
                    ps.add(p);

                    map.put(name, p);
                } else if(map.get(name).points<points) {
                    p = map.get(name);
                    p.points = points;

                    map.put(name, p);
                }
            }
            Collections.sort(ps);
            n = ps.size();

            System.out.println(n);
            for(int i=0;i<ps.size();i++) {
                int more = i;
                while(more<ps.size() && ps.get(more).points==ps.get(i).points) more++;
                more = ps.size() - more;
                double better = (double)more / (double)ps.size();
                String res;
//              System.out.println(i+" "+better+" "+ps.get(i));
                if(better>0.5) {
                    res = "noob";
                } else if(better<=0.5 && better>0.2) {
                    res = "random";
                } else if(better<=0.8 && better>0.1) {
                    res = "average";
                } else if(better<=0.9 && better>0.01) {
                    res = "hardcore";
                } else {
                    res = "pro";
                }
                System.out.println(ps.get(i).name+" "+res);
            }
        }
    }

    class Player implements Comparable<Player>{
        public String name;
        public int points;
        public Player(String name, int points) {
            this.name = name;
            this.points = points;
        }
        @Override
        public int compareTo(Player arg0) {
            return points - arg0.points;
        }
        @Override
        public String toString() {
            return name+" "+points;
        }
    }

    private Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
        new B().solve();
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;

public class Main {
   public static void main(String[] args) throws IOException
   {
	   (new Main()).solve();
   }
   public void Main() {
   }

   void solve()  throws IOException {
	  //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	  //Scanner in = new Scanner(System.in);
	   MyReader in = new MyReader();
	  PrintWriter out = new PrintWriter(System.out);
     // Scanner in = new Scanner(new FileReader("input.txt"));
	//  PrintWriter out = new PrintWriter("output.txt");
	 int n = in.nextInt();
	 Map<String, Integer> a = new HashMap<String, Integer>();
	 for (int i = 0; i < n; i++) {
		 String name = in.nextString();
		 int res = in.nextInt();
		 if (a.containsKey(name)) {
			 res = Math.max(a.get(name), res);
		 }
		 a.put(name, res);
	 }
	 int[] t = new int[1001];
	 for (Entry<String, Integer> res : a.entrySet()) {
		 t[res.getValue()]++;
	 }
	 int m = a.size();
	 out.println(m);
	 for (Entry<String, Integer> res : a.entrySet()) {
		 int after = 0;
		 for (int i = res.getValue() + 1; i < 1001; i++) {
			 after += t[i];
		 }
		 double g = (0.0 + after * 100) / m;
		 if (g > 50) {
			 out.println(res.getKey() + " noob");
		 } else if (g > 20) {
			 out.println(res.getKey() + " random");
		 } else if (g > 10) {
			 out.println(res.getKey() + " average");
		 } else if (g > 1) {
			 out.println(res.getKey() + " hardcore");
		 } else {
			 out.println(res.getKey() + " pro");
		 }
	 }

	out.close();
   }

};

class MyReader {
	private BufferedReader in;
	String[] parsed;
	int index = 0;

	public MyReader() {
		in = new BufferedReader(new InputStreamReader(System.in));
	}

	public int nextInt() throws NumberFormatException, IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return Integer.parseInt(parsed[index++]);
	}

	public String nextString() throws IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return parsed[index++];
	}

	private void read() throws IOException {
		parsed = in.readLine().split(" ");
		index = 0;
	}

	public String readLine() throws IOException {
		return in.readLine();
	}
};


#include <bits/stdc++.h>
using namespace std;
#define maxn 1001

map<string, int> ma;
string name[maxn];
int p[maxn], cnt;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, i, k;
	double a, b;
	string s, ret;
	cin >> n;
	while(n--) {
		cin >> s >> i;
		if (!ma[s]) {
			ma[s] = ++cnt;
			name[cnt] = s;
		}
		k = ma[s];
		p[k] = max(p[k], i);
	}
	cout << cnt;
	for (i = 1; i <= cnt; i++) {
		ret = "\n" + name[i] + " ";
		a = b = 0;
		for (k = 1; k <= cnt; k++) {
			a += p[k] <= p[i];
			b += p[k] > p[i];
		}
		a /= cnt;
		b /= cnt;
		if (b > 0.5) ret += "noob";
		else if (a >= 0.5 && b > 0.2) ret += "random";
		else if (a >= 0.8 && b > 0.1) ret += "average";
		else if (a >= 0.9 && b > 0.01) ret += "hardcore";
		else ret += "pro";
		cout << ret;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline bool id(const char ch) {
	return ch>='0'&&ch<='9';
}
inline int read(void) {
	int s=0;
	char ch=getchar();
	while(!id(ch)) ch=getchar();
	while(id(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return s;
}
const int MAXN=3e3+10;
int n,f[MAXN],h=1,t=0,q[MAXN],ans[MAXN],dfn[MAXN],vis;
vector<int>G[MAXN];
void dfs(const int k) {
	dfn[k]=++vis;
	for(int i=0;i<G[k].size();++i) {
		int to=G[k][i];
		if(!dfn[to]) f[to]=k,dfs(to);
		else {
			if(dfn[to]<dfn[k]) continue;
			q[++t]=to,ans[k]=1;
			for(int j=to;j!=k;j=f[j]) ans[j]=1,q[++t]=f[j];
		}
	}
	return;
}
int main() {
	n=read();
	for(int i=1,u,v;i<=n;++i) u=read(),v=read(),G[u].push_back(v),G[v].push_back(u);
	dfs(1);
	while(h<=t) {
		int tmp=q[h++];
		for(int i=0;i<G[tmp].size();++i) {
			int to=G[tmp][i];
			if(!ans[to]) ans[to]=ans[tmp]+1,q[++t]=to;
		}
	}
	for(int i=1;i<=n;++i) printf("%d ",ans[i]-1);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#define INF 1e9
using namespace std;
int n,m,cnt,head[5001],circle[5001],tot,ans[5001],dis[5001];
bool vis[5001],cir[5001];
struct Edge{
	int next,to;
}edge[10001];
inline void add(int u,int v){
	edge[++cnt].next=head[u];
	edge[cnt].to=v;
	head[u]=cnt;
	return;
}
int flag=0;
void dfs1(int p,int from){
	vis[p]=1;
	for(int i=head[p];i;i=edge[i].next){
		int v=edge[i].to;
		if(v==from||p==flag) continue;
		if(!vis[v]) dfs1(v,p);
		else {
			flag=v;
			circle[++tot]=v;
			cir[v]=1;
			break;
		}
	}
	if(flag&&flag!=p) circle[++tot]=p,cir[p]=1;
	if(flag==p) flag=0;
}
queue <int> q;
void spfa(int s){
	while(!q.empty()) q.pop();
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)
		dis[i]=INF;
	dis[s]=0;
	q.push(s);
	vis[s]=1;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=head[u];i;i=edge[i].next){
			int v=edge[i].to;
			if(dis[v]>dis[u]+1){
				dis[v]=dis[u]+1;
				if(!vis[v]){
					q.push(v);
					vis[v]=1;
				}
			}
		}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		add(u,v); add(v,u);
	}
	dfs1(1,1);
	for(int i=1;i<=n;i++)
		if(!cir[i]){
			tot=0;
			//printf("** %d\n",i);
			memset(cir,0,sizeof(cir));
			memset(circle,0,sizeof(circle));
			memset(vis,0,sizeof(vis));
			dfs1(i,i);
			break;
		}
	for(int i=1;i<=n;i++)
		if(cir[i]) printf("0 ");
		else {
			spfa(i);
			int ans=INF;
			for(int j=1;j<=n;j++)
				if(cir[j]) ans=min(ans,dis[j]);
			printf("%d ",ans);
		}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#define INF 1e9
using namespace std;
int n,m,cnt,head[5001],circle[5001],tot,ans[5001],dis[5001],pre[5001];
bool vis[5001],cir[5001];
struct Edge{
	int next,to;
}edge[10001];
inline void add(int u,int v){
	edge[++cnt].next=head[u];
	edge[cnt].to=v;
	head[u]=cnt;
	return;
}
void dfs(int p,int from){
	vis[p]=1;
	for(int i=head[p];i;i=edge[i].next){
		int v=edge[i].to;
		if(v==from) continue;
		if(!vis[v]) pre[v]=p,dfs(v,p);
		else {
			circle[1]=v;
			cir[v]=1;
			return;
		}
	}
}
struct node{
	int u,dis;
	bool operator <( const node &x )const{
        return x.dis < dis;
    }
};
priority_queue <node> q;
void dijkstra(int s){
	while(!q.empty()) q.pop();
	for(int i=1;i<=n;i++) dis[i]=INF;
	dis[s]=0;
	q.push((node){s,0});
	memset(vis,0,sizeof(vis));
	while(!q.empty()){
		node f=q.top();
		q.pop();
		int u=f.u;
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=head[u];i;i=edge[i].next){
			int v=edge[i].to;
			if(dis[v]>dis[u]+1){
				dis[v]=dis[u]+1;
				if(!vis[v]) q.push((node){v,dis[v]});
			}
		}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		add(u,v); add(v,u);
	}
	dfs(1,0);
	int u=circle[1];
	while(pre[u]!=circle[1]&&pre[u]){
		circle[++tot]=u;
		cir[u]=1;
		u=pre[u];
	}
	if(!pre[u]) circle[++tot]=1;
	for(int i=1;i<=n;i++)
		if(cir[i]) printf("0 ");
		else {
			dijkstra(i);
			int ans=INF;
			for(int j=1;j<=n;j++)
				if(cir[j]) ans=min(ans,dis[j]);
			printf("%d ",ans);
		}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n;
int cnt,h[5005],nex[5005<<1],to[5005<<1];//静态邻接表
int dep[5005],sk[1000005],top;//手动开栈
bool cir[5005],found=false,vis[5005];

void addedge(int x,int y)
{
	nex[++cnt] = h[x];
	to[cnt] = y;
	h[x] = cnt;
}

void findcir(int x,int f)
{
	if(found)//如果已经找到了，直接return
		return;
	vis[x] = true;
	sk[++top] = x; // 把节点压入栈
	for(int i=h[x];i;i=nex[i])
	{
		if(to[i]==f)
			continue;
		if(vis[to[i]])  //节点已经被访问过(找到环)
		{
			found = true;   // 找到环
			cir[to[i]] = true;
			while(sk[top]!=to[i])
				cir[sk[top--]] = true;  //在环上的所有点都标记为true
			return;
		}
		findcir(to[i],x);
		top--;
		vis[to[i]] = false; // 回溯
	}
}

void getdep(int x)
{
	for(int i=h[x];i;i=nex[i])
		if(!cir[to[i]] && dep[to[i]]==0)
		// 如果被访问节点在环上或者被访问过
		{
			dep[to[i]] = dep[x]+1;
			getdep(to[i]);  // 递归
		}
}

int main()
{
	cin>>n;
	for(int i=1,x,y;i<=n&&cin>>x>>y;i++)
	{
		addedge(x,y);
		addedge(y,x);
	}
	findcir(1,0);   // 找环
	for(int i=1;i<=n;i++)
		if(cir[i])  // 如果当前节点(起点)在环上
		{
			dep[i] = 0; // 起点深度为0
			getdep(i);  // 求深度
		}
	for(int i=1;i<=n;i++)
		cout<<dep[i]<<' ';cout<<endl;

	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
const int mx=5005;
int n,cnt=0,head[mx],num=0,top[mx],tck=0,dis[mx];
bool vis[mx],flag=false,cir[mx];
struct edge{
	int v,nxt;
}eg[mx<<1];
void add(int u,int v){
	eg[++cnt].v=v,eg[cnt].nxt=head[u],head[u]=cnt;
}
void dfs1(int x,int fa){
	if(flag) return ;
	vis[x]=true;
	top[++tck]=x;
	for(int i=head[x];i;i=eg[i].nxt){
		int v=eg[i].v;
		if(v==fa) continue;
		if(vis[v]){
			cir[v]=true;
			while(top[tck]!=v) cir[top[tck--]]=true;
			flag=true;
			return ;
		}
		dfs1(v,x);
		if(flag) return ;
		tck--;
	    vis[x]=false;
	}
}
void dfs2(int x,int fa){
	for(int i=head[x];i;i=eg[i].nxt){
		int v=eg[i].v;
		if(v==fa||cir[v]) continue;
		dis[v]=dis[x]+1;
		dfs2(v,x);
	}
}
int main(){
	int u,v,val;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs1(1,0);
	for(int i=1;i<=n;i++){
		if(cir[i]) dfs2(i,0);
	}
	for(int i=1;i<=n;i++) printf("%d ",dis[i]);
	return 0;
}


#include <bits/stdc++.h>

#define MAXN 3030
#define re register

using namespace std;

struct edge
{
	int to,next;
}e[MAXN<<1];

int first[MAXN],dis[MAXN];
int low[MAXN],dfn[MAXN];
bool iscir[MAXN],vis[MAXN];
int tot,n,cnt,startcir;

stack <int> p;

inline int read()
{
	re int res=0;re bool f=1;
	re char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=0;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		res=(res<<3)+(res<<1)+(ch&15);
		ch=getchar();
	}
	return f?res:-res;
}

inline void addedge(re int u,re int v)
{
	e[++tot]=(edge){v,first[u]};
	first[u]=tot;
}

inline void ADD(re int u,re int v)
{
	addedge(u,v);
	addedge(v,u);
}

void tarjan(re int u,re int fa)
{
	low[u]=dfn[u]=++cnt;
	p.push(u);
	for(re int i=first[u];i;i=e[i].next)
	{
		re int v=e[i].to;
		if(v==fa) continue;
		if(!dfn[v])
		{
			tarjan(v,u);
			low[u]=min(low[u],low[v]);
		}
		else if(!vis[v]) low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u])
	{
		if(p.top()^u)
		{
			startcir=p.top();
			while(p.top()^u)
			{
				iscir[p.top()]=true;
				vis[p.top()]=true;
				p.pop();
			}
			iscir[p.top()]=true;
			vis[p.top()]=true;
			p.pop();
		}
		else p.pop();
	}
}

void dfs(re int u,re int d)
{
	dis[u]=d;
	vis[u]=true;
	for(re int i=first[u];i;i=e[i].next)
	{
		re int v=e[i].to;
		if(vis[v]) continue;
		if(iscir[v]) dfs(v,d);
		else dfs(v,d+1);
	}
}

int main()
{
	n=read();
	for(re int i=1;i<=n;++i) ADD(read(),read());
	tarjan(1,1);
	memset(vis,0,sizeof vis);
	dfs(startcir,0);
	for(re int i=1;i<=n;++i) printf("%d ",dis[i]);
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int Max(int x,int y){return x>y?x:y;}
inline int Min(int x,int y){return x<y?x:y;}
typedef long long LL;
inline LL read(){
	register LL x=0,f=1;register char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<3)+(x<<1)+(c&15),c=getchar();
	return f*x;
}

const int MAXN=3005;
const int MAXM=6005;

struct Edge{
	int v,next;
}e[MAXM];
int first[MAXN],Ecnt;
inline void Add_edge(int u,int v){
	e[++Ecnt]=(Edge){v,first[u]};
	first[u]=Ecnt;
}

int dep[MAXN],st[MAXN];
bool vis[MAXN],huan[MAXN],Hflag;
int n,m,top;

inline void dfs1(int u,int pre){
	if(Hflag) return;
	st[++top]=u;vis[u]=true;
	for(int i=first[u];i;i=e[i].next){
		int v=e[i].v;
		if(v==pre) continue;
		if(vis[v]){
			/*while(st[top]!=v){
				huan[st[top]]=true;
				top--;
			}*/
			while(st[top]!=v)
				huan[st[top--]]=true;
			huan[v]=true;
			//top--;
			Hflag=true;
			return;
		}
		dfs1(v,u);
		vis[v]=false;top--;
	}
}

inline void dfs2(int u,int pre){
	if(dep[u]) return;
	if(huan[u]) return;
	for(int i=first[u];i;i=e[i].next){
		int v=e[i].v;
		if(v==pre) continue;
		dfs2(v,u);
		dep[u]=dep[v]+1;
	}
}

inline void dfs3(int u){
	for(int i=first[u];i;i=e[i].next){
		int v=e[i].v;
		if(huan[v]||dep[v]) continue;
		dep[v]=dep[u]+1;
		dfs3(v);
	}
}

int main(){
	n=read();
	for(int i=1;i<=n;i++){
		int x=read(),y=read();
		Add_edge(x,y);
		Add_edge(y,x);
	}
	dfs1(1,0);
	/*for(int i=1;i<=n;i++)
		printf("%d ",huan[i]);
	printf("\n");*/
	for(int i=1;i<=n;i++){
		if(huan[i]) dfs3(i);
		printf("%d ",dep[i]);
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
stack<int> st;map<int,int> mp;
int cnt,flag,h[10010],fa[10010],siz[10010],dis[10010],vis[10010];
struct edge{int to,nxt;}e[10010];
void addedge(int u,int v){e[++cnt]=(edge){v,h[u]};h[u]=cnt;}
void add(int u,int v){addedge(u,v);addedge(v,u);}
int n,x,y;
int find(int xx)
{
	while(fa[xx])xx=fa[xx];
	return xx;
}
int merge(int xx,int yy)
{
	int fx=find(xx),fy=find(yy);
	if(fx==fy)return 1;
	if(siz[fx]<siz[fy])
	{
		fa[fx]=fy;
		siz[fy]+=siz[fx];
		fa[xx]=fy;
		return 0;
	}
	else
	{
		fa[fy]=fx;
		siz[fx]+=siz[fy];
		fa[yy]=fx;
		return 0;
	}
}
void dfs1(int u)
{
	if(u==y)
	{
		while(!st.empty())
		{
			mp[st.top()]++;
			st.pop();
		}
		mp[x]++;flag=1;
		return;
	}
	for(int i=h[u];i;i=e[i].nxt)
	{
		int p=e[i].to;
		if(!vis[p])
		{
			vis[p]=1;st.push(p);
			dfs1(p);if(flag)return;
			st.pop();vis[p]=0;
		}
	}
}
void dfs2(int u)
{
	for(int i=h[u];i;i=e[i].nxt)
	{
		int p=e[i].to;
		if(!vis[p])
		{
			vis[p]=1;
			dis[p]=min(dis[p],dis[u]+1);
			dfs2(p);vis[p]=0;
		}
	}
}
int main()
{
	scanf("%d",&n);memset(dis,0x3f,sizeof(dis));
	for(int i=1;i<=n;i++)siz[i]=1;
	for(int i=1;i<=n;i++)
	{
		int xx,yy;scanf("%d%d",&xx,&yy);
		if(merge(xx,yy))x=xx,y=yy;
		else add(xx,yy);
	}
	vis[x]=1;dfs1(x);
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		memset(vis,0,sizeof(vis));
		dis[it->first]=0;
		dfs2(it->first);
	}
	for(int i=1;i<=n;i++)printf("%d ",dis[i]);
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <set>
#include <vector>
#define REP(i, n) (i) = 0; for(int _##i=(n); (i)<_##i; ++(i))
using namespace std;
vector<int> v[3005];
set<int> s;
int z[3005];
int dfs(int cur, int cnt, int last)
{
//    if(s.count(cur) != 0) return cnt;
    s.insert(cur);
    int Min = 1e9, i;
    REP(i, v[cur].size())
    {
        if(v[cur][i] != last)
        {
            if(s.count(v[cur][i]) != 0) Min = min(Min, cnt+1);
            else Min = min(Min, dfs(v[cur][i], cnt+1, cur));
        }
    }
    s.erase(cur);
    return Min;
}
int main()
{
    int i, j, n, Min = 1e9;
    scanf("%d", &n);
    REP(i, n)
    {
        int in1, in2;
        scanf("%d %d", &in1, &in2);
        v[in1-1].push_back(in2-1);
        v[in2-1].push_back(in1-1);
    }
//    printf("%d\n", dfs(3, 0, 3));
//    return 0;
    REP(i, n)
    {
        z[i] = dfs(i, 0, i);
        Min = min(Min, z[i]);
//        printf("%d ", z[i]);
    }
    REP(i, n) printf("%d ", z[i]-Min);
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <set>
#include <vector>
#define REP(i, n) (i) = 0; for(int _##i=(n); (i)<_##i; ++(i))
using namespace std;
vector<int> v[3005];
set<int> s;
int z[3005];
int dfs(int cur, int cnt, int last)
{
//    printf("%d %d\n", cur, cnt);
    if(s.count(cur) != 0)
    {
//        printf(" %d %d\n", cur, cnt);
        return cnt;
    }
    s.insert(cur);
    int Min = 1e9, i;
    REP(i, v[cur].size())
    {
        if(v[cur][i] != last) Min = min(Min, dfs(v[cur][i], cnt+1, cur));
    }
    s.erase(cur);
    return Min;
}
int main()
{
    int i, j, n, Min = 1e9;
    scanf("%d", &n);
    REP(i, n)
    {
        int in1, in2;
        scanf("%d %d", &in1, &in2);
        v[in1-1].push_back(in2-1);
        v[in2-1].push_back(in1-1);
    }
//    printf("%d\n", dfs(3, 0, 3));
//    return 0;
    REP(i, n)
    {
        s.clear();
        z[i] = dfs(i, 0, i);
        Min = min(Min, z[i]);
//        printf("%d ", z[i]);
    }
    REP(i, n) printf("%d ", z[i]-Min);
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <set>
#include <vector>
#define REP(i, n) (i) = 0; for(int _##i=(n); (i)<_##i; ++(i))
using namespace std;
vector<int> v[3005];
int s[3005];
int z[3005];
int dfs(int cur, int cnt, int last)
{
//    if(s.count(cur) != 0) return cnt;
//    s.insert(cur);
    s[cur] = 1;
    int Min = 1e9, i;
    REP(i, v[cur].size())
    {
        if(v[cur][i] != last)
        {
            if(s[v[cur][i]] != 0) Min = min(Min, cnt+1);
            else Min = min(Min, dfs(v[cur][i], cnt+1, cur));
        }
    }
//    s.erase(cur);
    s[cur] = 0;
    return Min;
}
int main()
{
    int i, j, n, Min = 1e9;
    scanf("%d", &n);
    REP(i, n)
    {
        int in1, in2;
        scanf("%d %d", &in1, &in2);
        v[in1-1].push_back(in2-1);
        v[in2-1].push_back(in1-1);
    }
//    printf("%d\n", dfs(3, 0, 3));
//    return 0;
    REP(i, n)
    {
        z[i] = dfs(i, 0, i);
        Min = min(Min, z[i]);
//        printf("%d ", z[i]);
    }
    REP(i, n) printf("%d ", z[i]-Min);
    return 0;
}


/**==============================================================*
*            "Bismillahir Rahmanir Raheem"                       *
*        Author          :  Misbah Uddin Tareq.                  *
*        Semester        :  5(C),CSE                             *
*        University      :  Leading University,Sylhet.           *
*===============================================================**/

#include<bits/stdc++.h>
using namespace std;
#define  ll                     long long
#define  pb                     push_back
#define  pii                    pair<int,int>
#define  pll                    pair<ll,ll>
#define  ff                     first
#define  ss                     second
#define  MX                     3005
#define  endl                   "\n"
#define  mod                    1e9+7
#define  pi                     acos(-1.0)
#define  PQ                     priority_queue
#define  mem(a,b)               memset(a, b, sizeof(a))
#define  bug(a)                 cout<<#a<<":"<<a<<endl
#define  all(x)                 (x).begin(),(x).end()
#define  allr(x)                (x).rbegin(),(x).rend()
#define  double_print(x,a)      cout<<fixed<<setprecision(x)<<a<<endl

vector<ll>adj[MX],v;
ll vis[MX],vis1[MX],dis[MX],par[MX],n,m,xx;
bool cycle=0;
bool ok=false;

ll cyc(ll u,ll i)
{
    if(ok)
        return 1;
    while(par[u]!=i)
    {
        v.pb(u);
        u=par[u];
    }
    v.pb(u);
    v.pb(i);
    if(v.size()>xx)
    {
        reverse(v.begin(),v.end());
        return 1;
    }
    v.clear();
    return 0;
}

void dfs(ll u)
{
    vis[u]=1;
    for(auto i : adj[u])
    {
        if(vis[i] && par[u]!=i)
        {
            int c=cyc(u,i);
            if(c)
            {
                ok=true;
            }
            return;
        }
        else if(!vis[i])
        {
            par[i]=u;
            dis[i]=dis[u]+1;
            if(!ok)
                dfs(i);
        }
    }
}

void bfs(ll s)
{
    mem(dis,0);
    mem(vis1,0);
    queue<ll>q;
    q.push(s);
    vis1[s]=1;
    dis[s]=0;
    while(!q.empty())
    {
        s=q.front();
        q.pop();
        for(auto it:adj[s])
        {
            if(vis[it] && !vis1[it]){
                dis[it]=0;
                vis1[it]=1;
               q.push(it);
            }

            if(!vis1[it])
            {
                vis1[it]=1;
                dis[it]=dis[s]+1;
                q.push(it);
            }
        }
    }
}

int main()
{
    //ios::sync_with_stdio(0); //cin.tie(0);

    ll n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        ll u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1);
    mem(vis,0);
    for(auto it:v)
    {
        vis[it]=1;
       // cout<<it<<" ";
    }
  //  cout<<endl;

    bfs(1);

    for(int i=1; i<=n; i++)
        cout<<dis[i]<<" ";
    cout<<endl;

    return 0;
}


/**==============================================================*
*            "Bismillahir Rahmanir Raheem"                       *
*        Author          :  Misbah Uddin Tareq.                  *
*        Semester        :  5(C),CSE                             *
*        University      :  Leading University,Sylhet.           *
*===============================================================**/

#include<bits/stdc++.h>
using namespace std;
#define  ll                     long long
#define  pb                     push_back
#define  pii                    pair<int,int>
#define  pll                    pair<ll,ll>
#define  ff                     first
#define  ss                     second
#define  MX                     3005
#define  endl                   "\n"
#define  mod                    1e9+7
#define  pi                     acos(-1.0)
#define  PQ                     priority_queue
#define  mem(a,b)               memset(a, b, sizeof(a))
#define  bug(a)                 cout<<#a<<":"<<a<<endl
#define  all(x)                 (x).begin(),(x).end()
#define  allr(x)                (x).rbegin(),(x).rend()
#define  double_print(x,a)      cout<<fixed<<setprecision(x)<<a<<endl

vector<ll>adj[MX],v;
ll vis[MX],vis1[MX],dis[MX],par[MX],n,m,xx;
bool cycle=0;
bool ok=false;

ll cyc(ll u,ll i)
{
    if(ok)
        return 1;
    while(par[u]!=i)
    {
        v.pb(u);
        u=par[u];
    }
    v.pb(u);
    v.pb(i);
    if(v.size()>xx)
    {
        reverse(v.begin(),v.end());
        return 1;
    }
    v.clear();
    return 0;
}

void dfs(ll u)
{
    vis[u]=1;
    for(auto i : adj[u])
    {
        if(vis[i] && par[u]!=i)
        {
            int c=cyc(u,i);
            if(c)
            {
                ok=true;
            }
            return;
        }
        else if(!vis[i])
        {
            par[i]=u;
            dis[i]=dis[u]+1;
            if(!ok)
                dfs(i);
        }
    }
}

void bfs(ll s)
{
    mem(dis,0);
    mem(vis1,0);
    queue<ll>q;
    q.push(s);
    vis1[s]=1;
    dis[s]=0;
    while(!q.empty())
    {
        s=q.front();
        q.pop();
        for(auto it:adj[s])
        {
            if(vis[it] && !vis1[it]){
                dis[it]=0;
                vis1[it]=1;
               q.push(it);
            }

            if(!vis1[it])
            {
                vis1[it]=1;
                dis[it]=dis[s]+1;
                q.push(it);
            }
        }
    }
}

int main()
{
    //ios::sync_with_stdio(0); //cin.tie(0);

    ll n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        ll u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1);
    mem(vis,0);
    for(auto it:v)
    {
        vis[it]=1;
       // cout<<it<<" ";
    }
   //cout<<endl;

    bfs(v[0]);

    for(int i=1; i<=n; i++)
        cout<<dis[i]<<" ";
    cout<<endl;

    return 0;
}


#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string.h>

using namespace std;

vector < vector < int > > V(3001) ;
int P[3001][3001] ;
int vis[3001] ;
deque < int > lol ;
bool _ = 0 ;
void dfs( int idx , pair < int , int > e )
{
    if ( _ )
        return ;
    if ( vis[idx] )
    {
        _ = 1;
        while ( lol.front() != idx ) lol.pop_front();
        return ;
    }
    vis[idx] = 1 ;
    for ( int i = 0 ; i < V[idx].size() ; i++ )
    {
        if ( P[idx][V[idx][i]] || P[V[idx][i]][idx] )
            continue;
        lol.push_back(V[idx][i]);
        P[idx][V[idx][i]] = 1;
        dfs(V[idx][i],make_pair(idx,V[idx][i]));
        if ( _ )
            return ;
        P[idx][V[idx][i]] = 0 ;
        lol.pop_back();
    }
}
int arr[3001] ;
int ans[3001] ;

void dfs2( int idx , int ctr)
{
    if ( vis[idx] )
    {
        return ;
    }
    vis[idx] = 1 ;
    ans[idx] = min(ans[idx],ctr);
    for ( int i = 0 ; i < V[idx].size() ; i++ )
        dfs2(V[idx][i],ctr+1);
}
int main()
{
    int n ;
    scanf("%d",&n);
    int v , u  ;
    for ( int i =  0 ; i < n ;i++ ) {
        scanf("%d %d",&v,&u);
        V[v].push_back(u);
        V[u].push_back(v);
    }
    for ( int i = 1;  i<= n ; i++ )
    {
        lol.clear();
        lol.push_back(i);
        dfs(i,{0,0});
        if ( _ )
            break;
    }
    lol.pop_front();
    fill(ans,ans+3001, 1E9);
    while ( lol.size() )
    {
        memset(vis,0,sizeof vis);
        arr[lol.front()] = 1 ;
        ans[lol.front()] = 0 ;
        dfs2(lol.front(),0);
        lol.pop_front() ;
    }
    for ( int i = 1 ; i <= n ; i++ )
        printf("%d ",ans[i]);
    return 0;
}


#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string.h>

using namespace std;

vector < vector < int > > V(3001) ;
int P[3001][3001] ;
int vis[3001] ;
deque < int > lol ;
bool _ = 0 ;
void dfs( int idx  )
{
    if ( _ )
        return ;
    if ( vis[idx] )
    {
        _ = 1;
        while ( lol.front() != idx ) lol.pop_front();
        return ;
    }
    vis[idx] = 1 ;
    for ( int i = 0 ; i < V[idx].size() ; i++ )
    {
        if ( P[idx][V[idx][i]] || P[V[idx][i]][idx] )
            continue;
        lol.push_back(V[idx][i]);
        P[idx][V[idx][i]] = 1;
        dfs(V[idx][i]);
        if ( _ )
            return ;
        P[idx][V[idx][i]] = 0 ;
        lol.pop_back();
    }
}
int arr[3001] ;
int ans[3001] ;

void dfs2( int idx , int ctr)
{
    if ( vis[idx] )
    {
        return ;
    }
    vis[idx] = 1 ;
    ans[idx] = min(ans[idx],ctr);
    for ( int i = 0 ; i < V[idx].size() ; i++ )
        dfs2(V[idx][i],ctr+1);
}
int main()
{
    int n ;
    scanf("%d",&n);
    int v , u  ;
    for ( int i =  0 ; i < n ;i++ ) {
        scanf("%d %d",&v,&u);
        V[v].push_back(u);
        V[u].push_back(v);
    }
    for ( int i = 1;  i<= n ; i++ )
    {
        lol.clear();
        lol.push_back(i);
        dfs(i);
        if ( _ )
            break;
    }
    lol.pop_front();
    fill(ans,ans+3001, 1E9);
    while ( lol.size() )
    {
        memset(vis,0,sizeof vis);
        arr[lol.front()] = 1 ;
        ans[lol.front()] = 0 ;
        dfs2(lol.front(),0);
        lol.pop_front() ;
    }
    for ( int i = 1 ; i <= n ; i++ )
        printf("%d ",ans[i]);
    return 0;
}


#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string.h>

using namespace std;

vector < vector < int > > V(3001) ;
int P[3001][3001] ;
int vis[3001] ;
deque < int > lol ;
bool _ = 0 ;
void dfs( int idx , pair < int , int > e )
{
    if ( _ )
        return ;
    if ( vis[idx] )
    {
        _ = 1;
        while ( lol.front() != idx ) lol.pop_front();
    }
    vis[idx] = 1 ;
    for ( int i = 0 ; i < V[idx].size() ; i++ )
    {
        if ( P[idx][V[idx][i]] || P[V[idx][i]][idx] )
            continue;
        lol.push_back(V[idx][i]);
        P[idx][V[idx][i]] = 1;
        dfs(V[idx][i],make_pair(idx,V[idx][i]));
        if ( _ )
            return ;
        P[idx][V[idx][i]] = 0 ;
        lol.pop_back();
    }
}
int arr[3001] ;
int ans[3001] ;

void dfs2( int idx , int ctr)
{
    if ( vis[idx] )
    {
        return ;
    }
    vis[idx] = 1 ;
    ans[idx] = min(ans[idx],ctr);
    for ( int i = 0 ; i < V[idx].size() ; i++ )
        dfs2(V[idx][i],ctr+1);
}
int main()
{
    int n ;
    scanf("%d",&n);
    int v , u  ;
    for ( int i =  0 ; i < n ;i++ ) {
        scanf("%d %d",&v,&u);
        V[v].push_back(u);
        V[u].push_back(v);
    }
    for ( int i = 1;  i<= n ; i++ )
    {
        memset(P,0,sizeof P);
        memset(vis,0,sizeof vis);
        lol.clear();
        lol.push_back(i);
        dfs(i,{0,0});
        if ( _ )
            break;
    }
    lol.pop_front();
    fill(ans,ans+3001, 1E9);
    while ( lol.size() )
    {
        memset(vis,0,sizeof vis);
        arr[lol.front()] = 1 ;
        ans[lol.front()] = 0 ;
        dfs2(lol.front(),0);
        lol.pop_front() ;
    }
    for ( int i = 1 ; i <= n ; i++ )
        printf("%d ",ans[i]);
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#define si(a) scanf("%d",&a)

using namespace std;

vector<vector<int> > graph;
int par[3005],p=-1,q,D,hu;
bool is[3005];
stack<int> _p,_q;
int dis[3005];

void dfs(int from,int now)
{
    //cout<<from<<" "<<now<<endl;
    is[now]=true;
    par[now]=from;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        if(is[graph[now][i]]){
            if(p==-1){
                p=now;
                q=graph[now][i];
            }
            continue;
        }
        dfs(now,graph[now][i]);
    }
    return ;
}

void distance(int from,int now,int dist)
{
    if(dis[now]!=-1){
        D=dist+dis[now];
        hu=1;
        return ;
    }
    if(is[now]){
        hu=1;
        return ;
    }
    D++;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        distance(now,graph[now][i],dist+1);
        if(hu)
            return ;
    }
    return ;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int n,i;
    si(n);
    vector<int> t;
    for(i=0;i<n;i++)
        graph.push_back(t);
    for(i=0;i<n;i++){
        int x,y;
        si(x);
        si(y);
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for(i=0;i<n;i++)
        is[i]=false;
    dfs(-1,0);
    for(i=0;i<n;i++)
        is[i]=false;
    is[p]=true,is[q]=true;
    i=p;
    while(par[i]!=q){
        is[par[i]]=true;
        i=par[i];
    }
    for(i=0;i<n;i++)
        dis[i]=-1;
    for(i=0;i<n;i++){
        D=0;
        hu=0;
        distance(-1,i,0);
        dis[i]=D;
        printf("%d ",D);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#define si(a) scanf("%d",&a)

using namespace std;

vector<vector<int> > graph;
int par[3005],p=-1,q,D,hu;
bool is[3005];
stack<int> _p,_q;
int dis[3005];

void dfs(int from,int now)
{
    //cout<<from<<" "<<now<<endl;
    is[now]=true;
    par[now]=from;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        if(is[graph[now][i]]){
            if(p==-1){
                p=now;
                q=graph[now][i];
            }
            continue;
        }
        dfs(now,graph[now][i]);
    }
    return ;
}

void distance(int from,int now,int dist)
{
    if(dis[now]!=-1){
        D=dist+dis[now];
        hu=1;
        return ;
    }
    if(is[now]){
        hu=1;
        D=dist;
        return ;
    }
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        distance(now,graph[now][i],dist+1);
        if(hu)
            return ;
    }
    return ;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int n,i;
    si(n);
    vector<int> t;
    for(i=0;i<n;i++)
        graph.push_back(t);
    for(i=0;i<n;i++){
        int x,y;
        si(x);
        si(y);
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for(i=0;i<n;i++)
        is[i]=false;
    dfs(-1,0);
    for(i=0;i<n;i++)
        is[i]=false;
    is[p]=true,is[q]=true;
    i=p;
    while(par[i]!=q){
        is[par[i]]=true;
        i=par[i];
    }
    for(i=0;i<n;i++)
        dis[i]=-1;
    for(i=0;i<n;i++){
        D=0;
        hu=0;
        distance(-1,i,0);
        //dis[i]=D;
        printf("%d ",D);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#define si(a) scanf("%d",&a)

using namespace std;

vector<vector<int> > graph;
int par[3005],p=-1,q,D,hu;
bool is[3005];
stack<int> _p,_q;
int dis[3005];

void dfs(int from,int now)
{
    //cout<<from<<" "<<now<<endl;
    is[now]=true;
    par[now]=from;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        if(is[graph[now][i]]){
            if(p==-1){
                p=now;
                q=graph[now][i];
            }
            continue;
        }
        dfs(now,graph[now][i]);
    }
    return ;
}

void distance(int from,int now)
{
    if(dis[now]!=-1){
        D+=dis[now];
        hu=1;
        return ;
    }
    if(is[now]){
        hu=1;
        return ;
    }
    D++;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        distance(now,graph[now][i]);
        if(hu)
            return ;
    }
    return ;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int n,i;
    si(n);
    vector<int> t;
    for(i=0;i<n;i++)
        graph.push_back(t);
    for(i=0;i<n;i++){
        int x,y;
        si(x);
        si(y);
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for(i=0;i<n;i++)
        is[i]=false;
    dfs(-1,0);
    for(i=0;i<n;i++)
        is[i]=false;
    is[p]=true,is[q]=true;
    i=p;
    while(par[i]!=q){
        is[par[i]]=true;
        i=par[i];
    }
    for(i=0;i<n;i++)
        dis[i]=-1;
    for(i=0;i<n;i++){
        D=0;
        hu=0;
        distance(-1,i);
        dis[i]=D;
        printf("%d ",D);
    }
    printf("\n");
    return 0;
}