#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int length = static_cast<int>(s.size());
    int ***dp = new int**[length];
    for(int i = 0;i < length;i++) {
        dp[i] = new int*[length];
        for(int j = 0;j < length;j++) {
            dp[i][j] = new int[5];
            memset(dp[i][j],INF,sizeof(int) * 5);
        }
    }
    for(int i = 0;i < length;i++) {
        if(s[i] == 'a') {
            dp[i][i][0] = 0;
        }else {
            dp[i][i][1] = 0;
        }
    }
    int result = 1;
    for(int len = 2;len <= length;len++) {
        for(int left = 0;left <= length - len;left++) {
            int right = left + len - 1;
            char leftChar = s[left],rightChar = s[right];
            dp[left][right][0] = min(dp[left][right][0],dp[left + 1][right][0] + (leftChar == 'a' ? 0 : 1));
            dp[left][right][0] = min(dp[left][right][0],dp[left][right - 1][0] + (rightChar == 'a' ? 0 : 1));
            dp[left][right][1] = min(dp[left][right][1],dp[left + 1][right][1] + (leftChar == 'b' ? 0 : 1));
            dp[left][right][1] = min(dp[left][right][1],dp[left][right - 1][1] + (rightChar == 'b' ? 0 : 1));
            dp[left][right][2] = min(dp[left][right][2],dp[left + 1][right][2] + (leftChar == 'a' ? 0 : 1));
            dp[left][right][2] = min(dp[left][right][2],dp[left][right - 1][2] + (rightChar == 'b' ? 0 : 1));
            dp[left][right][3] = min(dp[left][right][3],dp[left + 1][right][3] + (leftChar == 'b' ? 0 : 1));
            dp[left][right][3] = min(dp[left][right][3],dp[left][right - 1][3] + (rightChar == 'a' ? 0 : 1));
            dp[left][right][4] = min(dp[left][right][4],dp[left + 1][right][4] + (leftChar == 'a' ? 0 : 1));
            dp[left][right][4] = min(dp[left][right][4],dp[left][right - 1][4] + (rightChar == 'a' ? 0 : 1));
            if(leftChar == 'a') {
                dp[left][right][2] = min(dp[left][right][2],dp[left + 1][right][1]);
                dp[left][right][4] = min(dp[left][right][4],dp[left + 1][right][3]);
            }
            if(rightChar == 'a') {
                dp[left][right][3] = min(dp[left][right][3],dp[left][right - 1][1]);
                dp[left][right][4] = min(dp[left][right][4],dp[left][right - 1][2]);
            }
            if(leftChar == 'b') {
                dp[left][right][3] = min(dp[left][right][3],dp[left + 1][right][0]);
            }
            if(rightChar == 'b') {
                dp[left][right][2] = min(dp[left][right][2],dp[left][right - 1][0]);
            }
            for(int i = 0;i < 5;i++) {
                if(dp[left][right][i] != INF) {
                    result = max(result,right - left + 1 - dp[left][right][i]);
                }
            }
        }
    }
    cout << result << endl;
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int arr[3];
string s;
int bful(int i,int a,int b,int c)
{    if(i==s.size()-1)
    {
        if(s[i]=='a')
        {
         return a+b+c+1;
        }
      else
      {
         if(c==0)
          return a+b+1+c;
          else
              return a+b+c;
      }
    }

	if(s[i]=='b')
	{

		return max(bful(i+1,a,b,c),bful(i+1,a,b+1,0));
	}
	else
	{
		return max(bful(i+1,a,b,c+1),bful(i+1,a+1,0,0));
	}
return a+b+c;
}
int main()
{
	arr[0]=arr[1]=arr[2]=0;
	cin>>s;

	int si=bful(0,0,0,0);
    cout<<si<<endl;
	return 0;

}


#include<iostream>
#include<string>
using namespace std;
string s;
int dp[5001][4];
int bful(int i,int g)
{   if(i==s.size())
    return 0;
 /*if(g==0)
 {
     if(s[i]=='a')
         return dp[i][g]=(bful(i+1,1)+1);
     else
         return dp[i][g]=max(bful(i+1,2)+1,bful(i+1,0));
 }*/

 if(dp[i][g]!=-1)
     return dp[i][g];
    if(g==1&&s[i]=='a')
        return dp[i][g]=(bful(i+1,1)+1);
    if(g==1&&s[i]=='b')
        return dp[i][g]=max(bful(i+1,2)+1,max(i+1,1));
    if(g==2&&s[i]=='a')
        return dp[i][g]=max(bful(i+1,2),bful(i+1,3)+1);
    if(g==2&&s[i]=='b')
        return dp[i][g]=bful(i+1,2)+1;
     if(g==3&&s[i]=='a')
        return dp[i][g]=max(bful(i+1,3)+1,bful(i+1,3));
     if(g==3&&s[i]=='b')
        return dp[i][g]=bful(i+1,3);

   return 1;

}
void initialise()
{
    for(int i=0;i<5001;++i)
        for(int j=0;j<4;++j)
        {
            dp[i][j]=-1;
        }
}
int main()
{initialise();
    cin>>s;
 if(s[0]=='a')
    cout<<bful(1,1)+1<<endl;
 else
     cout<<bful(1,2)+1<<endl;
}


#include<iostream>
#include<string>
using namespace std;
int dp[5001][5001];
string s;
int bful(int i,int a,int b,int c)
{

    if(i==s.size()-1)
    {
        if(s[i]=='a')
        {
         return dp[i][a+b+c]=a+b+c+1;
        }
      else
      {
         if(c==0)
          return dp[i][a+b+c]=a+b+1+c;
          else
              return dp[i][a+b+c]=a+b+c;
      }
    }
     if(dp[i][a+b+c]!=-1)
    return dp[i][a+b+c];

	if(s[i]=='b')
	{

		return dp[i][a+b+c]=max(bful(i+1,a,b,c),bful(i+1,a,b+1,0));
	}
	else
	{
		return dp[i][a+b+c]=max(bful(i+1,a,b,c+1),bful(i+1,a+1,0,0));
	}
return dp[i][a+b+c]=a+b+c;
}
void initialise()
{
    for(int i=0;i<5001;++i)
        for(int j=0;j<5001;++j)
            dp[i][j]=-1;
}
int main()
{
   initialise();
	cin>>s;
	int si=bful(0,0,0,0);
    cout<<si<<endl;
	return 0;

}


#include<iostream>
#include<string>
using namespace std;
int dp[5001][2][2][2];
string s;
int bful(int i,int a,int b,int c)
{

    if(i==s.size()-1)
    {
        if(s[i]=='a')
        {
         return dp[i][a][b][c]=a+b+c+1;
        }
      else
      {
         if(c==0)
          return dp[i][a][b][c]=a+b+1+c;
          else
              return dp[i][a][b][c]=a+b+c;
      }
    }
     if(dp[i][a][b][c]!=-1)
    return dp[i][a][b][c];

	if(s[i]=='b')
	{

		return dp[i][a][b][c]=max(bful(i+1,a,b,c),bful(i+1,a,b+1,0));
	}
	else
	{
		return dp[i][a][b][c]=max(bful(i+1,a,b,c+1),bful(i+1,a+1,0,0));
	}
return dp[i][a][b][c]=a+b+c;
}
void initialise()
{
    for(int i=0;i<5001;++i)
        for(int j=0;j<2;++j)
            for(int k=0;k<2;++k)
                for(int p=0;p<2;++p)
                      dp[i][j][k][p]=-1;
}
int main()
{
   initialise();
	cin>>s;
	int si=bful(0,0,0,0);
    cout<<si<<endl;
	return 0;

}


#include<iostream>
#include<string>
using namespace std;
int dp[5001];
string s;
int bful(int i,int a,int b,int c)
{    if(i==s.size()-1)
    {
        if(s[i]=='a')
        {
         return dp[i]=a+b+c+1;
        }
      else
      {
         if(c==0)
          return dp[i]=a+b+1+c;
          else
              return dp[i]=a+b+c;
      }
    }

	if(s[i]=='b')
	{

		return dp[i]=max(bful(i+1,a,b,c),bful(i+1,a,b+1,0));
	}
	else
	{
		return dp[i]=max(bful(i+1,a,b,c+1),bful(i+1,a+1,0,0));
	}
return dp[i]=a+b+c;
}
void initialise()
{
    for(int i=0;i<5001;++i)
        dp[i]=0;
}
int main()
{
   initialise();
	cin>>s;
	int si=bful(0,0,0,0);
    cout<<si<<endl;
	return 0;

}


#include<iostream>
#include<string>
using namespace std;
string s;
int dp[5001][4];
int bful(int i,int g)
{   if(i==s.size())
    return 0;
 if(dp[i][g]!=-1)
     return dp[i][g];
    if(g==1&&s[i]=='a')
        return dp[i][g]=(bful(i+1,1)+1);
    if(g==1&&s[i]=='b')
        return dp[i][g]=max(bful(i+1,2)+1,max(i+1,1));
    if(g==2&&s[i]=='a')
        return dp[i][g]=max(bful(i+1,2),bful(i+1,3)+1);
    if(g==2&&s[i]=='b')
        return dp[i][g]=bful(i+1,2)+1;
     if(g==3&&s[i]=='a')
        return dp[i][g]=max(bful(i+1,3)+1,bful(i+1,3));
     if(g==3&&s[i]=='b')
        return dp[i][g]=bful(i+1,3);

   return 1;

}
void initialise()
{
    for(int i=0;i<5001;++i)
        for(int j=0;j<4;++j)
        {
            dp[i][j]=-1;
        }
}
int main()
{initialise();
    cin>>s;
    cout<<bful(0,1)<<endl;
}


#include<iostream>
#include<string>
using namespace std;
int dp[5001];
string s;
int bful(int i,int a,int b,int c)
{    if(dp[i]!=-1)
    return dp[i];

    if(i==s.size()-1)
    {
        if(s[i]=='a')
        {
         return dp[i]=a+b+c+1;
        }
      else
      {
         if(c==0)
          return dp[i]=a+b+1+c;
          else
              return dp[i]=a+b+c;
      }
    }

	if(s[i]=='b')
	{

		return dp[i]=max(bful(i+1,a,b,c),bful(i+1,a,b+1,0));
	}
	else
	{
		return dp[i]=max(bful(i+1,a,b,c+1),bful(i+1,a+1,0,0));
	}
return dp[i]=a+b+c;
}
void initialise()
{
    for(int i=0;i<5001;++i)
        dp[i]=-1;
}
int main()
{
   initialise();
	cin>>s;
	int si=bful(0,0,0,0);
    cout<<si<<endl;
	return 0;

}


#include<iostream>
using namespace std;
string s;
int dp[5001][4];
int bful(int i,int j)
{  if(i==s.size())
    return 0;
 if(dp[i][j]!=-1)
     return dp[i][j];
    if(s[i]=='a')
    {   if(j==0)
            return dp[i][j]=bful(i+1,1)+1;
        if(j==1)
            return dp[i][j]= bful(i+1,1)+1;
        if(j==2)
            return dp[i][j]=max(bful(i+1,2),bful(i+1,3)+1);
        if(j==3)
            return dp[i][j]=bful(i+1,3)+1;
    }
    if(s[i]=='b')
    {   if(j==0)
           return dp[i][j]=max(bful(i+1,2)+1,bful(i+1,0));
        if(j==1)
            return dp[i][j]=max(bful(i+1,1),bful(i+1,2)+1);
        if(j==2)
            return dp[i][j]=bful(i+1,2)+1;
        if(j==3)
            return dp[i][j]=bful(i+1,3);
    }
 return 0;
}
void initialise()
{
    for(int i=0;i<5001;++i)
        for(int j=0;j<4;++j)
            dp[i][j]=-1;
}
int main()
{ initialise();
    cin>>s;
 if(s[0]=='a')
 cout<<bful(1,1)+1<<endl;
else
    cout<<max(bful(1,2)+1,bful(1,0))<<endl;

}


#include<iostream>
#include<string>
using namespace std;
string s;
int dp[5001][4];
int bful(int i,int g)
{   if(i==s.size())
    return 0;

 if(dp[i][g]!=-1)
     return dp[i][g];
    if(g==1&&s[i]=='a')
        return dp[i][g]=max((bful(i+1,1)+1),bful(i+1,1));
    if(g==1&&s[i]=='b')
        return dp[i][g]=max(bful(i+1,2)+1,max(i+1,1));
    if(g==2&&s[i]=='a')
        return dp[i][g]=max(bful(i+1,2),bful(i+1,3)+1);
    if(g==2&&s[i]=='b')
        return dp[i][g]=max(bful(i+1,2)+1,bful(i+1,2));
     if(g==3&&s[i]=='a')
        return dp[i][g]=max(bful(i+1,3)+1,bful(i+1,3));
     if(g==3&&s[i]=='b')
        return dp[i][g]=bful(i+1,3);

   return 1;

}
void initialise()
{
    for(int i=0;i<5001;++i)
        for(int j=0;j<4;++j)
        {
            dp[i][j]=-1;
        }
}
int main()
{initialise();
    cin>>s;
 if(s[0]=='a')
    cout<<bful(0,1)<<endl;
 else
     cout<<bful(0,2)<<endl;
}


