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

main() {
  string s;
  int n;
  cin>>n>>s;
  string h="RGB";
  int ans=0;
  if(n==2){
  	int ans=0;
    if(s[0]==s[1]){
      if(s[0]=='G'){
        s[1]='R';
        ans++;
      }
      else if(s[0]=='R'){
        s[1]='G';
        ans++;
      }
      else{
        s[1]='G';
        ans++;
      }
    }
    cout<<ans<<endl<<s;
    return 0;
  }
  for(int i=1;i<n-1;i++){
    if(s[i]!=s[i-1] || s[i]!=s[i+1])continue;
    for(int j=0;j<3;j++){
      if(s[i-1]==h[j] && s[i+1]==h[j]){
        continue;
      }
      else{
        s[i]=h[j];
        ans++;
        break;
      }
    }
  }
  for(int i=1;i<n-1;i++){
    if(s[i]!=s[i-1] && s[i]!=s[i+1])continue;
    for(int j=0;j<3;j++){
      if(s[i-1]==h[j] && s[i+1]==h[j]){
        continue;
      }
      else{
        s[i]=h[j];
        ans++;
        break;
      }
    }
  }
  cout<<ans<<endl<<s;
}


#include <bits/stdc++.h>
using namespace std;
pair<int,int> b[200005];
int n,m,a[200005];
int solve(int x,int y){
	int mn=0,mx=0;
	mn=a[x];
	mx=a[y];
	//cout<<mn<<' '<<mx<<endl;
	for(int i=1;i<=m;i++){
		if(x>=b[i].first && x<=b[i].second && !(y>=b[i].first && y<=b[i].second)){
			mn--;
		}
	}
	return mx-mn;
}

main() {

	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=m;i++){
		cin>>b[i].first>>b[i].second;
	}
	int imax=-1e9+7;
	int mnn,mxx;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j)continue;
			int q=solve(i,j);
			if(imax<q){
				mnn=i,mxx=j;
				imax=q;
			}
			//cout<<i<<' '<<j<<' '<<q<<endl;

		}
	}
	//cout<<mn<<' '<<mx<<endl;;

	if(imax==-1e9+7){
		cout<<0<<endl<<0;
		return 0;
	}
	cout<<imax<<endl;
	int mn=a[mnn];
	int mx=a[mxx];
	int ans=0;
	for(int i=1;i<=m;i++){
		if(mnn>=b[i].first && mnn<=b[i].second && !(mxx>=b[i].first && mxx<=b[i].second)){
			mn--;
			ans++;
		}
	}
	cout<<ans<<endl;
	mn=a[mnn];
	mx=a[mxx];
	for(int i=1;i<=m;i++){
		if(mnn>=b[i].first && mnn<=b[i].second && !(mxx>=b[i].first && mxx<=b[i].second)){
			cout<<i<<' ';
		}
	}
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <map>
#include <set>
#include <stack>

using namespace std;
#define c(n) int n;cin >> n;
#define sz(x) int((x).size())
#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(a,b,i) for(int (i) = (a); (i) >= (b); --(i))
#define ff(a,b,i) for (int (i) = a; (i) < (b); ++(i))
#define repd(i,n) for (int (i) = n; (i)--; )
#define fe(i,a) for (int (i) = 0; (i) < int((a).size()); ++(i))
#define mem(a, val) memset((a),val,sizeof(a))

#define pb push_back
#define ppb pop_back
#define all(c) (c).begin(), (c).end()
#define pi acos(-1.0)
#define sqr(a) ((a)*(a))
#define mp(a,b) make_pair((a), (b))
#define xx first
#define yy second
#define MOD 1000000007
#define rt return 0
#define LL long long int
#define vt vector
#define vi vector<int>
#define vll vector<long long int>
#define vst vector<string>
#define col(n) cout << n <<endl
const LL infL = 1e18;
const int inf = 1e9;
int main() {
	c(n);
	string str;
	cin >> str;
	const string s = "RBG";
	int cnt = 0;
	ff(1, str.size(), i) {
		if (str[i] == str[i - 1]) {
			if (str[i - 1] != 'G' && (i + 1 == n || str[i + 1] != 'G'))str[i] = 'G';
			if (str[i - 1] != 'R' && (i + 1 == n || str[i + 1] != 'R'))str[i] = 'R';
			if (str[i - 1] != 'B' && (i + 1 == n || str[i + 1] != 'B'))str[i] = 'B';
			cnt++;
		}
	}
	col(cnt);
	col(str);
	rt;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <map>
#include <set>
#include <stack>

using namespace std;
#define c(n) int n;cin >> n;
#define sz(x) int((x).size())
#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(a,b,i) for(int (i) = (a); (i) >= (b); --(i))
#define ff(a,b,i) for (int (i) = a; (i) < (b); ++(i))
#define repd(i,n) for (int (i) = n; (i)--; )
#define fe(i,a) for (int (i) = 0; (i) < int((a).size()); ++(i))
#define mem(a, val) memset((a),val,sizeof(a))

#define pb push_back
#define ppb pop_back
#define all(c) (c).begin(), (c).end()
#define pi acos(-1.0)
#define sqr(a) ((a)*(a))
#define mp(a,b) make_pair((a), (b))
#define xx first
#define yy second
#define MOD 1000000007
#define rt return 0
#define LL long long int
#define vt vector
#define vi vector<int>
#define vll vector<long long int>
#define vst vector<string>
#define col(n) cout << n <<endl
const LL infL = 1e18;
const int inf = 1e9;
int main() {
	c(n);
	string str;
	cin >> str;
	const string s = "RBG";
	int cnt = 0;
	ff(1, str.size(), i) {
		if (str[i] == str[i - 1]) {
			if (str[i - 1] != 'G' && (i + 1 == n || str[i + 1] == 'G'))str[i] = 'G';
			if (str[i - 1] != 'R' && (i + 1 == n || str[i + 1] == 'R'))str[i] = 'R';
			if (str[i - 1] != 'B' && (i + 1 == n || str[i + 1] == 'B'))str[i] = 'B';
			cnt++;
		}
	}
	col(cnt);
	col(str);
	rt;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <map>
#include <set>
#include <stack>

using namespace std;
#define c(n) int n;cin >> n;
#define sz(x) int((x).size())
#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(a,b,i) for(int (i) = (a); (i) >= (b); --(i))
#define ff(a,b,i) for (int (i) = a; (i) < (b); ++(i))
#define repd(i,n) for (int (i) = n; (i)--; )
#define fe(i,a) for (int (i) = 0; (i) < int((a).size()); ++(i))
#define mem(a, val) memset((a),val,sizeof(a))

#define pb push_back
#define ppb pop_back
#define all(c) (c).begin(), (c).end()
#define pi acos(-1.0)
#define sqr(a) ((a)*(a))
#define mp(a,b) make_pair((a), (b))
#define xx first
#define yy second
#define MOD 1000000007
#define rt return 0
#define LL long long int
#define vt vector
#define vi vector<int>
#define vll vector<long long int>
#define vst vector<string>
#define col(n) cout << n <<endl
const LL infL = 1e18;
const int inf = 1e9;
int main() {
	c(n);
	string str;
	cin >> str;
	int cnt = 0;

	string ans="";
	ans += str[0];
	ff(1, str.size(), i) {
		if (str[i] != str[i - 1]) {
			ans += str[i];
			continue;
		}
		cnt++;
		set<char>s;
		s.insert('R');
		s.insert('G');
		s.insert('B');
		s.erase(str[i]);
		if (i + 1 < n) {
			s.erase(str[i + 1]);
		}
		ans += *s.begin();
		str[i] = *s.begin();
	}
	col(cnt);
	col(ans);
	rt;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <map>
#include <set>
#include <stack>

using namespace std;
#define c(n) int n;cin >> n;
#define sz(x) int((x).size())
#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(a,b,i) for(int (i) = (a); (i) >= (b); --(i))
#define ff(a,b,i) for (int (i) = a; (i) < (b); ++(i))
#define repd(i,n) for (int (i) = n; (i)--; )
#define fe(i,a) for (int (i) = 0; (i) < int((a).size()); ++(i))
#define mem(a, val) memset((a),val,sizeof(a))

#define pb push_back
#define ppb pop_back
#define all(c) (c).begin(), (c).end()
#define pi acos(-1.0)
#define sqr(a) ((a)*(a))
#define mp(a,b) make_pair((a), (b))
#define xx first
#define yy second
#define MOD 1000000007
#define rt return 0
#define LL long long int
#define vt vector
#define vi vector<int>
#define vll vector<long long int>
#define vst vector<string>
#define col(n) cout << n <<endl
const LL infL = 1e18;
const int inf = 1e9;
int main() {
	c(n);
	string str;
	cin >> str;
	const string s = "RBG";
	int cnt = 0;
	ff(1, str.size(), i) {
		if (str[i] == str[i - 1]) {
			if (i + 1 < str.size() && str[i] != str[i + 1]) {
				ff(0, s.size(), j) {
					if (s[j] != str[i] && s[j] != str[i + 1]) {
						str[i] = s[j];
						break;
					}
				}

			}
			else {
				if (i + 1 == str.size()) {
					ff(0, s.size(), j) {
						if (s[j] != str[i]) {
							str[i] = s[j];
							break;
						}
					}
				}
				else {
					ff(0, s.size(), j) {
						if (s[j] != str[i] && s[j]!=str[i+1]) {
							str[i] = s[j];
							break;
						}
					}
				}

			}
			cnt++;
		}
	}
	col(cnt);
	col(str);
	rt;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <map>
#include <set>
#include <stack>

using namespace std;
#define c(n) int n;cin >> n;
#define sz(x) int((x).size())
#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(a,b,i) for(int (i) = (a); (i) >= (b); --(i))
#define ff(a,b,i) for (int (i) = a; (i) < (b); ++(i))
#define repd(i,n) for (int (i) = n; (i)--; )
#define fe(i,a) for (int (i) = 0; (i) < int((a).size()); ++(i))
#define mem(a, val) memset((a),val,sizeof(a))

#define pb push_back
#define ppb pop_back
#define all(c) (c).begin(), (c).end()
#define pi acos(-1.0)
#define sqr(a) ((a)*(a))
#define mp(a,b) make_pair((a), (b))
#define xx first
#define yy second
#define MOD 1000000007
#define rt return 0
#define LL long long int
#define vt vector
#define vi vector<int>
#define vll vector<long long int>
#define vst vector<string>
#define col(n) cout << n <<endl
const LL infL = 1e18;
const int inf = 1e9;
int main() {
	c(n);
	string str;
	cin >> str;
	const string s = "RBG";
	int cnt = 0;
	ff(1, str.size(), i) {
		if (str[i] == str[i - 1]) {
			if (i + 1 < str.size() && str[i] != str[i + 1]) {
				ff(0, s.size(), j) {
					if (s[j] != str[i] && str[j] != str[i + 1]) {
						str[i] = s[j];
						break;
					}
				}

			}
			else {
				ff(0, s.size(), j) {
					if (s[j] != str[i]) {
						str[i] = s[j];
						break;
					}
				}
			}
			cnt++;
		}
	}
	col(cnt);
	col(str);
	rt;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	string str;
  int len;
  cin>>len;
  cin>>str;
  int ans = 0;
  for(int i=1;i<len;i++){
    if(str[i] == str[i-1]){
      char s = 'B';
      ans ++;
      if(str[i-1] == 'B' || (i + 1 < len && str[i+1] == 'B')){
        s = 'G';
        if(str[i-1] == 'G' || (i + 1 < len && str[i+1] == 'G'))s = 'R';
      }
      str[i] = s;
    }
  }
  cout<<ans<<endl<<str<<endl;
  return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	string str;
  int len;
  cin>>len;
  cin>>str;
  int ans = 0;
  for(int i=1;i<len;i++){
    if(str[i] == str[i-1]){
      char s = 'B';
      ans ++;
      if(str[i-1] == 'B' || (i + 1 < len && str[i+1] == 'B'))s = 'G';
      if(str[i-1] == 'G' || (i + 1 < len && str[i+1] == 'G'))s = 'R';
      str[i] = s;
    }
  }
  cout<<ans<<endl<<str<<endl;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
  string str;
  int len;
  cin>>len;
  cin>>str;
  // if(str[0] == str[1]){
  //   if(str[1] == 'B') str[0] = 'G';
  //   if(str[1] == 'G') str[0] = 'B';
  //   if(str[1] == 'R') str[0] = 'G';
  // }
  int ans = 1;
  int b = 0;
  for(int i=1;i<len;i++){
    if(str[i] == str[i-1]){
      ans ++;
    }
    else{
      // cout<<ans/2<<endl;
      b += ans / 2;
      ans = 1;
    }
  }
  b += (ans / 2);
  cout<<b<<endl;
  cout<<str<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define vi vector<ll>
#define vp vector<pair<int, int>>
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
using namespace std;
int main()
{
    IOS
    int n;
    string s;
    cin>>n>>s;
    string t="";
    int cnt=0;
    t=t+s[0];
    if(n==1)
    {
        cout<<0<<endl;
        cout<<t<<endl;
        return 0;
    }
    map<char, int>M1;
    map<int, char>M2;
    M1['R']=1;
    M1['G']=2;
    M1['B']=3;
    M2[6]=M2[5]='R';
    M2[2]=M2[4]='G';
    M2[3]=M2[7]='B';
    for (int i=1; i<n-1; i++)
    {
        if(s[i]==t[i-1])
        {
            char c=t[i-1];
            char ch=s[i+1];
            if(M1[c]==2 && M1[ch]==2)
                t=t+M2[7];
            else
                t=t+M2[M1[c]+M1[ch]];
            cnt++;
        }
        else
            t=t+s[i];
    }
    if(t[n-2]==s[n-1])
    {
        char ch=s[n-1];
        t=t+M2[5-M1[ch]];
        cnt++;
    }
    else
        t=t+s[n-1];
    cout<<cnt<<endl;
    cout<<t<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define vi vector<ll>
#define vp vector<pair<int, int>>
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    string t="";
    int cnt=0;
    t=t+s[0];
    if(n==1)
    {
        cout<<0<<endl;
        cout<<t<<endl;
        return 0;
    }
    map<char, int>M1;
    map<int, char>M2;
    M1['R']=1;
    M1['G']=2;
    M1['B']=3;
    M2[6]=M2[5]='R';
    M2[2]=M2[4]='G';
    M2[3]=M2[7]='B';
    for (int i=1; i<n-1; i++)
    {
        if(s[i]==t[i-1])
        {
            char c=t[i-1];
            char ch=s[i+1];
            if(M1[c]==2 && M1[ch]==2)
                t=t+M2[7];
            else
                t=t+M2[M1[c]+M1[ch]];
            cnt++;
        }
        else
            t=t+s[i];
    }
    if(t[n-2]==s[n-1])
    {
        char ch=s[n-1];
        t=t+M2[5-M1[ch]];
        cnt++;
    }
    else
        t=t+s[n-1];
    cout<<cnt<<endl;
    cout<<t<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define vi vector<ll>
#define vp vector<pair<int, int>>
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
using namespace std;
int main()
{
    IOS
    int n;
    string s;
    cin>>n>>s;
    string t="";
    int cnt=0;
    t=t+s[0];
    if(n==1)
    {
        cout<<0<<endl;
        cout<<t<<endl;
        return 0;
    }
    map<char, int>M1;
    map<int, char>M2;
    M1['R']=1;
    M1['G']=2;
    M1['B']=3;
    char a[8];
    a[6]=a[5]='R';
    a[2]=a[4]='G';
    a[3]=a[7]='B';
    for (int i=1; i<n-1; i++)
    {
        if(s[i]==t[i-1])
        {
            char c=t[i-1];
            char ch=s[i+1];
            if(M1[c]==2 && M1[ch]==2)
                t=t+a[7];
            else
                t=t+a[M1[c]+M1[ch]];
            cnt++;
        }
        else
            t=t+s[i];
    }
    if(t[n-2]==s[n-1])
    {
        char ch=s[n-1];
        t=t+a[5-M1[ch]];
        cnt++;
    }
    else
        t=t+s[n-1];
    cout<<cnt<<endl;
    cout<<t<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define vi vector<ll>
#define vp vector<pair<int, int>>
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    string t="";
    int cnt=0;
    t=t+s[0];
    map<char, int>M1;
    map<int, char>M2;
    M1['R']=1;
    M1['G']=2;
    M1['B']=3;
    M2[6]=M2[5]='R';
    M2[2]=M2[4]='G';
    M2[3]=M2[7]='B';
    for (int i=1; i<n-1; i++)
    {
        if(s[i]==t[i-1])
        {
            char c=t[i-1];
            char ch=s[i+1];
            if(M1[c]==2 && M1[ch]==2)
                t=t+M2[7];
            else
                t=t+M2[M1[c]+M1[ch]];
            cnt++;
        }
        else
            t=t+s[i];
    }
    if(t[n-2]==s[n-1])
    {
        char ch=s[n-1];
        t=t+M2[5-M1[ch]];
        cnt++;
    }
    else
        t=t+s[n-1];
    cout<<cnt<<endl;
    cout<<t<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define vi vector<ll>
#define vp vector<pair<int, int>>
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
using namespace std;
int main()
{
    IOS
    int n;
    string s;
    cin>>n>>s;
    string t="";
    int cnt=0;
    if(n==1)
    {
        cout<<0<<endl;
        cout<<s<<endl;
        return 0;
    }
    map<char, int>M1;
    map<int, char>M2;
    M1['R']=1;
    M1['G']=2;
    M1['B']=3;
    char a[8];
    a[6]=a[5]='R';
    a[2]=a[4]='G';
    a[3]=a[7]='B';
    for (int i=1; i<n-1; i++)
    {
        if(s[i]==s[i-1])
        {
            char c=s[i-1];
            char ch=s[i+1];
            if(M1[c]==2 && M1[ch]==2)
                s[i]=a[7];
            else
                s[i]=a[M1[c]+M1[ch]];
            cnt++;
        }
    }
    if(s[n-2]==s[n-1])
    {
        char ch=s[n-1];
        s[n-1]=a[5-M1[ch]];
        cnt++;
    }
    cout<<cnt<<endl;
    cout<<s<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793238
#define INF 1e9+5

int main()
{
	ll n,ans=0;string s,s1="RBG";
	cin>>n>>s;
	for(int x=0;x<n;x++){
         if(s[x]==s[x+1] && s[x]==s[x+2]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x] ||  s1[y]!=s[x+2]){
                    s[x+1]=s1[y];
                    x+=2;
                    ans++;
                    break;
                }
            }
        }
        else if(s[x]==s[x-1] || s[x]==s[x+1]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x-1] &&  s1[y]!=s[x+1]){
                    s[x]=s1[y];
                    ans++;
                    break;
                }
            }
        }
	}
	cout<<ans<<endl<<s<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793238
#define INF 1e9+5

int main()
{
	ll n,ans=0;string s,s1="RBG";
	cin>>n>>s;
	for(int x=0;x<n;x++){
         if(s[x]==s[x+1] && s[x]==s[x+2]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x] ||  s1[y]!=s[x+2]){
                    s[x+1]=s1[y];
                    x+=1;
                    ans++;
                    break;
                }
            }
        }
        else if(s[x]==s[x-1] || s[x]==s[x+1]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x-1] &&  s1[y]!=s[x+1]){
                    s[x]=s1[y];
                    ans++;
                    break;
                }
            }
        }
	}
	cout<<ans<<endl<<s<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793238
