public class Now_65 { public static void main(String[] args)throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] strings = bf.readLine().split(" "); int left = Integer.parseInt(strings[0]); int right = Integer.parseInt(strings[1]); int res = 0; for(int num = left ; num<=right ; num++){ if(isMagic(num)){ res++; } } System.out.println(res); }
private static boolean isMagic(int num) { List<Integer> list = new LinkedList<>(); int sum = 0; while (num>0){ list.add(num%10); sum+=num%10; num/=10; } if(sum%2 != 0) return false; int mid = sum/2; int len = list.size(); boolean[] dp = new boolean[mid+1]; dp[0]=true; for(int i=0;i<len;i++){ for(int j=mid;j>=list.get(i);j--){ dp[j]=dp[j-list.get(i)] || dp[j]; } } return dp[mid]; } }