Language: Java

#include<iostream>
#include<string>

using namespace std;

#define INF 1000000007
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
	string S;
	int K;
	cin >> S >> K;
	string G(S);
	int count_s = 0;
	int count_g = 1;
	for (int i = 1; i < S.length(); i++) {
		if (S[i] == S[i - 1]) {
			count_s++;
			S[i] = '0';
		}
	}
	for (int i = 2;i < G.length();i++) {
		if (G[i] == G[i-1]) {
			count_g++;
			G[i] = '0';
		}
	}
	if (S.length() == 1) {
		cout << count_s * ((K - 1) / 2 + 1) + count_g * K / 2 << endl;
		return 0;
	}
	if (S[0] != S[S.length()-1]) {
		cout << count_s * K <<endl; //SSSS...
	}
	else if(G[G.length()-1] == S[0]){
		cout << count_s + count_g * (K - 1) << endl; //SGGG...
	}
	else {
		cout << count_s * ((K-1)/2 + 1)  + count_g * K/2<< endl; //SGSGSGSG...
	}

Compiler output:
Main.java:1: error: illegal character: '#'
#include<iostream>
^
Main.java:2: error: illegal character: '#'
#include<string>
^
Main.java:6: error: illegal character: '#'
#define INF 1000000007
^
Main.java:6: error: class, interface, enum, or record expected
#define INF 1000000007
        ^
Main.java:7: error: illegal character: '#'
#define int long long
^
Main.java:8: error: illegal character: '#'
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
^
Main.java:8: error: class, interface, enum, or record expected
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
                                       ^
Main.java:8: error: class, interface, enum, or record expected
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
                                                ^
Main.java:9: error: illegal character: '#'
#define rep(i, n) FOR(i, 0, n)
^
Main.java:13: error: class, interface, enum, or record expected
}
^
Main.java:14: error: class, interface, enum, or record expected
int lcm(int a, int b) { return a / gcd(a, b) * b; }
                                                  ^
Main.java:18: error: unnamed classes are a preview feature and are disabled by default.
	int K;
	^
  (use --enable-preview to enable unnamed classes)
Main.java:19: error: class, interface, enum, or record expected
	cin >> S >> K;
	^
Main.java:20: error: <identifier> expected
	string G(S);
	          ^
Main.java:23: error: class, interface, enum, or record expected
	for (int i = 1; i < S.length(); i++) {
	^
Main.java:23: error: class, interface, enum, or record expected
	for (int i = 1; i < S.length(); i++) {
	                ^
Main.java:23: error: class, interface, enum, or record expected
	for (int i = 1; i < S.length(); i++) {
	                                ^
Main.java:26: error: class, interface, enum, or record expected
			S[i] = '0';
			^
Main.java:27: error: class, interface, enum, or record expected
		}
		^
Main.java:29: error: class, interface, enum, or record expected
	for (int i = 2;i < G.length();i++) {
	               ^
Main.java:29: error: class, interface, enum, or record expected
	for (int i = 2;i < G.length();i++) {
	                              ^
Main.java:32: error: class, interface, enum, or record expected
			G[i] = '0';
			^
Main.java:33: error: class, interface, enum, or record expected
		}
		^
Main.java:37: error: class, interface, enum, or record expected
		return 0;
		^
Main.java:38: error: class, interface, enum, or record expected
	}
	^
Main.java:41: error: class, interface, enum, or record expected
	}
	^
Main.java:44: error: class, interface, enum, or record expected
	}
	^
Main.java:47: error: class, interface, enum, or record expected
	}
	^
28 errors