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("\\",
"")); //金額 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);
}
for(int d2=d-1; 0<=d2; d2--){
adr.get(d2).v += v;
}
}
}
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); }
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3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vcihTdHJpbmcgbG49YnIucmVhZExpbmUoKTsgbG4hPW51bGw7IGxuPWJyLnJlYWRMaW5lKCkpewogICAgICAgICAgICBTdHJpbmdbXSBhciA9IGxuLnNwbGl0KCIgIik7IC8vMeihjOOCkuepuueZveOBp+WIhuWJsgogICAgICAgICAgICBmb3IoaW50IGQ9MDsgZCoyKzE8YXIubGVuZ3RoOyBkKyspewogICAgICAgICAgICAgICAgU3RyaW5nIG5tID0gYXJbZCoyXTsgLy/jgqjjg6rjgqIs55yMLi4uCiAgICAgICAgICAgICAgICBpbnQgdiA9IEludGVnZXIucGFyc2VJbnQoYXJbZCoyKzFdLnJlcGxhY2UoIlxcIiwiIikpOyAvL+mHkemhjQogICAgICAgICAgICAgICAgc3VtQWxsLnYgKz0gdjsvL+WFqOOCqOODquOCouWQiOioiAogICAgICAgICAgICAgICAgU3VtIHN1bSA9IGQ8YWRyLnNpemUoKSA/IGFkci5nZXQoZCkgOiBudWxsOwogICAgICAgICAgICAgICAgaWYoc3VtPT1udWxsKXsKICAgICAgICAgICAgICAgICAgICBzdW0gPSBuZXcgU3VtKCk7CiAgICAgICAgICAgICAgICAgICAgc3VtLm5tID0gbm07CiAgICAgICAgICAgICAgICAgICAgYWRyLmFkZChzdW0pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgLy/liIfjgormm7/jgo/jgorliKTlrpoKICAgICAgICAgICAgICAgIGlmKHN1bS5ubS5lcXVhbHMobm0pKXsKICAgICAgICAgICAgICAgICAgICBzdW0udiArPSB2OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgICAgICBmb3IoaW50IGQyPWFkci5zaXplKCktMTsgZDw9ZDI7IGQyLS0pewogICAgICAgICAgICAgICAgICAgICAgICBTdW0gc3VtMiA9IGFkci5nZXQoZDIpOwogICAgICAgICAgICAgICAgICAgICAgICBTdHJpbmcgc3VmID0gZDI9PTA/IuOCqOODquOCoiI6ZDI9PTE/IuecjCI6ZDI9PTI/IuWcsOWMuiI6IiI7CiAgICAgICAgICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoIiIrc3VtMi5ubStzdWYrIuWQiOioiDoiK3N1bTIudisiICIpOwogICAgICAgICAgICAgICAgICAgICAgICBhZHIucmVtb3ZlKGQyKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCk7CiAgICAgICAgICAgICAgICAgICAgc3VtID0gbmV3IFN1bSgpOwogICAgICAgICAgICAgICAgICAgIHN1bS5ubSA9IG5tOwogICAgICAgICAgICAgICAgICAgIHN1bS52ID0gdjsKICAgICAgICAgICAgICAgICAgICBhZHIuYWRkKHN1bSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmb3IoaW50IGQyPWQtMTsgMDw9ZDI7IGQyLS0pewogICAgICAgICAgICAgICAgICAgIGFkci5nZXQoZDIpLnYgKz0gdjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICBpbnQgZD0wOwogICAgICAgIGZvcihpbnQgZDI9YWRyLnNpemUoKS0xOyBkPD1kMjsgZDItLSl7CiAgICAgICAgICAgIFN1bSBzdW0yID0gYWRyLmdldChkMik7CiAgICAgICAgICAgIFN0cmluZyBzdWYgPSBkMj09MD8i44Ko44Oq44KiIjpkMj09MT8i55yMIjpkMj09Mj8i5Zyw5Yy6IjoiIjsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludCgiIitzdW0yLm5tK3N1Zisi5ZCI6KiIOiIrc3VtMi52KyIgIik7CiAgICAgICAgICAgIGFkci5yZW1vdmUoZDIpOwogICAgICAgIH0KICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oKTsKICAgICAgICAKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIuOCqOODquOCouWQiOioiDoiK3N1bUFsbC52KTsKICAgIH0KfQ==