#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxm = 100000+100;

int dp[maxm];
struct Edge
{
    int u,v,w,e;
    bool operator< (const Edge &rhs)const{
        if(w==rhs.w)return dp[e]<dp[rhs.e];
        return w<rhs.w;
    }
};

int n,m;
int v1[maxm],v2[maxm],w[maxm];
set<Edge> G[100000+100];
int dpG[100000+100];

int main()
{
    //freopen("I:\\Project\\acm\\Algorithm\\input.txt","r",stdin);//

    ios::sync_with_stdio(false);
    fill(begin(dp),end(dp),1);
    cin>>n>>m;
    for (int i = 0; i < m; i++) {
        cin>>v1[i]>>v2[i]>>w[i];

        // int down = 0,up = i;
        // while(down<up)
        // {
        //     int mid = (down+up)/2;
        //     auto iter = G[v1[i]].find(mid);
        //     if(iter==G)
        // }

        auto iter2 = G[v1[i]].lower_bound({0,0,w[i],0});
        if(iter2!=G[v1[i]].begin())
        {
            iter2--;
            dp[i] = dp[iter2->e]+1;
        }

        // for(auto e:G[v1[i]])
        // {
        //     if(e.w>w[i])
        //     {
        //         break;
        //     }
        //
        //     if(e.w<w[i])
        //     {
        //         if(dp[i]<dp[e.e]+1)
        //         {
        //             dp[i]=dp[e.e]+1;
        //         }
        //     }
        // }

        auto iter = G[v1[i]].lower_bound({0,0,w[i],0});
        while(true)
        {
            if(iter!=G[v1[i]].end()&& iter->w>=w[i]&&dp[iter->e]<=dp[i])
            {
                iter = G[v1[i]].erase(iter);
            }else{
                break;
            }
        }

        G[v2[i]].insert({v1[i],v2[i],w[i],i});
    }
    int ans=0;
    for(int i=0;i<m;i++)
    {
        if(ans<dp[i])ans=dp[i];
    }
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,m;
map<int,int> mc[100000+100];

int get(int x,int w)
{
	 auto it = mc[x].lower_bound(w);
	 if(it==mc[x].begin())return 0;
	 it--;
	 return it->second;
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	int ans = 0;
	for(int i=0;i<m;i++)
	{
		int a,b,w;
		cin>>a>>b>>w;
		int len = get(a,w);
		if(len<get(b,w+1))continue;
		mc[b][w]=len+1;
		auto it = mc[b].upper_bound(w);
		while(it!=mc[b].end()&&it->second<=len+1)
		{
			it = mc[b].erase(it);
		}
		ans = max(ans,len+1);
	}
	cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxm = 100000+100;

int dp[maxm];
struct Edge
{
    int u,v,w,e;
    bool operator< (const Edge &rhs)const{
        if(w==rhs.w)return dp[e]<dp[rhs.e];
        return w<rhs.w;
    }
};

int n,m;
int v1[maxm],v2[maxm],w[maxm];
set<Edge> G[100000+100];
int dpG[100000+100];

int main()
{
    //freopen("I:\\Project\\acm\\Algorithm\\input.txt","r",stdin);//

    ios::sync_with_stdio(false);
    fill(begin(dp),end(dp),1);
    cin>>n>>m;
    for (int i = 0; i < m; i++) {
        cin>>v1[i]>>v2[i]>>w[i];

        auto iter2 = G[v1[i]].lower_bound({0,0,w[i],0});
        if(iter2!=G[v1[i]].begin())
        {
            iter2--;
            dp[i] = dp[iter2->e]+1;
        }

        auto iter = G[v1[i]].lower_bound({0,0,w[i],0});
        int flag=0;
        if(iter== G[v1[i]].end()|| iter->w>w[i])flag=1;
        while(true)
        {
            if(iter!=G[v1[i]].end()&& iter->w>=w[i]&&dp[iter->e]<=dp[i])
            {
                iter = G[v1[i]].erase(iter);
                flag=1;
            }else{
                break;
            }
        }
        if(flag==1)
            G[v2[i]].insert({v1[i],v2[i],w[i],i});
    }
    int ans=0;
    for(int i=0;i<m;i++)
    {
        if(ans<dp[i])ans=dp[i];
    }
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxm = 100000+100;

struct Edge
{
    int u,v,w,e;
};

int n,m;
int v1[maxm],v2[maxm],w[maxm];
vector<Edge> G[100000+100];
int dp[maxm];

int main()
{
    //freopen("I:\\Project\\acm\\Algorithm\\input.txt","r",stdin);//

    ios::sync_with_stdio(false);
    fill(begin(dp),end(dp),1);
    cin>>n>>m;
    for (int i = 0; i < m; i++) {
        cin>>v1[i]>>v2[i]>>w[i];

        for(auto e:G[v1[i]])
        {
            if(e.w<w[i])
            {
                if(dp[i]<dp[e.e]+1)
                {
                    dp[i]=dp[e.e]+1;
                }
            }
        }
        G[v2[i]].push_back({v1[i],v2[i],w[i],i});
    }
    int ans=0;
    for(int i=0;i<m;i++)
    {
        if(ans<dp[i])ans=dp[i];
    }
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxm = 100000+100;

int dp[maxm];
struct Edge
{
    int u,v,w,e;
    bool operator< (const Edge &rhs)const{
        if(w==rhs.w)
        {
            return (e==-1?-1:dp[e])< (rhs.e==-1?-1:dp[rhs.e]);
        }
        return w<rhs.w;
    }
};

int n,m;
int v1[maxm],v2[maxm],w[maxm];
set<Edge> G[100000+100];
int dpG[100000+100];

int main()
{
    //freopen("I:\\Project\\acm\\Algorithm\\input.txt","r",stdin);//

    ios::sync_with_stdio(false);
    fill(begin(dp),end(dp),1);
    cin>>n>>m;
    for (int i = 0; i < m; i++) {
        cin>>v1[i]>>v2[i]>>w[i];

        // for(auto e:G[v1[i]])
        // {
        //     if(e.w>w[i])
        //     {
        //         break;
        //     }
        //
        //     if(e.w<w[i])
        //     {
        //         if(dp[i]<dp[e.e]+1)
        //         {
        //             dp[i]=dp[e.e]+1;
        //         }
        //     }
        // }

        auto iter2 = G[v1[i]].lower_bound({0,0,w[i],-1});
        if(iter2!=G[v1[i]].begin())
        {
            int k=0;
            // while(true)
            // {
                if(iter2==G[v1[i]].begin())break;
                else iter2--;
                dp[i] = max(dp[i], dp[iter2->e]+1);
                // k++;
                // if(k>10)break;
            // }
        }

        auto iter = G[v1[i]].lower_bound({0,0,w[i],-1});
        int flag=0;
        if(iter== G[v1[i]].end()|| iter->w>w[i])flag=1;
        //这里LIS原本写漏了，没有考虑w比当前小的他的dp值，又是考虑后端，忘了考虑前端。
        if(iter!=G[v1[i]].begin())
        {
            auto iter3 = iter;
            iter3--;
            if(dp[iter3->e]>=dp[i])continue;
        }
        while(true)
        {
            if(iter!=G[v1[i]].end()&& iter->w>=w[i]&&dp[iter->e]<=dp[i])
            {
                iter = G[v1[i]].erase(iter);
                flag=1;
            }else{
                break;
            }
        }
        if(flag==1)
            G[v2[i]].insert({v1[i],v2[i],w[i],i});
    }
    int ans=0;
    for(int i=0;i<m;i++)
    {
        if(ans<dp[i])ans=dp[i];
    }
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxm = 100000+100;

int dp[maxm];
struct Edge
{
    int u,v,w,e;
    bool operator< (const Edge &rhs)const{
        if(w==rhs.w)
        {
            return (e==-1?-1:dp[e])< (rhs.e==-1?-1:dp[rhs.e]);
        }
        return w<rhs.w;
    }
};

int n,m;
int v1[maxm],v2[maxm],w[maxm];
set<Edge> G[100000+100];
int dpG[100000+100];

int main()
{
    //freopen("I:\\Project\\acm\\Algorithm\\input.txt","r",stdin);//

    ios::sync_with_stdio(false);
    fill(begin(dp),end(dp),1);
    cin>>n>>m;
    for (int i = 0; i < m; i++) {
        cin>>v1[i]>>v2[i]>>w[i];

        // for(auto e:G[v1[i]])
        // {
        //     if(e.w>w[i])
        //     {
        //         break;
        //     }
        //
        //     if(e.w<w[i])
        //     {
        //         if(dp[i]<dp[e.e]+1)
        //         {
        //             dp[i]=dp[e.e]+1;
        //         }
        //     }
        // }

        auto iter2 = G[v1[i]].lower_bound({0,0,w[i],-1});
        if(iter2!=G[v1[i]].begin())
        {
            int k=0;
            while(true)
            {
                if(iter2==G[v1[i]].begin())break;
                else iter2--;
                dp[i] = max(dp[i], dp[iter2->e]+1);
                k++;
                if(k>100)break;
            }
        }

        auto iter = G[v1[i]].lower_bound({0,0,w[i],-1});
        int flag=0;
        if(iter== G[v1[i]].end()|| iter->w>w[i])flag=1;
        while(true)
        {
            if(iter!=G[v1[i]].end()&& iter->w>=w[i]&&dp[iter->e]<=dp[i])
            {
                iter = G[v1[i]].erase(iter);
                flag=1;
            }else{
                break;
            }
        }
        if(flag==1)
            G[v2[i]].insert({v1[i],v2[i],w[i],i});
    }
    int ans=0;
    for(int i=0;i<m;i++)
    {
        if(ans<dp[i])ans=dp[i];
    }
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxm = 100000+100;

int dp[maxm];
struct Edge
{
    int u,v,w,e;
    bool operator< (const Edge &rhs)const{
        if(w==rhs.w)return dp[e]<dp[rhs.e];
        return w<rhs.w;
    }
};

int n,m;
int v1[maxm],v2[maxm],w[maxm];
set<Edge> G[100000+100];
int dpG[100000+100];

int main()
{
    //freopen("I:\\Project\\acm\\Algorithm\\input.txt","r",stdin);//

    ios::sync_with_stdio(false);
    fill(begin(dp),end(dp),1);
    cin>>n>>m;
    for (int i = 0; i < m; i++) {
        cin>>v1[i]>>v2[i]>>w[i];

        for(auto e:G[v1[i]])
        {
            if(e.w>w[i])
            {
                break;
            }

            if(e.w<w[i])
            {
                if(dp[i]<dp[e.e]+1)
                {
                    dp[i]=dp[e.e]+1;
                }
            }
        }

        auto iter = G[v1[i]].lower_bound({0,0,w[i],0});
        while(true)
        {
            if(iter!=G[v1[i]].end()&& iter->w==w[i]&&dp[iter->e]<=dp[i])
            {
                iter = G[v1[i]].erase(iter);
            }else{
                break;
            }
        }

        G[v2[i]].insert({v1[i],v2[i],w[i],i});
    }
    int ans=0;
    for(int i=0;i<m;i++)
    {
        if(ans<dp[i])ans=dp[i];
    }
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxm = 100000+100;

int dp[maxm];
struct Edge
{
    int u,v,w,e;
    bool operator< (const Edge &rhs)const{
        if(w==rhs.w)
        {
            return (e==-1?-1:dp[e])< (rhs.e==-1?-1:dp[rhs.e]);
        }
        return w<rhs.w;
    }
};

int n,m;
int v1[maxm],v2[maxm],w[maxm];
set<Edge> G[100000+100];
int dpG[100000+100];

int main()
{
    //freopen("I:\\Project\\acm\\Algorithm\\input.txt","r",stdin);//

    ios::sync_with_stdio(false);
    fill(begin(dp),end(dp),1);
    cin>>n>>m;
    for (int i = 0; i < m; i++) {
        cin>>v1[i]>>v2[i]>>w[i];

        // for(auto e:G[v1[i]])
        // {
        //     if(e.w>w[i])
        //     {
        //         break;
        //     }
        //
        //     if(e.w<w[i])
        //     {
        //         if(dp[i]<dp[e.e]+1)
        //         {
        //             dp[i]=dp[e.e]+1;
        //         }
        //     }
        // }

        auto iter2 = G[v1[i]].lower_bound({0,0,w[i],-1});
        if(iter2!=G[v1[i]].begin())
        {
            int k=0;
            while(true)
            {
                if(iter2==G[v1[i]].begin())break;
                else iter2--;
                dp[i] = max(dp[i], dp[iter2->e]+1);
                k++;
                if(k>10)break;
            }
        }

        auto iter = G[v1[i]].lower_bound({0,0,w[i],-1});
        int flag=0;
        if(iter== G[v1[i]].end()|| iter->w>w[i])flag=1;
        while(true)
        {
            if(iter!=G[v1[i]].end()&& iter->w>=w[i]&&dp[iter->e]<=dp[i])
            {
                iter = G[v1[i]].erase(iter);
                flag=1;
            }else{
                break;
            }
        }
        if(flag==1)
            G[v2[i]].insert({v1[i],v2[i],w[i],i});
    }
    int ans=0;
    for(int i=0;i<m;i++)
    {
        if(ans<dp[i])ans=dp[i];
    }
    cout<<ans<<endl;

    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int M=2e5+10,MAX=1e5+1;
int n,m;
struct edge{
	int u,v,w;
	edge(){}
	edge(int a,int b,int c):u(a),v(b),w(c){}
	void in(){scanf("%d%d%d",&u,&v,&w);}
}e[M];
int ls[M<<4],rs[M<<4],maxv[M<<4],tot;
int F[M];
int query(int &o,int l,int r,int L,int R){
	if(L>R) return 0;
	if(!o)o=++tot;
	if(L<=l&&r<=R) return maxv[o];
	int v=0,mid=l+r>>1;
	if(L<=mid) v=query(ls[o],l,mid,L,R);
	if(R>mid) v=max(v,query(rs[o],mid+1,r,L,R));
	return v;
}
void update(int &o,int l,int r,int p,int v){
	if(!o) o=++tot;
	if(l==r){
		maxv[o]=max(maxv[o],v);
		return;
	}
	int mid=l+r>>1;
	if(p<=mid) update(ls[o],l,mid,p,v);
	else update(rs[o],mid+1,r,p,v);
	maxv[o]=max(maxv[ls[o]],maxv[rs[o]]);
}
int ans;
int main(){
	scanf("%d%d",&n,&m);tot=n;
	for(int i=1;i<=m;i++){e[i].in();++e[i].w;}
	for(int i=1;i<=m;i++){
		F[i]=query(e[i].u,1,MAX,1,e[i].w-1)+1;
		update(e[i].v,1,MAX,e[i].w,F[i]);
	}
	for(int i=1;i<=m;i++)if(ans<F[i])ans=F[i];
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int M=2e5+10,MAX=1e5+1;
int n,m;
struct edge{
	int u,v,w;
	edge(){}
	edge(int a,int b,int c):u(a),v(b),w(c){}
	void in(){scanf("%d%d%d",&u,&v,&w);}
}e[M];
int ls[M<<2],rs[M<<2],maxv[M<<2],tot;
int F[M];
int query(int &o,int l,int r,int L,int R){
	if(L>R) return 0;
	if(!o)o=++tot;
	if(L<=l&&r<=R) return maxv[o];
	int v=0,mid=l+r>>1;
	if(L<=mid) v=query(ls[o],l,mid,L,R);
	if(R>mid) v=max(v,query(rs[o],mid+1,r,L,R));
	return v;
}
void update(int &o,int l,int r,int p,int v){
	if(!o) o=++tot;
	if(l==r){
		maxv[o]=max(maxv[o],v);
		return;
	}
	int mid=l+r>>1;
	if(p<=mid) update(ls[o],l,mid,p,v);
	else update(rs[o],mid+1,r,p,v);
	maxv[o]=max(maxv[ls[o]],maxv[rs[o]]);
}
int ans;
int main(){
	scanf("%d%d",&n,&m);tot=n;
	for(int i=1;i<=m;i++){e[i].in();++e[i].w;}
	for(int i=1;i<=m;i++){
		F[i]=query(e[i].u,1,MAX,1,e[i].w-1)+1;
		update(e[i].v,1,MAX,e[i].w,F[i]);
	}
	for(int i=1;i<=m;i++)if(ans<F[i])ans=F[i];
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int M=3e5+10,MAX=1e5+1;
int n,m;
struct edge{
	int u,v,w;
	edge(){}
	edge(int a,int b,int c):u(a),v(b),w(c){}
	void in(){scanf("%d%d%d",&u,&v,&w);}
}e[M];
int ls[M<<5],rs[M<<5],maxv[M<<5],tot;
int F[M];
int query(int &o,int l,int r,int L,int R){
	if(L>R) return 0;
	if(!o)o=++tot;
	if(L<=l&&r<=R) return maxv[o];
	int v=0,mid=l+r>>1;
	if(L<=mid) v=query(ls[o],l,mid,L,R);
	if(R>mid) v=max(v,query(rs[o],mid+1,r,L,R));
	return v;
}
void update(int &o,int l,int r,int p,int v){
	if(!o) o=++tot;
	if(l==r){
		maxv[o]=max(maxv[o],v);
		return;
	}
	int mid=l+r>>1;
	if(p<=mid) update(ls[o],l,mid,p,v);
	else update(rs[o],mid+1,r,p,v);
	maxv[o]=max(maxv[ls[o]],maxv[rs[o]]);
}
int ans;
int main(){
	scanf("%d%d",&n,&m);tot=n;
	for(int i=1;i<=m;i++)
	{e[i].in();++e[i].w;}
	for(int i=1;i<=m;i++){
		F[i]=query(e[i].u,1,MAX,1,e[i].w-1)+1;
		update(e[i].v,1,MAX,e[i].w,F[i]);
		if(ans<F[i])ans=F[i];
	}
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int M=3e5+10,MAX=1e5+1;
int n,m;
struct edge{
	int u,v,w;
	edge(){}
	edge(int a,int b,int c):u(a),v(b),w(c){}
	void in(){scanf("%d%d%d",&u,&v,&w);}
}e[M];
int ls[M<<5],rs[M<<5],maxv[M<<5],tot;
int F[M];
int query(int &o,int l,int r,int L,int R){
	if(L>R) return 0;
	if(!o)o=++tot;
	if(L<=l&&r<=R) return maxv[o];
	int v=0,mid=l+r>>1;
	if(L<=mid) v=query(ls[o],l,mid,L,R);
	if(R>mid) v=max(v,query(rs[o],mid+1,r,L,R));
	return v;
}
void update(int &o,int l,int r,int p,int v){
	if(!o) o=++tot;
	if(l==r){
		maxv[o]=max(maxv[o],v);
		return;
	}
	int mid=l+r>>1;
	if(p<=mid) update(ls[o],l,mid,p,v);
	else update(rs[o],mid+1,r,p,v);
	maxv[o]=max(maxv[ls[o]],maxv[rs[o]]);
}
int ans;
int main(){
	scanf("%d%d",&n,&m);tot=n;
	for(int i=1;i<=m;i++){e[i].in();++e[i].w;}
	for(int i=1;i<=m;i++){
		F[i]=query(e[i].u,1,MAX,1,e[i].w-1)+1;
		update(e[i].v,1,MAX,e[i].w,F[i]);
		if(ans<F[i])ans=F[i];
	}
	printf("%d\n",ans);
	return 0;
}


import java.util.*;
public class equal_strings {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String s=in.next();
		char arr[]=s.toCharArray();
		Arrays.parallelSort(arr);
		int c=0,cnt=0,count=0;
		String str="";
		for(int i=0;i<arr.length;i++)
		{
			str=str+arr[i];
		}
		if(str.compareTo(s)!=0)
		{
			System.out.println("NO");
		}
		else
		{
			for(int i=0;i<s.length();i++)
			{
				if(s.charAt(i)=='a')
				{
					c++;
				}
				else if(s.charAt(i)=='b')
				{
					cnt++;
				}
				else
				{
					count++;
				}
			}
			if(c==count || cnt==count)
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
	}
}


import java.util.*;
public class check_string {
	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String s=in.next();
	char arr[]=s.toCharArray();
	ArrayList<Character> list = new ArrayList<>();
	Set<Long> set = new HashSet<>();
	for(char k:arr)
	{
		list.add(k);
	}
	Arrays.sort(arr);
	String str="";
	for(char k:arr)
	{
		str=str+k;
	}
	if(str.compareToIgnoreCase(s)!=0)
	{
		System.out.println("NO");
		System.exit(0);
	}
	if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
	{
		System.out.println("NO");
		System.exit(0);
	}
	list.clear();
	char c='a';
	long cnt=0;
	for(int i=0;i<s.length();i++)
	{
		if(s.charAt(i)==c)
		{
			cnt++;
		}
		else
		{
			set.add(cnt);
			c=(char) ((char)c+1);
			cnt=0;
			i--;
		}
	}
	if(set.size()<3)
	{
		System.out.println("YES");
	}
	else
	{
		System.out.println("NO");
	}
	}
}


import java.util.*;
public class equal_strings {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String s=in.next();
		char arr[]=s.toCharArray();
		Arrays.parallelSort(arr);
		int c=0,cnt=0,count=0;
		String str="";
		ArrayList<Character> list = new ArrayList<>();
		for(int i=0;i<arr.length;i++)
		{
			str=str+arr[i];
			list.add(arr[i]);
		}
		if(str.compareTo(s)!=0)
		{
			System.out.println("NO");
		}
		else if(list.contains('a')!=true)
		{
			System.out.println("NO");
		}
		else
		{
			for(int i=0;i<s.length();i++)
			{
				if(s.charAt(i)=='a')
				{
					c++;
				}
				else if(s.charAt(i)=='b')
				{
					cnt++;
				}
				else
				{
					count++;
				}
			}
			if(c==count && c!=0)
			{
				System.out.println("YES");
			}
			else if(cnt==count && cnt!=0)
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
	}
}


import java.util.*;
public class equal_strings {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String s=in.next();
		char arr[]=s.toCharArray();
		Arrays.parallelSort(arr);
		int c=0,cnt=0,count=0;
		String str="";
		for(int i=0;i<arr.length;i++)
		{
			str=str+arr[i];
		}
		if(str.compareTo(s)!=0)
		{
			System.out.println("NO");
		}
		else
		{
			for(int i=0;i<s.length();i++)
			{
				if(s.charAt(i)=='a')
				{
					c++;
				}
				else if(s.charAt(i)=='b')
				{
					cnt++;
				}
				else
				{
					count++;
				}
			}
			if(c==count && c!=0)
			{
				System.out.println("YES");
			}
			else if(cnt==count && cnt!=0)
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
	}
}


import java.util.*;
public class check_the_string {
	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String s=in.next();
	char arr[]=s.toCharArray();
	ArrayList<Character> list = new ArrayList<>();
	Set<Long> set = new HashSet<>();
	for(char k:arr)
	{
		list.add(k);
	}
	Arrays.sort(arr);
	String str="";
	for(char k:arr)
	{
		str=str+k;
	}
	if(str.compareToIgnoreCase(s)!=0)
	{
		System.out.println("NO");
		System.exit(0);
	}
	if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
	{
		System.out.println("NO");
		System.exit(0);
	}
	list.clear();
	char c='a';
	long cnt=0;
	for(int i=0;i<s.length();i++)
	{
		if(s.charAt(i)==c)
		{
			cnt++;
		}
		else
		{
			set.add(cnt);
			c=(char) ((char)c+1);
		}
	}
	if(set.size()<3)
	{
		System.out.println("YES");
	}
	else
	{
		System.out.println("NO");
	}
	}
}


import java.util.*;
public class check_the_string {
	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String s=in.next();
	char arr[]=s.toCharArray();
	ArrayList<Character> list = new ArrayList<>();
	Set<Integer> set = new HashSet<>();
	for(char k:arr)
	{
		list.add(k);
	}
	Arrays.sort(arr);
	String str="";
	for(char k:arr)
	{
		str=str+k;
	}
	if(str.compareTo(s)!=0)
	{
		System.out.println("NO");
		System.exit(0);
	}
	if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
	{
		System.out.println("NO");
		System.exit(0);
	}
	list.clear();
	char c='a';
	int cnt=0;
	for(int i=0;i<s.length();i++)
	{
		if(s.charAt(i)==c)
		{
			cnt++;
		}
		else
		{
			set.add(cnt);
			c=(char) ((char)c+1);
		}
	}
	if(set.size()<3)
	{
		System.out.println("YES");
	}
	else
	{
		System.out.println("NO");
	}
	}
}


import java.util.*;
public class check_the_string {
	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String s=in.next();
	char arr[]=s.toCharArray();
	ArrayList<Character> list = new ArrayList<>();
	Set<Integer> set = new HashSet<>();
	for(char k:arr)
	{
		list.add(k);
	}
	Arrays.sort(arr);
	String str="";
	for(char k:arr)
	{
		str=str+k;
	}
	if(str.compareTo(s)!=0)
	{
		System.out.println("NO");
		System.exit(0);
	}
	if(list.contains('a')!=true || list.contains('b')!=true)
	{
		System.out.println("NO");
		System.exit(0);
	}
	list.clear();
	char c='a';
	int cnt=0;
	for(int i=0;i<s.length();i++)
	{
		if(s.charAt(i)==c)
		{
			cnt++;
		}
		else
		{
			set.add(cnt);
			c=(char) ((char)c+1);
		}
	}
	if(set.size()<3)
	{
		System.out.println("YES");
	}
	else
	{
		System.out.println("NO");
	}
	}
}


import java.util.*;
public class check_the_string {
	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String s=in.next();
	char arr[]=s.toCharArray();
	ArrayList<Character> list = new ArrayList<>();
	Set<Long> set = new HashSet<>();
	for(char k:arr)
	{
		list.add(k);
	}
	Arrays.sort(arr);
	String str="";
	for(char k:arr)
	{
		str=str+k;
	}
	if(str.compareToIgnoreCase(s)!=0)
	{
		System.out.println("NO");
		System.exit(0);
	}
	if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
	{
		System.out.println("NO");
		System.exit(0);
	}
	list.clear();
	char c='a';
	long cnt=0;
	for(int i=0;i<s.length();i++)
	{
		if(s.charAt(i)==c)
		{
			cnt++;
		}
		else
		{
			set.add(cnt);
			c=(char) ((char)c+1);
		}
	}
	if(set.size()<2)
	{
		System.out.println("YES");
	}
	else
	{
		System.out.println("NO");
	}
	}
}

Click to see test details


import java.util.*;
public class check_the_string {
	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String s=in.next();
	char arr[]=s.toCharArray();
	ArrayList<Character> list = new ArrayList<>();
	Set<Long> set = new HashSet<>();
	for(char k:arr)
	{
		list.add(k);
	}
	Arrays.sort(arr);
	String str="";
	for(char k:arr)
	{
		str=str+k;
	}
	if(str.compareTo(s)!=0)
	{
		System.out.println("NO");
		System.exit(0);
	}
	if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
	{
		System.out.println("NO");
		System.exit(0);
	}
	list.clear();
	char c='a';
	long cnt=0;
	for(int i=0;i<s.length();i++)
	{
		if(s.charAt(i)==c)
		{
			cnt++;
		}
		else
		{
			set.add(cnt);
			c=(char) ((char)c+1);
		}
	}
	if(set.size()<3)
	{
		System.out.println("YES");
	}
	else
	{
		System.out.println("NO");
	}
	}
}


import java.util.*;
public class check_the_string {
	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String s=in.next();
	if(s.length()>100)
	{
	    System.out.println("NO");
	    System.exit(0);
	}
	char arr[]=s.toCharArray();
	ArrayList<Character> list = new ArrayList<>();
	Set<Integer> set = new HashSet<>();
	for(char k:arr)
	{
		list.add(k);
	}
	Arrays.sort(arr);
	String str="";
	for(char k:arr)
	{
		str=str+k;
	}
	if(str.compareTo(s)!=0)
	{
		System.out.println("NO");
		System.exit(0);
	}
	if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
	{
		System.out.println("NO");
		System.exit(0);
	}
	list.clear();
	char c='a';
	int cnt=0;
	for(int i=0;i<s.length();i++)
	{
		if(s.charAt(i)==c)
		{
			cnt++;
		}
		else
		{
			set.add(cnt);
			c=(char) ((char)c+1);
		}
	}
	if(set.size()<3)
	{
		System.out.println("YES");
	}
	else
	{
		System.out.println("NO");
	}
	}
}


import java.util.*;
public class equal_strings {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String s=in.next();
		char arr[]=s.toCharArray();
		Arrays.parallelSort(arr);
		int c=0,cnt=0,count=0;
		String str="";
		ArrayList<Character> list = new ArrayList<>();
		for(int i=0;i<arr.length;i++)
		{
			str=str+arr[i];
			list.add(arr[i]);
		}
		if(str.compareTo(s)!=0)
		{
			System.out.println("NO");
		}
		else if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
		{
			System.out.println("NO");
		}
		else
		{
			for(int i=0;i<s.length();i++)
			{
				if(s.charAt(i)=='a')
				{
					c++;
				}
				else if(s.charAt(i)=='b')
				{
					cnt++;
				}
				else
				{
					count++;
				}
			}
			if(c==count)
			{
				System.out.println("YES");
			}
			else if(cnt==count)
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
	}
}


import java.util.*;
public class equal_strings {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String s=in.next();
		char arr[]=s.toCharArray();
		Arrays.parallelSort(arr);
		int c=0,cnt=0,count=0;
		String str="";
		ArrayList<Character> list = new ArrayList<>();
		for(int i=0;i<arr.length;i++)
		{
			str=str+arr[i];
			list.add(arr[i]);
		}
		if(str.compareTo(s)!=0)
		{
			System.out.println("NO");
		}
		else if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
		{
			System.out.println("NO");
		}
		else
		{
			for(int i=0;i<s.length();i++)
			{
				if(s.charAt(i)=='a')
				{
					c++;
				}
				else if(s.charAt(i)=='b')
				{
					cnt++;
				}
				else
				{
					count++;
				}
			}
			if(c==count && c!=0)
			{
				System.out.println("YES");
			}
			else if(cnt==count && cnt!=0)
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
	}
}


import java.util.*;
public class equal_strings {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String s=in.next();
		char arr[]=s.toCharArray();
		Arrays.parallelSort(arr);
		int c=0,cnt=0,count=0;
		String str="";
		ArrayList<Character> list = new ArrayList<>();
		for(int i=0;i<arr.length;i++)
		{
			str=str+arr[i];
			list.add(arr[i]);
		}
		if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
		{
			System.out.println("NO");
		}
		else
		{
			for(int i=0;i<s.length();i++)
			{
				if(s.charAt(i)=='a')
				{
					c++;
				}
				else if(s.charAt(i)=='b')
				{
					cnt++;
				}
				else
				{
					count++;
				}
			}
			if(c==count)
			{
				System.out.println("YES");
			}
			else if(cnt==count)
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
	}
}


import java.util.*;
public class check_the_string {
	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String s=in.next();
	char arr[]=s.toCharArray();
	ArrayList<Character> list = new ArrayList<>();
	Set<Long> set = new HashSet<>();
	for(char k:arr)
	{
		list.add(k);
	}
	Arrays.sort(arr);
	String str="";
	for(char k:arr)
	{
		str=str+k;
	}
	if(str.compareToIgnoreCase(s)!=0)
	{
		System.out.println("NO");
		System.exit(0);
	}
	if(list.contains('a')!=true || list.contains('b')!=true || list.contains('c')!=true)
	{
		System.out.println("NO");
		System.exit(0);
	}
	list.clear();
	char c='a';
	long cnt=0;
	for(int i=0;i<s.length();i++)
	{
		if(s.charAt(i)==c)
		{
			cnt++;
		}
		else
		{
			set.add(cnt);
			c=(char) ((char)c+1);
		}
	}
	if(set.size()<2)
	{
		System.out.println("YES");
	}
	else
	{
		System.out.println("NO");
	}
	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main

{
    static Scanner in = new Scanner(System.in);

    public static void solve()
    {
        String s =in.nextLine();

           if(s.matches("^a+b+c+$"))
           {
               int a =0,b=0,c=0;
               for(int i=0;i<s.length();i++)
               {

                   if(s.charAt(i)=='a')
                   a++;
                   else if(s.charAt(i)=='b')
                   {
                       b++;
                   }
                   else
                   {
                       c++;
                   }
               }

               if(a==c || b==c)
               {
                   System.out.println("YES");
               }
               else
               {
                   System.out.println("NO");
               }
           }

           else
           {
               System.out.println("NO");
           }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		int t=1;
		//in.nextLine();

		while(t>0)
		{

		    solve();
		    t--;
		}

	//	System.out.println(x);
	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main

{
    static Scanner in = new Scanner(System.in);

    public static void solve()
    {
        String s =in.nextLine();

           if(s.matches("^a*b*c$"))
           {
               int a =0,b=0,c=0;
               for(int i=0;i<s.length();i++)
               {

                   if(s.charAt(i)=='a')
                   a++;
                   else if(s.charAt(i)=='b')
                   {
                       b++;
                   }
                   else
                   {
                       c++;
                   }
               }

               if(a==c || b==c)
               {
                   System.out.println("YES");
               }
               else
               {
                   System.out.println("NO");
               }
           }

           else
           {
               System.out.println("NO");
           }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		int t=1;
		//in.nextLine();

		while(t>0)
		{

		    solve();
		    t--;
		}

	//	System.out.println(x);
	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main

{
    static Scanner in = new Scanner(System.in);

    public static void solve()
    {
        String s =in.nextLine();

           if(s.matches("^a*b*c*$"))
           System.out.println("YES");
           else
           {
               System.out.println("NO");
           }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		int t=1;
		//in.nextLine();

		while(t>0)
		{

		    solve();
		    t--;
		}

	//	System.out.println(x);
	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main

{
    static Scanner in = new Scanner(System.in);

    public static void solve()
    {
        String s =in.nextLine();

           if(s.matches("^a+b*c+$"))
           {
               int a =0,b=0,c=0;
               for(int i=0;i<s.length();i++)
               {

                   if(s.charAt(i)=='a')
                   a++;
                   else if(s.charAt(i)=='b')
                   {
                       b++;
                   }
                   else
                   {
                       c++;
                   }
               }

               if(a==c || b==c)
               {
                   System.out.println("YES");
               }
               else
               {
                   System.out.println("NO");
               }
           }

           else
           {
               System.out.println("NO");
           }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		int t=1;
		//in.nextLine();

		while(t>0)
		{

		    solve();
		    t--;
		}

	//	System.out.println(x);
	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main

{
    static Scanner in = new Scanner(System.in);

    public static void solve()
    {
        String s =in.nextLine();

           if(s.matches("^a*b*c+$"))
           {
               int a =0,b=0,c=0;
               for(int i=0;i<s.length();i++)
               {

                   if(s.charAt(i)=='a')
                   a++;
                   else if(s.charAt(i)=='b')
                   {
                       b++;
                   }
                   else
                   {
                       c++;
                   }
               }

               if(a==c || b==c)
               {
                   System.out.println("YES");
               }
               else
               {
                   System.out.println("NO");
               }
           }

           else
           {
               System.out.println("NO");
           }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		int t=1;
		//in.nextLine();

		while(t>0)
		{

		    solve();
		    t--;
		}

	//	System.out.println(x);
	}
}


import java.util.Scanner;

public class Solve {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        String s = in.next();
        int[] arr = {0, 0, 0};
        for (int i = 0; i < s.length(); i++) {
            arr[s.charAt(i) - 'a']++;
        }
        System.out.println((arr[2] == arr[1] || arr[2] == arr[0])&&(s.indexOf("a")>=0 && s.indexOf("b")>=0 && s.indexOf("c")>=0) && s.lastIndexOf("a") < s.indexOf("b") && s.lastIndexOf("b") < s.indexOf("c") ? "YES" : "NO");
    }
}


import java.util.Scanner;

public class CF_960A {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int a = 0, b = 0, c = 0;
        int count1 = 0, count2 = 0, count3 = 0;
        int c1 = 0, c2 = 0, c3 = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'a') {
                c1 = i;
                break;
            }
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'b') {
                c2 = i;
                break;
            }
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'c') {
                c3 = i;
                break;
            }
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'a') {
                count1++;
                a = i;
            } else if (s.charAt(i) == 'b') {
                b = i;
                count2++;
            } else {
                count3++;
                c = i;
            }
        }
//        System.out.println(a + " " + b + " " + c);
        if (a <= c2 && b <= c3 && (count1 == count3 || count2 == count3) && count1 != 0 && count2 != 0 && count3 != 0) {
            System.out.println("YES");
        } else
            System.out.println("NO");
    }
}


import java.util.Scanner;

public class CF_960A {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int a = 0, b = 0, c = 0;
        int count1 = 0, count2 = 0, count3 = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'a') {
                count1++;
                a = i;
            } else if (s.charAt(i) == 'b') {
                b = i;
                count2++;
            } else {
                count3++;
                c = i;
            }
        }
//        System.out.println(a + " " + b + " " + c);
        if (a < b && b < c && (count1 == count3 || count2 == count3)) {
            System.out.println("YES");
        } else
            System.out.println("NO");
    }
}


import java.util.Scanner;

public class CF_960A {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int a = 0, b = 0, c = 0;
        int count1 = 0, count2 = 0, count3 = 0;
        int c1 = 0, c2 = 0, c3 = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'a') {
                c1 = i;
                break;
            }
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'b') {
                c2 = i;
                break;
            }
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'c') {
                c3 = i;
                break;
            }
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'a') {
                count1++;
                a = i;
            } else if (s.charAt(i) == 'b') {
                b = i;
                count2++;
            } else {
                count3++;
                c = i;
            }
        }
