Problem:
Problem B
Quality of Check Digits
The small city where you live plans to introduce a new social security number (SSN) system. Each citizen will be identified by a five-digit SSN. Its first four digits indicate the basic ID number (0000 - 9999) and the last one digit is a
check digit
for detecting errors.
For computing check digits, the city has decided to use an operation table. An operation table is a 10 $\times$ 10 table of decimal digits whose diagonal elements are all 0. Below are two example operation tables.
Operation Table 1
Operation Table 2
Using an operation table, the check digit $e$ for a four-digit basic ID number $abcd$ is computed by using the following formula. Here, $i \otimes
 j$ denotes the table element at row $i$ and column $j$.
$e = (((0 \otimes a) \otimes  b) \otimes c) \otimes d$
For example, by using Operation Table 1 the check digit $e$ for a basic ID number $abcd = $ 2016 is computed in the following way.
$e = (((0 \otimes 2) \otimes 0) \otimes 1) \otimes 6$
$\;\;\;  = (( \;\;\;\;\;\;\;\;\;  1 \otimes 0) \otimes 1) \otimes 6$
$\;\;\;  = ( \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 7 \otimes 1) \otimes 6$
$\;\;\;  =  \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 9 \otimes 6$
$\;\;\;  =  \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;  6$
Thus, the SSN is 20166.
Note that the check digit depends on the operation table used. With Operation Table 2, we have $e = $ 3 for the same basic ID number 2016, and the whole SSN will be 20163.
Figure B.1. Two kinds of common human errors
The purpose of adding the check digit is to detect human errors in writing/typing SSNs. The following
check
function can detect certain human errors. For a five-digit number $abcde$, the check function is defined as follows.
check
($abcde$) $ = ((((0 \otimes a) \otimes b) \otimes c) \otimes d) \otimes e$
This function returns 0 for a correct SSN. This is because every diagonal element in an operation table is 0 and for a correct SSN we have $e = (((0 \otimes a) \otimes b) \otimes c) \otimes d$:
check
($abcde$) $ = ((((0 \otimes a) \otimes b) \otimes c) \otimes d) \otimes e = e \otimes e = 0$
On the other hand, a non-zero value returned by check indicates that the given number cannot be a correct SSN. Note that, depending on the operation table used, check function may return 0 for an incorrect SSN. Kinds of errors detected depends on the operation table used; the table decides the quality of error detection.
The city authority wants to detect two kinds of common human errors on digit sequences: altering one single digit and transposing two adjacent digits, as shown in Figure B.1.
An operation table is good if it can detect all the common errors of the two kinds on all SSNs made from four-digit basic ID numbers 0000{9999. Note that errors with the check digit, as well as with four basic ID digits, should be detected. For example, Operation Table 1 is good. Operation Table 2 is not good because, for 20613, which is a number o
...(truncated)

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  vvi a(10,vi(10));
  cin >> a;
  auto ch = [&](vi v){
    ll k = 0;
    rep(i,0,sz(v))k = a[k][v[i]];
    return k;
  };
  int res = 0;
  rep(i,0,10000){
    vi v(5);
    {
      int k = i;
      rep(j,0,4){
        v[3-j] = k%10;k /= 10;
      }
    }
    {
      int k = 0;
      rep(j,0,4)v[4] = a[v[4]][v[j]];
    }
    bool is = false;
    rep(j,0,5)rep(k,0,10){
      if(v[j] == k)continue;
      int g = v[j];v[j] = k;
      if(!ch(v)){is = true;break;}
      v[j] = g;
    }
    rep(j,0,4){
      if(v[j] == v[j+1])continue;
      swap(v[j],v[j+1]);
      if(!ch(v)){is = true;break;}
      swap(v[j],v[j+1]);
    }
    res += is;
  }
  cout << res << endl;
  

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3432
final_rank: 3

code_snippet: #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int x[11][11];
int check(string s) {
	int ret = 0;
	for (int i = 0; i < s.size(); i++) ret = x[ret][s[i] - 48];
	return ret;
}
int main() {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> x[i][j];
		}
	}
	int ret = 0;
	for (int i = 0; i < 10000; i++) {
		string s = to_string(i);
		while (s.size() < 4) s = '0' + s;
		int e = check(s);
		string t = s + (char)(e + 48);
		bool flag = true;
		for (int j = 0; j < 5; j++) {
			for (int k = 0; k < 10; k++) {
				string r = t; r[j] = k + 48;
				if (r == t) continue;
				if (check(r) == 0) flag = false;
			}
		}
		for (int j = 0; j < 4; j++) {
			string r = t; swap(r[j], r[j + 1]);
			if (r == t) continue;
			if (check(r) == 0) flag = false;
		}
		if (!flag) ret++;
	}
	cout << ret << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3528
final_rank: 8

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

int A[10][10];

