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 );
		
		
		var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long n = nk[0];
		var p = Console.ReadLine().Split().Select(long.Parse).ToArray();
		for (int i = 0; i < n; i++)
		{
			p[i]--;
		}
		var c = Console.ReadLine().Split().Select(long.Parse).ToArray();
		
		long finalAns = -1000000000000000;
		for (int s = 0; s < n; s++)
		{
			long k = nk[1];
			long sm = 0;
			long now = s;
			long cnt = 0;
			do{
				now = p[now];
				sm+=c[now];
				cnt++;
			}while(now!=s);

			long ans = 0;
			if(sm>0){
				ans+=sm*(k/cnt);
				k%=cnt;
			}else{
				k = Min(k, cnt);
			}

			long mx = -100000000000000;
			now = s;
			long tmp = 0;
			for (int j = 0; j < k; j++)
			{
				now = p[now];
				tmp+=c[now];
				if(tmp>mx)mx = tmp;
			}
			ans+=mx;
			if(ans>finalAns)finalAns = ans;
		}
		
		Console.WriteLine(finalAns);
	}
}


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:13:26: error: 'string' has not been declared
   13 |         static void Main(string[] args)
      |                          ^~~~~~
a.cc:13:35: error: expected ',' or '...' before 'args'
   13 |         static void Main(string[] args)
      |                                   ^~~~
a.cc:63:2: error: expected ';' after class definition
   63 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Program::Main(int*)':
a.cc:18:17: error: 'var' was not declared in this scope
   18 |                 var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
      |                 ^~~
a.cc:19:26: error: 'nk' was not declared in this scope; did you mean 'n'?
   19 |                 long n = nk[0];
      |                          ^~
      |                          n
a.cc:20:21: error: expected ';' before 'p'
   20 |                 var p = Console.ReadLine().Split().Select(long.Parse).ToArray();
      |                     ^
a.cc:23:25: error: 'p' was not declared in this scope
   23 |                         p[i]--;
      |                         ^
a.cc:25:21: error: expected ';' before 'c'
   25 |                 var c = Console.ReadLine().Split().Select(long.Parse).ToArray();
      |                     ^
a.cc:35:39: error: 'p' was not declared in this scope
   35 |                                 now = p[now];
      |                                       ^
a.cc:36:37: error: 'c' was not declared in this scope
   36 |                                 sm+=c[now];
      |                                     ^
a.cc:45:37: error: 'Min' was not declared in this scope; did you mean 'Main'?
   45 |                                 k = Min(k, cnt);
      |                                     ^~~
      |                                     Main
a.cc:53:39: error: 'p' was not declared in this scope
   53 |                                 now = p[now];
      |                                       ^
a.cc:54:38: error: 'c' was not declared in this scope
   54 |                                 tmp+=c[now];
      |                                      ^
a.cc:61:17: error: 'Console' was not declared in this scope
   61 |                 Console.WriteLine(finalAns);
      |                 ^~~~~~~