Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi kategória, 2025. december 7.

December 7, 2025, 10:30 AM – December 7, 2025, 3:30 PM

digits-1

We call two (positive) numbers friends if the sum of their digits is equal. For example, the following numbers are all friends with each other:
3,12,21,30,102,111,120,201,210
Considering, for instance, 111: among numbers smaller than it, its closest friend is 102; among numbers larger than it, the closest friend is 120. We want to determine these closest friends for various numbers. That is: given XX, find the largest possible LL and smallest possible RR such that 0<L<X<R0 < L < X < R, and both LL and RR have the same digit sum as XX.

Input specification

The first line contains a single integer TT: the number of test cases. Then TT lines follow, each containing a number XX.

Output specification

Output TT lines, each containing the requested LL and RR numbers. If for a given XX there is no LL or RR, output 1−1 in the corresponding position.

Constraints

1T1001\le T \le 100
1X1_000_000_000_000_0001\le X \le 1\_000\_000\_000\_000\_000

Sample input 1

  1. 5
  2. 10
  3. 2
  4. 738374
  5. 123123123
  6. 11000
download as text file

Sample output 1

  1. 1 100
  2. -1 11
  3. 738365 738383
  4. 123123114 123123132
  5. 10100 20000
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024