Language: C++

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;class Program
{
	
	static void Main(string[] args)
	{
        var exStdIn = new System.IO.StreamReader( "stdin.txt" );System.Console.SetIn( exStdIn );
		//const long inf = 100000000000000;
		
		var rck = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long r = rck[0], c = rck[1],k = rck[2];
		var map = new long[r, c];
		for (int i = 0; i < k; i++)
		{
			var rcv = Console.ReadLine().Split().Select(long.Parse).ToArray();
			map[rcv[0]-1, rcv[1]-1] = rcv[2];
		}
		var dp = new long[r, c, 4];

		dp[0,0,0] = 0;
		dp[0,0,1] = map[0, 0];
		for (int ri = 0; ri < r; ri++)
		{
			for (int ci = 0; ci < c; ci++)
			{
				for (int ni = 0; ni < 4; ni++)
				{
					if(ri<r-1){
						dp[ri+1,ci,0] = Max(dp[ri+1,ci,0], dp[ri,ci,ni]+map[ri+1,ci]);
						//dp[ri+1,ci,ni] = Max(dp[ri+1,ci,ni], dp[ri,ci,ni]);
					}
					if(ci<c-1){
						if(ni<3)dp[ri,ci+1,ni+1] = Max(dp[ri,ci+1,ni+1], dp[ri,ci,ni]+map[ri,ci+1]);
						dp[ri,ci+1,ni] = Max(dp[ri,ci+1,ni], dp[ri,ci,ni]);
					}
				}
			}
		}
		long ans = Max(Max(dp[r-1, c-1, 0], dp[r-1, c-1, 1]), Max(dp[r-1, c-1, 2], dp[r-1, c-1, 3]));
		Console.WriteLine(ans);
	}
}


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;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.Diagnostics;
      |       ^~~~~~
a.cc:5:7: error: expected nested-name-specifier before 'System'
    5 | using System.IO;
      |       ^~~~~~
a.cc:6:7: error: expected nested-name-specifier before 'System'
    6 | using System.Linq;
      |       ^~~~~~
a.cc:7:7: error: expected nested-name-specifier before 'System'
    7 | using System.Numerics;
      |       ^~~~~~
a.cc:8:7: error: expected nested-name-specifier before 'System'
    8 | using System.Text;
      |       ^~~~~~
a.cc:9:7: error: expected nested-name-specifier before 'System'
    9 | using System.Text.RegularExpressions;
      |       ^~~~~~
a.cc:10:7: error: expected nested-name-specifier before 'System'
   10 | using System.Threading.Tasks;
      |       ^~~~~~
a.cc:11:7: error: expected nested-name-specifier before 'static'
   11 | using static System.Math;class Program
      |       ^~~~~~
a.cc:14:26: error: 'string' has not been declared
   14 |         static void Main(string[] args)
      |                          ^~~~~~
a.cc:14:35: error: expected ',' or '...' before 'args'
   14 |         static void Main(string[] args)
      |                                   ^~~~
a.cc:51:2: error: expected ';' after class definition
   51 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Program::Main(int*)':
a.cc:16:9: error: 'var' was not declared in this scope
   16 |         var exStdIn = new System.IO.StreamReader( "stdin.txt" );System.Console.SetIn( exStdIn );
      |         ^~~
a.cc:16:65: error: 'System' was not declared in this scope
   16 |         var exStdIn = new System.IO.StreamReader( "stdin.txt" );System.Console.SetIn( exStdIn );
      |                                                                 ^~~~~~
a.cc:16:87: error: 'exStdIn' was not declared in this scope
   16 |         var exStdIn = new System.IO.StreamReader( "stdin.txt" );System.Console.SetIn( exStdIn );
      |                                                                                       ^~~~~~~
a.cc:19:21: error: expected ';' before 'rck'
   19 |                 var rck = Console.ReadLine().Split().Select(long.Parse).ToArray();
      |                     ^~~
a.cc:20:26: error: 'rck' was not declared in this scope
   20 |                 long r = rck[0], c = rck[1],k = rck[2];
      |                          ^~~
a.cc:21:21: error: expected ';' before 'map'
   21 |                 var map = new long[r, c];
      |                     ^~~
a.cc:22:37: error: 'k' was not declared in this scope
   22 |                 for (int i = 0; i < k; i++)
      |                                     ^
a.cc:24:29: error: expected ';' before 'rcv'
   24 |                         var rcv = Console.ReadLine().Split().Select(long.Parse).ToArray();
      |                             ^~~
a.cc:25:25: error: 'map' was not declared in this scope
   25 |                         map[rcv[0]-1, rcv[1]-1] = rcv[2];
      |                         ^~~
a.cc:25:29: error: 'rcv' was not declared in this scope
   25 |                         map[rcv[0]-1, rcv[1]-1] = rcv[2];
      |                             ^~~
a.cc:27:21: error: expected ';' before 'dp'
   27 |                 var dp = new long[r, c, 4];
      |                     ^~
a.cc:29:17: error: 'dp' was not declared in this scope
   29 |                 dp[0,0,0] = 0;
      |                 ^~
a.cc:30:29: error: 'map' was not declared in this scope
   30 |                 dp[0,0,1] = map[0, 0];
      |                             ^~~
a.cc:33:47: error: 'c' was not declared in this scope; did you mean 'ci'?
   33 |                         for (int ci = 0; ci < c; ci++)
      |                                               ^
      |                                               ci
a.cc:38:65: error: 'Max' was not declared in this scope
   38 |                                                 dp[ri+1,ci,0] = Max(dp[ri+1,ci,0], dp[ri,ci,ni]+map[ri+1,ci]);
      |                                                                 ^~~
a.cc:42:76: error: 'Max' was not declared in this scope
   42 |                                                 if(ni<3)dp[ri,ci+1,ni+1] = Max(dp[ri,ci+1,ni+1], dp[ri,ci,ni]+map[ri,ci+1]);
      |                                                                            ^~~
a.cc:43:66: error: 'Max' was not declared in this scope
   43 |                                                 dp[ri,ci+1,ni] = Max(dp[ri,ci+1,ni], dp[ri,ci,ni]);
      |                                                                  ^~~
a.cc:48:44: error: 'c' was not declared in this scope
   48 |                 long ans = Max(Max(dp[r-1, c-1, 0], dp[r-1, c-1, 1]), Max(dp[r-1, c-1, 2], dp[r-1, c-1, 3]));
      |                                            ^
a.cc:48:32: error: 'Max' was not declared in this scope
   48 |                 long ans = Max(Max(dp[r-1, c-1, 0], dp[r-1, c-1, 1]), Max(dp[r-1, c-1, 2], dp[r-1, c-1, 3]));
      |                                ^~~
a.cc:48:28: error: 'Max' was not declared in this scope
   48 |                 long ans = Max(Max(dp[r-1, c-1, 0], dp[r-1, c-1, 1]), Max(dp[r-1, c-1, 2], dp[r-1, c-1, 3]));
      |                            ^~~
a.cc:49:17: error: 'Console' was not declared in this scope
   49 |                 Console.WriteLine(ans);
      |                 ^~~~~~~