#include<iostream>
#include<string>
using namespace std;
string s;
int dp[5001][4];
int bful(int i,int g)
{   if(i==s.size())
    return 0;
 if(dp[i][g]!=-1)
     return dp[i][g];
    if(g==1&&s[i]=='a')
        return dp[i][g]=max((bful(i+1,1)+1),bful(i+1,1));
    if(g==1&&s[i]=='b')
        return dp[i][g]=max(bful(i+1,2)+1,max(i+1,1));
    if(g==2&&s[i]=='a')
        return dp[i][g]=max(bful(i+1,2),bful(i+1,3)+1);
    if(g==2&&s[i]=='b')
        return dp[i][g]=max(bful(i+1,2)+1,bful(i+1,2));
     if(g==3&&s[i]=='a')
        return dp[i][g]=max(bful(i+1,3)+1,bful(i+1,3));
     if(g==3&&s[i]=='b')
        return dp[i][g]=bful(i+1,3);

   return 1;

}
void initialise()
{
    for(int i=0;i<5001;++i)
        for(int j=0;j<4;++j)
        {
            dp[i][j]=-1;
        }
}
int main()
{initialise();
    cin>>s;
    cout<<bful(0,1)<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define LL long long
#define maxn 5005
using namespace std;
int pipei(char *S,char *T)
{
	int lens=strlen(S);
	int lent=strlen(T);
	int i,j,m;
	int flag=0;
	int cnt=0;
	for(i=0;i<=lens-lent;i++)
	{
		flag=0;
		for(j=0,m=i;j<lent;j++,m++)
		{
			if(S[m]!=T[j])
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
			cnt++;
	}
	return cnt;
}
int main()
{
	char S[maxn];
	while(cin>>S)
	{
		int len=strlen(S);
		int res=0;
		int maxi=0;
		int sum,i;
		for(sum=0,i=0;i<len;i++)
		{
			if(S[i]=='b')
			{
				sum++;
			}
			if(S[i]=='b'&&i==len-1)
			{
				maxi=max(maxi,sum);
			}
			else if(S[i]=='a')
			{
				res++;
				maxi=max(maxi,sum);
				sum=0;
			}
		}
		cout << res+maxi << endl;
	}
 	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define LL long long
#define maxn 5005
using namespace std;
int pipei(char *S,char *T)
{
	int lens=strlen(S);
	int lent=strlen(T);
	int i,j,m;
	int flag=0;
	int cnt=0;
	for(i=0;i<=lens-lent;i++)
	{
		flag=0;
		for(j=0,m=i;j<lent;j++,m++)
		{
			if(S[m]!=T[j])
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
			cnt++;
	}
	return cnt;
}
int main()
{
	char S[maxn];
	while(cin>>S)
	{
		int len=strlen(S);
		int res,resb;
		res=resb=0;
		int maxi=0;
		int sum,i;
		for(sum=0,i=0;i<len;i++)
		{
			if(S[i]=='b')
			{
				sum++;
				resb++;
			}
			if(S[i]=='b'&&i==len-1)
			{
				maxi=max(maxi,sum);
			}
			else if(S[i]=='a')
			{
				res++;
				maxi=max(maxi,sum);
				sum=0;
			}
		}
		int ans;
		ans=max(res+maxi,resb);
		cout << ans << endl;
	}
 	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define LL long long
#define maxn 5005
using namespace std;
int pipei(char *S,char *T)
{
	int lens=strlen(S);
	int lent=strlen(T);
	int i,j,m;
	int flag=0;
	int cnt=0;
	for(i=0;i<=lens-lent;i++)
	{
		flag=0;
		for(j=0,m=i;j<lent;j++,m++)
		{
			if(S[m]!=T[j])
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
			cnt++;
	}
	return cnt;
}
int main()
{
	char S[maxn];
	int ja[maxn];
	while(cin>>S)
	{
		int len=strlen(S);
		int res,resb;
		res=resb=0;
		int maxi,maxj;
		maxi=maxj=0;
		int sum,i;
		memset(ja,0,sizeof(ja));
		for(int i=len-1;i>=0;i--)
		{
			if(S[i]=='a')
			{
				ja[i]=ja[i+1]+1;
			}
			else
				ja[i]=ja[i+1];
			//cout << ja[i] << endl;
		}
		for(sum=0,i=0;i<len;i++)
		{
			if(S[i]=='b')
			{
				sum++;
				resb++;
				if(i==len-1)
					maxi=max(maxi,sum);
				maxj=max(maxj,ja[i+1]+resb);
			}
			else if(S[i]=='a')
			{
				res++;
				maxi=max(maxi,sum);
				sum=0;
			}
		}

		int ans;
		ans=max(res+maxi,resb);
		ans=max(ans,maxj);
		cout << ans << endl;
	}
 	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define LL long long
#define maxn 5005
using namespace std;
int dp[3][maxn];
int main()
{
	char S[maxn];
	while(cin>>S)
	{
		dp[0][0]=0;
		dp[1][0]=0;
		dp[2][0]=0;
		memset(dp,0,sizeof(dp));
		int len=strlen(S);
		for(int i=0;i<len;i++)
		{
			dp[0][i+1]=dp[0][i]+(S[i]=='a');//a类型
			dp[1][i+1]=max(dp[0][i],dp[1][i])+(S[i]=='b');//ab类型或者b类型
			dp[2][i+1]=max(dp[1][i],dp[2][i])+(S[i]=='a');//aba类型
		}
		int ans;
		ans=max(max(dp[0][len],dp[1][len]),dp[2][len]);
		cout << ans << endl;
	}
 	return 0;
}


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

string s;
ll counta[100010],countb[100010];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>s;
	ll ans=-1,n=s.size(),j,i;
	for (i=1;i<=n;i++)
	{
		if (s[i-1] == 'a')	{counta[i] = counta[i-1] + 1;	countb[i] = countb[i-1];}
		else	{countb[i] = countb[i-1] + 1;	counta[i] = counta[i-1];}
	}
//	 for (i=1;i<=n;i++)	cout<<counta[i]<<" ";
//	 cout<<endl;
//	 for (i=1;i<=n;i++)	cout<<countb[i]<<" ";
//	 cout<<endl;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=i;j++)
		{
			ans = max(ans,counta[j] + (countb[i]-countb[j-1]) + counta[n]-counta[i]);
		}
	}
	cout<<ans;
	return 0;
}


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

string s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>s;
	int i,j,counter=1,ans=-1;
	for (i=0;i<s.size();i++)
	{
		j = i+1;
		char a = s[i];
		counter=1;
		while (s[j] == a && j<s.size())	{j++;	counter++;}
		if (a=='b' || j==s.size())	ans = max(counter,ans);
		else
		{
			while (s[j] == 'b' && j<s.size())	{j++;	counter++;}
			if (j==s.size())	ans = max(counter,ans);
			else
			{
				while (s[j] == 'a' && j<s.size())	{j++;	counter++;}
				ans = max(counter,ans);
			}
		}
	}
	cout<<ans;
	return 0;
}


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

string s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>s;
	int i,j,counter=1,ans=-1;
	for (i=0;i<s.size();i++)
	{
		j = i+1;
		char a = s[i];
		counter=1;
		while (s[j] == a && j<s.size())	{j++;	counter++;}
		if (a=='b')
		{
			if (j==s.size())	ans = max(counter,ans);
			while (s[j]=='a' && j<s.size())	{j++;	counter++;}
			ans = max(counter,ans);
		}
		else
		{
			while (s[j] == 'b' && j<s.size())	{j++;	counter++;}
			if (j==s.size())	ans = max(counter,ans);
			else
			{
				while (s[j] == 'a' && j<s.size())	{j++;	counter++;}
				ans = max(counter,ans);
			}
		}
	}
	cout<<ans;
	return 0;
}


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

string s;
ll counta[100010],countb[100010];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>s;
	ll ans=-1,n=s.size(),j,i;
	for (i=1;i<=n;i++)
	{
		if (s[i-1] == 'a')	{counta[i] = counta[i-1] + 1;	countb[i] = countb[i-1];}
		else	{countb[i] = countb[i-1] + 1;	counta[i] = counta[i-1];}
	}
	// for (i=1;i<=n;i++)	cout<<counta[i]<<" ";
	// cout<<endl;
	// for (i=1;i<=n;i++)	cout<<countb[i]<<" ";
	// cout<<endl;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=i;j++)
		{
			ans = max(ans,counta[j] + (countb[i]-countb[j-1]) + counta[n]-counta[i-1]);
		}
	}
	cout<<ans;
	return 0;
}


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

string s;
int dp[100010],starta[100010],startb[100010];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>s;
	cout<<s.size()<<endl;
	int i,n,j;
	for (i=0;i<s.size();i++)	dp[i] = 1;
	for (i=0;i<s.size();i++)
	{
		if (s[i]=='a' && i<s.size())
		{
			starta[i] = 1;
			i++;
			while (s[i]=='a' && i<s.size())	{	starta[i] = starta[i-1]+1;	i++;}
		}
		else
		{
			while (s[i]!='a' && i<s.size())	i++;
		}
	}
	for (i=0;i<s.size();i++)
	{
		if (s[i]=='b' && i<s.size())
		{
			startb[i] = 1;
			i++;
			while (s[i]=='b' && i<s.size())	{	startb[i] = startb[i-1]+1;	i++;}
		}
		else
		{
			while (s[i]!='b' && i<s.size())	i++;
		}
	}
	for (i=0;i<s.size();i++)
	{
		for (j=0;j<i;j++)
		{
			if (s[i] == 'a')
			{
				dp[i] = max(dp[i],dp[j]+1);
				if (s[j] == 'a')
				{
					starta[i] = starta[j] + 1;
				}
			}
			if (s[i] == 'b')
			{
				if (s[j] == 'b')
				{
					dp[i] = max(dp[i],dp[j]+1);
					startb[i] = startb[j] + 1;
					dp[i] = max(dp[i],startb[i]);
				}
				else
				{
					dp[i] = max(dp[i],starta[j]+1);
				}
			}
		}
	}
//	for (i=0;i<s.size();i++)	cout<<starta[i]<<" ";
//	cout<<endl;
//	for (i=0;i<s.size();i++)	cout<<dp[i]<<" ";
//	cout<<endl;
	cout<<dp[s.size()-1];
	return 0;
}


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

string s;
ll counta[100010],countb[100010];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>s;
	ll ans=-1,n=s.size(),j,i;
	for (i=1;i<=n;i++)
	{
		if (s[i-1] == 'a')	{counta[i] = counta[i-1] + 1;	countb[i] = countb[i-1];}
		else	{countb[i] = countb[i-1] + 1;	counta[i] = counta[i-1];}
	}
	 for (i=1;i<=n;i++)	cout<<counta[i]<<" ";
	 cout<<endl;
	 for (i=1;i<=n;i++)	cout<<countb[i]<<" ";
	 cout<<endl;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=i;j++)
		{
			ans = max(ans,counta[j] + (countb[i]-countb[j-1]) + counta[n]-counta[i]);
		}
	}
	cout<<ans;
	return 0;
}


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

string s;
int dp[100010],starta[100010],startb[100010];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>s;
//	cout<<s.size()<<endl;
	int i,n,j;
	for (i=0;i<s.size();i++)	dp[i] = 1;
	for (i=0;i<s.size();i++)
	{
		if (s[i]=='a' && i<s.size())
		{
			starta[i] = 1;
			i++;
			while (s[i]=='a' && i<s.size())	{	starta[i] = starta[i-1]+1;	i++;}
		}
		else
		{
			while (s[i]!='a' && i<s.size())	i++;
		}
	}
	for (i=0;i<s.size();i++)
	{
		if (s[i]=='b' && i<s.size())
		{
			startb[i] = 1;
			i++;
			while (s[i]=='b' && i<s.size())	{	startb[i] = startb[i-1]+1;	i++;}
		}
		else
		{
			while (s[i]!='b' && i<s.size())	i++;
		}
	}
	for (i=0;i<s.size();i++)
	{
		for (j=0;j<i;j++)
		{
			if (s[i] == 'a')
			{
				dp[i] = max(dp[i],dp[j]+1);
				if (s[j] == 'a')
				{
					starta[i] = starta[j] + 1;
				}
			}
			if (s[i] == 'b')
			{
				if (s[j] == 'b')
				{
					dp[i] = max(dp[i],dp[j]+1);
					startb[i] = startb[j] + 1;
					dp[i] = max(dp[i],startb[i]);
				}
				else
				{
					dp[i] = max(dp[i],starta[j]+1);
				}
			}
		}
	}
//	for (i=0;i<s.size();i++)	cout<<starta[i]<<" ";
//	cout<<endl;
//	for (i=0;i<s.size();i++)	cout<<dp[i]<<" ";
//	cout<<endl;
	cout<<dp[s.size()-1];
	return 0;
}


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

string s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>s;
	int i,j,counter=1,ans=-1;
	for (i=0;i<s.size();i++)
	{
		j = i+1;
		char a = s[i];
		counter=1;
		while (s[j] == a && j<s.size())	{j++;	counter++;}
		if (a=='b')
		{
			if (j==s.size())	ans = max(counter,ans);
			else
			{
				while (s[j]=='a' && j<s.size())	{j++;	counter++;}
				ans = max(counter,ans);
			}
		}
		else
		{
			while (s[j] == 'b' && j<s.size())	{j++;	counter++;}
			if (j==s.size())	ans = max(counter,ans);
			else
			{
				while (s[j] == 'a' && j<s.size())	{j++;	counter++;}
				ans = max(counter,ans);
			}
		}
	}
	cout<<ans;
	return 0;
}


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

string s;
ll counta[100010],countb[100010];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>s;
	ll ans=-1,n=s.size(),j,i;
	for (i=1;i<=n;i++)
	{
		if (s[i-1] == 'a')	{counta[i] = counta[i-1] + 1;	countb[i] = countb[i-1];}
		else	{countb[i] = countb[i-1] + 1;	counta[i] = counta[i-1];}
	}
	// for (i=1;i<=n;i++)	cout<<counta[i]<<" ";
	// cout<<endl;
	// for (i=1;i<=n;i++)	cout<<countb[i]<<" ";
	// cout<<endl;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=i;j++)
		{
			ans = max(ans,counta[j] + (countb[i]-countb[j]) + counta[n]-counta[i]);
		}
	}
	cout<<ans;
	return 0;
}


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

const int INF  = 0x3f3f3f3f;
const int maxn = 500002;
const int Mod  = 1e9 + 7;

#define ll       long long
#define mem(x,y) memset(x,y,sizeof(x))
#define IO       ios_base::sync_with_stdio(0);

const int mn=5e3-5;
int n;
char s[mn];
int sa[mn],sb[mn];

