import java.io.*;
import java.util.*;
class Main{
+ "A \\5000 C \\4000 E \\7000"
+"\n"+"A \\90000 C \\6500 E \\8000"
+"\n"+"A \\7500 C \\5500 E \\4000"
+"\n"+"A \\6000 C \\3000 F \\2000"
+"\n"+"A \\3500 C \\9000 F \\6500"
+"\n"+"A \\4200 C \\4500 F \\3000"
+"\n"+"A \\3500 D \\8000 E \\3000"
+"\n"+"A \\40000 D \\9500 E \\4880"
+"\n"+"B \\3500 C \\8000 E \\4500"
+"\n"+"B \\4200 C \\9500 E \\5000"
;
class Sum{
public int v;
}
List<Sum> adr = new ArrayList<Sum>(); //住所階層
Sum sumAll = new Sum();
for(String ln
=br.
readLine(); ln
!=null; ln
=br.
readLine()){ String[] ar
= ln.
split(" "); //1行を空白で分割 for(int d=0; d*2+1<ar.length; d++){
String nm
= ar
[d
*2]; //エリア,県... int v
= Integer.
parseInt(ar
[d
*2+1].
replace("\\",
"")); //金額 if(d==0){
sumAll.v += v;//全エリア合計
}
Sum sum = d<adr.size() ? adr.get(d) : null;
if(sum==null){
sum = new Sum();
sum.nm = nm;
adr.add(sum);
}
//切り替わり判定
if(sum.nm.equals(nm)){
sum.v += v;
}
else{
for(int d2=adr.size()-1; d<=d2; d2--){
Sum sum2 = adr.get(d2);
String suf
= d2
==0?"エリア":d2
==1?"県":d2
==2?"地区":""; System.
out.
print(""+sum2.
nm+suf
+"合計:"+sum2.
v+" "); adr.remove(d2);
}
sum = new Sum();
sum.nm = nm;
sum.v = v;
adr.add(sum);
}
}
}
int d=0;
for(int d2=adr.size()-1; d<=d2; d2--){
Sum sum2 = adr.get(d2);
String suf
= d2
==0?"エリア":d2
==1?"県":d2
==2?"地区":""; System.
out.
print(""+sum2.
nm+suf
+"合計:"+sum2.
v+" "); adr.remove(d2);
}
System.
out.
println("エリア合計:"+sumAll.
v); }
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgTWFpbnsKICAgIHB1YmxpYyBzdGF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oKTsgbG4hPW51bGw7IGxuPWJyLnJlYWRMaW5lKCkpewogICAgICAgICAgICBTdHJpbmdbXSBhciA9IGxuLnNwbGl0KCIgIik7IC8vMeihjOOCkuepuueZveOBp+WIhuWJsgogICAgICAgICAgICBmb3IoaW50IGQ9MDsgZCoyKzE8YXIubGVuZ3RoOyBkKyspewogICAgICAgICAgICAgICAgU3RyaW5nIG5tID0gYXJbZCoyXTsgLy/jgqjjg6rjgqIs55yMLi4uCiAgICAgICAgICAgICAgICBpbnQgdiA9IEludGVnZXIucGFyc2VJbnQoYXJbZCoyKzFdLnJlcGxhY2UoIlxcIiwiIikpOyAvL+mHkemhjQogICAgICAgICAgICAgICAgaWYoZD09MCl7CiAgICAgICAgICAgICAgICAgICAgc3VtQWxsLnYgKz0gdjsvL+WFqOOCqOODquOCouWQiOioiAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgU3VtIHN1bSA9IGQ8YWRyLnNpemUoKSA/IGFkci5nZXQoZCkgOiBudWxsOwogICAgICAgICAgICAgICAgaWYoc3VtPT1udWxsKXsKICAgICAgICAgICAgICAgICAgICBzdW0gPSBuZXcgU3VtKCk7CiAgICAgICAgICAgICAgICAgICAgc3VtLm5tID0gbm07CiAgICAgICAgICAgICAgICAgICAgYWRyLmFkZChzdW0pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgLy/liIfjgormm7/jgo/jgorliKTlrpoKICAgICAgICAgICAgICAgIGlmKHN1bS5ubS5lcXVhbHMobm0pKXsKICAgICAgICAgICAgICAgICAgICBzdW0udiArPSB2OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgICAgICBmb3IoaW50IGQyPWFkci5zaXplKCktMTsgZDw9ZDI7IGQyLS0pewogICAgICAgICAgICAgICAgICAgICAgICBTdW0gc3VtMiA9IGFkci5nZXQoZDIpOwogICAgICAgICAgICAgICAgICAgICAgICBTdHJpbmcgc3VmID0gZDI9PTA/IuOCqOODquOCoiI6ZDI9PTE/IuecjCI6ZDI9PTI/IuWcsOWMuiI6IiI7CiAgICAgICAgICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoIiIrc3VtMi5ubStzdWYrIuWQiOioiDoiK3N1bTIudisiICIpOwogICAgICAgICAgICAgICAgICAgICAgICBhZHIucmVtb3ZlKGQyKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCk7CiAgICAgICAgICAgICAgICAgICAgc3VtID0gbmV3IFN1bSgpOwogICAgICAgICAgICAgICAgICAgIHN1bS5ubSA9IG5tOwogICAgICAgICAgICAgICAgICAgIHN1bS52ID0gdjsKICAgICAgICAgICAgICAgICAgICBhZHIuYWRkKHN1bSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgaW50IGQ9MDsKICAgICAgICBmb3IoaW50IGQyPWFkci5zaXplKCktMTsgZDw9ZDI7IGQyLS0pewogICAgICAgICAgICBTdW0gc3VtMiA9IGFkci5nZXQoZDIpOwogICAgICAgICAgICBTdHJpbmcgc3VmID0gZDI9PTA/IuOCqOODquOCoiI6ZDI9PTE/IuecjCI6ZDI9PTI/IuWcsOWMuiI6IiI7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoIiIrc3VtMi5ubStzdWYrIuWQiOioiDoiK3N1bTIudisiICIpOwogICAgICAgICAgICBhZHIucmVtb3ZlKGQyKTsKICAgICAgICB9CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCk7CiAgICAgICAgCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCLjgqjjg6rjgqLlkIjoqIg6IitzdW1BbGwudik7CiAgICB9Cn0=