import java.io.*; public class encoding { int pos; String s; public static void main(String[] args) throws Exception { // StreamTokenizer st = new StreamTokenizer(new FileReader(new File("encoding.in"))); BufferedReader br = new BufferedReader(new FileReader(new File("encoding.in"))); String line = ""; encoding coder = new encoding(); while((line=br.readLine())!=null) { System.out.println(coder.encode(line)); } } encoding() { pos=0; s=""; } public String encode(String s) { if(s.equals("")) return ""; String output = ""; this.s=s; this.pos=0; while(pos < s.length()) { output += getNextToken(); } return output; } public String getNextToken() { if(pos >= s.length()) return ""; if(getSeqLength() > 1) { char c = s.charAt(pos); int l = getSeqLength(); pos += l; return "" + l + "" + c; } else if(getSeqLength() == 1) { String out = "1"; while(getSeqLength() == 1) { if(s.charAt(pos) != '1') { out += s.charAt(pos); } else { out += "11"; } pos++; } out+="1"; return out; } else { return ""; } } public int getSeqLength() { if(pos >= s.length()) return 0; if(pos == s.length()-1) return 1; return 1 + getSeqLength(s.charAt(pos), pos+1); } public int getSeqLength(char c, int p) { if(p>=s.length()) return 0; if(s.charAt(p) != c) { return 0; } else { if(getSeqLength(c, p+1) >= 7) return 8; return 1 + getSeqLength(c, p+1); } } }