//spnauti-rusT {{{ #[allow(unused_imports)] use std::cell::*; #[allow(unused_imports)] use std::cmp::Ordering::{self, *}; #[allow(unused_imports)] use std::collections::*; use std::fmt::Debug; use std::io::*; #[allow(unused_imports)] use std::iter::{self, *}; #[allow(unused_imports)] use std::ops::{self, *}; use std::str::{self, *}; #[allow(unused_macros)] macro_rules! m { ($c:tt,$x:expr,$y:expr) => {{ let b = $y; let a = &mut$x; if b$c * a { *a = b; true } else { false } }}; } #[allow(unused_macros)] macro_rules! l { ($($v:ident),+ =$e:expr) => {$(let$v=$e;)+}; ($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+}; (mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+}; (mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+}; } #[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} } #[allow(unused_macros)] fn reader() -> WordReaderC { WordReaderC::new() } #[allow(unused_macros)] fn writer() -> BufWriter { BufWriter::new(stdout()) } struct WordReaderC { buf: Vec, pos: usize, q: std::io::StdinLock<'static>, } //' #[allow(dead_code)] impl WordReaderC { fn new() -> Self { let r = unsafe { &*Box::into_raw(Box::new(stdin())) }; Self { q: r.lock(), buf: Vec::new(), pos: 0, } } fn next_line(&mut self) -> bool { self.buf.clear(); self.pos = 0; self.q.read_until(b'\n', &mut self.buf).unwrap_or(0) > 0 } fn is_ws(c: u8) -> bool { c == b' ' || c == b'\r' || c == b'\n' || c == b'\t' } fn byte(&mut self) -> Option { if self.pos == self.buf.len() { if !self.next_line() { return None; } } self.pos += 1; Some(self.buf[self.pos - 1]) } fn vb(&mut self) -> Vec { let mut s = Vec::with_capacity(8); let mut f = false; loop { if let Some(c) = self.byte() { if !Self::is_ws(c) { s.push(c); f = true; } else if f { break; } } else { break; } } s } fn s(&mut self) -> String { String::from_utf8(self.vb()).expect("invalid utf8") } fn i(&mut self) -> i32 { self.p() } fn l(&mut self) -> i64 { self.p() } fn u(&mut self) -> usize { self.p() } fn f(&mut self) -> f64 { self.p() } fn vi(&mut self, n: usize) -> Vec { self.vp(n) } fn vl(&mut self, n: usize) -> Vec { self.vp(n) } fn vu(&mut self, n: usize) -> Vec { self.vp(n) } fn ii(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() } fn iu(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() } fn p(&mut self) -> T where T::Err: Debug, { let w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::().unwrap() } fn vp(&mut self, n: usize) -> Vec where T::Err: Debug, { (0..n).map(|_| self.p()).collect() } fn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug, { self.vp(n).into_iter() } } //------------------- End rusT }}} fn next_permutation(a: &mut [T]) -> bool { let n = a.len(); for i in (0..n - 1).rev() { if a[i] < a[i + 1] { for j in (i + 1..n).rev() { if a[i] < a[j] { a.swap(i, j); break; } } a[i + 1..n].reverse(); return true; } } false } fn main() { let mut rin = reader(); let mut rout = writer(); let mut s = rin.vb(); s.sort(); let mut sol = Vec::new(); sol.push(s.clone()); while next_permutation(&mut s) { sol.push(s.clone()); } writeln!(rout, "{}", sol.len()).ok(); for a in sol { writeln!(rout, "{}", String::from_utf8(a).unwrap()).ok(); } }