Language: C++

import java.util.*;
import java.io.*;


public class Main {

    public static void main(String args[]){
         FastScanner sc = new FastScanner();
         PrintWriter out = new PrintWriter(System.out);
         int H = sc.nextInt();
         int W = sc.nextInt();
         long[][] G = new long[10][10];
         for(int i=0;i<10;i++){
             for(int j=0;j<10;j++){
                 G[i][j] = sc.nextInt();
             }
         }
         long[][] table = graph.wf(G);

         int res = 0;
         for(int i=0;i<H;i++){
             for(int j=0;j<W;j++){
                 int a = sc.nextInt();
                 if(a==-1) continue;
                 else{
                    res += table[a][1];
                 }
             }
         }


         out.println(res);
         out.flush();
        //  System.out.println(sum);
    }
}

class MyMath{
    public static long gcm(long a, long b){
        if(a<b) return gcm(b, a);

        if(a%b==0 || b==0) return b;

        long remainder = a%b;
        return gcm(b, remainder);
    }

    public static long summation(long a, long b){
        return b*(b+1)/2-a*(a-1)/2;
    }

    public static long factorial(long n){

        if(n<=1) return 1;
        else return factorial(n-1)*n;
    }

    public static long binomial(int a, int b){
        if(a<b) return 0;
        long[][] table = new long[a+1][a+1];
        for(int i=0;i<a+1;i++){
            table[0][a] =  0;
            table[i][0] = 1;
            table[i][i] = 1;
        }
        for(int i=1;i<a+1;i++){
            for(int j=1;j<a+1;j++){
                if(i<j) table[i][j] = 0;
                else{
                    table[i][j] = table[i-1][j-1] + table[i-1][j];
                }
            }
        }
        return table[a][b];

    }
}

class graph{
    public static long dijkstra(int[][] G, int s, int t){
        Integer[] dist = new Integer[G.length];
        PriorityQueue<Integer> manage = new PriorityQueue<>((x,y) -> dist[x]-dist[y]);
        HashSet<Integer> searched = new HashSet<>();
        Arrays.fill(dist,Integer.MAX_VALUE);
        dist[s] = 0;
        searched.add(s);
        for(int i=0;i<G.length;i++){
            if(G[s][i]!=-1){
                dist[i] = G[s][i];
                manage.add(i);
            }
        }
        while(manage.size()>0){
            int now = manage.poll();
            searched.add(now);
            for(int i=0;i<G.length;i++){
                if(G[now][i]!=-1){
                    if(!searched.contains(i)){
                        if(dist[i]==Integer.MAX_VALUE){
                            dist[i] = dist[now] + G[now][i];
                            manage.add(i);
                        }
                        else{
                            dist[i] = Math.min(dist[i],dist[now]+G[now][i]);
                            manage.remove(i);
                            manage.add(i);
                        }
                    }
                }
            }
            if(searched.contains(t)) break;
        }

        return dist[t];
    }