int Calc(vector<int> B) {
    int Cur = 0;
    rep(i,0,B.size()) {
        Cur = A[Cur][B[i]];
    }
    return Cur;
}

int main() {
    rep(i,0,10) {
        rep(j,0,10) cin >> A[i][j];
    }
    int ANS = 0;
    rep(i,0,10) {
        rep(j,0,10) {
            rep(k,0,10) {
                rep(l,0,10) {
                    vector<int> B(4);
                    B[0] = i, B[1] = j, B[2] = k, B[3] = l;
                    B.push_back(Calc(B));
                    bool check = true;
                    rep(m,0,4) {
                        if (B[m] == B[m+1]) continue;
                        auto C = B;
                        swap(C[m],C[m+1]);
                        if (Calc(C) == 0) check = false;
                    }
                    rep(m,0,5) {
                        rep(n,0,10) {
                            if (B[m] == n) continue;
                            auto C = B;
                            C[m] = n;
                            if (Calc(C) == 0) check = false;
                        }
                    }
                    if (!check) ANS++;
                }
            }
        }
    }
    cout << ANS << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3436
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vll=vector<ll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)

vector<vector<int>> V(10,vector<int>(10));
int f(int a,int b){
    return V[a][b];
}
int f(vector<int> D){
    reverse(D.begin(),D.end());
    D.push_back(0);
    reverse(D.begin(),D.end());
    int n=D.size();
    for(int i=0;i<n-1;i++){
        D[i+1]=f(D[i],D[i+1]);
    }
    return D[n-1];
}
int main(){
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>V[i][j];
        }
    }
    int an=0;
    for(int k=0;k<10000;k++){
        bool OK=1;
        vector<int> D;
        int n=k;
        for(int j=0;j<4;j++){
            D.push_back(n%10);
            n/=10;
        }
        reverse(D.begin(),D.end());
        D.push_back(f(D));
        for(int i=0;i<4;i++){
            if(D[i]==D[i+1])continue;
            swap(D[i],D[i+1]);
            if(f(D)==0)OK=0;
            swap(D[i],D[i+1]);
        }
        for(int i=0;i<5;i++){
            rep(j,9){
                D[i]=(D[i]+1)%10;
                if(f(D)==0)OK=0;
            }
            D[i]=(D[i]+1)%10;
        }
        if(!OK)an++;
    }
    cout<<an<<endl;

    
}
accuracy: 1
time_ms: 20
memory_kb: 3460
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define ALL(v) v.begin(),v.end()

int table[10][10];

int main(void) {
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> table[i][j];
    }
  }
  map<string, int> check;
  for (int i = 0; i < 1e5; ++i) {
    int tmp = i;
    int base = 10000;
    int c = 0;
    for (int j = 0; j < 5; ++j) {
      int idx = tmp / base;
      c = table[ c ][ idx ];
      tmp %= base;
      base /= 10;
    }
    tmp = i;
    string s;
    for (int j = 0; j < 5; ++j) {
      s.push_back(tmp % 10 + '0');
      tmp /= 10;
    }
    reverse(ALL(s));
    check[s] = c;
  }
  
  // alter
  int ans = 0;
  for (int i = 0; i < 1e4; ++i) {
    int tmp = i;
    string s;
    for (int j = 0; j < 4; ++j) {
      s.push_back(tmp % 10 + '0');
      tmp /= 10;
    }
    reverse(ALL(s));
    
    tmp = i;
    int base = 1000;
    int c = 0;
    for (int j = 0; j < 4; ++j) {
      int idx = tmp / base;
      c = table[ c ][ idx ];
      tmp %= base;
      base /= 10;
    }
    s.push_back(c + '0');
    
    bool bad = false;
    for (int j = 0; j < 5; ++j) {
      for (char k = '0'; k <= '9'; ++k) {
        if (s[j] == k) continue;
        auto tmp = s;
        tmp[j] = k;
        if (check[tmp] == 0) {
          bad = true;
        }
      }
    }
    // swap
    for (int j = 0; j < 4; ++j) {
      auto tmp = s;
      swap(tmp[j], tmp[j + 1]);
      if (tmp == s) continue;
      if (check[tmp] == 0) {
        bad = true;
      }
    }
    if (bad) {
      ++ans;
    }
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 100
memory_kb: 11252
final_rank: 18

code_snippet: #include <bits/stdc++.h>

using namespace std;
int a[17][17];

int find_e(int i1, int i2, int i3, int i4) {
    int e = a[0][i1];
    e = a[e][i2];
    e = a[e][i3];
    e = a[e][i4];
    return e;
}

bool check(int i1, int i2, int i3, int i4, int e) {
    int e_check = find_e(i1, i2, i3, i4);
    return (a[e_check][e] == 0);
}

vector <vector <int>> get_1(int i1, int i2, int i3, int i4, int e, int k) {
    vector <vector <int>> res_get_1;
    if (k == 1){
        for (int i=0; i<=9; i++){
            if (i != i1){
                res_get_1.push_back({i, i2, i3, i4, e});
            }
        }
    }
    else if (k == 2){
        for (int i=0; i<=9; i++){
            if (i != i2){
                res_get_1.push_back({i1, i, i3, i4, e});
            }
        }
    }
    else if (k == 3){
        for (int i=0; i<=9; i++){
            if (i != i3){
                res_get_1.push_back({i1, i2, i, i4, e});
            }
        }
    }
    else if (k == 4){
        for (int i=0; i<=9; i++){
            if (i != i4){
                res_get_1.push_back({i1, i2, i3, i, e});
            }
        }
    }
    else {
        for (int i=0; i<=9; i++){
            if (i != e){
                res_get_1.push_back({i1, i2, i3, i4, i});
            }
        }
    }

    return res_get_1;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    for (int i=0; i<=9; i++){
        for (int j=0; j<=9; j++){
            cin >> a[i][j];
        }
    }

    int res = 0;
    for (int i1=0; i1<=9; i1++){
        for (int i2=0; i2<=9; i2++){
            for (int i3=0; i3<=9; i3++){
                for (int i4=0; i4<=9; i4++){
                    int e = find_e(i1, i2, i3, i4);
                    assert(check(i1, i2, i3, i4, e));

                    bool is_invalid = false;
                    for (int k=1; k<=5; k++){
                        vector <vector <int>> get_1s = get_1(i1, i2, i3, i4, e, k);
                        assert(get_1s.size() == 9);
                        for (auto v : get_1s) {
                            if (check(v[0], v[1], v[2], v[3], v[4])) {
                                is_invalid = true;
                                break;
                            }
                        }
                        if (is_invalid) {
                            break;
                        }
                    }

                    if (i1 != i2 && check(i2, i1, i3, i4, e)) {
                        is_invalid = true;
                    }

                    if (i2 != i3 && check(i1, i3, i2, i4, e)) {
                        is_invalid = true;
                    }

                    if (i3 != i4 && check(i1, i2, i4, i3, e)) {
                        is_invalid = true;
                    }

                    if (i4 != e && check(i1, i2, i3, e, i4)) {
                        is_invalid = true;
                    }

                    if (is_invalid) {
                        res++;
                    }
                }
            }
        }
    }

    cout << res << '\n';

}
accuracy: 1
time_ms: 20
memory_kb: 3444
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;
int a[17][17];

int find_e(int i1, int i2, int i3, int i4) {
    int e = a[0][i1];
    e = a[e][i2];
    e = a[e][i3];
    e = a[e][i4];
    return e;
}

bool check(int i1, int i2, int i3, int i4, int e) {
    int e_check = a[0][i1];
    e_check = a[e_check][i2];
    e_check = a[e_check][i3];
    e_check = a[e_check][i4];
    return (e == e_check);
}

vector <vector <int>> get_1(int i1, int i2, int i3, int i4, int e, int k) {
    vector <vector <int>> res_get_1;
    if (k == 1){
        for (int i=0; i<=9; i++){
            if (i != i1){
                res_get_1.push_back({i, i2, i3, i4, e});
            }
        }
    }
    else if (k == 2){
        for (int i=0; i<=9; i++){
            if (i != i2){
                res_get_1.push_back({i1, i, i3, i4, e});
            }
        }
    }
    else if (k == 3){
        for (int i=0; i<=9; i++){
            if (i != i3){
                res_get_1.push_back({i1, i2, i, i4, e});
            }
        }
    }
    else if (k == 4){
        for (int i=0; i<=9; i++){
            if (i != i4){
                res_get_1.push_back({i1, i2, i3, i, e});
            }
        }
    }
    else {
        for (int i=0; i<=9; i++){
            if (i != e){
                res_get_1.push_back({i1, i2, i3, i4, i});
            }
        }
    }

    return res_get_1;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    for (int i=0; i<=9; i++){
        for (int j=0; j<=9; j++){
            cin >> a[i][j];
        }
    }

    int res = 0;
    for (int i1=0; i1<=9; i1++){
        for (int i2=0; i2<=9; i2++){
            for (int i3=0; i3<=9; i3++){
                for (int i4=0; i4<=9; i4++){
                    int e = find_e(i1, i2, i3, i4);

                    assert(check(i1, i2, i3, i4, e));

                    bool is_invalid = false;
                    for (int k=1; k<=5; k++){
                        vector <vector <int>> get_1s = get_1(i1, i2, i3, i4, e, k);
                        for (auto v : get_1s) {
                            if (check(v[0], v[1], v[2], v[3], v[4])) {
                                is_invalid = true;
                                break;
                            }
                        }
                        if (is_invalid) {
                            break;
                        }
                    }

                    if (i1 != i2 && check(i2, i1, i3, i4, e)) {
                        is_invalid = true;
                    }

                    if (i2 != i3 && check(i1, i3, i2, i4, e)) {
                        is_invalid = true;
                    }

                    if (i3 != i4 && check(i1, i2, i4, i3, e)) {
                        is_invalid = true;
                    }

                    if (i4 != e && check(i1, i2, i3, e, i4)) {
                        is_invalid = true;
                    }

//                    if (check(i2, i1, i3, i4, e) && check(i1, i3, i2, i4, e) && check(i1, i2, i4, i3, e) && check(i1, i2, i3, e, i4)) {
//                        cout << i1 << i2 << i3 << i4 << e << '\n';
//                        is_invalid = true;
//                    }

                    if (is_invalid) {
                        res++;
                    }
                }
            }
        }
    }

    cout << res << '\n';

}
accuracy: 0.5217391304347826
time_ms: 20
memory_kb: 3448
final_rank: 19

code_snippet: #include "bits/stdc++.h"

using namespace std;

int main(){
    vector x(10,vector<int>(10));
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin>>x[i][j];
        }
    }
    auto f=[&](vector<int>a){
        int ret=0;
        for(auto &i:a){
            ret=x[ret][i];
        }
        return ret;
    };
    auto mk_vec=[&](int x){
        vector<int>ret;
        for (int i = 0; i < 4; ++i) {
            ret.emplace_back(x%10);
            x/=10;
        }
        std::reverse(ret.begin(), ret.end());
        ret.emplace_back(f(ret));
        return ret;
    };
    auto ch=[&](int x){
        auto v=mk_vec(x);
        auto cop=v;
        for (int i = 0; i < 5; ++i) {
            for (int j = 0; j < 10; ++j) {
                if(v[i]==j)continue;
                cop[i]=j;
                if(f(cop)==0)return true;
            }
            cop[i]=v[i];
        }
        for (int i = 0; i < 4; ++i) {
            if(v[i]==v[i+1])continue;
            swap(v[i],v[i+1]);
            if(f(v)==0)return true;
            swap(v[i],v[i+1]);
        }
        return false;
    };
