Recently Vasya found a golden ticket — a sequence which consists of $$$n$$$ digits $$$a_1a_2\dots a_n$$$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $$$350178$$$ is lucky since it can be divided into three segments $$$350$$$, $$$17$$$ and $$$8$$$: $$$3+5+0=1+7=8$$$. Note that each digit of sequence should belong to exactly one segment.Help Vasya! Tell him if the golden ticket he found is lucky or not.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of digits in the ticket. The second line contains $$$n$$$ digits $$$a_1 a_2 \dots a_n$$$ ($$$0 \le a_i \le 9$$$) — the golden ticket. Digits are printed without spaces.

If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).

NoteIn the first example the ticket can be divided into $$$7$$$, $$$34$$$ and $$$52$$$: $$$7=3+4=5+2$$$.In the second example it is impossible to divide ticket into segments with equal sum.

use std::io::{self, Read};
use std::collections::BTreeSet;

fn main() -> () {
    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();

    handle.read_to_string(&mut buffer).unwrap();

    let mut arr = buffer.split_whitespace().take(1).map(|x| x.parse::<i32>().unwrap() ).collect::<Vec<_>>();
    let n = arr[0] as usize;
    let mut num = buffer.split_whitespace().skip(1).take(1).next().unwrap();
    let mut b = vec![];
    for i in num.chars() {
        let digit = i as u32 - '0' as u32;
        b.push(digit);
    }
    let s : u32 = b.iter().sum();

    if s == 0 {
        println!("YES");
        return
    }

    'outer: for i in 1..s+1 {
        if s % i == 0 {
            let ss = s / i;
            let mut segsum = 0;
            let mut count_seg = 0;
            for j in 0..n {
                segsum += b[j];
                if segsum == ss {
                    segsum = 0;
                    count_seg += 1;
                } else if segsum > ss {
                    continue 'outer;
                }
            }
            if count_seg > 1 {
                println!("YES");
                return
            }
        }
    }

    println!("NO");
}

use std::io;

fn main() {
    let mut input_text = String::new();
    io::stdin()
        .read_line(&mut input_text)
        .expect("failed to read from stdin");

    let trimmed = input_text.trim();
    let mut no_of_digits: u32 = 0;
    match trimmed.parse::<u32>() {
        Ok(i) => no_of_digits = i,
        Err(..) => println!("this was not an integer: {}", trimmed),
    };

    let mut input_digits = String::new();
 	io::stdin()
        .read_line(&mut input_digits)
        .expect("failed to read from stdin");
    let digits = input_digits.trim();

   	let mut answer : bool = false;
   	let total_sum: u32 = digits.chars().map(|x| x.to_digit(10).unwrap()).sum();
    for i in 1..total_sum {
        let mut sum: u32 = 0;
    	for c in digits.chars() {
			let current_digit = c.to_digit(10).unwrap();
			sum += current_digit;
			if sum == i {
				sum = 0;
			}
    	}
    	if sum == 0 {
    		answer = true;
    	}
    }
    if answer || total_sum == 0 {
    	println!("YES");
    } else {
    	println!("NO");
    }
}

use std::io;

