#![allow(unused_must_use, non_snake_case, unused_labels, unused_imports, non_upper_case_globals)] use external::*; use cplib::prelude::*; use nest as vec; const INTERACTIVE: bool = false; // const INTERACTIVE: bool = true; use input_interactive as input; fn solve() { input! { _: usize, S: chars } !out << "UEC"; let mut f = false; for c in S { if f { !out << c; } else if c == 'c' { f = true; } } } fn main() { out::init(INTERACTIVE || !SUBMISSION); solve(); out::print() } // You can view my cp-library at https://github.com/solalyth/cplib-rs mod cplib { #![allow(unused_macros, dead_code)] pub const SUBMISSION: bool = true; pub mod prelude { pub use std::{ collections::{VecDeque, HashMap, HashSet, BTreeMap, BTreeSet, BinaryHeap}, cmp::{Ordering, Reverse}, mem::{swap, replace} }; pub use crate::cplib::{ *, SUBMISSION, ds::segtree::SegtreeOp, util::{ output::{out, end}, traits::*, func::binary_search }, }; use std::fmt; #[derive(Clone, Copy, PartialEq, PartialOrd)] pub struct F64(pub f64); impl Eq for F64 {} impl Ord for F64 { fn cmp(&self, other: &Self) -> Ordering { self.partial_cmp(other).unwrap() } } impl fmt::Debug for F64 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) } } } pub mod ds { pub mod unionfind { use std::fmt::Debug; use crate::cplib::util::func::join; pub trait Abelian { type T: Clone + Eq; fn e() -> Self::T; fn add(l: &Self::T, r: &Self::T) -> Self::T; fn inv(x: &Self::T) -> Self::T; fn sub(l: &Self::T, r: &Self::T) -> Self::T { Self::add(l, &Self::inv(r)) } } pub struct Nop; impl Abelian for Nop { type T = (); fn e() {} fn add(_: &(), _: &()) {} fn inv(_: &()) {} } pub struct UnionFind { par: Vec, size: Vec, diff: Vec, next: Vec } impl UnionFind { pub fn new_nop(len: usize) -> Self { Self::new(len) } } impl UnionFind { pub fn new(len: usize) -> Self { UnionFind { par: (0..len).collect(), size: vec![1; len], diff: vec![Op::e(); len], next: (0..len).collect() } } pub fn clear(&mut self) { for i in 0..self.len() { self.par[i] = i; self.size[i] = 1; self.diff[i] = Op::e(); self.next[i] = i; } } pub fn extend(&mut self, len: usize) { let bef = self.len(); self.par.extend(bef..len); self.size.resize(len, 1); self.diff.resize(len, Op::e()); self.next.extend(bef..len); } pub fn len(&self) -> usize { self.par.len() } pub fn leader(&mut self, i: usize) -> usize { let p = self.par[i]; if self.par[p] == p { return p; } let u = self.leader(p); self.diff[i] = Op::add(&self.diff[i], &self.diff[p]); self.par[i] = u; u } pub fn size(&mut self, mut i: usize) -> usize { i = self.leader(i); self.size[i] } pub fn is_same(&mut self, i: usize, j: usize) -> bool { self.leader(i) == self.leader(j) } pub fn diff(&mut self, i: usize, j: usize) -> Op::T { assert!(self.is_same(i, j)); Op::sub(&self.diff[i], &self.diff[j]) } pub fn merge(&mut self, i: usize, j: usize, mut w: Op::T) -> Option<(usize, usize)> { let (mut u, mut v) = (self.leader(i), self.leader(j)); w = Op::sub(&Op::add(&w, &self.diff[j]), &self.diff[i]); if u == v { return if w == Op::e() { Some((u, !0)) } else { None } } if !(self.size[u] < self.size[v]) { (u, v) = (v, u); w = Op::inv(&w); } self.par[u] = v; self.diff[u] = w; self.size[v] += self.size[u]; self.next.swap(i, j); Some((v, u)) } pub fn groups(&mut self) -> Vec> { let mut res = crate::nest![void; self.len()]; for i in 0..self.len() { res[self.leader(i)].push(i); } res } pub fn group(&self, i: usize) -> Vec { let (mut res, mut j) = (vec![i], self.next[i]); while j != i { res.push(j); j = self.next[j]; } res } pub fn leaders(&self) -> Vec { (0..self.len()).filter(|&i| self.par[i] == i).collect() } } impl Clone for UnionFind { fn clone(&self) -> Self { Self { par: self.par.clone(), size: self.size.clone(), diff: self.diff.clone(), next: self.next.clone() } } } impl std::fmt::Debug for UnionFind where Op::T: Debug { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut uf = self.clone(); let g = uf.groups().into_iter().map(|s| { join(s.into_iter().map(|i| format!("{i}({:?})", uf.diff[i]).trim_end_matches("(())").into())).unwrap() }); write!(f, "[{}]", join(g.into_iter().map(|s| format!("{{{s}}}"))).unwrap_or(String::new())) } } } pub mod segtree { use std::{fmt::Debug, mem::replace, ops::{Index, IndexMut, RangeBounds}, slice::SliceIndex}; use crate::cplib::util::func::to_bounds; #[allow(unused_variables)] pub trait SegtreeOp: Sized { type Value: Clone + Debug; type Lazy: Clone; fn id_value() -> Self::Value; fn prod_value(lhs: &Self::Value, rhs: &Self::Value) -> Self::Value; fn act_value(value: &mut Self::Value, lazy: &Self::Lazy) {} fn prod_lazy(lazy: &mut Self::Lazy, ad: &Self::Lazy) {} fn segtree_new(len: usize) -> Segtree { Segtree::new(len) } fn segtree_from_iter(iter: impl Iterator) -> Segtree { Segtree::from_iter(iter) } } pub struct Segtree { tree: Vec, lazy: Vec>, depth: u32 } impl Segtree { pub fn new(len: usize) -> Self { let depth = (len.max(2)-1).ilog2() + 2; Segtree { tree: vec![Op::id_value(); 1< usize { 1 << self.depth-1 } pub fn get(&mut self, mut i: usize) -> &Op::Value { i += self.len(); for j in (1..self.depth).rev() { self.push(i >> j); } &self.tree[i] } pub fn set(&mut self, mut i: usize, f: impl FnOnce(&mut Op::Value)) { i += self.len(); for j in (1..self.depth).rev() { self.push(i >> j); } f(&mut self.tree[i]); for j in 1..self.depth { self.update(i >> j); } } pub fn entry(&mut self) -> Entry<'_, Op> { for i in 1..self.len() { self.push(i); } Entry { seg: self, changed: false } } pub fn fold(&mut self, range: impl RangeBounds) -> Op::Value { let [mut l, mut r] = to_bounds(range, self.len()).map(|v| v+self.len()); if r == self.len() { return Op::id_value(); } let (mut rl, mut rr) = (Op::id_value(), Op::id_value()); for i in (1..self.depth).rev() { self.push(l >> i); self.push(r-1 >> i); } while l < r { if l&1 == 1 { rl = Op::prod_value(&rl, &self.tree[l]); l += 1; } if r&1 == 1 { rr = Op::prod_value(&self.tree[r-1], &rr); } l >>= 1; r >>= 1; } Op::prod_value(&rl, &rr) } pub fn apply_lazy(&mut self, range: impl RangeBounds, lazy: Op::Lazy) { let [l, r] = to_bounds(range, self.len()).map(|v| v + self.len()); if r == self.len() { return; } for i in (1..self.depth).rev() { self.push(l >> i); self.push(r-1 >> i); } let (mut s, mut t) = (l, r); while s < t { if s&1 == 1 { Op::act_value(&mut self.tree[s], &lazy); self.comp_lazy(s, &lazy); s += 1; } if t&1 == 1 { t -= 1; Op::act_value(&mut self.tree[t], &lazy); self.comp_lazy(t, &lazy); } s >>= 1; t >>= 1; } for i in 1..self.depth { if ((l >> i) << i) != l { self.update(l >> i); } if ((r >> i) << i) != r { self.update(r-1 >> i); } } } pub fn max_right(&mut self, l: usize, f: impl Fn(&Op::Value) -> bool) -> usize { assert!(l <= self.len()); if l == self.len() { return self.len(); } let (mut r, mut val) = (l + self.len(), Op::id_value()); for i in (1..self.depth).rev() { self.push(r >> i); } loop { while r&1 == 0 { r >>= 1; } let tmp = Op::prod_value(&val, &self.tree[r]); if !f(&tmp) { break; } val = tmp; r += 1; if r & r-1 == 0 { return self.len(); } } while r < self.len() { self.push(r); r *= 2; let tmp = Op::prod_value(&val, &self.tree[r]); if f(&tmp) { val = tmp; r += 1; } } r - self.len() } pub fn min_left(&mut self, r: usize, f: impl Fn(&Op::Value) -> bool) -> usize { assert!(r <= self.len()); if r == 0 { return 0; } let (mut l, mut val) = (r + self.len(), Op::id_value()); for i in (1..self.depth).rev() { self.push(l-1 >> i); } loop { l -= 1; while l != 1 && l&1 == 1 { l >>= 1; } let tmp = Op::prod_value(&self.tree[l], &val); if !f(&tmp) { break; } val = tmp; if l & l-1 == 0 { return 0; } } while l < self.len() { self.push(l); l = 2*l + 1; let tmp = Op::prod_value(&self.tree[l], &val); if f(&tmp) { val = tmp; l -= 1; } } l+1 - self.len() } #[track_caller] fn push(&mut self, i: usize) { debug_assert!(i != 0); debug_assert!(i < self.len()); let Some(lazy) = replace(&mut self.lazy[i], None) else { return }; Op::act_value(&mut self.tree[2*i], &lazy); Op::act_value(&mut self.tree[2*i+1], &lazy); self.comp_lazy(2*i, &lazy); self.comp_lazy(2*i+1, &lazy); } fn update(&mut self, i: usize) { debug_assert!(i < self.len()); debug_assert!(self.lazy[i].is_none()); self.tree[i] = Op::prod_value(&self.tree[2*i], &self.tree[2*i+1]); } fn comp_lazy(&mut self, i: usize, ad: &Op::Lazy) { if let Some(lazy) = &mut self.lazy[i] { Op::prod_lazy(lazy, ad); } else { self.lazy[i] = Some(ad.clone()); } } } impl Clone for Segtree { fn clone(&self) -> Self { Self { tree: self.tree.clone(), lazy: self.lazy.clone(), depth: self.depth.clone() } } } impl Debug for Segtree where Op::Value: Debug { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut seg = self.clone(); for i in 1..seg.len() { seg.push(i); } write!(f, "{:?}", &seg.tree[self.len()..]) } } impl FromIterator for Segtree { fn from_iter>(iter: T) -> Self { let v = iter.into_iter().collect::>(); let mut seg = Self::new(v.len()); let len = seg.len(); for (i, v) in v.into_iter().enumerate() { seg.tree[len+i] = v; } for i in (1..seg.len()).rev() { seg.update(i); } seg } } pub struct Entry<'a, Op: SegtreeOp> { seg: &'a mut Segtree, changed: bool } impl> Index for Entry<'_, Op> { type Output = I::Output; fn index(&self, index: I) -> &Self::Output { Index::index(&self.seg.tree[self.seg.len()..], index) } } impl> IndexMut for Entry<'_, Op> { fn index_mut(&mut self, index: I) -> &mut Self::Output { let len = self.seg.len(); self.changed = true; IndexMut::index_mut(&mut self.seg.tree[len..], index) } } impl Drop for Entry<'_, Op> { fn drop(&mut self) { if self.changed { for i in (1..self.seg.len()).rev() { self.seg.update(i); } } } } } pub mod trie { use std::fmt::Debug; pub struct Trie { dat: Vec, len: usize } impl Trie { pub fn new() -> Self { Self { dat: vec![!0; (N+1)*1024], len: 1 } } pub fn len(&self) -> usize { self.len } fn new_cell(&mut self) -> usize { if self.dat.len() == self.len * (N+1) { let len = self.dat.len()/(N+1); self.dat.resize(len*(N+1)*2, !0); for i in len..len*2 { self.dat[i*(N+1)+N] = 0; } } self.len += 1; self.len - 1 } pub fn parent(&self, idx: usize) -> Option { assert!(idx < self.len); if idx != 0 { Some(self.dat[idx*(N+1)+N]) } else { None } } pub fn check_next(&self, idx: usize, c: usize) -> Option { assert!(c < N); if self.dat[idx*(N+1)+c] != !0 { Some(self.dat[idx*(N+1)+c]) } else { None } } pub fn next(&mut self, idx: usize, c: usize) -> usize { assert!(c < N); if self.dat[idx*(N+1)+c] == !0 { let nx = self.new_cell(); self.dat[idx*(N+1)+c] = nx; self.dat[nx*(N+1)+N] = idx; } self.dat[idx*(N+1)+c] } pub fn insert(&mut self, s: impl Iterator) -> Vec { let mut res = vec![0]; let mut cur = 0; for c in s { cur = self.next(cur, c); res.push(cur); } res } pub fn aho_corasick(&self) -> (Vec, Vec) { let mut ac = vec![0; self.len]; let mut que = vec![0]; while let Some(p) = que.pop() { for c in 0..N { let c = self.dat[p*(N+1)+c]; if c == !0 { continue; } let mut cur = p; ac[c] = loop { if cur == 0 { break 0; } cur = ac[cur]; if self.dat[cur*(N+1)+c] != !0 { break self.dat[cur*(N+1)+c]; } }; que.push(c); } } let mut ac_nx = vec![0; self.len*N]; for i in 0..ac.len() { for c in 0..N { let mut cur = i; ac_nx[i*N+c] = loop { if self.dat[cur*(N+1)+c] != !0 { break self.dat[cur*(N+1)+c]; } if cur == 0 { break cur; } cur = ac[cur]; }; } } (ac, ac_nx) } } impl Debug for Trie { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut tmp = vec![None; self.len]; tmp[0] = Some(String::new()); let mut stk = vec![0]; while let Some(i) = stk.pop() { for c in 0..N { let nx = self.dat[i*(N+1)+c]; if nx == !0 { continue; } let mut s = tmp[i].clone().unwrap(); s.push((b'a' + c as u8) as char); tmp[nx] = Some(s); stk.push(nx); } } let mut res = String::from(""); for s in &tmp[1..] { res += ", "; if let Some(s) = s { res += s; } else { res += "*"; } } write!(f, "[@{res}]") } } } } pub mod algo { pub mod func { pub fn next_permutation(v: &mut [T]) -> bool { let Some(i) = v.windows(2).rposition(|w| w[0] < w[1]) else { return false; }; let j = v.iter().rposition(|e| e > &v[i]).unwrap(); v.swap(i, j); v[i+1..].reverse(); true } pub fn prev_permutation(v: &mut [T]) -> bool { let Some(i) = v.windows(2).rposition(|w| w[0] > w[1]) else { return false; }; let j = v.iter().rposition(|e| e < &v[i]).unwrap(); v.swap(i, j); v[i+1..].reverse(); true } pub fn run_length(iter: impl IntoIterator) -> Vec<(T, usize)> { let mut res = vec![]; for t in iter { let Some(l) = res.last_mut() else { res.push((t, 1)); continue; }; if t == l.0 { l.1 += 1; } else { res.push((t, 1)); } } res } } } pub mod graph { } pub mod abstracts { use std::fmt::Debug; pub struct Nop; pub trait Monoid: Sized { type T: Clone + PartialEq + Debug; fn e() -> Self::T; fn prod(l: &Self::T, r: &Self::T) -> Self::T; } pub trait Group { type T: Clone + PartialEq + Debug; fn e() -> Self::T; fn add(l: &Self::T, r: &Self::T) -> Self::T; fn inv(x: &Self::T) -> Self::T; fn sub(l: &Self::T, r: &Self::T) -> Self::T { Self::add(l, &Self::inv(r)) } } impl Group for Nop { type T = (); fn e() {} fn add(_: &(), _: &()) {} fn inv(_: &()) {} } } pub mod math { pub mod func { pub fn gcd(mut a: usize, mut b: usize) -> usize { while b != 0 { (a, b) = (b, a%b); } a } pub fn lcm(a: usize, b: usize) -> Option { (a/gcd(a, b)).checked_mul(b) } pub fn extended_gcd(mut a: i64, mut b: i64) -> (i64, i64, i64) { if (a, b) == (0, 0) { return (0, 0, 0); } let mut st = vec![]; while b != 0 { st.push(a/b); (a, b) = (b, a%b); } let (mut x, mut y) = (a.signum(), 0); for z in st.into_iter().rev() { (x, y) = (y, x - z*y); } (x, y, a.abs()) } pub fn modinv(x: usize, m: usize) -> Option { let (x, _, g) = extended_gcd(x as i64, m as i64); if g == 1 { Some(x.rem_euclid(m as i64) as usize) } else { None } } pub fn mpow(mut x: usize, mut n: usize, m: usize) -> usize { x %= m; if n == 0 { return if x == 0 {0} else {1}; } let mut res = 1; while n != 0 { if n&1 == 1 { res = res*x % m; } x = x*x % m; n >>= 1; } res } pub fn quotient_floor(n: usize) -> Vec<(usize, usize, usize)> { let mut res = vec![]; let b = (n as f64).sqrt() as usize + 1; for i in 1..=n/b { res.push((i, i+1, n/i)); } for x in (1..b).rev() { let l = n/(x+1); let r = n/x; if l != r { res.push((l+1, r+1, x)); } } res } pub fn quotient_ceil(n: usize) -> Vec<(usize, usize, usize)> { let mut res = vec![]; let b = (n as f64).sqrt() as usize+2; for i in 1..(n+b-1)/b { res.push((i, i+1, (n+i-1)/i)); } for x in (2..b).rev() { let l = (n+x-1)/x; let r = (n+x-2)/(x-1); if l != r { res.push((l, r, x)); } } res.push((n, n+1, 1)); res } pub fn partitions(n: usize, k: usize) -> Vec> { let mut cur = vec![0; k]; cur[k-1] = n; let mut res = vec![cur.clone()]; while cur[0] != n { for i in (1..k).rev() { if cur[i] != 0 { cur[k-1] = std::mem::replace(&mut cur[i], 0)-1; cur[i-1] += 1; break; } } debug_assert!(cur.iter().sum::() == n); res.push(cur.clone()); } res } } pub mod prime { use std::ops::{Add, Sub}; const MASK_29BIT: usize = (1<<29)-1; pub struct LpfSieve { primes: Vec, table: Vec, } impl LpfSieve { pub fn new(mut max: usize) -> Self { assert!(usize::BITS == 64); max = max.max(10); let mut primes = vec![]; let mut table = vec![0; max+1]; for i in 2..=max { if table[i] == 0 { primes.push(i); table[i] = (1 << 58) + (i << 29) + 1; } let lpf_i = (table[i] >> 29) & MASK_29BIT; for &p in &primes { if !(p <= lpf_i && i*p <= max) { break; } table[p*i] = if p == lpf_i { table[i] + (1 << 58) } else { (1 << 58) + (p << 29) + i }; } } Self { primes, table } } pub fn max(&self) -> usize { self.table.len()-1 } pub fn primes(&self) -> &[usize] { &self.primes } pub fn is_prime(&self, n: usize) -> bool { (self.table[n] >> 29) & MASK_29BIT == n } pub fn data(&self, n: usize) -> (usize, usize, usize) { assert!(2 <= n); ((self.table[n] >> 29) & MASK_29BIT, self.table[n] >> 58, self.table[n] & MASK_29BIT) } pub fn fold(&self, mut n: usize, mut init: T, mut f_vpe: impl FnMut(&mut T, usize, usize)) -> T { assert!(n != 0); while n != 1 { let (lpf, exp, nx) = self.data(n); f_vpe(&mut init, lpf, exp); n = nx; } init } pub fn factorize(&self, n: usize) -> Vec<(usize, usize)> { self.fold(n, vec![], |v, p, e| { v.push((p, e)); } ) } pub fn factorize_big(&self, mut n: usize) -> Vec<(usize, usize)> { assert_ne!(n, 0); let mut res = vec![]; for &p in &self.primes { let mut cnt = 0; while n%p == 0 { cnt += 1; n /= p; } if cnt != 0 { res.push((p, cnt)); } if n < p*p { break; } } if n != 1 { res.push((n, 1)); } res } pub fn divisors(&self, n: usize) -> Vec { assert!(n != 0); self.fold(n, vec![1], |v, p, e| { for i in 0..v.len() { let mut k = 1; for _ in 0..e { k *= p; v.push(v[i]*k); } } }) } pub fn totient_point(&self, n: usize) -> usize { self.fold(n, n, |v, p, _e| { *v -= *v/p; }) } pub fn totient(&self, n: usize) -> Vec { let mut res = vec![0; n+1]; res[1] = 1; for i in 2..=n { let (lpf, exp, _nx) = self.data(i); res[i] = res[i/lpf] * if exp == 1 { lpf-1 } else { lpf }; } res } pub fn mobius_point(&self, n: usize) -> i64 { self.fold(n, 1, |v, _p, e| { *v = if e == 1 { -*v } else { 0 }; }) } pub fn mobius(&self, n: usize) -> Vec { let mut res = vec![0; n+1]; res[1] = 1; for i in 2..=n { let (_lpf, exp, nx) = self.data(i); if exp == 1 { res[i] = -res[nx]; } } res } pub fn div_zeta>(&self, mut f: Vec) -> Vec { let vl = f.len()-1; for &p in self.primes() { if vl < p { break; } for i in 1..=vl/p { f[i*p] = f[i*p] + f[i]; } } f } pub fn div_mobius>(&self, mut g: Vec) -> Vec { let vl = g.len()-1; for &p in self.primes() { if vl < p { break; } for i in (1..=vl/p).rev() { g[i*p] = g[i*p] - g[i]; } } g } pub fn div_mobius_point + Sub>(&self, g: &[T], idx: usize) -> T { let mut res = T::default(); for i in self.fold(idx, vec![1i32], |v, p, _| { for i in 0..v.len() { v.push(-v[i] * p as i32); } }) { if 0 <= i { res = res + g[idx/i as usize]; } else { res = res - g[idx/-i as usize]; } } res } pub fn mul_zeta>(&self, mut f: Vec) -> Vec { let vl = f.len() - 1; for &p in self.primes() { if vl < p { break; } for i in (1..=vl/p).rev() { f[i] = f[i] + f[i*p]; } } f } pub fn mul_mobius>(&self, mut g: Vec) -> Vec { let vl = g.len() - 1; for &p in self.primes() { if vl < p { break; } for i in 1..=vl/p { g[i*p] = g[i*p] - g[i]; } } g } pub fn mul_mobius_point + Sub>(&self, g: &[T], idx: usize) -> T { let mut res = T::default(); let gl = g.len() - 1; let t = self.mobius(gl/idx); for (i, m) in t.into_iter().enumerate() { if m == 1 { res = res + g[i*idx]; } else if m == -1 { res = res - g[i*idx]; } } res } } } pub mod modtable { static mut P: usize = 0; static mut INV: Vec = vec![]; static mut F: Vec = vec![]; static mut FINV: Vec = vec![]; pub fn init(p: usize, max: usize) { let (mut inv, mut f, mut finv) = (vec![0; max+1], vec![0; max+1], vec![0; max+1]); inv[1] = 1; for i in 2..=max { inv[i] = p - (p/i * inv[p%i] % p); } debug_assert!((1..=max).all(|i| i*inv[i]%p == 1)); f[0] = 1; finv[0] = 1; for i in 1..=max { f[i] = f[i-1]*i % p; finv[i] = finv[i-1]*inv[i] % p; } debug_assert!((0..=max).all(|i| f[i]*finv[i]%p == 1)); unsafe { (P, INV, F, FINV) = (p, inv, f, finv); } } pub fn c(n: usize, k: usize) -> usize { if n < k { 0 } else { unsafe { F[n] * FINV[k] % P * FINV[n-k] % P } } } pub fn p(n: usize, k: usize) -> usize { if n < k { 0 } else { unsafe { F[n] * FINV[n-k] % P } } } pub fn f(n: usize) -> usize { unsafe { F[n] } } pub fn finv(n: usize) -> usize { unsafe { FINV[n] } } } } pub mod util { pub mod output { #![allow(static_mut_refs, non_camel_case_types)] use std::{mem::replace, ops::{Not, Shl}, fmt::Write}; static mut BUFFER: Buffer = Buffer { buf: String::new(), endp: false, prev: Previous::LineHead }; pub struct Buffer { buf: String, endp: bool, prev: Previous, } impl Buffer { const LEN: usize = 16*1024*1024; fn print(&mut self) { if replace(&mut self.prev, Previous::LineHead) == Previous::LineHead { self.buf.pop(); } if crate::cplib::SUBMISSION { println!("{}", self.buf); } else { eprint!("\x1b[32m"); if self.buf.is_empty() { println!(">> (empty)"); } else { for s in self.buf.split('\n') { eprint!(">> "); println!("{s}"); } } eprint!("\x1b[0m"); } self.buf.clear(); } fn space(&mut self, sp: bool) { let prev = replace(&mut self.prev, if sp {Previous::Space} else {Previous::NoSpace}); if (sp || prev == Previous::Space) && prev != Previous::LineHead { self.buf.push(' '); } } } #[derive(Clone, Copy)] pub struct out; pub struct out_usp; pub struct end; #[derive(PartialEq, Eq, Clone, Copy)] enum Previous { Space, NoSpace, LineHead, } impl out { pub fn init(endp: bool) { unsafe { BUFFER.buf.reserve(Buffer::LEN); BUFFER.endp = endp; } } pub fn print() { unsafe { BUFFER.print(); } } pub fn space() { unsafe { if BUFFER.prev == Previous::NoSpace { BUFFER.prev = Previous::Space; } } } fn push(v: &T) { unsafe { BUFFER.space(true); v.fmt(&mut BUFFER.buf); } } } impl out_usp { fn push(v: &T) { unsafe { BUFFER.space(false); v.fmt(&mut BUFFER.buf); } } } impl Not for out { type Output = out_usp; fn not(self) -> Self::Output { out_usp } } macro_rules! impl_outs { ($($t:ty),+) => { $( impl Shl for $t { type Output = Self; fn shl(self, rhs: T) -> Self::Output { Self::push(&rhs); self } } impl Shl for $t { type Output = Self; fn shl(self, _: end) -> Self::Output { unsafe { if BUFFER.endp { BUFFER.print(); } else { BUFFER.buf += "\n"; BUFFER.prev = Previous::LineHead; } } self } } )+ }; } impl_outs!(out, out_usp); macro_rules! impl_for_slices { ($($t:ty),+) => { $(impl_for_slices!($t; out, out_usp);)+ }; ($t:ty; $($u:ty),+) => { $( impl Shl<$t> for $u { type Output = Self; fn shl(self, rhs: $t) -> Self::Output { for v in rhs { Self::push(v); } self } } )+} } impl_for_slices!(&[T], &Vec); trait Primitive { fn fmt(&self, buf: &mut String); } macro_rules! impl_primitive { ($($t:ty),+) => { $( impl Primitive for $t { fn fmt(&self, buf: &mut String) { write!(buf, "{self}").ok(); } } )+ } } impl_primitive!(char, u32, u64, u128, usize, i32, i64, i128, f32, f64, &str, &String); impl Primitive for u8 { fn fmt(&self, buf: &mut String) { buf.push(*self as char); } } impl Primitive for bool { fn fmt(&self, buf: &mut String) { *buf += if *self { "Yes" } else { "No" }; } } } pub mod traits { pub trait Grid: Copy + Default { const AROUND: [[i64; 2]; 8] = [[0, -1], [0, 1], [-1, 0], [1, 0], [-1, -1], [-1, 1], [1, -1], [1, 1]]; fn add(self, rhs: [i64; 2]) -> Self; fn apply(self, c: char, n: i64) -> Self { let mut d = Self::AROUND[match c { 'L' => 0, 'R' => 1, 'U' => 2, 'D' => 3, _ => unreachable!() }]; d[0] *= n; d[1] *= n; self.add(d) } fn around4(self) -> [Self; 4] { let mut res = [Default::default(); 4]; for i in 0..4 { res[i] = self.add(Self::AROUND[i]); } res } fn around8(self) -> [Self; 8] { let mut res = [Default::default(); 8]; for i in 0..8 { res[i] = self.add(Self::AROUND[i]); } res } fn rotate(self, n: usize, t: i64) -> Self; } impl Grid for [usize; 2] { fn add(mut self, rhs: [i64; 2]) -> Self { for i in 0..2 { self[i] = self[i].wrapping_add_signed(rhs[i] as isize); } self } fn rotate(self, n: usize, t: i64) -> Self { let [i, j] = self; match t.rem_euclid(4) { 0 => [i, j], 1 => [j, n-1-i], 2 => [n-1-i, n-1-j], 3 => [n-1-j, i], _ => unreachable!() } } } impl Grid for [i64; 2] { fn add(mut self, rhs: [i64; 2]) -> Self { for i in 0..2 { self[i] += rhs[i]; } self } fn rotate(self, _: usize, _: i64) -> Self { unimplemented!() } } pub trait CharUtil: Clone { const LOWER: [Self; 26]; const UPPER: [Self; 26]; const NUMBER: [Self; 10]; fn parse_lower(self) -> usize; fn parse_upper(self) -> usize; fn parse_digit(self) -> usize; fn flip(self) -> Self; } impl CharUtil for char { const LOWER: [char; 26] = { let (mut out, mut i) = (['_'; 26], 0); while i < 26 { out[i] = (i+97) as u8 as char; i += 1; } out }; const UPPER: [char; 26] = { let (mut out, mut i) = (['_'; 26], 0); while i < 26 { out[i] = (i+65) as u8 as char; i += 1; } out }; const NUMBER: [char; 10] = { let (mut res, mut i) = (['_'; 10], 0); while i < 10 { res[i] = (i+48) as u8 as char; i += 1; } res }; fn parse_lower(self) -> usize { debug_assert!('a' <= self && self <= 'z'); self as usize - 97 } fn parse_upper(self) -> usize { debug_assert!('A' <= self && self <= 'Z'); self as usize - 65 } fn parse_digit(self) -> usize { debug_assert!('0' <= self && self <= '9'); self as usize - 48 } fn flip(self) -> Self { (self as u8 ^ 32) as char } } use std::collections::{BTreeMap, HashMap}; use std::hash::Hash; pub trait MapInit { type K; type V; fn init(&mut self, key: Self::K, init: Self::V) -> &mut Self::V; } impl MapInit for HashMap { type K = K; type V = V; fn init(&mut self, key: K, init: V) -> &mut V { self.entry(key).or_insert(init) } } impl MapInit for BTreeMap { type K = K; type V = V; fn init(&mut self, key: K, init: V) -> &mut V { self.entry(key).or_insert(init) } } } pub mod macros { #[macro_export] macro_rules! epr { ($($args:tt)*) => { if !$crate::SUBMISSION { let inf = "4611686018427387903"; let mut res = String::new(); let mut stk = String::new(); for c in format!($($args)*).chars() { if c.is_numeric() { stk.push(c); } else { if (inf.len() == stk.len() && inf <= &stk) || inf.len() < stk.len() { res += "inf"; } else { res += &stk; } stk.clear(); res.push(c); } } eprintln!("\x1b[31m{res}\x1b[0m"); } } } #[macro_export] macro_rules! table { ($v:expr) => { if !$crate::SUBMISSION { use std::fmt::Write; let mut lmax = $v.iter().map(|v| v.iter().map(|e| format!("{e}").len()).max().unwrap_or(0)).max().unwrap_or(0); let mut tmp = String::new(); for v in &$v { tmp += " [ "; for &e in v { write!(&mut tmp, "{e: >lmax$}, "); } tmp.pop(); tmp.pop(); tmp += "]\n"; } eprintln!("\x1b[38;5;208m{} = [\n{tmp}]\x1b[0m", stringify!($v)); } }; ($v:expr, $inf:expr) => { if !$crate::SUBMISSION { use std::fmt::Write; let mut lmax = $v.iter().map(|v| v.iter().map(|e| format!("{e}").len()).max().unwrap_or(0)).max().unwrap_or(0).max(3); let mut tmp = String::new(); for v in &$v { tmp += " [ "; for &e in v { if e < $inf { write!(&mut tmp, "{e: >lmax$}, "); } else { write!(&mut tmp, "{: >lmax$}, ", "inf"); } } tmp.pop(); tmp.pop(); tmp += "]\n"; } eprintln!("\x1b[38;5;208m{} = [\n{tmp}]\x1b[0m", stringify!($v)); } }; } #[macro_export] macro_rules! oj_local { ($oj:expr, $local:expr) => { if $crate::SUBMISSION { $oj } else { $local } }; } #[macro_export] macro_rules! nest { [void; $n:expr] => { std::vec![std::vec![]; $n] }; [void; $n:expr $(;$m:expr)+] => { std::vec![crate::nest![void$(;$m)+]; $n] }; [$($v:expr),*] => { std::vec![$($v),*] }; [$e:expr; $n:expr] => { std::vec![$e; $n] }; [$e:expr; $n:expr $(;$m:expr)+] => { std::vec![crate::nest![$e$(;$m)+]; $n] }; } #[macro_export] macro_rules! min { ($($vl:expr),+) => { [$($vl),+].into_iter().reduce(|x,y| if x <= y {x} else {y}).unwrap() } } #[macro_export] macro_rules! max { ($($vl:expr),+) => { [$($vl),+].into_iter().reduce(|x,y| if x >= y {x} else {y}).unwrap() } } #[macro_export] macro_rules! chmin { ($dst:expr; $v:expr) => { { let v = $v; if v < $dst { $dst = v; true } else { false } } }; ($dst:expr; $($vl:expr),+) => { crate::chmin!($dst; crate::min!($($vl),+)) } } #[macro_export] macro_rules! chmax { ($dst:expr; $v:expr) => { { let v = $v; if $dst < v { $dst = v; true } else { false } } }; ($dst:expr; $($vl:expr),+) => { crate::chmax!($dst; crate::max!($($vl),+)) } } #[macro_export] macro_rules! safe_pow { ($v:expr, $e:expr) => { { let (mut v, mut e, mut res) = ($v, $e, 1); if e == 0 {1} else if v == 0 {0} else { while e != 0 { if e%2 == 1 { res = res.saturating_mul(v); } v = v.saturating_mul(v); e /= 2; } res } } }; ($v:expr, $e:expr, $m:expr) => { { let (mut v, mut e, m, mut res) = ($v, $e, $m, 1); if e == 0 {1%m} else if v == 0 {0} else { while e != 0 { if e%2 == 1 { res = (res*v)%m; } v = v*v%m; e /= 2; } res.rem_euclid(m) } } } } #[macro_export] macro_rules! cum { ($iter:expr) => {{ let mut cum = vec![0]; for (i, v) in $iter.enumerate() { cum.push(cum[i] + v); } cum }}; } } pub mod func { use std::ops::{RangeBounds, Bound}; pub fn binary_search(low: usize, high: usize) -> Option { if 1 < high.wrapping_sub(low) { Some(low.wrapping_add(high)/2) } else { None } } pub fn to_bounds(range: impl RangeBounds, sup: usize) -> [usize; 2] { let mut l = match range.start_bound() { Bound::Included(&v) => v, Bound::Excluded(&v) => v+1, Bound::Unbounded => 0 }; let mut r = match range.end_bound() { Bound::Included(&v) => v+1, Bound::Excluded(&v) => v, Bound::Unbounded => sup }; if l >= r { l = 0; r = 0; } assert!(r <= sup, "valid: 0..{sup}, input: {l}..{r}"); [l, r] } pub(crate) fn join(s: impl Iterator) -> Option { let mut res = s.into_iter().fold(String::new(), |mut acc, e| { acc += &e; acc += ", "; acc }); if res.is_empty() { return None; } res.truncate(res.len() - 2); Some(res) } } } } mod external { pub use { proconio::{ input, input_interactive, marker::{Bytes as bytes, Chars as chars, Usize1 as u1} }, }; #[macro_export] macro_rules! input_one { () => { { input! { x: usize } x } }; } }