//    vector<int>test={2,0,1,6};
//    cout<<f(test)<<'\n';
    int ans=0;
    for(int i=0;i<10000;i++){
        if(ch(i))ans++;
    }
    cout<<ans<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3488
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//const long long MOD = 1000000007;
const long long MOD = 998244353;
const long double PI = 3.14159265358979;
const long long INF = 1LL<<60;
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
#define deb(var) do{cout << #var << " : "; view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
void view(vector<string>& v){cout << endl;for(auto& s :v){view(s);}cout << endl;}
template<typename T> void view(vector<T>& v){for(auto& e :v){cout << e << " ";}cout << endl;}
template<typename T> void view(vector<vector<T>>& vv){cout << endl;for(auto& v:vv){view(v);}}
ll gcd(ll a, ll b){if (b == 0) return a;else return gcd(b, a % b);}
ll lcm(ll x,ll y){return ll(x/gcd(x,y))*y;}
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long


int n = 10;
vector<vector<int>> a(n, vector<int> (n));


bool check(string s) {
	int cur = 0;
	for (int i=0; i<5; i++) {
		cur = a[cur][s[i] - '0'];
	}
	return (bool)cur;
}

int e(string s) {
	int cur = 0;
	for (int i=0; i<4; i++) {
		cur = a[cur][s[i] - '0'];
	}
	return cur;
}

int32_t main() {
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int i=0; i<10000; i++) {
		string s = to_string(i);
		while (s.size() < 4) {
			s = '0'+ s;
		}
		s.push_back(e(s) + '0');
		int res = 0;
		for (int i=0; i<5; i++) {
			string t = s;
			for (int j=0; j<10; j++) {
				t[i] = '0' + j;
				if (t == s) continue;
				if (!check(t)) res = 1;
			}
		}
		for (int i=0; i<4; i++) {
			string t = s;
			swap(t[i], t[i + 1]);
			if (t == s) continue;
			if (!check(t)) res = 1;
		}
		ans += res;
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3500
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//const long long MOD = 1000000007;
const long long MOD = 998244353;
const long double PI = 3.14159265358979;
const long long INF = 1LL<<60;
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
#define deb(var) do{cout << #var << " : "; view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
void view(vector<string>& v){cout << endl;for(auto& s :v){view(s);}cout << endl;}
template<typename T> void view(vector<T>& v){for(auto& e :v){cout << e << " ";}cout << endl;}
template<typename T> void view(vector<vector<T>>& vv){cout << endl;for(auto& v:vv){view(v);}}
ll gcd(ll a, ll b){if (b == 0) return a;else return gcd(b, a % b);}
ll lcm(ll x,ll y){return ll(x/gcd(x,y))*y;}
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long


int n = 10;
vector<vector<int>> a(n, vector<int> (n));


bool check(string s) {
	int cur = 0;
	for (int i=0; i<5; i++) {
		cur = a[cur][s[i] - '0'];
	}
	return (bool)cur;
}

int32_t main() {
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int i=0; i<100000; i++) {
		string s = to_string(i);
		while (s.size() < 5) {
			s = '0'+ s;
		}
		if (check(s)) continue;
		int res = 0;
		for (int i=0; i<5; i++) {
			string t = s;
			for (int j=0; j<10; j++) {
				if (s[i] != '0' + j) {
					t[i] = '0' + j;
					if (!check(t)) res = 1;
				}
			}
		}
		for (int i=0; i<4; i++) {
			string t = s;
			if (t[i] == t[i + 1]) continue;
			swap(t[i], t[i + 1]);
			if (!check(t)) res = 1;
		}
		ans += res;
	}
	cout << ans << endl;
}
accuracy: 0.5217391304347826
time_ms: 20
memory_kb: 3496
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