//        System.out.println(a + " " + b + " " + c);
        if (a <= c2 && b <= c3 && (count1 == count3 || count2 == count3)) {
            System.out.println("YES");
        } else
            System.out.println("NO");
    }
}


import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class solution {
    public static void merge(int arr[], int l, int m, int r) {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int[n1];
        int R[] = new int[n2];

        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    public static void sort(int arr[], int l, int r) {
        if (l < r) {
            // Find the middle point
            int m = (l + r) / 2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        } else return gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        long v = a * b;
        long u = gcd(a, b);
        return v / u;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        char ar[] = s.toCharArray();
        Arrays.sort(ar);
        String t = new String(ar);
        int a = 0;
        int b = 0;
        int c = 0;
        for(int i=0;i<t.length();i++){
            if(t.charAt(i) == 'a')a++;
            else if(t.charAt(i) == 'b')b++;
            else c++;
        }
        if(t.equals(s) == false){
            System.out.println("NO");
        }
        else if(a == 0 || b == 0 || (c!=a && c!=b)){
            System.out.println("NO");
        }
        else{
            System.out.println("YES");
        }
    }

    static class sort implements Comparator<ArrayList<Integer>> {

        @Override
        public int compare(ArrayList<Integer> o1, ArrayList<Integer> o2) {
            int c = o1.get(0).compareTo(o2.get(0));
            return c;
        }

    }
}


import java.util.*;
import java.io.*;
//Captain on duty!

public class Main {

    static void compare(Main.pair a[], int n) {

        Arrays.sort(a, new Comparator<Main.pair>() {
            @Override
            public int compare(Main.pair p1, Main.pair p2) {
                return p1.f - p2.f;
            }
        });
    }

    public static boolean checkPalindrome(String s) {
        // reverse the given String
        String reverse = new StringBuffer(s).reverse().toString();

        // check whether the string is palindrome or not
        if (s.equals(reverse))
            return true;

        else
            return false;
    }

    static class pair implements Comparable {
        int f;
        int s;

        pair(int fi, int se) {
            f = fi;
            s = se;
        }

        public int compareTo(Object o)//desc order
        {
            pair pr = (pair) o;
            if (s > pr.s)
                return -1;
            if (s == pr.s) {
                if (f > pr.f)
                    return 1;
                else
                    return -1;
            } else
                return 1;
        }

        public boolean equals(Object o) {
            pair ob = (pair) o;
            if (o != null) {
                if ((ob.f == this.f) && (ob.s == this.s))
                    return true;
            }
            return false;
        }

        public int hashCode() {
            return (this.f + " " + this.s).hashCode();
        }

    }

    public static boolean palin(int l, int r, char[] c) {
        while (l <= r) {
            if (c[l] != c[r]) return false;
            l++;
            r--;
        }
        return true;
    }

    public static long gcd(long a, long b) {
        if (b == 0)
            return a;

        return gcd(b, a % b);
    }
    public static long lcm(long a, long b)
    {
        return (a*b)/gcd(a, b);
    }

    public static long hcf(long a, long b) {
        long t;
        while (b != 0) {
            t = b;
            b = a % b;
            a = t;
        }
        return a;
    }

    public static boolean isPrime(long n) {
        if (n <= 1)
            return false;

        // Check from 2 to n-1
        for (int i = 2; i <= Math.sqrt(n) + 1; i++)
            if (n % i == 0)
                return false;

        return true;
    }

    public static String reverse(String str) {
        String str1 = "";
        for (int i = 0; i < str.length(); i++) {
            str1 = str1 + str.charAt(str.length() - i - 1);
        }
        return str1;
    }

    public static double fact(long a) {
        if (a == 1)
            return 1;
        else
            return a * fact(a - 1);
    }

    static boolean isPerfectSquare(double x)
    {

        // Find floating point value of
        // square root of x.
        double sr = Math.sqrt(x);

        // If square root is an integer
        return ((sr - Math.floor(sr)) == 0);
    }

    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

    }

    public static void main(String[] args) {
        FastReader s = new FastReader();
        //System.out.println("Forces Babyy!!");

          String str=s.next();
          int f=0;
          for(int i=0;i<str.length()-1;i++)
          {
              if((str.charAt(i+1)-'a')-(str.charAt(i)-'a')!=1 && (str.charAt(i+1)-'a')-(str.charAt(i)-'a')!=0)
              {
                  f=1;
                  break;
              }
          }
          if(f==1)
              System.out.println("NO");
          else
          {
              //System.out.println("YES");
              if(str.charAt(0)!='a')
                  System.out.println("NO");
              else
              {
                  int al=0;
                  int bl=0;
                  int cl=0;
                  for(int i=0;i<str.length();i++)
                  {
                      if(str.charAt(i)=='a')
                          al++;
                      else if(str.charAt(i)=='b')
                          bl++;
                      else
                          cl++;

                  }
                  if((al==0 || bl==0 || cl==0))
                      System.out.println("NO");
                  else if(cl==al || cl==bl)
                      System.out.println("YES");
                  else
                      System.out.println("NO");
              }
          }

    }

}


