#![allow(unused_imports)] fn main() { input! { mut n: Bytes, } for c in &mut n { *c -= b'0'; } if let Some((mut i, _)) = n.iter().find_position(|&&c| c < 4) { for c in n.iter_mut().skip(i) { *c = 9; } if i == 0 { n.remove(0); } while i > 0 { n[i-1] -= 1; n[i] = 9; if n[i-1] >= 4 { break; } i -= 1; } } if n[0] < 4 { n.remove(0); } let mut ans = vec![]; for c in n { ans.push((if c <= 4 { 4 } else { 5 } + b'0') as char); } println!("{}", ans.iter().join("")); } /* a */ use itertools::{Itertools as _, iproduct, izip}; use proconio::{input, marker::*}; use std::{cell::RefCell, cmp::Reverse, collections::*, thread::LocalKey}; #[macro_export] macro_rules! chmax { ($a:expr, $b:expr) => {{ let tmp = $b; if $a < tmp { $a = tmp; true } else { false } }}; } #[macro_export] macro_rules! chmin { ($a:expr, $b:expr) => {{ let tmp = $b; if $a > tmp { $a = tmp; true } else { false } }}; } #[macro_export] /// mvec![] macro_rules! mvec { ($val:expr; ()) => { $val }; ($val:expr; ($size:expr $(,$rest:expr)*)) => { vec![mvec![$val; ($($rest),*)]; $size] }; }