Problem:
Score: 300 points

Problem Statement

We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.

According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.

Determine if he is correct.

Constraints

c_{i, j} \ (1 \leq i \leq 3, 1 \leq j \leq 3) is an integer between 0 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

c_{1,1} c_{1,2} c_{1,3}
c_{2,1} c_{2,2} c_{2,3}
c_{3,1} c_{3,2} c_{3,3}

Output

If Takahashi's statement is correct, print Yes; otherwise, print No.

Sample Input 1

1 0 1
2 1 2
1 0 1

Sample Output 1

Yes

Takahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1.

Sample Input 2

2 2 2
2 1 2
2 2 2

Sample Output 2

No

Takahashi is incorrect in this case.

Sample Input 3

0 8 8
0 8 8
0 8 8

Sample Output 3

Yes

Sample Input 4

1 8 6
2 9 7
0 7 7

Sample Output 4

No

Solution in Rust (1.15.1) (judge verdict: Accepted)

extern crate core;

use std::io::{self, Read};
use lib::*;

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    //list[i][j]
    let list = input
        .split("\n")
        .map(|x| {
            x.split_whitespace()
                .map(|x| x.parse::<i32>().unwrap())
                .collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();
    for i in 0..2 {
        for j in 0..2 {
            if list[i][j] - list[i][j + 1] != list[i + 1][j] - list[i + 1][j + 1] {
                return "No".to_string();
            }
        }
    }
    return "Yes".to_string();
}

#[test]
fn test() {
    let tests = vec![
        (
            "1 0 1
2 1 2
1 0 1",
            "Yes",
        ),
        (
            "2 2 2
2 1 2
2 2 2",
            "No",
        ),
        (
            "0 8 8
0 8 8
0 8 8
",
            "Yes",
        ),
        (
            "1 8 6
2 9 7
0 7 7",
            "No",
        ),
    ];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}

mod lib {
    //https://qiita.com/edo_m18/items/0588d290a19f2afc0a84
    mod graph {
        #[derive(Debug, PartialEq, Clone)]
        pub struct Node {
            pub edges: Vec<(usize, f64)>,
            pub done: bool,
            pub cost: f64,
            pub id: usize,
            pub previous_node: Option<usize>,
        }

        impl Node {
            pub fn new(id: usize) -> Node {
                Node {
                    edges: Vec::new(),
                    done: false,
                    cost: -1.0,
                    id: id,
                    previous_node: None,
                }
            }

            pub fn add_node(&mut self, id: usize, cost: f64) {
                self.edges.push((id, cost));
            }
        }

        pub fn min_route(mut nodes: Vec<Node>) -> (f64, Vec<Node>) {
            nodes[0].cost = 0.0;

            loop {
                let mut process_node: Option<usize> = None;

                for node in &nodes {
                    // 訪問済み or まだコストが未設定
                    if node.done || node.cost < 0.0 {
                        continue;
                    }

                    match process_node {
                        Option::None => process_node = Some(node.id),
                        Option::Some(pn) => {
                            if node.cost < nodes[pn].cost {
                                process_node = Some(node.id);
                            }
                        }
                    }
                }

                match process_node {
                    Option::Some(pn) => {
                        nodes[pn].done = true;

                        for edge in nodes[pn].edges.clone() {
                            let node = edge.0;
                            let cost = nodes[pn].cost + edge.1;

                            // コストが未設定 or コストの少ない経路がある場合はアップデート
                            let needs_update =
                                (nodes[node].cost < 0.0) || (nodes[node].cost > cost);
                            if needs_update {
                                nodes[node].cost = cost;
                                nodes[node].previous_node = Some(pn);
                            }
                        }
                    }
                    None => {
                        break;
                    }
                }
            }

            let goal_node = nodes.last().unwrap();

            let mut path: Vec<Node> = Vec::new();
            let mut current_node = goal_node;
            loop {
                let next_node = current_node.previous_node;
                match next_node {
                    Option::None => {
                        break;
                    }
                    Option::Some(next_node) => {
                        path.push(nodes[next_node].clone());
                        current_node = &nodes[next_node];
                    }
                }
            }

            let sum = path.clone()
                .into_iter()
                .filter_map(|x| {
                    x.previous_node
                        .map(|id| x.edges.iter().find(|x| x.0 == id).unwrap().1)
                })
                .sum::<f64>() + path[0].edges.last().unwrap().1;

            (sum, path)
        }
    }

}