macro_rules! readln {
    () => {{
        use std::io;
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

fn can_be_splitted(slice : &[i32], sum : i32) -> bool {
    let mut curr_sum = 0;
    let mut index = 0;
    let mut at_least_one = false;
    loop {
        if index >= slice.len() {
            return at_least_one && curr_sum == 0;
        }

        curr_sum += slice[index];
        if curr_sum == sum {
            curr_sum = 0;
            at_least_one = true;
        } else if curr_sum > sum {
            return false;
        }
        index += 1;
    }

    true
}

fn solve(length : usize, digits : Vec<i32>) -> (bool, i32) {
    let mut curr_sum = 0;
    for index in 0..(length - 1) {
        curr_sum += digits[index];
        if can_be_splitted(&digits[(index + 1)..], curr_sum) {
            return (true, curr_sum);
        }
    }
    (false, 0)
}

fn main() {
    let length = readln!(usize);

    let digits = readln!();
    let digits : Vec<i32> = digits.chars().map(|ch| ch.to_digit(10).unwrap() as i32).collect();

    let (result, sum) = solve(length, digits);

    println!("{}", if result { "YES" } else { "NO" });
}

use std::io;
use std::slice::Iter;
use std::iter::Peekable;

fn check_step(iter : &mut Peekable<Iter<u64>>, check_sum : u64) -> Option<bool> {
    if iter.len() == 0 { return None }
    let mut sum = 0;
    while let Some(x) = iter.next() {
        sum += x;
        if sum == check_sum {
            while iter.peek().map(|x| **x == 0).unwrap_or(false) {
                iter.next();
            }
            return Some(true)
        }
    }
    Some(false)
}

fn check(iter : Iter<u64>, check_sum : u64) -> bool {
    if iter.len() == 0 { return false }
    let mut iter = iter.peekable();
    while let Some(flag) = check_step(&mut iter, check_sum) {
        if !flag {
            return false
        }
    }
    true
}

fn main() {
    let n = {
        let mut buffer = String::new();
        io::stdin().read_line(&mut buffer).unwrap();
        buffer.trim().parse().unwrap()
    };
    let nums : Vec<u64> = {
        let mut buffer = String::with_capacity(n);
        let mut char_str = String::from("0");
        io::stdin().read_line(&mut buffer).unwrap();
        buffer
        .trim()
        .chars()
        .map(|x| {
            char_str.pop();
            char_str.push(x);
            char_str.trim().parse().unwrap()
        })
        .collect()
    };
    let mut iter = nums.iter();
    let mut sum = 0;
    let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);
    while let Some(x) = iter.next() {
        sum_rest -= x;
        sum += x;
        if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {
            if check(iter.clone(), sum) {
                println!("YES");
                return
            }
        }
    }
    println!("NO");
}

use std::io::{self, Read};
use std::collections::BTreeSet;

fn main() -> () {
    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();

    handle.read_to_string(&mut buffer).unwrap();

    let mut arr = buffer.split_whitespace().take(1).map(|x| x.parse::<i32>().unwrap() ).collect::<Vec<_>>();
    let n = arr[0] as usize;
    let mut num = buffer.split_whitespace().skip(1).take(1).next().unwrap();
    let mut b = vec![];
    for i in num.chars() {
        let digit = i as u32 - '0' as u32;
        b.push(digit);
    }
    let s : u32 = b.iter().sum();

    'outer: for i in 1..s+1 {
        if s % i == 0 {
            let ss = s / i;
            let mut segsum = 0;
            let mut count_seg = 0;
            for j in 0..n {
                segsum += b[j];
                if segsum == ss {
                    segsum = 0;
                    count_seg += 1;
                } else if segsum > ss {
                    continue 'outer;
                }
            }
            if count_seg > 1 {
                println!("YES");
                return
            }
        }
    }

    println!("NO");
}

use std::io;

fn main() {
    let mut input_text = String::new();
    io::stdin()
        .read_line(&mut input_text)
        .expect("failed to read from stdin");

    let trimmed = input_text.trim();
    let mut no_of_digits: u32 = 0;
    match trimmed.parse::<u32>() {
        Ok(i) => no_of_digits = i,
        Err(..) => println!("this was not an integer: {}", trimmed),
    };

    let mut input_digits = String::new();
 	io::stdin()
        .read_line(&mut input_digits)
        .expect("failed to read from stdin");
    let digits = input_digits.trim();

   	let mut answer : bool = false;
   	let total_sum: u32 = digits.chars().map(|x| x.to_digit(10).unwrap()).sum();
    for i in 1..total_sum {
        let mut sum: u32 = 0;
    	for c in digits.chars() {
			let current_digit = c.to_digit(10).unwrap();
			sum += current_digit;
			if sum == i {
				sum = 0;
			}
    	}
    	if sum == 0 {
    		answer = true;
    	}
    }
    if answer {
    	println!("YES");
    } else {
    	println!("NO");
    }
}

use std::io;

fn main() {
    let mut input_text = String::new();
    io::stdin()
        .read_line(&mut input_text)
        .expect("failed to read from stdin");

    let trimmed = input_text.trim();
    let mut no_of_digits: u32 = 0;
    match trimmed.parse::<u32>() {
        Ok(i) => no_of_digits = i,
        Err(..) => println!("this was not an integer: {}", trimmed),
    };

    let mut input_digits = String::new();
 	io::stdin()
        .read_line(&mut input_digits)
        .expect("failed to read from stdin");
    let digits = input_digits.trim();

   	let mut answer : bool = false;
    for i in 1..901 {
        let mut sum: u32 = 0;
    	for c in digits.chars() {
			let current_digit = c.to_digit(10).unwrap();
			sum += current_digit;
			if sum == i {
				sum = 0;
			}
    	}
    	if sum == 0 {
    		answer = true;
    	}
    }
    if answer {
    	println!("YES");
    } else {
    	println!("NO");
    }
}

use std::io;

fn main() {
    let mut input_text = String::new();
    io::stdin()
        .read_line(&mut input_text)
        .expect("failed to read from stdin");

    let trimmed = input_text.trim();
    let mut no_of_digits: u32 = 0;
    match trimmed.parse::<u32>() {
        Ok(i) => no_of_digits = i,
        Err(..) => println!("this was not an integer: {}", trimmed),
    };

    let mut input_digits = String::new();
 	io::stdin()
        .read_line(&mut input_digits)
        .expect("failed to read from stdin");
    let digits = input_digits.trim();

   	let mut answer : bool = false;
   	let total_sum: u32 = digits.chars().map(|x| x.to_digit(10).unwrap()).sum();
    for i in 0..total_sum {
        let mut sum: u32 = 0;
    	for c in digits.chars() {
			let current_digit = c.to_digit(10).unwrap();
			sum += current_digit;
			if sum == i {
				sum = 0;
			}
    	}
    	if sum == 0 {
    		answer = true;
    	}
    }
    if answer {
    	println!("YES");
    } else {
    	println!("NO");
    }
}

use std::io;

macro_rules! readln {
    () => {{
        use std::io;
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

fn can_be_splitted(slice : &[i32], sum : i32) -> bool {
    let mut curr_sum = 0;
    let mut index = 0;
    let mut at_least_one = false;
    loop {
        if index >= slice.len() {
            return at_least_one;
        }

        curr_sum += slice[index];
        if curr_sum == sum {
            curr_sum = 0;
            at_least_one = true;
        } else if curr_sum > sum {
            return false;
        }
        index += 1;
    }

    true
}

fn solve(length : usize, digits : Vec<i32>) -> (bool, i32) {
    let mut curr_sum = 0;
    for index in 0..(length - 1) {
        curr_sum += digits[index];
        if can_be_splitted(&digits[(index + 1)..], curr_sum) {
            return (true, curr_sum);
        }
    }
    (false, 0)
}

fn main() {
    let length = readln!(usize);

    let digits = readln!();
    let digits : Vec<i32> = digits.chars().map(|ch| ch.to_digit(10).unwrap() as i32).collect();

    let (result, sum) = solve(length, digits);

    println!("{}", if result { "YES" } else { "NO" });
}

use std::io;

macro_rules! readln {
    () => {{
        use std::io;
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

fn can_be_splitted(slice : &[i32], sum : i32) -> bool {
    let mut curr_sum = 0;
    let mut index = 0;
    loop {
        if index >= slice.len() {
            return curr_sum == 0;
        }

        curr_sum += slice[index];
        if curr_sum == sum {
            curr_sum = 0;
        } else if curr_sum > sum {
            return false;
        }
        index += 1;
    }

    true
}

fn solve(length : usize, digits : Vec<i32>) -> (bool, i32) {
    let mut curr_sum = 0;
    for index in 0..(length - 1) {
        curr_sum += digits[index];
        if can_be_splitted(&digits[(index + 1)..], curr_sum) {
            return (true, curr_sum);
        }
    }
    (false, 0)
}

fn main() {
    let length = readln!(usize);

    let digits = readln!();
    let digits : Vec<i32> = digits.chars().map(|ch| ch.to_digit(10).unwrap() as i32).collect();

    let (result, sum) = solve(length, digits);

    println!("{}", if result { "YES" } else { "NO" });
}

use std::io;
use std::slice::Iter;

fn check(mut iter : Iter<u64>, check_sum : u64) -> bool {
    let mut did_something = false;
    let mut sum = 0;
    while let Some(x) = iter.next() {
        sum += x;
        did_something = true;
        if sum == check_sum {
            sum = 0;
        }
    }
    if sum == 0 && did_something {
        true
    } else {
        false
    }
}

fn main() {
    let n = {
        let mut buffer = String::new();
        io::stdin().read_line(&mut buffer).unwrap();
        buffer.trim().parse().unwrap()
    };
    let nums : Vec<u64> = {
        let mut buffer = String::with_capacity(n);
        let mut char_str = String::from("0");
        io::stdin().read_line(&mut buffer).unwrap();
        buffer
        .trim()
        .chars()
        .map(|x| {
            char_str.pop();
            char_str.push(x);
            char_str.trim().parse().unwrap()
        })
        .collect()
    };
    let mut iter = nums.iter();
    let mut sum = 0;
    let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);
    while let Some(x) = iter.next() {
        sum_rest -= x;
        sum += x;
        if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {
            if check(iter.clone(), sum) {
                println!("YES");
                return
            }
        }
    }
    println!("NO");
}

use std::io;

fn main() {
    let n = {
        let mut buffer = String::new();
        io::stdin().read_line(&mut buffer).unwrap();
        buffer.trim().parse().unwrap()
    };
    let nums : Vec<u64> = {
        let mut buffer = String::with_capacity(n);
        let mut char_str = String::from("0");
        io::stdin().read_line(&mut buffer).unwrap();
        buffer
        .trim()
        .chars()
        .map(|x| {
            char_str.pop();
            char_str.push(x);
            char_str.trim().parse().unwrap()
        })
        .collect()
    };
    let mut iter = nums.iter();
    let mut sum = 0;
    {
        let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);
        let mut exhausted = true;
        while let Some(x) = iter.next() {
            sum_rest -= x;
            sum += x;
            if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {
                exhausted = false;
                break
            }
        }
        if exhausted {
            println!("TRUE");
        }
    }
    let mut sum2 = 0;
    while let Some(x) = iter.next() {
        sum2 += x;
        if sum2 == sum {
            sum2 = 0;
        }
    }
    if sum2 == 0 {
        println!("YES")
    } else {
        println!("NO")
    }
}

use std::io;
use std::slice::Iter;

fn check(mut iter : Iter<u64>, check_sum : u64) -> bool {
    let mut sum = 0;
    while let Some(x) = iter.next() {
        sum += x;
        if sum == check_sum {
            sum = 0;
        }
    }
    if sum == 0 {
        true
    } else {
        false
    }
}

fn main() {
    let n = {
        let mut buffer = String::new();
        io::stdin().read_line(&mut buffer).unwrap();
        buffer.trim().parse().unwrap()
    };
    let nums : Vec<u64> = {
        let mut buffer = String::with_capacity(n);
        let mut char_str = String::from("0");
        io::stdin().read_line(&mut buffer).unwrap();
        buffer
        .trim()
        .chars()
        .map(|x| {
            char_str.pop();
            char_str.push(x);
            char_str.trim().parse().unwrap()
        })
        .collect()
    };
    let mut iter = nums.iter();
    let mut sum = 0;
    let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);
    while let Some(x) = iter.next() {
        sum_rest -= x;
        sum += x;
        if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {
            if check(iter.clone(), sum) {
                println!("YES");
                return
            }
        }
    }
    println!("NO");
}

use std::io;
use std::slice::Iter;

fn check_step(iter : &mut Iter<u64>, check_sum : u64) -> Option<bool> {
    if iter.as_slice().len() == 0 { return None }
    let mut iter = iter.peekable();
    let mut sum = 0;
    while let Some(x) = iter.next() {
        sum += x;
        if sum == check_sum {
            while iter.peek().map(|x| **x == 0).unwrap_or(false) {
                iter.next();
            }
            return Some(true)
        }
    }
    Some(false)
}

fn check(mut iter : Iter<u64>, check_sum : u64) -> bool {
    if iter.as_slice().len() == 0 { return false }
    while let Some(flag) = check_step(&mut iter, check_sum) {
        if !flag {
            return false
        }
    }
    true
}

fn main() {
    let n = {
        let mut buffer = String::new();
        io::stdin().read_line(&mut buffer).unwrap();
        buffer.trim().parse().unwrap()
    };
    let nums : Vec<u64> = {
        let mut buffer = String::with_capacity(n);
        let mut char_str = String::from("0");
        io::stdin().read_line(&mut buffer).unwrap();
        buffer
        .trim()
        .chars()
        .map(|x| {
            char_str.pop();
            char_str.push(x);
            char_str.trim().parse().unwrap()
        })
        .collect()
    };
    let mut iter = nums.iter();
    let mut sum = 0;
    let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);
    while let Some(x) = iter.next() {
        sum_rest -= x;
        sum += x;
        if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {
            if check(iter.clone(), sum) {
                println!("YES");
                return
            }
        }
    }
    println!("NO");
}

use std::io;

fn main() {
    let n = {
        let mut buffer = String::new();
        io::stdin().read_line(&mut buffer).unwrap();
        buffer.trim().parse().unwrap()
    };
    let nums : Vec<u64> = {
        let mut buffer = String::with_capacity(n);
        let mut char_str = String::from("0");
        io::stdin().read_line(&mut buffer).unwrap();
        buffer
        .trim()
        .chars()
        .map(|x| {
            char_str.pop();
            char_str.push(x);
            char_str.trim().parse().unwrap()
        })
        .collect()
    };
    let mut iter = nums.iter();
    let mut sum = 0;
    {
        let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);
        let mut exhausted = true;
        while let Some(x) = iter.next() {
            sum_rest -= x;
            sum += x;
            if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {
                exhausted = false;
                break
            }
        }
        if exhausted {
            println!("NO");
        }
    }
    let mut sum2 = 0;
    while let Some(x) = iter.next() {
        sum2 += x;
        if sum2 == sum {
            sum2 = 0;
        }
    }
    if sum2 == 0 {
        println!("YES")
    } else {
        println!("NO")
    }
}

use std::io;
use std::slice::Iter;

fn check_step(iter : &mut Iter<u64>, check_sum : u64) -> Option<bool> {
    if iter.as_slice().len() == 0 { return None }
    let mut sum = 0;
    while let Some(x) = iter.next() {
        sum += x;
        if sum == check_sum {
            return Some(true)
        }
    }
    Some(false)
}

fn check(mut iter : Iter<u64>, check_sum : u64) -> bool {
    if iter.as_slice().len() == 0 { return false }
    while let Some(flag) = check_step(&mut iter, check_sum) {
        if !flag {
            return false
        }
    }
    true
}

fn main() {
    let n = {
        let mut buffer = String::new();
        io::stdin().read_line(&mut buffer).unwrap();
        buffer.trim().parse().unwrap()
    };
    let nums : Vec<u64> = {
        let mut buffer = String::with_capacity(n);
        let mut char_str = String::from("0");
        io::stdin().read_line(&mut buffer).unwrap();
        buffer
        .trim()
        .chars()
        .map(|x| {
            char_str.pop();
            char_str.push(x);
            char_str.trim().parse().unwrap()
        })
        .collect()
    };
    let mut iter = nums.iter();
    let mut sum = 0;
    let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);
    while let Some(x) = iter.next() {
        sum_rest -= x;
        sum += x;
        if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {
            if check(iter.clone(), sum) {
                println!("YES");
                return
            }
        }
    }
    println!("NO");
}


Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.The committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.Unfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color $$$x$$$ such that there are currently at least two puppies of color $$$x$$$ and recolor all puppies of the color $$$x$$$ into some arbitrary color $$$y$$$. Luckily, this operation can be applied multiple times (including zero).For example, if the number of puppies is $$$7$$$ and their colors are represented as the string "abababc", then in one operation Slava can get the results "zbzbzbc", "bbbbbbc", "aaaaaac", "acacacc" and others. However, if the current color sequence is "abababc", then he can't choose $$$x$$$='c' right now, because currently only one puppy has the color 'c'.Help Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of puppies. The second line contains a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters, where the $$$i$$$-th symbol denotes the $$$i$$$-th puppy's color.

If it's possible to recolor all puppies into one color, print "Yes". Otherwise print "No". Output the answer without quotation signs.

NoteIn the first example Slava can perform the following steps:   take all puppies of color 'a' (a total of two) and recolor them into 'b';  take all puppies of color 'd' (a total of two) and recolor them into 'c';  take all puppies of color 'b' (three puppies for now) and recolor them into 'c'. In the second example it's impossible to recolor any of the puppies.In the third example all the puppies' colors are the same; thus there's no need to recolor anything.

fn raw_input() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_string()
}