#define INF 1e9+5

int main()
{
	ll n,ans=0;string s,s1="RBG";
	cin>>n>>s;
	for(int x=0;x<n-1;x++){
         if(s[x]==s[x+1] && s[x]==s[x+2]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x] ||  s1[y]!=s[x+2]){
                    s[x+1]=s1[y];
                    x+=2;
                    ans++;
                    break;
                }
            }
        }
        else if(s[x]==s[x-1] || s[x]==s[x+1]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x-1] &&  s1[y]!=s[x+1]){
                    s[x]=s1[y];
                    ans++;
                    break;
                }
            }
        }
	}
	cout<<ans<<endl<<s<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793238
#define INF 1e9+5

int main()
{
	ll n,ans=0;string s,s1="RBG";
	cin>>n>>s;
	if(n>2){
	for(int x=1;x<n-1;x++){
         if(s[x]==s[x+1] && s[x]==s[x+2]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x] ||  s1[y]!=s[x+2]){
                    s[x+1]=s1[y];
                    x+2;
                    ans++;
                    break;
                }
            }
        }
        else if(s[x]==s[x-1] || s[x]==s[x+1]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x-1] &&  s1[y]!=s[x+1]){
                    s[x]=s1[y];
                    ans++;
                    break;
                }
            }
        }
	}
	}
	else{
        if(s[0]==s[1]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[0]){
                    s[0]=s1[y];
                    ans++;
                    break;
                }
            }
        }
	}
	cout<<ans<<endl<<s<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793238
#define INF 1e9+5

int main()
{
	ll n,ans=0;string s,s1="RBG";
	cin>>n>>s;
	for(int x=1;x<n-1;x++){
         if(s[x]==s[x+1] && s[x]==s[x+2]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x] ||  s1[y]!=s[x+2]){
                    s[x+1]=s1[y];
                    x+2;
                    ans++;
                    break;
                }
            }
        }
        else if(s[x]==s[x-1] || s[x]==s[x+1]){
            for(int y=0;y<3;y++){
                if(s1[y]!=s[x-1] &&  s1[y]!=s[x+1]){
                    s[x]=s1[y];
                    ans++;
                    break;
                }
            }
        }
	}
	cout<<ans<<endl<<s<<endl;
}


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

int main() {

	int n ;
	cin >> n ;
	stack<char> store , pot ;
	for(int i=0 ; i<n ; i++){
		char ch ;
		cin >> ch ;
		store.push(ch) ;
	}

	char ch ;
	ch = store.top() ;
	store.pop() ;
	pot.push(ch) ;
	int no = 0 ;

	for(int i=1 ; i<n ; i++){
		ch = store.top() ;
		store.pop() ;
		if(store.top() != pot.top()){
			pot.push(ch) ;
			continue ;
		}
		no++ ;
		if(store.top() != 'R' && pot.top() != 'R'){
			pot.push('R') ;
		}else if(store.top() != 'G' && pot.top() != 'G'){
			pot.push('G') ;
		}else if(store.top() != 'B' && pot.top() != 'B'){
			pot.push('B') ;
		}

	}
	cout << no << endl ;
	while(!pot.empty()){
		cout << pot.top() ;
		pot.pop() ;
	}

		return 0 ;
}


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

int main() {

	int n ;
	cin >> n ;
	stack<char> store , pot ;
	for(int i=0 ; i<n ; i++){
		char ch ;
		cin >> ch ;
		store.push(ch) ;
	}

	char ch ;
	ch = store.top() ;
	store.pop() ;
	pot.push(ch) ;
	int no = 0 ;

	for(int i=1 ; i<n ; i++){
		ch = store.top() ;
		store.pop() ;
		if(store.top() != pot.top()){
			pot.push(ch) ;
			continue ;
		}
		no++ ;
		if(store.top() != 'R' && pot.top() != 'R'){
			pot.push('R') ;
		}else if(store.top() != 'G' && pot.top() != 'G'){
			pot.push('G') ;
		}else if(store.top() != 'B' && pot.top() != 'B'){
			pot.push('B') ;
		}

	}
	cout << no << endl ;
	while(!pot.empty()){
		cout << pot.top() ;
	}

		return 0 ;
}


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

int main() {

	int n ;
	cin >> n ;
	stack<char> store , pot ;
	store.push('#') ;
	for(int i=0 ; i<n ; i++){
		char ch ;
		cin >> ch ;
		store.push(ch) ;
	}

	char ch ;
	ch = store.top() ;
	store.pop() ;
	pot.push(ch) ;
	int no = 0 ;

	for(int i=1 ; i<n ; i++){
		ch = store.top() ;
		store.pop() ;
		if(ch != pot.top()){
			pot.push(ch) ;
			continue ;
		}
		no++ ;
		if(store.top() != 'R' && pot.top() != 'R'){
			pot.push('R') ;
		}else if(store.top() != 'G' && pot.top() != 'G'){
			pot.push('G') ;
		}else if(store.top() != 'B' && pot.top() != 'B'){
			pot.push('B') ;
		}

	}
	cout << no << endl ;
	while(pot.top() != '#'){
		cout << pot.top() ;
		pot.pop() ;
	}

		return 0 ;
}


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

int main() {

	int n ;
	cin >> n ;
	stack<char> store , pot ;
	for(int i=0 ; i<n ; i++){
		char ch ;
		cin >> ch ;
		store.push(ch) ;
	}

	char ch ;
	ch = store.top() ;
	store.pop() ;
	pot.push(ch) ;
	int no = 0 ;

	for(int i=1 ; i<n ; i++){
		ch = store.top() ;
		store.pop() ;
		if(ch != pot.top()){
			pot.push(ch) ;
			continue ;
		}
		no++ ;
		if(store.top() != 'R' && pot.top() != 'R'){
			pot.push('R') ;
		}else if(store.top() != 'G' && pot.top() != 'G'){
			pot.push('G') ;
		}else if(store.top() != 'B' && pot.top() != 'B'){
			pot.push('B') ;
		}

	}
	cout << no << endl ;
	while(!pot.empty()){
		cout << pot.top() ;
		pot.pop() ;
	}

		return 0 ;
}


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

