RAONE - Ra-One Numbers

In the War between good and evil . Ra-One is on the evil side and G-One on the good side.

Ra-One is fond of destroying cities and its G-one's duty to protect them..


Ra-One loves to destroy cities whose Zip Code has special properties. He says he loves to destroy cities which have Ra-One numbers as their ZIp Code.

Any number is Ra-one if the Difference between Sum of digits at even location and Sum of digits at odd location is One (1).. For eg... for 234563 is Ra-One number

digits at odd location are 3,5,3 (unit place is location 1 )

digits at even location are 2,4,6

Diff = (2+4+6)-(3+5+3)=12-11 = 1.

And 123456 is not Ra-One number

diff = (5+3+1) - (2+4+6) = -4


G-One knows this about Ra-one and wants to deploy his Army members in those cities. 1 army member will be deployed in each city.

G-one knows the range of ZIP-Codes where Ra-One might attack & needs your help to find out how many army members he needs.

Can you help Him ?


first line will have only one integer 't' number of Zip-Code ranges. it is followed by t lines

each line from 2nd line cotains 2 integer 'from'  and 'to'. these indicate the range of Zip codes where Ra-one might attack .(from and to are included in the range)


A single number for each test case telling how many army members G-One needs to deploy.

each number should be on separate lines


1 10
10 100

for 1st test case the only number is 10
for 2nd test case numbers are 10,21,32,43,54,65,76,87,98

t will be less than 100
from and to will be between 0 and 10^8 inclusive

hide comments
jpgmoreira: 2020-07-25 01:56:05

Indexing starting from 1, from right to left.

horro: 2020-06-29 20:29:15

Indexing from right to left, don't use long long (getting tle) !! Nice digit dp problem

Shubham Jadhav: 2020-06-28 17:34:26

Nice Problem

hrithik_sh10: 2020-06-03 20:26:01

ac in two go

Last edit: 2020-06-03 20:26:32
zxcv_1: 2020-03-18 16:47:09

Worst problem statement . Why didnt they mention order of indexing ?

abhimanyu_1998: 2019-12-14 21:02:02


scolar_fuad: 2019-11-22 19:51:04

My 2nd digit dp problem
great one to learn digit dp
happy coding

Manish Kumar Prajapati: 2019-10-09 19:31:27

(5+3+1) - (2+4+6) = -3 .

bhagirathi08: 2019-09-08 11:13:11

3rd digit dp problem AC in one go

cichipi_: 2018-12-10 12:07:57

Stupid problem statement...
10 is Ra-one but 100 is not.....why?
cz , they start index counting in reverse order... ,so for 100, 1 is in 3rd position

Added by:Devil D
Time limit:0.101s
Source limit:30000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64