import java.util.*;
import java.io.*;
//Captain on duty!

public class Main {

    static void compare(Main.pair a[], int n) {

        Arrays.sort(a, new Comparator<Main.pair>() {
            @Override
            public int compare(Main.pair p1, Main.pair p2) {
                return p1.f - p2.f;
            }
        });
    }

    public static boolean checkPalindrome(String s) {
        // reverse the given String
        String reverse = new StringBuffer(s).reverse().toString();

        // check whether the string is palindrome or not
        if (s.equals(reverse))
            return true;

        else
            return false;
    }

    static class pair implements Comparable {
        int f;
        int s;

        pair(int fi, int se) {
            f = fi;
            s = se;
        }

        public int compareTo(Object o)//desc order
        {
            pair pr = (pair) o;
            if (s > pr.s)
                return -1;
            if (s == pr.s) {
                if (f > pr.f)
                    return 1;
                else
                    return -1;
            } else
                return 1;
        }

        public boolean equals(Object o) {
            pair ob = (pair) o;
            if (o != null) {
                if ((ob.f == this.f) && (ob.s == this.s))
                    return true;
            }
            return false;
        }

        public int hashCode() {
            return (this.f + " " + this.s).hashCode();
        }

    }

    public static boolean palin(int l, int r, char[] c) {
        while (l <= r) {
            if (c[l] != c[r]) return false;
            l++;
            r--;
        }
        return true;
    }

