Language: C++

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		long Inf = (long) 1e18;
		long[][] ma = new long[3 * N + 1][];
		for(int i=0;i<3 * N + 1; i++){
			ma[i] = new long[N];
			for(int j=0;j<N; j++){
				ma[i][j] = -Inf;
			}
		}
		for(int i=0;i<M;i++) C[i] -= P;
		
		ma[0][0] = 0;
		for(int i=0;i<3*N;i++){
			for(int j=0;j<M;j++){
				int a = A[j];
				int b = B[j];
				long c = C[j];
//Console.WriteLine(String.Join(",", a, b, c));
				if(ma[i][a] == -Inf) continue;
				ma[i + 1][b] = Math.Max(ma[i + 1][b], ma[i][a] + c);
			}
		}
//Console.WriteLine("ok");
		
		long ma0 = 0;
		for(int i=0;i<=N;i++){
			ma0 = Math.Max(ma0, ma[N-1][i]);
		}
		long ma1 = 0;
		for(int i=N+1;i<=2*N;i++){
			ma1 = Math.Max(ma1, ma[N-1][i]);
		}
		long ma2 = 0;
		for(int i=2*N+1;i<=3*N;i++){
			ma2 = Math.Max(ma1, ma[N-1][i]);
		}
		
		if(ma2 > ma1){
			Console.WriteLine(-1);
			return;
		} else {
			Console.WriteLine(Math.Max(ma0, 0));
		}
		
		
		
	}
	int N,M;
	long P;
	int[] A,B;
	long[] C;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1]; P = d[2];
		A = new int[M];
		B = new int[M];
		C = new long[M];
		for(int i=0;i<M;i++){
			d = ria();
			A[i] = d[0] - 1;
			B[i] = d[1] - 1;
			C[i] = d[2];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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.Linq;
      |       ^~~~~~
a.cc:5:7: error: expected nested-name-specifier before 'System'
    5 | using System.Text;
      |       ^~~~~~
a.cc:12:2: error: expected ';' after class definition
   12 | }
      |  ^
      |  ;
a.cc: In static member function 'static void TEST::Main()':
a.cc:9:17: error: 'Sol' was not declared in this scope
    9 |                 Sol mySol =new Sol();
      |                 ^~~
a.cc:10:17: error: 'mySol' was not declared in this scope
   10 |                 mySol.Solve();
      |                 ^~~~~