    public static long[][] wf(long[][] G){
        long[][] dist = G;
        for(int i=0;i<G.length;i++){
            dist[i][i] = 0;
        }
        for(int i=0;i<G.length;i++){
            for(int j=0;j<G.length;j++){
                if(dist[i][j]==-1) dist[i][j] = 1_000_000_000;
            }
        }
        for(int i=0;i<G.length;i++){
            for(int j=0;j<G.length;j++){
                for(int k=0;k<G.length;k++){
                    dist[i][j] = Math.min(dist[i][j],dist[i][k]+dist[k][j]);
                }
            }
        }
        return dist;
    }
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.io.*;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: expected unqualified-id before 'public'
    5 | public class Main {
      | ^~~~~~
a.cc:39:11: error: expected ':' before 'static'
   39 |     public static long gcm(long a, long b){
      |           ^~~~~~~
      |           :
a.cc:48:11: error: expected ':' before 'static'
   48 |     public static long summation(long a, long b){
      |           ^~~~~~~
      |           :
a.cc:52:11: error: expected ':' before 'static'
   52 |     public static long factorial(long n){
      |           ^~~~~~~
      |           :
a.cc:58:11: error: expected ':' before 'static'
   58 |     public static long binomial(int a, int b){
      |           ^~~~~~~
      |           :
a.cc:77:2: error: expected ';' after class definition
   77 | }
      |  ^
      |  ;
a.cc: In static member function 'static long int MyMath::binomial(int, int)':
a.cc:60:13: error: structured binding declaration cannot have type 'long int'
   60 |         long[][] table = new long[a+1][a+1];
      |             ^~
a.cc:60:13: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:60:13: error: empty structured binding declaration
a.cc:60:15: error: expected initializer before '[' token
   60 |         long[][] table = new long[a+1][a+1];
      |               ^
a.cc:62:13: error: 'table' was not declared in this scope; did you mean 'mutable'?
   62 |             table[0][a] =  0;
      |             ^~~~~
      |             mutable
a.cc:68:25: error: 'table' was not declared in this scope; did you mean 'mutable'?
   68 |                 if(i<j) table[i][j] = 0;
      |                         ^~~~~
      |                         mutable
a.cc:70:21: error: 'table' was not declared in this scope; did you mean 'mutable'?
   70 |                     table[i][j] = table[i-1][j-1] + table[i-1][j];
      |                     ^~~~~
      |                     mutable
a.cc:74:16: error: 'table' was not declared in this scope; did you mean 'mutable'?
   74 |         return table[a][b];
      |                ^~~~~
      |                mutable
a.cc: At global scope:
a.cc:80:11: error: expected ':' before 'static'
   80 |     public static long dijkstra(int[][] G, int s, int t){
      |           ^~~~~~~
      |           :
a.cc:80:39: error: multidimensional array must have bounds for all dimensions except the first
   80 |     public static long dijkstra(int[][] G, int s, int t){
      |                                       ^
a.cc:80:41: error: expected ',' or '...' before 'G'
   80 |     public static long dijkstra(int[][] G, int s, int t){
      |                                         ^
a.cc:117:11: error: expected ':' before 'static'
  117 |     public static long[][] wf(long[][] G){
      |           ^~~~~~~
      |           :
a.cc:117:23: error: expected unqualified-id before '[' token
  117 |     public static long[][] wf(long[][] G){
      |                       ^
a.cc:136:2: error: expected ';' after class definition
  136 | }
      |  ^
      |  ;
a.cc: In static member function 'static long int graph::dijkstra(...)':
a.cc:81:9: error: 'Integer' was not declared in this scope
   81 |         Integer[] dist = new Integer[G.length];
      |         ^~~~~~~
a.cc:81:17: error: expected primary-expression before ']' token
   81 |         Integer[] dist = new Integer[G.length];
      |                 ^
a.cc:82:9: error: 'PriorityQueue' was not declared in this scope
   82 |         PriorityQueue<Integer> manage = new PriorityQueue<>((x,y) -> dist[x]-dist[y]);
      |         ^~~~~~~~~~~~~
a.cc:82:32: error: 'manage' was not declared in this scope
   82 |         PriorityQueue<Integer> manage = new PriorityQueue<>((x,y) -> dist[x]-dist[y]);
      |                                ^~~~~~
a.cc:82:45: error: 'PriorityQueue' does not name a type
   82 |         PriorityQueue<Integer> manage = new PriorityQueue<>((x,y) -> dist[x]-dist[y]);
      |                                             ^~~~~~~~~~~~~
a.cc:82:59: error: expected primary-expression before '>' token
   82 |         PriorityQueue<Integer> manage = new PriorityQueue<>((x,y) -> dist[x]-dist[y]);
      |                                                           ^
a.cc:82:62: error: 'x' was not declared in this scope
   82 |         PriorityQueue<Integer> manage = new PriorityQueue<>((x,y) -> dist[x]-dist[y]);
      |                                                              ^
a.cc:82:64: error: 'y' was not declared in this scope
   82 |         PriorityQueue<Integer> manage = new PriorityQueue<>((x,y) -> dist[x]-dist[y]);
      |                                                                ^
a.cc:82:78: error: 'dist' was not declared in this scope
   82 |         PriorityQueue<Integer> manage = new PriorityQueue<>((x,y) -> dist[x]-dist[y]);
      |                                                                              ^~~~
a.cc:83:9: error: 'HashSet' was not declared in this scope
   83 |         HashSet<Integer> searched = new HashSet<>();
      |         ^~~~~~~
a.cc:83:26: error: 'searched' was not declared in this scope
   83 |         HashSet<Integer> searched = new HashSet<>();
      |                          ^~~~~~~~
a.cc:83:41: error: 'HashSet' does not name a type
   83 |         HashSet<Integer> searched = new HashSet<>();
      |                                         ^~~~~~~
a.cc:83:49: error: expected primary-expression before '>' token
   83 |         HashSet<Integer> searched = new HashSet<>();
      |                                                 ^
a.cc:83:51: error: expected primary-expression before ')' token
   83 |         HashSet<Integer> searched = new HashSet<>();
      |                                                   ^
a.cc:84:9: error: 'Arrays' was not declared in this scope
   84 |         Arrays.fill(dist,Integer.MAX_VALUE);
      |         ^~~~~~
a.cc:85:14: error: 's' was not declared in this scope
   85 |         dist[s] = 0;
      |              ^
a.cc:87:23: error: 'G' was not declared in this scope
   87 |         for(int i=0;i<G.length;i++){
      |                       ^
a.cc:96:27: error: 'G' was not declared in this scope
   96 |             for(int i=0;i<G.length;i++){
      |                           ^
a.cc:104:39: error: 'Math' was not declared in this scope; did you mean 'MyMath'?
  104 |                             dist[i] = Math.min(dist[i],dist[now]+G[now][i]);
      |                                       ^~~~
      |                                       MyMath
a.cc:111:34: error: 't' was not declared in this scope
  111 |             if(searched.contains(t)) break;
      |                                  ^
a.cc:114:21: error: 't' was not declared in this scope
  114 |         return dist[t];
      |                     ^
a.cc: At global scope:
a.cc:140:12: error: expected ':' before 'final'
  140 |     private final InputStream in = System.in;
      |            ^~~~~~
      |            :
a.cc:140:13: error: 'final' does not name a type
  140 |     private final InputStream in = System.in;
      |             ^~~~~
a.cc:141:12: error: expected ':' before 'final'
  141 |     private final byte[] buffer = new byte[1024];
      |            ^~~~~~
      |            :
a.cc:141:13: error: 'final' does not name a type
  141 |     private final byte[] buffer = new byte[1024];
      |             ^~~~~
a.cc:142:12: error: expected ':' before 'int'
  142 |     private int ptr = 0;
      |            ^~~~
      |            :
a.cc:143:12: error: expected ':' before 'int'
  143 |     private int buflen = 0;
      |            ^~~~
      |            :
a.cc:144:12: error: expected ':' before 'boolean'
  144 |     private boolean hasNextByte() {
      |            ^~~~~~~~
      |            :
a.cc:144:13: error: 'boolean' does not name a type; did you mean 'bool'?
  144 |     private boolean hasNextByte() {
      |             ^~~~~~~
      |             bool
a.cc:160:12: error: expected ':' before 'int'
  160 |     private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
      |            ^~~~
      |            :
a.cc:161:12: error: expected ':' before 'static'
  161 |     private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
      |            ^~~~~~~
      |            :
a.cc:161:20: error: 'boolean' does not name a type; did you mean 'bool'?
  161 |     private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
      |                    ^~~~~~~
      |                    bool
a.cc:162:11: error: expected ':' before 'boolean'
  162 |     public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
      |           ^~~~~~~~
      |           :
a.cc:162:12: error: 'boolean' does not name a type; did you mean 'bool'?
  162 |     public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
      |            ^~~~~~~
      |            bool
a.cc:163:11: error: expected ':' before 'String'
  163 |     public String next() {
      |           ^~~~~~~
      |           :
a.cc:163:12: error: 'String' does not name a type
  163 |     public String next() {
      |            ^~~~~~
a.cc:173:11: error: expected ':' before 'long'
  173 |     public long nextLong() {
      |           ^~~~~
      |           :
a.cc:197:11: error: expected ':' before 'int'
  197 |     public int nextInt() {
      |           ^~~~
      |           :
a.cc:202:11: error: expected ':' before 'double'
  202 |     public double nextDouble() { return Double.parseDouble(next());}
      |           ^~~~~~~
      |           :
a.cc:203:2: error: expected ';' after class definition
  203 | }
      |  ^
      |  ;
a.cc: In member function 'int FastScanner::readByte()':
a.cc:160:34: error: 'hasNextByte' was not declared in this scope
  160 |     private int readByte() { if (hasNextByte()) re