// Arup Guha
// 7/11/2012
// Example that uses arrays to calculate the average temperature for a city in each year.

import java.io.*;
import java.util.*;

// Stores a single weather point: A year and average temperature.
class weatherpoint implements Comparable<weatherpoint> {
	
	private int year;
	private double temp;
	
	public weatherpoint(int myyear, double mytemp) {
		year = myyear;
		temp = mytemp;
	}
	
	// Here is how we compare two temperatures.
	public int compareTo(weatherpoint other) {
		
		if (this.temp < other.temp - 1e-10)
			return -1;
		else if (this.temp > other.temp + 1e-10)
			return 1;
		return 0;
	}
	
	public String toString() {
		return year+"\t"+temp;
	}
}

public class weather2 {
	
	public final static int START_YEAR = 1995;
	public final static int CUR_YEAR = 2012;
	
	public static void main(String[] args) throws Exception {
		
		Scanner stdin = new Scanner(System.in);
		
		// Get the input file.
		System.out.println("Please enter a weather file.");
		String file = stdin.next();
		
		Scanner fin = new Scanner(new File(file));
		
		// Set up our arrays.
		double[] sumTemp = new double[CUR_YEAR - START_YEAR + 1];
		int[] numDays = new int[CUR_YEAR - START_YEAR + 1];
		
		// Read all tokens in the file.
		while (fin.hasNext()) {
			
			// Read in this day's data.
			int mon = fin.nextInt();
			int day = fin.nextInt();
			int year = fin.nextInt();
			double temp = fin.nextDouble();
			
			// Just in case the double gets stored inaccurately.
			if (Math.abs(temp+99) > 1e-10) {
				sumTemp[year - START_YEAR] += temp;
				numDays[year - START_YEAR]++;
			}
		}
		
		weatherpoint[] avg = new weatherpoint[CUR_YEAR - START_YEAR + 1];
		
		// Will crash if one year has all invalid readings.
		for (int i=0; i<sumTemp.length; i++) {
			
			// Create a weather point object for each year.
			avg[i] = new weatherpoint(i+START_YEAR, sumTemp[i]/numDays[i]);
			System.out.println(avg[i]);
		}
		System.out.println();
		
		// Sort and print - coldest to hottest years.
		Arrays.sort(avg);
		
		for (int i=0; i<avg.length; i++)
			System.out.println(avg[i]);
		
		fin.close();
	}
}