use crate::euclid::gcd; #[allow(unused_imports)] #[cfg(feature = "dbg")] use dbg::lg; fn main() { let mut buf = ngtio::with_stdin(); let s = buf.string(); let a = s .split('.') .map(|a| a.parse::().unwrap()) .collect::>(); let y = a[0] * 1000 + a[1]; let x = 1000; let g = gcd(x, y); let x = x / g; let y = y / g; let ans_c = match (x + y) % 2 { 0 => 'A', 1 => match x % 2 { 0 => 'C', 1 => 'B', _ => unreachable!(), }, _ => unreachable!(), }; let ans_r = (x - 1) + (y - 1) + (x + y) / 2 + (x - y).abs() / 2; println!("{} {}", ans_c, ans_r); } // euclid {{{ #[allow(dead_code)] mod euclid { mod crt { use super::Signed; pub fn crt(res0: T, mod0: T, res1: T, mod1: T) -> Option<(T, T)> { assert!(T::zero() < mod0); assert!(T::zero() < mod1); let (a, _b, g) = super::ext_gcd(mod0, mod1); if g.divides(res1 - res0) { let quot = mod1 / g; let a = ((res1 - res0) / g * a) % quot; let a = if a < T::zero() { a + quot } else { a }; assert!(T::zero() <= a && a < quot); Some((res0 + a * mod0, mod0 * quot)) } else { None } } } mod ext_gcd { use {super::Signed, std::mem::swap}; #[allow(clippy::many_single_char_names)] pub fn ext_gcd(x: T, y: T) -> (T, T, T) { assert_ne!(x, T::zero()); assert_ne!(y, T::zero()); let (a, g) = { let mut x = x; let mut y = y; let mut u = T::one(); let mut v = T::zero(); while x != T::zero() { let q = y / x; y -= q * x; v -= q * u; swap(&mut x, &mut y); swap(&mut u, &mut v); } if y < T::zero() { (-v, -y) } else { (v, y) } }; assert_eq!((g - a * x) % y, T::zero()); let b = (g - a * x) / y; (a, b, g) } } mod gcd { use {super::Int, std::mem::swap}; pub fn gcd(mut x: T, mut y: T) -> T { while x != T::zero() { y = y.rem_euclid(x); swap(&mut x, &mut y); } y.abs() } } use std::{ fmt::Debug, ops::{ Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign, }, }; pub use {crt::crt, ext_gcd::ext_gcd, gcd::gcd}; pub trait Int: Debug + Copy + Ord + Add + AddAssign + Sub + SubAssign + Mul + MulAssign + Div + DivAssign + Rem + RemAssign { fn zero() -> Self; fn one() -> Self; fn increment(&mut self); fn abs(self) -> Self; fn div_euclid(self, rhs: Self) -> Self; fn rem_euclid(self, rhs: Self) -> Self; fn divides(self, n: Self) -> bool { n.rem_euclid(self) == Self::zero() } } pub trait Unsigned: Int {} pub trait Signed: Int + Neg {} macro_rules! impl_unsigned { ($($t:ty),* $(,)?) => {$( impl Int for $t { fn zero() -> Self { 0 } fn one() -> Self { 1 } fn increment(&mut self) { *self += 1; } fn abs(self) -> Self { self } fn div_euclid(self, rhs: Self) -> Self { self.div_euclid(rhs) } fn rem_euclid(self, rhs: Self) -> Self { self.rem_euclid(rhs) } } impl Unsigned for $t {} )*} } impl_unsigned! { usize, u8, u16, u32, u64, u128, } macro_rules! impl_signed { ($($t:ty),* $(,)?) => {$( impl Int for $t { fn zero() -> Self { 0 } fn one() -> Self { 1 } fn increment(&mut self) { *self += 1; } fn abs(self) -> Self { self.abs() } fn div_euclid(self, rhs: Self) -> Self { self.div_euclid(rhs) } fn rem_euclid(self, rhs: Self) -> Self { self.rem_euclid(rhs) } } impl Signed for $t {} )*} } impl_signed! { isize, i8, i16, i32, i64, i128, } } // }}} // template {{{ #[cfg(not(feature = "dbg"))] #[allow(unused_macros)] #[macro_export] macro_rules! lg { ($($expr:expr),*) => {}; } #[allow(dead_code)] mod ngtio { mod i { pub use self::{ multi_token::{Leaf, Parser, ParserTuple, RawTuple, Tuple, VecLen}, token::{Token, Usize1}, }; use std::{ io::{self, BufRead}, iter, }; pub fn with_stdin() -> Tokenizer> { io::BufReader::new(io::stdin()).tokenizer() } pub fn with_str(src: &str) -> Tokenizer<&[u8]> { src.as_bytes().tokenizer() } pub struct Tokenizer { queue: Vec, // FIXME: String のみにすると速そうです。 scanner: S, } macro_rules! prim_method { ($name:ident: $T:ty) => { pub fn $name(&mut self) -> $T { <$T>::leaf().parse(self) } }; ($name:ident) => { prim_method!($name: $name); }; } macro_rules! prim_methods { ($name:ident: $T:ty; $($rest:tt)*) => { prim_method!($name:$T); prim_methods!($($rest)*); }; ($name:ident; $($rest:tt)*) => { prim_method!($name); prim_methods!($($rest)*); }; () => () } impl Tokenizer { pub fn token(&mut self) -> String { self.load(); self.queue.pop().expect("入力が終了したのですが。") } pub fn new(scanner: S) -> Self { Self { queue: Vec::new(), scanner, } } fn load(&mut self) { while self.queue.is_empty() { let mut s = String::new(); let length = self.scanner.read_line(&mut s).unwrap(); // 入力が UTF-8 でないときにエラーだそうです。 if length == 0 { break; } self.queue = s.split_whitespace().rev().map(str::to_owned).collect(); } } pub fn skip_line(&mut self) { assert!( self.queue.is_empty(), "行の途中で呼ばないでいただきたいです。現在のトークンキュー: {:?}", &self.queue ); self.load(); } pub fn end(&mut self) { self.load(); assert!(self.queue.is_empty(), "入力はまだあります!"); } pub fn parse(&mut self) -> T::Output { T::parse(&self.token()) } pub fn parse_collect(&mut self, n: usize) -> B where B: iter::FromIterator, { iter::repeat_with(|| self.parse::()).take(n).collect() } pub fn tuple(&mut self) -> ::Output { T::leaf_tuple().parse(self) } pub fn vec(&mut self, len: usize) -> Vec { T::leaf().vec(len).parse(self) } pub fn vec_tuple( &mut self, len: usize, ) -> Vec<::Output> { T::leaf_tuple().vec(len).parse(self) } pub fn vec2(&mut self, height: usize, width: usize) -> Vec> { T::leaf().vec(width).vec(height).parse(self) } pub fn vec2_tuple( &mut self, height: usize, width: usize, ) -> Vec::Output>> where T: RawTuple, { T::leaf_tuple().vec(width).vec(height).parse(self) } prim_methods! { u8; u16; u32; u64; u128; usize; i8; i16; i32; i64; i128; isize; f32; f64; char; string: String; } } mod token { use super::multi_token::Leaf; use std::{any, fmt, marker, str}; pub trait Token: Sized { type Output; fn parse(s: &str) -> Self::Output; fn leaf() -> Leaf { Leaf(marker::PhantomData) } } impl Token for T where T: str::FromStr, ::Err: fmt::Debug, { type Output = Self; fn parse(s: &str) -> Self::Output { s.parse().unwrap_or_else(|_| { panic!("Parse error!: ({}: {})", s, any::type_name::(),) }) } } pub struct Usize1 {} impl Token for Usize1 { type Output = usize; fn parse(s: &str) -> Self::Output { usize::parse(s) .checked_sub(1) .expect("Parse error! (Zero substruction error of Usize1)") } } } mod multi_token { use super::{Token, Tokenizer}; use std::{io::BufRead, iter, marker}; pub trait Parser: Sized { type Output; fn parse(&self, server: &mut Tokenizer) -> Self::Output; fn vec(self, len: usize) -> VecLen { VecLen { len, elem: self } } } pub struct Leaf(pub(super) marker::PhantomData); impl Parser for Leaf { type Output = T::Output; fn parse(&self, server: &mut Tokenizer) -> T::Output { server.parse::() } } pub struct VecLen { pub len: usize, pub elem: T, } impl Parser for VecLen { type Output = Vec; fn parse(&self, server: &mut Tokenizer) -> Self::Output { iter::repeat_with(|| self.elem.parse(server)) .take(self.len) .collect() } } pub trait RawTuple { type LeafTuple: Parser; fn leaf_tuple() -> Self::LeafTuple; } pub trait ParserTuple { type Tuple: Parser; fn tuple(self) -> Self::Tuple; } pub struct Tuple(pub T); macro_rules! impl_tuple { ($($t:ident: $T:ident),*) => { impl<$($T),*> Parser for Tuple<($($T,)*)> where $($T: Parser,)* { type Output = ($($T::Output,)*); #[allow(unused_variables)] fn parse(&self, server: &mut Tokenizer) -> Self::Output { match self { Tuple(($($t,)*)) => { ($($t.parse(server),)*) } } } } impl<$($T: Token),*> RawTuple for ($($T,)*) { type LeafTuple = Tuple<($(Leaf<$T>,)*)>; fn leaf_tuple() -> Self::LeafTuple { Tuple(($($T::leaf(),)*)) } } impl<$($T: Parser),*> ParserTuple for ($($T,)*) { type Tuple = Tuple<($($T,)*)>; fn tuple(self) -> Self::Tuple { Tuple(self) } } }; } impl_tuple!(); impl_tuple!(t1: T1); impl_tuple!(t1: T1, t2: T2); impl_tuple!(t1: T1, t2: T2, t3: T3); impl_tuple!(t1: T1, t2: T2, t3: T3, t4: T4); impl_tuple!(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5); impl_tuple!(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6); impl_tuple!(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7); impl_tuple!( t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8 ); } trait Scanner: BufRead + Sized { fn tokenizer(self) -> Tokenizer { Tokenizer::new(self) } } impl Scanner for R {} } pub use self::i::{with_stdin, with_str}; mod prelude { pub use super::i::{Parser, ParserTuple, RawTuple, Token, Usize1}; } } // }}}