    public static long gcd(long a, long b) {
        if (b == 0)
            return a;

        return gcd(b, a % b);
    }
    public static long lcm(long a, long b)
    {
        return (a*b)/gcd(a, b);
    }

    public static long hcf(long a, long b) {
        long t;
        while (b != 0) {
            t = b;
            b = a % b;
            a = t;
        }
        return a;
    }

    public static boolean isPrime(long n) {
        if (n <= 1)
            return false;

        // Check from 2 to n-1
        for (int i = 2; i <= Math.sqrt(n) + 1; i++)
            if (n % i == 0)
                return false;

        return true;
    }

    public static String reverse(String str) {
        String str1 = "";
        for (int i = 0; i < str.length(); i++) {
            str1 = str1 + str.charAt(str.length() - i - 1);
        }
        return str1;
    }

    public static double fact(long a) {
        if (a == 1)
            return 1;
        else
            return a * fact(a - 1);
    }

    static boolean isPerfectSquare(double x)
    {

        // Find floating point value of
        // square root of x.
        double sr = Math.sqrt(x);

        // If square root is an integer
        return ((sr - Math.floor(sr)) == 0);
    }

    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

    }

    public static void main(String[] args) {
        FastReader s = new FastReader();
        //System.out.println("Forces Babyy!!");

          String str=s.next();
          int f=0;
          for(int i=0;i<str.length()-1;i++)
          {
              if((str.charAt(i+1)-'a')-(str.charAt(i)-'a')<0)
              {
                  f=1;
                  break;
              }
          }
          if(f==1)
              System.out.println("NO");
          else
          {
              //System.out.println("YES");
              if(str.charAt(0)!='a')
                  System.out.println("NO");
              else
              {
                  int al=0;
                  int bl=0;
                  int cl=0;
                  for(int i=0;i<str.length();i++)
                  {
                      if(str.charAt(i)=='a')
                          al++;
                      else if(str.charAt(i)=='b')
                          bl++;
                      else
                          cl++;

                  }
                  if(cl==al || cl==bl)
                      System.out.println("YES");
                  else
                      System.out.println("NO");
              }
          }

    }

}


