#K33562. Balanced Number Checker
Balanced Number Checker
Balanced Number Checker
A positive integer N is considered balanced if the sum of the digits in its first half equals the sum of the digits in its last half. If N has an odd number of digits, the middle digit is ignored. Formally, if n is the number of digits in N and we denote the digits by \(d_1, d_2, \ldots, d_n\), then for an even-length number, the number is balanced if
\[ \sum_{i=1}^{n/2} d_i = \sum_{i=n/2+1}^{n} d_i \]
and for an odd-length number, if
\[ \sum_{i=1}^{\lfloor n/2 \rfloor} d_i = \sum_{i=\lfloor n/2 \rfloor+2}^{n} d_i \]
For example, for N = 12321, the sum of the first half digits (1 + 2) equals the sum of the last half digits (2 + 1), so the number is balanced.
inputFormat
The input consists of a single line containing a positive integer N.
Example: 12321
outputFormat
Output a single line containing True
if the number is balanced, and False
otherwise.
5
True
</p>