static int countSpacesAtEnd(S s) { int n = l(s), i = n; while (i > 0 && s.charAt(i-1) == ' ') --i; ret n-i; }