a.cc: At global scope:
a.cc:15:15: error: expected ':' before 'void'
   15 |         public void Solve(){
      |               ^~~~~
      |               :
a.cc:64:12: error: expected unqualified-id before '[' token
   64 |         int[] A,B;
      |            ^
a.cc:65:13: error: expected unqualified-id before '[' token
   65 |         long[] C;
      |             ^
a.cc:66:15: error: expected ':' before 'Sol'
   66 |         public Sol(){
      |               ^~~~
      |               :
a.cc:80:16: error: 'String' does not name a type
   80 |         static String rs(){return Console.ReadLine();}
      |                ^~~~~~
a.cc:84:16: error: 'String' does not name a type
   84 |         static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
      |                ^~~~~~
a.cc:85:19: error: expected unqualified-id before '[' token
   85 |         static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
      |                   ^
a.cc:86:20: error: expected unqualified-id before '[' token
   86 |         static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
      |                    ^
a.cc:87:22: error: expected unqualified-id before '[' token
   87 |         static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
      |                      ^
a.cc:88:2: error: expected ';' after class definition
   88 | }
      |  ^
      |  ;
a.cc: In member function 'void Sol::Solve()':
a.cc:17:21: error: structured binding declaration cannot have type 'long int'
   17 |                 long[][] ma = new long[3 * N + 1][];
      |                     ^~
a.cc:17:21: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:17:21: error: empty structured binding declaration
a.cc:17:23: error: expected initializer before '[' token
   17 |                 long[][] ma = new long[3 * N + 1][];
      |                       ^
a.cc:19:25: error: 'ma' was not declared in this scope
   19 |                         ma[i] = new long[N];
      |                         ^~
a.cc:24:38: error: 'C' was not declared in this scope
   24 |                 for(int i=0;i<M;i++) C[i] -= P;
      |                                      ^
a.cc:26:17: error: 'ma' was not declared in this scope
   26 |                 ma[0][0] = 0;
      |                 ^~
a.cc:29:41: error: 'A' was not declared in this scope
   29 |                                 int a = A[j];
      |                                         ^
a.cc:30:41: error: 'B' was not declared in this scope
   30 |                                 int b = B[j];
      |                                         ^
a.cc:31:42: error: 'C' was not declared in this scope
   31 |                                 long c = C[j];
      |                                          ^
a.cc:34:48: error: 'Math' was not declared in this scope
   34 |                                 ma[i + 1][b] = Math.Max(ma[i + 1][b], ma[i][a] + c);
      |                                                ^~~~
a.cc:41:31: error: 'Math' was not declared in this scope
   41 |                         ma0 = Math.Max(ma0, ma[N-1][i]);
      |                               ^~~~
a.cc:45:31: error: 'Math' was not declared in this scope
   45 |                         ma1 = Math.Max(ma1, ma[N-1][i]);
      |                               ^~~~
a.cc:49:31: error: 'Math' was not declared in this scope
   49 |                         ma2 = Math.Max(ma1, ma[N-1][i]);
      |                               ^~~~
a.cc:53:25: error: 'Console' was not declared in this scope
   53 |                         Console.WriteLine(-1);
      |                         ^~~~~~~
a.cc:56:25: error: 'Console' was not declared in this scope
   56 |                         Console.WriteLine(Math.Max(ma0, 0));
      |                         ^~~~~~~
a.cc:56:43: error: 'Math' was not declared in this scope
   56 |                         Console.WriteLine(Math.Max(ma0, 0));
      |                                           ^~~~
a.cc: In constructor 'Sol::Sol()':
a.cc:67:17: error: 'var' was not declared in this scope
   67 |                 var d = ria();
      |                 ^~~
a.cc:68:21: error: 'd' was not declared in this scope
   68 |                 N = d[0]; M = d[1]; P = d[2];
      |                     ^
a.cc:69:17: error: 'A' was not declared in this scope
   69 |                 A = new int[M];
      |                 ^
a.cc:70:17: error: 'B' was not declared in this scope
   70 |                 B = new int[M];
      |                 ^
a.cc:71:17: error: 'C' was not declared in this scope
   71 |                 C = new long[M];
      |                 ^
a.cc:73:29: error: 'ria' was not declared in this scope; did you mean 'ri'?
   73 |                         d = ria();
      |                             ^~~
      |                             ri
a.cc: In static member function 'static int Sol::ri()':
a.cc:81:32: error: expected primary-expression before 'int'
   81 |         static int ri(){return int.Parse(Console.ReadLine());}
      |                                ^~~
a.cc:81:32: error: expected ';' before 'int'
a.cc:81:35: error: expected unqualified-id before '.' token
   81 |         static int ri(){return int.Parse(Console.ReadLine());}
      |                                   ^
a.cc: In static member function 'static long int Sol::rl()':
a.cc:82:33: error: expected primary-expression before 'long'
   82 |         static long rl(){return long.Parse(Console.ReadLine());}
      |                                 ^~~~
a.cc:82:33: error: expected ';' before 'long'
a.cc:82:37: error: expected unqualified-id before '.' token
   82 |         static long rl(){return long.Parse(Console.ReadLine());}
      |                                     ^
a.cc: In static member function 'static double Sol::rd()':
a.cc:83:35: error: expected primary-expression before 'double'
   83 |         static double rd(){return double.Parse(Console.ReadLine());}
      |                                   ^~~~~~
a.cc:83:35: error: expected ';' before 'double'
a.cc:83:41: error: expected unqualified-id before '.' token
   83 |         static double rd(){return double.Parse(Console.ReadLine());}
      |                                         ^