int main() {
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1; i<=n+1; i++) {
        sa[i]=sa[i-1]+(s[i]=='a');//前i项多少个a
        sb[i]=sb[i-1]+(s[i]=='b');
    }
    int ans=0;
    for(int i=0; i<=n+1; i++) {
        for(int j=i; j<=n+1; j++) {
            ans=max(ans,sa[i]+sb[j]-sb[i]+sa[n]-sa[j]);
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

const int INF  = 0x3f3f3f3f;
const int maxn = 500002;
const int Mod  = 1e9 + 7;

#define ll       long long
#define mem(x,y) memset(x,y,sizeof(x))
#define IO       ios_base::sync_with_stdio(0);

const int mn=5e4-5;
int n;
char s[mn];
int sa[mn],sb[mn];

int main() {
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1; i<=n+1; i++) {
        sa[i]=sa[i-1]+(s[i]=='a');//前i项多少个a
        sb[i]=sb[i-1]+(s[i]=='b');
    }
    int ans=0;
    for(int i=0; i<=n+1; i++) {
        for(int j=i; j<=n+1; j++) {
            ans=max(ans,sa[i]+sb[j]-sb[i]+sa[n]-sa[j]);
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

const int INF  = 0x3f3f3f3f;
const int maxn = 500002;
const int Mod  = 1e9 + 7;

#define ll       long long
#define mem(x,y) memset(x,y,sizeof(x))
#define IO       ios_base::sync_with_stdio(0);

const int mn=5e3-5;
int n;
char s[mn];
int sa[mn],sb[mn];

int main(void)
{
    string s;
    while(cin>>s){
    int n=s.size();
    sa[0]=0;
    sb[0]=0;

    for(int i=0;i<n;i++)
    {
        sa[i]=sa[i-1]+(s[i]=='a');
        sb[i]=sb[i-1]+(s[i]=='b');
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i;j<n;j++)
        {
            ans=max(ans,sa[i]+sb[j]-sb[i]+sa[n-1]-sa[j]);
        }
    }
    cout<<ans<<endl;
}
}


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

const int INF  = 0x3f3f3f3f;
const int maxn = 500002;
const int Mod  = 1e9 + 7;

#define ll       long long
#define mem(x,y) memset(x,y,sizeof(x))
#define IO       ios_base::sync_with_stdio(0);

const int mn=5e3-5;
int n;
char s[mn];
int sa[mn],sb[mn];

int main(void)
{
    string s;
    while(cin>>s){
    int n=s.size();
    sa[0]=0;
    sb[0]=0;

    for(int i=0;i<n;i++)
    {
        sa[i]=sa[i-1]+(s[i]=='a');
        sb[i]=sb[i-1]+(s[i]=='b');
    }
    int ans=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            ans=max(ans,sa[i]+sb[j]-sb[i]+sa[n-1]-sa[j]);
        }
    }
    cout<<ans<<endl;
}
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;

char str[5005];
int a[5005];

int main()
{
    cin >> str;
    int n = 1;
    int len = strlen(str);
    int cnt = 1;
    if(str[0] == 'b')
        a[n++] = 0;
    for(int i = 1; i < len; i++)
    {
        if(str[i] != str[i-1])
        {
            a[n++] = cnt;
            cnt = 1;
        }
        else cnt++;
    }
    a[n++] = cnt;
    if(str[len-1] == 'b')
        a[n++] = 0;
/*
    for(int i = 1; i < n; i++)
        printf("%d ", a[i]);
    printf("\n");
*/
    int ans = 0;
    for(int i = 2; i < n; i += 2)
    {
        int lmx = 0, rmx = 0;
        for(int j = 1; j < i; j += 2)
            if(lmx < a[j]) lmx = a[j];
        for(int j = i+1; j < n; j += 2)
            if(rmx < a[j]) rmx = a[j];
        ans = max(ans, lmx + a[i] + rmx);
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;

char str[5005];
int a[5005];
int pre[5005];

int main()
{
    cin >> str;
    int n = 1;
    int len = strlen(str);
    int cnt = 1;
    if(str[0] == 'b')
        a[n++] = 0;
    for(int i = 1; i < len; i++)
    {
        if(str[i] != str[i-1])
        {
            a[n++] = cnt;
            cnt = 1;
        }
        else cnt++;
    }
    a[n++] = cnt;
    if(str[len-1] == 'b')
        a[n++] = 0;

    int lsum1 = 0, rsum1 = 0;
    pre[0] = 0;
    for(int i = 1; i < n; i++)
    {
        pre[i] = pre[i-1] + a[i];
        if(i % 2 == 1) rsum1 += a[i];
        //printf("%d ", a[i]);
    }
    //printf("\n");
    int ans = rsum1;
    for(int i = 2; i < n; i += 2)
    {
        lsum1 += a[i-1];
        rsum1 -= a[i-1];
        int lmx = lsum1, ltmp = lsum1;
        for(int j = i - 2; j > 0; j -= 2)
        {
            ltmp -= a[j+1];
            ltmp += a[j];
            lmx = max(lmx, ltmp);
        }
        int rmx = rsum1, rtmp = rsum1;
        for(int j = i + 2; j < n; j += 2)
        {
            rtmp -= a[j-1];
            rtmp += a[j];
            rmx = max(rmx, rtmp);
        }
        ans = max(ans, lmx+a[i]+rmx);
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;

char str[5005];
int a[5005];

int main()
{
    cin >> str;
    int n = 1;
    int len = strlen(str);
    int cnt = 1;
    if(str[0] == 'b')
        a[n++] = 0;
    for(int i = 1; i < len; i++)
    {
        if(str[i] != str[i-1])
        {
            a[n++] = cnt;
            cnt = 1;
        }
        else cnt++;
    }
    a[n++] = cnt;
    if(str[len-1] == 'b')
        a[n++] = 0;
/*
    for(int i = 1; i < n; i++)
        printf("%d ", a[i]);
    printf("\n");
*/
    int ans = 0;
    int tsum = 0;
    for(int i = 2; i < n; i += 2)
    {
        tsum += a[i];
        int lmx = 0, rmx = 0;
        int lsum1 = 0, lsum2 = 0;
        for(int j = 1; j < i; j++)
            if(j % 2 == 1) lsum1 += a[j];
            else lsum2 += a[j];
        lmx = max(lsum1, lsum2);

        int rsum1 = 0, rsum2 = 0;
        for(int j = i + 1; j < n; j++)
            if(j%2 == 1) rsum1 += a[j];
            else rsum2 += a[j];
        rmx = max(rsum1, rsum2);

        ans = max(ans, lmx + a[i] + rmx);
    }
    ans = max(ans, len - tsum);
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;

char str[5005];
int a[5005];
int pre[5005];

int main()
{
    cin >> str;
    int n = 1;
    int len = strlen(str);
    int cnt = 1;
    if(str[0] == 'b')
        a[n++] = 0;
    for(int i = 1; i < len; i++)
    {
        if(str[i] != str[i-1])
        {
            a[n++] = cnt;
            cnt = 1;
        }
        else cnt++;
    }
    a[n++] = cnt;
    if(str[len-1] == 'b')
        a[n++] = 0;

    int lsum1 = 0, rsum1 = 0;
    pre[0] = 0;
    for(int i = 1; i < n; i++)
    {
        pre[i] = pre[i-1] + a[i];
        if(i % 2 == 1) rsum1 += a[i];
        //printf("%d ", a[i]);
    }
    //printf("\n");
    int ans = 0;
    for(int i = 2; i < n; i += 2)
    {
        lsum1 += a[i-1];
        rsum1 -= a[i-1];
        int lmx = lsum1, ltmp = lsum1;
        for(int j = i - 2; j > 0; j -= 2)
        {
            ltmp -= a[j+1];
            ltmp += a[j];
            lmx = max(lmx, ltmp);
        }
        int rmx = rsum1, rtmp = rsum1;
        for(int j = i + 2; j < n; j += 2)
        {
            rtmp -= a[j-1];
            rtmp += a[j];
            rmx = max(rmx, rtmp);
        }
        ans = max(ans, lmx+a[i]+rmx);
    }
    cout << ans << endl;

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pair < int , int > pii

const int N = 2000 + 100;
int n, t[N], mark[N], sumr[N], suml[N];
string s;

int main(){
	string s;
	cin >> s;

	bool flag = 0;
	for(int i = 0; i < s.size(); i++)
		if(s[i] == 'b') flag = 1;

	if(!flag){
		cout << s.size() << endl;
		return 0 ;
	}

	int cur = 1, last = 1;
	for(int i = 1; i < s.size(); i++){
		if(s[i] == s[i-1]) cur++;
		else{
//			cout << "% " << endl;
			t[last] = cur;
			if(s[i-1] == 'b') mark[last] = 1;
			cur = 1;
			last++;
		}
//		cout << "# " << i+1 << " " << s.size() << endl;
	}
	t[last] = cur;
	if(s[s.size()-1] == 'b') mark[last] = 1;
	last++;

	for(int i = 1; i < last; i++){
		sumr[i] = sumr[i-1];
		if(mark[i]) sumr[i] += t[i];
	}
	for(int i = last-1; i > 0; i--){
		suml[i] = suml[i+1];
		if(mark[i]) suml[i] += t[i];
	}

	int ans = s.size()-1;
	for(int i = 0; i < last; i++){
		if(mark[i]){
			ans = min(ans, sumr[i-1]+suml[i+1]);
		}
	}
	cout << s.size() - ans << endl;
}


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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pair < int , int > pii

const int N = 2000 + 100;
int n, t[N], mark[N], suma[N], sumb[N];
string s;

int main(){
	string s;
	cin >> s;

	bool flag = 0;
	for(int i = 0; i < s.size(); i++)
		if(s[i] == 'b') flag = 1;

	if(!flag){
		cout << s.size() << endl;
		return 0 ;
	}

	int cur = 1, last = 1;
	for(int i = 1; i < s.size(); i++){
		if(s[i] == s[i-1]) cur++;
		else{
//			cout << "% " << endl;
			t[last] = cur;
			if(s[i-1] == 'b') mark[last] = 1;
			cur = 1;
			last++;
		}
//		cout << "# " << i+1 << " " << s.size() << endl;
	}
	t[last] = cur;
	if(s[s.size()-1] == 'b') mark[last] = 1;
	last++;

//	for(int i = 0; i < last; i++)
//		cout << "% " << t[i] << " " << mark[i] << endl;

	for(int i = 1; i <= last; i++){
		suma[i] = suma[i-1];
		sumb[i] = sumb[i-1];
		if(!mark[i]) suma[i] += t[i];
		else sumb[i] += t[i];
	}

//	for(int i = 0; i < last; i++)
//		cout << "# " << i << " " << suma[i] << " " << sumb[i] << endl;

	int ans = s.size() - 1;
	for(int i = 0; i < last; i++){
		for(int j = last; j > i; j--){
			int an = sumb[i] + sumb[last-1] - sumb[j-1] + suma[j-1] - suma[i];
			ans = min(an, ans);
		}
	}
	cout << s.size() - ans << endl;
}


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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pair < int , int > pii

const int N = 5000 + 100; // =|||||||||||||||||||||||||
int n, t[N], mark[N], suma[N], sumb[N];
string s;

int main(){
	string s;
	cin >> s;

	bool flag = 0;
	for(int i = 0; i < s.size(); i++)
		if(s[i] == 'b') flag = 1;

	if(!flag){
		cout << s.size() << endl;
		return 0 ;
	}

	int cur = 1, last = 1;
	for(int i = 1; i < s.size(); i++){
		if(s[i] == s[i-1]) cur++;
		else{
//			cout << "% " << endl;
			t[last] = cur;
			if(s[i-1] == 'b') mark[last] = 1;
			cur = 1;
			last++;
		}
//		cout << "# " << i+1 << " " << s.size() << endl;
	}
	t[last] = cur;
	if(s[s.size()-1] == 'b') mark[last] = 1;
	last++;

//	for(int i = 0; i < last; i++)
//		cout << "% " << t[i] << " " << mark[i] << endl;

	for(int i = 1; i <= last; i++){
		suma[i] = suma[i-1];
		sumb[i] = sumb[i-1];
		if(!mark[i]) suma[i] += t[i];
		else sumb[i] += t[i];
	}

//	for(int i = 0; i < last; i++)
//		cout << "# " << i << " " << suma[i] << " " << sumb[i] << endl;

	int ans = s.size() - 1;
	for(int i = 0; i < last; i++){
		for(int j = last; j > i; j--){
			int an = sumb[i] + sumb[last-1] - sumb[j-1] + suma[j-1] - suma[i];
			ans = min(an, ans);
		}
	}
	cout << s.size() - ans << endl;
}


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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pair < int , int > pii

const int N = 2000 + 100;
int n, t[N], mark[N], sumr[N], suml[N];
string s;

int main(){
	string s;
	cin >> s;

	int cur = 1, last = 1;
	for(int i = 1; i < s.size(); i++){
		if(s[i] == s[i-1]) cur++;
		else if(s[i] != s[i-1] || i+1 == s.size()){
//			cout << "% " << endl;
			t[last] = cur;
			if(s[i-1] == 'b') mark[last] = 1;
			cur = 1;
			last++;
		}
//		cout << "# " << i+1 << " " << s.size() << endl;
	}
	t[last] = cur;
	if(s[s.size()-1] == 'b') mark[last] = 1;
	last++;

	for(int i = 1; i < last; i++){
		sumr[i] = sumr[i-1];
		if(mark[i]) sumr[i] += t[i];
	}
	for(int i = last-1; i > 0; i--){
		suml[i] = suml[i+1];
		if(mark[i]) suml[i] += t[i];
	}

	int ans = 1e9;
	for(int i = 0; i < last; i++){
		if(mark[i]){
			ans = min(ans, sumr[i-1]+suml[i+1]);
		}
	}
	cout << s.size() - ans << endl;
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vlli vector<long long int>
#define pb push_back
#define mp make_pair
#define all(c)  ((c).begin()), ((c).end())
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	string s;
	cin>>s;
	vi a1(s.size()+1,0);
	vi a2(s.size()+1,0);
	vi b(s.size()+1,0);
	FOR(i,1,s.size()+1){
		//cout<<i<<s[i-1]<<endl;
		if(s[i-1]=='a')
			a1[i]=a1[i-1]+1;
		else
			a1[i]=a1[i-1];
		//cout<<i<<endl;
		if(s[i-1]=='b')
			b[i]=b[i-1]+1;
		else
			b[i]=b[i-1];
	}
	ROF(i,s.size()-1,0){
		if(s[i]=='a')
			a2[i]=a2[i+1]+1;
		else
			a2[i]=a2[i+1];
	}
	int max=0;
	FOR(i,0,s.size()){
		FOR(j,i+1,s.size()+1){
			//cout<<i<<" "<<j<<endl;
			if(a1[i]+b[j]-b[i]+a2[j]>max){
				max=a1[i]+b[j]-b[i]+a2[j];
			}

		}
	}
	cout<<max<<endl;
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vlli vector<long long int>
#define pb push_back
#define mp make_pair
#define all(c)  ((c).begin()), ((c).end())
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	string s;
	cin>>s;
	vi a1(s.size()+1,0);
	vi a2(s.size()+1,0);
	vi b(s.size()+1,0);
	FOR(i,1,s.size()+1){
		//cout<<i<<s[i-1]<<endl;
		if(s[i-1]=='a')
			a1[i]=a1[i-1]+1;
		else
			a1[i]=a1[i-1];
		//cout<<i<<endl;
		if(s[i-1]=='b')
			b[i]=b[i-1]+1;
		else
			b[i]=b[i-1];
	}
	ROF(i,s.size()-1,0){
		if(s[i]=='a')
			a2[i]=a2[i+1]+1;
		else
			a2[i]=a2[i+1];
	}
	int max=0;
	FOR(i,0,s.size()-1){
		FOR(j,i+1,s.size()+1){
			//cout<<i<<" "<<j<<endl;
			if(a1[i]+b[j]-b[i]+a2[j]>max){
				max=a1[i]+b[j]-b[i]+a2[j];
			}

		}
	}
	cout<<max<<endl;
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vlli vector<long long int>
#define pb push_back
#define mp make_pair
#define all(c)  ((c).begin()), ((c).end())
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	string s;
	cin>>s;
	vi a1(s.size()+1,0);
	vi a2(s.size()+1,0);
	vi b(s.size()+1,0);
	FOR(i,1,s.size()+1){
		//cout<<i<<s[i-1]<<endl;
		if(s[i-1]=='a')
			a1[i]=a1[i-1]+1;
		else
			a1[i]=a1[i-1];
		//cout<<i<<endl;
		if(s[i-1]=='b')
			b[i]=b[i-1]+1;
		else
			b[i]=b[i-1];
	}
	ROF(i,s.size()-1,0){
		if(s[i]=='a')
			a2[i]=a2[i+1]+1;
		else
			a2[i]=a2[i+1];
	}
	int max=0;
	FOR(i,0,s.size()+1){
		FOR(j,i+1,s.size()+1){
			//cout<<i<<" "<<j<<endl;
			if(a1[i]+b[j]-b[i]+a2[j]>max){
				max=a1[i]+b[j]-b[i]+a2[j];
			}

		}
	}
	cout<<max<<endl;
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vlli vector<long long int>
#define pb push_back
#define mp make_pair
#define all(c)  ((c).begin()), ((c).end())
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	string s;
	cin>>s;
	vi a1(s.size()+1,0);
	vi a2(s.size()+1,0);
	vi b(s.size()+1,0);
	FOR(i,1,s.size()+1){
		//cout<<i<<s[i-1]<<endl;
		if(s[i-1]=='a')
			a1[i]=a1[i-1]+1;
		else
			a1[i]=a1[i-1];
		//cout<<i<<endl;
		if(s[i-1]=='b')
			b[i]=b[i-1]+1;
		else
			b[i]=b[i-1];
	}
	ROF(i,s.size()-1,0){
		if(s[i]=='a')
			a2[i]=a2[i+1]+1;
		else
			a2[i]=a2[i+1];
	}
	int max=0;
	FOR(i,0,s.size()+1){
		FOR(j,i,s.size()+1){
			//cout<<i<<" "<<j<<endl;
			if(a1[i]+b[j]-b[i]+a2[j]>max){
				max=a1[i]+b[j]-b[i]+a2[j];
			}

		}
	}
	cout<<max<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5010;
int n,m;
char buf[maxn];
int sum[maxn][2];

int main(){
	scanf("%s",buf+1);
	n=strlen(buf+1);
	for (int i=1;i<=n;i++){
		if (buf[i]=='a') sum[i][0]++;
		else sum[i][1]++;
		sum[i][0]+=sum[i-1][0];
		sum[i][1]+=sum[i-1][1];
	}
	int ans=0;
	if (sum[n][1]==0){
		printf("0");
		return 0;
	}
	for (int i=1;i<=n;i++){
		for (int j=i;j<=n;j++){
			int num_1=sum[i-1][0],num_2=sum[j][1]-sum[i-1][1],num_3=sum[n][0]-sum[j][0];
			ans=max(ans,num_1+num_2+num_3);
		}
	}
	printf("%d",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=10010;
int n,m;
char buf[maxn];
int sum[maxn][2];

int main(){
	scanf("%s",buf+1);
	n=strlen(buf+1);
	for (int i=1;i<=n;i++){
		if (buf[i]=='a') sum[i][0]++;
		else sum[i][1]++;
		sum[i][0]+=sum[i-1][0];
		sum[i][1]+=sum[i-1][1];
	}
	int ans=0;
	if (sum[n][1]==0){
		printf("%d",n);
		return 0;
	}
	for (int i=1;i<=n;i++){
		for (int j=i;j<=n;j++){
			int num_1=sum[i-1][0],num_2=sum[j][1]-sum[i-1][1],num_3=sum[n][0]-sum[j][0];
			ans=max(ans,num_1+num_2+num_3);
		}
	}
	printf("%d",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5010;
int n,m;
char buf[maxn];
int sum[maxn][2];

int main(){
	scanf("%s",buf+1);
	n=strlen(buf+1);
	for (int i=1;i<=n;i++){
		if (buf[i]=='a') sum[i][0]++;
		else sum[i][1]++;
		sum[i][0]+=sum[i-1][0];
		sum[i][1]+=sum[i-1][1];
	}
	int ans=0;
	for (int i=1;i<=n;i++){
		for (int j=i;j<=n;j++){
			int num_1=sum[i-1][0],num_2=sum[j][1]-sum[i-1][1],num_3=sum[n][0]-sum[j][0];
			ans=max(ans,num_1+num_2+num_3);
		}
	}
	printf("%d",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5010;
int n,m;
char buf[maxn];
int sum[maxn][2];

int main(){
	scanf("%s",buf+1);
	n=strlen(buf+1);
	for (int i=1;i<=n;i++){
		if (buf[i]=='a') sum[i][0]++;
		else sum[i][1]++;
		sum[i][0]+=sum[i-1][0];
		sum[i][1]+=sum[i-1][1];
	}
	int ans=0;
	for (int i=1;i<=n;i++){
		for (int j=i+1;j<=n;j++){
			int num_1=sum[i-1][0],num_2=sum[j][1]-sum[i-1][1],num_3=sum[n][0]-sum[j][0];
			ans=max(ans,num_1+num_2+num_3);
		}
	}
	printf("%d",ans);
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;
const int MAXM = 1e5+17;
const int MAXN = 5e3+17;
string str;
int frt[MAXN],bhd[MAXN],sum[MAXN][MAXN];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
   	cin>>str;
   	vector<pii > vec;
   	for (int i = 0; i < str.length(); ++i)
   	{
   		if(str[i]=='a')
   		{
   			int temp = 0;
   			while(str[i]!='b'&&i<str.length())
   			{

   				temp++;
   				i++;
   			}
   			vec.push_back(pii(temp,1));
   			i--;
   		}
   		else
   		{
   			int temp = 0;
   			while(str[i]!='a'&&i<str.length())
   			{
   				temp++;
   				i++;
   			}
   			vec.push_back(pii(temp,2));
   			i--;
   		}
   	}
   	for (int i = 0; i < vec.size(); ++i)
   	{
   		//cerr<<vec[i].first<<"  "<<vec[i].second<<endl;
   	}
   	for (int i = 0,temp = 0; i < vec.size(); ++i)
   	{
   		if(vec[i].second==1)
   		{
   			frt[i] = temp;
   			temp += vec[i].first;
   		}
   		else
   			frt[i] = temp;
   	}
   	for (int i = vec.size()-1,temp = 0; i > -1; --i)
   	{
   		if(vec[i].second==1)
   		{
   			bhd[i] = temp;
   			temp += vec[i].first;
   		}
   		else
   			bhd[i] = temp;
   	}
   	for (int i = 0; i < vec.size(); ++i)
   	{
   		//debug(i);debug(frt[i]);debug(bhd[i]);
   	}
   	for (int i = 0; i < vec.size(); ++i)
   	{
   		sum[i][i] = vec[i].second==2?vec[i].first:0;
   		for (int j = i+1; j < vec.size(); ++j)
   		{
   			sum[i][j] = sum[i][j-1] + (vec[j].second==2?vec[j].first:0);
   			//debug(i);debug(j);debug(sum[i][j]);
		}
   	}
   	int ans = 1;
   	for (int i = 0; i < vec.size(); ++i)
   	{
   		for (int j = i; j < vec.size(); ++j)
   		{
   			//debug(i);debug(j);debug(sum[i][j]);debug(frt[i]);debug(bhd[i]);
   			ans = max(ans,sum[i][j]+frt[i]+bhd[j]);
   		}
   	}
   	int temp = 0;
   	for(int i=0;i<str.length();++i)
   		if(str[i]=='a') temp++;
   	cout<<max(ans,temp)<<endl;
    return 0;
}


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

#define ll unsigned long long
const int N = 2e5 + 5;

int n, m, u, v;
int bigSz[N], inDex[N];
ll A, B, C;
vector<int> adj[N], big;
vector<ll> sumAdj[N];
vector<bool> hav[N];
vector<pair<int, int> > edge;

ll calc(ll a, ll b, ll c){
	if(a > b) swap(a, b);
	if(a > c) swap(a, c);
	if(b > c) swap(b, c);
	return A * a + B * b + C * c;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n >> m;
	cin >> A >> B >> C;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		if(u > v) swap(u, v);
		edge.push_back({u, v});
	}
	int magic = sqrt(m);

	ll ans = 0, numEdge = 0, sumEdge = 0;
	for(ll i = 0; i < n; i++){
		sort(adj[i].begin(), adj[i].end());
		if(adj[i].size() > magic){
			bigSz[i] = 1;
			inDex[i] = (int)big.size();
			big.push_back(i);
		}

		ans += 1ULL * (n - i - 1) * A * ((i - 1) * i / 2);
		ans += 1ULL * B * (n - i - 1) * i * i;
		ans += 1ULL * i * C * ((n + i) * (n - i - 1) / 2);

		ll sum = 0, cnt = 0;
		for(int j: adj[i]){
			if(j >= i) break;
			ans -= 1ULL * (i - j - 1) * (A * j + C * i) + 1ULL * B * ((i - j - 1) * (i + j) / 2);
			ans -= 1ULL * j * (B * j + C * i) + 1ULL * A * ((j - 1) * j / 2);
			ans += 1ULL * cnt * (B * j + C * i) + sum;
			sum += A * j; cnt++;
		}

		ans -= 1ULL * numEdge * C * i + sumEdge;
		for(int j: adj[i]){
			if(j >= i) break;
			numEdge++;
			sumEdge += A * j + B * i;
		}
	}

	for(int i = 0; i < n; i++){
		sumAdj[i].push_back(0);
		ll sum = 0;
		for(int j: adj[i]){
			sum += j;
			sumAdj[i].push_back(sum);
		}
		hav[i].assign((int)big.size(), 0);
	}

	for(ll i = 0; i < n; i++){
		for(int j: adj[i]){
			if(j >= i) break;

			int R = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin() - 1;
			if(R >= 0 && R < adj[j].size() && adj[j][R] < j){
				R++;
				ans += 1ULL * R * (B * j + C * i) + 1ULL * A * sumAdj[j][R];
			}

			int L = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin();
			R = lower_bound(adj[j].begin(), adj[j].end(), i) - adj[j].begin() - 1;
			if(L > R || L < 0 || L >= adj[j].size() || R < 0 || R >= adj[j].size()){
				continue;
			}
			if(adj[j][L] <= j || adj[j][R] >= i){
				continue;
			}
			R++;
			ans += 1ULL * (R - L) * (A * j + C * i) + 1ULL * B * (sumAdj[j][R] - sumAdj[j][L]);
		}
	}

	for(int i = 0; i < n; i++){
		for(int j: adj[i]){
			if(bigSz[j] == 1){
				hav[i][inDex[j]] = 1;
			}
		}
	}

	ll cnt0 = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for(auto e: edge){
		int u = e.first, v = e.second;

		if(bigSz[u] + bigSz[v] == 0){
			int ptr = 0;
			for(int j: adj[u]){
				while(ptr + 1 < adj[v].size() && adj[v][ptr] < j){
					ptr++;
				}
				if(adj[v][ptr] == j){
					if(bigSz[j] == 0){
						cnt0 += calc(u, v, j);
					} else {
						cnt1 += calc(u, v, j);
					}
				}
			}
		}

		if(bigSz[u] + bigSz[v] == 1){
			for(int j: big){
				if(hav[u][inDex[j]] == 1 && hav[v][inDex[j]] == 1){
					cnt2 += calc(u, v, j);
				}
			}
		}

		if(bigSz[u] + bigSz[v] == 2){
			for(int j: big){
				if(hav[u][inDex[j]] == 1 && hav[v][inDex[j]] == 1){
					cnt3 += calc(u, v, j);
				}
			}
		}
	}
	ll res = (cnt0 / 3) + cnt1 + (cnt2 / 2) + (cnt3 / 3);
	ans -= res;

	cout << ans;
}


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

#define ll long long
const int N = 2e5 + 5;

int n, m, u, v;
int bigSz[N], inDex[N];
ll A, B, C;
vector<int> adj[N], big;
vector<ll> sumAdj[N];
vector<bool> hav[N];
vector<pair<int, int> > edge;

ll calc(ll a, ll b, ll c){
	if(a > b) swap(a, b);
	if(a > c) swap(a, c);
	if(b > c) swap(b, c);
	return A * a + B * b + C * c;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n >> m;
	cin >> A >> B >> C;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		if(u > v) swap(u, v);
		edge.push_back({u, v});
	}
	int magic = sqrt(m);

	ll ans = 0, numEdge = 0, sumEdge = 0;
	for(int i = 0; i < n; i++){
		sort(adj[i].begin(), adj[i].end());
		if(adj[i].size() > magic){
			bigSz[i] = 1;
			inDex[i] = (int)big.size();
			big.push_back(i);
		}

		ans += 1LL * (n - i - 1) * A * (i - 1) * i / 2;
		ans += 1LL * B * (n - i - 1) * i * i;
		ans += 1LL * i * C * (n + i) * (n - i - 1) / 2;

		ll sum = 0, cnt = 0;
		for(int j: adj[i]){
			if(j >= i) break;
			ans -= 1LL * (i - j - 1) * (A * j + C * i) + 1LL * B * (i - j - 1) * (i + j) / 2;
			ans -= 1LL * j * (B * j + C * i) + 1LL * A * (j - 1) * j / 2;
			ans += 1LL * cnt * (B * j + C * i) + sum;
			sum += A * j; cnt++;
		}

		ans -= 1LL * numEdge * C * i + sumEdge;
		for(int j: adj[i]){
			if(j >= i) break;
			numEdge++;
			sumEdge += A * j + B * i;
		}
	}

	for(int i = 0; i < n; i++){
		sumAdj[i].push_back(0);
		ll sum = 0;
		for(int j: adj[i]){
			sum += j;
			sumAdj[i].push_back(sum);
		}
		hav[i].assign((int)big.size(), 0);
	}

	for(int i = 0; i < n; i++){
		for(int j: adj[i]){
			if(j >= i) break;

			int R = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin() - 1;
			if(R >= 0 && R < adj[j].size() && adj[j][R] < j){
				R++;
				ans += 1LL * R * (B * j + C * i) + 1LL * A * sumAdj[j][R];
			}

			int L = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin();
			R = lower_bound(adj[j].begin(), adj[j].end(), i) - adj[j].begin() - 1;
			if(L > R || L < 0 || L >= adj[j].size() || R < 0 || R >= adj[j].size()){
				continue;
			}
			if(adj[j][L] <= j || adj[j][R] >= i){
				continue;
			}
			R++;
			ans += 1LL * (R - L) * (A * j + C * i) + 1LL * B * (sumAdj[j][R] - sumAdj[j][L]);
		}
	}

	for(int i = 0; i < n; i++){
		for(int j: adj[i]){
			if(bigSz[j] == 1){
				hav[i][inDex[j]] = 1;
			}
		}
	}

	ll cnt0 = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for(auto e: edge){
		int u = e.first, v = e.second;

		if(bigSz[u] + bigSz[v] == 0){
			int ptr = 0;
			for(int j: adj[u]){
				while(ptr + 1 < adj[v].size() && adj[v][ptr] < j){
					ptr++;
				}
				if(adj[v][ptr] == j){
					if(bigSz[j] == 0){
						cnt0 += calc(u, v, j);
					} else {
						cnt1 += calc(u, v, j);
					}
				}
			}
		}

		if(bigSz[u] + bigSz[v] == 1){
			for(int j: big){
				if(hav[u][inDex[j]] == 1 && hav[v][inDex[j]] == 1){
					cnt2 += calc(u, v, j);
				}
			}
		}

		if(bigSz[u] + bigSz[v] == 2){
			for(int j: big){
				if(hav[u][inDex[j]] == 1 && hav[v][inDex[j]] == 1){
					cnt3 += calc(u, v, j);
				}
			}
		}
	}
	ll res = (cnt0 / 3) + cnt1 + (cnt2 / 2) + (cnt3 / 3);
	ans -= res;

	cout << ans;
}


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

#define ll unsigned long long
const int N = 2e5 + 5;

int n, m, u, v;
int bigSz[N], inDex[N];
ll A, B, C;
vector<int> adj[N], big;
vector<ll> sumAdj[N];
vector<bool> hav[N];
vector<pair<int, int> > edge;

ll calc(ll a, ll b, ll c){
	if(a > b) swap(a, b);
	if(a > c) swap(a, c);
	if(b > c) swap(b, c);
	return A * a + B * b + C * c;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n >> m;
	cin >> A >> B >> C;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		if(u > v) swap(u, v);
		edge.push_back({u, v});
	}
	int magic = sqrt(m);

	ll ans = 0, numEdge = 0, sumEdge = 0;
	for(ll i = 0; i < n; i++){
		sort(adj[i].begin(), adj[i].end());
		if(adj[i].size() > magic){
			bigSz[i] = 1;
			inDex[i] = (int)big.size();
			big.push_back(i);
		}

		ans += 1ULL * (n - i - 1) * A * ((i - 1) * i / 2);
		ans += 1ULL * B * (n - i - 1) * i * i;
		ans += 1ULL * i * C * ((n + i) * (n - i - 1) / 2);

		ll sum = 0, cnt = 0;
		for(int j: adj[i]){
			if(j >= i) break;
			ans -= 1ULL * (i - j - 1) * (A * j + C * i) + 1ULL * B * ((i - j - 1) * (i + j) / 2);
			ans -= 1ULL * j * (B * j + C * i) + 1ULL * A * ((j - 1) * j / 2);
			ans += 1ULL * cnt * (B * j + C * i) + sum;
			sum += A * j; cnt++;
		}

		ans -= 1ULL * numEdge * C * i + sumEdge;
		for(int j: adj[i]){
			if(j >= i) break;
			numEdge++;
			sumEdge += A * j + B * i;
		}
	}

	for(int i = 0; i < n; i++){
		sumAdj[i].push_back(0);
		ll sum = 0;
		for(int j: adj[i]){
			sum += j;
			sumAdj[i].push_back(sum);
		}
		hav[i].assign((int)big.size(), 0);
	}

	for(int i = 0; i < n; i++){
		for(int j: adj[i]){
			if(j >= i) break;

			int R = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin() - 1;
			if(R >= 0 && R < adj[j].size() && adj[j][R] < j){
				R++;
				ans += 1ULL * R * (B * j + C * i) + 1ULL * A * sumAdj[j][R];
			}

			int L = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin();
			R = lower_bound(adj[j].begin(), adj[j].end(), i) - adj[j].begin() - 1;
			if(L > R || L < 0 || L >= adj[j].size() || R < 0 || R >= adj[j].size()){
				continue;
			}
			if(adj[j][L] <= j || adj[j][R] >= i){
				continue;
			}
			R++;
			ans += 1ULL * (R - L) * (A * j + C * i) + 1ULL * B * (sumAdj[j][R] - sumAdj[j][L]);
		}
	}

	for(int i = 0; i < n; i++){
		for(int j: adj[i]){
			if(bigSz[j] == 1){
				hav[i][inDex[j]] = 1;
			}
		}
	}

	ll cnt0 = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for(auto e: edge){
		int u = e.first, v = e.second;

		if(bigSz[u] + bigSz[v] == 0){
			int ptr = 0;
			for(int j: adj[u]){
				while(ptr + 1 < adj[v].size() && adj[v][ptr] < j){
					ptr++;
				}
				if(adj[v][ptr] == j){
					if(bigSz[j] == 0){
						cnt0 += calc(u, v, j);
					} else {
						cnt1 += calc(u, v, j);
					}
				}
			}
		}

		if(bigSz[u] + bigSz[v] == 1){
			for(int j: big){
				if(hav[u][inDex[j]] == 1 && hav[v][inDex[j]] == 1){
					cnt2 += calc(u, v, j);
				}
			}
		}

		if(bigSz[u] + bigSz[v] == 2){
			for(int j: big){
				if(hav[u][inDex[j]] == 1 && hav[v][inDex[j]] == 1){
					cnt3 += calc(u, v, j);
				}
			}
		}
	}
	ll res = (cnt0 / 3) + cnt1 + (cnt2 / 2) + (cnt3 / 3);
	ans -= res;

	cout << ans;
}


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

#define ll unsigned long long
const int N = 2e5 + 5;

int n, m, u, v;
int bigSz[N], inDex[N];
ll A, B, C;
vector<int> adj[N], big;
vector<ll> sumAdj[N];
vector<bool> hav[N];
vector<pair<int, int> > edge;

ll calc(ll a, ll b, ll c){
	if(a > b) swap(a, b);
	if(a > c) swap(a, c);
	if(b > c) swap(b, c);
	return A * a + B * b + C * c;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n >> m;
	cin >> A >> B >> C;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		if(u > v) swap(u, v);
		edge.push_back({u, v});
	}
	int magic = sqrt(m);

	ll ans = 0, numEdge = 0, sumEdge = 0;
	for(ll i = 0; i < n; i++){
		sort(adj[i].begin(), adj[i].end());
		if(adj[i].size() > magic){
			bigSz[i] = 1;
			inDex[i] = (int)big.size();
			big.push_back(i);
		}

		ans += 1ULL * (n - i - 1) * A * ((i - 1) * i / 2);
		ans += 1ULL * B * (n - i - 1) * i * i;
		ans += 1ULL * i * C * ((n + i) * (n - i - 1) / 2);

		ll sum = 0, cnt = 0;
		for(ll j: adj[i]){
			if(j >= i) break;
			ans -= 1ULL * (i - j - 1) * (A * j + C * i) + 1ULL * B * ((i - j - 1) * (i + j) / 2);
			ans -= 1ULL * j * (B * j + C * i) + 1ULL * A * ((j - 1) * j / 2);
			ans += 1ULL * cnt * (B * j + C * i) + sum;
			sum += A * j; cnt++;
		}

		ans -= 1ULL * numEdge * C * i + sumEdge;
		for(int j: adj[i]){
			if(j >= i) break;
			numEdge++;
			sumEdge += A * j + B * i;
		}
	}

	for(int i = 0; i < n; i++){
		sumAdj[i].push_back(0);
		ll sum = 0;
		for(int j: adj[i]){
			sum += j;
			sumAdj[i].push_back(sum);
		}
		hav[i].assign((int)big.size(), 0);
	}

	for(ll i = 0; i < n; i++){
		for(ll j: adj[i]){
			if(j >= i) break;

			int R = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin() - 1;
			if(R >= 0 && R < adj[j].size() && adj[j][R] < j){
				R++;
				ans += 1ULL * R * (B * j + C * i) + 1ULL * A * sumAdj[j][R];
			}

			int L = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin();
			R = lower_bound(adj[j].begin(), adj[j].end(), i) - adj[j].begin() - 1;
			if(L > R || L < 0 || L >= adj[j].size() || R < 0 || R >= adj[j].size()){
				continue;
			}
			if(adj[j][L] <= j || adj[j][R] >= i){
				continue;
			}
			R++;
			ans += 1ULL * (R - L) * (A * j + C * i) + 1ULL * B * (sumAdj[j][R] - sumAdj[j][L]);
		}
	}

	for(int i = 0; i < n; i++){
		for(int j: adj[i]){
			if(bigSz[j] == 1){
				hav[i][inDex[j]] = 1;
			}
		}
	}

	ll cnt0 = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for(auto e: edge){
		int u = e.first, v = e.second;

		if(bigSz[u] + bigSz[v] == 0){
			int ptr = 0;
			for(int j: adj[u]){
				while(ptr + 1 < adj[v].size() && adj[v][ptr] < j){
					ptr++;
				}
				if(adj[v][ptr] == j){
					if(bigSz[j] == 0){
						if(u < j && j < v){
							cnt0 += calc(u, v, j);
						}
					} else {
						cnt1 += calc(u, v, j);
					}
				}
			}
		}

		if(bigSz[u] + bigSz[v] == 1){
			for(int j: big){
				if(hav[u][inDex[j]] == 1 && hav[v][inDex[j]] == 1){
					if((bigSz[u] == 1 && j < u) || (bigSz[v] == 1 && j < v)){
						cnt2 += calc(u, v, j);
					}
				}
			}
		}

		if(bigSz[u] + bigSz[v] == 2){
			for(int j: big){
				if(hav[u][inDex[j]] == 1 && hav[v][inDex[j]] == 1){
					if(u < j && j < v){
						cnt3 += calc(u, v, j);
					}
				}
			}
		}
	}
	ll res = cnt0 + cnt1 + cnt2 + cnt3;
	ans -= res;

	cout << ans;
}


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

#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = g[i].next)
#define forup(i,l,r) for (register int i = l ; i <= r ; i += lowbit(i))
#define fordown(i,id) for (register int i = id ; i ; i -= lowbit(i))
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define lowbit(x) (x&(-x))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pr;

const int inf = 2e8;
const int N = 6e6 + 10;
const int maxn = 200020;
const ll mod = 998244353;

vector <int> g[maxn];
pr e[maxn];
int head[maxn],cnt,deg[maxn],n,m,tmp,tag[maxn],tot;
bitset <maxn> has[420];
ull ans,A,B,C;

inline ull C2(ull n){
	return n * (n - 1) / 2;
}
ull solve1(){
	ull res = 0;
	rep(i,1,n){
		res += (C * C2(i - 1) + B * (i - 1) * (n - i) + A * C2(n - i)) * (i - 1);
	}
//	cout<<1<<" "<<res<<endl;
	return res;
	//cout<<1<<" "<<res<<endl;
}
inline ull Sum(ull l,ull r){
	if ( l > r ) return 0;
	return (l + r) * (r - l + 1) / 2;
}
ull solve2(){
	ull res = 0;
	rep(i,1,m){
		int x = e[i].fi , y = e[i].se;
	//	res += (A * (x - 1) + B * (y - 1)) * (n - y) + C * Sum(n - y,n - 1) + (A * (x - 1) + C * (y - 1)) * (y - x - 1) + B * Sum(x,y - 2) + (B * (x - 1) + C * (y - 1)) * (x - 1) + A * Sum(0,x - 2);
		ull cur1 = (A * (x - 1) + B * (y - 1)) * (n - y) + C * Sum(y,n - 1);
		ull cur2 = (A * (x - 1) + C * (y - 1)) * (y - x - 1) + B * Sum(x,y - 2);
		ull cur3 = (B * (x - 1) + C * (y - 1)) * (x - 1) + A * Sum(0,x - 2);
		res += cur1 + cur2 + cur3;
	//	cout<<cur1<<" "<<cur2<<" "<<cur3<<" for edge "<<x<<" "<<y<<endl;
	}
//cout<<2<<" "<<res<<endl;
	return res;

}
ull pres[maxn],pres2[maxn],posts[maxn],posts2[maxn];
ull solve3(){
	ull res = 0;
	rep(i,1,n){
		sort(g[i].begin(),g[i].end());
		if ( g[i].size() < 2 ) continue;
		int id = lower_bound(g[i].begin(),g[i].end(),i) - g[i].begin(); //标号强行从1开始
		int tot = g[i].size();
		rep(j,0,id - 1){
			int id = j + 1;

			pres2[id] = pres2[id - 1] + pres[id - 1] * A + B * (id - 1) * (g[i][j] - 1);
			pres[id] = pres[id - 1] + g[i][j] - 1;
		}
		posts[tot + 1] = posts2[tot + 1] = 0;
		repd(j,tot - 1,id){
			int id = j + 1;

			posts2[id] = posts2[id + 1] + posts[id + 1] * C + B * (tot - id) * (g[i][j] - 1);
			posts[id] = posts[id + 1] + g[i][j] - 1;
		}
		ull cur = (C2(id) * C + (tot - id) * id * B + C2(tot - id) * A) * (i - 1) + pres2[id] + posts2[id + 1] + A * pres[id] * (tot - id) + C * posts[id + 1] * id;
		res += cur;
//		cout<<cur<<" for point "<<i<<endl;
	}
//	cout<<3<<" "<<res<<endl;
	return res;
}
int a[maxn],vis[maxn];
inline ull cal(ull x,ull y,ull z){ return A * (x - 1) + B * (y - 1) + C * (z - 1); }
ull solve4(){ //三元环
	ull res = 0;
	tmp = m / 400;
	rep(i,1,n) if ( deg[i] > tmp ){
	   	tag[i] = ++tot , a[tot] = i;
		rvc(j,g[i]){
			has[tot][g[i][j]] = 1;
		}
	}
	rep(i,1,m){
		int x = e[i].fi , y = e[i].se;
		rep(j,1,tot){
			if ( a[j] < x || a[j] < y ) continue;
			if ( has[j][x] && has[j][y] ) res += cal(x,y,a[j]);
		}
	}
	rep(k,1,n){ //枚举最大点
		if ( tag[k] ) continue;
		rvc(j,g[k]){
			if ( g[k][j] > k ) continue;
			vis[g[k][j]] = k;
		}
		rvc(j,g[k]){
			int x = g[k][j];
			if ( tag[x] ){
				rvc(i,g[k]){
					if ( g[k][i] > k ) continue;
					if ( g[k][i] > x && has[tag[x]][g[k][i]] ) res += cal(x,g[k][i],k);
				}
			}
			else{
				rvc(i,g[x]){
					if ( g[x][i] > x && vis[g[x][i]] == k ) res += cal(x,g[x][i],k);
				}
			}
		}
	}
//	cout<<4<<" "<<res<<endl;
	return res;
}
int main(){
//	freopen("input.txt","r",stdin);
	scanf("%d %d",&n,&m);
	cin>>A>>B>>C;
	rep(i,1,m){
		int x,y;
		scanf("%d %d",&x,&y) , x++ , y++;
		if ( x > y ) swap(x,y);
		//adde(x,y) , adde(y,x);
		e[i] = mp(x,y);
		g[x].pb(y) , g[y].pb(x);
	}
	ans = solve1() - solve2() + solve3() - solve4();
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;
const int MAX_N=200005;
int n,m,A,B,C;
int sum_a[MAX_N],sum_b[MAX_N],sum_c[MAX_N];
map<int,bool> G[MAX_N];
vector<int> g[MAX_N];
int ans;
set<vector<int> > S;
signed main()
{
	cin>>n>>m>>A>>B>>C;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		u++,v++;
		g[u].push_back(v);
		g[v].push_back(u);
		G[u][v]=G[v][u]=true;
	}
	for(int i=1;i<=n;i++)sort(g[i].begin(),g[i].end());
	for(int i=1;i<=n;i++)
	{
		if(i<n-1)ans+=A*(i-1)*((n-i)*(n-i-1)/2);
		if(i>1 && i<n)ans+=B*(i-1)*(i-1)*(n-i);
		if(i>2)ans+=C*(i-1)*((i-1)*(i-2)/2);
	}
	for(int i=1;i<=n;i++)
	{
		sum_a[i]=sum_a[i-1]+(i-1)*A;
		sum_b[i]=sum_b[i-1]+(i-1)*B;
		sum_c[i]=sum_c[i-1]+(i-1)*C;
	}
	for(int i=1;i<=n;i++)
	{
		int siz=g[i].size()-1;
		int cnt_0=0,cnt_1=0;
		for(int j=0;j<g[i].size();j++)
		{
			int v=g[i][j];
			if(v<i)cnt_0++;
			else cnt_1++;
			if(v<i)
			{
				ans-=sum_a[v-1]+B*(v-1)*(v-1)+C*(i-1)*(v-1);
				ans+=A*(v-1)*(siz-j)+B*(v-1)*j;
			}
			else
			{
				ans-=A*(i-1)*(n-v)+B*(v-1)*(n-v)+sum_c[n]-sum_c[v];
				ans-=A*(i-1)*(v-i-1)+sum_b[v-1]-sum_b[i]+C*(v-1)*(v-i-1);
				ans+=C*(v-1)*j+B*(v-1)*(siz-j);
			}
		}
		ans+=A*(i-1)*(cnt_1*(cnt_1-1)/2)+B*(i-1)*cnt_0*cnt_1+C*(i-1)*(cnt_0*(cnt_0-1)/2);
	}
	int s=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<g[i].size();j++)
		{
			int u=i,v=g[i][j];
			if(g[u].size()>g[v].size())swap(u,v);
			for(int k=0;k<g[u].size();k++)
			{
				int t=g[u][k];
				if(t==v)continue;
				if(G[v][t])
				{
				//  vector<int> vec={u,v,t};
					vector<int> vec;
					vec.push_back(u);
					vec.push_back(v);
					vec.push_back(t);
					sort(vec.begin(),vec.end());
					if(S.count(vec))continue;
					S.insert(vec);
					s+=(vec[0]-1)*A+(vec[1]-1)*B+(vec[2]-1)*C;
				}
			}
		}
	}
	ans-=s;
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#include<tr1/unordered_map>

#define REP(i,a,b) for(int i=a;i<=b;++i)
#define DREP(i,a,b) for(int i=a;i>=b;--i)
typedef long long ll;

using namespace std;

void File(){
    freopen("20180625T2.in","r",stdin);
    freopen("20180625T2.out","w",stdout);
}

const int maxn=2e5+10;
int n,m;
unsigned long long de[maxn],A,B,C,ans,suma[maxn],sumb[maxn],sumc[maxn];
vector<int>to[maxn];
tr1::unordered_map<int,bool>G[maxn];

void init(){
    scanf("%d%d",&n,&m);
    cin>>A>>B>>C;
    REP(i,1,m){
        int u,v;
        scanf("%d%d",&u,&v);
        ++u; ++v; ++de[u]; ++de[v];
        to[u].push_back(v);
        to[v].push_back(u);
        G[u][v]=1;
        G[v][u]=1;
    }
    REP(i,1,n)sort(to[i].begin(),to[i].end());
}

void cal(){
    REP(i,1,n){
        ans+=A*(i-1)*((ll)(n-i-1)*(n-i)/2);
        ans+=B*(i-1)*(i-1)*(n-i);
        ans+=C*(i-1)*((ll)(i-1)*(i-2)/2);
    }
    REP(i,1,n){
        suma[i]=suma[i-1]+(i-1)*A;
        sumb[i]=sumb[i-1]+(i-1)*B;
        sumc[i]=sumc[i-1]+(i-1)*C;
    }
    REP(i,1,n){
        int siz=to[i].size()-1;
        unsigned long long cnt0=0,cnt1=0;
        REP(j,0,siz){
            int v=to[i][j];
            v<i ? (++cnt0) : (++cnt1);
            if(v<i){
                ans-=suma[v-1]+B*(v-1)*(v-1)+C*(i-1)*(v-1);
                ans+=A*(v-1)*(siz-j)+B*(v-1)*j;
            }
            else{
                ans-=A*(i-1)*(n-v)+B*(v-1)*(n-v)+sumc[n]-sumc[v];
                ans-=A*(i-1)*(v-i-1)+sumb[v-1]-sumb[i]+C*(v-1)*(v-i-1);
                ans+=C*(v-1)*j+B*(v-1)*(siz-j);
            }
        }
        ans+=A*(i-1)*(cnt1*(cnt1-1)/2)+B*(i-1)*cnt0*cnt1+C*(i-1)*cnt0*(cnt0-1)/2;
    }
}

bool cmp(int _,int __){return de[_]<de[__];}

void find_circle(){
    int qu[maxn];
    REP(i,1,n)qu[i]=i;
    sort(qu+1,qu+n+1,cmp);
    int t=1,qq[3];
    while(t+1<=n && de[qu[t+1]]<=sqrt(m))++t;
    unsigned long long s[4]={0};
    REP(i,1,t){
        int u=qu[i],siz=to[u].size()-1;
        REP(j,0,siz)REP(k,j+1,siz)if(G[to[u][j]][to[u][k]]){
            int cnt=0;
            qq[0]=u; qq[1]=to[u][j]; qq[2]=to[u][k];
            REP(l,0,2)if(de[qq[l]]<=sqrt(m))++cnt;
            sort(qq,qq+3);
            s[cnt]+=(qq[0]-1)*A+(qq[1]-1)*B+(qq[2]-1)*C;
        }
    }
    ans-=s[1]+s[2]/2+s[3]/3;
    REP(i,t+1,n)REP(j,i+1,n)REP(k,j+1,n)
        if(G[qu[i]][qu[j]] && G[qu[j]][qu[k]] && G[qu[i]][qu[k]]){
            qq[0]=qu[i]; qq[1]=qu[j]; qq[2]=qu[k];
            sort(qq,qq+3);
            s[0]+=(qq[0]-1)*A+(qq[1]-1)*B+(qq[2]-1)*C;
        }
    ans-=s[0];
}

int main(){
    init();
    cal();
    find_circle();
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;
const int MAX_N=200005;
int n,m,A,B,C;
int sum_a[MAX_N],sum_b[MAX_N],sum_c[MAX_N];
vector<int> g[MAX_N];
int ans;
vector<int> vec[MAX_N];
int vis[MAX_N];
signed main()
{
	cin>>n>>m>>A>>B>>C;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		u++,v++;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=1;i<=n;i++)sort(g[i].begin(),g[i].end());
	for(int i=1;i<=n;i++)
	{
		if(i<n-1)ans+=A*(i-1)*((n-i)*(n-i-1)/2);
		if(i>1 && i<n)ans+=B*(i-1)*(i-1)*(n-i);
		if(i>2)ans+=C*(i-1)*((i-1)*(i-2)/2);
	}
	for(int i=1;i<=n;i++)
	{
		sum_a[i]=sum_a[i-1]+(i-1)*A;
		sum_b[i]=sum_b[i-1]+(i-1)*B;
		sum_c[i]=sum_c[i-1]+(i-1)*C;
	}
	for(int i=1;i<=n;i++)
	{
		int siz=g[i].size()-1;
		int cnt_0=0,cnt_1=0;
		for(int j=0;j<g[i].size();j++)
		{
			int v=g[i][j];
			if(v<i)cnt_0++;
			else cnt_1++;
			if(v<i)
			{
				ans-=sum_a[v-1]+B*(v-1)*(v-1)+C*(i-1)*(v-1);
				ans+=A*(v-1)*(siz-j)+B*(v-1)*j;
			}
			else
			{
				ans-=A*(i-1)*(n-v)+B*(v-1)*(n-v)+sum_c[n]-sum_c[v];
				ans-=A*(i-1)*(v-i-1)+sum_b[v-1]-sum_b[i]+C*(v-1)*(v-i-1);
				ans+=C*(v-1)*j+B*(v-1)*(siz-j);
			}
		}
		ans+=A*(i-1)*(cnt_1*(cnt_1-1)/2)+B*(i-1)*cnt_0*cnt_1+C*(i-1)*(cnt_0*(cnt_0-1)/2);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<g[i].size();j++)
		{
			int u=i,v=g[i][j];
			if(u>v)continue;
			if(g[u].size()<g[v].size())swap(u,v);
			vec[u].push_back(v);
		}
	}
	for(int x=1;x<=n;x++)
	{
		for(int i=0;i<vec[x].size();i++)vis[vec[x][i]]=1;
		for(int i=0;i<vec[x].size();i++)
		{
			int to=vec[x][i];
			for(int j=0;j<vec[to].size();j++)
			{
				if(vis[vec[to][j]])
				{
					vector<int> v;
					v.push_back(x-1);
					v.push_back(to-1);
					v.push_back(vec[to][j]-1);
					sort(v.begin(),v.end());
					ans-=A*v[0]+B*v[1]+C*v[2];
				}
			}
		}
		for(int i=0;i<vec[x].size();i++)vis[vec[x][i]]=0;
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N=200005;
int n,m;
unsigned long long sum_a[MAX_N],sum_b[MAX_N],sum_c[MAX_N],A,B,C;
map<int,bool> G[MAX_N];
vector<int> g[MAX_N];
unsigned long long ans;
set<vector<int> > S;
signed main()
{
	cin>>n>>m>>A>>B>>C;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		u++,v++;
		g[u].push_back(v);
		g[v].push_back(u);
		G[u][v]=G[v][u]=true;
	}
	for(int i=1;i<=n;i++)sort(g[i].begin(),g[i].end());
	for(int i=1;i<=n;i++)
	{
		if(i<n-1)ans+=A*(i-1)*(n-i)*(n-i-1)/2;
		if(i>1 && i<n)ans+=B*(i-1)*(i-1)*(n-i);
		if(i>2)ans+=C*(i-1)*(i-1)*(i-2)/2;
	}
	for(int i=1;i<=n;i++)
	{
		sum_a[i]=sum_a[i-1]+(i-1)*A;
		sum_b[i]=sum_b[i-1]+(i-1)*B;
		sum_c[i]=sum_c[i-1]+(i-1)*C;
	}
	for(int i=1;i<=n;i++)
	{
		int siz=g[i].size()-1;
		unsigned long long cnt_0=0,cnt_1=0;
		for(int j=0;j<g[i].size();j++)
		{
			int v=g[i][j];
			if(v<i)cnt_0++;
			else cnt_1++;
			if(v<i)
			{
				ans-=sum_a[v-1]+B*(v-1)*(v-1)+C*(i-1)*(v-1);
				ans+=A*(v-1)*(siz-j)+B*(v-1)*j;
			}
			else
			{
				ans-=A*(i-1)*(n-v)+B*(v-1)*(n-v)+sum_c[n]-sum_c[v];
				ans-=A*(i-1)*(v-i-1)+sum_b[v-1]-sum_b[i]+C*(v-1)*(v-i-1);
				ans+=C*(v-1)*j+B*(v-1)*(siz-j);
			}/**/
		}
		ans+=A*(i-1)*(cnt_1*(cnt_1-1)/2)+B*(i-1)*cnt_0*cnt_1+C*(i-1)*(cnt_0*(cnt_0-1)/2);
	}
	unsigned long long s=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<g[i].size();j++)
		{
			int u=i,v=g[i][j];
			if(g[u].size()>g[v].size())swap(u,v);
			for(int k=0;k<g[u].size();k++)
			{
				int t=g[u][k];
				if(t==v)continue;
				if(G[v][t])
				{
				//	vector<int> vec={u,v,t};
					vector<int> vec;
					vec.push_back(u);
					vec.push_back(v);
					vec.push_back(t);
					sort(vec.begin(),vec.end());
					if(S.count(vec))continue;
					S.insert(vec);
					s+=(vec[0]-1)*A+(vec[1]-1)*B+(vec[2]-1)*C;/**/
				//	if(u<v && v<t)s+=(u-1)*A+(v-1)*B+(t-1)*C;
				}
			}
		}
	}
//	cout<<ans<<" "<<s<<endl;
//	ans-=s/6;
	ans-=s;
	cout<<ans<<endl;/**/
	return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N=200005;
int n,m;
unsigned long long sum_a[MAX_N],sum_b[MAX_N],sum_c[MAX_N],A,B,C;
map<int,bool> G[MAX_N];
vector<int> g[MAX_N];
unsigned long long ans;
signed main()
{
	cin>>n>>m>>A>>B>>C;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		u++,v++;
		g[u].push_back(v);
		g[v].push_back(u);
		G[u][v]=G[v][u]=true;
	}
	for(int i=1;i<=n;i++)sort(g[i].begin(),g[i].end());
	for(int i=1;i<=n;i++)
	{
		if(i<n-1)ans+=A*(i-1)*(n-i)*(n-i-1)/2;
		if(i>1 && i<n)ans+=B*(i-1)*(i-1)*(n-i);
		if(i>2)ans+=C*(i-1)*(i-1)*(i-2)/2;
	}
	for(int i=1;i<=n;i++)
	{
		sum_a[i]=sum_a[i-1]+(i-1)*A;
		sum_b[i]=sum_b[i-1]+(i-1)*B;
		sum_c[i]=sum_c[i-1]+(i-1)*C;
	}
	for(int i=1;i<=n;i++)
	{
		int siz=g[i].size()-1;
		unsigned long long cnt_0=0,cnt_1=0;
		for(int j=0;j<g[i].size();j++)
		{
			int v=g[i][j];
			if(v<i)cnt_0++;
			else cnt_1++;
			if(v<i)
			{
				ans-=sum_a[v-1]+B*(v-1)*(v-1)+C*(i-1)*(v-1);
				ans+=A*(v-1)*(siz-j)+B*(v-1)*j;
			}
			else
			{
				ans-=A*(i-1)*(n-v)+B*(v-1)*(n-v)+sum_c[n]-sum_c[v];
				ans-=A*(i-1)*(v-i-1)+sum_b[v-1]-sum_b[i]+C*(v-1)*(v-i-1);
				ans+=C*(v-1)*j+B*(v-1)*(siz-j);
			}/**/
		}
		ans+=A*(i-1)*(cnt_1*(cnt_1-1)/2)+B*(i-1)*cnt_0*cnt_1+C*(i-1)*(cnt_0*(cnt_0-1)/2);
	}
	__int128 s=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<g[i].size();j++)
		{
			int u=i,v=g[i][j];
			if(g[u].size()>g[v].size())swap(u,v);
			for(int k=0;k<g[u].size();k++)
			{
				int t=g[u][k];
				if(t==v)continue;
				if(G[v][t])
				{
				//	vector<int> vec={u,v,t};
					vector<int> vec;
					vec.push_back(u);
					vec.push_back(v);
					vec.push_back(t);
					sort(vec.begin(),vec.end());
					s+=(vec[0]-1)*A+(vec[1]-1)*B+(vec[2]-1)*C;
				}
			}
		}
	}
//	cout<<ans<<" "<<s<<endl;
	ans-=s/6;
	cout<<ans<<endl;/**/
	return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N=200005;
int n,m;
unsigned long long sum_a[MAX_N],sum_b[MAX_N],sum_c[MAX_N],A,B,C;
map<int,bool> G[MAX_N];
vector<int> g[MAX_N];
unsigned long long ans;
set<vector<int> > S;
signed main()
{
	cin>>n>>m>>A>>B>>C;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		u++,v++;
		g[u].push_back(v);
		g[v].push_back(u);
		G[u][v]=G[v][u]=true;
	}
	for(int i=1;i<=n;i++)sort(g[i].begin(),g[i].end());
	for(int i=1;i<=n;i++)
	{
		if(i<n-1)ans+=A*(i-1)*(n-i)*(n-i-1)/2;
		if(i>1 && i<n)ans+=B*(i-1)*(i-1)*(n-i);
		if(i>2)ans+=C*(i-1)*(i-1)*(i-2)/2;
	}
	for(int i=1;i<=n;i++)
	{
		sum_a[i]=sum_a[i-1]+(i-1)*A;
		sum_b[i]=sum_b[i-1]+(i-1)*B;
		sum_c[i]=sum_c[i-1]+(i-1)*C;
	}
	for(int i=1;i<=n;i++)
	{
		int siz=g[i].size()-1;
		unsigned long long cnt_0=0,cnt_1=0;
		for(int j=0;j<g[i].size();j++)
		{
			int v=g[i][j];
			if(v<i)cnt_0++;
			else cnt_1++;
			if(v<i)
			{
				ans-=sum_a[v-1]+B*(v-1)*(v-1)+C*(i-1)*(v-1);
				ans+=A*(v-1)*(siz-j)+B*(v-1)*j;
			}
			else
			{
				ans-=A*(i-1)*(n-v)+B*(v-1)*(n-v)+sum_c[n]-sum_c[v];
				ans-=A*(i-1)*(v-i-1)+sum_b[v-1]-sum_b[i]+C*(v-1)*(v-i-1);
				ans+=C*(v-1)*j+B*(v-1)*(siz-j);
			}/**/
		}
		ans+=A*(i-1)*(cnt_1*(cnt_1-1)/2)+B*(i-1)*cnt_0*cnt_1+C*(i-1)*(cnt_0*(cnt_0-1)/2);
	}
	__int128 s=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<g[i].size();j++)
		{
			int u=i,v=g[i][j];
			if(g[u].size()>g[v].size())swap(u,v);
			for(int k=0;k<g[u].size();k++)
			{
				int t=g[u][k];
				if(t==v)continue;
				if(G[v][t])
				{
				//	vector<int> vec={u,v,t};
					vector<int> vec;
					vec.push_back(u);
					vec.push_back(v);
					vec.push_back(t);
					sort(vec.begin(),vec.end());
					if(S.count(vec))continue;
					S.insert(vec);
					s+=(vec[0]-1)*A+(vec[1]-1)*B+(vec[2]-1)*C;/**/
				//	if(u<v && v<t)s+=(u-1)*A+(v-1)*B+(t-1)*C;
				}
			}
		}
	}
//	cout<<ans<<" "<<s<<endl;
//	ans-=s/6;
	ans-=s;
	cout<<ans<<endl;/**/
	return 0;
}


#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
#define il inline
#define ull unsigned long long
#define _(d) while(d(isdigit(ch=getchar())))
using namespace std;
const int N=2e5+5;
bool vis[N];
ull A,B,C,ans;
int n,m,q[4],in[N];
struct node{
    int l,r;
}t[N];
vector<int> g[N];
il int read(){
    int x,f=1;char ch;
    _(!)ch=='-'?f=-1:f;x=ch^48;
    _()x=(x<<1)+(x<<3)+(ch^48);
    return f*x;
}
int main()
{
    n=read();m=read();
    scanf("%llu%llu%llu",&A,&B,&C);
    for(int i=1;i<=n;i++){
        if(i<n-1)ans+=A*(ull)(1ll*(n-i)*(n-i-1)/2)*(i-1);
        if(i!=1&&i!=n)ans+=B*(ull)(1ll*(i-1)*(n-i))*(i-1);
        if(i>2)ans+=C*(ull)(1ll*(i-1)*(i-2)/2)*(i-1);
    }
    for(int i=1;i<=m;i++){
        int x=read()+1,y=read()+1;
        in[x]++;in[y]++;
        t[i]=(node){x,y};
        if(x>y)swap(x,y);
        ans-=(ull)(B*(x-1)+C*(y-1))*(ull)(x-1)+A*(ull)(1ll*(x-1)*(x-2)/2ll);
        ans-=(ull)(A*(x-1)+C*(y-1))*(ull)(y-x-1)+B*(ull)(1ll*(y-x-1)*(x+y-2)/2ll);
        ans-=(ull)(A*(x-1)+B*(y-1))*(ull)(n-y)+C*(ull)(1ll*(n-y)*(y-1+n)/2ll);
        g[x].push_back(y);g[y].push_back(x);
    }
    for(int i=1;i<=n;i++)sort(g[i].begin(),g[i].end());
    for(int x=1;x<=n;x++){
        int sz=g[x].size()-1;
        int num1=0,num2=0;
        for(int i=0;i<=sz;i++){
            int to=g[x][i];
            if(to<x){
                num1++;
                ans+=A*(to-1)*(sz-i)+B*(to-1)*i;
            }
            else{
                num2++;
                ans+=B*(to-1)*(sz-i)+C*(to-1)*i;
            }
        }
        ans+=(ull)(x-1)*(A*(1ll*num2*(num2-1)/2)+B*(1ll*num1*num2)+C*(1ll*num1*(num1-1)/2));
    }
    for(int i=1;i<=n;i++)g[i].clear();
    for(int i=1;i<=m;i++){
        int x=t[i].l,y=t[i].r;
        if(in[x]<in[y]||(in[x]==in[y]&&x>y))swap(x,y);
        g[x].push_back(y);
    }
    for(int x=1;x<=n;x++){
        for(int i=0;i<g[x].size();i++)vis[g[x][i]]=1;
        for(int i=0;i<g[x].size();i++){
            int to=g[x][i];
            for(int j=0;j<g[to].size();j++){
                if(vis[g[to][j]]){
                    q[1]=x-1;q[2]=to-1;q[3]=g[to][j]-1;
                    sort(q+1,q+4);
                    ans-=A*q[1]+B*q[2]+C*q[3];
                }
            }
        }
        for(int i=0;i<g[x].size();i++)vis[g[x][i]]=0;
    }
    printf("%llu\n",ans);
    return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define endl "\n"
#define int unsigned long long
#define ii pair<int, int>
#define pb push_back
#define HANH "PARKSEO"
using namespace std;

const int N=2e5+5;
int n, m, x1, x2, x3, kt[N];
int a[N], b[N], c[N];
ii f[N];
vector <int> dau[N], cuoi[N];
int A, B, C, kq, g1, mod;

void tinh(int vt)
{
    int AA, CC, sa, sc, t, aa;
    AA=a[vt-1]; CC=c[vt+1]; sa=vt-1; sc=n-vt;
    t=b[vt]-b[vt-1];
    kq+=AA*sc+CC*sa+t*sa*sc;
    for(int i=0; i<cuoi[vt].size(); ++i){
        int xx=cuoi[vt][i];
        //if(kt[xx]==vt) continue;
        //kt[xx]=vt;
        sa-=1;
        aa=a[xx]-a[xx-1];
        kq-=aa*sc+t*sc+CC;
        AA-=aa;
    }
    for(int i=0; i<dau[vt].size(); ++i){
        int xx=dau[vt][i];
        //if(kt[xx]==vt) continue;
        // kt[xx]=vt;
        aa=c[xx]-c[xx+1];
        kq-=aa*sa+t*sa+AA;
    }
}

void tinh1(int k, int u, int v)
{
    if(u==v-1) return;
    int AA, CC, BB, sl, bb;
    AA=a[u]-a[u-1];
    CC=c[v]-c[v+1];
    BB=b[v-1]-b[u];
    sl=v-u-1;
    for(int i=0; i<dau[u].size(); ++i){
        int xx=dau[u][i];
        if(kt[xx]==k || xx<=u || xx>=v) continue;
        kt[xx]=k;
        bb=b[xx]-b[xx-1];
        kq+=AA+bb+CC;
    }
    for(int i=0; i<cuoi[v].size(); ++i){
        int xx=cuoi[v][i];
        if(kt[xx]==k || xx<=u || xx>=v) continue;
        kt[xx]=k;
        bb=b[xx]-b[xx-1];
        kq+=AA+bb+CC;
    }
    kq-=(AA+CC)*sl+BB;
}

main()
{
    ios_base::sync_with_stdio(0);
    scanf("%I64u%I64u%I64u%I64u%I64u", &n, &m, &x1, &x2, &x3);
    A=x1; B=x2; C=x3;
    for(int i=1; i<=n; ++i){
        a[i]=a[i-1]+1ll*x1*(i-1);
        b[i]=b[i-1]+1ll*x2*(i-1);
    }
    for(int i=n; i>0; --i) c[i]=c[i+1]+1ll*x3*(i-1);
    for(int i=1; i<=m; ++i){
        scanf("%I64u%I64u", &f[i].x, &f[i].y);
        ++f[i].x; ++f[i].y;
        if(f[i].x>f[i].y) swap(f[i].x, f[i].y);
        if(f[i].y>n) continue;
        dau[f[i].x].pb(f[i].y);
        cuoi[f[i].y].pb(f[i].x);
    }
    for(int i=2; i<n; ++i) tinh(i);
    memset(kt, 0, sizeof(kt));
    for(int i=1; i<=m; ++i) if(f[i].y<=n) tinh1(i, f[i].x, f[i].y);
    printf("%I64u", kq);
    return 0;
}


/* Author haleyk10198 */
/* �@��:  haleyk10198 */
/* CF handle: haleyk100198*/
/* FOR ACM-ICPC WF*/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using ull = unsigned long long;

#define pb push_back

constexpr auto MAGIC = 300;

constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL<<60);
constexpr auto INF = 2147483647LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2> p){
	out << p.first << ' ' << p.second;
	return out;
}

template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2> &p){
	in >> p.first >> p.second;
	return in;
}

auto printVector = []<typename T>(ostream& out, vector<T> v){
	copy(v.begin(), v.end(), ostream_iterator<T>(out, " "));
};

constexpr auto MAXN = 100010;

int n, m;
ull a, b, c, res;
ull all, one, two, three;

vi e[MAXN];
vi st[MAXN];

pii p[MAXN];

/*
	include: all
	exclude: one pair
	include: two pair
	exclude: three pair
*/

int main(){
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
//		freopen("output.txt","w",stdout);
		freopen("debug.txt", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);

	cin >> n >> m >> a >> b >> c;

	for(int i = 0; i < n; i++){
		res += 1LL*i*i*(i-1)/2*c;
		all += 1LL*i*i*(i-1)/2*c;
		res += 1LL*i*i*(n-1-i)*b;
		all += 1LL*i*i*(n-1-i)*b;
		res += 1LL*i*(n-1-i)*(n-1-i-1)/2*a;
		all += 1LL*i*(n-1-i)*(n-1-i-1)/2*a;
	}

	for(int i = 0, x, y; i < m; i++){
		cin >> x >> y;
		e[x].pb(y);
		e[y].pb(x);

		if(x > y)
			swap(x, y);

		p[i] = pair(x, y);

		//left
		res -= 1LL*x*(x-1)/2*a;
		one -= 1LL*x*(x-1)/2*a;
		res -= 1LL*x*x*b;
		one -= 1LL*x*x*b;
		res -= 1LL*x*y*c;
		one -= 1LL*x*y*c;

		//mid
		res -= 1LL*x*(y-x-1)*a;
		one -= 1LL*x*(y-x-1)*a;
		res -= 1LL*(y-x-1)*(x+1+y-1)/2*b;
		one -= 1LL*(y-x-1)*(x+1+y-1)/2*b;
		res -= 1LL*y*(y-x-1)*c;
		one -= 1LL*y*(y-x-1)*c;

		//right
		res -= 1LL*x*(n-y-1)*a;
		one -= 1LL*x*(n-y-1)*a;
		res -= 1LL*y*(n-y-1)*b;
		one -= 1LL*y*(n-y-1)*b;
		res -= 1LL*(n-y-1)*(y+1+n-1)/2*c;
		one -= 1LL*(n-y-1)*(y+1+n-1)/2*c;
	}

	for(int i = 0; i < n; i++){
		sort(e[i].begin(), e[i].end());

		//both left
		int pos = upper_bound(e[i].begin(), e[i].end(), i)-e[i].begin();
		ll tot = accumulate(e[i].begin(), e[i].begin()+pos, 0LL); ll totl = tot;
		for(int j = 0; j < pos; j++){
			tot -= e[i][j];
			res += 1LL*e[i][j]*(pos-j-1)*a;
			two += 1LL*e[i][j]*(pos-j-1)*a;
			res += 1LL*tot*b;
			two += 1LL*tot*b;
			res += 1LL*i*(pos-j-1)*c;
			two += 1LL*i*(pos-j-1)*c;
		}

		//at mid
		int lcnt = pos, rcnt = e[i].size()-pos;
		ll totr = accumulate(e[i].begin()+pos, e[i].end(), 0LL);

		res += 1LL*totl*rcnt*a;
		two += 1LL*totl*rcnt*a;
		res += 1LL*i*lcnt*rcnt*b;
		two += 1LL*i*lcnt*rcnt*b;
		res += 1LL*totr*lcnt*c;
		two += 1LL*totr*lcnt*c;

		//both right
		tot = totr;
		for(int j = pos; j < e[i].size(); j++){
			tot -= e[i][j];
			res += 1LL*(e[i].size()-j-1)*i*a;
			two += 1LL*(e[i].size()-j-1)*i*a;
			res += 1LL*e[i][j]*(e[i].size()-j-1)*b;
			two += 1LL*e[i][j]*(e[i].size()-j-1)*b;
			res += 1LL*tot*c;
			two += 1LL*tot*c;
		}
	}

	//three

	vi magicnums;
	for(int i = 0; i < n; i++){
		while(e[i].size() && e[i].back() > i){
			e[i].pop_back();
		}
		if(e[i].size() >= MAGIC){
			st[i] = vi(n, 0);
			for(auto x: e[i])
				st[i][x] = 1;
			magicnums.pb(i);
		}
	}

	for(auto x: magicnums){
		for(int i = 0; i < m; i++){
			auto [y, z] = p[i];

			if(z < x){
				if(st[x][y] && st[x][z]){
					res -= 1LL*y*a;
					three -= 1LL*y*a;
					res -= 1LL*z*b;
					three -= 1LL*z*b;
					res -= 1LL*x*c;
					three -= 1LL*x*c;
				}
			}
		}
	}

	for(int i = 0; i < n; i++){
		if(st[i].empty()){
			//no magic
			for(int j = 0; j < e[i].size(); j++){
				int y = e[i][j];
				for(int k = 0, z; k < e[i].size(); k++){
					z = e[i][k];
					if(binary_search(e[z].begin(), e[z].end(), y)){
						res -= 1LL*y*a;
						three -= 1LL*y*a;
						res -= 1LL*z*b;
						three -= 1LL*z*b;
						res -= 1LL*i*c;
						three -= 1LL*i*c;
					}
				}
			}
		}
	}

	cout << res << endl;

	#ifdef LOCAL
		cerr << all << ' ' << -one << ' ' << two << ' ' << -three << endl;
	#endif

	return 0;
}


/* Author haleyk10198 */
/* �@��:  haleyk10198 */
/* CF handle: haleyk100198*/
/* FOR ACM-ICPC WF*/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using ull = unsigned long long;

#define pb push_back

constexpr auto MAGIC = 300;

constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL<<60);
constexpr auto INF = 2147483647LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2> p){
	out << p.first << ' ' << p.second;
	return out;
}

