Progress in Artillery
Artillery has long been a military branch where counting devices are heavily utilized. Initially, these devices were mechanical, using wheels with numbers to display calculations. However, technology advanced, and eventually, designers created an electronic device that used segment indicators to show results.
While the device was praised for its speed and accuracy, its display method raised concerns. A traditionalist general viewed it with suspicion, thinking that segment indicators were unreliable. If a necessary segment failed to light up, or an unnecessary one did, the result could be misleading. If the error resulted in gibberish, the operator would notice. But if the result still appeared plausible, like a normal sequence of numbers, it could be problematic. For example, altering one digit could change 888 to 808. With two digits altered, 888 could become 800. Such errors could lead to catastrophic consequences, like mistakenly firing on friendly positions.
Your task is to create a program that, given a number, calculates the maximum deviation that can occur in its display due to a "one-segment error" in one or two digits.
Input
The input consists of a single line containing a non-negative integer N, which is checked for potential distortions, where 0 ≤ N ≤ 10^1000.
Output
The output should include two lines:
1. The first line should display a positive integer representing the maximum deviation from the true display with a one-segment error. 2. The second line should display a positive integer representing the maximum deviation with two one-segment errors occurring in different digits.
If a deviation is impossible in any of these cases, output the word NO instead of a number.
Consider only scenarios where the distorted result appears valid. The device is assumed not to display insignificant leading zeros, so distortions like changing 888 to 088 are not considered.