#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,a,b,c=0;
  string s1[3],s2[1];
  char str1[11];
  cin >> s1[0] >> n;
 
  for(int i=0;i<n;i++){
    cin >> s1[1] >> a >> b;

    if(s1[1] == "replace"){      // 置き換え
      cin >> s2[0];
      for(int j=a;j<=b;j++){
	s1[0][j]=s2[0][c];
	c++;
      }
      c=0;
    }

    if(s1[1] == "reverse"){      // 逆順
      for(int j=0;j<=(b-a)/2;j++){
	str1[0]=s1[0][a+j];
	s1[0][a+j]=s1[0][b-j];
	s1[0][b-j]=str1[0];
      }
    }

    if(s1[1] == "print"){        // 出力
      for(int j=a;j<=b;j++){
	cout << s1[0][j];
      }
      cout << endl;
    }

  }

  return 0;
}
#include <bits/stdc++.h>
using namespace std;

# define ll long long 
# define VI vector<int>
# define VLL vector<ll>
# define PII pair<int,int> 
#define mp make_pair
#define pb push_back
# define PI acos(-1)
# define ld long double
const int MxN = 200001 ; 
# define FOR(i,a,b) for(int i = a ; i < b ; ++i)
# define RFOR(i,a,b) for(int i = a ; i >= b ; --i)

/* VARIABLES */
int n , k ; 
VI a(MxN) ; 

/* END OF VARIABLES */



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;  

	cin >> n >> k ; 
	FOR(i,0,n)
		cin >> a[i] ; 
	if(k>=3*log2((ld)n))
	{
		FOR(i,0,n)
			cout<<n<<' ';
		return 0;
	}
	FOR(i,0,k) {
		VI tmp(n+1) ; 
		FOR(j,0,n) {
			int l = max(0,j-a[j])  ; 
			int r = min(n-1,j+a[j]) ; 
			tmp[l]++;
			if(r+1 < n) 
				tmp[r+1]--;
		}
		FOR(j,1,n) {
			tmp[j] += tmp[j-1] ; 
		}
		FOR(j,0,n){
			a[j] = tmp[j] ; 
		}
	}
	
	FOR(i,0,n) 
	cout << a[i] << " " ;
	
	return 0 ; 
}

