use std::io::{stdin, stdout, Write, stderr};
use std::str::FromStr;
use std::fmt::Display;
use std::ops::{Shl, Shr};
use std::any::type_name;
#[allow(nonstandard_style)]
pub struct rin;
#[allow(nonstandard_style)]
pub struct rout;
#[allow(nonstandard_style)]
pub struct rerr;
#[allow(nonstandard_style)]
pub struct endl;
#[allow(nonstandard_style)]
pub struct flush;
impl<T> Shl<T> for rout where T: Display{
type Output = rout;
fn shl(self, rhs: T) -> rout {
stdout().write(rhs.to_string().as_bytes()).unwrap();
self
}
}
impl Shl<endl> for rout where{
type Output = ();
fn shl(self, _: endl) -> () {
stdout().write(b"\n").unwrap();
stdout().flush().unwrap();
}
}
impl Shl<flush> for rout where{
type Output = ();
fn shl(self, _: flush) -> () {
stdout().flush().unwrap();
}
}
impl<T> Shl<T> for rerr where T: Display{
type Output = rerr;
fn shl(self, rhs: T) -> rerr {
stderr().write(rhs.to_string().as_bytes()).unwrap();
self
}
}
impl Shl<endl> for rerr where{
type Output = ();
fn shl(self, _: endl) -> () {
stderr().write(b"\n").unwrap();
stderr().flush().unwrap();
}
}
impl Shl<flush> for rerr where{
type Output = ();
fn shl(self, _: flush) -> () {
stderr().flush().unwrap();
}
}
impl<T> Shr<&mut T> for rin where T: FromStr {
type Output = rin;
#[allow(unused_results)]
fn shr(self, rhs: &mut T) -> rin {
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
if let Ok(item) = T::from_str(&buf.trim()) {
*rhs = item
} else {
panic!("\"{}\" is not a {}", &buf, type_name::<T>())
};
self
}
}
impl Shr<flush> for rin {
type Output = ();
#[allow(unused_results)]
fn shr(self, _: flush) -> () {}
}
#[test]
fn test() {
rout << 1 << " " << "HelloWorld!" << endl;
}