Language: C++

import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int N=scan.nextInt();
    int K=scan.nextInt();
    int R=scan.nextInt();
    int S=scan.nextInt();
    int P=scan.nextInt();
    scan.nextLine();
    String[] T=scan.nextLine().split("");
    String[] before=new String[N];
    int count=0;
    for(int i=0;i<T.length;i++){
      if(i-K<0){
        if(T[i].equals("r")){
          before[i]="p";
          count+=P;
        }
        else if(T[i].equals("s")){
          before[i]="r";
          count+=R;
        }
        else if(T[i].equals("p")){
          before[i]="s";
          count+=S;
        }
      }
      else{
        if(T[i].equals("r")){
          if(before[i-K].equals("p")){
            before[i]="r";
            count+=0;
          }else{
            before[i]="p";
            count+=P;
          }
        }
        if(T[i].equals("p")){
          if(before[i-K].equals("s")){
            before[i]="p";
            count+=0;
          }else{
            before[i]="s";
            count+=S;
          }
        }
        if(T[i].equals("s")){
          if(before[i-K].equals("r")){
            before[i]="s";
            count+=0;
          }else{
            before[i]="r";
            count+=R;
          }
        }
      }
    }
    System.out.println(count);
  }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:9: error: expected ':' before 'static'
    3 |   public static void main(String[] args){
      |         ^~~~~~~
      |         :
a.cc:3:27: error: 'String' has not been declared
    3 |   public static void main(String[] args){
      |                           ^~~~~~
a.cc:3:36: error: expected ',' or '...' before 'args'
    3 |   public static void main(String[] args){
      |                                    ^~~~
a.cc:61:2: error: expected ';' after class definition
   61 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:4:5: error: 'Scanner' was not declared in this scope
    4 |     Scanner scan=new Scanner(System.in);
      |     ^~~~~~~
a.cc:5:11: error: 'scan' was not declared in this scope
    5 |     int N=scan.nextInt();
      |           ^~~~
a.cc:11:5: error: 'String' was not declared in this scope
   11 |     String[] T=scan.nextLine().split("");
      |     ^~~~~~
a.cc:11:12: error: expected primary-expression before ']' token
   11 |     String[] T=scan.nextLine().split("");
      |            ^
a.cc:12:12: error: expected primary-expression before ']' token
   12 |     String[] before=new String[N];
      |            ^
a.cc:14:19: error: 'T' was not declared in this scope
   14 |     for(int i=0;i<T.length;i++){
      |                   ^
a.cc:17:11: error: 'before' was not declared in this scope
   17 |           before[i]="p";
      |           ^~~~~~
a.cc:21:11: error: 'before' was not declared in this scope
   21 |           before[i]="r";
      |           ^~~~~~
a.cc:25:11: error: 'before' was not declared in this scope
   25 |           before[i]="s";
      |           ^~~~~~
a.cc:31:14: error: 'before' was not declared in this scope
   31 |           if(before[i-K].equals("p")){
      |              ^~~~~~
a.cc:40:14: error: 'before' was not declared in this scope
   40 |           if(before[i-K].equals("s")){
      |              ^~~~~~
a.cc:49:14: error: 'before' was not declared in this scope
   49 |           if(before[i-K].equals("r")){
      |              ^~~~~~
a.cc:59:5: error: 'System' was not declared in this scope
   59 |     System.out.println(count);
      |     ^~~~~~