import java.util.*;
import java.io.*;
//Captain on duty!

public class Main {

    static void compare(Main.pair a[], int n) {

        Arrays.sort(a, new Comparator<Main.pair>() {
            @Override
            public int compare(Main.pair p1, Main.pair p2) {
                return p1.f - p2.f;
            }
        });
    }

    public static boolean checkPalindrome(String s) {
        // reverse the given String
        String reverse = new StringBuffer(s).reverse().toString();

        // check whether the string is palindrome or not
        if (s.equals(reverse))
            return true;

        else
            return false;
    }

    static class pair implements Comparable {
        int f;
        int s;

        pair(int fi, int se) {
            f = fi;
            s = se;
        }

        public int compareTo(Object o)//desc order
        {
            pair pr = (pair) o;
            if (s > pr.s)
                return -1;
            if (s == pr.s) {
                if (f > pr.f)
                    return 1;
                else
                    return -1;
            } else
                return 1;
        }

        public boolean equals(Object o) {
            pair ob = (pair) o;
            if (o != null) {
                if ((ob.f == this.f) && (ob.s == this.s))
                    return true;
            }
            return false;
        }

        public int hashCode() {
            return (this.f + " " + this.s).hashCode();
        }

    }

    public static boolean palin(int l, int r, char[] c) {
        while (l <= r) {
            if (c[l] != c[r]) return false;
            l++;
            r--;
        }
        return true;
    }

    public static long gcd(long a, long b) {
        if (b == 0)
            return a;

        return gcd(b, a % b);
    }
    public static long lcm(long a, long b)
    {
        return (a*b)/gcd(a, b);
    }

    public static long hcf(long a, long b) {
        long t;
        while (b != 0) {
            t = b;
            b = a % b;
            a = t;
        }
        return a;
    }

    public static boolean isPrime(long n) {
        if (n <= 1)
            return false;

        // Check from 2 to n-1
        for (int i = 2; i <= Math.sqrt(n) + 1; i++)
            if (n % i == 0)
                return false;

        return true;
    }

    public static String reverse(String str) {
        String str1 = "";
        for (int i = 0; i < str.length(); i++) {
            str1 = str1 + str.charAt(str.length() - i - 1);
        }
        return str1;
    }

    public static double fact(long a) {
        if (a == 1)
            return 1;
        else
            return a * fact(a - 1);
    }

    static boolean isPerfectSquare(double x)
    {

        // Find floating point value of
        // square root of x.
        double sr = Math.sqrt(x);

        // If square root is an integer
        return ((sr - Math.floor(sr)) == 0);
    }

    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

    }

    public static void main(String[] args) {
        FastReader s = new FastReader();
        //System.out.println("Forces Babyy!!");

          String str=s.next();
          int f=0;
          for(int i=0;i<str.length()-1;i++)
          {
              if((str.charAt(i+1)-'a')-(str.charAt(i)-'a')!=1 && (str.charAt(i+1)-'a')-(str.charAt(i)-'a')!=0)
              {
                  f=1;
                  break;
              }
          }
          if(f==1)
              System.out.println("NO");
          else
          {
              //System.out.println("YES");
              if(str.charAt(0)!='a')
                  System.out.println("NO");
              else
              {
                  int al=0;
                  int bl=0;
                  int cl=0;
                  for(int i=0;i<str.length();i++)
                  {
                      if(str.charAt(i)=='a')
                          al++;
                      else if(str.charAt(i)=='b')
                          bl++;
                      else
                          cl++;

                  }
                  if(cl==al || cl==bl || (al==0 && bl==0 && cl==0))
                      System.out.println("YES");
                  else
                      System.out.println("NO");
              }
          }

    }

}


import java.io.*;
import java.util.*;
public class Main {
    final static long mod = 1000000007;

    static void debug(Object...args)
    {
        System.out.println(Arrays.deepToString(args));
    }

    public static void main(String[] args) throws Exception {
        InputReader sc = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        Random gen = new Random();
        int test = 1;//sc.nextInt();
        for(int tt=1; tt<=test;tt++) {

            String s = sc.nextLine();
            char [] ar  = s.toCharArray();
            StringBuffer sb = new StringBuffer();
            for(int i=0;i<s.length()-1;i++)
            {
                if(ar[i]!=ar[i+1])
                    sb.append(ar[i]);
            }
            sb.append(ar[ar.length-1]);
            String str = sb.toString();

                int a = 0;
                int b = 0;
                int c = 0;
            for (char ch : str.toCharArray()) {
                if (ch == 'a')
                    a++;
                else if (ch == 'b')
                    b++;
                else
                    c++;
            }
                if(str.equals("abc")) {
                    if (c == a || c == b || (c == 0))
                        pw.println("YES");
                    else
                        pw.println("NO");
                }
                else
                {
                    if(a==0 && str.equals("bc") && b==c)
                    {
                        pw.println("YES");
                    }
                    else if(b==0 && str.equals("ac") && a==c)
                        pw.println("YES");
                    else if(c==0)
                        pw.println("YES");
                    else
                        pw.println("NO");

                }

        }
        pw.flush();
        pw.close();

    }

    static class Data implements Comparable<Data>{
        long x;
        long y;

        public Data (long m, long n) {
            x = m;
            y = n;
        }
        @Override
        public int compareTo(Data o) {
            return (int) (x - o.x);
        }
    }

    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream st) {
            this.stream = st;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int [] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }
        public long[] nextLongArray(int n) {
            long [] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

        public static int[] shuffle(int[] a, Random gen)
        { for(int i = 0, n = a.length;i < n;i++)
        { int ind = gen.nextInt(n-i)+i;
            int d = a[i];
            a[i] = a[ind];
            a[ind] = d;

        }
            return a;
        }
        public static char[] shuffle(char[] a, Random gen)
        { for(int i = 0, n = a.length;i < n;i++)
        { int ind = gen.nextInt(n-i)+i;
            char d = a[i];
            a[i] = a[ind];
            a[ind] = d;

        }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }

}


import java.io.*;
import java.util.*;
public class Main {
    final static long mod = 1000000007;

    static void debug(Object...args)
    {
        System.out.println(Arrays.deepToString(args));
    }