template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2> &p){
	in >> p.first >> p.second;
	return in;
}

auto printVector = []<typename T>(ostream& out, vector<T> v){
	copy(v.begin(), v.end(), ostream_iterator<T>(out, " "));
};

constexpr auto MAXN = 200010;

int n, m;
ull a, b, c, res;
ull all, one, two, three;

vi e[MAXN];
vi st[MAXN];

pii p[MAXN];

/*
	include: all
	exclude: one pair
	include: two pair
	exclude: three pair
*/

int main(){
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
//		freopen("output.txt","w",stdout);
		freopen("debug.txt", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);

	cin >> n >> m >> a >> b >> c;

	for(int i = 0; i < n; i++){
		res += 1LL*i*i*(i-1)/2*c;
		all += 1LL*i*i*(i-1)/2*c;
		res += 1LL*i*i*(n-1-i)*b;
		all += 1LL*i*i*(n-1-i)*b;
		res += 1LL*i*(n-1-i)*(n-1-i-1)/2*a;
		all += 1LL*i*(n-1-i)*(n-1-i-1)/2*a;
	}

	for(int i = 0, x, y; i < m; i++){
		cin >> x >> y;
		e[x].pb(y);
		e[y].pb(x);

		if(x > y)
			swap(x, y);

		p[i] = pair(x, y);

		//left
		res -= 1LL*x*(x-1)/2*a;
		one -= 1LL*x*(x-1)/2*a;
		res -= 1LL*x*x*b;
		one -= 1LL*x*x*b;
		res -= 1LL*x*y*c;
		one -= 1LL*x*y*c;

		//mid
		res -= 1LL*x*(y-x-1)*a;
		one -= 1LL*x*(y-x-1)*a;
		res -= 1LL*(y-x-1)*(x+1+y-1)/2*b;
		one -= 1LL*(y-x-1)*(x+1+y-1)/2*b;
		res -= 1LL*y*(y-x-1)*c;
		one -= 1LL*y*(y-x-1)*c;

		//right
		res -= 1LL*x*(n-y-1)*a;
		one -= 1LL*x*(n-y-1)*a;
		res -= 1LL*y*(n-y-1)*b;
		one -= 1LL*y*(n-y-1)*b;
		res -= 1LL*(n-y-1)*(y+1+n-1)/2*c;
		one -= 1LL*(n-y-1)*(y+1+n-1)/2*c;
	}

	for(int i = 0; i < n; i++){
		sort(e[i].begin(), e[i].end());

		//both left
		int pos = upper_bound(e[i].begin(), e[i].end(), i)-e[i].begin();
		ll tot = accumulate(e[i].begin(), e[i].begin()+pos, 0LL); ll totl = tot;
		for(int j = 0; j < pos; j++){
			tot -= e[i][j];
			res += 1LL*e[i][j]*(pos-j-1)*a;
			two += 1LL*e[i][j]*(pos-j-1)*a;
			res += 1LL*tot*b;
			two += 1LL*tot*b;
			res += 1LL*i*(pos-j-1)*c;
			two += 1LL*i*(pos-j-1)*c;
		}

		//at mid
		int lcnt = pos, rcnt = e[i].size()-pos;
		ll totr = accumulate(e[i].begin()+pos, e[i].end(), 0LL);

		res += 1LL*totl*rcnt*a;
		two += 1LL*totl*rcnt*a;
		res += 1LL*i*lcnt*rcnt*b;
		two += 1LL*i*lcnt*rcnt*b;
		res += 1LL*totr*lcnt*c;
		two += 1LL*totr*lcnt*c;

		//both right
		tot = totr;
		for(int j = pos; j < e[i].size(); j++){
			tot -= e[i][j];
			res += 1LL*(e[i].size()-j-1)*i*a;
			two += 1LL*(e[i].size()-j-1)*i*a;
			res += 1LL*e[i][j]*(e[i].size()-j-1)*b;
			two += 1LL*e[i][j]*(e[i].size()-j-1)*b;
			res += 1LL*tot*c;
			two += 1LL*tot*c;
		}
	}

	//three

	vi magicnums;
	for(int i = 0; i < n; i++){
		while(e[i].size() && e[i].back() > i){
			e[i].pop_back();
		}
		if(e[i].size() >= MAGIC){
			st[i] = vi(n, 0);
			for(auto x: e[i])
				st[i][x] = 1;
			magicnums.pb(i);
		}
	}

	for(auto x: magicnums){
		for(int i = 0; i < m; i++){
			auto [y, z] = p[i];

			if(z < x){
				if(st[x][y] && st[x][z]){
					res -= 1LL*y*a;
					three -= 1LL*y*a;
					res -= 1LL*z*b;
					three -= 1LL*z*b;
					res -= 1LL*x*c;
					three -= 1LL*x*c;
				}
			}
		}
	}

	for(int i = 0; i < n; i++){
		if(st[i].empty()){
			//no magic
			for(int j = 0; j < e[i].size(); j++){
				int y = e[i][j];
				for(int k = 0, z; k < e[i].size(); k++){
					z = e[i][k];
					if(binary_search(e[z].begin(), e[z].end(), y)){
						res -= 1LL*y*a;
						three -= 1LL*y*a;
						res -= 1LL*z*b;
						three -= 1LL*z*b;
						res -= 1LL*i*c;
						three -= 1LL*i*c;
					}
				}
			}
		}
	}

	cout << res << endl;

	#ifdef LOCAL
		cerr << all << ' ' << -one << ' ' << two << ' ' << -three << endl;
	#endif

	return 0;
}


