Language: C++

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest
{
    class MainClass : IDisposable
    {
        Scanner sc;
        Writer wr;
        string backPath = "..";
        char dirSep = System.IO.Path.DirectorySeparatorChar;
        string inFilePath = null;
        string outFilePath = null;
        public MainClass()
        {
            this.inFilePath = this.backPath
                            + this.dirSep
                            + this.backPath
                            + this.dirSep
                            + "in.txt";
            this.outFilePath = this.backPath
                             + this.dirSep
                             + this.backPath
                             + this.dirSep
                             + "out.txt";
        }
        static void Main(string[] args)
        {
            using (var mainClass = new MainClass())
            {
                //mainClass.MakeTestCase();
                mainClass.Solve();
            }
        }

        public void Dispose()
        {
            if (this.sc != null)
            {
                this.sc.Dispose();
                this.sc = null;
            }
            if (this.wr != null)
            {
                this.wr.Dispose();
                this.wr = null;
            }
        }

        void MakeTestCase()
        {
            Random rand = new Random();
            this.wr = new Writer(inFilePath);


        }

        void Solve()
        {
            this.wr = new Writer(this.isReactive);
            //this.wr = new Writer(this.outFilePath);
#if DEBUG
            if (!this.isReactive)
                this.sc = new Scanner(this.inFilePath);
            else
                this.sc = new Scanner();
#else
            this.sc = new Scanner();
#endif

            int H = sc.NextInt;
            int W = sc.NextInt;
            int[,] c = new int[10, 10];
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    c[i, j] = sc.NextInt;
                }
            }
            for (int k = 0; k < 10; k++)
            {
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        c[i, j] = Math.Min(c[i, j], c[i, k] + c[k, j]);
                    }
                }
            }
            int[,] A = new int[H, W];
            int ans = 0;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    A[i, j] = sc.NextInt;
                    if (A[i, j] != -1)
                    {
                        ans += c[A[i, j], 1];
                    }
                }
            }
            wr.WriteLine(ans);

        }

        bool isReactive = false; // TODO: reactive check !!
    }

    class Writer : IDisposable
    {
        private System.IO.TextWriter writer;
        private StringBuilder sb;
        private bool isReactive;
        public Writer(string path) : this(new System.IO.StreamWriter(path))
        {
        }
        public Writer(bool isReactive) : this(null, isReactive)
        {
        }
        public Writer(System.IO.TextWriter writer = null, bool isReactive = false)
        {
            this.writer = (writer ?? Console.Out);
            this.isReactive = isReactive;
            if (!this.isReactive)
                this.sb = new StringBuilder();
        }
        public void Dispose()
        {
            if (!this.isReactive)
                this.writer.Write(sb.ToString());
            if (!this.writer.Equals(Console.Out))
                this.writer.Dispose();
        }
        public void Write(object val)
        {
            if (this.isReactive)
            {
                this.writer.Write(val.ToString());
                this.writer.Flush();
            }
            else
                this.sb.Append(val.ToString());
        }
        public void Write(string format, params object[] vals)
        {
            if (this.isReactive)
            {
                this.writer.Write(format, vals);
                this.writer.Flush();
            }
            else
                this.sb.AppendFormat(format, vals);
        }
        public void WriteLine(object val)
        {
            this.Write(val.ToString() + System.Environment.NewLine);
        }
        public void WriteLine(string format, params object[] vals)
        {
            this.Write(format + System.Environment.NewLine, vals);
        }
    }

    class Scanner : IDisposable
    {
        private Queue<string> buffer;
        private char[] sep;
        private System.IO.TextReader reader;
        public Scanner(string path) : this(new System.IO.StreamReader(path))
        {
        }
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0)
            {
                string str = string.Empty;
                while (string.IsNullOrEmpty(str))
                    str = this.reader.ReadLine();

                str.Split(this.sep).ToList()
                    .ForEach(el => this.buffer.Enqueue(el));
            }
        }

        public void Dispose()
        {
            if (!this.reader.Equals(Console.In))
                this.reader.Dispose();
        }

        public string Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }

        public bool IsEnd
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}

Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.Linq;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.Text;
      |       ^~~~~~
a.cc:9:5: error: expected class-name before '{' token
    9 |     {
      |     ^
a.cc:10:9: error: 'Scanner' does not name a type
   10 |         Scanner sc;
      |         ^~~~~~~
a.cc:11:9: error: 'Writer' does not name a type
   11 |         Writer wr;
      |         ^~~~~~
a.cc:12:9: error: 'string' does not name a type
   12 |         string backPath = "..";
      |         ^~~~~~
a.cc:14:9: error: 'string' does not name a type
   14 |         string inFilePath = null;
      |         ^~~~~~
a.cc:15:9: error: 'string' does not name a type
   15 |         string outFilePath = null;
      |         ^~~~~~
a.cc:16:15: error: expected ':' before 'MainClass'
   16 |         public MainClass()
      |               ^~~~~~~~~~
      |               :
a.cc:29:26: error: 'string' has not been declared
   29 |         static void Main(string[] args)
      |                          ^~~~~~
a.cc:29:35: error: expected ',' or '...' before 'args'
   29 |         static void Main(string[] args)
      |                                   ^~~~
a.cc:38:15: error: expected ':' before 'void'
   38 |         public void Dispose()
      |               ^~~~~
      |               :
a.cc:111:6: error: expected ';' after class definition
  111 |     }
      |      ^
      |      ;
a.cc:13:23: error: 'System' was not declared in this scope
   13 |         char dirSep = System.IO.Path.DirectorySeparatorChar;
      |                       ^~~~~~