fn sort_str(s: String) -> Vec<char> {
    let mut s: Vec<char> = s.chars().collect();
    s.sort_unstable();
    s
}

fn solve(n: u32) -> &'static str {
    if n == 1 {
        return "Yes";
    } else {
        let doggos = raw_input();
        let doggos = sort_str(doggos);

        for i in 1..doggos.len() {
            if doggos[i] == doggos[i - 1] {
                return "Yes";
            }
        }
    }
    "No"
}

fn main() {
    let n: u32 = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().parse().unwrap()
    };
    println!("{}", solve(n));
}

fn raw_input() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_string()
}

fn sort_str(s: String) -> Vec<char> {
    let mut s: Vec<char> = s.chars().collect();
    s.sort_unstable();
    s
}

fn solve(n: u32) -> &'static str {
    if n == 1 {
        "Yes"
    } else {
        let doggos = raw_input();
        let doggos = sort_str(doggos);

        let mut doggos_without_doubles = doggos.clone();
        doggos_without_doubles.dedup();

        if doggos != doggos_without_doubles {
            "Yes"
        } else {
            "No"
        }
    }
}

fn main() {
    let n: u32 = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().parse().unwrap()
    };
    println!("{}", solve(n));
}

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn get_line() -> String {
    let stdin = stdin();
    let mut line = String::new();
    stdin.lock().read_line(&mut line).expect("io error.");
    line.trim().to_string()
}

#[allow(dead_code)]
fn get_word<T: FromStr>() -> T {
    (&get_line()).parse().ok().expect("parse error.")
}

#[allow(dead_code)]
fn get_vec<T: FromStr>() -> Vec<T> {
    (&get_line()).split(' ').map(|x| x.parse().ok().expect("parse error.")).collect()
}

fn main() {
    let n = get_word::<u64>();
    let s = get_line();

    if n == 1 {
        println!("Yes");
        return;
    }

    let mut cnt = [0u64; 26];
    for c in s.chars() {
        cnt[((c as u8) - ('a' as u8)) as usize] += 1;
    }

    for k in cnt.iter() {
        if *k > 1 {
            println!("Yes");
            return;
        }
    }

    println!("No");
}

fn read_string() -> String {
    let mut string: String = String::new();
    std::io::stdin().read_line(&mut string)
        .ok()
        .expect("Ошибка чтения ввода");
    return string;
}

fn main() {
    let n: i32 = read_string().trim().parse().unwrap();
    if n == 1 {
        println!("{}", "Yes")
    }else {
        let text = read_string();
        let mut counter = [0; 26];
        let mut res = false;
        for ch in text.trim().chars() {
            let value: u32 = ch as u32 - 'a' as u32;
            counter[value as usize] += 1;
            if counter[value as usize] > 1 {
                res = true;
            }
        }
        if res{
            println!("{}", "Yes")
        }else {
            println!("{}", "No")
        }
    }
}

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn get_line() -> String {
    let stdin = stdin();
    let mut line = String::new();
    stdin.lock().read_line(&mut line).expect("io error.");
    line.trim().to_string()
}

#[allow(dead_code)]
fn get_word<T: FromStr>() -> T {
    (&get_line()).parse().ok().expect("parse error.")
}

#[allow(dead_code)]
fn get_vec<T: FromStr>() -> Vec<T> {
    (&get_line()).split(' ').map(|x| x.parse().ok().expect("parse error.")).collect()
}

fn main() {
    let _ = get_word::<u64>();
    let s = get_line();

    let mut cnt = [0u64; 26];
    for c in s.chars() {
        cnt[((c as u8) - ('a' as u8)) as usize] += 1;
    }

    for k in cnt.iter() {
        if *k > 1 {
            println!("Yes");
            return;
        }
    }

    println!("No");
}

fn read_string() -> String {
    let mut string: String = String::new();
    std::io::stdin().read_line(&mut string)
        .ok()
        .expect("Ошибка чтения ввода");
    return string;
}

fn main() {
    read_string();
    let text = read_string();
    let mut counter = [0; 26];
    let mut res = false;
    for ch in text.trim().chars() {
        let value: u32 = ch as u32 - 'a' as u32;
        counter[value as usize] += 1;
        if counter[value as usize] > 1 {
            res = true;
        }
    }
    if res {
        println!("{}", "Yes")
    }else {
        println!("{}", "No")
    }
}


Calculate the number of ways to place $$$n$$$ rooks on $$$n \times n$$$ chessboard so that both following conditions are met:  each empty cell is under attack;  exactly $$$k$$$ pairs of rooks attack each other. An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two rooks attack each other if they share the same row or column, and there are no other rooks between them. For example, there are only two pairs of rooks that attack each other in the following picture:  One of the ways to place the rooks for $$$n = 3$$$ and $$$k = 2$$$ Two ways to place the rooks are considered different if there exists at least one cell which is empty in one of the ways but contains a rook in another way.The answer might be large, so print it modulo $$$998244353$$$.

The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 200000$$$; $$$0 \le k \le \frac{n(n - 1)}{2}$$$).

Print one integer — the number of ways to place the rooks, taken modulo $$$998244353$$$.

// ---------- begin ModInt ----------
const MOD: u32 = 998_244_353;