/* Author haleyk10198 */
/* �@��:  haleyk10198 */
/* CF handle: haleyk100198*/
/* FOR ACM-ICPC WF*/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using ull = unsigned long long;

#define pb push_back

constexpr auto MAGIC = 420;

constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL<<60);
constexpr auto INF = 2147483647LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2> p){
	out << p.first << ' ' << p.second;
	return out;
}

template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2> &p){
	in >> p.first >> p.second;
	return in;
}

auto printVector = []<typename T>(ostream& out, vector<T> v){
	copy(v.begin(), v.end(), ostream_iterator<T>(out, " "));
};

constexpr auto MAXN = 200010;

int n, m;
ull a, b, c, res;
ull all, one, two, three;

vi e[MAXN];
vi st[MAXN];

pii p[MAXN];

/*
	include: all
	exclude: one pair
	include: two pair
	exclude: three pair
*/

int main(){
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
//		freopen("output.txt","w",stdout);
		freopen("debug.txt", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);

	cin >> n >> m >> a >> b >> c;

	for(int i = 0; i < n; i++){
		res += 1LL*i*i*(i-1)/2*c;
		all += 1LL*i*i*(i-1)/2*c;
		res += 1LL*i*i*(n-1-i)*b;
		all += 1LL*i*i*(n-1-i)*b;
		res += 1LL*i*(n-1-i)*(n-1-i-1)/2*a;
		all += 1LL*i*(n-1-i)*(n-1-i-1)/2*a;
	}

	for(int i = 0, x, y; i < m; i++){
		cin >> x >> y;
		e[x].pb(y);
		e[y].pb(x);

		if(x > y)
			swap(x, y);

		p[i] = pair(x, y);

		//left
		res -= 1LL*x*(x-1)/2*a;
		one -= 1LL*x*(x-1)/2*a;
		res -= 1LL*x*x*b;
		one -= 1LL*x*x*b;
		res -= 1LL*x*y*c;
		one -= 1LL*x*y*c;

		//mid
		res -= 1LL*x*(y-x-1)*a;
		one -= 1LL*x*(y-x-1)*a;
		res -= 1LL*(y-x-1)*(x+1+y-1)/2*b;
		one -= 1LL*(y-x-1)*(x+1+y-1)/2*b;
		res -= 1LL*y*(y-x-1)*c;
		one -= 1LL*y*(y-x-1)*c;

		//right
		res -= 1LL*x*(n-y-1)*a;
		one -= 1LL*x*(n-y-1)*a;
		res -= 1LL*y*(n-y-1)*b;
		one -= 1LL*y*(n-y-1)*b;
		res -= 1LL*(n-y-1)*(y+1+n-1)/2*c;
		one -= 1LL*(n-y-1)*(y+1+n-1)/2*c;
	}

	for(int i = 0; i < n; i++){
		sort(e[i].begin(), e[i].end());

		//both left
		int pos = upper_bound(e[i].begin(), e[i].end(), i)-e[i].begin();
		ll tot = accumulate(e[i].begin(), e[i].begin()+pos, 0LL); ll totl = tot;
		for(int j = 0; j < pos; j++){
			tot -= e[i][j];
			res += 1LL*e[i][j]*(pos-j-1)*a;
			two += 1LL*e[i][j]*(pos-j-1)*a;
			res += 1LL*tot*b;
			two += 1LL*tot*b;
			res += 1LL*i*(pos-j-1)*c;
			two += 1LL*i*(pos-j-1)*c;
		}

		//at mid
		int lcnt = pos, rcnt = e[i].size()-pos;
		ll totr = accumulate(e[i].begin()+pos, e[i].end(), 0LL);

		res += 1LL*totl*rcnt*a;
		two += 1LL*totl*rcnt*a;
		res += 1LL*i*lcnt*rcnt*b;
		two += 1LL*i*lcnt*rcnt*b;
		res += 1LL*totr*lcnt*c;
		two += 1LL*totr*lcnt*c;

		//both right
		tot = totr;
		for(int j = pos; j < e[i].size(); j++){
			tot -= e[i][j];
			res += 1LL*(e[i].size()-j-1)*i*a;
			two += 1LL*(e[i].size()-j-1)*i*a;
			res += 1LL*e[i][j]*(e[i].size()-j-1)*b;
			two += 1LL*e[i][j]*(e[i].size()-j-1)*b;
			res += 1LL*tot*c;
			two += 1LL*tot*c;
		}
	}

	//three

	vi magicnums;
	for(int i = 0; i < n; i++){
		while(e[i].size() && e[i].back() > i){
			e[i].pop_back();
		}
		if(e[i].size() >= MAGIC){
			st[i] = vi(n, 0);
			for(auto x: e[i])
				st[i][x] = 1;
			magicnums.pb(i);
		}
	}

	for(auto x: magicnums){
		for(int i = 0; i < m; i++){
			auto [y, z] = p[i];

			if(z < x){
				if(st[x][y] && st[x][z]){
					res -= 1LL*y*a;
					three -= 1LL*y*a;
					res -= 1LL*z*b;
					three -= 1LL*z*b;
					res -= 1LL*x*c;
					three -= 1LL*x*c;
				}
			}
		}
	}

	for(int i = 0; i < n; i++){
		if(st[i].empty()){
			//no magic
			for(int j = 0; j < e[i].size(); j++){
				int y = e[i][j];
				for(int k = 0, z; k < e[i].size(); k++){
					z = e[i][k];
					if(binary_search(e[z].begin(), e[z].end(), y)){
						res -= 1LL*y*a;
						three -= 1LL*y*a;
						res -= 1LL*z*b;
						three -= 1LL*z*b;
						res -= 1LL*i*c;
						three -= 1LL*i*c;
					}
				}
			}
		}
	}

	cout << res << endl;

	#ifdef LOCAL
		cerr << all << ' ' << -one << ' ' << two << ' ' << -three << endl;
	#endif

	return 0;
}