/* ACL
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
// using mint = modint998244353;
// using mint = modint;
istream& operator>>(istream &is, mint &x) { is >> x; return is; }
ostream &operator<<(ostream &os, const mint &x) { os << x.val(); return os; } //*/

#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define rng(x) (x).begin(), (x).end()
#define popcount(n) __builtin_popcountl((long long int)(n))
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
inline long long int floor_sqrt(long long int n) { long long int x = 0, y = 1e4; while(y - x > 1) {int z = (x + y) / 2; if(z * z <= n) x = z; else y = z; } return x; }
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> void drop(T x) { cout << x << endl; exit(0); }
//iostream
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename S, typename T> istream& operator>>(istream &is, pair<S, T> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for(auto &&it=v.begin();it!=v.end();) os << *it << (++it!=v.end()?" ":""); return os; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &e : v) is >> e; return is;}
template<typename T> ostream& operator<<(ostream &os, const set<T> &s) { for(auto &&it=s.begin();it!=s.end();) os << *it << (++it!=s.end()?" ":""); return os; }
template<typename S, typename T> ostream& operator<<(ostream &os, const map<S, T> &mp) { for(auto &&it=mp.begin();it!=mp.end();) os << *it << (++it!=mp.end()?" ":""); return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> void print(T x) { cout << x << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { std::cout << head << " "; print(std::forward<Tail>(tail)...); }
using ll = long long;
// using ll = unsigned long long;
using ld = long double;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
const int dy[4] = {0, -1, 0, 1};
const int dx[4] = {1, 0, -1, 0};
const int INF = 1<<30;
const ll LINF = 1LL<<62 - 1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);

// N, MAX_M

constexpr int N = 10, MAX_M = 10000, D = 5;
vector<vector<int>> table(N, vector<int>(N));

int check(const vector<int> &a)
{
    int cur = 0;
    rep(i,a.size()) cur = table[cur][a[i]];
    return cur;
}

bool ng(const vector<int> &a)
{
    vector<int> test = {9, 9, 9, 9, 2};
    // transpose
    rep(i,D-1)
    {
        vector<int> b = a;
        swap(b[i], b[i+1]);
        if(a == b) continue;
        // if(a == test) print(b);

        if(check(b) == 0) return true;
    }
    // if(a == test) print("hoge");
    // altering
    rep(i,D) rep(j,10)
    {
        vector<int> b = a;
        if(b[i] == j) continue;
        b[i] = j;
        if(check(b) == 0) return true;
    }
    // if(a == test) print("hoge");
    return false;
}

vector<int> get_number(int x)
{
    vector<int> res;
    while(x)
    {
        res.push_back(x % 10);
        x /= 10;
    }
    while(res.size() < D) res.push_back(0);
    reverse(rng(res));
    // print(res);
    return res;
}

int main()
{
    rep(i,N) rep(j,N) cin >> table[i][j];
    ll ans = 0;
    for(int i=0; i<MAX_M; ++i)
    {
        auto num = get_number(i);
        num.erase(num.begin());
        num.push_back(check(num));
        if(ng(num)) ++ans;
        // print(num);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3468
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vpll = vector<pair<ll, ll>>;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
const int inf = 1<<30;
const ll INF = 1ll<<60;
const ll mod = 1000000007;
//const ll mod = 998244353;
//const ll dx[4] = {1, 0, -1, 0};
//const ll dy[4] = {0, 1, 0, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class T> void disp1(vector<T> &array, bool blank=1) {
    rep(i, array.size()) cout << ((i&&blank) ? " " : "") << array[i];
    cout << endl;
    //cout << " ";
}
template<class T> void disp2(vector<vector<T>> &array, bool blank=1) {
    rep(i, array.size()) disp1(array[i], blank);
}

ll rem(ll a, ll b) { return (a % b + b) % b; }      // 余りを0~b-1に丸める
// 小数の入力が文字で与えられたとき、10^n倍したものを返す
ll x10(string str_f, ll n) {
    if (str_f[0] == '-') return -x10(str_f.substr(1), n);
    ll times = 1; rep(i,n) times *= 10;     // times = 10^n
    int id = -1; rep(i,str_f.size()) if (str_f[i] == '.') id = i;
    if (id == -1) { return stoll(str_f)*times; }
    string str_int = str_f.substr(0, id), str_dec = str_f.substr(id+1);
    while (str_dec.size() < n) str_dec += '0';
    return stoll(str_int)*times + stoll(str_dec);
}
// A^N (mod)
ll modpow(ll A, ll N, ll mod) {
    ll RES = 1;
    while (N) {
        if (N & 1) RES = RES * A % mod;
        A = A * A % mod;
        N >>= 1;
    }
    return RES;
}

//using mint = modint1000000007;

const int n = 10;
int x[10][10];

string to_str(int t) {
    string ret;
    rep(i,5) {
        ret.pb(t%10+'0');
        t /= 10;
    }
    reverse(all(ret));
    return ret;
}


int f(int i) {
    int ret = i*10;
    int e = 0, d = 1000;
    rep(j,4) {
        e = x[e][i/d];
        i %= d;
        d /= 10;
    }
    ret += e;
    return ret;
}

int g(int t, int j, int k) {
    string s = to_str(t);
    s[j] = '0' + k;
    return stoi(s);
}

int check(int s) {
    int e = 0, d = 10000;
    rep(j,5) {
        e = x[e][s/d];
        s %= d;
        d /= 10;
    }
    return e;
}


int sw(int t, int j) {
    string s = to_str(t);
    swap(s[j], s[j+1]);
    return stoi(s);
}


int main() {
    rep(i,n) rep(j,n) cin >> x[i][j];
    int ans = 0;
    rep(i,10000) {
        int t = f(i);
        //cout << t << endl;
        bool ok = false;
        rep(j,5) {
            rep(k,10) {
                // j桁目をkにする
                int s = g(t, j, k);
                if (s == t) continue;
                //cout << s << endl;
                if (check(s) == 0) ok = 1;
            }
        }
        rep(j,4) {
            int s = sw(t, j);
            //cout << s << endl;
            if (s == t) continue;
            if (check(s) == 0) ok = 1;
        }
        //printf("\n");
        if (ok) ans++;
        //cout << i << endl;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 3220
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pint;
const ll MOD = 1000000007;
const ll INF = 922337203685477580;
#define rep(i, n) for(ll i = (ll)0; i < (ll)(n); i++)
#define Rep(i, s, t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll POW(ll a, ll n, ll mod = INF) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll to_int(string S) {
  ll N = S.size();
  ll ans = 0;
  rep (i, N) {
    ans = ans * 10 + (S[i] - '0');
  }
  return ans;
}

int main() {
  IOS;
  vector<vector<ll>> V(10, vector<ll>(10));
  rep (i, 10) rep (j, 10) cin >> V[i][j];
  ll ans = 0;
  rep (i, 10000) {
    ll ni = i;
    ll tmp = 0;
    rep (j, 4) {
      tmp = V[tmp][ni / POW(10, (3 - j))];
      ni %= POW(10, (3 - j));
    }
    ni = i * 10 + tmp;
    string S = to_string(ni);
    ll LEN = S.size();
    rep (j, 5 - LEN) {
      S = '0' + S;
    }
    bool flag = true;
    rep (j, 5) {
      rep (k, 10) {
        string T = S;
        if (T[j] - '0' == k) continue;
        T[j] = '0' + k;
        ll ttmp = 0;
        ll nni = to_int(T);
        rep (l, 5) {
          if (ttmp >= 10 || ttmp < 0 || nni / POW(10, (4 - l)) < 0 || nni / POW(10, (4 - l)) >= 10) {
            cout << i << endl;
          }
          ttmp = V[ttmp][nni / POW(10, (4 - l))];
          nni %= POW(10, (4 - l));
        }
        if (ttmp == 0) {
          flag = false;
        }
      }
    }
    rep (j, 4) {
      string T = S;
      swap(T[j], T[j + 1]);
      if (S == T) continue;
      ll ttmp = 0;
      ll nni = to_int(T);
      rep (l, 5) {
        ttmp = V[ttmp][nni / POW(10, (4 - l))];
        nni %= POW(10, (4 - l));
      }
      if (ttmp == 0) {
        flag = false;
      }
    }
    if (!flag) ans++;
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 120
memory_kb: 3308
final_rank: 17

code_snippet: #include <iostream>
#define llint long long

using namespace std;

llint a[10][10];

llint check(string s)
{
  llint p = 0;
  for(int i = 0; i < s.size(); i++){
    p = a[p][s[i]-'0'];
  }
  return p;
}

bool calc(llint x)
{
  string s;
  for(int i = 0; i < 4; i++, x /= 10) s += x%10 + '0';
  s += check(s)+'0';

  for(int i = 0; i < 5; i++){
    for(int j = 0; j < 10; j++){
      string t = s;
      t[i] = j+'0';
      if(check(t) == 0 && s != t) return false;
    }
  }
  for(int i = 0; i < 4; i++){
    string t = s;
    swap(t[i], t[i+1]);
    if(check(t) == 0 && s != t) return false;
  }
  return true;
}

int main(void)
{
  for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
      cin >> a[i][j];
    }
  }

  llint ans = 0;
  for(int i = 0; i < 10000; i++){
    if(!calc(i)) ans++;
  }
  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3220
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define int long long
//typedef long long i64;

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<'\n'
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<'\n'
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<'\n'
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<'\n'
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<'\n'
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

#define MAX_N (1000)
#define INF (1LL << 60)
#define eps 1e-9
const int MOD = (int)1e9 + 7;

vector<vector<int>> c;

bool is_correct(vector<int> v) {
    int ab = c[0][v[0]];
    int bc = c[ab][v[1]];
    int cd = c[bc][v[2]];
    int e = c[cd][v[3]];
    return c[e][v[4]]==0;
}

signed main(){
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);

    c.resize(10, vector<int>(10));
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            cin >> c[i][j];
        }
    }

    int ans=0;
    for(int id=0; id<10000; id++){
        string d = to_string(id);
        int n = d.length();
        for(int i=0; i<4-n; i++){
            d.insert(d.begin(),'0');
        }
        //debug(d);
        assert(d.length()==4);
        vector<int> v;
        for(int i=0; i<d.length(); i++) {
            v.push_back(d[i]-'0');
            debug(i,d[i]-'0');
        }

        int ab = c[0][v[0]];
        int bc = c[ab][v[1]];
        int cd = c[bc][v[2]];
        int e = c[cd][v[3]];
        v.push_back(e);
        //for(int i=0; i<v.size(); i++) cout << v[i]; cout << endl;

        bool f=false;
        for(int i=0; i<5; i++){
            for(int j=0; j<10; j++){
                vector<int> u = v;
                if(u[i]==j) continue;
                u[i] = j;
                if(is_correct(u)) {
                    f=true;
                }
            }
        }

        for(int i=0; i<4; i++){
            vector<int> u=v;
            if(u[i]==u[i+1]) continue;
            int tmp = u[i];
            u[i] = u[i+1];
            u[i+1] = tmp;
            if(is_correct(u)) f=true;
        }

        if(f) ans++;

    }

    cout << ans << endl;
}

/*

概要：
10x10のoperation tableが与えられる。
human errorsを検知できないIDの数を求める。

human errorは、１つの桁が異なるもの、隣接する桁が入れ替わってるもの。
check(abced)=0 なら正しいSSNである。
しかし、check(abced)=0でも正しいSSNでない場合があり、悪いtableとされる。

table2は、10000個のIDのうち、3439の番号でエラーを検知できない。


考察：
各IDに対して全てのhuman errorを試して、エラー検知できるか判定する。

10000 * (エラー1=10*5 + エラー2=4) = 10000 * 54 = 540000

各IDに対して、eを求める。
eを含めたIDに対して、全てのhuman errorでエラーとなるか判定する

*/
accuracy: 1
time_ms: 20
memory_kb: 3300
final_rank: 11

code_snippet: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int table[10][10];
    
int f(vi &a){
    int e=0;
    for(int t:a)e=table[e][t];
    return e;
}

void run(){
    rep(i,10)rep(j,10)cin>>table[i][j];
    int ans=0;
    rep(n,10000){
        vi a;
        int t=n;
        rep(_,4)a.eb(t%10),t/=10;
        reverse(all(a));
        a.eb(f(a));
        bool o=true;
        rep(i,5)rep(j,10){
            if(a[i]==j)continue;
            vi b=a;
            b[i]=j;
            o&=!!f(b);
        }
        rep(i,4){
            if(a[i]==a[i+1])continue;
            vi b=a;
            swap(b[i],b[i+1]);
            o&=!!f(b);
        }
        ans+=!o;
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3220
final_rank: 1

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

vector<vector<int>>v(10, vector<int>(10));

int check(string s) {
	int ret = 0;
	for (auto i : s) {
		ret = v[ret][i];
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int ans = 0;
	for (auto &i : v)for (auto &j : i)cin >> j;
	for (char i = 0; i < 10; i++) {
		for (char j = 0; j < 10; j++) {
			for (char k = 0; k < 10; k++) {
				for (char l = 0; l < 10; l++) {
					string s;
					s.push_back(i);
					s.push_back(j);
					s.push_back(k);
					s.push_back(l);
					char add = 0;
					for (auto e : s) {
						add = v[add][e];
					}
					s.push_back(add);
					bool ok = true;
					for (int a = 0; a < 5; a++) {
						for (char b = 0; b < 10; b++) {
							if (s[a] == b)continue;
							string t = s;
							t[a] = b;
							if (!check(t))ok = false;
						}
					}
					for (int a = 0; a < 4; a++) {
						if (s[a] == s[a + 1])continue;
						swap(s[a], s[a + 1]);
						if (!check(s))ok = false;
						swap(s[a], s[a + 1]);
					}
					if (!ok)ans++;
				}
			}
		}
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3256
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
int check(vector<int> &d2, vector<vector<int>> &x){
  int a = d2[0];
  int b = d2[1];
  int c = d2[2];
  int d = d2[3];
  int e = d2[4];
  return x[x[x[x[x[0][a]][b]][c]][d]][e];
}
int main(){
  vector<vector<int>> x(10, vector<int>(10));
  for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < 10000; i++){
    string S = to_string(i);
    while (S.size() < 4){
      S = '0' + S;
    }
    vector<int> d(5);
    for (int j = 0; j < 4; j++){
      d[j] = S[j] - '0';
    }
    d[4] = x[x[x[x[0][d[0]]][d[1]]][d[2]]][d[3]];
    bool err = false;
    for (int i = 0; i < 5; i++){
      for (int j = 0; j < 10; j++){
        if (d[i] != j){
          vector<int> d2 = d;
          d2[i] = j;
          if (check(d2, x) == 0){
            err = true;
          }
        }
      }
    }
    for (int i = 0; i < 4; i++){
      if (d[i] != d[i + 1]){
        vector<int> d2 = d;
        swap(d2[i], d2[i + 1]);
        if (check(d2, x) == 0){
          err = true;
        }
      }
    }
    if (err){
      ans++;
    }
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3284
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define lambda(res, ...) (function<res(__VA_ARGS__)>)[&](__VA_ARGS__)->res
#define method(name, res, ...)                                                 \
  function<res(__VA_ARGS__)> name = lambda(res, __VA_ARGS__)
#define foreach(i,n) for(auto&i:(n))

using namespace std;

int main(){
  int table[10][10];
  foreach(i,table)
    foreach(j,i)
    cin >> j;

  method(f,int,int x,int y){
    return table[x][y];
  };
  method(g,int,vector<int> xs){
    int res = 0;
    foreach(i,xs){
      res = f(res,i);
    }
    return res;
  };
  method(digits,vector<int>,int x,int n){
    vector<int> res;
    for(int i=0;i<n;++i){
      res.emplace_back(x%10);
      x/=10;
    }
    reverse(res.begin(),res.end());
    return res;
  };

  method(func,bool,int x){
    int y = x * 10 + g(digits(x,4));
    vector<int> ys = digits(y,5);
    foreach(i,ys){
      for(int j=0;j<10;++j){
        if(i==j)continue;
        swap(i, j);
        if(g(ys)==0)return true;
        swap(i, j);
      }
    }
    for(int i=0;i<4;++i){
      if(ys[i]==ys[i+1])continue;
      swap(ys[i],ys[i+1]);
      if(g(ys)==0)return true;
      swap(ys[i],ys[i+1]);
    }
    return false;
  };

  int ans = 0;

  for(int i=0;i<10000;++i){
    ans += func(i);
  }

  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3160
final_rank: 9

code_snippet: #include<bits/stdc++.h>
#define lambda(res,...) (function<res(__VA_ARGS__)>)[&](__VA_ARGS__) -> res
#define method(name,res,...) function<res(__VA_ARGS__)> name = (function<res(__VA_ARGS__)>)[&](__VA_ARGS__) -> res
#define foreach(i,n) for(auto &i:(n))

using namespace std;

vector<int> fact(int x){
	vector<int> res;
	for(int i=0;i<4;++i){
		int num = x % 10;
		res.emplace_back(num);
		x/=10;
	}
	reverse(res.begin(),res.end());
	return res;
}
int main(){
	vector<vector<int>> table(10,vector<int>(10));
	foreach(i,table){
		foreach(j,i){
			cin >> j;
		}
	}

	method(apply,int,vector<int> line){
		int res = 0;
		foreach(i,line){
			res = table[res][i];
		}
		return res;
	};
	method(func,bool,int x){
		vector<int> line = fact(x);
		int collect = apply(line);
		line.emplace_back(collect);
		//change one digits 
		foreach(i,line){
			for(int j=0;j<10;++j){
				if(i==j)continue;
				swap(i,j);
				int current = apply(line);
				if(current==0)return true;
				swap(i,j);
			}
		}

		//swap two digits
		for(int i=0;i+1<line.size();++i){
			if(line[i]==line[i+1])continue;
			swap(line[i],line[i+1]);
			int current = apply(line);
			if(current==0)return true;
			swap(line[i],line[i+1]);
		};
		return false;
	};

	int ans = 0;
	for(int i=0;i<10000;++i){
		ans +=  func(i);
	}

	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3164
final_rank: 10