#B4058. Triangle Contained Number

    ID: 11715 Type: Default 1000ms 256MiB

Triangle Contained Number

Triangle Contained Number

Given a six-digit number \(x\) (i.e. \(100000 \le x \le 999999\)), we define \(x\) as a triangle contained number if and only if it satisfies the following conditions:

  • Each of its six decimal digits is nonzero.
  • If we denote its digits by \(a, b, c, d, e, f\), there exists a partition of these digits into two groups of three such that the three numbers in each group can serve as the lengths of the sides of a triangle. In other words, for each group \(\{p, q, r\}\), the triangle inequality must hold, i.e., \(p+q>r\), \(p+r>q\), and \(q+r>p\).

Given two integers \(l\) and \(r\) (with \(100000 \le l \le r \le 999999\)), your task is to count how many triangle contained numbers exist in the interval \([l, r]\).

inputFormat

The input consists of two integers \(l\) and \(r\) separated by a space.

\(100000 \le l \le r \le 999999\)

outputFormat

Output a single integer representing the count of triangle contained numbers in the interval \([l, r]\).

sample

100000 100000
0