#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> Self::Output {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> Self::Output {
        ModInt(if self.0 == 0 {0} else {MOD - self.0})
    }
}

impl std::fmt::Display for ModInt {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for ModInt {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

impl From<usize> for ModInt {
    fn from(val: usize) -> ModInt {
        ModInt((val % MOD as usize) as u32)
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------
// ---------- begin Precalc ----------
#[allow(dead_code)]
struct Precalc {
    inv: Vec<ModInt>,
    fact: Vec<ModInt>,
    ifact: Vec<ModInt>,
}

#[allow(dead_code)]
impl Precalc {
    pub fn new(n: usize) -> Precalc {
        let mut inv = vec![ModInt::one(); n + 1];
        let mut fact = vec![ModInt::one(); n + 1];
        let mut ifact = vec![ModInt::one(); n + 1];
        for i in 2..(n + 1) {
            inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);
            fact[i] = fact[i - 1] * ModInt(i as u32);
            ifact[i] = ifact[i - 1] * inv[i];
        }
        Precalc {
            inv: inv,
            fact: fact,
            ifact: ifact,
        }
    }
    pub fn inv(&self, n: usize) -> ModInt {
        self.inv[n]
    }
    pub fn fact(&self, n: usize) -> ModInt {
        self.fact[n]
    }
    pub fn ifact(&self, n: usize) -> ModInt {
        self.ifact[n]
    }
    pub fn comb(&self, n: usize, k: usize) -> ModInt {
        if k > n {
            return ModInt::zero();
        }
        self.fact[n] * self.ifact[k] * self.ifact[n - k]
    }
}
// ---------- end Precalc ----------
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        m: u64,
    }
    if m > n as u64 - 1 {
        println!("0");
        return;
    }
    let m = m as usize;
    let pc = Precalc::new(n + m);
    if m == 0 {
        println!("{}", pc.fact(n));
        return;
    }
    let mut ans = ModInt::zero();
    let mut sign = ModInt::one();
    for i in (1..=(n - m)).rev() {
        ans += sign * pc.comb(n - m, i) * ModInt::from(i).pow(n as u32);
        sign = -sign;
    }
    ans *= pc.comb(n, n - m) * ModInt(2);
    println!("{}", ans);
}

fn main() {
    run();
}

// ---------- begin ModInt ----------
const MOD: u32 = 998_244_353;

#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> Self::Output {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> Self::Output {
        ModInt(if self.0 == 0 {0} else {MOD - self.0})
    }
}

impl std::fmt::Display for ModInt {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for ModInt {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

impl From<usize> for ModInt {
    fn from(val: usize) -> ModInt {
        ModInt((val % MOD as usize) as u32)
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------
// ---------- begin Precalc ----------
#[allow(dead_code)]
struct Precalc {
    inv: Vec<ModInt>,
    fact: Vec<ModInt>,
    ifact: Vec<ModInt>,
}

#[allow(dead_code)]
impl Precalc {
    pub fn new(n: usize) -> Precalc {
        let mut inv = vec![ModInt::one(); n + 1];
        let mut fact = vec![ModInt::one(); n + 1];
        let mut ifact = vec![ModInt::one(); n + 1];
        for i in 2..(n + 1) {
            inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);
            fact[i] = fact[i - 1] * ModInt(i as u32);
            ifact[i] = ifact[i - 1] * inv[i];
        }
        Precalc {
            inv: inv,
            fact: fact,
            ifact: ifact,
        }
    }
    pub fn inv(&self, n: usize) -> ModInt {
        self.inv[n]
    }
    pub fn fact(&self, n: usize) -> ModInt {
        self.fact[n]
    }
    pub fn ifact(&self, n: usize) -> ModInt {
        self.ifact[n]
    }
    pub fn comb(&self, n: usize, k: usize) -> ModInt {
        if k > n {
            return ModInt::zero();
        }
        self.fact[n] * self.ifact[k] * self.ifact[n - k]
    }
}
// ---------- end Precalc ----------
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn run() {
    input! {
        n: usize,
        m: u64,
    }
    if m > n as u64 - 1 {
        println!("0");
        return;
    }
    let m = m as usize;
    let pc = Precalc::new(n + m);
    if m == 0 {
        println!("{}", pc.fact(n));
        return;
    }
    let mut ans = ModInt::zero();
    let mut sign = ModInt::one();
    for i in (1..=(n - m)).rev() {
        ans += sign * pc.comb(n - m, i) * ModInt::from(i).pow(n as u32);
        sign = -sign;
    }
    ans *= pc.comb(n, n - m) * ModInt(2);
    println!("{}", ans);
}
fn main() {
    run();
}

#![allow(unused_imports, unused_macros)]

use kyoproio::*;
use std::{
    collections::*,
    io::{self, prelude::*},
    iter,
    mem::{replace, swap},
};

fn main() -> io::Result<()> {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024)
        .spawn(solve)?
        .join()
        .unwrap();
    Ok(())
}

fn solve() {
    let stdin = io::stdin();
    let mut kin = KInput::new(stdin.lock());
    let stdout = io::stdout();
    let mut out = io::BufWriter::new(stdout.lock());
    macro_rules! output { ($($args:expr),+) => { write!(&mut out, $($args),+).unwrap(); }; }
    macro_rules! outputln {
        ($($args:expr),+) => { output!($($args),+); outputln!(); };
        () => { output!("\n"); if cfg!(debug_assertions) { out.flush().unwrap(); } }
    }

    let (n, k): (i64, i64) = kin.input();
    if k >= n {
        outputln!("0");
        return;
    }
    const MOD: i64 = 998244353;
    let c = Combination::new(n as usize, MOD);
    if k == 0 {
        outputln!("{}", c.fact(n));
        return;
    }
    let mut ans = 0;
    let mut sign = 1;
    for i in (1..=n - k).rev() {
        ans += MOD + sign * (c.pow(i, n) * c.comb(n - k, i) % MOD);
        sign = -sign;
    }
    ans %= MOD;
    ans = ans * c.comb(n, n - k) % MOD * 2 % MOD;
    outputln!("{}", ans);
}
pub fn mod_pow(mut a: i64, mut b: i64, m: i64) -> i64 {
    let mut y = 1;
    while b > 0 {
        if b & 1 == 1 {
            y = y * a % m;
        }
        a = a * a % m;
        b >>= 1;
    }
    y
}
pub fn mod_inv(x: i64, m: i64) -> i64 {
    mod_pow(x, m - 2, m)
}
pub struct Combination {
    m: i64,
    fact: Vec<i64>,
}
impl Combination {
    pub fn new(size: usize, m: i64) -> Self {
        let mut comb = Self {
            m,
            fact: Vec::new(),
        };
        comb.resize(size);
        comb
    }
    pub fn resize(&mut self, size: usize) {
        let old_len = self.fact.len();
        self.fact.resize(size + 1, 0);
        for i in old_len..=size {
            self.fact[i] = if i == 0 {
                1
            } else {
                i as i64 * self.fact[i - 1] % self.m
            };
        }
    }
    pub fn fact(&self, x: i64) -> i64 {
        self.fact[x as usize]
    }
    pub fn perm(&self, a: i64, b: i64) -> i64 {
        if a >= b {
            self.fact(a) * self.inv(self.fact(a - b)) % self.m
        } else {
            0
        }
    }
    pub fn comb(&self, a: i64, b: i64) -> i64 {
        if a >= b {
            self.fact(a) * self.inv(self.fact(b) * self.fact(a - b) % self.m) % self.m
        } else {
            0
        }
    }
    pub fn pow(&self, a: i64, b: i64) -> i64 {
        mod_pow(a, b, self.m)
    }
    pub fn inv(&self, x: i64) -> i64 {
        self.pow(x, self.m - 2)
    }
}

// -----------------------------------------------------------------------------
pub mod kyoproio {
    use std::io::prelude::*;
    pub trait Input {
        fn str(&mut self) -> &str;
        fn input<T: InputParse>(&mut self) -> T {
            T::input(self)
        }
        fn iter<T: InputParse>(&mut self) -> Iter<T, Self> {
            Iter(self, std::marker::PhantomData)
        }
        fn seq<T: InputParse, B: std::iter::FromIterator<T>>(&mut self, n: usize) -> B {
            self.iter().take(n).collect()
        }
    }
    pub struct KInput<R> {
        src: R,
        buf: String,
        pos: usize,
    }
    impl<R: BufRead> KInput<R> {
        pub fn new(src: R) -> Self {
            Self {
                src,
                buf: String::with_capacity(1024),
                pos: 0,
            }
        }
    }
    impl<R: BufRead> Input for KInput<R> {
        fn str(&mut self) -> &str {
            loop {
                if self.pos >= self.buf.len() {
                    self.pos = 0;
                    self.buf.clear();
                    if self.src.read_line(&mut self.buf).expect("io error") == 0 {
                        return &self.buf;
                    }
                }
                let range = self.pos
                    ..self.buf[self.pos..]
                        .find(|c: char| c.is_ascii_whitespace())
                        .map(|i| i + self.pos)
                        .unwrap_or_else(|| self.buf.len());
                self.pos = range.end + 1;
                if range.end > range.start {
                    return &self.buf[range];
                }
            }
        }
    }
    pub struct Iter<'a, T, I: ?Sized>(&'a mut I, std::marker::PhantomData<*const T>);
    impl<'a, T: InputParse, I: Input + ?Sized> Iterator for Iter<'a, T, I> {
        type Item = T;
        fn next(&mut self) -> Option<T> {
            Some(self.0.input())
        }
    }
    pub trait InputParse: Sized {
        fn input<I: Input + ?Sized>(src: &mut I) -> Self;
    }
    impl InputParse for Vec<u8> {
        fn input<I: Input + ?Sized>(src: &mut I) -> Self {
            src.str().as_bytes().to_owned()
        }
    }
    macro_rules! from_str_impl {
        { $($T:ty)* } => {
            $(impl InputParse for $T {
                fn input<I: Input + ?Sized>(src: &mut I) -> Self {
                    src.str().parse::<$T>().expect("parse error")
                }
            })*
        }
    }
    from_str_impl! {
        String char bool f32 f64 isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128
    }
    macro_rules! tuple_impl {
        ($H:ident $($T:ident)*) => {
            impl<$H: InputParse, $($T: InputParse),*> InputParse for ($H, $($T),*) {
                fn input<I: Input + ?Sized>(src: &mut I) -> Self {
                    ($H::input(src), $($T::input(src)),*)
                }
            }
            tuple_impl!($($T)*);
        };
        () => {}
    }
    tuple_impl!(A B C D E F G);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

/// Verified by https://atcoder.jp/contests/arc093/submissions/3968098
mod mod_int {
    use std::ops::*;
    pub trait Mod: Copy { fn m() -> i64; }
    #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
    pub struct ModInt<M> { pub x: i64, phantom: ::std::marker::PhantomData<M> }
    impl<M: Mod> ModInt<M> {
        // x >= 0
        pub fn new(x: i64) -> Self { ModInt::new_internal(x % M::m()) }
        fn new_internal(x: i64) -> Self {
            ModInt { x: x, phantom: ::std::marker::PhantomData }
        }
        pub fn pow(self, mut e: i64) -> Self {
            debug_assert!(e >= 0);
            let mut sum = ModInt::new_internal(1);
            let mut cur = self;
            while e > 0 {
                if e % 2 != 0 { sum *= cur; }
                cur *= cur;
                e /= 2;
            }
            sum
        }
        #[allow(dead_code)]
        pub fn inv(self) -> Self { self.pow(M::m() - 2) }
    }
    impl<M: Mod, T: Into<ModInt<M>>> Add<T> for ModInt<M> {
        type Output = Self;
        fn add(self, other: T) -> Self {
            let other = other.into();
            let mut sum = self.x + other.x;
            if sum >= M::m() { sum -= M::m(); }
            ModInt::new_internal(sum)
        }
    }
    impl<M: Mod, T: Into<ModInt<M>>> Sub<T> for ModInt<M> {
        type Output = Self;
        fn sub(self, other: T) -> Self {
            let other = other.into();
            let mut sum = self.x - other.x;
            if sum < 0 { sum += M::m(); }
            ModInt::new_internal(sum)
        }
    }
    impl<M: Mod, T: Into<ModInt<M>>> Mul<T> for ModInt<M> {
        type Output = Self;
        fn mul(self, other: T) -> Self { ModInt::new(self.x * other.into().x % M::m()) }
    }
    impl<M: Mod, T: Into<ModInt<M>>> AddAssign<T> for ModInt<M> {
        fn add_assign(&mut self, other: T) { *self = *self + other; }
    }
    impl<M: Mod, T: Into<ModInt<M>>> SubAssign<T> for ModInt<M> {
        fn sub_assign(&mut self, other: T) { *self = *self - other; }
    }
    impl<M: Mod, T: Into<ModInt<M>>> MulAssign<T> for ModInt<M> {
        fn mul_assign(&mut self, other: T) { *self = *self * other; }
    }
    impl<M: Mod> Neg for ModInt<M> {
        type Output = Self;
        fn neg(self) -> Self { ModInt::new(0) - self }
    }
    impl<M> ::std::fmt::Display for ModInt<M> {
        fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
            self.x.fmt(f)
        }
    }
    impl<M: Mod> ::std::fmt::Debug for ModInt<M> {
        fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
            let (mut a, mut b, _) = red(self.x, M::m());
            if b < 0 {
                a = -a;
                b = -b;
            }
            write!(f, "{}/{}", a, b)
        }
    }
    impl<M: Mod> From<i64> for ModInt<M> {
        fn from(x: i64) -> Self { Self::new(x) }
    }
    // Finds the simplest fraction x/y congruent to r mod p.
    // The return value (x, y, z) satisfies x = y * r + z * p.
    fn red(r: i64, p: i64) -> (i64, i64, i64) {
        if r.abs() <= 10000 {
            return (r, 1, 0);
        }
        let mut nxt_r = p % r;
        let mut q = p / r;
        if 2 * nxt_r >= r {
            nxt_r -= r;
            q += 1;
        }
        if 2 * nxt_r <= -r {
            nxt_r += r;
            q -= 1;
        }
        let (x, z, y) = red(nxt_r, r);
        (x, y - q * z, z)
    }
} // mod mod_int

