import java.io.IOException; import java.lang.String; class exchange { public static void main(String [] args) throws IOException { exchange app = new exchange(); app.run(); } public void run() throws IOException{ Input input = new Input(); int pocet = input.readInt(); String jmeno; String x; double cena; while(true){ String nazev = input.readString(); if(pocet == 0 && nazev.contains("END")) break; St [] poradi = new St[pocet]; Stock [] buy = new Stock[pocet]; Stock [] sell = new Stock[pocet]; int b = 0; int s = 0; for(int i = 0 ; i < pocet ; i++) { jmeno = input.readString(); x = input.readString(); cena = input.readDouble(); poradi[i] = new St(i, x, jmeno, cena); if(x.contains("s")) sell[s++] = new Stock(s, cena, jmeno); else buy[b++] = new Stock(b, cena, jmeno); } if(s > 0 && b > 0) { QuickSort.quicksort(sell, s); QuickSort.quicksort(buy, b); /*System.out.print(nazev+"\n"); for(int i = 0 ; i < pocet ; i++) { if(poradi[i].getX()) { int j = b-1; Stock []xxx = new Stock[b]; int count = 0; while(buy[j].getCena() >= poradi[i].getCena()) { xxx[count++] = buy[j]; if(--j < 0) break; } QuickSort.quicksort1(xxx, count); if(j == b-1) System.out.print(poradi[i].getName() + ": " + "NO-ONE" + "\n"); else { System.out.print(poradi[i].getName() + ": "); for(int k = 0 ; ((k < xxx.length ) && (xxx[k] != null)); k++) { System.out.print(xxx[k].getName() + " "); } System.out.print("\n"); } } else { int j = 0; Stock []xxx = new Stock[s]; int count = 0; while(sell[j].getCena() <= poradi[i].getCena()) { xxx[count++] = sell[j]; if(++j == s) break; } QuickSort.quicksort1(xxx, count); if(j == 0) System.out.print(poradi[i].getName() + ": " + "NO-ONE" + "\n"); else { System.out.print(poradi[i].getName() + ": "); for(int k = 0 ; ((k < xxx.length ) && (xxx[k] != null)); k++) { System.out.print(xxx[k].getName() + " "); } System.out.print("\n"); } } }*/ }else { System.out.print(nazev + "\n"); if(s > 0) { for(int a = 0 ; a < s ; a++) System.out.print(sell[a].getName() + ": NO-ONE\n"); } if(b > 0) { for(int a = 0 ; a < b ; a++) System.out.print(buy[a].getName() + ": NO-ONE\n"); } } pocet = input.readInt(); } } } class Input{ int c; public Input() throws IOException{ c = System.in.read(); } public int readInt() throws IOException{ skipWS(); int s = 0; while('0' <= c && c <='9') { s = 10 * s + (c - '0'); c = System.in.read(); } return s; } public double readDouble() throws IOException { skipWS(); double s = 0; while ('0' <= c && c <='9') { s = 10 * s + (c - '0'); c = System.in.read(); } c = System.in.read(); double i = 1; while ('0' <= c && c <= '9') { i = i/10; s = s + (double) (c - '0') * i; c = System.in.read(); } return s; } public String readString() throws IOException { skipWS(); char data[] = new char[21]; int j = 0; while (('a' <= c && c <='z') || ('A' <= c && c <='Z')) { data[j] = (char)c; j++; c = System.in.read(); if(j > 20) break; } String str = new String(data); return str; } public void skipWS() throws IOException{ while(c == ' ' || c == '\n' || c == '\r') { c = System.in.read(); } } } class QuickSort { public static void quicksort(Stock[] a, int pocet) { quicksort(a, 0, pocet-1); } public static void quicksort1(Stock[] a, int pocet) { quicksort1(a, 0, pocet-1); } public static void quicksort(Stock[] a, int left, int right) { if (right <= left) { return; } int i = partion(a, left, right); quicksort(a, left, i - 1); quicksort(a, i + 1, right); } public static void quicksort1(Stock[] a, int left, int right) { if (right <= left) { return; } int i = partion1(a, left, right); quicksort1(a, left, i - 1); quicksort1(a, i + 1, right); } private static int partion(Stock[] a, int left, int right) { int i = left - 1; int j = right; while (true) { while (a[++i].getCena() < a[right].getCena()); while (a[right].getCena() < a[--j].getCena()) { if (j == left) { break; } } if (i >= j) { break; } exch(a, i, j); } exch(a, i, right); return i; } private static void exch(Stock[] a, int i, int j) { Stock swap = a[i]; a[i] = a[j]; a[j] = swap; } private static int partion1(Stock[] a, int left, int right) { int i = left - 1; int j = right; while (true) { while (a[++i].getPoradi() < a[right].getPoradi()); while (a[right].getPoradi() < a[--j].getPoradi()) { if (j == left) { break; } } if (i >= j) { break; } exch1(a, i, j); } exch1(a, i, right); return i; } private static void exch1(Stock[] a, int i, int j) { Stock swap = a[i]; a[i] = a[j]; a[j] = swap; } } class Stock { private int poradi; private double cena; private String jmeno; public Stock(int poradi, double cena, String jmeno) { this.poradi = poradi; this.cena = cena; this.jmeno = jmeno; } public int getPoradi() { return this.poradi; } public double getCena() { return this.cena; } public String getName() { return this.jmeno; } } class St { private int poradi; private boolean x; private double cena; private String jmeno; public St(int poradi, String x, String jmeno, double cena) { this.poradi = poradi; this.cena = cena; if(x.contains("s")) this.x = true; else this.x = false; this.jmeno = jmeno; } public int getPoradi() { return this.poradi; } public boolean getX() { return this.x; } public String getName() { return this.jmeno; } public double getCena() { return this.cena; } }