extern crate core;

use std::str::FromStr;
use std::fmt;
use std::cmp::Ordering;
use std::fmt::{Display, Error, Formatter};
use std::ops::Range;
use std::collections::{BinaryHeap};

struct Istream {
    line: Vec<String>,
    position: usize
}
type Parse<T: FromStr> = Result<T, T::Err>;
impl Istream {
    fn new() -> Istream {
        Istream {line:vec![], position: 0}
    }
    fn read_word(&mut self) -> &String {
        if self.position == self.line.len() {
            let mut line= String::new();
            std::io::stdin().read_line(&mut line).ok();
            self.line = line.split_whitespace().map(|x|x.to_string()).collect();
            self.position = 0
        }
        let result = &self.line[self.position];
        self.position += 1;
        result
    }
    fn read(&mut self) -> String {
        self.read_word().to_string()
    }
    fn get<T: FromStr>(&mut self) -> T {self.read_word().parse().ok().unwrap()}
    fn read_usize(&mut self) -> usize {self.get()}
    fn read_int(&mut self) -> i32 {self.get()}
    fn read_long(&mut self) -> i64 {self.get()}
    fn read_double(&mut self) -> f64 {self.get()}
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}

macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! assign_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        assign_all!(iter; $($n:$t),*);
    };
    ($iter:expr; ) => {};
    ($iter:expr; $n:ident:$t:ty) => {
        let $n: $t = $iter.next().unwrap().parse().ok().unwrap();
    };
    ($iter: expr; $n:ident:$t:ty, $($m:ident:$u:ty),*) => {
        let $n: $t = $iter.next().unwrap().parse().ok().unwrap();
        assign_all!($iter; $($m:$u),*);
    };
}
macro_rules! repeat {
    ($count:expr; $($statement:tt)+) => {
        for _ in 0 .. $count {
            $($statement)*
        }
    };
}

macro_rules! yields {
    ($count:expr; $block:block) => {{
        let mut vec = Vec::with_capacity($count);
        for _ in 0 .. $count {
            vec.push($block);
        }
        vec
    }}
}
macro_rules! array {
    ($factor: expr, ) => {$factor};
    ($factor: expr, $dimension: expr) => {{
        let size = $dimension;
        let mut vec = Vec::with_capacity(size);
        for _ in 0 .. size {
            vec.push(array!($factor, ))
        }
        vec
    }};
    ($factor:expr, $dimension:expr, $($r:expr),*) => {{
        let size = $dimension;
        let mut vec = Vec::with_capacity(size);
        for _ in 0 .. size{
            let factor = array!($factor, $($r),*);
            vec.push(factor)
        }
        vec
    }};
}
fn tabulate<F, R>(count: usize, mut generator: F) -> Vec<R> where F : FnMut(usize) -> R {
    let mut result = Vec::<R>::with_capacity(count);
    for f in 0 .. count {
        result.push(generator(f));
    }
    result
}
struct Table {
    table: Vec<Vec<usize>>
}
impl Table {
    fn new(table: Vec<Vec<usize>>) -> Table {
        Table{table: table}
    }
    fn check(&self, snn: usize) -> bool {
        let t = &self.table;
        t[t[t[t[t[0][snn / 10000]][snn / 1000 % 10]][snn / 100 % 10]][snn / 10 % 10]][snn % 10] == 0
    }
    fn convert(&self, base_id: usize) -> usize {
        let t = &self.table;
        base_id * 10 + t[t[t[t[0][base_id / 1000]][base_id / 100 % 10]][base_id / 10 % 10]][base_id % 10]
    }
    fn can_detect_altering_one_single_digit(&self, snn: usize) -> bool {
        let mut digit: usize = 10000;
        for _ in 0..5 {
            for diff in 1 .. 10 {
                let wrong = ((snn / digit / 10) * 10 + ((snn / digit) + diff) % 10) * digit + snn % digit;
                if self.check(wrong) {
                    return false
                }
            }
            digit /= 10;
        }
        return true
    }
    fn can_detect_transposing_two_digits(&self, snn: usize) -> bool {
        //println!("transposing {}", snn);
        let mut digit: usize = 1000;
        for _ in 0 .. 4{
            let upper = snn / digit;
            if upper / 10 % 10 != upper % 10 && self.check((upper / 100 * 100 + upper / 10 % 10 + upper % 10 * 10) * digit + snn % digit) {
                return false
            }
            digit /= 10;
        }
        return true
    }
}
fn main() {
    let table = yields!(10; {read_line!(' '; usize)});
    let table = Table::new(table);
    let mut count = 0;
    for base_id in 0..10000 as usize {
        let snn = table.convert(base_id);
        if !table.can_detect_transposing_two_digits(snn) || !table.can_detect_altering_one_single_digit(snn) {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 5036