a.cc: In constructor 'ProgrammingContest::MainClass::MainClass()':
a.cc:18:18: error: request for member 'inFilePath' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   18 |             this.inFilePath = this.backPath
      |                  ^~~~~~~~~~
a.cc:18:36: error: request for member 'backPath' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   18 |             this.inFilePath = this.backPath
      |                                    ^~~~~~~~
a.cc:19:36: error: request for member 'dirSep' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   19 |                             + this.dirSep
      |                                    ^~~~~~
a.cc:20:36: error: request for member 'backPath' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   20 |                             + this.backPath
      |                                    ^~~~~~~~
a.cc:21:36: error: request for member 'dirSep' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   21 |                             + this.dirSep
      |                                    ^~~~~~
a.cc:23:18: error: request for member 'outFilePath' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   23 |             this.outFilePath = this.backPath
      |                  ^~~~~~~~~~~
a.cc:23:37: error: request for member 'backPath' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   23 |             this.outFilePath = this.backPath
      |                                     ^~~~~~~~
a.cc:24:37: error: request for member 'dirSep' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   24 |                              + this.dirSep
      |                                     ^~~~~~
a.cc:25:37: error: request for member 'backPath' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   25 |                              + this.backPath
      |                                     ^~~~~~~~
a.cc:26:37: error: request for member 'dirSep' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   26 |                              + this.dirSep
      |                                     ^~~~~~
a.cc: In static member function 'static void ProgrammingContest::MainClass::Main(int*)':
a.cc:31:19: error: expected nested-name-specifier before '(' token
   31 |             using (var mainClass = new MainClass())
      |                   ^
a.cc: In member function 'void ProgrammingContest::MainClass::Dispose()':
a.cc:40:22: error: request for member 'sc' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   40 |             if (this.sc != null)
      |                      ^~
a.cc:40:28: error: 'null' was not declared in this scope
   40 |             if (this.sc != null)
      |                            ^~~~
a.cc:42:22: error: request for member 'sc' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   42 |                 this.sc.Dispose();
      |                      ^~
a.cc:43:22: error: request for member 'sc' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   43 |                 this.sc = null;
      |                      ^~
a.cc:45:22: error: request for member 'wr' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   45 |             if (this.wr != null)
      |                      ^~
a.cc:45:28: error: 'null' was not declared in this scope
   45 |             if (this.wr != null)
      |                            ^~~~
a.cc:47:22: error: request for member 'wr' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   47 |                 this.wr.Dispose();
      |                      ^~
a.cc:48:22: error: request for member 'wr' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   48 |                 this.wr = null;
      |                      ^~
a.cc: In member function 'void ProgrammingContest::MainClass::MakeTestCase()':
a.cc:54:13: error: 'Random' was not declared in this scope
   54 |             Random rand = new Random();
      |             ^~~~~~
a.cc:55:18: error: request for member 'wr' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   55 |             this.wr = new Writer(inFilePath);
      |                  ^~
a.cc:55:27: error: expected type-specifier before 'Writer'
   55 |             this.wr = new Writer(inFilePath);
      |                           ^~~~~~
a.cc: In member function 'void ProgrammingContest::MainClass::Solve()':
a.cc:62:18: error: request for member 'wr' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   62 |             this.wr = new Writer(this.isReactive);
      |                  ^~
a.cc:62:27: error: expected type-specifier before 'Writer'
   62 |             this.wr = new Writer(this.isReactive);
      |                           ^~~~~~
a.cc:70:18: error: request for member 'sc' in '(ProgrammingContest::MainClass*)this', which is of pointer type 'ProgrammingContest::MainClass*' (maybe you meant to use '->' ?)
   70 |             this.sc = new Scanner();
      |                  ^~
a.cc:70:27: error: expected type-specifier before 'Scanner'
   70 |             this.sc = new Scanner();
      |                           ^~~~~~~
a.cc:73:21: error: 'sc' was not declared in this scope
   73 |             int H = sc.NextInt;
      |                     ^~
a.cc:75:17: error: expected identifier before ',' token
   75 |             int[,] c = new int[10, 10];
      |                 ^
a.cc:75:17: error: expected ']' before ',' token
a.cc:75:16: error: structured binding declaration cannot have type 'int'
   75 |             int[,] c = new int[10, 10];
      |                ^
a.cc:75:16: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:75:16: error: empty structured binding declaration
a.cc:75:20: error: expected initializer before 'c'
   75 |             int[,] c = new int[10, 10];
      |                    ^
a.cc:80:21: error: 'c' was not declared in this scope
   80 |                     c[i, j] = sc.NextInt;
      |                     ^
a.cc:89:25: error: 'c' was not declared in this scope
   89 |                         c[i, j] = Math.Min(c[i, j], c[i, k] + c[k, j]);
      |                         ^
a.cc:89:35: error: 'Math' was not declared in this scope
   89 |                         c[i, j] = Math.Min(c[i, j], c[i, k] + c[k, j]);
      |                                   ^~~~
a.cc:93:17: error: expected identifier before ',' token
   93 |             int[,] A = new int[H, W];
      |                 ^
a.cc:93:17: error: expected ']' before ',' token
a.cc:93:16: error: structured binding declaration cannot have type 'int'
   93 |             int[,] A = new int[H, W];
      |                ^
a.cc:93:16: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:93:16: error: empty structured binding declaration
a.cc:93:20: error: expected initializer before 'A'
   93 |             int[,] A = new int[H, W];
      |                    ^
a.cc:99:21: error: 'A' was not declared in t