    public static void main(String[] args) throws Exception {
        InputReader sc = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        Random gen = new Random();
        int test = 1;//sc.nextInt();
        for(int tt=1; tt<=test;tt++) {

            String s = sc.nextLine();
            char [] ar  = s.toCharArray();
            int a = 0;
            int b = 0;
            int c = 0;
            for (char value : ar) {

                if (value == 'a')
                    a++;
                else if (value == 'b')
                    b++;
                else if (value == 'c')
                    c++;
            }

                if(c==a || c==b) {
                    if(s.matches("a+b+c+"))
                        pw.println("YES");
                    else
                        pw.println("NO");

                }
                else
                    pw.println("NO");

        }
        pw.flush();
        pw.close();

    }

    static class Data implements Comparable<Data>{
        long x;
        long y;

        public Data (long m, long n) {
            x = m;
            y = n;
        }
        @Override
        public int compareTo(Data o) {
            return (int) (x - o.x);
        }
    }

    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream st) {
            this.stream = st;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int [] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }
        public long[] nextLongArray(int n) {
            long [] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

        public static int[] shuffle(int[] a, Random gen)
        { for(int i = 0, n = a.length;i < n;i++)
        { int ind = gen.nextInt(n-i)+i;
            int d = a[i];
            a[i] = a[ind];
            a[ind] = d;

        }
            return a;
        }
        public static char[] shuffle(char[] a, Random gen)
        { for(int i = 0, n = a.length;i < n;i++)
        { int ind = gen.nextInt(n-i)+i;
            char d = a[i];
            a[i] = a[ind];
            a[ind] = d;

        }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }

}


import java.io.*;
import java.util.*;
public class Main {
    final static long mod = 1000000007;

    static void debug(Object...args)
    {
        System.out.println(Arrays.deepToString(args));
    }

    public static void main(String[] args) throws Exception {
        InputReader sc = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        Random gen = new Random();
        int test = 1;//sc.nextInt();
        for(int tt=1; tt<=test;tt++) {

            String s = sc.nextLine();
            char [] ar  = s.toCharArray();
            int a = 0;
            int b = 0;
            int c = 0;
            for (char value : ar) {

                if (value == 'a')
                    a++;
                else if (value == 'b')
                    b++;
                else if (value == 'c')
                    c++;
            }

                if(c==a || c==b &&  (s.matches("a+b+c+")))
                    pw.println("YES");
                else
                    pw.println("NO");

        }
        pw.flush();
        pw.close();

    }

    static class Data implements Comparable<Data>{
        long x;
        long y;

        public Data (long m, long n) {
            x = m;
            y = n;
        }
        @Override
        public int compareTo(Data o) {
            return (int) (x - o.x);
        }
    }

    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream st) {
            this.stream = st;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int [] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }
        public long[] nextLongArray(int n) {
            long [] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

        public static int[] shuffle(int[] a, Random gen)
        { for(int i = 0, n = a.length;i < n;i++)
        { int ind = gen.nextInt(n-i)+i;
            int d = a[i];
            a[i] = a[ind];
            a[ind] = d;

        }
            return a;
        }
        public static char[] shuffle(char[] a, Random gen)
        { for(int i = 0, n = a.length;i < n;i++)
        { int ind = gen.nextInt(n-i)+i;
            char d = a[i];
            a[i] = a[ind];
            a[ind] = d;

        }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }

}


#include <bits/stdc++.h>

using namespace std;

int a, b, c;
string s, t;