// Can U hack it?

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=2e5+10,mod=1e9;

ll ls[maxn];
pii arr[maxn];
int pl[maxn];
bool is[maxn];
vector<int>v[maxn];
ll a,b,c;
int n,m;

inline ll Sum(ll n){
    return ((n*(n+1))/2);
}

ll solve0(){
    ll ans=0;
    for(int i=0;i<n;i++)
	ans+=1ll*i*a*(1ll*(n-1-i)*(n-2-i)/2);
    for(int i=0;i<n;i++)
	ans+=1ll*i*c*(1ll*i*(i-1)/2);
    for(int i=0;i<n;i++)
	ans+=1ll*i*b*i*(n-1-i);
    return ans;
}

ll solve1(){
    ll ans=0,rm=0;
    for(int i=0;i<n;i++){
	fill(ls,ls+sz(v[i])+3,0);
	ll sm=Sum(n-1)-i;
	int pos=-1;
	for(int j=0;j<sz(v[i]);j++){
	    sm-=v[i][j];
	    int bf=j==0?0:v[i][j-1];
	    ls[j]=1ll*(j==0?0:ls[j-1])+Sum(v[i][j]-1)-(j==0?0:Sum(v[i][j-1]))-1ll*i*(bf<=i && i<=v[i][j]);
	    if(v[i][j]<i) pos=j;
	}
	ll smd=(pos==-1?0:ls[pos])+Sum(i-1)-(pos==-1?0:Sum(v[i][pos]));
	for(int j=0;j<sz(v[i]);j++){
	    if(v[i][j]<i){
		ll cnt1=v[i][j]-j,cnt2=i-v[i][j]-1-pos+j,cnt3=n-i-sz(v[i])+pos;
		ll num=1ll*a*(ls[j]+1ll*v[i][j]*(cnt2+cnt3))+1ll*b*(1ll*cnt1*v[i][j]+smd-ls[j]+1ll*i*cnt3)+1ll*c*(1ll*i*(cnt1+cnt2)+sm-smd);
		if(num&1) rm++,num--;
		ans+=num/2;
	    }
	    else{
		ll cnt1=i-1-pos,cnt2=v[i][j]-i-j+pos,cnt3=n-v[i][j]-sz(v[i])+j;
		ll num=1ll*a*(smd+1ll*i*(cnt2+cnt3))+1ll*b*(1ll*i*cnt1+ls[j]-smd+1ll*v[i][j]*cnt3)+1ll*c*(1ll*v[i][j]*(cnt1+cnt2)+sm-ls[j]);
		if(num&1) rm++,num--;
		ans+=num/2;
	    }
	}
    }
    ans+=rm/2;
    return ans;
}