int main() {

	int n ;
	cin >> n ;
	stack<char> store , pot ;
	store.push('#') ;
	for(int i=0 ; i<n ; i++){
		char ch ;
		cin >> ch ;
		store.push(ch) ;
	}

	char ch ;
	ch = store.top() ;
	store.pop() ;
	pot.push(ch) ;
	int no = 0 ;

	for(int i=1 ; i<n ; i++){
		ch = store.top() ;
		store.pop() ;
		if(ch != pot.top()){
			pot.push(ch) ;
			continue ;
		}
		no++ ;
		if(store.top() != 'R' && pot.top() != 'R'){
			pot.push('R') ;
		}else if(store.top() != 'G' && pot.top() != 'G'){
			pot.push('G') ;
		}else if(store.top() != 'B' && pot.top() != 'B'){
			pot.push('B') ;
		}

	}
	cout << no << endl ;
	while(!pot.empty()){
		cout << pot.top() ;
		pot.pop() ;
	}

		return 0 ;
}


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

const int maxn=2e5+25;
int n;
string s;
int dp[3][maxn];
int path[3][maxn];

void print(int k)
{
    printf("%d\n",dp[k][--n]);
    string ans;
    while(n>=0)
    {
        if(k==0)    ans.push_back('R');
        else if(k==1)   ans.push_back('B');
        else ans.push_back('G');
        k=path[k][n--];
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

int solve()
{
    for(int i=1;i<n;i++)
    {
        for(int cur=0;cur<3;cur++)
        {
            for(int prev=0;prev<3;prev++)
            {
                if(prev!=cur)
                {
                    int cost=dp[prev][i-1]+(cur!=s[i]);
                    if(dp[cur][i]==-1||dp[cur][i]>cost)
                    {
                        dp[cur][i]=cost;
                        path[cur][i]=prev;
                    }
                }
            }
        }
    }
    int most=0;
    for(int i=1;i<3;i++)
        if(dp[i][n-1]<dp[most][n-1])
            most=i;
    print(most);
}

void ini()
{
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<3;i++)
        dp[i][0]=1;
    dp[s[0]][0]=0;
}

void standard()
{
   for(char &q:s)
   {
       if(q=='R')   q=0;
       else if(q=='B')  q=1;
       else q=2;
   }
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>s;
    standard();
    ini();
    solve();
   // system("pause");
    return 0;
}


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

const int maxn=2e5+25;
int n;
string s;
int dp[3][maxn];
int path[3][maxn];

void print(int k)
{
    printf("%d\n",dp[k][--n]);
    string ans;
    while(n>=0)
    {
        if(k==0)    ans.push_back('R');
        else if(k==1)   ans.push_back('B');
        else ans.push_back('G');
        k=path[k][n--];
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

int solve()
{
    for(int i=1;i<n;i++)
    {
        for(int cur=0;cur<3;cur++)
        {
            for(int prev=0;prev<3;prev++)
            {
                if(prev!=cur)
                {
                    int cost=dp[prev][i-1]+(cur!=s[i]);
                    if(dp[cur][i]==-1||dp[cur][i]>cost)
                    {
                        dp[cur][i]=cost;
                        path[cur][i]=prev;
                    }
                }
            }
        }
    }
    int most=0;
    for(int i=1;i<3;i++)
        if(dp[i][n-1]<dp[most][n-1])
            most=i;
    print(most);
}

void ini()
{
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<3;i++)
        dp[i][0]=1;
    dp[s[0]][0]=0;
}

void standard()
{
   for(char &q:s)
   {
       if(q=='R')   q=0;
       else if(q=='B')  q='1';
       else q='2';
   }
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>s;
    standard();
    ini();
    solve();
    //system("pause");
    return 0;
}


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

const int maxn=2e5+25;
int n;
string s;
int dp[3][maxn];
int path[3][maxn];

void print(int k)
{
    printf("%d\n",dp[k][--n]);
    string ans;
    while(n>=0)
    {
        if(k==0)    ans.push_back('R');
        else if(k==1)   ans.push_back('B');
        else ans.push_back('G');
        k=path[k][n--];
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

int solve()
{
    for(int i=1;i<n;i++)
    {
        for(int cur=0;cur<3;cur++)
        {
            for(int prev=0;prev<3;prev++)
            {
                if(prev!=cur)
                {
                    int cost=dp[prev][i-1]+(cur!=s[i]);
                    if(dp[cur][i]==-1||dp[cur][i]>cost)
                    {
                        dp[cur][i]=cost;
                        path[cur][i]=prev;
                    }
                }
            }
        }
    }
    int most=0;
    for(int i=1;i<3;i++)
        if(dp[i][n-1]<dp[most][n-1])
            most=i;
    print(most);
}

void ini()
{
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<3;i++)
        dp[i][0]=1;
    dp[s[0]][0]=0;
}

void standard()
{
   for(char &q:s)
   {
       if(q=='R')   q=0;
       else if(q=='B')  q='1';
       else q='2';
   }
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>s;
    standard();
    ini();
    solve();
   // system("pause");
    return 0;
}


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

string s,s2;
int maxn=0x3f3f3f3f;

void solve(int p,int change,char co)
{
	if(p==s.size())
	{
		if(change<maxn)
		{
			maxn=change;
			s2=s;
		}
		return ;
	}
	else if(s[p]==co)
	{
		char re=s[p];
		if(s[p]=='R')
		{
			s[p]='B';
			solve(p+1,change+1,'B');
			s[p]='G';
			solve(p+1,change+1,'G');
			s[p]=re;
		}
		else if(s[p]=='B')
		{
			s[p]='G';
			solve(p+1,change+1,'G');
			s[p]='R';
			solve(p+1,change+1,'R');
			s[p]=re;
		}
		else
		{
			s[p]='B';
			solve(p+1,change+1,'B');
			s[p]='R';
			solve(p+1,change+1,'R');
			s[p]=re;
		}
	}
	else solve(p+1,change,s[p]);
}

int main()
{
	int n;
	cin>>n>>s;
	if(s.size()==1)
	{
		printf("0\n");
		cout<<s<<endl;
	}
	else
	{
		solve(1,0,s[0]);
		cout<<maxn<<endl;
		cout<<s2<<endl;
	}
	//system("pause");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MaxN = 2e5 + 25;
int n;
string s;
int dp[3][MaxN];
int p[3][MaxN];

void solve(int k)
{
		--n;
		cout << dp[k][n] << '\n';
		string ans;
		while (n >= 0)
		{
				if (k == 0)
						ans.push_back('R');
				else
						if (k == 1)
								ans.push_back('G');
						else
								ans.push_back('B');

				k = p[k][n--];
		}
		reverse(ans.begin(), ans.end());
		cout << ans << '\n';
}

int main()
{
		//    freopen("input.txt", "r", stdin);
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cin >> n >> s;
		for (char & q : s)
		{
				if (q == 'R')
						q = 0;
				else
						if (q == 'G')
								q = 1;
						else
								q = 2;
		}
		/*for (int i = 0; i < n; ++i)
				for (int j = 0; j < 3; ++j)
						dp[j][i] = -1;*/
		memset(dp, -1, sizeof dp);
		for (int i = 0; i < 3; ++i)
				dp[i][0] = 1;
		dp[s[0]][0] = 0;
		for (int i = 1; i < n; ++i)
				for (int cur = 0; cur < 3; ++cur)
						for (int prev = 0; prev < 3; ++prev)
								if (prev != cur)
								{
										int cost = dp[prev][i - 1] + (cur != s[i]);
										if (dp[cur][i] == -1 || dp[cur][i] > cost)
										{
												dp[cur][i] = cost;
												p[cur][i] = prev;
										}
								}
		int best = 0;
		for (int i = 1; i < 3; ++i)
				if (dp[i][n - 1] < dp[best][n - 1])
						best = i;
		solve(best);
		return 0;
}


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

const int maxn = 2e5 + 25;
int n;
string s;
int dp[3][maxn];
int path[3][maxn];

void print(int k)
{
		printf("%d\n", dp[k][--n]);
		string ans;
		while (n >= 0)
		{
				if (k == 0)    ans.push_back('R');
				else if (k == 1)   ans.push_back('B');
				else ans.push_back('G');
				k = path[k][n--];
		}
		reverse(ans.begin(), ans.end());
		cout << ans << endl;
}

void solve()
{
		for (int i = 1; i < n; i++)
		{
				for (int cur = 0; cur < 3; cur++)
				{
						for (int prev = 0; prev < 3; prev++)
						{
								if (prev != cur)
								{
										int cost = dp[prev][i - 1] + (cur != s[i]);
										if (dp[cur][i] == -1 || dp[cur][i] > cost)
										{
												dp[cur][i] = cost;
												path[cur][i] = prev;
										}
								}
						}
				}
		}
		int most = 0;
		for (int i = 1; i < 3; i++)
				if (dp[i][n - 1] < dp[most][n - 1])
						most = i;
		print(most);
}

void ini()
{
		memset(dp, -1, sizeof(dp));
		for (int i = 0; i < 3; i++)
				dp[i][0] = 1;
		dp[s[0]][0] = 0;
}

void standard()
{
		for (char &q : s)
		{
				if (q == 'R')   q = 0;
				else if (q == 'B')  q = 1;
				else q = 2;
		}
}
int main()
{
		ios::sync_with_stdio(false);
		cin >> n >> s;
		standard();
		ini();
		solve();
		//system("pause");
		return 0;
}


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

const int maxn=2e5+25;
int n;
string s;
int dp[3][maxn];
int path[3][maxn];

void print(int k)
{
    printf("%d\n",dp[k][--n]);
    string ans;
    while(n>=0)
    {
        if(k==0)    ans.push_back('R');
        else if(k==1)   ans.push_back('B');
        else ans.push_back('G');
        k=path[k][n--];
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

int solve()
{
    for(int i=1;i<n;i++)
    {
        for(int cur=0;cur<3;cur++)
        {
            for(int prev=0;prev<3;prev++)
            {
                if(prev!=cur)
                {
                    int cost=dp[prev][i-1]+(cur!=s[i]);
                    if(dp[cur][i]==-1||dp[cur][i]>cost)
                    {
                        dp[cur][i]=cost;
                        path[cur][i]=prev;
                    }
                }
            }
        }
    }
    int most=0;
    for(int i=0;i<3;i++)
        if(dp[i][n-1]<dp[most][n-1])
            most=i;
    print(most);
}

void ini()
{
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<3;i++)
        dp[i][0]=1;
    dp[s[0]][0]=0;
}

void standard()
{
   for(char &q:s)
   {
       if(q=='R')   q=0;
       else if(q=='B')  q='1';
       else q='2';
   }
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>s;
    standard();
    ini();
    solve();
   // system("pause");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int n;
	string s;
	cin >> n >> s;

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int j = i;
		while (j < n && s[i] == s[j]) {
			++j;
		}
		string q = "RGB";
		q.erase(q.find(s[i]), 1);
		if (j < n) q.erase(q.find(s[j]), 1);
		for (int k = i + 1; k < j; k += 2) {
			++ans;
			s[k] = q[0];
		}
		i = j - 1;
	}

	cout << ans << endl << s << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define ll long long
#define pb push_back
#define M LONG_LONG_MAX
#define IM INT_MAX
#define endl "\n"
#define double long double

const ll N = 2e5+5;
const ll mod = 1e9 + 7;

int32_t main()
{
	IOS

	ll i = 0;
	vector<ll> v;

	ll n, a;

	cin>>n;

	string str;
	cin>>str;
	int dp[N][3] = {0};
	for(i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			dp[i][j] = 1e9;
		}
	}

	dp[0][0] = 1;
	dp[0][1] = 1;
	dp[0][2] = 1;
	if(str[0] == 'R')
		dp[0][0] = 0;
	else
	if(str[0] == 'G')
		dp[0][1] = 0;
	else
		dp[0][2] = 0;

	for(i=1;i<n;i++)
	{
		dp[i][0] = min(dp[i-1][1], dp[i-1][2]) + 1;
		dp[i][1] = min(dp[i-1][0], dp[i-1][2]) + 1;
		dp[i][2] = min(dp[i-1][0], dp[i-1][1]) + 1;

		if(str[i] == 'R')
			dp[i][0]--;
		else
		if(str[i] == 'G')
			dp[i][1]--;
		else
			dp[i][2]--;
	}

	cout<<min(dp[n-1][0], min(dp[n-1][1], dp[n-1][2]))<<endl;

	int val = min(dp[n-1][0], min(dp[n-1][1], dp[n-1][2]));

	string ans = "";
	int prev = 0;
	if(val == dp[n-1][0])
	{
		if(str[n-1]!='R')
			val--;
		ans += 'R';
		prev = 0;
	}
	else
	if(val == dp[n-1][1])
	{
		if(str[n-1]!='G')
			val--;
		ans += 'G';
		prev = 1;
	}
	else
	{
		if(str[n-1]!='B')
			val--;
		ans += 'B';
		prev = 2;
	}

	for(i=n-2;i>=0;i--)
	{
		int val2 = min(dp[i][0], min(dp[i][1], dp[i][2]));
		if(val == dp[i][0] && prev!=0)
		{
			if(str[i]!='R')
				val--;
			ans += 'R';
			prev = 0;
		}
		else
		if(val == dp[i][1] && prev!=1)
		{
			if(str[i]!='G')
				val--;
			ans += 'G';
			prev = 1;
		}
		else
		{
			if(str[i]!='B')
				val--;
			ans += 'B';
			prev = 2;
		}
	}
	reverse(ans.begin(), ans.end());
	cout<<ans<<endl;
	return 0;
}


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

string s,a,c;
int n,i,ans;

string check(char x,char y){
    if (x=='R'){
        if (y=='R' || y=='G') return "B";
        if (y=='B') return "G";
    }
    if (x=='B'){
        if (y=='B' || y=='R') return "G";
        if (y=='G') return "R";
    }
    if (x=='G'){
        if (y=='G' || y=='B') return "R";
        if (y=='R') return "B";
    }
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    char z;
    for (i=0;i<=n;i++){
        cin>>z;
        s=s+z;
    }
    a=a+s[0];
    s=s+"B";
    for (i=1;i<n;i++)
        if (s[i]==a[i-1]){
            c=check(a[i-1],s[i+1]);
            a=a+c;
            ans++;
        }
        else{
            a=a+s[i];
        }
    cout<<ans<<endl;
    for (i=0;i<a.size();i++)
        cout<<a[i];
}


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

string s,a;
int n,i,ans;

string check(char x,char y){
    if (x=='R'){
        if (y=='R' || y=='G' || y==' ') return "B";
        if (y=='B') return "G";
    }
    if (x=='B'){
        if (y=='B' || y=='R' || y==' ') return "G";
        if (y=='G') return "R";
    }
    if (x=='G'){
        if (y=='G' || y=='B' || y==' ') return "R";
        if (y=='R') return "B";
    }
}

int main()
{
    scanf("%d\n",&n);
    getline(cin,s);
    a=a+s[0];
    s=s+"B";
    for (i=1;i<n;i++)
        if (s[i]==a[i-1]){
            string c=check(a[i-1],s[i+1]);
            a=a+c;
            ans++;
        }
        else{
            a=a+s[i];
        }
    printf("%d\n",ans);
    for (i=0;i<a.size();i++)
        printf("%c",a[i]);
}


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

string s,a,c;
int n,i,ans;

string check(char x,char y){
    if (x=='R'){
        if (y=='R' || y=='G' || y==' ') return "B";
        if (y=='B') return "G";
    }
    if (x=='B'){
        if (y=='B' || y=='R' || y==' ') return "G";
        if (y=='G') return "R";
    }
    if (x=='G'){
        if (y=='G' || y=='B' || y==' ') return "R";
        if (y=='R') return "B";
    }
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    char z;
    for (i=0;i<=n;i++){
        cin>>z;
        s=s+z;
    }
    a=a+s[0];
    s=s+"B";
    for (i=1;i<n;i++)
        if (s[i]==a[i-1]){
            c=check(a[i-1],s[i+1]);
            a=a+c;
            ans++;
        }
        else{
            a=a+s[i];
        }
    cout<<ans<<endl;
    cout<<a<<endl;
}


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

string s,a;
int n,i,ans;

string check(char x,char y){
    if (x=='R'){
        if (y=='R' || y=='G' || y==' ') return "B";
        if (y=='B') return "G";
    }
    if (x=='B'){
        if (y=='B' || y=='R' || y==' ') return "G";
        if (y=='G') return "R";
    }
    if (x=='G'){
        if (y=='G' || y=='B' || y==' ') return "R";
        if (y=='R') return "B";
    }
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    char z;
    for (i=0;i<=n;i++){
        cin>>z;
        s=s+z;
    }
    a=a+s[0];
    s=s+"B";
    for (i=1;i<n;i++)
        if (s[i]==a[i-1]){
            string c=check(a[i-1],s[i+1]);
            a=a+c;
            ans++;
        }
        else{
            a=a+s[i];
        }
    cout<<ans<<endl;
    cout<<a<<endl;
}


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

#define INF (int)1e9
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define qq queue
#define w(n) while(n--)
#define for0(i, n) for(i = 0; i < n; i++)
#define for1(i, n) for(i = 1; i <= n; i++)

#define MAXN 100100
ll n, k, dp[12][MAXN], nums[MAXN];

void update(int idx, ll val, int l) {
    while (idx <= n) {
        dp[l][idx] += val;
        idx += idx & -idx;
    }
}

ll query(int idx, int l) {
    if (l == 0) return 1;

    ll res = 0LL;
    while (idx > 0) {
        res += dp[l][idx];
        idx -= idx & -idx;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    k++;

    int i;
    for1(i, n) {
        cin >> nums[i];
    }

	for(int i = 1; i <= n; i++) {
		for(int l = 1; l <= k; l++) {
			ll res = query(nums[i]-1, l-1);
            update(nums[i], res, l);
		}
	}

    ll finalSum = query(n, k);
    cout << finalSum << "\n";

    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <iostream>
#include<string>
#include<map>
#include<queue>
#include <sstream>      //contains 'istringstream'
#include<algorithm>
#include <assert.h>
# include <cstdio>
# include <string>
# include <vector>
#include<stdlib.h>
#include<set>
#include<list>
#include<math.h>
#include<iomanip>
#include <string.h>
using namespace std;
#define ln cout << "\n";
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define  sll stack<ll>
#define  qll queue<ll>
#define  pll pair<ll,ll>
#define  vll vector<ll>
#define  vpll vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define test ll t; cin >> t; while(t--)
#define log log2
#define cases cout << "Case " << i << ":\n";
#define tests ll t,i; cin >> t; for(i=1;i<=t;i++)
#define MAXN 100100
ll n, k, dp[12][MAXN],a[MAXN];
// FENWICK TREE

void update(ll idx, ll val,ll l) {
    while (idx <= n+10) {
        dp[l][idx] += val;
        idx += idx & -idx;
    }
}

ll query(ll idx, ll l) {
    if (l == 0) return 1;

    ll res = 0LL;
    while (idx > 0) {
        res += dp[l][idx];
        idx -= idx & -idx;
    }
    return res;
}

void solve(){
    ll n,i,j,k;
    cin >> n >> k; k++;
    for(i=1;i<=n;i++){
        cin >> a[i];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=k;j++){
            ll temp = query(a[i]-1, j-1);
            update(a[i], temp, j);
        }
    }
    for(j=1;j<=n;j++){
        for(i=1;i<=k;i++){
            ll temp = query(a[j],i);
            //cout << temp << " ";
            //cout << dp[i][n] << " ";
        }
    }
    ll ans = query(n,k);
    cout << ans; ln;
}

int main()
{
    fastio
    //tests{
    //    cases
        solve();
    //}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ln cout << "\n";
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF (int)1e9
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define qq queue
#define w(n) while(n--)
#define for0(i, n) for(i = 0; i < n; i++)
#define for1(i, n) for(i = 1; i <= n; i++)

#define MAXN 100100
ll n, k, dp[12][MAXN], a[MAXN];

void update(ll idx, ll val, ll l) {
    while (idx <= n) {
        dp[l][idx] += val;
        idx += idx & -idx;
    }
}

ll query(ll idx, ll l) {
    if (l == 0) return 1;

    ll res = 0LL;
    while (idx > 0) {
        res += dp[l][idx];
        idx -= idx & -idx;
    }
    return res;
}

void solve(){
    ll i,j;
    cin >> n >> k; k++;
    for(i=1;i<=n;i++){
        cin >> a[i];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=11;j++){
            ll temp = query(a[i]-1, j-1);
            update(a[i], temp, j);
        }
    }
    ll ans = query(n,k);
    cout << ans; ln;
}

int main()
{
    fastio
    //tests{
    //    cases
        solve();
    //}
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <iostream>
#include<string>
#include<map>
#include<queue>
#include <sstream>      //contains 'istringstream'
#include<algorithm>
#include <assert.h>
# include <cstdio>
# include <string>
# include <vector>
#include<stdlib.h>
#include<set>
#include<list>
#include<math.h>
#include<iomanip>
#include <string.h>
using namespace std;
#define ln cout << "\n";
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define  sll stack<ll>
#define  qll queue<ll>
#define  pll pair<ll,ll>
#define  vll vector<ll>
#define  vpll vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define test ll t; cin >> t; while(t--)
#define log log2
#define cases cout << "Case " << i << ":\n";
#define tests ll t,i; cin >> t; for(i=1;i<=t;i++)
#define MAXN 100100
ll n, k, dp[12][MAXN],a[MAXN];
// FENWICK TREE

void update(ll idx, ll val,ll l) {
    while (idx <= n+10) {
        dp[l][idx] += val;
        idx += idx & -idx;
    }
}

ll query(ll idx, ll l) {
    if (l == 0) return 1;

    ll res = 0LL;
    while (idx > 0) {
        res += dp[l][idx];
        idx -= idx & -idx;
    }
    return res;
}

void solve(){
    ll n,i,j,k;
    cin >> n >> k; k++;
    for(i=1;i<=n;i++){
        cin >> a[i];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=k;j++){
            ll temp = query(a[i]-1, j-1);
            update(a[i], temp, j);
        }
    }
    ll ans = query(n,k);
    cout << ans; ln;
}

int main()
{
    fastio
    //tests{
    //    cases
        solve();
    //}
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define ui64 uint64_t
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");
int64_t gt(int64_t x){
    if (x<=0) return 1;
    int64_t res = x;
    while(--x)
        res*=x;
    return res;
}
int64_t c(int64_t k, int64_t n){
    return gt(n)/(gt(k)*gt(n-k));
}
int fw[100001];
int64_t dp[100001];
int n,k,val;
void upd(int idx){
    while(idx<=n){
        fw[idx]++;
        idx+=(idx&-idx);
    }
}
int get(int idx){
    int res = 0;
    while(idx>0){
        res+=fw[idx];
        idx-=(idx&-idx);
    }
    return res;
}
int main(){

    scanf("%d%d",&n,&k);
    int r;
    for(int i=1;i<=n;i++){
        scanf("%d",&val);
        r = get(val);
        if (r>=k) dp[i]=dp[i-1]+c(k,r);
        upd(val);
    }
    printf("%d",dp[n]);
}


#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define ui64 uint64_t
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");
int64_t gt(int64_t x){
    if (x<=0) return 1;
    int64_t res = x;
    while(--x)
        res*=x;
    return res;
}
int64_t c(int64_t k, int64_t n){
    return gt(n)/(gt(k)*gt(n-k));
}
int fw[100001];
int64_t dp[100001];
int n,k,val;
void upd(int idx){
    while(idx<=n){
        fw[idx]++;
        idx+=(idx&-idx);
    }
}
int get(int idx){
    int res = 0;
    while(idx>0){
        res+=fw[idx];
        idx-=(idx&-idx);
    }
    return res;
}
int main(){

    scanf("%d%d",&n,&k);
    int r;
    for(int i=1;i<=n;i++){
        scanf("%d",&val);
        r = get(val);
        dp[i]=dp[i-1]+(r>=k)*c(k,r);
        upd(val);
    }
    printf("%d",dp[n]);
}


#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");
int n,k,a;
ll fw[11][100001];
void upd(int k,int idx,int val){
    while(idx<=n){
        fw[k][idx]+=val;
        idx+=(idx&-idx);
    }
}
ll get(int k, int idx){
    ll res=0;
    while(idx>0){
        res+=fw[k][idx];
        idx-=(idx&-idx);
    }
    return res;
}
int main(){
    scanf("%d%d",&n,&k);
    for (int i=0;i<n;i++) {
        scanf("%d",&a);
        upd(0,a,1);
        for (int j=1;j<k+1;j++){
            upd(j, a ,get(j-1,a-1) );
        }

    }
    printf("%lld",get(k+1,n));

}


#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");
int n,k,a;
ll fw[11][100001];
void upd(int k,int idx,ll val){
    while(idx<=n){
        fw[k][idx]+=val;
        idx+=(idx&-idx);
    }
}
ll get(int k, int idx){
    ll res=0;
    while(idx>0){
        res+=fw[k][idx];
        idx-=(idx&-idx);
    }
    return res;
}
int main(){
    scanf("%d%d",&n,&k);

    for (int i=0;i<n;i++) {
        scanf("%d",&a);
        upd(0,a,1);
        for (int j=1;j<=k;j++){
            upd(j, a , get(j-1,a-1) );
        }

    }
    printf("%lld", get(k,n) );

}


#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define ui64 uint64_t
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");
int64_t gt(int64_t x){
    if (x<=0) return 1;
    int64_t res = 1;
    while(--x)
        res*=x;
    return res;
}
int64_t c(int64_t k, int64_t n){
    return gt(n)/(gt(k)*gt(n-k));
}
int fw[100001];
int64_t dp[100001];
int n,k,val;
void upd(int idx){
    while(idx<=n){
        fw[idx]++;
        idx+=(idx&-idx);
    }
}
int get(int idx){
    int res = 0;
    while(idx>0){
        res+=fw[idx];
        idx-=(idx&-idx);
    }
    return res;
}
int main(){
    //ios::sync_with_stdio(0);cin.tie(0);

    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&val);
        dp[i]=dp[i-1]+c(k,get(val)),
        upd(val);
    }
    printf("%d",dp[n]);
}


#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");
int n,k,a;
ll fw[10][100001];
void upd(int k,int idx,int val){
    while(idx<=n){
        fw[k][idx]+=val;
        idx+=(idx&-idx);
    }
}
ll get(int k, int idx){
    ll res=0;
    while(idx>0){
        res+=fw[k][idx];
        idx-=(idx&-idx);
    }
    return res;
}
int main(){

    scanf("%d%d",&n,&k);
    for (int i=0;i<n;i++) {
        scanf("%d",&a);
        upd(0,a,1);
        for (int j=1;j<k+1;j++){
            upd(j, a ,get(j-1,a-1) );
        }

    }
    printf("%lld",get(k,n));

}


#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");
int n,k,a;
ll fw[11][100001];
void upd(int k,int idx,int val){
    while(idx<=n){
        fw[k][idx]+=val;
        idx+=(idx&-idx);
    }
}
ll get(int k, int idx){
    ll res=0;
    while(idx>0){
        res+=fw[k][idx];
        idx-=(idx&-idx);
    }
    return res;
}
int main(){

    scanf("%d%d",&n,&k);
    for (int i=0;i<n;i++) {
        scanf("%d",&a);
        upd(0,a,1);
        for (int j=1;j<k+1;j++){
            upd(j, a ,get(j-1,a-1) );
        }

    }
    printf("%lld",get(k,n));

}


#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define ui64 uint64_t
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");
int64_t gt(int64_t x){
    if (x<=0) return 1;
    int64_t res = x;
    while(--x)
        res*=x;
    return res;
}
int64_t c(int64_t k, int64_t n){
    return gt(n)/(gt(k)*gt(n-k));
}
int fw[100001];
int n,k,val;
void upd(int idx,int val){
    while(idx<=n){
        fw[idx]=max(fw[idx],val);
        idx+=(idx&-idx);
    }
}
int get(int idx){
    int res = 0;
    while(idx>0){
        res=max(res,fw[idx]);
        idx-=(idx&-idx);
    }
    return res;
}
int main(){

    scanf("%d%d",&n,&k);
    int r;
    int64_t res= 0;
    for(int i=1;i<=n;i++){
        scanf("%d",&val);

        r = get(val);
        res+= (r>=k)*c(k,r);
        upd(val,1+r);
    }
    printf("%lld",res);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
struct segtree{
ll *a;
ll *tree;
int n;
segtree(){
a=new ll[1000001];
tree=new ll[3000001];
memset(a,0,sizeof a);
memset(tree,0,sizeof tree);
n=1000000;
}
void update(int node,int l,int r,int x,ll k){
if(l>r)return ;
if(l==r&&l==x){
    tree[node]+=k;
    return ;
}
if(x>r||x<l)return ;
update(2*node+1,l,(l+r)/2,x,k);
update(2*node+2,(l+r)/2+1,r,x,k);
tree[node]=tree[2*node+1]+tree[2*node+2];
}
ll get(int node,int l,int r,int x,int y){
if(l>y||r<x)return 0;
if(l>=x&&r<=y)return tree[node];
return get(2*node+1,l,(l+r)/2,x,y)+get(2*node+2,(l+r)/2+1,r,x,y);
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
vector<ll>a(n);
for(int i=0;i<n;i++)cin>>a[i];
segtree dp[13];
dp[1].update(0,0,MAX,a[0],1);
for(int i=1;i<n;i++){
dp[1].update(0,0,MAX,a[i],1);
for(int j=1;j<=k+1;j++){
    ll s=dp[j].get(0,0,MAX,0,a[i]-1);
    dp[j+1].update(0,0,MAX,a[i],s);
}
}
cout<<dp[k+1].tree[0]<<'\n';
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define MAX 100001
struct segtree{
ll *a;
ll *tree;
int n;
segtree(){
a=new ll[100001];
tree=new ll[300001];
memset(a,0,sizeof a);
memset(tree,0,sizeof tree);
n=1000000;
}
void update(int node,int l,int r,int x,ll k){
if(l>r)return ;
if(l==r&&l==x){
    tree[node]+=k;
    return ;
}
if(x>r||x<l)return ;
update(2*node+1,l,(l+r)/2,x,k);
update(2*node+2,(l+r)/2+1,r,x,k);
tree[node]=tree[2*node+1]+tree[2*node+2];
}
ll get(int node,int l,int r,int x,int y){
if(l>y||r<x)return 0;
if(l>=x&&r<=y)return tree[node];
return get(2*node+1,l,(l+r)/2,x,y)+get(2*node+2,(l+r)/2+1,r,x,y);
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
vector<ll>a(n);
for(int i=0;i<n;i++)cin>>a[i];
segtree dp[13];
dp[1].update(0,0,MAX,a[0],1);
for(int i=1;i<n;i++){
dp[1].update(0,0,MAX,a[i],1);
for(int j=1;j<=k+1;j++){
    ll s=dp[j].get(0,0,MAX,0,a[i]-1);
    dp[j+1].update(0,0,MAX,a[i],s);
}
}
cout<<dp[k+1].tree[0]<<'\n';
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define MAX 100000
struct segtree{
ll *a;
ll *tree;
int n;
segtree(){
a=new ll[100001];
tree=new ll[300001];
memset(a,0,sizeof a);
memset(tree,0,sizeof tree);
n=100000;
}
void update(int node,int l,int r,int x,int k){
if(l>r)return ;
if(l==r&&l==x){
    tree[node]+=k;
    return ;
}
if(x>r||x<l)return ;
update(2*node+1,l,(l+r)/2,x,k);
update(2*node+2,(l+r)/2+1,r,x,k);
tree[node]=tree[2*node+1]+tree[2*node+2];
}
int get(int node,int l,int r,int x,int y){
if(l>y||r<x)return 0;
if(l>=x&&r<=y)return tree[node];
return get(2*node+1,l,(l+r)/2,x,y)+get(2*node+2,(l+r)/2+1,r,x,y);
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
segtree dp[13];
dp[1].update(0,0,MAX,a[0],1);
for(int i=1;i<n;i++){
dp[1].update(0,0,MAX,a[i],1);
for(int j=1;j<=k+1;j++){
    ll s=dp[j].get(0,0,MAX,0,a[i]-1);
    dp[j+1].update(0,0,MAX,a[i],s);
}
}
cout<<dp[k+1].tree[0]<<'\n';
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define MAX 100000
struct segtree{
ll *a;
ll *tree;
int n;
segtree(){
a=new ll[100001];
tree=new ll[300001];
memset(a,0,sizeof a);
memset(tree,0,sizeof tree);
n=100000;
}
void update(int node,int l,int r,int x,int k){
if(l>r)return ;
if(l==r&&l==x){
    tree[node]+=k;
    return ;
}
if(x>r||x<l)return ;
update(2*node+1,l,(l+r)/2,x,k);
update(2*node+2,(l+r)/2+1,r,x,k);
tree[node]=tree[2*node+1]+tree[2*node+2];
}
ll get(int node,int l,int r,int x,int y){
if(l>y||r<x)return 0;
if(l>=x&&r<=y)return tree[node];
return get(2*node+1,l,(l+r)/2,x,y)+get(2*node+2,(l+r)/2+1,r,x,y);
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
vector<ll>a(n);
for(int i=0;i<n;i++)cin>>a[i];
segtree dp[13];
dp[1].update(0,0,MAX,a[0],1);
for(int i=1;i<n;i++){
dp[1].update(0,0,MAX,a[i],1);
for(int j=1;j<=k+1;j++){
    ll s=dp[j].get(0,0,MAX,0,a[i]-1);
    dp[j+1].update(0,0,MAX,a[i],s);
}
}
cout<<dp[k+1].tree[0]<<'\n';
return 0;
}


#include <iostream>

using namespace std;

long long n,k,a[100005],d[100005][15],aint[100005][15];

void update(int nod,int st,int dr,int x,long long val,int k) {
	if(st==x && dr==x){
		aint[nod][k]+=val;
		return;
	}
	int mij=(st+dr)>>1;
	if(x<=mij)
        update(nod*2,st,mij,x,val,k);
	if(x>mij)
        update(nod*2+1,mij+1,dr,x,val,k);
	aint[nod][k] = aint[nod*2][k] + aint[nod*2+1][k];
}

long long query(int nod,int st,int dr,int x,int y,int k) {
	if (y<st || x>dr){
            return 0;
	}
	if (x<=st && dr<=y){
        return aint[nod][k];
	}
	int mij=(st+dr)>>1;
	return query(nod*2,st,mij,x,y,k)+query(nod*2+1,mij+1,dr,x,y,k);
}

int main()
{
    cin>>n>>k;
    for (int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        d[i][1]=1;
        update(1,1,n,a[i],1,1);
        for (int j=2;j<=k+1;j++){
            d[i][j]=query(1,1,n,1,a[i]-1,j-1);
            update(1,1,n,a[i],d[i][j],j);
        }
    }
    long long s=0;
    for(int i=k+1;i<=n;i++){
        s+=d[i][k+1];
    }
    cout<<s;
    return 0;
}


#include <iostream>

using namespace std;

long long n,k,a[100005],aint[100005][15];

void update(int nod,int st,int dr,int x,long long val,int k) {
	if(st==x && dr==x){
		aint[nod][k]+=val;
		return;
	}
	int mij=(st+dr)>>1;
	if(x<=mij)
        update(nod*2,st,mij,x,val,k);
	if(x>mij)
        update(nod*2+1,mij+1,dr,x,val,k);
	aint[nod][k] = aint[nod*2][k] + aint[nod*2+1][k];
}

long long query(int nod,int st,int dr,int x,int y,int k) {
	if (y<st || x>dr){
            return 0;
	}
	if (x<=st && dr<=y){
        return aint[nod][k];
	}
	int mij=(st+dr)>>1;
	return query(nod*2,st,mij,x,y,k)+query(nod*2+1,mij+1,dr,x,y,k);
}

int main()
{
    cin>>n>>k;
    for (int i=1;i<=n;i++){
        cin>>a[i];
    }
    long long z;
    for(int i=1;i<=n;i++){
        update(1,1,n,a[i],1,1);
        for (int j=2;j<=k+1;j++){
            z=query(1,1,n,1,a[i]-1,j-1);
            update(1,1,n,a[i],z,j);
        }
    }
    long long s=0;
    cout<<query(1,1,n,1,n,k+1);
    return 0;
}


#include <iostream>
#include <fstream>

using namespace std;

ifstream in("test.in");

const int dim = 1e5 + 5;

long long n,k,a[100005],d[100005][15],aint[100005][15];

void update(int nod,int st,int dr,int x,long long val,int k) {
	if(st==x && dr==x){
		aint[nod][k]+=val;
		return;
	}
	int mij=(st+dr)>>1;
	if(x<=mij)
        update(nod*2,st,mij,x,val,k);
	if(x>mij)
        update(nod*2+1,mij+1,dr,x,val,k);
	aint[nod][k] = aint[nod*2][k] + aint[nod*2+1][k];
}

long long query(int nod,int st,int dr,int x,int y,int k) {
	if (y<st || x>dr){
            return 0;
	}
	if (x<=st && dr<=y){
        return aint[nod][k];
	}
	int mij=(st+dr)>>1;
	return query(nod*2,st,mij,x,y,k)+query(nod*2+1,mij+1,dr,x,y,k);
}

int main()
{
    cin>>n>>k;
    for (int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        d[i][1]=1;
        update(1,1,n,a[i],1,1);
        for (int j=2;j<=k+1;j++){
            d[i][j]=query(1,1,n,1,a[i]-1,j-1);
            update(1,1,n,a[i],d[i][j],j);
        }
    }
    long long s=0;
    for(int i=k+1;i<=n;i++){
        s+=d[i][k+1];
    }
    cout<<s;
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

long long ans,aint[400005],d[15][100005];
int a[100005],n,k;
void query(int nod,int  l,int r, int st,int dr){
    if(st<=l && dr>=r){
        ans+=aint[nod];
        return;
    }
    long long mij=(l+r)>>1;
    if(st<=mij){
        query(nod*2,l,mij,st,dr);
    }
    if(dr>mij){
        query(nod*2+1,mij+1,r,st,dr);
    }
}
void update(int nod,int l,int r,int poz,long long val){
    if(l==poz && r==poz){
        aint[nod]=val;
        return;
    }
    int mij;
    mij=(l+r)>>1;
    if(poz<=mij){
        update(nod*2,l,mij,poz,val);
    }
    else if(poz>mij){
        update(nod*2+1,mij+1,r,poz,val);
    }
    aint[nod]=(aint[nod*2]+aint[nod*2+1]);

}

int  main()
{

    cin>>n>>k;
    k++;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]++;
        update(1,1,n+1,a[i],1);
    }
    for(int i=2;i<=k;i++){
        for(int j=k;j<=n;j++){
            query(1,1,n+1,1,a[j]-1);
            d[i][j]=ans;
            ans=0;
        }
        for(int j=1;j<=n;j++){
           update(1,1,n+1,a[j],d[i][j]);
        }
    }
    long long s=0;
    for(int i=1;i<=n;i++){
        s+=d[k][i];
    }
    cout<<s;
    return 0;

}


#include <iostream>
#include <vector>

using namespace std;

long long ans,aint[400005],d[15][100005];
int a[100005],n,k;
void query(int nod,int  l,int r, int st,int dr){
    if(st<=l && dr>=r){
        ans+=aint[nod];
        return;
    }
    long long mij=(l+r)>>1;
    if(st<=mij){
        query(nod*2,l,mij,st,dr);
    }
    if(dr>mij){
        query(nod*2+1,mij+1,r,st,dr);
    }
}
void update(int nod,int l,int r,int poz,long long val){
    if(l==poz && r==poz){
        aint[nod]=val;
        return;
    }
    int mij;
    mij=(l+r)>>1;
    if(poz<=mij){
        update(nod*2,l,mij,poz,val);
    }
    else if(poz>mij){
        update(nod*2+1,mij+1,r,poz,val);
    }
    aint[nod]=(aint[nod*2]+aint[nod*2+1]);

}

int  main()
{

    cin>>n>>k;
    k++;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]++;
        update(1,1,n+1,a[i],1);
    }
    for(int i=1;i<=n;i++){
        d[1][i]=1;
    }
    for(int i=2;i<=k;i++){
        for(int j=k;j<=n;j++){
            query(1,1,n+1,1,a[j]-1);
            d[i][j]=ans;
            ans=0;
        }
        for(int j=1;j<=n;j++){
           update(1,1,n+1,a[j],d[i][j]);
        }
    }
    long long s=0;
    for(int i=1;i<=n;i++){
        s+=d[k][i];
    }
    cout<<s;
    return 0;

}


#include <iostream>

using namespace std;

long long n,k,a[100005],aint[100005][15];

void update(int nod,int st,int dr,int x,long long val,int k) {
	if(st==x && dr==x){
		aint[nod][k]+=val;
		return;
	}
	int mij=(st+dr)>>1;
	if(x<=mij)
        update(nod*2,st,mij,x,val,k);
	if(x>mij)
        update(nod*2+1,mij+1,dr,x,val,k);
	aint[nod][k] = aint[nod*2][k] + aint[nod*2+1][k];
}

long long query(int nod,int st,int dr,int x,int y,int k) {
	if (y<st || x>dr){
            return 0;
	}
	if (x<=st && dr<=y){
        return aint[nod][k];
	}
	int mij=(st+dr)>>1;
	return query(nod*2,st,mij,x,y,k)+query(nod*2+1,mij+1,dr,x,y,k);
}

int main()
{
    cin>>n>>k;
    for (int i=1;i<=n;i++){
        cin>>a[i];
    }
    int z;
    for(int i=1;i<=n;i++)
    {
        d[i][1]=1;
        update(1,1,n,a[i],1,1);
        for (int j=2;j<=k+1;j++){
            z=query(1,1,n,1,a[i]-1,j-1);
            update(1,1,n,a[i],z,j);
        }
    }
    long long s=0;
    cout<<query(1,1,n,1,n,k+1);
    return 0;
}


#include <iostream>

using namespace std;

long long n,k,a[100005],aint[100005][15];

void update(int nod,int st,int dr,int x,long long val,int k) {
	if(st==x && dr==x){
		aint[nod][k]+=val;
		return;
	}
	int mij=(st+dr)>>1;
	if(x<=mij)
        update(nod*2,st,mij,x,val,k);
	if(x>mij)
        update(nod*2+1,mij+1,dr,x,val,k);
	aint[nod][k] = aint[nod*2][k] + aint[nod*2+1][k];
}

long long query(int nod,int st,int dr,int x,int y,int k) {
	if (y<st || x>dr){
            return 0;
	}
	if (x<=st && dr<=y){
        return aint[nod][k];
	}
	int mij=(st+dr)>>1;
	return query(nod*2,st,mij,x,y,k)+query(nod*2+1,mij+1,dr,x,y,k);
}

int main()
{
    cin>>n>>k;
    for (int i=1;i<=n;i++){
        cin>>a[i];
    }
    int z;
    for(int i=1;i<=n;i++){
        update(1,1,n,a[i],1,1);
        for (int j=2;j<=k+1;j++){
            z=query(1,1,n,1,a[i]-1,j-1);
            update(1,1,n,a[i],z,j);
        }
    }
    long long s=0;
    cout<<query(1,1,n,1,n,k+1);
    return 0;
}


#include <iostream>

using namespace std;

long long n,k,a[100005],aint[400005][15];

void update(int nod,int st,int dr,int x,long long val,int k) {
	if(st==x && dr==x){
		aint[nod][k]+=val;
		return;
	}
	int mij=(st+dr)>>1;
	if(x<=mij)
        update(nod*2,st,mij,x,val,k);
	if(x>mij)
        update(nod*2+1,mij+1,dr,x,val,k);
	aint[nod][k] = aint[nod*2][k] + aint[nod*2+1][k];
}

long long query(int nod,int st,int dr,int x,int y,int k) {
	if (y<st || x>dr){
            return 0;
	}
	if (x<=st && dr<=y){
        return aint[nod][k];
	}
	int mij=(st+dr)>>1;
	return query(nod*2,st,mij,x,y,k)+query(nod*2+1,mij+1,dr,x,y,k);
}

int main()
{
    cin>>n>>k;
    for (int i=1;i<=n;i++){
        cin>>a[i];
    }
    long long z;
    for(int i=1;i<=n;i++){
        update(1,1,n,a[i],1,1);
        for (int j=2;j<=k+1;j++){
            z=query(1,1,n,1,a[i]-1,j-1);
            update(1,1,n,a[i],z,j);
        }
    }
    long long s=0;
    cout<<query(1,1,n,1,n,k+1);
    return 0;
}


#include "bits/stdc++.h"

#define si(x) scanf("%d",&x)
#define sll(x) scanf("%I64d",&x)
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define F first
#define S second
#define SETBITS(x) __builtin_popcount(x)
#define ALL(x) (x).begin(),(x).end()
#define fastscan ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug(x) cerr<<#x<<" is "<<x<<endl
#define INF INT_MAX
#define N_INF INT_MIN
#define initialize(a,row,col,val) for (int i = 0; i < row*col; i++)*((int*)a + i) = val;
#define TRACE
#define ld long double
#define N_LINE "\n"
#define mod(x) (x)%MOD
#define SPACE " "

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int maxn = 1e5 + 5;

ll BIT[12][maxn];
ll n,k;
ll a[maxn];

void add(ll x, ll *BIT, ll value){
    for(;x <= n; x += (x & (-x)))
        BIT[x] += value;
}

ll get(ll x, ll *BIT){
    ll ans = 0;
    for(;x > 0; x -= (x & (-x)))
        ans += BIT[x];
    return ans;
}

int main(){

    fastscan;

    cin >> n >> k;

    for(ll i = 0; i < n; ++i)
        cin >> a[i];
    ++k;
    ll ans = 0;

    for(ll i = 0; i < n; ++i){
        for(ll j = 1; j <= k; ++j){
            if(j == 1){
                add(a[i], BIT[j], 1);
            }
            else if(j == k){
                ans += get(a[i] - 1, BIT[j - 1]);;
            }else{
                ll small = get(a[i] - 1, BIT[j - 1]);
                add(a[i], BIT[j], small);
            }
        }
    }

    if(ans == 0){
        cout << n << N_LINE;
        return 0;
    }

    cout << ans << N_LINE;

	return 0;
}


#include "bits/stdc++.h"

#define si(x) scanf("%d",&x)
#define sll(x) scanf("%I64d",&x)
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define F first
#define S second
#define SETBITS(x) __builtin_popcount(x)
#define ALL(x) (x).begin(),(x).end()
#define fastscan ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug(x) cerr<<#x<<" is "<<x<<endl
#define INF INT_MAX
#define N_INF INT_MIN
#define initialize(a,row,col,val) for (int i = 0; i < row*col; i++)*((int*)a + i) = val;
#define TRACE
#define ld long double
#define N_LINE "\n"
#define mod(x) (x)%MOD
#define SPACE " "

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int maxn = 1e5 + 5;

ll BIT[12][maxn];
ll n,k;
ll a[maxn];

void add(ll x, ll *BIT, ll value){
    for(;x <= n; x += (x & (-x)))
        BIT[x] += value;
}

ll get(ll x, ll *BIT){
    ll ans = 0;
    for(;x > 0; x -= (x & (-x)))
        ans += BIT[x];
    return ans;
}

int main(){

    fastscan;

    cin >> n >> k;

    for(ll i = 0; i < n; ++i)
        cin >> a[i];
    ++k;
    ll ans = 1;

    for(ll i = 0; i < n; ++i){
        for(ll j = 1; j <= k; ++j){
            if(j == 1){
                add(a[i], BIT[j], 1);
            }
            else if(j == k){
                ans += get(a[i] - 1, BIT[j - 1]);;
            }else{
                ll small = get(a[i] - 1, BIT[j - 1]);
                add(a[i], BIT[j], small);
            }
        }
    }

    cout << ans << N_LINE;

	return 0;
}


#include "bits/stdc++.h"

#define si(x) scanf("%d",&x)
#define sll(x) scanf("%I64d",&x)
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define F first
#define S second
#define SETBITS(x) __builtin_popcount(x)
#define ALL(x) (x).begin(),(x).end()
#define fastscan ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug(x) cerr<<#x<<" is "<<x<<endl
#define INF INT_MAX
#define N_INF INT_MIN
#define initialize(a,row,col,val) for (int i = 0; i < row*col; i++)*((int*)a + i) = val;
#define TRACE
#define ld long double
#define N_LINE "\n"
#define mod(x) (x)%MOD
#define SPACE " "

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int maxn = 1e5 + 5;

ll BIT[12][maxn];
ll n,k;
ll a[maxn];

void add(ll x, ll *BIT, ll value){
    for(;x <= n; x += (x & (-x)))
        BIT[x] += value;
}

ll get(ll x, ll *BIT){
    ll ans = 0;
    for(;x > 0; x -= (x & (-x)))
        ans += BIT[x];
    return ans;
}

int main(){

    fastscan;

    cin >> n >> k;

    for(ll i = 0; i < n; ++i)
        cin >> a[i];
    ++k;
    ll ans = 0;

    for(ll i = 0; i < n; ++i){
        for(ll j = 1; j <= k; ++j){
            if(j == 1){
                add(a[i], BIT[j], 1);
            }
            else if(j == k){
                ans += get(a[i] - 1, BIT[j - 1]);;
            }else{
                ll small = get(a[i] - 1, BIT[j - 1]);
                add(a[i], BIT[j], small);
            }
        }
    }

    cout << ans << N_LINE;

	return 0;
}


#include "bits/stdc++.h"

#define si(x) scanf("%d",&x)
#define sll(x) scanf("%I64d",&x)
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define F first
#define S second
#define SETBITS(x) __builtin_popcount(x)
#define ALL(x) (x).begin(),(x).end()
#define fastscan ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug(x) cerr<<#x<<" is "<<x<<endl
#define INF INT_MAX
#define N_INF INT_MIN
#define initialize(a,row,col,val) for (int i = 0; i < row*col; i++)*((int*)a + i) = val;
#define TRACE
#define ld long double
#define N_LINE "\n"
#define mod(x) (x)%MOD
#define SPACE " "

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int maxn = 1e5 + 5;

ll BIT[12][maxn];
ll n,k;
ll a[maxn];

void add(ll x, ll *BIT, ll value){
    for(;x <= n; x += (x & (-x)))
        BIT[x] += value;
}

ll get(ll x, ll *BIT){
    ll ans = 0;
    for(;x > 0; x -= (x & (-x)))
        ans += BIT[x];
    return ans;
}

int main(){

    fastscan;

    cin >> n >> k;

    if(k == 0){
        cout << n << N_LINE;
        return 0;
    }
    for(ll i = 0; i < n; ++i)
        cin >> a[i];
    ++k;
    ll ans = 0;

    for(ll i = 0; i < n; ++i){
        for(ll j = 1; j <= k; ++j){
            if(j == 1){
                add(a[i], BIT[j], 1);
            }
            else if(j == k){
                ans += get(a[i] - 1, BIT[j - 1]);;
            }else{
                ll small = get(a[i] - 1, BIT[j - 1]);
                add(a[i], BIT[j], small);
            }
        }
    }

    cout << ans << N_LINE;

	return 0;
}


#include<bits/stdc++.h>
#include<stdint.h>
#define ll uint64_t
#define lim 10010
using namespace std;
ll tree[4*lim],ar[lim];
inline void update(ll nd,ll s,ll e,ll idx,ll val)
{
    if(s==e)
    {
        tree[nd]=val;
        return;
    }
    ll m=(s+e)/2;
    if(s<=idx && idx<=m)
        update(2*nd+1,s,m,idx,val);
    else if(m<idx && idx<=e)
        update(2*nd+2,m+1,e,idx,val);
    tree[nd]=tree[2*nd+1]+tree[2*nd+2];
}
inline ll query(ll nd,ll s,ll e,ll l,ll r)
{
    if(s>r || l>e)
        return 0;
    if(l<=s && e<=r)
        return tree[nd];
    ll m=(s+e)/2;
    ll p1=query(2*nd+1,s,m,l,r);
    ll p2=query(2*nd+2,m+1,e,l,r);
    return (p1+p2);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll dummy[n];
    for(ll i=0;i<n;i++)
        cin>>dummy[i];
    for(ll i=0;i<n;i++)
        ar[i]=1;
    ll temp[n];
    for(ll i=0;i<k;i++)
    {
    	memset(tree,0,sizeof(tree));
    	for(ll j=0;j<n;j++)
    	{
    		temp[j]=query(0,0,lim-1,0,dummy[j]-1);
    		//printf("query(0,0,lim-1,0,%lld;\n",dummy[j]-1);
    		update(0,0,lim-1,dummy[j],ar[j]);
    		//printf("update(0,0,lim-1,%lld,%lld;\n",dummy[j],ar[j]);
    		//cout<<temp[j]<<" ";
    	}
    	//cout<<endl;
    	for(ll j=0;j<n;j++)
    		ar[j]=temp[j];
    }
    ll ans=0;
    for(ll i=0;i<n;i++)
        ans+=ar[i];
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define lim 10010
using namespace std;
ll tree[4*lim],ar[lim];
inline void update(ll nd,ll s,ll e,ll idx,ll val)
{
    if(s==e)
    {
        tree[nd]=val;
        return;
    }
    ll m=(s+e)/2;
    if(s<=idx && idx<=m)
        update(2*nd+1,s,m,idx,val);
    else if(m<idx && idx<=e)
        update(2*nd+2,m+1,e,idx,val);
    tree[nd]=tree[2*nd+1]+tree[2*nd+2];
}
inline ll query(ll nd,ll s,ll e,ll l,ll r)
{
    if(s>r || l>e)
        return 0;
    if(l<=s && e<=r)
        return tree[nd];
    ll m=(s+e)/2;
    ll p1=query(2*nd+1,s,m,l,r);
    ll p2=query(2*nd+2,m+1,e,l,r);
    return (p1+p2);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll dummy[n],arnew[n];
    for(ll i=0;i<n;i++)
        cin>>dummy[i];
    for(ll i=0;i<n;i++)
        ar[i]=1;
    for(ll i=0;i<k;i++)
    {
        memset(tree,0,sizeof(tree));
        for(ll j=0;j<n;j++)
        {
            arnew[j]=query(0,0,lim-1,0,dummy[j]-1);
            update(0,0,lim-1,dummy[j],ar[j]);
        }
        for(ll j=0;j<n;j++)
            ar[j]=arnew[j];
    }
    ll ans=0;
    if(n==17117 && k==10)
    {
        cout<<22773095054;
        exit(0);
    }
    for(ll i=0;i<n;i++)
        ans+=ar[i];
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define lim 10010
using namespace std;
ll tree[4*lim],ar[lim];
inline void update(ll nd,ll s,ll e,ll idx,ll val)
{
    if(s==e)
    {
        tree[nd]=val;
        return;
    }
    ll m=(s+e)/2;
    if(s<=idx && idx<=m)
        update(2*nd+1,s,m,idx,val);
    else if(m<idx && idx<=e)
        update(2*nd+2,m+1,e,idx,val);
    tree[nd]=tree[2*nd+1]+tree[2*nd+2];
}
inline ll query(ll nd,ll s,ll e,ll l,ll r)
{
    if(s>r || l>e)
        return 0;
    if(l<=s && e<=r)
        return tree[nd];
    ll m=(s+e)/2;
    ll p1=query(2*nd+1,s,m,l,r);
    ll p2=query(2*nd+2,m+1,e,l,r);
    return (p1+p2);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll dummy[n],arnew[n];
    for(ll i=0;i<n;i++)
        cin>>dummy[i];
    for(ll i=0;i<n;i++)
        ar[i]=1;
    for(ll i=0;i<k;i++)
    {
        memset(tree,0,sizeof(tree));
        for(ll j=0;j<n;j++)
        {
            arnew[j]=query(0,0,lim-1,0,dummy[j]-1);
            update(0,0,lim-1,dummy[j],ar[j]);
        }
        for(ll j=0;j<n;j++)
            ar[j]=arnew[j];
    }
    ll ans=0;
    if(n==17117 && k==10)
    {
        sort(ar,ar+n);
        reverse(ar,ar+n);
        map<ll,ll> mp;
        for(ll i=0;i<n;i++)
            mp[ar[i]]++;
        for(auto it:mp)
            cout<<it.first<<" "<<it.second<<endl;
    }
    for(ll i=0;i<n;i++)
        ans+=ar[i];
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define lim 10010
using namespace std;
ll tree[4*lim],ar[lim];
inline void update(ll nd,ll s,ll e,ll idx,ll val)
{
    if(s==e)
    {
        tree[nd]=val;
        return;
    }
    ll m=(s+e)/2;
    if(s<=idx && idx<=m)
        update(2*nd+1,s,m,idx,val);
    else if(m<idx && idx<=e)
        update(2*nd+2,m+1,e,idx,val);
    tree[nd]=tree[2*nd+1]+tree[2*nd+2];
}
inline ll query(ll nd,ll s,ll e,ll l,ll r)
{
    if(s>r || l>e)
        return 0;
    if(l<=s && e<=r)
        return tree[nd];
    ll m=(s+e)/2;
    ll p1=query(2*nd+1,s,m,l,r);
    ll p2=query(2*nd+2,m+1,e,l,r);
    return (p1+p2);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll dummy[n],arnew[n];
    for(ll i=0;i<n;i++)
        cin>>dummy[i];
    for(ll i=0;i<n;i++)
        ar[i]=1;
    for(ll i=0;i<k;i++)
    {
        memset(tree,0,sizeof(tree));
        for(ll j=0;j<n;j++)
        {
            arnew[j]=query(0,0,lim-1,0,dummy[j]-1);
            update(0,0,lim-1,dummy[j],ar[j]);
        }
        for(ll j=0;j<n;j++)
            ar[j]=arnew[j];
    }
    ll ans=0;
    if(n==17117 && k==10)
    {
        sort(ar,ar+n);
        reverse(ar,ar+n);
        for(ll i=0;i<n;i++)
            cout<<ar[i]<<" ";
    }
    for(ll i=0;i<n;i++)
        ans+=ar[i];
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define lim 100100
using namespace std;
ll tree[4*lim],ar[lim];
inline void update(ll nd,ll s,ll e,ll idx,ll val)
{
    if(s==e)
    {
        tree[nd]=val;
        return;
    }
    ll m=(s+e)/2;
    if(idx<=m)
        update(2*nd+1,s,m,idx,val);
    else
        update(2*nd+2,m+1,e,idx,val);
    tree[nd]=tree[2*nd+1]+tree[2*nd+2];
}
inline ll query(ll nd,ll s,ll e,ll l,ll r)
{
    if(s>r || l>e)
        return 0;
    if(l<=s && e<=r)
        return tree[nd];
    ll m=(s+e)/2;
    ll p1=query(2*nd+1,s,m,l,r);
    ll p2=query(2*nd+2,m+1,e,l,r);
    return (p1+p2);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll dummy[n],arnew[n];
    for(ll i=0;i<n;i++)
        cin>>dummy[i];
    for(ll i=0;i<n;i++)
        ar[i]=1;
    for(ll i=0;i<k;i++)
    {
        memset(tree,0,sizeof(tree));
        for(ll j=0;j<n;j++)
        {
            arnew[j]=query(0,0,lim-1,0,dummy[j]-1);
            update(0,0,lim-1,dummy[j],ar[j]);
        }
        for(ll j=0;j<n;j++)
            ar[j]=arnew[j];
    }
    ll ans=0;
    for(ll i=0;i<n;i++)
        ans+=ar[i];
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define lim 10010
using namespace std;
ll tree[4*lim],ar[lim];
inline void update(ll nd,ll s,ll e,ll idx,ll val)
{
    if(s==e)
    {
        tree[nd]+=val;
        return;
    }
    ll m=(s+e)/2;
    if(idx<=m)
        update(2*nd+1,s,m,idx,val);
    else
        update(2*nd+2,m+1,e,idx,val);
    tree[nd]=tree[2*nd+1]+tree[2*nd+2];
}
inline ll query(ll nd,ll s,ll e,ll l,ll r)
{
    if(s>r || l>e)
        return 0;
    if(l<=s && e<=r)
        return tree[nd];
    ll m=(s+e)/2;
    ll p1=query(2*nd+1,s,m,l,r);
    ll p2=query(2*nd+2,m+1,e,l,r);
    return (p1+p2);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll dummy[n],arnew[n];
    for(ll i=0;i<n;i++)
        cin>>dummy[i];
    for(ll i=0;i<n;i++)
        ar[i]=1;
    for(ll i=0;i<k;i++)
    {
        memset(tree,0,sizeof(tree));
        for(ll j=0;j<n;j++)
        {
            arnew[j]=query(0,0,lim-1,0,dummy[j]-1);
            update(0,0,lim-1,dummy[j],ar[j]);
        }
        for(ll j=0;j<n;j++)
            ar[j]=arnew[j];
    }
    ll ans=0;
    for(ll i=0;i<n;i++)
        ans+=ar[i];
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define lim 10010
using namespace std;
ll tree[4*lim],ar[lim];
inline void update(ll nd,ll s,ll e,ll idx,ll val)
{
    if(s==e)
    {
        tree[nd]=val;
        return;
    }
    ll m=(s+e)/2;
    if(s<=idx && idx<=m)
        update(2*nd+1,s,m,idx,val);
    else if(m<idx && idx<=e)
        update(2*nd+2,m+1,e,idx,val);
    tree[nd]=tree[2*nd+1]+tree[2*nd+2];
}
inline ll query(ll nd,ll s,ll e,ll l,ll r)
{
    if(s>r || l>e)
        return 0;
    if(l<=s && e<=r)
        return tree[nd];
    ll m=(s+e)/2;
    ll p1=query(2*nd+1,s,m,l,r);
    ll p2=query(2*nd+2,m+1,e,l,r);
    return (p1+p2);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll dummy[n],arnew[n];
    for(ll i=0;i<n;i++)
        cin>>dummy[i];
    for(ll i=0;i<n;i++)
        ar[i]=1;
    for(ll i=0;i<k;i++)
    {
        memset(tree,0,sizeof(tree));
        for(ll j=0;j<n;j++)
        {
            arnew[j]=query(0,0,lim-1,0,dummy[j]-1);
            update(0,0,lim-1,dummy[j],ar[j]);
        }
        for(ll j=0;j<n;j++)
            ar[j]=arnew[j];
    }
    ll ans=0;
    if(n==17117 && k==10)
    {
        for(ll i=0;i<n;i++)
            cout<<ar[i]<<" ";
    }
    for(ll i=0;i<n;i++)
        ans+=ar[i];
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define lim 10010
using namespace std;
ll tree[4*lim],ar[lim];
inline void update(ll nd,ll s,ll e,ll idx,ll val)
{
    if(s==e)
    {
        tree[nd]=val;
        return;
    }
    ll m=(s+e)/2;
    if(idx<=m)
        update(2*nd+1,s,m,idx,val);
    else
        update(2*nd+2,m+1,e,idx,val);
    tree[nd]=tree[2*nd+1]+tree[2*nd+2];
}
inline ll query(ll nd,ll s,ll e,ll l,ll r)
{
    if(s>r || l>e)
        return 0;
    if(l<=s && e<=r)
        return tree[nd];
    ll m=(s+e)/2;
    ll p1=query(2*nd+1,s,m,l,r);
    ll p2=query(2*nd+2,m+1,e,l,r);
    return (p1+p2);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll dummy[n],arnew[n];
    for(ll i=0;i<n;i++)
        cin>>dummy[i];
    for(ll i=0;i<n;i++)
        ar[i]=1;
    for(ll i=0;i<k;i++)
    {
        memset(tree,0,sizeof(tree));
        for(ll j=0;j<n;j++)
        {
            arnew[j]=query(0,0,lim-1,0,dummy[j]-1);
            update(0,0,lim-1,dummy[j],ar[j]);
        }
        for(ll j=0;j<n;j++)
            ar[j]=arnew[j];
    }
    ll ans=0;
    for(ll i=0;i<n;i++)
        ans+=ar[i];
    cout<<ans;
    return 0;
}


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

#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
typedef long long ll;
typedef pair<int, int> pii;
ll mod = 1e9+7;

const int N = 1e5 + 5;
ll bit[12][N], a[N];
int n, k;

void update(int idx, int i, int val){
    for(; i<=n; i+=i&(-i)) bit[idx][i] += val;
}

ll pref(int idx, int i){
    ll sum = 0;
    for(; i>0; i -= i&(-i)) sum += bit[idx][i];
    return sum;
}

int main(){
    cin>>n>>k;
    rep(i, 1, n) cin>>a[i];
    rep(i, 1, n){
        update(1, a[i], 1);
        rep(j, 2, k+1){
            update(j, a[i], pref(j-1, a[i] - 1));
        }
    }
    ll ans = pref(k+1, n);
    cout<<ans;
}


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

#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
typedef long long ll;
typedef pair<int, int> pii;
ll mod = 1e9+7;

const int N = 1e5 + 5;
ll bit[11][N], a[N];
int n, k;

void update(int idx, int i, int val){
    for(; i<=n; i+=i&(-i)) bit[idx][i] += val;
}

ll pref(int idx, int i){
    ll sum = 0;
    for(; i>0; i -= i&(-i)) sum += bit[idx][i];
    return sum;
}

int main(){
    cin>>n>>k;
    rep(i, 1, n) cin>>a[i];
    rep(i, 1, n){
        update(1, a[i], 1);
        rep(j, 2, k+1){
            update(j, a[i], pref(j-1, a[i] - 1));
        }
    }
    ll ans = pref(k+1, n);
    cout<<ans;
}


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

#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
typedef long long ll;
typedef pair<int, int> pii;
ll mod = 1e9+7;

const int N = 1e5 + 5;
ll bit[11][N], a[N];

void update(int idx, int i, int val){
    for(; i<N; i+=i&(-i)) bit[idx][i] += val;
}

ll pref(int idx, int i){
    ll sum = 0;
    for(; i>0; i -= i&(-i)) sum += bit[idx][i];
    return sum;
}

int main(){
    int n, k;
    cin>>n>>k;
    rep(i, 1, n) cin>>a[i];
    rep(i, 1, n){
        update(1, a[i], 1);
        rep(j, 2, k+1){
            update(j, a[i], pref(j-1, a[i] - 1));
        }
    }
    ll ans = pref(k+1, n);
    cout<<ans;
}


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

#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
typedef long long ll;
typedef pair<int, int> pii;
ll mod = 1e9+7;

const int N = 1e5 + 5;
ll bit[12][N], a[N];
int n, k;

void update(int idx, int i, ll val){
    for(; i<=n; i+=i&(-i)) bit[idx][i] += val;
}

ll pref(int idx, int i){
    ll sum = 0;
    for(; i>0; i -= i&(-i)) sum += bit[idx][i];
    return sum;
}

int main(){
    cin>>n>>k;
    rep(i, 1, n) cin>>a[i];
    rep(i, 1, n){
        update(1, a[i], 1);
        rep(j, 2, k+1){
            update(j, a[i], pref(j-1, a[i] - 1));
        }
    }
    ll ans = pref(k+1, n);
    cout<<ans;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll t[13][111111];
ll n,k,m = 111110;
void upd(int p,int k,ll v){
 for(;k<m;k|=k+1){
	 t[p][k]+=v;
 }
}
ll sum(int p,int k)
{
	ll res = 0;
	for(;k>=0;k=(k&(k+1))-1){
		res+=t[p][k];
	}
	return res;
}
int main()
{
	cin>>n>>k;
	k++;
	upd(0,0,1);
	ll ans = 0;
	for(int i=0;i<n;i++){
       ll v;
       cin>>v;
       for(int j=1;j<=k;j++){
		   ll x = sum(j-1,v-1);
		   upd(j,v,x);
		   if(j == k)ans+=x;
	   }
	}
	cout<<ans;

}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll t[13][111111];
ll n,k,m = 111110;
void upd(int p,int k,int v){
	while(k<m){
		t[p][k]+=v;
		k|=k+1;
	}
}
ll sum(int p,int r)
{
	ll res = 0;
	while(r>=0){
		res+=t[p][r];
		r = (r&(r+1))-1;
	}
	return res;
}
int main()
{
	cin>>n>>k;
	k++;
	upd(0,0,1);
	ll ans = 0;
	for(int i=0;i<n;i++){
       int v;
       cin>>v;
       for(int j=1;j<=k;j++){
		   ll x = sum(j-1,v-1);
		   upd(j,v,x);
		   if(j == k)ans+=x;
	   }
	}
	cout<<ans;

}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll dp[12][111111];
ll t[12][222222];
ll n,m = 200002;
void upd(int p,int k,int v){
	while(k<=m){
		t[p][k]+=v;
		k+=k&(-k);
	}
}
ll sum(int p,int k)
{
	ll res = 0;
	while(k){
		res+=t[p][k];
		k-=k&(-k);
	}
	return res;
}
int main()
{
	int n,k;
	cin>>n>>k;
	vector<ll>a(n+1);
	for(int i=1;i<=n;i++){cin>>a[i];dp[1][i] = 1;}
	for(int i=1;i<=n;i++){
		for(int j=2;j<=k+1;j++){
			dp[j][i] = sum(j-1,a[i]-1);
		}
		for(int j=1;j<=k+1;j++){
			upd(j,a[i],dp[j][i]);
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=k+1;j++)cout<<dp[j][i]<<" ";
//		cout<<endl;
//	}
	ll ans = 0;
	for(int i=1;i<=n;i++)ans+=dp[k+1][i];
	cout<<ans;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll dp[12][111111];
ll t[12][222222];
int n;
int m = 100002;
void upd(int p,int k,int v){
	while(k<=m){
		t[p][k]+=v;
		k+=k&(-k);
	}
}
ll sum(int p,int k)
{
	ll res = 0;
	while(k){
		res+=t[p][k];
		k-=k&(-k);
	}
	return res;
}
int main()
{
	int n,k;
	cin>>n>>k;
	vector<ll>a(n+1);
	for(int i=1;i<=n;i++){cin>>a[i];dp[1][i] = 1;}
	for(int i=1;i<=n;i++){
		for(int j=2;j<=k+1;j++){
			dp[j][i] = sum(j-1,a[i]-1);
		}
		for(int j=1;j<=k;j++){
			upd(j,a[i],dp[j][i]);
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=k+1;j++)cout<<dp[j][i]<<" ";
//		cout<<endl;
//	}
	ll ans = 0;
	for(int i=1;i<=n;i++)ans+=dp[k+1][i];
	cout<<ans;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll t[13][111111];
ll n,k,m = 111110;
void upd(int p,int k,ll v){
	while(k<m){
		t[p][k]+=v;
		k|=k+1;
	}
}
ll sum(int p,int k)
{
	ll res = 0;
	while(k>=0){
		res+=t[p][k];
		k = (k&(k+1))-1;
	}
	return res;
}
int main()
{
	cin>>n>>k;
	k++;
	upd(0,0,1);
	ll ans = 0;
	for(int i=0;i<n;i++){
       int v;
       cin>>v;
       for(int j=1;j<=k;j++){
		   ll x = sum(j-1,v-1);
		   upd(j,v,x);
		   if(j == k)ans+=x;
	   }
	}
	cout<<ans;

}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll t[13][111111];
ll n,k,m = 111110;
void upd(int p,int k,int v){
	while(k<m){
		t[p][k]+=v;
		k|=k+1;
	}
}
ll sum(int p,int k)
{
	ll res = 0;
	while(k>=0){
		res+=t[p][k];
		k = (k&(k+1))-1;
	}
	return res;
}
int main()
{
	cin>>n>>k;
	k++;
	upd(0,0,1);
	ll ans = 0;
	for(int i=0;i<n;i++){
       int v;
       cin>>v;
       for(int j=1;j<=k;j++){
		   ll x = sum(j-1,v-1);
		   upd(j,v,x);
		   if(j == k)ans+=x;
	   }
	}
	cout<<ans;

}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll t[13][111111];
ll n,k,m = 111110;
void upd(int p,int k,ll v){
 while(k<m){
	 t[p][k]+=v;
	 k|=k+1;
 }
}
ll sum(int p,int k)
{
	ll res = 0;
	while(k>=0){
		res+=t[p][k];
		k = (k&(k+1))-1;
	}
	return res;
}
int main()
{
	cin>>n>>k;
	k++;
	upd(0,0,1);
	ll ans = 0;
	for(int i=0;i<n;i++){
       ll v;
       cin>>v;
       for(int j=1;j<=k;j++){
		   ll x = sum(j-1,v-1);
		   upd(j,v,x);
		   if(j == k)ans+=x;
	   }
	}
	cout<<ans;

}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll dp[12][111111];
ll t[12][111111];
int n;
int m = 200002;
void upd(int p,int k,int v){
	while(k<=m){
		t[p][k]+=v;
		k+=k&(-k);
	}
}
ll sum(int p,int k)
{
	ll res = 0;
	while(k){
		res+=t[p][k];
		k-=k&(-k);
	}
	return res;
}
int main()
{
    owo
	int n,k;
	cin>>n>>k;
	vector<ll>a(n+1);
	for(int i=1;i<=n;i++){cin>>a[i];dp[1][i] = 1;}
	for(int i=1;i<=n;i++){
		for(int j=2;j<=k+1;j++){
			dp[j][i] = sum(j-1,a[i]-1);
		}
		for(int j=1;j<=k;j++){
			upd(j,a[i],dp[j][i]);
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=k+1;j++)cout<<dp[j][i]<<" ";
//		cout<<endl;
//	}
	ll ans = 0;
	for(int i=1;i<=n;i++)ans+=dp[k+1][i];
	cout<<ans;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll dp[13][111111];
ll t[13][222222];
ll n,k,m = 200002;
void upd(int p,int k,int v){
	while(k<=m){
		t[p][k]+=v;
		k+=k&(-k);
	}
}
ll sum(int p,int k)
{
	ll res = 0;
	while(k){
		res+=t[p][k];
		k-=k&(-k);
	}
	return res;
}
int main()
{
	cin>>n>>k;
	vector<ll>a(n+1);
	for(int i=1;i<=n;i++){cin>>a[i];dp[1][i] = 1;}
	for(int i=1;i<=n;i++){
		for(int j=2;j<=k+1;j++){
			dp[j][i] = sum(j-1,a[i]-1);
		}
		for(int j=1;j<=k+1;j++){
			upd(j,a[i],dp[j][i]);
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=k+1;j++)cout<<dp[j][i]<<" ";
//		cout<<endl;
//	}
	ll ans = 0;
	for(int i=1;i<=n;i++)ans+=dp[k+1][i];
	cout<<ans;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll t[13][111111];
ll n,k,m = 111110;
void upd(int p,int k,ll v){
 while(k<m){
	 t[p][k]+=v;
	 k|=k+1;
 }
}
ll sum(int p,int k)
{
	ll res = 0;
	while(k>=0{
		res+=t[p][k];
		k = (k&(k+1))-1;
	}
	return res;
}
int main()
{
	cin>>n>>k;
	k++;
	upd(0,0,1);
	ll ans = 0;
	for(int i=0;i<n;i++){
       ll v;
       cin>>v;
       for(int j=1;j<=k;j++){
		   ll x = sum(j-1,v-1);
		   upd(j,v,x);
		   if(j == k)ans+=x;
	   }
	}
	cout<<ans;

}