// Path: geo-locator/src/edu/cmu/geolocator/common/CollectionSorting.java
// public class CollectionSorting {
// 
//   @SuppressWarnings({ "unchecked", "rawtypes" })
//   public static ArrayList<Entry<String, Float>> rankArray(ArrayList<Entry<String, Float>> as) {
//     // sort by frequency
//     Collections.sort(as, new Comparator() {
//       public int compare(Object o1, Object o2) {
//         Map.Entry e1 = (Map.Entry) o1;
//         Map.Entry e2 = (Map.Entry) o2;
//         Float first = (Float) e1.getValue();
//         Float second = (Float) e2.getValue();
//         return second.compareTo(first);
//       }
//     });
// 
//     return as;
//   }
// 
//   @SuppressWarnings({ "unchecked", "rawtypes" })
//   public static <T extends Comparable<T>> ArrayList<Entry<String, T>> rankIntArray(ArrayList<Entry<String, T>> as) {
//     // sort by frequency
//     Collections.sort(as, new Comparator() {
//       public int compare(Object o1, Object o2) {
//         Map.Entry e1 = (Map.Entry) o1;
//         Map.Entry e2 = (Map.Entry) o2;
//         T first = (T) e1.getValue();
//         T second = (T) e2.getValue();
//         return second.compareTo(first);
//       }
//     });
//     return as;
//   }
// 
//   public static LinkedHashMap sortHashMapByValuesD(HashMap passedMap) {
//     ArrayList mapKeys = new ArrayList(passedMap.keySet());
//     ArrayList mapValues = new ArrayList(passedMap.values());
//     Collections.sort(mapValues);
//     Collections.sort(mapKeys);
// 
//     LinkedHashMap sortedMap = new LinkedHashMap();
// 
//     Iterator valueIt = mapValues.iterator();
//     while (valueIt.hasNext()) {
//       Object val = valueIt.next();
//       Iterator keyIt = mapKeys.iterator();
// 
//       while (keyIt.hasNext()) {
//         Object key = keyIt.next();
//         String comp1 = passedMap.get(key).toString();
//         String comp2 = val.toString();
// 
//         if (comp1.equals(comp2)) {
//           passedMap.remove(key);
//           mapKeys.remove(key);
//           sortedMap.put((String) key, val);
//           break;
//         }
// 
//       }
// 
//     }
//     return sortedMap;
//   }
// }
// 
// Path: geo-locator/src/edu/cmu/geolocator/io/GetReader.java
// public class GetReader {
// 
//   public static BufferedReader getUTF8FileReader(String filename) throws FileNotFoundException,
//           UnsupportedEncodingException {
//     File file = new File(filename);
//     BufferedReader bin = new BufferedReader(new InputStreamReader(new FileInputStream(file),
//             "utf-8"));
//     return bin;
//   }
// 
//   public static IndexSearcher getIndexSearcherFromWriter(String filename) throws IOException {
//     IndexWriter iw = GetWriter.getIndexWriter(filename, 1024);
//     IndexReader ir = IndexReader.open(iw, false);
//     IndexSearcher searcher = new IndexSearcher(ir);
//     return searcher;
//   }
// 
//   public static IndexSearcher getIndexSearcher(String filename, String diskOrMem) throws Exception {
//     IndexReader reader;
//     Directory d ;
//     if (diskOrMem.equals("disk"))
//       d = FSDirectory.open(new File(filename));
//     else if (diskOrMem.equals("mmap"))
//       d=  MmapDirectory(new File(filename));
//     else
//       throw new Exception("parameter for directory type not defined.");
//     
//     if(OSUtil.isWindows())
//      reader = IndexReader.open(FSDirectory.open(new File(filename)));
//     else
//       reader = IndexReader.open(NIOFSDirectory.open(new File(filename))); 
//     IndexSearcher searcher = new IndexSearcher(reader);
//     return searcher;
//   }
// 
//   private static Directory MmapDirectory(File file) {
//     // TODO Auto-generated method stub
//     return null;
//   }
// 
//   public static BufferedReader getCommandLineReader() throws UnsupportedEncodingException {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "utf-8"));
//     return br;
//   }
// 
// }


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Scanner;
import java.util.Map.Entry;
import edu.cmu.geolocator.common.CollectionSorting;
import edu.cmu.geolocator.io.GetReader;
    s.useDelimiter("\t");
    int count = 0;
    int total = 0;
    while (s.hasNext()) {
      total++;
      if (total % 18000000 == 0)
        System.out.println(total / 18);
      temp = s.next();
      if (count == 1) {
        // System.out.println(asciiStr);
        asciiStr = temp.toLowerCase();
      }
      if (count == 14) { 
        // This is for storing the balanced or population prefered.
        if (true)
          if (locations.containsKey(asciiStr))
            locations.put(asciiStr, locations.get(asciiStr) + Long.parseLong(temp));
          else
            locations.put(asciiStr, Long.parseLong(temp));
        //This is for storing the ambiguity prefered locations.
        if(false)
        if (locations.containsKey(asciiStr))
          locations.put(asciiStr, locations.get(asciiStr)+1);
        else
          locations.put(asciiStr, 1L);
      }
      count = count % 18;
      count++;
    }
    ArrayList<Entry<String, Long>> as = new ArrayList<Entry<String, Long>>(locations.entrySet());
// Path: geo-locator/src/edu/cmu/geolocator/common/CollectionSorting.java
// public class CollectionSorting {
// 
//   @SuppressWarnings({ "unchecked", "rawtypes" })
//   public static ArrayList<Entry<String, Float>> rankArray(ArrayList<Entry<String, Float>> as) {
//     // sort by frequency
//     Collections.sort(as, new Comparator() {
//       public int compare(Object o1, Object o2) {
//         Map.Entry e1 = (Map.Entry) o1;
//         Map.Entry e2 = (Map.Entry) o2;
//         Float first = (Float) e1.getValue();
//         Float second = (Float) e2.getValue();
//         return second.compareTo(first);
//       }
//     });
// 
//     return as;
//   }
// 
//   @SuppressWarnings({ "unchecked", "rawtypes" })
//   public static <T extends Comparable<T>> ArrayList<Entry<String, T>> rankIntArray(ArrayList<Entry<String, T>> as) {
//     // sort by frequency
//     Collections.sort(as, new Comparator() {
//       public int compare(Object o1, Object o2) {
//         Map.Entry e1 = (Map.Entry) o1;
//         Map.Entry e2 = (Map.Entry) o2;
//         T first = (T) e1.getValue();
//         T second = (T) e2.getValue();
//         return second.compareTo(first);
//       }
//     });
//     return as;
//   }
// 
//   public static LinkedHashMap sortHashMapByValuesD(HashMap passedMap) {
//     ArrayList mapKeys = new ArrayList(passedMap.keySet());
//     ArrayList mapValues = new ArrayList(passedMap.values());
//     Collections.sort(mapValues);
//     Collections.sort(mapKeys);
// 
//     LinkedHashMap sortedMap = new LinkedHashMap();
// 
//     Iterator valueIt = mapValues.iterator();
//     while (valueIt.hasNext()) {
//       Object val = valueIt.next();
//       Iterator keyIt = mapKeys.iterator();
// 
//       while (keyIt.hasNext()) {
//         Object key = keyIt.next();
//         String comp1 = passedMap.get(key).toString();
//         String comp2 = val.toString();
// 
//         if (comp1.equals(comp2)) {
//           passedMap.remove(key);
//           mapKeys.remove(key);
//           sortedMap.put((String) key, val);
//           break;
//         }
// 
//       }
// 
//     }
//     return sortedMap;
//   }
// }
// 
// Path: geo-locator/src/edu/cmu/geolocator/io/GetReader.java
// public class GetReader {
// 
//   public static BufferedReader getUTF8FileReader(String filename) throws FileNotFoundException,
//           UnsupportedEncodingException {
//     File file = new File(filename);
//     BufferedReader bin = new BufferedReader(new InputStreamReader(new FileInputStream(file),
//             "utf-8"));
//     return bin;
//   }
// 
//   public static IndexSearcher getIndexSearcherFromWriter(String filename) throws IOException {
//     IndexWriter iw = GetWriter.getIndexWriter(filename, 1024);
//     IndexReader ir = IndexReader.open(iw, false);
//     IndexSearcher searcher = new IndexSearcher(ir);
//     return searcher;
//   }
// 
//   public static IndexSearcher getIndexSearcher(String filename, String diskOrMem) throws Exception {
//     IndexReader reader;
//     Directory d ;
//     if (diskOrMem.equals("disk"))
//       d = FSDirectory.open(new File(filename));
//     else if (diskOrMem.equals("mmap"))
//       d=  MmapDirectory(new File(filename));
//     else
//       throw new Exception("parameter for directory type not defined.");
//     
//     if(OSUtil.isWindows())
//      reader = IndexReader.open(FSDirectory.open(new File(filename)));
//     else
//       reader = IndexReader.open(NIOFSDirectory.open(new File(filename))); 
//     IndexSearcher searcher = new IndexSearcher(reader);
//     return searcher;
//   }
// 
//   private static Directory MmapDirectory(File file) {
//     // TODO Auto-generated method stub
//     return null;
//   }
// 
//   public static BufferedReader getCommandLineReader() throws UnsupportedEncodingException {
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "utf-8"));
//     return br;
//   }
// 
// }


// Path: geo-locator/src/edu/cmu/geolocator/resource/gazindexing/GazStringStat.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Scanner;
import java.util.Map.Entry;
import edu.cmu.geolocator.common.CollectionSorting;
import edu.cmu.geolocator.io.GetReader;

    s.useDelimiter("\t");
    int count = 0;
    int total = 0;
    while (s.hasNext()) {
      total++;
      if (total % 18000000 == 0)
        System.out.println(total / 18);
      temp = s.next();
      if (count == 1) {
        // System.out.println(asciiStr);
        asciiStr = temp.toLowerCase();
      }
      if (count == 14) { 
        // This is for storing the balanced or population prefered.
        if (true)
          if (locations.containsKey(asciiStr))
            locations.put(asciiStr, locations.get(asciiStr) + Long.parseLong(temp));
          else
            locations.put(asciiStr, Long.parseLong(temp));
        //This is for storing the ambiguity prefered locations.
        if(false)
        if (locations.containsKey(asciiStr))
          locations.put(asciiStr, locations.get(asciiStr)+1);
        else
          locations.put(asciiStr, 1L);
      }
      count = count % 18;
      count++;
    }
    ArrayList<Entry<String, Long>> as = new ArrayList<Entry<String, Long>>(locations.entrySet());
    ArrayList<Entry<String, Long>> sortedLocations = CollectionSorting.rankIntArray(as);