ll solve2(){
    for(int i=0;i<n;i++)
	arr[i]={sz(v[i]),i};
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
	pl[arr[i].S]=i;
    ll ans=0;
    for(int k=0;k<n;k++){
	for(int u:v[k])
	    is[u]=1;
	for(int j:v[k]){
	    if(pl[k]<=pl[j])continue;
	    for(int i:v[j]){
		if(pl[j]<=pl[i])continue;
		if(is[i]) ans+=1ll*a*i+1ll*b*j+1ll*c*k;
	    }
	}
	for(int u:v[k])
	    is[u]=0;
    }
    return ans;
}

int main(){
    scanf("%d%d",&n,&m);
    scanf("%lld%lld%lld",&a,&b,&c);
    for(int i=0;i<m;i++){
	int a,b;scanf("%d%d",&a,&b);
	v[a].PB(b);v[b].PB(a);
    }
    for(int i=0;i<n;i++)
	sort(v[i].begin(),v[i].end());
    solve1();
    ll ans=solve0()-solve1()-solve2();
    if(ans<0) ans=(~(-ans))+1;
    printf("%lld\n",ans);
    return 0;
}


// Can U hack it?

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=2e5+10,mod=1e9;

ll ls[maxn];
pii arr[maxn];
int pl[maxn];
bool is[maxn];
vector<int>v[maxn];
ll a,b,c;
int n,m;

