pub mod scanner { pub struct Scanner { buf: Vec, } impl Scanner { pub fn new() -> Self { Self { buf: vec![] } } pub fn new_from(source: &str) -> Self { let source = String::from(source); let buf = Self::split(source); Self { buf } } pub fn next(&mut self) -> T { loop { if let Some(x) = self.buf.pop() { return x.parse().ok().expect(""); } let mut source = String::new(); std::io::stdin().read_line(&mut source).expect(""); self.buf = Self::split(source); } } fn split(source: String) -> Vec { source .split_whitespace() .rev() .map(String::from) .collect::>() } } } use crate::scanner::Scanner; use std::io::Write; fn main() { let mut scanner = Scanner::new(); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); let t: usize = 1; for _ in 0..t { solve(&mut scanner, &mut out); } } pub struct SquareMatrix(Vec>); impl SquareMatrix { pub fn dot(&self, rhs: &SquareMatrix) -> SquareMatrix { let size = self.0.len(); let mut res = SquareMatrix(vec![vec![0; size]; size]); for i in 0..size { for j in 0..size { for k in 0..size { res.0[i][j] += self.0[i][k] * rhs.0[k][j]; } } } res } pub fn pow(&self, n: usize) -> SquareMatrix { let size = self.0.len(); let mut res = SquareMatrix(vec![vec![0; size]; size]); for i in 0..size { res.0[i][i] = 1; } let mut now = SquareMatrix(self.0.clone()); let mut n = n; while n > 0 { if (n & 1) == 1 { res = res.dot(&now); } now = now.dot(&now); n >>= 1; } res } } fn solve(scanner: &mut Scanner, out: &mut std::io::BufWriter) { let a: isize = scanner.next(); let b: isize = scanner.next(); let c: isize = scanner.next(); let d: isize = scanner.next(); let ans = SquareMatrix(vec![vec![a, b], vec![c, d]]).pow(3); writeln!(out, "{} {}", ans.0[0][0], ans.0[0][1]).unwrap(); writeln!(out, "{} {}", ans.0[1][0], ans.0[1][1]).unwrap(); }