4. $(5-7,8)$ The phone PIN code consists of 4 digits (and can start with zero, for example, 0951). Petya calls "lucky" those PIN codes where the sum of the outer digits equals the sum of the middle digits, for example $1357: 1+7=3+5$. In his phone, he uses only "lucky" PIN codes. Petya says that even if he forgets one digit (but remembers its position), he can easily restore it. And if he forgets two digits (but remembers their positions), he will have to try only a small number of PIN codes.

a) How many PIN codes will Petya have to try in the worst case?

b) How many "lucky" PIN codes exist in total?
Answer: a) $10 ;$ b) 670 .

Solution: a) Obviously, in the worst case, Petya tries all possible values for one digit and reconstructs the PIN code from them. Thus, no more than 10 combinations need to be tried. Using the example of the PIN code 0099, we can see that if you forget the two middle digits, you need to try exactly 10 combinations. b) The sum of a pair of digits can take values from 0 to 18. It is easy to notice that the sum equal to 0 can be obtained in only one way, equal to 1 in two ways, ..., equal to 10 in 11 ways, ..., equal to 18 in one way. In total, the number of lucky PIN codes is $N=1^{2}+2^{2}+\ldots+10^{2}+11^{2}+10^{2}+\ldots+1^{2}=670$.