inline ll Sum(ll n){
    return ((n*(n+1))/2);
}

ll solve0(){
    ll ans=0;
    for(int i=0;i<n;i++)
	ans+=1ll*i*a*(1ll*(n-1-i)*(n-2-i)/2);
    for(int i=0;i<n;i++)
	ans+=1ll*i*c*(1ll*i*(i-1)/2);
    for(int i=0;i<n;i++)
	ans+=1ll*i*b*i*(n-1-i);
    return ans;
}

ll solve1(){
    ll ans=0,rm=0;
    for(int i=0;i<n;i++){
	fill(ls,ls+sz(v[i])+3,0);
	ll sm=Sum(n-1)-i;
	int pos=-1;
	for(int j=0;j<sz(v[i]);j++){
	    sm-=v[i][j];
	    int bf=j==0?0:v[i][j-1];
	    ls[j]=1ll*(j==0?0:ls[j-1])+Sum(v[i][j]-1)-(j==0?0:Sum(v[i][j-1]))-1ll*i*(bf<=i && i<=v[i][j]);
	    if(v[i][j]<i) pos=j;
	}
	ll smd=(pos==-1?0:ls[pos])+Sum(i-1)-(pos==-1?0:Sum(v[i][pos]));
	for(int j=0;j<sz(v[i]);j++){
	    if(v[i][j]<i){
		ll cnt1=v[i][j]-j,cnt2=i-v[i][j]-1-pos+j,cnt3=n-i-sz(v[i])+pos;
		ll num=1ll*a*(ls[j]+1ll*v[i][j]*(cnt2+cnt3))+1ll*b*(1ll*cnt1*v[i][j]+smd-ls[j]+1ll*i*cnt3)+1ll*c*(1ll*i*(cnt1+cnt2)+sm-smd);
		if(num&1) rm++,num--;
		ans+=num/2;
	    }
	    else{
		ll cnt1=i-1-pos,cnt2=v[i][j]-i-j+pos,cnt3=n-v[i][j]-sz(v[i])+j;
		ll num=1ll*a*(smd+1ll*i*(cnt2+cnt3))+1ll*b*(1ll*i*cnt1+ls[j]-smd+1ll*v[i][j]*cnt3)+1ll*c*(1ll*v[i][j]*(cnt1+cnt2)+sm-ls[j]);
		if(num&1) rm++,num--;
		ans+=num/2;
	    }
	}
    }
    ans+=rm/2;
    return ans;
}

ll solve2(){
    for(int i=0;i<n;i++)
	arr[i]={sz(v[i]),i};
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
	pl[arr[i].S]=i;
    ll ans=0;
    for(int k=0;k<n;k++){
	for(int u:v[k])
	    is[u]=1;
	for(int j:v[k]){
	    if(pl[k]<=pl[j])continue;
	    for(int i:v[j]){
		if(pl[j]<=pl[i])continue;
		if(is[i]) ans+=1ll*a*i+1ll*b*j+1ll*c*k;
	    }
	}
	for(int u:v[k])
	    is[u]=0;
    }
    return ans;
}

int main(){
    scanf("%d%d",&n,&m);
    scanf("%lld%lld%lld",&a,&b,&c);
    for(int i=0;i<m;i++){
	int a,b;scanf("%d%d",&a,&b);
	v[a].PB(b);v[b].PB(a);
    }
    for(int i=0;i<n;i++)
	sort(v[i].begin(),v[i].end());
    solve1();
    ll ans=solve0()-solve1()-solve2();
    unsigned long long ANS=(ans>=0?ans:(~(-ans))+1);
    printf("%llu\n",ANS);
    return 0;
}


// Can U hack it?

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=2e5+10,mod=1e9;

ll ls[maxn];
pii arr[maxn];
int pl[maxn];
bool is[maxn];
vector<int>v[maxn];
ll a,b,c;
int n,m;

inline ll Sum(ll n){
    return ((n*(n+1))/2);
}

ll solve0(){
    ll ans=0;
    for(int i=0;i<n;i++)
	ans+=1ll*i*a*(1ll*(n-1-i)*(n-2-i)/2);
    for(int i=0;i<n;i++)
	ans+=1ll*i*c*(1ll*i*(i-1)/2);
    for(int i=0;i<n;i++)
	ans+=1ll*i*b*i*(n-1-i);
    return ans;
}

ll solve1(){
    ll ans=0,rm=0;
    for(int i=0;i<n;i++){
	fill(ls,ls+sz(v[i])+3,0);
	ll sm=Sum(n-1)-i;
	int pos=-1;
	for(int j=0;j<sz(v[i]);j++){
	    sm-=v[i][j];
	    int bf=j==0?0:v[i][j-1];
	    ls[j]=1ll*(j==0?0:ls[j-1])+Sum(v[i][j]-1)-(j==0?0:Sum(v[i][j-1]))-1ll*i*(bf<=i && i<=v[i][j]);
	    if(v[i][j]<i) pos=j;
	}
	ll smd=(pos==-1?0:ls[pos])+Sum(i-1)-(pos==-1?0:Sum(v[i][pos]));
	for(int j=0;j<sz(v[i]);j++){
	    if(v[i][j]<i){
		ll cnt1=v[i][j]-j,cnt2=i-v[i][j]-1-pos+j,cnt3=n-i-sz(v[i])+pos;
		ll num=1ll*a*(ls[j]+1ll*v[i][j]*(cnt2+cnt3))+1ll*b*(1ll*cnt1*v[i][j]+smd-ls[j]+1ll*i*cnt3)+1ll*c*(1ll*i*(cnt1+cnt2)+sm-smd);
		if(num&1) rm++,num--;
		ans+=num/2;
	    }
	    else{
		ll cnt1=i-1-pos,cnt2=v[i][j]-i-j+pos,cnt3=n-v[i][j]-sz(v[i])+j;
		ll num=1ll*a*(smd+1ll*i*(cnt2+cnt3))+1ll*b*(1ll*i*cnt1+ls[j]-smd+1ll*v[i][j]*cnt3)+1ll*c*(1ll*v[i][j]*(cnt1+cnt2)+sm-ls[j]);
		if(num&1) rm++,num--;
		ans+=num/2;
	    }
	}
    }
    ans+=rm/2;
    return ans;
}

ll solve2(){
    for(int i=0;i<n;i++)
	arr[i]={sz(v[i]),i};
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
	pl[arr[i].S]=i;
    ll ans=0;
    for(int k=0;k<n;k++){
	for(int u:v[k])
	    is[u]=1;
	for(int j:v[k]){
	    if(pl[k]<=pl[j])continue;
	    for(int i:v[j]){
		if(pl[j]<=pl[i])continue;
		if(is[i]) ans+=1ll*a*min(i,min(j,k))+1ll*b*(i+j+k-min(i,min(j,k))-max(i,max(j,k)))+1ll*c*max(i,max(j,k));
	    }
	}
	for(int u:v[k])
	    is[u]=0;
    }
    return ans;
}

int main(){
    scanf("%d%d",&n,&m);
    scanf("%lld%lld%lld",&a,&b,&c);
    for(int i=0;i<m;i++){
	int a,b;scanf("%d%d",&a,&b);
	v[a].PB(b);v[b].PB(a);
    }
    for(int i=0;i<n;i++)
	sort(v[i].begin(),v[i].end());
    ll ans=solve0()-solve1()-solve2();
    unsigned long long ANS=(ans>=0?ans:(~(-ans))+1);
    printf("%llu\n",ANS);
    return 0;
}


// Can U hack it?

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=2e5+10;

ll ls[maxn];
pii arr[maxn];
int pl[maxn];
bool is[maxn];
vector<int>v[maxn];
ll a,b,c;
int n,m;

inline ll Sum(ll n){
    return ((n*(n+1))/2);
}

ll solve0(){
    ll ans=0;
    for(int i=0;i<n;i++)
	ans+=1ll*i*a*(1ll*(n-1-i)*(n-2-i)/2);
    for(int i=0;i<n;i++)
	ans+=1ll*i*c*(1ll*i*(i-1)/2);
    for(int i=0;i<n;i++)
	ans+=1ll*i*b*i*(n-1-i);
    return ans;
}

ll solve1(){
    ll ans=0,rm=0;
    for(int i=0;i<n;i++){
	fill(ls,ls+sz(v[i])+3,0);
	ll sm=Sum(n-1)-i;
	int pos=-1;
	for(int j=0;j<sz(v[i]);j++){
	    sm-=v[i][j];
	    int bf=j==0?0:v[i][j-1];
	    ls[j]=1ll*(j==0?0:ls[j-1])+Sum(v[i][j]-1)-(j==0?0:Sum(v[i][j-1]))-1ll*i*(bf<=i && i<=v[i][j]);
	    if(v[i][j]<i) pos=j;
	}
	ll smd=(pos==-1?0:ls[pos])+Sum(i-1)-(pos==-1?0:Sum(v[i][pos]));
	for(int j=0;j<sz(v[i]);j++){
	    if(v[i][j]<i){
		int cnt1=v[i][j]-j,cnt2=i-v[i][j]-1-pos+j,cnt3=n-i-sz(v[i])+pos;
		ll num=1ll*a*(ls[j]+v[i][j]*(cnt2+cnt3))+1ll*b*(cnt1*v[i][j]+smd-ls[j]+i*cnt3)+1ll*c*(i*cnt1+i*cnt2+sm-smd);
		if(num&1) rm++,num--;
		ans+=num/2;
	    }
	    else{
		int cnt1=i-1-pos,cnt2=v[i][j]-i-j+pos,cnt3=n-v[i][j]-sz(v[i])+j;
		ll num=1ll*a*(smd+i*cnt2+i*cnt3)+1ll*b*(i*cnt1+ls[j]-smd+v[i][j]*cnt3)+1ll*c*(v[i][j]*cnt1+v[i][j]*cnt2+sm-ls[j]);
		if(num&1) rm++,num--;
		ans+=num/2;
	    }
	}
    }
    ans+=rm/2;
    return ans;
}

ll solve2(){
    for(int i=0;i<n;i++)
	arr[i]={sz(v[i]),i};
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
	pl[arr[i].S]=i;
    ll ans=0;
    for(int k=0;k<n;k++){
	for(int u:v[k])
	    is[u]=1;
	for(int j:v[k]){
	    if(pl[k]<=pl[j])continue;
	    for(int i:v[j]){
		if(pl[j]<=pl[i])continue;
		if(is[i]) ans+=1ll*a*i+1ll*b*j+1ll*c*k;
	    }
	}
	for(int u:v[k])
	    is[u]=0;
    }
    return ans;
}

int main(){
    scanf("%d%d",&n,&m);
    scanf("%lld%lld%lld",&a,&b,&c);
    for(int i=0;i<m;i++){
	int a,b;scanf("%d%d",&a,&b);
	v[a].PB(b);v[b].PB(a);
    }
    for(int i=0;i<n;i++)
	sort(v[i].begin(),v[i].end());
    solve1();
    ll ans=solve0()-solve1()-solve2();
    if(ans<0) ans=(~(-ans))+1;
    printf("%lld\n",ans);
    return 0;
}