<>;@A=glob<>;/R/and$A[-2]+=pop@A,unshift@A,0or$A[1]+=shift@A,push@A,0for<>=~/./g;print"@A"