macro_rules! define_mod {
    ($struct_name: ident, $modulo: expr) => {
        #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
        struct $struct_name {}
        impl mod_int::Mod for $struct_name { fn m() -> i64 { $modulo } }
    }
}
const MOD: i64 = 998_244_353;
define_mod!(P, MOD);
type ModInt = mod_int::ModInt<P>;

// Depends on ModInt.rs
fn fact_init(w: usize) -> (Vec<ModInt>, Vec<ModInt>) {
    let mut fac = vec![ModInt::new(1); w];
    let mut invfac = vec![0.into(); w];
    for i in 1 .. w {
        fac[i] = fac[i - 1] * i as i64;
    }
    invfac[w - 1] = fac[w - 1].inv();
    for i in (0 .. w - 1).rev() {
        invfac[i] = invfac[i + 1] * (i as i64 + 1);
    }
    (fac, invfac)
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input!(n: usize, k: i64);
    let (fac, invfac) = fact_init(n + 1);
    if k > n as i64 - 1 {
        puts!("0\n");
        return;
    }
    let k = k as usize;
    if k == 0 {
        puts!("{}\n", fac[n]);
        return;
    }
    let mut inex = ModInt::new(0);
    // Sur(n, n - k)
    for i in 0..n - k + 1 {
        let sgn = if (n - k + i) % 2 == 0 { 1 } else { MOD - 1 };
        let tmp = ModInt::new(i as i64).pow(n as i64);
        inex += tmp * sgn * fac[n - k] * invfac[i] * invfac[n - k - i];
    }
    puts!("{}\n", inex * fac[n] * invfac[n - k] * invfac[k] * 2);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


You are given a positive (greater than zero) integer $$$n$$$.You have to represent $$$n$$$ as the sum of integers (possibly negative) consisting only of ones (digits '1'). For example, $$$24 = 11 + 11 + 1 + 1$$$ and $$$102 = 111 - 11 + 1 + 1$$$. Among all possible representations, you have to find the one that uses the minimum number of ones in total.

The single line contains one integer $$$n$$$ ($$$1 \le n < 10^{50}$$$).

Print one integer $$$x$$$ — the minimum number of ones, such that there exist a representation of $$$n$$$ as the sum of integers (possibly negative) that uses $$$x$$$ ones in total.

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;

// 下の桁からdpっぽく?
// +がいくつ、-がいくつ、暫定carryがいくつ
// この時1を幾つで合わせられるか的な
// MLE
// なんか状態多いっぽいが
//
//

const INF: i32 = 100000;

fn run() {
    input!(s: bytes);
    let m = 200;
    let geta = m / 9 + 1;
    let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
    dp[geta] = vec![vec![0; m + 1]; m + 1];
    for &s in s.iter().rev() {
        let s = (s - b'0') as i32;
        let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
        for (carry, dp) in dp.iter().enumerate() {
            for (add, dp) in dp.iter().enumerate() {
                for (sub, dp) in dp.iter().enumerate() {
                    if *dp == INF {
                        continue;
                    }
                    let carry = carry as i32 - geta as i32;
                    let d = add as i32 - sub as i32 + carry;
                    if d.rem_euclid(10) != s {
                        continue;
                    }
                    let carry = (d.div_euclid(10) + geta as i32) as usize;
                    next[carry][add][sub].chmin(*dp + (add + sub) as i32);
                }
            }
        }
        dp = next;
        for dp in dp.iter_mut() {
            for i in (0..m).rev() {
                for j in (0..m).rev() {
                    dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);
                }
            }
        }
    }
    let mut ans = INF;
    for (carry, dp) in dp.iter().enumerate() {
        for (add, dp) in dp.iter().enumerate() {
            for (sub, dp) in dp.iter().enumerate() {
                let carry = carry as i32 - geta as i32;
                let add = add as i32;
                let sub = sub as i32;
                let mut v = *dp;
                if carry == 0 {
                } else if carry > 0 && sub >= carry {
                    v += carry;
                } else if carry < 0 && add >= -carry {
                    v += -carry;
                } else {
                    v += INF;
                }
                ans.chmin(v);
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;

// 下の桁からdpっぽく?
// +がいくつ、-がいくつ、暫定carryがいくつ
// この時1を幾つで合わせられるか的な
// MLE
// なんか状態多いっぽいが
//
//

const INF: i32 = 100000;

fn run() {
    input!(s: bytes);
    let m = 300;
    let geta = m / 9 + 1;
    let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
    dp[geta] = vec![vec![0; m + 1]; m + 1];
    for &s in s.iter().rev() {
        let s = (s - b'0') as i32;
        let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
        for (carry, dp) in dp.iter().enumerate() {
            for (add, dp) in dp.iter().enumerate() {
                for (sub, dp) in dp.iter().enumerate() {
                    if *dp == INF {
                        continue;
                    }
                    let carry = carry as i32 - geta as i32;
                    let d = add as i32 - sub as i32 + carry;
                    if d.rem_euclid(10) != s {
                        continue;
                    }
                    let carry = (d.div_euclid(10) + geta as i32) as usize;
                    next[carry][add][sub].chmin(*dp + (add + sub) as i32);
                }
            }
        }
        dp = next;
        for dp in dp.iter_mut() {
            for i in (0..m).rev() {
                for j in (0..m).rev() {
                    dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);
                }
            }
        }
    }
    let mut ans = INF;
    for (carry, dp) in dp.iter().enumerate() {
        for (add, dp) in dp.iter().enumerate() {
            for (sub, dp) in dp.iter().enumerate() {
                let carry = carry as i32 - geta as i32;
                let add = add as i32;
                let sub = sub as i32;
                let mut v = *dp;
                if carry == 0 {
                } else if carry > 0 && sub >= carry {
                    v += carry;
                } else if carry < 0 && add >= -carry {
                    v += -carry;
                } else {
                    v += INF;
                }
                ans.chmin(v);
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

// vec with some initial value
#[allow(unused_macros)]
macro_rules! vvec {
    ($($x:expr),+; $y:expr; $n:expr) => {{
        let mut v = vec![$y; $n];

        let mut it = v.iter_mut();
        $(
            *it.next().unwrap() = $x;
        )+

        v
    }}
}

#[allow(unused_macros)]
macro_rules! it {
    ($x:expr) => {
        once($x)
    };
    ($first:expr,$($x:expr),+) => {
        chain(
            once($first),
            it!($($x),+)
        )
    }
}

#[allow(unused_macros)]
macro_rules! pushed {
    ($c:expr, $x:expr) => {{
        let mut c = $c;
        c.push($x);
        c
    }};
}

#[allow(unused_macros)]
macro_rules! inserted {
    ($c:expr, $($x:expr),*) => {{
        let mut c = $c;
        c.insert($($x),*);
        c
    }};
}

#[allow(unused_macros)]
macro_rules! read_tuple {
    ($($t:ty),+) => {{
        let mut line = String::new();
        io::stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_str() -> Vec<char> {
    read::<String>().chars().collect()
}

#[allow(dead_code)]
fn read_row<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_col<T: FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

#[allow(dead_code)]
fn read_mat<T: FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_row()).collect()
}

#[allow(dead_code)]
fn read_vec<R, F: FnMut() -> R>(n: usize, mut f: F) -> Vec<R> {
    (0..n).map(|_| f()).collect()
}

trait IterCopyExt<'a, T>: IntoIterator<Item = &'a T> + Sized
where
    T: 'a + Copy,
{
    fn citer(self) -> std::iter::Copied<Self::IntoIter> {
        self.into_iter().copied()
    }
}

impl<'a, T, I> IterCopyExt<'a, T> for I
where
    I: IntoIterator<Item = &'a T>,
    T: 'a + Copy,
{
}

const B: i32 = 250;
const C: i32 = 25;

fn main() {
    let n = read::<String>()
        .chars()
        .map(|c| c.to_digit(10).unwrap() as i32)
        .collect::<Vec<_>>();

    let dp = n.citer().fold(
        (-C..=C)
            .map(|t| {
                (0..B)
                    .map(|i| {
                        if i < t {
                            vec![i32::MAX; B as usize]
                        } else {
                            vec![t; B as usize]
                        }
                    })
                    .collect::<Vec<_>>()
            })
            .collect::<Vec<_>>(),
        |prev, d| {
            // eprintln!("{:?}", prev);
            (-C..=C)
                .map(|t| {
                    let d = d + t;
                    let mut dp = (0..B)
                        .map(|i| {
                            let mut v = vec![i32::MAX; B as usize];

                            (-C..=C).for_each(|c| {
                                if i + 10 * c >= d && i + 10 * c < B + d {
                                    let j = i + 10 * c - d;
                                    v[j as usize] = prev[(c + C) as usize][i as usize][j as usize]
                                        .saturating_add(i + j);
                                }
                            });

                            v
                        })
                        .collect::<Vec<_>>();
                    for i in 0..B {
                        for j in 0..B {
                            if i > 0 {
                                dp[i as usize][j as usize] =
                                    min(dp[i as usize][j as usize], dp[i as usize - 1][j as usize]);
                            }
                            if j > 0 {
                                dp[i as usize][j as usize] =
                                    min(dp[i as usize][j as usize], dp[i as usize][j as usize - 1]);
                            }
                        }
                    }
                    dp
                })
                .collect::<Vec<_>>()
        },
    );
    let ans = dp[0 + C as usize][B as usize - 1][B as usize - 1];
    println!("{}", ans);
}

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;

// 下の桁からdpっぽく?
// +がいくつ、-がいくつ、暫定carryがいくつ
// この時1を幾つで合わせられるか的な
// MLE
// なんか状態多いっぽいが
//
//

const INF: i32 = 100000;

fn dfs(
    pos: usize,
    add: i32,
    sub: i32,
    carry: i32,
    s: &[i32],
    dp: &mut Map<(usize, i32, i32, i32), i32>,
) -> i32 {
    if let Some(&v) = dp.get(&(pos, add, sub, carry)) {
        return v;
    }
    if pos == 0 {
        return if carry == 0 {
            0
        } else if carry > 0 && sub >= carry {
            carry
        } else if carry < 0 && add >= -carry {
            -carry
        } else {
            INF
        };
    }
    let mut ans = INF;
    if add > 0 {
        ans = ans.min(dfs(pos, add - 1, sub, carry, s, dp));
    }
    if sub > 0 {
        ans = ans.min(dfs(pos, add, sub - 1, carry, s, dp));
    }
    let d = add - sub + carry;
    if d.rem_euclid(10) == s[pos - 1] {
        let carry = d.div_euclid(10);
        ans = ans.min(dfs(pos - 1, add, sub, carry, s, dp) + add + sub);
    }
    dp.insert((pos, add, sub, carry), ans);
    ans
}

fn run() {
    input!(s: bytes);
    let m = 150;
    let geta = m / 10 + 2;
    let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
    dp[geta] = vec![vec![0; m + 1]; m + 1];
    for &s in s.iter().rev() {
        let s = (s - b'0') as i32;
        let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
        for (carry, dp) in dp.iter().enumerate() {
            for (add, dp) in dp.iter().enumerate() {
                for (sub, dp) in dp.iter().enumerate() {
                    if *dp == INF {
                        continue;
                    }
                    let carry = carry as i32 - geta as i32;
                    let d = add as i32 - sub as i32 + carry;
                    if d.rem_euclid(10) != s {
                        continue;
                    }
                    let carry = (d.div_euclid(10) + geta as i32) as usize;
                    next[carry][add][sub].chmin(*dp + (add + sub) as i32);
                }
            }
        }
        dp = next;
        for dp in dp.iter_mut() {
            for i in (0..m).rev() {
                for j in (0..m).rev() {
                    dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);
                }
            }
        }
    }
    let mut ans = INF;
    for (carry, dp) in dp.iter().enumerate() {
        for (add, dp) in dp.iter().enumerate() {
            for (sub, dp) in dp.iter().enumerate() {
                let carry = carry as i32 - geta as i32;
                let add = add as i32;
                let sub = sub as i32;
                let mut v = *dp;
                if carry == 0 {
                } else if carry > 0 && sub >= carry {
                    v += carry;
                } else if carry < 0 && add >= -carry {
                    v += -carry;
                } else {
                    v += INF;
                }
                ans.chmin(v);
            }
        }
    }
    println!("{}", ans);
    /*
    let s = s.into_iter().map(|s| (s - b'0') as i32).collect::<Vec<_>>();
    let mut map = Map::new();
    let ans = dfs(s.len(), 100, 100, 0, &s, &mut map);
    println!("{}", ans);
    */
}

fn main() {
    run();
}

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;

// 下の桁からdpっぽく?
// +がいくつ、-がいくつ、暫定carryがいくつ
// この時1を幾つで合わせられるか的な
// MLE
// なんか状態多いっぽいが
//
//

const INF: i32 = 100000;

fn dfs(
    pos: usize,
    add: i32,
    sub: i32,
    carry: i32,
    s: &[i32],
    dp: &mut Map<(usize, i32, i32, i32), i32>,
) -> i32 {
    if let Some(&v) = dp.get(&(pos, add, sub, carry)) {
        return v;
    }
    if pos == 0 {
        return if carry == 0 {
            0
        } else if carry > 0 && sub >= carry {
            carry
        } else if carry < 0 && add >= -carry {
            -carry
        } else {
            INF
        };
    }
    let mut ans = INF;
    if add > 0 {
        ans = ans.min(dfs(pos, add - 1, sub, carry, s, dp));
    }
    if sub > 0 {
        ans = ans.min(dfs(pos, add, sub - 1, carry, s, dp));
    }
    let d = add - sub + carry;
    if d.rem_euclid(10) == s[pos - 1] {
        let carry = d.div_euclid(10);
        ans = ans.min(dfs(pos - 1, add, sub, carry, s, dp) + add + sub);
    }
    dp.insert((pos, add, sub, carry), ans);
    ans
}

fn run() {
    input!(s: bytes);
    let m = 100;
    let geta = 11;
    let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
    dp[geta] = vec![vec![0; m + 1]; m + 1];
    for &s in s.iter().rev() {
        let s = (s - b'0') as i32;
        let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
        for (carry, dp) in dp.iter().enumerate() {
            for (add, dp) in dp.iter().enumerate() {
                for (sub, dp) in dp.iter().enumerate() {
                    if *dp == INF {
                        continue;
                    }
                    let carry = carry as i32 - geta as i32;
                    let d = add as i32 - sub as i32 + carry;
                    if d.rem_euclid(10) != s {
                        continue;
                    }
                    let carry = (d.div_euclid(10) + geta as i32) as usize;
                    next[carry][add][sub].chmin(*dp + (add + sub) as i32);
                }
            }
        }
        dp = next;
        for dp in dp.iter_mut() {
            for i in (0..m).rev() {
                for j in (0..m).rev() {
                    dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);
                }
            }
        }
    }
    let mut ans = INF;
    for (carry, dp) in dp.iter().enumerate() {
        for (add, dp) in dp.iter().enumerate() {
            for (sub, dp) in dp.iter().enumerate() {
                let carry = carry as i32 - geta as i32;
                let add = add as i32;
                let sub = sub as i32;
                let mut v = *dp;
                if carry == 0 {
                } else if carry > 0 && sub >= carry {
                    v += carry;
                } else if carry < 0 && add >= -carry {
                    v += -carry;
                } else {
                    v += INF;
                }
                ans.chmin(v);
            }
        }
    }
    println!("{}", ans);
    /*
    let s = s.into_iter().map(|s| (s - b'0') as i32).collect::<Vec<_>>();
    let mut map = Map::new();
    let ans = dfs(s.len(), 100, 100, 0, &s, &mut map);
    println!("{}", ans);
    */
}

fn main() {
    run();
}

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;

// 下の桁からdpっぽく?
// +がいくつ、-がいくつ、暫定carryがいくつ
// この時1を幾つで合わせられるか的な
// MLE
// なんか状態多いっぽいが
//
//

const INF: i32 = 100000;

fn dfs(
    pos: usize,
    add: i32,
    sub: i32,
    carry: i32,
    s: &[i32],
    dp: &mut Map<(usize, i32, i32, i32), i32>,
) -> i32 {
    if let Some(&v) = dp.get(&(pos, add, sub, carry)) {
        return v;
    }
    if pos == 0 {
        return if carry == 0 {
            0
        } else if carry > 0 && sub >= carry {
            carry
        } else if carry < 0 && add >= -carry {
            -carry
        } else {
            INF
        };
    }
    let mut ans = INF;
    if add > 0 {
        ans = ans.min(dfs(pos, add - 1, sub, carry, s, dp));
    }
    if sub > 0 {
        ans = ans.min(dfs(pos, add, sub - 1, carry, s, dp));
    }
    let d = add - sub + carry;
    if d.rem_euclid(10) == s[pos - 1] {
        let carry = d.div_euclid(10);
        ans = ans.min(dfs(pos - 1, add, sub, carry, s, dp) + add + sub);
    }
    dp.insert((pos, add, sub, carry), ans);
    ans
}

fn run() {
    input!(s: bytes);
    let m = 100;
    let geta = 11;
    let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
    dp[geta] = vec![vec![0; m + 1]; m + 1];
    for &s in s.iter().rev() {
        let s = (s - b'0') as i32;
        let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];
        for (carry, dp) in dp.iter().enumerate() {
            for (add, dp) in dp.iter().enumerate() {
                for (sub, dp) in dp.iter().enumerate() {
                    if *dp == INF {
                        continue;
                    }
                    let carry = carry as i32 - geta as i32;
                    let d = add as i32 - sub as i32 + carry;
                    if d.rem_euclid(10) != s {
                        continue;
                    }
                    let carry = (d.div_euclid(10) + geta as i32) as usize;
                    next[carry][add][sub].chmin(*dp + (add + sub) as i32);
                }
            }
        }
        dp = next;
        for dp in dp.iter_mut() {
            for i in (0..m).rev() {
                for j in (0..m).rev() {
                    dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);
                }
            }
        }
    }
    let mut ans = INF;
    for (carry, dp) in dp.iter().enumerate() {
        for (add, dp) in dp.iter().enumerate() {
            for (sub, dp) in dp.iter().enumerate() {
                let carry = carry as i32 - geta as i32;
                let add = add as i32;
                let sub = sub as i32;
                let mut v = *dp;
                if carry == 0 {
                } else if carry > 0 && sub >= carry {
                    v += carry;
                } else if carry < 0 && add >= -carry {
                    v += carry;
                } else {
                    v += INF;
                }
                ans.chmin(v);
            }
        }
    }
    println!("{}", ans);
    /*
    let s = s.into_iter().map(|s| (s - b'0') as i32).collect::<Vec<_>>();
    let mut map = Map::new();
    let ans = dfs(s.len(), 100, 100, 0, &s, &mut map);
    println!("{}", ans);
    */
}

fn main() {
    run();
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::collections::*;
use std::io::Write;

type Map<K, V> = HashMap<K, V>;

// 下の桁からdpっぽく?
// +がいくつ、-がいくつ、暫定carryがいくつ
// この時1を幾つで合わせられるか的な

const INF: i32 = 100000;

fn dfs(
    pos: usize,
    add: i32,
    sub: i32,
    carry: i32,
    s: &[i32],
    dp: &mut Map<(usize, i32, i32, i32), i32>,
) -> i32 {
    if let Some(&v) = dp.get(&(pos, add, sub, carry)) {
        return v;
    }
    if pos == 0 {
        return if carry == 0 {
            0
        } else if carry > 0 && sub >= carry {
            carry
        } else if carry < 0 && add >= -carry {
            carry
        } else {
            INF
        };
    }
    let mut ans = INF;
    if add > 0 {
        ans = ans.min(dfs(pos, add - 1, sub, carry, s, dp));
    }
    if sub > 0 {
        ans = ans.min(dfs(pos, add, sub - 1, carry, s, dp));
    }
    let d = add - sub + carry;
    if d.rem_euclid(10) == s[pos - 1] {
        let carry = d.div_euclid(10);
        ans = ans.min(dfs(pos - 1, add, sub, carry, s, dp) + add + sub);
    }
    dp.insert((pos, add, sub, carry), ans);
    ans
}

fn run() {
    input!(s: bytes);
    let s = s.into_iter().map(|s| (s - b'0') as i32).collect::<Vec<_>>();
    let mut map = Map::new();
    let ans = dfs(s.len(), 100, 100, 0, &s, &mut map);
    println!("{}", ans);
}

fn main() {
    run();
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

// vec with some initial value
#[allow(unused_macros)]
macro_rules! vvec {
    ($($x:expr),+; $y:expr; $n:expr) => {{
        let mut v = vec![$y; $n];

        let mut it = v.iter_mut();
        $(
            *it.next().unwrap() = $x;
        )+

        v
    }}
}

#[allow(unused_macros)]
macro_rules! it {
    ($x:expr) => {
        once($x)
    };
    ($first:expr,$($x:expr),+) => {
        chain(
            once($first),
            it!($($x),+)
        )
    }
}

#[allow(unused_macros)]
macro_rules! pushed {
    ($c:expr, $x:expr) => {{
        let mut c = $c;
        c.push($x);
        c
    }};
}

#[allow(unused_macros)]
macro_rules! inserted {
    ($c:expr, $($x:expr),*) => {{
        let mut c = $c;
        c.insert($($x),*);
        c
    }};
}

#[allow(unused_macros)]
macro_rules! read_tuple {
    ($($t:ty),+) => {{
        let mut line = String::new();
        io::stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_str() -> Vec<char> {
    read::<String>().chars().collect()
}

#[allow(dead_code)]
fn read_row<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_col<T: FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

#[allow(dead_code)]
fn read_mat<T: FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_row()).collect()
}

#[allow(dead_code)]
fn read_vec<R, F: FnMut() -> R>(n: usize, mut f: F) -> Vec<R> {
    (0..n).map(|_| f()).collect()
}

trait IterCopyExt<'a, T>: IntoIterator<Item = &'a T> + Sized
where
    T: 'a + Copy,
{
    fn citer(self) -> std::iter::Copied<Self::IntoIter> {
        self.into_iter().copied()
    }
}

impl<'a, T, I> IterCopyExt<'a, T> for I
where
    I: IntoIterator<Item = &'a T>,
    T: 'a + Copy,
{
}

// const B: usize = 500;
const B: usize = 22;
const C: usize = 5;

// fn solve(
//     n: &[usize],
//     carry: usize,
//     plus_max: usize,
//     minus_max: usize,
//     memo: &mut Vec<Vec<Vec<Vec<Option<Option<(usize, usize, usize)>>>>>>,
// ) -> Option<(usize, usize, usize)> {
//     if let Some(ret) = memo[n.len()][carry][plus_max][minus_max] {
//         return ret;
//     }

//     let ret = if plus_max >= B || minus_max >= B {
//         None
//     } else if n.is_empty() {
//         if plus_max >= carry {
//             Some((carry, carry, 0))
//         } else {
//             None
//         }
//     } else {
//         let d = *n.last().unwrap() + carry;

//         (0..=C)
//             .filter_map(|c| {
//                 // make -c*10 + d
//                 if plus_max + 10 * c < d || minus_max + d < 10 * c {
//                     None
//                 } else {
//                     solve(
//                         &n[0..n.len() - 1],
//                         c,
//                         min(plus_max, minus_max + d - 10 * c),
//                         min(minus_max, plus_max + 10 * c - d),
//                         memo,
//                     )
//                     .map(|t| {
//                         let x = if t.2 + d >= 10 * c {
//                             max(t.1, t.2 + d - 10 * c)
//                         } else {
//                             t.1
//                         };
//                         let y = if t.1 + 10 * c >= d {
//                             max(t.1 + 10 * c - d, t.2)
//                         } else {
//                             t.2
//                         };
//                         (t.0 + x + y, x, y)
//                     })
//                 }
//             })
//             .min()
//     };

//     // eprintln!("{} {} {} {} {:?}", n.len(), carry, plus_max, minus_max, ret);
//     memo[n.len()][carry][plus_max][minus_max] = Some(ret);

//     ret
// }

fn main() {
    let n = read::<String>()
        .chars()
        .map(|c| c.to_digit(10).unwrap() as usize)
        .collect::<Vec<_>>();

    let dp = n.citer().fold(
        (0..=C)
            .map(|t| {
                (0..B)
                    .map(|i| {
                        if i < t {
                            vec![usize::MAX; B]
                        } else {
                            vec![t; B]
                        }
                    })
                    .collect::<Vec<_>>()
            })
            .collect::<Vec<_>>(),
        |prev, d| {
            // eprintln!("{:?}", prev);
            (0..=C)
                .map(|t| {
                    let d = d + t;
                    let mut dp = (0..B)
                        .map(|i| {
                            let mut v = vec![usize::MAX; B];

                            (0..=C).for_each(|c| {
                                if i + 10 * c >= d && i + 10 * c < B + d {
                                    let j = i + 10 * c - d;
                                    v[j] = prev[c][i][j].saturating_add(i + j);
                                }
                            });

                            v
                        })
                        .collect::<Vec<_>>();
                    for i in 0..B {
                        for j in 0..B {
                            if i > 0 {
                                dp[i][j] = min(dp[i][j], dp[i - 1][j]);
                            }
                            if j > 0 {
                                dp[i][j] = min(dp[i][j], dp[i][j - 1]);
                            }
                        }
                    }
                    dp
                })
                .collect::<Vec<_>>()
        },
    );
    let ans = dp[0][B - 1][B - 1];
    println!("{}", ans);

    // let mut memo = vec![vec![vec![vec![None; B]; B]; C + 1]; n.len() + 1];
    // let ans2 = (0..B)
    //     .filter_map(|i| (0..B).filter_map(|j| solve(&n, 0, i, j, &mut memo)).min())
    //     .min()
    //     .unwrap()
    //     .0;
    // println!("{}", ans2);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

// vec with some initial value
#[allow(unused_macros)]
macro_rules! vvec {
    ($($x:expr),+; $y:expr; $n:expr) => {{
        let mut v = vec![$y; $n];

        let mut it = v.iter_mut();
        $(
            *it.next().unwrap() = $x;
        )+

        v
    }}
}

#[allow(unused_macros)]
macro_rules! it {
    ($x:expr) => {
        once($x)
    };
    ($first:expr,$($x:expr),+) => {
        chain(
            once($first),
            it!($($x),+)
        )
    }
}

#[allow(unused_macros)]
macro_rules! pushed {
    ($c:expr, $x:expr) => {{
        let mut c = $c;
        c.push($x);
        c
    }};
}

#[allow(unused_macros)]
macro_rules! inserted {
    ($c:expr, $($x:expr),*) => {{
        let mut c = $c;
        c.insert($($x),*);
        c
    }};
}

#[allow(unused_macros)]
macro_rules! read_tuple {
    ($($t:ty),+) => {{
        let mut line = String::new();
        io::stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_str() -> Vec<char> {
    read::<String>().chars().collect()
}

#[allow(dead_code)]
fn read_row<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_col<T: FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

#[allow(dead_code)]
fn read_mat<T: FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_row()).collect()
}

#[allow(dead_code)]
fn read_vec<R, F: FnMut() -> R>(n: usize, mut f: F) -> Vec<R> {
    (0..n).map(|_| f()).collect()
}

trait IterCopyExt<'a, T>: IntoIterator<Item = &'a T> + Sized
where
    T: 'a + Copy,
{
    fn citer(self) -> std::iter::Copied<Self::IntoIter> {
        self.into_iter().copied()
    }
}

impl<'a, T, I> IterCopyExt<'a, T> for I
where
    I: IntoIterator<Item = &'a T>,
    T: 'a + Copy,
{
}

fn main() {
    let n = read::<String>()
        .chars()
        .map(|c| c.to_digit(10).unwrap() as usize)
        .collect::<Vec<_>>();

    const B: usize = 500;

    let dp = n.citer().fold(
        vec![
            vec![vec![0usize; B]; B],
            vvec![vec![usize::MAX; B]; vec![1usize; B]; B],
        ],
        |prev, d| {
            // eprintln!("{:?}", prev);
            (0..2)
                .map(|t| {
                    let d = d + t;
                    let mut dp = (0..B)
                        .map(|i| {
                            let mut v = vec![usize::MAX; B];

                            if i >= d {
                                v[i - d] = prev[0][i][i - d].saturating_add(i + (i - d));
                            }

                            if i + 10 >= d && i + 10 - d < B {
                                v[i + 10 - d] =
                                    prev[1][i][i + 10 - d].saturating_add(i + (i + 10 - d))
                            }

                            v
                        })
                        .collect::<Vec<_>>();
                    for i in 0..B {
                        for j in 0..B {
                            if i > 0 {
                                dp[i][j] = min(dp[i][j], dp[i - 1][j]);
                            }
                            if j > 0 {
                                dp[i][j] = min(dp[i][j], dp[i][j - 1]);
                            }
                        }
                    }
                    dp
                })
                .collect::<Vec<_>>()
        },
    );
    let ans = dp[0][B - 1][B - 1];
    println!("{}", ans);
}