int main(){
      cin >> s;
      t = s;
      sort(t.begin(), t.end());
      if(t != s)
            return cout << "NO", 0;
      for(int i = 0;i < s.size(); i++){
             if(s[i] == 'a')
                   a++;
             else if(s[i] == 'b')
                    b++;
             else
                    c++;
      }
      if(a == c or b == c)
            cout << "YES";
      else
            cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

int a, b c;
string s, t;

int main(){
      cin >> s;
      t = s;
      sort(t.begin(), t.end());
      if(t != s)
            return cout << "NO", 0;
      for(int i = 0;i < s.size(); i++){
             if(s[i] == 'a')
                   a++;
             else if(s[i] == 'b')
                    b++;
             else
                    c++;
      }
      if(a == c or b == c)
            cout << "YES";
      else
            cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

int a, b, c;
string s, t;

int main(){
      cin >> s;
      t = s;

      for(int i = 0;i < s.size(); i++){
             if(s[i] == 'a')
                   a++;
             else if(s[i] == 'b')
                    b++;
             else
                    c++;
      }
      sort(t.begin(), t.end());
      if(a == 0 or b == 0)
           return cout << "NO", 0;
      if(t != s)
            return cout << "NO", 0;
      if(a == c or (b == c and b != 0))
            cout << "YES";
      else
            cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

int a, b, c;
string s, t;

int main(){
      cin >> s;
      t = s;
      sort(t.begin(), t.end());
      if(t != s)
            return cout << "NO", 0;
      for(i = 0;i < s.size(); i++){
             if(s[i] == 'a')
                   a++;
             else if(s[i] == 'b')
                    b++;
             else
                    c++;
      }
      if(a == c or b == c)
            cout << "YES";
      else
            cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

int a, b, c;
string s, t;

int main(){
      cin >> s;
      t = s;
      sort(t.begin(), t.end());
      if(t != s)
            return cout << "NO", 0;
      for(int i = 0;i < s.size(); i++){
             if(s[i] == 'a')
                   a++;
             else if(s[i] == 'b')
                    b++;
             else
                    c++;
      }
      if(a == c or (b == c and b != 0))
            cout << "YES";
      else
            cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;

int a, b, c;
string s, t;

int main(){
      cin >> s;
      t = s;

      for(int i = 0;i < s.size(); i++){
             if(s[i] == 'a')
                   a++;
             else if(s[i] == 'b')
                    b++;
             else
                    c++;
      }
      sort(t.begin(), t.end());
      if(a == 0)
           return cout << "NO", 0;
      if(t != s)
            return cout << "NO", 0;
      if(a == c or (b == c and b != 0))
            cout << "YES";
      else
            cout << "NO";
}


#include<bits/stdc++.h>
using namespace std;
#define  fast()      ios :: sync_with_stdio(false); cin.tie(0);
#define  ll             long long int
#define  ull            unsigned long long int
#define     sz(x)       (int)x.size()
#define  ld             long double
#define  vi             vector<int>
#define vl              vector<long long>
#define vc              vector<char>
#define vs              vector<string>
#define vp              vector< pair<ll,ll> >
#define sl              set<long long>
#define sc              set<char>
#define sts             stack<string>
#define max_3(a,b,c)    max(a, max(b,c))
#define max_4(a,b,c,d)  max(a,max(b,max(c,d)))
#define min_3(a,b,c)    min(a, min(b,c))
#define min_4(a,b,c,d)  min(a,min(b,min(c,d)))
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define pi              2*acos(0.0)
#define N               100006
#define in              1234567890;
int main()
{
    fast()
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    ll n,i,t,j=0,x=5000000,y=5000000,k,c=0,a=0,b=0,z=5000000;
    string s;
    vl v;
    cin>>s;
    sc p;
    for(i=0; i<s.size(); i++)
    {
        p.insert(s[i]);
        if(s[i]=='a') a++;
        if(s[i]=='b') b++;
        if(s[i]=='c') c++;
    }
    for(i=0; i<s.size(); i++)
    {
        if(s[i]=='a')
        {
            x=i;
           // break;
        }
    }
    for(i=x+1; i<s.size(); i++)
    {
        if(s[i]=='b')
        {
            y=i;
            //break;
        }
    }
    for(i=y+1; i<s.size(); i++)
    {
        if(s[i]=='c')
        {
            z=i;
            //break;
        }
    }
    if(x<y&&y<z&&p.size()==3&&(c==a||c==b))
        cout<<"YES";
    else
        cout<<"NO";
}


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

int main()
{
	int n,a0=0,a1=0,a0b0=0,a1b0=0,ans=0;cin>>n;
	string a,b;cin>>a>>b;
	for(int i=0;i<n;i++)
	{
		if(b[i]=='0')
		{
			if(a[i]=='0')a0b0++,a0++;
			else a1b0++,a1++;
		}
		else
		{
			if(a[i]=='0')a0++;
			else a1++;
		}
	}
	ans=a0b0*a1+a1b0*a0-a0b0*a1b0;
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int K=100005;
int a[K],b[K];
char c[K];
int main()
{
	int n;
	long long sum0=0,sum1=0,sum2000=0,sum2001=0,sum=0;
	scanf("%d",&n);
	int cnt=0;
	for(int i=0;i<n;i++)cnt++;
	scanf("%s",c+1);
	for(int i=1;i<=n;i++)
		a[i]=c[i]-'0';
	for(int i=1;i<=n;i++)
		b[i]=c[i]-'0';
	for(int i=1;i<=n;i++)
	{
		if(a[i])
			sum1++;
		else
			sum0++;
		if(!b[i])
		{
			if(a[i])
				sum2000++;
			else
				sum2001++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(b[i])
			continue;
		if(a[i])
			sum+=sum0;
		else
			sum+=sum1;
	}

	cout<<sum-sum2000*sum2001-2<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int K=100005;
int a[K],b[K];
char c[K];
int main()
{
	int n;
	long long sum0=0,sum1=0,sum2000=0,sum2001=0,sum=0;
	scanf("%d",&n);
	int cnt=0;
	for(int i=0;i<n;i++)cnt++;
	scanf("%s",c+1);
	for(int i=1;i<=n;i++)
		a[i]=c[i]-'0';
	scanf("%s",c+1);
	for(int i=1;i<=n;i++)
		b[i]=c[i]-'0';
	for(int i=1;i<=n;i++)
	{
		if(a[i])
			sum1++;
		else
			sum0++;
		if(!b[i])
		{
			if(a[i])
				sum2000++;
			else
				sum2001++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(b[i])
			continue;
		if(a[i])
			sum+=sum0;
		else
			sum+=sum1;
	}
	cout<<sum-sum2000*sum2001<<endl;
	return 0;
}


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

typedef long long int intl;
typedef unsigned long long intu;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define Unique(a)     sort(all(a)),a.erase(unique(all(a)),a.end())
#define OUTPUT        freopen("output.txt","w",stdout);
#define FasterIO      ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sfi(x)        scanf("%d", &x)
#define sfii(a, b)    scanf("%d %d", &a, &b)
#define sfl(x)        scanf("%lld", &x)
#define sfu(x)        scanf("%llu", &x)
#define pfi(x)        printf("%d\n", x)
#define pfl(x)        printf("%lld\n", x)
#define pfu(x)        printf("%llu\n", x)
#define fr(i,a,b)     for(intl i = (a) ; i <= (b) ; i++)
#define pb            push_back
#define mp            make_pair
#define ff            first
#define ss            second
#define sf            second.first
#define ssd           second.second
#define all(a)        a.begin(),a.end()
#define mem(a,v)      memset((a), v, sizeof(a))
#define min3(a,b,c)   min(a,min(b,c))
#define max3(a,b,c)   max(a,max(b,c))
#define SQ(a)         ((a)*(a))
#define ABS(x)        ((x)<0?-(x):(x))
#define PI            acos(-1.0)
#define INF           0x3f3f3f3f
#define mod           1000000007
#define mxn           100010

int main()
{
    int n; cin>>n;
    string a, b; cin>>a>>b;

    int ways = 0;
    int zeroZero, zeroOne, oneZero, oneOne;
    zeroZero = zeroOne = oneZero = oneOne = 0;

    for(int i=0; i<n; i++){
        if(a[i] == '0' && b[i] == '0') zeroZero++;
        else if(a[i] == '0' && b[i] == '1') zeroOne++;
        else if(a[i] == '1' && b[i] == '0') oneZero++;
        else oneOne++;
    }

    ways += (zeroZero*oneZero) + (zeroZero*oneOne);
    ways += (zeroOne*oneZero);
    cout<<ways<<endl;
    return 0;
}


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

typedef long long int intl;
typedef unsigned long long intu;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define Unique(a)     sort(all(a)),a.erase(unique(all(a)),a.end())
#define OUTPUT        freopen("output.txt","w",stdout);
#define FasterIO      ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sfi(x)        scanf("%d", &x)
#define sfii(a, b)    scanf("%d %d", &a, &b)
#define sfl(x)        scanf("%lld", &x)
#define sfu(x)        scanf("%llu", &x)
#define pfi(x)        printf("%d\n", x)
#define pfl(x)        printf("%lld\n", x)
#define pfu(x)        printf("%llu\n", x)
#define fr(i,a,b)     for(intl i = (a) ; i <= (b) ; i++)
#define pb            push_back
#define mp            make_pair
#define ff            first
#define ss            second
#define sf            second.first
#define ssd           second.second
#define all(a)        a.begin(),a.end()
#define mem(a,v)      memset((a), v, sizeof(a))
#define min3(a,b,c)   min(a,min(b,c))
#define max3(a,b,c)   max(a,max(b,c))
#define SQ(a)         ((a)*(a))
#define ABS(x)        ((x)<0?-(x):(x))
#define PI            acos(-1.0)
#define INF           0x3f3f3f3f
#define mod           1000000007
#define mxn           100010

int main()
{
    int n; cin>>n;
    string a, b; cin>>a>>b;

    int ways = 0;
    for(int i=0; i<n; i++){
        int x1 = a[i] - '0', y1 = b[i] - '0';
        for(int j=i+1; j<n; j++){
            int x2 = a[j] - '0', y2 = b[j] - '0';
            if(((x1|y1) != (x2|y1)) || ((x1|y2) != (x2|y2))) ways++;
        }
    }
    cout<<ways<<endl;
    return 0;
}


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

typedef long long int intl;
typedef unsigned long long intu;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define Unique(a)     sort(all(a)),a.erase(unique(all(a)),a.end())
#define OUTPUT        freopen("output.txt","w",stdout);
#define FasterIO      ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sfi(x)        scanf("%d", &x)
#define sfii(a, b)    scanf("%d %d", &a, &b)
#define sfl(x)        scanf("%lld", &x)
#define sfu(x)        scanf("%llu", &x)
#define pfi(x)        printf("%d\n", x)
#define pfl(x)        printf("%lld\n", x)
#define pfu(x)        printf("%llu\n", x)
#define fr(i,a,b)     for(intl i = (a) ; i <= (b) ; i++)
#define pb            push_back
#define mp            make_pair
#define ff            first
#define ss            second
#define sf            second.first
#define ssd           second.second
#define all(a)        a.begin(),a.end()
#define mem(a,v)      memset((a), v, sizeof(a))
#define min3(a,b,c)   min(a,min(b,c))
#define max3(a,b,c)   max(a,max(b,c))
#define SQ(a)         ((a)*(a))
#define ABS(x)        ((x)<0?-(x):(x))
#define PI            acos(-1.0)
#define INF           0x3f3f3f3f
#define mod           1000000007
#define mxn           100010

int main()
{
    intl n; cin>>n;
    string a, b; cin>>a>>b;

    intl ways = 0;
    intl zeroZero, zeroOne, oneZero, oneOne;
    zeroZero = zeroOne = oneZero = oneOne = 0;

    for(intl i=0; i<n; i++){
        if(a[i] == '0' && b[i] == '0') zeroZero++;
        else if(a[i] == '0' && b[i] == '1') zeroOne++;
        else if(a[i] == '1' && b[i] == '0') oneZero++;
        else oneOne++;
    }

    ways += (zeroZero*oneZero) + (zeroZero*oneOne);
    ways += (zeroOne*oneZero);
    cout<<ways<<endl;
    return 0;
}


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

typedef long long int intl;
typedef unsigned long long intu;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define Unique(a)     sort(all(a)),a.erase(unique(all(a)),a.end())
#define OUTPUT        freopen("output.txt","w",stdout);
#define FasterIO      ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sfi(x)        scanf("%d", &x)
#define sfii(a, b)    scanf("%d %d", &a, &b)
#define sfl(x)        scanf("%lld", &x)
#define sfu(x)        scanf("%llu", &x)
#define pfi(x)        printf("%d\n", x)
#define pfl(x)        printf("%lld\n", x)
#define pfu(x)        printf("%llu\n", x)
#define fr(i,a,b)     for(intl i = (a) ; i <= (b) ; i++)
#define pb            push_back
#define mp            make_pair
#define ff            first
#define ss            second
#define sf            second.first
#define ssd           second.second
#define all(a)        a.begin(),a.end()
#define mem(a,v)      memset((a), v, sizeof(a))
#define min3(a,b,c)   min(a,min(b,c))
#define max3(a,b,c)   max(a,max(b,c))
#define SQ(a)         ((a)*(a))
#define ABS(x)        ((x)<0?-(x):(x))
#define PI            acos(-1.0)
#define INF           0x3f3f3f3f
#define mod           1000000007
#define mxn           100010

int main()
{
    int n; cin>>n;
    string a, b; cin>>a>>b;

    int ways = 0;
    int zeroZero, zeroOne, oneZero, oneOne;
    zeroZero = zeroOne = oneZero = oneOne = 0;

    for(int i=0; i<n; i++){
        if(a[i] == '0' && b[i] == '0') zeroZero++;
        else if(a[i] == '0' && b[i] == '1') zeroOne++;
        else if(a[i] == '1' && b[i] == '0') oneZero++;
        else oneOne++;
    }

    ways += max(zeroZero, oneZero) + max(zeroZero, oneOne);
    ways += max(zeroOne, oneZero);
    cout<<ways<<endl;
    return 0;
}


// B

#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <chrono>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <list>

using namespace std;
using namespace std::chrono;

typedef pair<int, int> pii;

int n;
string s1;
string s2;
int zero = 0;
int one = 0;
int total = 0;
int a[10001];
int b[10001];
vector<int> oneindex;

int main() {

    cin >> n;
    cin >> s1 >> s2;

    for (int i=0; i<n; i++) {
        if (s1[i] == '1') {
            one++;
        }
        else {
            zero++;
        }
    }

    int x = one*zero;
    int extra = 0;
    for (int i=0; i<n; i++) {
        if (s2[i] == '1') {
            oneindex.push_back(i);
        }
    }
    for (int i=0; i<oneindex.size(); i++) {
        for (int j=i+1; j<oneindex.size(); j++) {
            int a = oneindex[i];
            int b = oneindex[j];
            if (s2[a] == '1' && s2[b] == '1') {
                if ((s1[a] == '1' && s1[b] == '0') || (s1[a] == '0' && s1[b] == '1')) {
                    extra++;
                }
            }
        }
    }

    cout << x-extra;

    return 0;
}


// B

#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <chrono>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <list>

using namespace std;
using namespace std::chrono;

typedef pair<int, int> pii;

int n;
string s1, s2;
int oo = 0;
int zz = 0;
int oz = 0;
int zo = 0;

int main() {

    cin >> n;
    cin >> s1 >> s2;

    for (int i=0; i<n; i++) {
        if (s1[i] == '1' && s2[i] == '1') {
            oo++;
        }
        if (s1[i] == '1' && s2[i] == '0') {
            oz++;
        }
        if (s1[i] == '0' && s2[i] == '1') {
            zo++;
        }
        if (s1[i] == '0' && s2[i] == '0') {
            zz++;
        }
    }
    cout << oo*zz+oz*zo+oz*zz;

    return 0;
}


// B

#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <chrono>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <list>

using namespace std;
using namespace std::chrono;

typedef pair<int, int> pii;

int n;
string s1;
string s2;
int zero = 0;
int one = 0;
int total = 0;
int a[10001];
int b[10001];

int main() {

    cin >> n;
    cin >> s1 >> s2;

    for (int i=0; i<n; i++) {
        if (s1[i] == '1') {
            one++;
        }
        else {
            zero++;
        }
    }

    int total = 0;
    if (one >= 2) {
        total += (one)*(one-1)/2;
    }
    if (zero >= 2) {
        total += (zero)*(zero-1)/2;
    }
    int bigtotal = n*(n-1)/2;

    int extra = 0;

    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            if (s2[i] == '1' && s2[j] == '1') {
                if ((s1[i] == '1' && s1[j] == '0') || (s1[i] == '0' && s1[j] == '1')) {
                    extra++;
                }
            }
        }
    }

    cout << bigtotal-total-extra;

    return 0;
}


// B

#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <chrono>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <list>

using namespace std;
using namespace std::chrono;

typedef pair<int, int> pii;

int n;
string s1, s2;
int oo = 0;
int zz = 0;
int oz = 0;
int zo = 0;

int main() {

    cin >> n;
    cin >> s1 >> s2;

    for (int i=0; i<n; i++) {
        if (s1[i] == '1' && s2[i] == '1') {
            oo++;
        }
        if (s1[i] == '1' && s2[i] == '0') {
            oz++;
        }
        if (s1[i] == '0' && s2[i] == '1') {
            zo++;
        }
        if (s1[i] == '0' && s2[i] == '0') {
            zz++;
        }
    }
    long long x = oo*zz;
    long long y = oz*zo;
    long long z = oz*zz;
    cout << x+y+z << '\n';

    return 0;
}


// B

#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <chrono>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <list>

using namespace std;
using namespace std::chrono;

typedef pair<int, int> pii;

int n;
string s1, s2;
long long oo = 0;
long long zz = 0;
long long oz = 0;
long long zo = 0;

int main() {

    cin >> n;
    cin >> s1 >> s2;

    for (int i=0; i<n; i++) {
        if (s1[i] == '1' && s2[i] == '1') {
            oo++;
        }
        if (s1[i] == '1' && s2[i] == '0') {
            oz++;
        }
        if (s1[i] == '0' && s2[i] == '1') {
            zo++;
        }
        if (s1[i] == '0' && s2[i] == '0') {
            zz++;
        }
    }
    long long x = oo*zz;
    long long y = oz*zo;
    long long z = oz*zz;
    cout << x+y+z << '\n';

    return 0;
}


// B

#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <chrono>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <list>

using namespace std;
using namespace std::chrono;

typedef pair<int, int> pii;

int n;
string s1, s2;
int oo = 0;
int zz = 0;
int oz = 0;
int zo = 0;

int main() {

    cin >> n;
    cin >> s1 >> s2;

    for (int i=0; i<n; i++) {
        if (s1[i] == '1' && s2[i] == '1') {
            oo++;
        }
        if (s1[i] == '1' && s2[i] == '0') {
            oz++;
        }
        if (s1[i] == '0' && s2[i] == '1') {
            zo++;
        }
        if (s1[i] == '0' && s2[i] == '0') {
            zz++;
        }
    }
    cout << (long long)(oo*zz+oz*zo+oz*zz);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define M 1000000007
#define INF 1000000007
typedef pair<lli,lli> ll;
#define mem(a,x) memset(a,x,sizeof(a))
lli n,m,k;
lli vis[100007];
lli dist[507][507];
lli path[207][207];
lli path1[207][207];
vector<int> v2;
vector<lli> v[100007];
lli x,y,c,z;
map<int,int> m1;
struct edge
{
    int a,b,cost;
};
lli c1=0;
lli p=0;
/*void djkstra(int x,vector<ll> v[])
{
    mem(vis,0);
    dist[x]=0;
    s2.insert({0,x});
    while(!s2.empty())
    {
        ll p=*s2.begin();
        s2.erase(s2.begin());
        x=p.second;
        if(vis[x])
        continue;
        vis[x]=1;
        for(int j=0;j<v[x].size();j++)
        {
            if(dist[v[x][j].second]>dist[x]+v[x][j].first)
            {
                dist[v[x][j].second]=dist[x]+v[x][j].first;
                s2.insert({dist[v[x][j].second],v[x][j].second});
                a[v[x][j].second]=x;
            }
        }
    }
}*/
lli parent[100007];
lli find(lli a)
{
    return a==parent[a]?a:parent[a]=find(parent[a]);
}
void dset(lli n)
{
    for(int j=0;j<=n;j++)
    parent[j]=j;
}
void unio(lli a,lli b,lli rank[])
{
    if(rank[find(a)]>rank[find(b)])
    parent[find(b)]=find(a);
    else if(rank[find(b)]>rank[find(a)])
    parent[find(a)]=find(b);
    else
    {
        parent[find(a)]=find(b);
        rank[find(b)]++;
    }
}
bool check(lli a,lli b)
{
    return find(a)==find(b);
}
lli q,u,v1,w,l,t1;
lli a[100007];
lli b[100007];
int re[100007];
int main()
{
    cin>>n;
    string s,s1;
    cin>>s>>s1;
    int c=0;
    int c1=0;
    int c2=0;
    int c3=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='1')
        c+=1;
        if(s[i-1]=='0'&&s1[i-1]=='0')
        c1+=1;
        if(s[i-1]=='1'&&s1[i-1]=='0')
        c2+=1;
        if(s[i-1]=='0'&&s1[i-1]!='0')
        c3+=1;
    }
    lli s2=0;
    s2=c*c1+(c3)*c2;
    cout<<s2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define M 1000000007
#define INF 1000000007
typedef pair<lli,lli> ll;
#define mem(a,x) memset(a,x,sizeof(a))
lli n,m,k;
lli vis[100007];
lli dist[507][507];
lli path[207][207];
lli path1[207][207];
vector<int> v2;
vector<lli> v[100007];
lli x,y,c,z;
map<int,int> m1;
struct edge
{
    int a,b,cost;
};
lli c1=0;
lli p=0;
/*void djkstra(int x,vector<ll> v[])
{
    mem(vis,0);
    dist[x]=0;
    s2.insert({0,x});
    while(!s2.empty())
    {
        ll p=*s2.begin();
        s2.erase(s2.begin());
        x=p.second;
        if(vis[x])
        continue;
        vis[x]=1;
        for(int j=0;j<v[x].size();j++)
        {
            if(dist[v[x][j].second]>dist[x]+v[x][j].first)
            {
                dist[v[x][j].second]=dist[x]+v[x][j].first;
                s2.insert({dist[v[x][j].second],v[x][j].second});
                a[v[x][j].second]=x;
            }
        }
    }
}*/
lli parent[100007];
lli find(lli a)
{
    return a==parent[a]?a:parent[a]=find(parent[a]);
}
void dset(lli n)
{
    for(int j=0;j<=n;j++)
    parent[j]=j;
}
void unio(lli a,lli b,lli rank[])
{
    if(rank[find(a)]>rank[find(b)])
    parent[find(b)]=find(a);
    else if(rank[find(b)]>rank[find(a)])
    parent[find(a)]=find(b);
    else
    {
        parent[find(a)]=find(b);
        rank[find(b)]++;
    }
}
bool check(lli a,lli b)
{
    return find(a)==find(b);
}
lli q,u,v1,w,l,t1;
lli a[100007];
lli b[100007];
int re[100007];
int main()
{
    cin>>n;
    string s,s1;
    cin>>s>>s1;
    int c=0;
    int c1=0;
    int c2=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='1')
        c+=1;
        if(s[i-1]=='0'&&s1[i-1]=='0')
        c1+=1;
        if(s[i-1]=='1'&&s1[i-1]=='0')
        c2+=1;
    }
    lli s2=c*c1+(n-c-c1)*c2;
    cout<<s2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define M 1000000007
#define INF 1000000007
typedef pair<lli,lli> ll;
#define mem(a,x) memset(a,x,sizeof(a))
lli n,m,k;
lli vis[100007];
lli dist[507][507];
lli path[207][207];
lli path1[207][207];
vector<int> v2;
vector<lli> v[100007];
lli x,y,c,z;
map<int,int> m1;
struct edge
{
    int a,b,cost;
};
lli c1=0;
lli p=0;
/*void djkstra(int x,vector<ll> v[])
{
    mem(vis,0);
    dist[x]=0;
    s2.insert({0,x});
    while(!s2.empty())
    {
        ll p=*s2.begin();
        s2.erase(s2.begin());
        x=p.second;
        if(vis[x])
        continue;
        vis[x]=1;
        for(int j=0;j<v[x].size();j++)
        {
            if(dist[v[x][j].second]>dist[x]+v[x][j].first)
            {
                dist[v[x][j].second]=dist[x]+v[x][j].first;
                s2.insert({dist[v[x][j].second],v[x][j].second});
                a[v[x][j].second]=x;
            }
        }
    }
}*/
lli parent[100007];
lli find(lli a)
{
    return a==parent[a]?a:parent[a]=find(parent[a]);
}
void dset(lli n)
{
    for(int j=0;j<=n;j++)
    parent[j]=j;
}
void unio(lli a,lli b,lli rank[])
{
    if(rank[find(a)]>rank[find(b)])
    parent[find(b)]=find(a);
    else if(rank[find(b)]>rank[find(a)])
    parent[find(a)]=find(b);
    else
    {
        parent[find(a)]=find(b);
        rank[find(b)]++;
    }
}
bool check(lli a,lli b)
{
    return find(a)==find(b);
}
lli q,u,v1,w,l,t1;
lli a[100007];
lli b[100007];
int re[100007];
int main()
{
    cin>>n;
    string s,s1;
    cin>>s>>s1;
    int c=0;
    int c1=0;
    int c2=0;
    int c3=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='1')
        c+=1;
        if(s[i-1]=='0'&&s1[i-1]=='0')
        c1+=1;
        if(s[i-1]=='1'&&s1[i-1]=='0')
        c2+=1;
        if(s[i-1]=='0'&&s1[i-1]!='0')
        c3+=1;
    }
    lli s2=0;
    lli s2=c*c1+(c3)*c2;
    cout<<s2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define M 1000000007
#define INF 1000000007
typedef pair<lli,lli> ll;
#define mem(a,x) memset(a,x,sizeof(a))
lli n,m,k;
lli vis[100007];
lli dist[507][507];
lli path[207][207];
lli path1[207][207];
vector<int> v2;
vector<lli> v[100007];
lli x,y,c,z;
map<int,int> m1;
struct edge
{
    int a,b,cost;
};
lli c1=0;
lli p=0;
/*void djkstra(int x,vector<ll> v[])
{
    mem(vis,0);
    dist[x]=0;
    s2.insert({0,x});
    while(!s2.empty())
    {
        ll p=*s2.begin();
        s2.erase(s2.begin());
        x=p.second;
        if(vis[x])
        continue;
        vis[x]=1;
        for(int j=0;j<v[x].size();j++)
        {
            if(dist[v[x][j].second]>dist[x]+v[x][j].first)
            {
                dist[v[x][j].second]=dist[x]+v[x][j].first;
                s2.insert({dist[v[x][j].second],v[x][j].second});
                a[v[x][j].second]=x;
            }
        }
    }
}*/
lli parent[100007];
lli find(lli a)
{
    return a==parent[a]?a:parent[a]=find(parent[a]);
}
void dset(lli n)
{
    for(int j=0;j<=n;j++)
    parent[j]=j;
}
void unio(lli a,lli b,lli rank[])
{
    if(rank[find(a)]>rank[find(b)])
    parent[find(b)]=find(a);
    else if(rank[find(b)]>rank[find(a)])
    parent[find(a)]=find(b);
    else
    {
        parent[find(a)]=find(b);
        rank[find(b)]++;
    }
}
bool check(lli a,lli b)
{
    return find(a)==find(b);
}
lli q,u,v1,w,l,t1;
lli a[100007];
lli b[100007];
int re[100007];
int main()
{
    cin>>n;
    string s,s1;
    cin>>s>>s1;
    int c=0;
    int c1=0;
    int c2=0;
    int c3=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='1')
        c+=1;
        if(s[i-1]=='0'&&s1[i-1]=='0')
        c1+=1;
        if(s[i-1]=='1'&&s1[i-1]=='0')
        c2+=1;
        if(s[i-1]=='0'&&s1[i-1]!='0')
        c3+=1;
    }
    lli s2=c*c1+(c3)*c2;
    cout<<s2;
}