Increase and Decrease
InterviewTime limit1sMemory limit1024 MB
Count the increase-then-decrease numbers in each inclusive range [a, b] for up to 100000 queries, with a and b at most 10^6.
- Level
Easy3 of 10
- Topics
- Prefix sum, Implementation
- Solved
- No attempts yet
x
Jeonghyeon, a student at Daegu Science High School, enjoys finding patterns in numbers. Lately he has become fascinated with increase-then-decrease numbers.
A positive integer is an increase-then-decrease number if its digits increase and then decrease when written in decimal without a leading zero. Formally, for a positive integer with , an integer, and , is an increase-then-decrease number if there exists some such that . For example, is an increase-then-decrease number because .
Given two positive integers and , count the increase-then-decrease numbers between and , inclusive.
Input
The first line contains the number of test cases .
Each of the next lines contains two positive integers and , separated by a space.
Output
For each test case, print the number of increase-then-decrease numbers between and , inclusive, on its own line.