#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long int ull;
using namespace std;
const ll MOD = (ll)1e9+7;
int MAXN = 1e6;
//classes
//global
int N, K;
string str;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  //ifstream fin("hps.in");
  //ofstream fout("hps.out");
  //stop
  cin >> N >> K >> str;
  stack<pair<char,int>> st;
  for(char& i: str){
    if(!st.empty() && st.top().first == i){
      st.emplace(i, st.top().second+1);
    }
    else st.emplace(i, 1);
    if(!st.empty() && st.top().second == K){
      int rem = K;
      while(rem--){
        st.pop();
      }
    }
  }
  string ans = "";
  while(!st.empty()){
    ans += st.top().first;
    st.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << ans << '\n';
  return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |