Language: C++

package main

import (
	. "fmt"
	"bufio"
	"os"
	"strconv"
)

const INF int = 1e9
const LINF int64 = 1e9
const MOD int = INF + 7

func main() {
	next := newScanner()
	h, w := next.Int(), next.Int()
	c := make([][]int, 10)
	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			a := next.Int()

			c[i] = append(c[i], a)
		}
	}
	for k := 0; k < 10; k++ {
		for i := 0; i < 10; i++ {
			for j := 0; j < 10; j++ {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j])
			}
		}
	}

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			a := next.Int()

			if a == -1 {
				continue
			} else {
				ans += c[a][1]
			}
		}
	}

	Println(ans)
}

// Scanner begin

type scanner struct {
	r	*bufio.Reader
	buf []byte
	p	int
}

func newScanner() *scanner {
	return &scanner{r: bufio.NewReaderSize(os.Stdin, 10000)}
}

func (s *scanner) next() string {
	s.pre()
	start := s.p

	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}

	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)

	return string(s.buf[start:])
}

func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}

func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}

func (s *scanner) Float() float32 {
	f, _ := strconv.ParseFloat(s.next(), 32)

	return float32(f)
}

func (s *scanner) Float64() float64 {
	f, _ := strconv.ParseFloat(s.next(), 64)

	return f
}

func (s *scanner) Bool() bool {
	b, _ := strconv.ParseBool(s.next())

	return b
}

func (s *scanner) String() string {
	return s.next()
}


func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}

func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

// Scanner end

// Standard Function begin

func Itob(i int) bool {
	if i == 0 {
		return false
	} else {
		return true
	}
}

func Btoi(f bool) int {
	if f {
		return 1
	} else {
		return 0
	}
}

func min(a ...int) int {
	ret := a[0]
	for _, e := range a {
		if e < ret {
			ret = e
		}
	}

	return ret
}

func max(a ...int) int {
	ret := a[0]
	for _, e := range a {
		if e > ret {
			ret = e
		}
	}

	return ret
}

func minInt64(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		if e < ret {
			ret = e
		}
	}

	return ret
}

func maxInt64(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		if e > ret {
			ret = e
		}
	}

	return ret
}

func minFloat(a ...float32) float32 {
	ret := a[0]
	for _, e := range a {
		if e < ret {
			ret = e
		}
	}

	return ret
}

func maxFloat(a ...float32) float32 {
	ret := a[0]
	for _, e := range a {
		if e > ret {
			ret = e
		}
	}

	return ret
}

func minFloat64(a ...float64) float64 {
	ret := a[0]
	for _, e := range a {
		if e < ret {
			ret = e
		}
	}

	return ret
}

func maxFloat64(a ...float64) float64 {
	ret := a[0]
	for _, e := range a {
		if e > ret {
			ret = e
		}
	}

	return ret
}

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func absFloat(a float32) float32 {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func absFloat64(a float64) float64 {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

// Standard Struct begin

type pair struct {
	first, second int
}

type pairs []pair

func Newpair() *pair {
	return &pair {
		first : 0,
		second : 0,
	}
}

func (p pairs) Less(i, j int) bool {
	if p[i].first < p[j].first {
		return true
	} else if p[i].first == p[j].first {
		return p[i].second < p[j].second
	} else {
		return false
	}
}


Compiler output:
a.cc:1:1: error: 'package' does not name a type
    1 | package main
      | ^~~~~~~
a.cc:51:1: error: 'type' does not name a type; did you mean 'typeof'?
   51 | type scanner struct {
      | ^~~~
      | typeof
a.cc:57:1: error: 'func' does not name a type
   57 | func newScanner() *scanner {
      | ^~~~
a.cc:61:6: error: expected constructor, destructor, or type conversion before '(' token
   61 | func (s *scanner) next() string {
      |      ^
a.cc:76:6: error: expected constructor, destructor, or type conversion before '(' token
   76 | func (s *scanner) Line() string {
      |      ^
a.cc:84:6: error: expected constructor, destructor, or type conversion before '(' token
   84 | func (s *scanner) Int() int {
      |      ^
a.cc:89:6: error: expected constructor, destructor, or type conversion before '(' token
   89 | func (s *scanner) Int64() int64 {
      |      ^
a.cc:94:6: error: expected constructor, destructor, or type conversion before '(' token
   94 | func (s *scanner) Float() float32 {
      |      ^
a.cc:100:6: error: expected constructor, destructor, or type conversion before '(' token
  100 | func (s *scanner) Float64() float64 {
      |      ^
a.cc:106:6: error: expected constructor, destructor, or type conversion before '(' token
  106 | func (s *scanner) Bool() bool {
      |      ^
a.cc:112:6: error: expected constructor, destructor, or type conversion before '(' token
  112 | func (s *scanner) String() string {
      |      ^
a.cc:117:6: error: expected constructor, destructor, or type conversion before '(' token
  117 | func (s *scanner) pre() {
      |      ^
a.cc:124:6: error: expected constructor, destructor, or type conversion before '(' token
  124 | func (s *scanner) readLine() {
      |      ^
a.cc:142:1: error: 'func' does not name a type
  142 | func Itob(i int) bool {
      | ^~~~
a.cc:150:1: error: 'func' does not name a type
  150 | func Btoi(f bool) int {
      | ^~~~
a.cc:158:1: error: 'func' does not name a type
  158 | func min(a ...int) int {
      | ^~~~
a.cc:169:1: error: 'func' does not name a type
  169 | func max(a ...int) int {
      | ^~~~
a.cc:180:1: error: 'func' does not name a type
  180 | func minInt64(a ...int64) int64 {
      | ^~~~
a.cc:191:1: error: 'func' does not name a type
  191 | func maxInt64(a ...int64) int64 {
      | ^~~~
a.cc:202:1: error: 'func' does not name a type
  202 | func minFloat(a ...float32) float32 {
      | ^~~~
a.cc:213:1: error: 'func' does not name a type
  213 | func maxFloat(a ...float32) float32 {
      | ^~~~
a.cc:224:1: error: 'func' does not name a type
  224 | func minFloat64(a ...float64) float64 {
      | ^~~~
a.cc:235:1: error: 'func' does not name a type
  235 | func maxFloat64(a ...float64) float64 {
      | ^~~~
a.cc:246:1: error: 'func' does not name a type
  246 | func abs(a int) int {
      | ^~~~
a.cc:254:1: error: 'func' does not name a type
  254 | func absInt64(a int64) int64 {
      | ^~~~
a.cc:262:1: error: 'func' does not name a type
  262 | func absFloat(a float32) float32 {
      | ^~~~
a.cc:270:1: error: 'func' does not name a type
  270 | func absFloat64(a float64) float64 {
      | ^~~~
a.cc:280:1: error: 'type' does not name a type; did you mean 'typeof'?
  280 | type pair struct {
      | ^~~~
      | typeof
a.cc:284:1: error: 'type' does not name a type; did you mean 'typeof'?
  284 | type pairs []pair
      | ^~~~
      | typeof
a.cc:293:6: error: expected constructor, destructor, or type conversion before '(' token
  293 | func (p pairs) Less(i, j int) bool {
      |      ^