# Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) B. Order Book

```public void solve(int testNumber, InputReader in, OutputWriter out) {
int cb = 0;
int cs = 0;
Map<Integer, Integer> BMap = new TreeMap<Integer, Integer>(Collections.reverseOrder());
Map<Integer, Integer> SMap = new TreeMap<Integer, Integer>();
for (int i = 0; i < n; i++) {
String t = in.next();
if (t.equals("B")) {
Integer d = Integer.valueOf(in.next());
Integer p = Integer.valueOf(in.next());
if (BMap.containsKey(d))
BMap.put(d, BMap.get(d) + p);
else
BMap.put(d,p);
cb++;
}
else{
Integer d = Integer.valueOf(in.next());
Integer p = Integer.valueOf(in.next());
if (SMap.containsKey(d))
SMap.put(d, SMap.get(d) + p);
else
SMap.put(d,p);
cs++;
}
}
Stream<Map.Entry<Integer, Integer>> stream_s = SMap.entrySet().stream().limit(s).sorted(Map.Entry.comparingByKey(Collections.reverseOrder()));

Stream<Map.Entry<Integer, Integer>> stream_b = BMap.entrySet().stream().limit(s);

stream_s.forEach(ss -> out.printLine("S " + ss.getKey() + " " + ss.getValue()));
stream_b.forEach(ss -> out.printLine("B " + ss.getKey() + " " + ss.getValue()));

}```