import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String s = scan.next(); scan.close(); if(s.length() < 3) { System.out.println(0); System.exit(0); } System.out.println(cww(s)); } static int cww(String s) { int l = s.length(); if(l < 3) { return 0; } int max = 0; String s1 = ""; String s2 = ""; for(int i = 0; i < l - 2; i++) { char c1 = s.charAt(i); if(c1 == 0) { continue; } for(int j = i + 1; j < l - 1; j++) { char c2 = s.charAt(j); if(c2 == c1) { continue; } for(int k = j + 1; k < l; k++) { char c3 = s.charAt(k); int p = 0; if(c2 == c3) { p += 100 * Character.getNumericValue(c1); p += 10 * Character.getNumericValue(c2); p += Character.getNumericValue(c3); s1 = String.valueOf(c1); s2 = String.valueOf(c2); StringBuilder sb = new StringBuilder(s); sb.deleteCharAt(sb.indexOf(s1)); sb.deleteCharAt(sb.indexOf(s2)); sb.deleteCharAt(sb.indexOf(s2)); max = Math.max(max, p + cww(sb.toString())); } } } } return max; } }