//Miss ME??
#include<bits/stdc++.h>
using namespace std;
//#define int long long int
int n,a[1005];
int diff[1005];
bool check(int k)
{
    for(int i=0;i<n;i++)
    {
        if(diff[i]!=diff[i%k])
            return 0;
    }
    return 1;
}
signed main()
{
    cin>>n;
    a[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        diff[i]=a[i+1]-a[i];
    }
    int k;
    for(k=1;k<=n;k++)
    {
        if(check(k))
        {
            break;
        }
    }
    int consk=k;
    std::vector<int> v;
    while(k<n)
    {
        v.push_back(k);
        k+=consk;
    }
    v.push_back(n);
    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}


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

int main(void){

	long long int n,i,j,k=0,size;
	cin>>n;
	size=n;
	long long int a[n],diff[n],sizea[n];

	for(i=0;i<n;i++){

		cin>>a[i];

	}

	diff[0]=a[0];
	for(i=1;i<n;i++){
		diff[i]=a[i]-a[i-1];
	}

	//long long int mark;
	//bool flag=false;
	for(i=1;i<n;i++){

		if(diff[i]==diff[0]){
			size=i;

			for(j=i+1;j<n;j++){

				if(diff[j%size]==diff[j]){

				}

				else{
					break;
				}

			}

			if(j==n){
				sizea[k]=size;
				k++;
			}

		}

	}

	cout<<k+1<<endl;

	for(i=0;i<k;i++){
		cout<<sizea[i]<<" ";
	}

	cout<<n;

	return 0;
}


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

int main(void){

	long long int n,i,j,size;
	cin>>n;
	size=n;
	long long int a[n],diff[n];

	for(i=0;i<n;i++){

		cin>>a[i];

	}

	diff[0]=a[0];
	for(i=1;i<n;i++){
		diff[i]=a[i]-a[i-1];
	}

	long long int mark;
	bool flag=false;
	for(i=1;i<n;i++){

		if(diff[i]==diff[0]){
			size=i;
			flag=false;
			for(j=i;j<n;j++){

				if(diff[j%size]==diff[j]){

					if(diff[j]==diff[0] && flag==false){
						flag=true;
						mark=j;

					}

				}

				else{
					i=mark;
					break;
				}

			}

			if(j==n){
				break;
			}

		}

	}

	if(n%size!=0)
	cout<<((n/size)+1)<<endl;

	else
	cout<<((n/size))<<endl;

	long long int temp=size;
	cout<<size<<" ";
	while(size<n){

		if(temp+size<=n){
			size=size+temp;
		}

		else{
			size=(size+temp)-((size+temp)%n);
		}

		cout<<size<<" ";
	}

	return 0;
}


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

int main(void){

	long long int n,i,j,size;
	cin>>n;
	size=n;
	long long int a[n],diff[n];

	for(i=0;i<n;i++){

		cin>>a[i];

	}

	diff[0]=a[0];
	for(i=1;i<n;i++){
		diff[i]=a[i]-a[i-1];
	}

	j=0;
	for(i=1;i<n;i++){

		if(diff[i]==diff[0]){
			size=i;
			for(j=i;j<n;j++){

				if(diff[j%size]==diff[j])
				continue;

				else{
					i=j+1;
					break;
				}

			}

			if(j==n){
				break;
			}

		}

	}

	if(n%size!=0)
	cout<<((n/size)+1)<<endl;

	else
	cout<<((n/size))<<endl;

	long long int temp=size;
	cout<<size<<" ";
	while(size<n){

		if(temp+size<=n){
			size=size+temp;
		}

		else{
			size=(size+temp)-((size+temp)%n);
		}

		cout<<size<<" ";
	}

	return 0;
}


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

int main(void){

	long long int n,i,j,size;
	cin>>n;
	size=n;
	long long int a[n],diff[n];

	for(i=0;i<n;i++){

		cin>>a[i];

	}

	diff[0]=a[0];
	for(i=1;i<n;i++){
		diff[i]=a[i]-a[i-1];
	}

	//long long int mark;
	//bool flag=false;
	for(i=1;i<n;i++){

		if(diff[i]==diff[0]){
			size=i;
			//flag=false;
			for(j=i+1;j<n;j++){

				if(diff[j%size]==diff[j]){

					/*if(diff[j]==diff[0] && flag==false){
						flag=true;
						mark=j;

					}*/
					continue;

				}

				else{
					break;
				}

			}

			if(j==n){
				break;
			}

		}

	}

	if(n%size!=0)
	cout<<((n/size)+1)<<endl;

	else
	cout<<((n/size))<<endl;

	long long int temp=size;
	cout<<size<<" ";
	while(size<n){

		if(temp+size<=n){
			size=size+temp;
		}

		else{
			size=(size+temp)-((size+temp)%n);
		}

		cout<<size<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i-1]=a[i]-a[i-1];
    }
    vector<int>temp(n);
    int dem = 0;
    for(int len=1;len<=n;len++){
        bool check = true;
        for(int i=0;i<n;i++){
            if(b[i]!=b[i%len]){
                check = false;
            }
        }
        if(check == true){
            temp[dem++]=len;

        }

    }
    cout<<dem<<endl;
    for(int i=0;i<dem;i++)
        cout<<temp[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a(n+1),b(n);
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i-1]=a[i]-a[i-1];
    }
    vector<int>temp(n);
    int dem = 0;
    for(int len=1;len<=n;len++){
        bool check = true;
        for(int i=0;i<n;i++){
            if(b[i]!=b[i%len]){
                check = false;

            }
        }
        if(check == true)
            temp[dem++]=len;
    }
    cout<<dem<<endl;
    for(int i=0;i<dem;i++)
        cout<<temp[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i-1]=a[i]-a[i-1];
    }
    vector<int>temp(n);
    int dem = 0;
    for(int len=1;len<=n;len++){
        bool check = true;
        for(int i=0;i<n;i++){
            {
                if(b[i]!=b[i%len]){
                    check = false;
                    break;
                }
            }
            if(check == true){
                temp[dem++]=len;
                break;

                }

        }

    }
    cout<<dem<<endl;
    for(int i=0;i<dem;i++)
        cout<<temp[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i-1]=a[i]-a[i-1];
    }
    cout<<n<<endl;
    for(int i=0;i<n;i++){
        cout<<b[i]<<" ";
    }

}


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

int main()
{
	int n,a[1007]={0},x,cnt;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	x=a[1];cnt=1;
	vector<int> v;
	for(int i=2;i<=n;i++)
	{
		if(a[i]-a[i-1]==x)
		{
			int f=0;
			for(int j=1,k=i;j<i && k<=n;j++,k++)
			{
				if(a[j]-a[j-1]!=a[k]-a[k-1])
				{
					f=1;
					break;
				}
			}
			if(f==0)
			{
				v.push_back(i-1);
			}
		}
	}v.push_back(n);
	cout<<v.size()<<endl;
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i]<<" ";
	}
	return 0;
}


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

int main()
{
	int n,a[1007],x,cnt;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	x=a[1];cnt=1;
	vector<int> v;
	for(int i=2;i<=n;i++)
	{
		if(a[i]-a[i-1]==x)
		{
			v.push_back(i-1);
		}
	}v.push_back(n);
	cout<<v.size()<<endl;
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i]<<" ";
	}
	return 0;
}


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

int main()
{
	int n,a[1007]={0},x,cnt;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	x=a[1];cnt=1;
	vector<int> v;
	for(int i=2;i<=n;i++)
	{
		if(a[i]-a[i-1]==x)
		{
			int f=0;
			for(int j=1,k=i,c=1;j<i && k<=n;j++,k++,c++)
			{
				if(a[j]-a[j-1]!=a[k]-a[k-1])
				{
					f=1;
					break;
				}
				if(c==i-1)
				{
					j=0;
					c=0;
				}
			}
			if(f==0)
			{
				v.push_back(i-1);
			}
		}
	}v.push_back(n);
	cout<<v.size()<<endl;
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i]<<" ";
	}
	return 0;
}


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

int main()
{
	int n,a[1007]={0},x,cnt;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	x=a[1];cnt=1;
	vector<int> v;
	for(int i=2;i<=n;i++)
	{
		if(a[i]-a[i-1]==x)
		{
			int f=0;
			for(int j=1,k=i,c=1;j<i && k<=n;j++,k++,c++)
			{
				if(a[j]-a[j-1]!=a[k]-a[k-1])
				{
					f=1;
					break;
				}
				if(c==i-1)
				{
					j=0;
				}
			}
			if(f==0)
			{
				v.push_back(i-1);
			}
		}
	}v.push_back(n);
	cout<<v.size()<<endl;
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i]<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int arr[n+1];
    arr[0] = 0;
    for(int i = 1; i<=n; i++)    {
        cin >> arr[i];
    }
    int x[n];
    for(int i = 0; i<n; i++)   {
        x[i] = arr[i+1] - arr[i];
    }
    int num = 0, flag = 1, ct = 0, j = 0;
    int ans[2000] = {0};
    for(int i = 1; i<= n; i++)  {
        while(j+i < n)  {
            if(x[j] != x[j+i])  {
                flag = 0;
            }
            j++;
        }
        if(flag)    {
            ans[i] = i;
        }
        j = 0;
        flag = 1;
    }
    for(int i = 0; i<2000; i++) {
        if(ans[i] > 0)  {
            ct++;
        }
    }
    cout << ct << "\n" ;
    for(int i = 0; i<2000; i++) {
        if(ans[i]  > 0) {
            cout << ans[i] << " ";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin >> n;
   int arr[n+1];
   for(int i = 1; i<=n; i++)    {
       cin >> arr[i];
   }
   int x[n];
   for(int i = 1; i<=n; i++) {
       x[i-1] = arr[i] - arr[i-1];
   }
   int length[n];
   for(int i = 0; i<n; i++) {
       length[i] = 0;
   }
   int k = 1, j = 0;
   int flag = 0, total = 0;
   while(j!=n)  {
        for(int i = 0; i<n; i++) {
            if(arr[i+1] != x[i%k]+arr[i])    {
                    flag = 1;
            }
        }
        if(!flag)    {
                total++;
                length[j] = k;
            }
            flag = 0;
            k++;
        j++;
        }
   cout << total << "\n";
   for(int i = 0; i<n; i++) {
       if(length[i] != 0)
            cout << length[i] << " ";
   }
   int h = 0;

   return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin >> n;
   int arr[n+1];
   for(int i = 1; i<=n; i++)    {
       cin >> arr[i];
   }
   int x[n];
   for(int i = 1; i<=n; i++) {
       x[i-1] = arr[i] - arr[i-1];
   }
   int length[n];
   for(int i = 0; i<n; i++) {
       length[i] = 0;
   }
   int k = 1, j = 0;
   int flag = 0, total = 0;
   while(j!=n)  {
        for(int i = 0; i<n; i++) {
            if(arr[i+1] != x[i%k]+arr[i])    {
                    flag = 1;
            }
        }
        if(!flag)    {
                total++;
                length[j] = k;
            }
            flag = 0;
            k++;
        j++;
        }
   cout << total << "\n";
   for(int i = 0; i<n; i++) {
       if(length[i] != 0)
            cout << length[i] << " ";
   }
   int h = 1;

   return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin >> n;
   int arr[n+1];
   for(int i = 1; i<=n; i++)    {
       cin >> arr[i];
   }
   int x[n];
   for(int i = 1; i<=n; i++) {
       x[i-1] = arr[i] - arr[i-1];
   }
   int length[n];
   for(int i = 0; i<n; i++) {
       length[i] = 0;
   }
   int k = 1, j = 0;
   int flag = 0, total = 0;
   while(j!=n)  {
        for(int i = 0; i<n; i++) {
            if(arr[i+1] != x[i%k]+arr[i])    {
                    flag = 1;
            }
        }
        if(!flag)    {
                total++;
                length[j] = k;
            }
            flag = 0;
            k++;
        j++;
        }
   cout << total << "\n";
   for(int i = 0; i<n; i++) {
       if(length[i] != 0)
            cout << length[i] << " ";
   }

   return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int arr[n+1];
    arr[0] = 0;
    for(int i = 1; i<=n; i++)    {
        cin >> arr[i];
    }
    int x[n];
    for(int i = 0; i<n; i++)   {
        x[i] = arr[i+1] - arr[i];
    }
    int num = 0, flag = 1, ct = 0, j = 0;
    int ans[1000] = {0};
    for(int i = 1; i<= n; i++)  {
        while(j+i < n)  {
            if(x[j] != x[j+i])  {
                flag = 0;
            }
            j++;
        }
        if(flag)    {
            ans[i] = i;
        }
        j = 0;
        flag = 1;
    }
    for(int i = 0; i<1000; i++) {
        if(ans[i] > 0)  {
            ct++;
        }
    }
    cout << ct << "\n" ;
    for(int i = 0; i<1000; i++) {
        if(ans[i]  > 0) {
            cout << ans[i] << " ";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,z=0;
    cin>>n;
    long long arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    if(n==1)
    {
        cout<<1<<endl;
        cout<<1;
        return 0;
    }
    long long d=arr[0];
    vector<long long>v;
    vector<long long>v3;
    v.push_back(arr[0]);
    for(long long i=1;i<n;i++)
    {
        v.push_back(arr[i]-arr[i-1]);
    }
    for(long long i=1;i<n;i++)
    {
        if(d==v[i])
        {
            if(n%i==0)
            {
                cout<<n/i<<endl;
                z=i;
                while(i<=n){
                    cout<<i<<" ";
                    i+=z;
            }
            }
            else
            {
                cout<<n/i +1<<endl;
                z=i;
                while(i<n){
                cout<<i<<" ";
                i+=z;
                }
                cout<<n;
            }
            return 0;
        }
    }
    cout<<1<<endl;
    cout<<n;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    if(n==1)
    {
        cout<<1<<endl;
        cout<<1;
        return 0;
    }
    int d=arr[0];
    vector<int>v;
    for(int i=1;i<n;i++)
    {
        if(arr[i]-arr[i-1]==d)
        {
            /*for(int j=i+1;j<2*(i+1);j++)
            {

            }*/
            int j=i;
            while(1)
            {
                if(i<n)
                    v.push_back(i);
                else
                {
                    v.push_back(n);
                    break;
                }
                i+=j;
            }
            cout<<v.size()<<endl;
            for(int k=0;k<v.size();k++)
                cout<<v[k]<<" ";
            return 0;
        }
    }
    cout<<1<<endl;
    cout<<n;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    if(n==1)
    {
        cout<<1<<endl;
        cout<<1;
        return 0;
    }
    long long d=arr[0];
    vector<long long>v;
    vector<long long>v1;
    v.push_back(arr[0]);
    for(long long i=1;i<n;i++)
        v.push_back(arr[i]-arr[i-1]);
    for(long long j=1;j<=n;j++)
    {
        int flag=0;
        for(long long k=0;k<n;k++)
        {
            if(v[k]!=v[k%j])
                flag=1;
        }
        if(flag==0)
            v1.push_back(j);
    }
    cout<<v1.size()<<endl;
    for(int j=0;j<v1.size();j++)
        cout<<v1[j]<<" ";
    return 0;
   // cout<<1<<endl;
   // cout<<n;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long arr[n];
    for(long long i=0;i<n;i++){
        cin>>arr[i];
    }
    if(n==1)
    {
        cout<<1<<endl;
        cout<<1;
        return 0;
    }
    long long d=arr[0];
    vector<long long>v;
    for(long long i=1;i<n;i++)
    {
        if(arr[i]-arr[i-1]==d)
        {
            /*for(long long j=i+1;j<2*(i+1);j++)
            {

            }*/
            long long j=i;
            while(1)
            {
                if(i<n)
                    v.push_back(i);
                else
                {
                    v.push_back(n);
                    break;
                }
                i+=j;
            }
            cout<<v.size()<<endl;
            for(long long k=0;k<v.size();k++)
                cout<<v[k]<<" ";
            return 0;
        }
    }
    cout<<1<<endl;
    cout<<n;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n, *a, *res, i, j, ans[1001] = {0}, l = 0;
	scanf("%d", &n);
	a = (int*)malloc(n * sizeof(int));
	res = (int*)malloc((n - 1) * sizeof(int));
	for(i = 0; i < n; i++)scanf("%d", &a[i]);

	res[0] = a[0];
	for(i = 1; i < n; i++)
	{
		res[i] = a[i] - a[i - 1];
	}

	for(int i = 0; i < n; i++)printf("%d ", res[i]);
	printf("\n");
	for(j = 1; j < n; j++)
	{
		for(i = 0; i < n; i++)
		{
			if(res[i] != res[i % j])break;
		}
		if(i == n)ans[j] = 1, l++;
	}

	printf("%d\n", l);
	for(i = 0; i < 1001; i ++)
	{
		if(ans[i])printf("%d ", i);
	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n, *a, *res, sum = 0, i, j;
	scanf("%d", &n);
	a = (int*)malloc(n * sizeof(int));
	res = (int*)malloc((n - 1) * sizeof(int));
	for(i = 0; i < n; i++)scanf("%d", &a[i]);

	sum = res[0] = a[0];
	for(i = 1; i < n; i++)
	{
		res[i] = a[i] - sum;
		sum += res[i];
	}

	for(j = 1; j < n; j++)
	{
		for(i = 0; i < n; i++)
		{
			if(res[i] != res[i % j])break;
		}
		if(i == n)break;
	}

	printf("%d\n", (n + j - 1) / j);
	for(i = j; i < n; i += j)
	{
		printf("%d ", i);
	}

	if(i != n - 1)printf("%d ", n - 1);
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n, *a, *res, sum = 0, i, j;
	scanf("%d", &n);
	a = (int*)malloc(n * sizeof(int));
	res = (int*)malloc((n - 1) * sizeof(int));
	for(i = 0; i < n; i++)scanf("%d", &a[i]);

	sum = res[0] = a[0];
	for(i = 1; i < n; i++)
	{
		res[i] = a[i] - sum;
		sum += res[i];
	}

	for(j = 1; j < n; j++)
	{
		for(i = 0; i < n; i++)
		{
			if(res[i] != res[i % j])break;
		}
		if(i == n)break;
	}

	printf("%d\n", (n + j - 1) / j);
	for(i = j; i < n; i += j)
	{
		printf("%d ", i);
	}

	if(i != n - 1)printf("%d ", n);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n, *a, *res, sum = 0;
	scanf("%d", &n);
	a = (int*)malloc(n * sizeof(int));
	res = (int*)malloc((n - 1) * sizeof(int));
	for(int i = 0; i < n; i++)scanf("%d", &a[i]);

	sum = res[0] = a[0];
	for(int i = 1; i < n; i++)
	{
		res[i] = a[i] - sum;
		sum += res[i];
	}
	printf("%d\n", n);
	for(int i = 0; i < n; i++)printf("%d ", res[i]);

}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n, *a, *res, sum = 0, i, j;
	scanf("%d", &n);
	a = (int*)malloc(n * sizeof(int));
	res = (int*)malloc((n - 1) * sizeof(int));
	for(i = 0; i < n; i++)scanf("%d", &a[i]);

	sum = res[0] = a[0];
	for(i = 1; i < n; i++)
	{
		res[i] = a[i] - sum;
		sum += res[i];
	}

	for(j = 1; j < n; j++)
	{
		for(i = 0; i < n; i++)
		{
			if(res[i] != res[i % j])break;
		}
		if(i == n)break;
	}

	printf("%d\n", (n + j - 1) / j);
	for(i = j; i < n; i += j)
	{
		printf("%d ", i);
	}

	if(i != n - 1)printf("%d ", n);
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n, *a, *res, i, j, ans[1001] = {0}, l = 0;
	scanf("%d", &n);
	a = (int*)malloc(n * sizeof(int));
	res = (int*)malloc((n - 1) * sizeof(int));
	for(i = 0; i < n; i++)scanf("%d", &a[i]);

	res[0] = a[0];
	for(i = 1; i < n; i++)
	{
		res[i] = a[i] - a[i - 1];
	}

	for(j = 1; j <= n; j++)
	{
		for(i = 0; i < n; i++)
		{
			if(res[i] != res[i % j])break;
		}
		if(i == n)ans[j] = 1, l++;
	}

	printf("%d\n", l);
	for(i = 0; i < 1001; i ++)
	{
		if(ans[i])printf("%d ", i);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long  long ll;
#define INF 1e9
#define int ll
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
#define rep2(i,a,b) for(int i=a;i*i <=b;i++)
#define pb push_back
/*
int power (double base,double exponent)
{
	double result;
	result = pow(base, exponent);

	return result;
}*/

signed main(){
int n;
cin >> n;

int a[n+1];
rep(i,1,n) cin >> a[i] ;

int x[n+1];
rep(i,1,n) x[i-1]=a[i]-a[i-1];

vector <int> v;
rep(i,1,n){
int flag=0;
    rep(j,0,n-1){
        if(x[j]==x[j%i]){flag=1; break;}
        }
    if(flag) v.pb(i);
}
cout << v.size() << endl;
rep(i,0,v.size()-1) cout << v[i] << " ";
cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long  long ll;
#define INF 1e9
#define int ll
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
#define rep2(i,a,b) for(int i=a;i*i <=b;i++)
#define pb push_back
/*
int power (double base,double exponent)
{
	double result;
	result = pow(base, exponent);

	return result;
}*/

signed main(){
int n;
cin >> n;

int a[n+1];
rep(i,1,n) cin >> a[i] ;

int x[n+1];
rep(i,1,n) x[i-1]=a[i]-a[i-1];

vector <int> v;
rep(i,1,n){
int flag=0;
    rep(j,0,n-1){
        if(x[j]==x[j%i]){flag=1; break;}
        }
    if(flag) v.pb(i);
}

rep(i,0,v.size()-1) cout << v[i] << " ";
cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long  long ll;
#define INF 1e9
#define int ll
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
#define rep2(i,a,b) for(int i=a;i*i <=b;i++)
#define pb push_back
/*
int power (double base,double exponent)
{
	double result;
	result = pow(base, exponent);

	return result;
}*/
int a[1111],x[1111];
signed main(){
int n;
cin >> n;

rep(i,1,n) cin >> a[i] ;

rep(i,1,n) x[i-1]=a[i]-a[i-1];

vector <int> v;
rep(i,1,n){
int flag=0;
    rep(j,0,n-1){
        if(x[j]!=x[j%i]){flag=1; break;}
        }
    if(!flag) v.pb(i);
}
cout << v.size() << endl;
rep(i,0,v.size()-1) cout << v[i] << " ";
cout << endl;
	return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
#include<climits>
using namespace std;

///////////////////////////////////Nikhil Srivastava////////////////////////////////////////
///////////////////////////////////IIT Jodhpur//////////////////////////////////////////////
///////////////////////////////////Bazinga//////////////////////////////////////////////////
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define sci(a) scanf("%d",&a)
#define scl(a) scanf("%I64d",&a)
#define scc(a) scanf("%c",&a)
#define scf(a) scanf("%f",&a)
#define scd(a) scanf("%lf",&a)
#define scs(a) scanf("%s",&a)
#define printi(x) printf("%d\n",x)
#define printl(x) printf("%lld\n",x)
#define loop(i,a,n) for(int i=a;i<n;++i)
#define loopd(i,a,n) for(int i=a;i>=n;--i)
#define nl cout<<"\n"
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(),x.end()
#define pi pair < int,int >
#define pl pair < ll,ll >
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define maxi 100005
#define MOD (1000000007LL)
#define INF 1LL<<32
#define MAXI 1000005
#define ff first
#define blk 320
#define ss second
static int rowNbr[] = {-1, -1, -1,  0, 0,  1, 1, 1};
static int colNbr[] = {-1,  0,  1, -1, 1, -1, 0, 1};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define FILE_IO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
#define pqDijkstra priority_queue<pi,vector<pi >, greater<pi > > pq
ll power(ll base, ll p){
ll ans = 1;while(p){if(p&1)ans=(ans*base);base=(base*base);p/=2;}return ans;
}

ll modPower(ll base, ll p, ll mod){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
// bool isMultSafeToDo(ll a, ll b){  /// INF is the maximum value variable can have ATQ.
//     if (a <= (INF+b-1ll)/b)return true;
//     return false;
// }
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}
bool isPrime[MAXI];
void sieve(){
    isPrime[0] = isPrime[1] = 1;
    for(int i = 2;i*i <= 1000000; i++){
        if(isPrime[i] == 0){
            if(i*1LL*i <= 1000000){
                for(int j = i*i;j <= 1000000; j += i)
                    isPrime[j] = 1;
            }
        }
    }
}

int main()
{
            int n;
            cin >> n ;
            int a[n+5];
            a[0] = 0 ;
            loop(i,0,n)
            {
                cin >> a[i+1];
            }
            int b[n+5];
            vector<int> ans;
            for(int k = 1 ; k <= n ; ++k )
             {
                 int i ;
                 for(i=0;i<k;++i)
                 {
                     b[i]=a[i+1]-a[i];
                 }
                 for(i;i<n;++i)
                 if(a[i+1]!=a[i]+b[i%k])goto f;
                    ans.pb(k);
                f:;
             }
            cout << ans.size() << endl;
            for(auto i:ans)
            cout<<i<<" ";
            return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
#include<climits>
using namespace std;

///////////////////////////////////Nikhil Srivastava////////////////////////////////////////
///////////////////////////////////IIT Jodhpur//////////////////////////////////////////////
///////////////////////////////////Bazinga//////////////////////////////////////////////////
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define sci(a) scanf("%d",&a)
#define scl(a) scanf("%I64d",&a)
#define scc(a) scanf("%c",&a)
#define scf(a) scanf("%f",&a)
#define scd(a) scanf("%lf",&a)
#define scs(a) scanf("%s",&a)
#define printi(x) printf("%d\n",x)
#define printl(x) printf("%lld\n",x)
#define loop(i,a,n) for(int i=a;i<n;++i)
#define loopd(i,a,n) for(int i=a;i>=n;--i)
#define nl cout<<"\n"
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(),x.end()
#define pi pair < int,int >
#define pl pair < ll,ll >
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define maxi 100005
#define MOD (1000000007LL)
#define INF 1LL<<32
#define MAXI 1000005
#define ff first
#define blk 320
#define ss second
static int rowNbr[] = {-1, -1, -1,  0, 0,  1, 1, 1};
static int colNbr[] = {-1,  0,  1, -1, 1, -1, 0, 1};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define FILE_IO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
#define pqDijkstra priority_queue<pi,vector<pi >, greater<pi > > pq
ll power(ll base, ll p){
ll ans = 1;while(p){if(p&1)ans=(ans*base);base=(base*base);p/=2;}return ans;
}

ll modPower(ll base, ll p, ll mod){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
// bool isMultSafeToDo(ll a, ll b){  /// INF is the maximum value variable can have ATQ.
//     if (a <= (INF+b-1ll)/b)return true;
//     return false;
// }
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}
bool isPrime[MAXI];
void sieve(){
    isPrime[0] = isPrime[1] = 1;
    for(int i = 2;i*i <= 1000000; i++){
        if(isPrime[i] == 0){
            if(i*1LL*i <= 1000000){
                for(int j = i*i;j <= 1000000; j += i)
                    isPrime[j] = 1;
            }
        }
    }
}

int main()
{
    //SPEED;

                int n;
                cin >> n ;
                vector<int> a(n+1);
                loop(i,0,n)cin>>a[i+1];
                vector<int> b(n+1);
                vector<int> ans;
                for(int k = 1 ; k <= n ;++k )
                  {
                      for(int i = 0 ; i < k ; ++i )
                      {
                          b[i]=a[i+1]-a[i];
                      }
                      for(int i = k ; i <= n ; ++i )
                      {
                          if(a[i+1]!=a[i]+b[i%k])
                          goto f;
                      }
                      ans.push_back(k);
                      f:;
                  }
                cout << ans.size();
    return 0;

}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
#include<climits>
using namespace std;

///////////////////////////////////Nikhil Srivastava////////////////////////////////////////
///////////////////////////////////IIT Jodhpur//////////////////////////////////////////////
///////////////////////////////////Bazinga//////////////////////////////////////////////////
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define sci(a) scanf("%d",&a)
#define scl(a) scanf("%I64d",&a)
#define scc(a) scanf("%c",&a)
#define scf(a) scanf("%f",&a)
#define scd(a) scanf("%lf",&a)
#define scs(a) scanf("%s",&a)
#define printi(x) printf("%d\n",x)
#define printl(x) printf("%lld\n",x)
#define loop(i,a,n) for(int i=a;i<n;++i)
#define loopd(i,a,n) for(int i=a;i>=n;--i)
#define nl cout<<"\n"
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(),x.end()
#define pi pair < int,int >
#define pl pair < ll,ll >
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define maxi 100005
#define MOD (1000000007LL)
#define INF 1LL<<32
#define MAXI 1000005
#define ff first
#define blk 320
#define ss second
static int rowNbr[] = {-1, -1, -1,  0, 0,  1, 1, 1};
static int colNbr[] = {-1,  0,  1, -1, 1, -1, 0, 1};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define FILE_IO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
#define pqDijkstra priority_queue<pi,vector<pi >, greater<pi > > pq
ll power(ll base, ll p){
ll ans = 1;while(p){if(p&1)ans=(ans*base);base=(base*base);p/=2;}return ans;
}

ll modPower(ll base, ll p, ll mod){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
// bool isMultSafeToDo(ll a, ll b){  /// INF is the maximum value variable can have ATQ.
//     if (a <= (INF+b-1ll)/b)return true;
//     return false;
// }
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}
bool isPrime[MAXI];
void sieve(){
    isPrime[0] = isPrime[1] = 1;
    for(int i = 2;i*i <= 1000000; i++){
        if(isPrime[i] == 0){
            if(i*1LL*i <= 1000000){
                for(int j = i*i;j <= 1000000; j += i)
                    isPrime[j] = 1;
            }
        }
    }
}

int main()
{
    //SPEED;

                int n;
                cin >> n ;
                vector<int> a(n+1);
                loop(i,0,n)cin>>a[i+1];
                vector<int> b(n+1);
                vector<int> ans;
                for(int k = 1 ; k <= n ;++k )
                  {
                      for(int i = 0 ; i < k ; ++i )
                      {
                          b[i]=a[i+1]-a[i];
                      }
                      for(int i = k ; i <= n ; ++i )
                      {
                          if(a[i+1]!=a[i]+b[i%k])
                          goto f;
                      }
                      ans.push_back(k);
                      f:;
                  }
                cout << ans.size();
                cout<<endl;
                for(auto i:ans)cout<<i<<" ";
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int a[1200],b[1200],aa[1200];
int main()
{
    int n,m;
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++) scanf("%d",&aa[i]);
        for(int i=0;i<n;i++)
        a[i]=aa[i+1]-aa[i];//,printf("%d ",a[i]);
        int c=0;
            for(int k=1;k<= n;k++)
            {
                int i=0;
                while(a[i]==a[(i%k)]&&i<n)  i++;//,printf("%d %d %d\n",a[i],a[i%k],i) ;
                //printf("i  %d\n",i);
                if(i==n) b[++c]=k;
            }
            printf("%d\n",c);
            for(int i=1;i<=c;i++)
                printf("%d ",b[i]);
                printf("\n");

    }
}


#include<bits/stdc++.h>
using namespace std;
int n,k,fl,a[1005],b[1005],c[1005];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",a+i),b[i]=a[i]-a[i-1];
	for(int i=1;i<=n;++i){
		fl=1;
		for(int j=i+1;j<=n;++j) if(b[j]!=b[j-i]) {fl=0;break;}
		if(fl) c[++k]=i;
	}
	printf("%d\n",k);
	for(int i=1;i<=k;++i) printf("%d ",c[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1200];
int main()
{
    int n,m;
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
            printf("%d\n1 ",n);
        for(int i=2;i<=n;i++)
            printf("%d ",a[i]-a[i-1]);
        printf("\n");
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
//	int t;
//	cin>>t;
//	while(t--)
//	{

		int n,i;
		cin>>n;
		vector<int> a(n);
		for(i=0;i<n;i++)
		cin>>a[i];
		vector<int> x(n);
		x[0]=a[0];
		for(i=1;i<n;i++)
		{
			x[i]=a[i]-a[i-1];
		}
	//	for(i=0;i<n;i++)
	//	cout<<x[i]<<" ";
		int ans=1;
	//	ans++;
	//	vector<int> res;
		int j=0,sz=1;
		for(i=1;i<n;i++)
		{
			if(x[i]==x[j])
			{
				j++;
				if(j==sz)
				{
					ans++;
					j=0;
				}

			}
			else
			{
				ans=1;
				sz=i+1;
				j=0;
			}
		}
		if(j==0)
		cout<<ans<<"\n";
		else
		cout<<ans+1<<"\n";
		if(ans==0&&j==0)
		cout<<n;
		else
		{
			int x=(n/sz),c=sz;
			while(x--)
			{
				cout<<sz<<" ";
				c=c+sz;
			}
			if(n%sz)
			cout<<n;
		}
//	}

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
//	int t;
//	cin>>t;
//	while(t--)
//	{

		int n,i;
		cin>>n;
		vector<int> a(n);
		for(i=0;i<n;i++)
		cin>>a[i];
		vector<int> x(n);
		x[0]=a[0];
		for(i=1;i<n;i++)
		{
			x[i]=a[i]-a[i-1];
		}
	//	for(i=0;i<n;i++)
	//	cout<<x[i]<<" ";
		int ans=1;
	//	ans++;
	//	vector<int> res;
		int j=0,sz=1;
		for(i=1;i<n;i++)
		{
			if(x[i]==x[j])
			{
				j++;
				if(j==sz)
				{
					ans++;
					j=0;
				}

			}
			else
			{
				ans=1;
				sz=i+1;
				j=0;
			}
		}
		if(ans==1)
		cout<<ans<<"\n";
		else
		cout<<ans+1<<"\n";
		if(ans==1&&j==0)
		cout<<n;
		else
		{
			int x=(n/sz),c=sz;
			while(x--)
			{
				cout<<c<<" ";
				c=c+sz;
			}
			if(n%sz)
			cout<<n;
		}
//	}

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
//	int t;
//	cin>>t;
//	while(t--)
//	{

		int n,i;
		cin>>n;
		vector<int> a(n);
		for(i=0;i<n;i++)
		cin>>a[i];
		vector<int> x(n);
		x[0]=a[0];
		for(i=1;i<n;i++)
		{
			x[i]=a[i]-a[i-1];
		}
	//	for(i=0;i<n;i++)
	//	cout<<x[i]<<" ";
		int ans=1;
	//	ans++;
	//	vector<int> res;
		int j=0,sz=1;
		for(i=1;i<n;i++)
		{
			if(x[i]==x[j])
			{
				j++;
				if(j==sz)
				{
					ans++;
					j=0;
				}

			}
			else
			{
				ans=1;
				sz=i+1;
				j=0;
			}
		}
		if(j==0)
		cout<<ans<<"\n";
		else
		cout<<ans+1<<"\n";
		if(ans==0&&j==0)
		cout<<n;
		else
		{
			int x=(n/sz),c=sz;
			while(x--)
			{
				cout<<c<<" ";
				c=c+sz;
			}
			if(n%sz)
			cout<<n;
		}
//	}

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i=a;i<b;i++)
#define pb push_back
#define pll pair <long long,long long>
#define mp make_pair
#define ff first
#define ss second
#define maa 1000000007
#define endl '\n'
#define ld long double
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

/// freopen("input.txt","r",stdin);
/// freopen("output.txt","w",stdout);
/// I m the happy one
ll n,c ;
cin>>n ;
ll r[n] ;
fr(i,0,n)
cin>>r[i] ;
ll ans=1 ;

           c=r[0] ;

fr(i,1,n)
{
      if(fabs(r[i]-r[i-1])!=c)
      {
                ans=0 ;
                break ;
      }
}
vector<ll>v ;
fr(i,2,n+1)
{
       ll x[n] ;
       x[0]=r[0]%i ;
       ll f=1 ;
       fr(j,1,n)
       {
                 x[j]=r[j]-r[j-1] ;
                 x[j]%=i ;
                 if(x[j%i]!=x[j])
                 {
                           f=0 ;
                           break ;
                 }
       }
       if(f)
       v.pb(i) ;
}
cout<<(v.size()+ans)<<endl ;
if(ans==1)
cout<<"1 " ;
fr(i,0,v.size())
cout<<v[i]<<" " ;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i=a;i<b;i++)
#define pb push_back
#define pll pair <long long,long long>
#define mp make_pair
#define ff first
#define ss second
#define maa 1000000007
#define endl '\n'
#define ld long double
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

/// freopen("input.txt","r",stdin);
/// freopen("output.txt","w",stdout);
/// I m the happy one
ll n,c ;
cin>>n ;
ll r[n] ;
fr(i,0,n)
cin>>r[i] ;
ll ans=1 ;

           c=r[0] ;

fr(i,1,n)
{
      if(r[i]-r[i-1]!=c)
      {
                ans=0 ;
                break ;
      }
}
vector<ll>v ;
fr(i,2,n+1)
{
       ll x[n] ;
       x[0]=r[0]%i ;
       ll f=1 ;
       fr(j,1,n)
       {
                 x[j]=r[j]-r[j-1] ;
                 x[j]%=i ;
                 if(x[j%i]!=x[j])
                 {
                           f=0 ;
                           break ;
                 }
       }
       if(f)
       v.pb(i) ;
}
cout<<(v.size()+ans)<<endl ;
if(ans==1)
cout<<"1 " ;
fr(i,0,v.size())
cout<<v[i]<<" " ;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i=a;i<b;i++)
#define pb push_back
#define pll pair <long long,long long>
#define mp make_pair
#define ff first
#define ss second
#define maa 1000000007
#define endl '\n'
#define ld long double
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

/// freopen("input.txt","r",stdin);
/// freopen("output.txt","w",stdout);
/// I m the happy one
ll n,c ;
cin>>n ;
ll r[n] ;
fr(i,0,n)
cin>>r[i] ;
ll ans=1 ;

           c=r[0] ;

fr(i,1,n)
{
      if(fabs(r[i]-r[i-1])!=c)
      {
                ans=0 ;
                break ;
      }
}
vector<ll>v ;
fr(i,2,n+1)
{
       ll x[n] ;
       x[0]=r[0]%i ;
       ll f=1 ;
       fr(j,1,n)
       {
                 x[j]=r[j]-r[j-1] ;
                 x[j]%=i ;
                 x[j]+=i ;
                 x[j]%=i ;
                 if(x[j%i]!=x[j])
                 {
                           f=0 ;
                           break ;
                 }
       }
       if(f)
       v.pb(i) ;
}
cout<<(v.size()+ans)<<endl ;
if(ans==1)
cout<<"1 " ;
fr(i,0,v.size())
cout<<v[i]<<" " ;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i=a;i<b;i++)
#define pb push_back
#define pll pair <long long,long long>
#define mp make_pair
#define ff first
#define ss second
#define maa 1000000007
#define endl '\n'
#define ld long double
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

/// freopen("input.txt","r",stdin);
/// freopen("output.txt","w",stdout);
/// I m the happy one
ll n,c ;
cin>>n ;
ll r[n] ;
fr(i,0,n)
cin>>r[i] ;
ll ans=1 ;
vector<ll>v ;
fr(i,1,n+1)
{
       ll x[n] ;
       x[0]=r[0] ;
       ll f=1 ;
       fr(j,1,n)
       {
                 x[j]=r[j]-r[j-1] ;
                 if(x[j%i]!=x[j])
                 {
                           f=0 ;
                           break ;
                 }
       }
       if(f)
       v.pb(i) ;
}
cout<<(v.size())<<endl ;
fr(i,0,v.size())
cout<<v[i]<<" " ;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i=a;i<b;i++)
#define pb push_back
#define pll pair <long long,long long>
#define mp make_pair
#define ff first
#define ss second
#define maa 1000000007
#define endl '\n'
#define ld long double
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

/// freopen("input.txt","r",stdin);
/// freopen("output.txt","w",stdout);
/// I m the happy one
ll n,c ;
cin>>n ;
ll r[n] ;
fr(i,0,n)
cin>>r[i] ;
ll ans=1 ;
if(n!=1)
{
           c=r[1]-r[0] ;
}
fr(i,1,n)
{
      if(r[i]-r[i-1]!=c)
      {
                ans=0 ;
                break ;
      }
}
vector<ll>v ;
fr(i,2,n+1)
{
       ll x[n] ;
       x[0]=r[0]%i ;
       ll f=1 ;
       fr(j,1,n)
       {
                 x[j]=r[j]-r[j-1] ;
                 x[j]%=i ;
                 if(x[j%i]!=x[j])
                 {
                           f=0 ;
                           break ;
                 }
       }
       if(f)
       v.pb(i) ;
}
cout<<(v.size()+ans)<<endl ;
if(ans==1)
cout<<"1 " ;
fr(i,0,v.size())
cout<<v[i]<<" " ;

}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
#include <cstdlib>
using namespace std;
void printvector(std::vector<int> v){for(int i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}

bool check(int k,std::vector<int> v)
{
	//printvector(v);
	int l=v.size();
	bool ans=true;
	for (int i = k; i <l; ++i)
	{
		if(v[i]!=v[i-k])return false;

	}
	 return ans;
}

int     main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

   int n;cin>>n;
   std::vector<int> v1;
   std::vector<int> v;
   for (int i = 0; i < n; ++i)
   {
   	 int x;cin>>x;
   	 v1.push_back(x);
   	 if(i!=0)v.push_back(v1[i]-v1[i-1]);
   	 else v.push_back(v1[i]);
   }

   int k=1;
   while(k<=n)
   {
    if(check(k,v))cout<<k<<" ";
    k++;
   }
   cout<<" "<<endl;

  return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
#include <cstdlib>
using namespace std;
void printvector(std::vector<int> v){for(int i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}

bool check(int k,std::vector<int> v)
{
	//printvector(v);
	int l=v.size();
	bool ans=true;
	for (int i = k; i <l; ++i)
	{
		if(v[i]!=v[i-k])return false;

	}
	 return ans;
}

int     main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

   int n;cin>>n;
   std::vector<int> v1;
   std::vector<int> v;
   for (int i = 0; i < n; ++i)
   {
   	 int x;cin>>x;
   	 v1.push_back(x);
   	 if(i!=0)v.push_back(v1[i]-v1[i-1]);
   	 else v.push_back(v1[i]);
   }

   int k=1;
   while(!check(k,v))k++;
   int ans=k;
   while(ans<n)
   {
   	cout<<ans<<" ";
   	ans+=k;
   }
   cout<<n<<endl;

  return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
#include <cstdlib>
using namespace std;
//void prlong long int vector(std::vector<long long int > v){for(long long int  i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}

bool check(long long int  k,std::vector<long long int > v)
{
	//prlong long int vector(v);
	long long int  l=v.size();
	bool ans=true;
	for (long long int  i = k; i <l; ++i)
	{
		if(v[i]!=v[i-k])return false;

	}
	 return ans;
}
 int      main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

   long long int  n;cin>>n;
   std::vector<long long int > v1;
   std::vector<long long int > v;
   for (long long int  i = 0; i < n; ++i)
   {
   	 long long int  x;cin>>x;
   	 v1.push_back(x);
   	 if(i!=0)v.push_back(v1[i]-v1[i-1]);
   	 else v.push_back(v1[i]);
   }

   long long int  k=1;
   while(k<=n)
   {
    if(check(k,v))cout<<k<<" ";
    k++;
   }
   cout<<" "<<endl;

  return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
#include <cstdlib>
using namespace std;
void prinvector(std::vector<long long int > v){for(long long int  i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}

bool check(long long int  k,std::vector<long long int > v)
{
	//prlong long int vector(v);
	long long int  l=v.size();
	bool ans=true;
	for (long long int  i = k; i <l; ++i)
	{
		if(v[i]!=v[i-k])return false;

	}
	 return ans;
}
 int      main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

   long long int  n;cin>>n;
   std::vector<long long int > v1;
   std::vector<long long int > v;
   for (long long int  i = 0; i < n; ++i)
   {
   	 long long int  x;cin>>x;
   	 v1.push_back(x);
   	 if(i!=0)v.push_back(v1[i]-v1[i-1]);
   	 else v.push_back(v1[i]);
   }

   long long int  k=1;
   std::vector<long long int> ans;
   while(k<=n)
   {
    if(check(k,v))ans.push_back(k);
   k++;
   }
   cout<<ans.size()<<endl;
   prinvector(ans);

  return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
#include <cstdlib>
using namespace std;
void prlong long int vector(std::vector<long long int > v){for(long long int  i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}

bool check(long long int  k,std::vector<long long int > v)
{
	//prlong long int vector(v);
	long long int  l=v.size();
	bool ans=true;
	for (long long int  i = k; i <l; ++i)
	{
		if(v[i]!=v[i-k])return false;

	}
	 return ans;
}
 int      main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

   long long int  n;cin>>n;
   std::vector<long long int > v1;
   std::vector<long long int > v;
   for (long long int  i = 0; i < n; ++i)
   {
   	 long long int  x;cin>>x;
   	 v1.push_back(x);
   	 if(i!=0)v.push_back(v1[i]-v1[i-1]);
   	 else v.push_back(v1[i]);
   }

   long long int  k=1;
   while(k<=n)
   {
    if(check(k,v))cout<<k<<" ";
    k++;
   }
   cout<<" "<<endl;

  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define cheetah ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
#define deb1(x) cerr<<"["#x<<":"<<x<<"]"<<"  ";
#define deb2(x,y) cerr<<"["#x<<":"<<x<<" "#y<<":"<<y<<"]";
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl ("\n");
typedef tree<ll int ,null_type,less<ll int> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//  *(set_name.find_by_order(k))    set_name.order_of_key(k)

int main (){
	clock_t t1, t2;
    t1 = clock();
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif

    cheetah;
    cout<<fixed;
    cout.precision(10);
    int t = 1;
    // cin>>t;

    while(t--){
    	int n;cin>>n;
    	int a[n];
    	int b[n];
    	for(int i = 0;i<n;i++){
    		cin>>b[i];
    		a[i] = b[i];
    		if(i>0){
    			a[i] = b[i]-b[i-1];
    		}
    	}
    	vector<int> v;
    	for(int i = 1;i<=n;i++){
    		ll int temp = 0;
    		int flag = 1;
    		for(int j = 0;j<n; j++){
    			int index = (j%i);
    			temp += a[index];
    			deb1(temp);
    			if(temp!=b[j]){
    				flag = 0;break;
    			}
    		}
    		if(flag)
    			v.pb(i);
    	}
    	cout<<v.size()<<endl;
    	for(auto it:v){
    		cout<<it<<" ";
    	}

    }

    t2 = clock();
    #ifndef ONLINE_JUDGE
	cerr << "time taken : " << (t2 - t1) / (long double)CLOCKS_PER_SEC<<" seconds";
    #endif
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define cheetah ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
#define deb(x) cerr<<"["#x<<":"<<x<<"]"<<"  ";
#define deb(x,y) cerr<<"["#x<<":"<<x<<" "#y<<":"<<y<<"]";
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl ("\n");
typedef tree<ll int ,null_type,less<ll int> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//  *(set_name.find_by_order(k))    set_name.order_of_key(k)

int main (){
	clock_t t1, t2;
    t1 = clock();
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif

    cheetah;
    cout<<fixed;
    cout.precision(10);
    int t = 1;
    // cin>>t;

    while(t--){
    	int n;cin>>n;
    	int a[n];
    	int b[n];
    	for(int i = 0;i<n;i++){
    		cin>>b[i];
    		a[i] = b[i];
    		if(i>0){
    			a[i] = b[i]-b[i-1];
    		}
    	}
    	vector<int> v;
    	for(int i = 1;i<=n;i++){
    		int temp = 0;
    		int flag = 1;
    		for(int j = 0;j<n; j++){
    			int index = (j%i);
    			temp += a[index];
    			deb(temp,index);
    			if(temp!=b[j]){
    				flag = 0;break;
    			}
    		}
    		if(flag)
    			v.pb(i);
    	}
    	cout<<v.size()<<endl;
    	for(auto it:v){
    		cout<<it<<" ";
    	}

    }

    t2 = clock();
    #ifndef ONLINE_JUDGE
	cerr << "time taken : " << (t2 - t1) / (long double)CLOCKS_PER_SEC<<" seconds";
    #endif
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define cheetah ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
#define deb(x) cerr<<"["#x<<":"<<x<<"]"<<"  ";
#define deb(x,y) cerr<<"["#x<<":"<<x<<" "#y<<":"<<y<<"]";
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl ("\n");
typedef tree<ll int ,null_type,less<ll int> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//  *(set_name.find_by_order(k))    set_name.order_of_key(k)

int main (){
	clock_t t1, t2;
    t1 = clock();
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif

    cheetah;
    cout<<fixed;
    cout.precision(10);
    int t = 1;
    // cin>>t;

    while(t--){
    	int n;cin>>n;
    	int a[n];
    	int b[n];
    	for(int i = 0;i<n;i++){
    		cin>>b[i];
    		a[i] = b[i];
    		if(i>0){
    			a[i] = b[i]-b[i-1];
    		}
    	}
    	vector<int> v;
    	for(int i = 1;i<=n;i++){
    		ll int temp = 0;
    		int flag = 1;
    		for(int j = 0;j<n; j++){
    			int index = (j%i);
    			temp += a[index];
    			if(temp!=b[j]){
    				flag = 0;break;
    			}
    		}
    		if(flag)
    			v.pb(i);
    	}
    	cout<<v.size()<<endl;
    	for(auto it:v){
    		cout<<it<<" ";
    	}

    }

    t2 = clock();
    #ifndef ONLINE_JUDGE
	cerr << "time taken : " << (t2 - t1) / (long double)CLOCKS_PER_SEC<<" seconds";
    #endif
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define cheetah ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
#define deb1(x) cout<<"["#x<<":"<<x<<"]"<<"  ";
#define deb2(x,y) cout<<"["#x<<":"<<x<<" "#y<<":"<<y<<"]";
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl ("\n");
typedef tree<ll int ,null_type,less<ll int> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//  *(set_name.find_by_order(k))    set_name.order_of_key(k)

int main (){
	clock_t t1, t2;
    t1 = clock();
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif

    cheetah;
    cout<<fixed;
    cout.precision(10);
    int t = 1;
    // cin>>t;

    while(t--){
    	int n;cin>>n;
    	int a[n];
    	int b[n];
    	for(int i = 0;i<n;i++){
    		cin>>b[i];
    		a[i] = b[i];
    		if(i>0){
    			a[i] = b[i]-b[i-1];
    		}
    	}
    	vector<int> v;
    	for(int i = 1;i<=n;i++){
    		ll int temp = 0;
    		int flag = 1;
    		for(int j = 0;j<n; j++){
    			int index = (j%i);
    			temp += a[index];
    			// deb2(temp,index);
    			if(temp!=b[j]){
    				flag = 0;break;
    			}
    		}
    		if(flag)
    			v.pb(i);
    	}
    	cout<<v.size()<<endl;
    	for(auto it:v){
    		cout<<it<<" ";
    	}

    }

    t2 = clock();
    #ifndef ONLINE_JUDGE
	cerr << "time taken : " << (t2 - t1) / (long double)CLOCKS_PER_SEC<<" seconds";
    #endif
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define cheetah ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
#define deb(x) cerr<<"["#x<<":"<<x<<"]"<<"  ";
#define deb(x,y) cerr<<"["#x<<":"<<x<<" "#y<<":"<<y<<"]";
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl ("\n");
typedef tree<ll int ,null_type,less<ll int> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//  *(set_name.find_by_order(k))    set_name.order_of_key(k)

int main (){
	clock_t t1, t2;
    t1 = clock();
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif

    cheetah;
    cout<<fixed;
    cout.precision(10);
    int t = 1;
    // cin>>t;

    while(t--){
    	int n;cin>>n;
    	int a[n];
    	int b[n];
    	for(int i = 0;i<n;i++){
    		cin>>b[i];
    		a[i] = b[i];
    		if(i>0){
    			a[i] = b[i]-b[i-1];
    		}
    		if(a[i]<0){
    			cout<<1<<endl;
    			cout<<n;
    			return 0;
    		}
    	}
    	vector<int> v;
    	for(int i = 1;i<=n;i++){
    		ll int temp = 0;
    		int flag = 1;
    		for(int j = 0;j<n; j++){
    			int index = (j%i);
    			temp += a[index];
    			if(temp!=b[j]){
    				flag = 0;break;
    			}
    		}
    		if(flag)
    			v.pb(i);
    	}
    	cout<<v.size()<<endl;
    	for(auto it:v){
    		cout<<it<<" ";
    	}

    }

    t2 = clock();
    #ifndef ONLINE_JUDGE
	cerr << "time taken : " << (t2 - t1) / (long double)CLOCKS_PER_SEC<<" seconds";
    #endif
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define cheetah ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
#define deb(x) cerr<<"["#x<<":"<<x<<"]"<<"  ";
#define deb(x,y) cerr<<"["#x<<":"<<x<<" "#y<<":"<<y<<"]";
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl ("\n");
typedef tree<ll int ,null_type,less<ll int> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//  *(set_name.find_by_order(k))    set_name.order_of_key(k)

int main (){
	clock_t t1, t2;
    t1 = clock();
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif

    cheetah;
    cout<<fixed;
    cout.precision(10);
    int t = 1;
    // cin>>t;

    while(t--){
    	int n;cin>>n;
    	int a[n];
    	int b[n];
    	for(int i = 0;i<n;i++){
    		cin>>b[i];
    		a[i] = b[i];
    		if(i>0){
    			a[i] = b[i]-b[i-1];
    		}
    		// if(a[i]<0){
    		// 	cout<<1<<endl;
    		// 	cout<<n;
    		// 	return 0;
    		// }
    	}
    	vector<int> v;
    	for(int i = 1;i<=n;i++){
    		ll int temp = 0;
    		int flag = 1;
    		for(int j = 0;j<n; j++){
    			int index = (j%i);
    			temp += a[index];
    			if(temp!=b[j]){
    				flag = 0;break;
    			}
    		}
    		if(flag)
    			v.pb(i);
    	}
    	cout<<v.size()<<endl;
    	for(auto it:v){
    		cout<<it<<" ";
    	}

    }

    t2 = clock();
    #ifndef ONLINE_JUDGE
	cerr << "time taken : " << (t2 - t1) / (long double)CLOCKS_PER_SEC<<" seconds";
    #endif
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define cheetah ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
#define deb(x) cerr<<"["#x<<":"<<x<<"]"<<"  ";
#define deb(x,y) cerr<<"["#x<<":"<<x<<" "#y<<":"<<y<<"]";
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl ("\n");
typedef tree<ll int ,null_type,less<ll int> ,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//  *(set_name.find_by_order(k))    set_name.order_of_key(k)

int main (){
	clock_t t1, t2;
    t1 = clock();
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif

    cheetah;
    cout<<fixed;
    cout.precision(10);
    int t = 1;
    // cin>>t;

    while(t--){
    	int n;cin>>n;
    	int a[n];
    	int b[n];
    	for(int i = 0;i<n;i++){
    		cin>>b[i];
    		a[i] = b[i];
    		if(i>0){
    			a[i] = b[i]-b[i-1];
    		}
    	}
    	vector<int> v;
    	for(int i = 1;i<=n;i++){
    		ll int temp = 0;
    		int flag = 1;
    		for(int j = 0;j<n; j++){
    			int index = (j%i);
    			temp += a[index];
    			deb(temp,index);
    			if(temp!=b[j]){
    				flag = 0;break;
    			}
    		}
    		if(flag)
    			v.pb(i);
    	}
    	cout<<v.size()<<endl;
    	for(auto it:v){
    		cout<<it<<" ";
    	}

    }

    t2 = clock();
    #ifndef ONLINE_JUDGE
	cerr << "time taken : " << (t2 - t1) / (long double)CLOCKS_PER_SEC<<" seconds";
    #endif
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6;

int n, k, cnt, key[maxn + 5];

struct item {
    int s, id;
} a[maxn + 5];

struct query {
    int l, r;
} q[maxn + 5];

int s[maxn + 5][2], tag[maxn + 5];

void settag(int p) {
    swap(s[p][0], s[p][1]);
    tag[p] ^= 1;
}

void upd(int p) {
    s[p][0] = s[p + p][0] + s[p + p + 1][0];
    s[p][1] = s[p + p][1] + s[p + p + 1][1];
}

void push(int p) {
    if (tag[p] != 0) {
        settag(p + p); settag(p + p + 1);
        tag[p] = 0;
    }
}

void build(int p, int l, int r) {
    tag[p] = 0, s[p][0] = r - l + 1, s[p][1] = 0;
    if (l == r) return ;
    int mid = (l + r) >> 1;
    build(p + p, l, mid); build(p + p + 1, mid + 1, r);
}

void modify(int p, int l, int r, int ql, int qr) {
    if (l == ql && r == qr) {
        settag(p); return ;
    }
    push(p);
    int mid = (l + r) >> 1;
    if (qr <= mid) modify(p + p, l, mid, ql, qr);
    else if (mid < ql) modify(p + p + 1, mid + 1, r, ql, qr);
    else modify(p + p, l, mid, ql, mid), modify(p + p + 1, mid + 1, r, mid + 1, qr);
    upd(p);
}

pair <int, int> query(int p, int l, int r, int ql, int qr) {
    push(p);
    if (l == ql && r == qr) return {s[p][0], s[p][1]};
    int mid = (l + r) >> 1;
    if (qr <= mid) return query(p + p, l, mid, ql, qr);
    else if (mid < ql) return query(p + p + 1, mid + 1, r, ql, qr);
    else {
        pair <int, int> x = query(p + p, l, mid, ql, mid);
        pair <int, int> y = query(p + p + 1, mid + 1, r, mid + 1, qr);
        return {x.first + y.first, x.second + y.second};
    }
}

vector <int> p[maxn + 5], L[maxn + 5], R[maxn + 5];

int main() {
    scanf("%d %d", &n, &k);
    long long ans = 1ll * n * (n - 1) * (n - 2) / 6;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i].s);
        a[i].id = i;
        key[++cnt] = a[i].s;
    }
    for (int i = 1; i <= k; i++) {
        scanf("%d %d", &q[i].l, &q[i].r);
        q[i].r++;
    }
    sort(key + 1, key + cnt + 1);
    cnt = unique(key + 1, key + cnt + 1) - key - 1;
    for (int i = 1; i <= n; i++) {
        a[i].s = lower_bound(key + 1, key + cnt + 1, a[i].s) - key;
        p[a[i].s].push_back(a[i].id);
    }
    for (int i = 1; i <= k; i++) {
        q[i].l = lower_bound(key + 1, key + cnt + 1, q[i].l) - key;
        q[i].r = lower_bound(key + 1, key + cnt + 1, q[i].r) - key;
        L[q[i].l].push_back(q[i].r);
        R[q[i].r].push_back(q[i].l);
    }
    build(1, 1, cnt);
    for (int i = 1; i <= cnt; i++) {
        for (auto t : L[i]) {
            modify(1, 1, n, i, t - 1);
        }
        for (auto t : R[i]) {
            modify(1, 1, n, t, i - 1);
        }
        int o = 0;
        pair <int, int> e;
        if (i - 1 >= 1) {
            e = query(1, 1, n, 1, i - 1);
            o += e.first;
        }
        if (i + 1 <= n) {
            e = query(1, 1, n, i + 1, n);
            o += e.second;
        }
        ans -= 1ll * o * (o - 1) / 2;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
#define count abcdefg
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
void read(int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}
const int N = 3e5 + 5;
int n, m, tot, a[N], l[N], r[N], c[N];
vector<int> I[N], J[N];

#define tot gfuhsd
int ch[N << 1][2], sum[N << 1], tot, tag[N << 1];
int build(int u, int v) {
	int now = ++tot;
	if(u == v) return now;
	int mid = (u + v) >> 1;
	ch[now][0] = build(u, mid);
	ch[now][1] = build(mid + 1, v);
	return now;
}
void pushdown(int p, int l, int r) {
	if(tag[p]) {
		int mid = (l + r) >> 1;
		tag[ch[p][0]] ^= 1, tag[ch[p][1]] ^= 1;
		sum[ch[p][0]] = mid - l + 1 - sum[ch[p][0]];
		sum[ch[p][1]] = r - mid - sum[ch[p][1]];
		tag[p] = 0;
	}
}
void rev(int p, int l, int r, int u, int v) {
	if (u > v) return ;
	if(u <= l && v >= r) {
		sum[p] = r - l + 1 - sum[p];
		tag[p] ^= 1;
		return ;
	}
	pushdown(p, l, r);
	int mid = (l + r) >> 1;
	if(u <= mid) rev(ch[p][0], l, mid, u, v);
	if(v > mid) rev(ch[p][1], mid + 1, r, u, v);
	sum[p] = sum[ch[p][0]] + sum[ch[p][1]];
	return ;
}
int query(int p, int l, int r, int u, int v, int k) {
	if(u > v) return 0;
	if(u <= l && v >= r) return k ? sum[p] : (r - l + 1 - sum[p]);
	pushdown(p, l, r);
	int mid = (l + r) >> 1, res = 0;
	if(u <= mid) res += query(ch[p][0], l, mid, u, v, k);
	if(v > mid) res += query(ch[p][1], mid + 1, r, u, v, k);
	return res;
}
#undef tot

long long calc(int p) { return 1LL * p * (p - 1) / 2; }
int main()
{
	//  freopen("x.in", "r", stdin);
	read(n); read(m);
	for(int i = 1; i <= n; ++i) read(a[i]), c[++tot] = a[i];
	sort(c + 1, c + tot + 1);
	tot = unique(c + 1, c + tot + 1) - c - 1;
	for(int i = 1; i <= n; ++i) a[i] = lower_bound(c + 1, c + tot + 1, a[i]) - c;
	for(int i = 1; i <= m; ++i) {
		read(l[i]), read(r[i]);
		l[i] = lower_bound(c + 1, c + tot + 1, l[i]) - c;
		r[i] = upper_bound(c + 1, c + tot + 1, r[i]) - c - 1;
	}
	for(int i = 1; i <= m; ++i) I[l[i]].push_back(i), J[r[i]].push_back(i);
	build(1, tot);
	long long ans = 0;
	for(int i = 1; i <= tot; ++i) {
		for(int j = 0; j < (signed)I[i].size(); ++j) {
			int id = I[i][j];
			rev(1, 1, tot, l[id], r[id]);
		}
		ans += calc(query(1, 1, tot, 1, i - 1, 0) + query(1, 1, tot, i + 1, tot, 1));
		for(int j = 0; j < (signed)J[i].size(); ++j) {
			int id = J[i][j];
			rev(1, 1, tot, l[id], r[id]);
		}
	}
	printf("%I64d\n", 1LL * n * (n - 1) * (n - 2) / 6 - ans);
	return 0;
}


#include <bits/stdc++.h>
#define count abcdefg
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
void read(int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}
const int N = 3e5 + 5;
int n, m, tot, a[N], l[N], r[N], c[N];
vector<int> I[N], J[N];

#define tot gfuhsd
int ch[N << 1][2], sum[N << 1], tot, tag[N << 1];
int build(int u, int v) {
	int now = ++tot;
	if(u == v) return now;
	int mid = (u + v) >> 1;
	ch[now][0] = build(u, mid);
	ch[now][1] = build(mid + 1, v);
	return now;
}
void pushdown(int p, int l, int r) {
	if(tag[p]) {
		int mid = (l + r) >> 1;
		tag[ch[p][0]] ^= 1, tag[ch[p][1]] ^= 1;
		sum[ch[p][0]] = mid - l + 1 - sum[ch[p][0]];
		sum[ch[p][1]] = r - mid - sum[ch[p][1]];
		tag[p] = 0;
	}
}
void rev(int p, int l, int r, int u, int v) {
	if(u <= l && v >= r) {
		sum[p] = r - l + 1 - sum[p];
		tag[p] ^= 1;
		return ;
	}
	pushdown(p, l, r);
	int mid = (l + r) >> 1;
	if(u <= mid) rev(ch[p][0], l, mid, u, v);
	if(v > mid) rev(ch[p][1], mid + 1, r, u, v);
	sum[p] = sum[ch[p][0]] + sum[ch[p][1]];
	return ;
}
int query(int p, int l, int r, int u, int v, int k) {
	if(u > v) return 0;
	if(u <= l && v >= r) return k ? sum[p] : (r - l + 1 - sum[p]);
	pushdown(p, l, r);
	int mid = (l + r) >> 1, res = 0;
	if(u <= mid) res += query(ch[p][0], l, mid, u, v, k);
	if(v > mid) res += query(ch[p][1], mid + 1, r, u, v, k);
	return res;
}
#undef tot

long long calc(int p) { return 1LL * p * (p - 1) / 2; }
int main()
{
	// freopen("x.in", "r", stdin);
	read(n); read(m);
	for(int i = 1; i <= n; ++i) read(a[i]), c[++tot] = a[i];
	sort(c + 1, c + tot + 1);
	tot = unique(c + 1, c + tot + 1) - c - 1;
	for(int i = 1; i <= n; ++i) a[i] = lower_bound(c + 1, c + tot + 1, a[i]) - c;
	for(int i = 1; i <= m; ++i) {
		read(l[i]), read(r[i]);
		l[i] = lower_bound(c + 1, c + tot + 1, l[i]) - c;
		r[i] = upper_bound(c + 1, c + tot + 1, r[i]) - c - 1;
	}
	for(int i = 1; i <= m; ++i) I[l[i]].push_back(i), J[r[i]].push_back(i);
	build(1, tot);
	long long ans = 0;
	for(int i = 1; i <= tot; ++i) {
		for(int j = 0; j < (signed)I[i].size(); ++j) {
			int id = I[i][j];
			rev(1, 1, tot, l[id], r[id]);
		}
		ans += calc(query(1, 1, tot, 1, i - 1, 0) + query(1, 1, tot, i + 1, tot, 1));
		for(int j = 0; j < (signed)J[i].size(); ++j) {
			int id = J[i][j];
			rev(1, 1, tot, l[id], r[id]);
		}
	}
	printf("%I64d\n", 1LL * n * (n - 1) * (n - 2) / 6 - ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bitset>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 250010
#define maxm 100010
#define inf 1000000007
#define mod 998244353
#define inv 499122177
#define pi acos(-1)
#define G 3
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
typedef long double ld;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-+'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m;
struct P{
    int l,r;
}p[maxn];
int a[maxn],b[maxn],top,deg[maxn];
vector<pii>v[maxn];
struct Segment_Tree{
    int t[maxn*4],tag[maxn*4];
    void pushdown(int k,int l,int r)
    {
        if(!tag[k])  return;
        int mid=(l+r)/2;
        t[k*2]=mid-l+1-t[k*2];tag[k*2]^=1;
        t[k*2+1]=r-mid-t[k*2+1];tag[k*2+1]^=1;
        tag[k]=0;
    }
    void modi(int k,int l,int r,int x,int y)
    {
        if(l>=x&&r<=y)
        {
            t[k]=r-l+1-t[k];tag[k]^=1;
            return;
        }
        pushdown(k,l,r);
        int mid=(l+r)/2;
        if(mid>=x)  modi(k*2,l,mid,x,y);
        if(mid<y)   modi(k*2+1,mid+1,r,x,y);
        t[k]=t[k*2]+t[k*2+1];
    }
    int query(int k,int l,int r,int x,int y)
    {
        if(l>=x&&r<=y)  return t[k];
        pushdown(k,l,r);
        int mid=(l+r)/2,res=0;
        if(mid>=x)  res+=query(k*2,l,mid,x,y);
        if(mid<y)   res+=query(k*2+1,mid+1,r,x,y);
        return res;
    }
    void clear(int k,int l,int r)
    {
        tag[k]=t[k]=0;
        if(l==r)  return;
        int mid=(l+r)/2;
        clear(k*2,l,mid);
        clear(k*2+1,mid+1,r);
    }
}S;
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)  b[i]=a[i];
    b[n+1]=inf;
    for(int i=1;i<=n;i++)  a[i]=lower_bound(b+1,b+n+1,a[i])-a;
    for(int i=1;i<=m;i++)
    {
        p[i].l=read();p[i].r=read();
        p[i].l=lower_bound(b+1,b+n+2,p[i].l)-b;
        p[i].r=upper_bound(b+1,b+n+2,p[i].r)-b-1;
        if(p[i].l<=p[i].r)
        {
            v[p[i].l].push_back(mp(p[i].r,1));
            v[p[i].r+1].push_back(mp(p[i].l,-1));
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            if(v[i][j].se==1)  S.modi(1,1,n,i,v[i][j].fi);
            else               S.modi(1,1,n,v[i][j].fi,i-1);
        }
        if(i>1)  deg[i]+=i-1-S.query(1,1,n,1,i-1);
    }
    S.clear(1,1,n);
    for(int i=1;i<=n;i++)  v[i].clear();
    for(int i=1;i<=n;i++)  v[p[i].r].push_back(mp(p[i].l,1)),v[p[i].l-1].push_back(mp(p[i].r,-1));
    for(int i=n;i>=1;i--)
    {
        for(int j=0;j<v[i].size();j++)
          if(v[i][j].se==1)  S.modi(1,1,n,v[i][j].fi,i);
          else               S.modi(1,1,n,i+1,v[i][j].fi);
        if(i<n)  deg[i]+=S.query(1,1,n,i+1,n);
    }
    ll ans=1ll*n*(n-1)*(n-2)/6;
    for(int i=1;i<=n;i++)  ans-=1ll*deg[i]*(deg[i]-1)/2;
    cout<<ans<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bitset>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 100010
#define maxm 100010
#define inf 1000000007
#define mod 998244353
#define inv 499122177
#define pi acos(-1)
#define G 3
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
typedef long double ld;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-+'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m;
struct P{
    int l,r;
}p[maxn];
int a[maxn],b[maxn],top,deg[maxn];
vector<pii>v[maxn];
struct Segment_Tree{
    int t[maxn*4],tag[maxn*4];
    void pushdown(int k,int l,int r)
    {
        if(!tag[k])  return;
        int mid=(l+r)/2;
        t[k*2]=mid-l+1-t[k*2];tag[k*2]^=1;
        t[k*2+1]=r-mid-t[k*2+1];tag[k*2+1]^=1;
        tag[k]=0;
    }
    void modi(int k,int l,int r,int x,int y)
    {
        if(l>=x&&r<=y)
        {
            t[k]=r-l+1-t[k];tag[k]^=1;
            return;
        }
        pushdown(k,l,r);
        int mid=(l+r)/2;
        if(mid>=x)  modi(k*2,l,mid,x,y);
        if(mid<y)   modi(k*2+1,mid+1,r,x,y);
        t[k]=t[k*2]+t[k*2+1];
    }
    int query(int k,int l,int r,int x,int y)
    {
        if(l>=x&&r<=y)  return t[k];
        pushdown(k,l,r);
        int mid=(l+r)/2,res=0;
        if(mid>=x)  res+=query(k*2,l,mid,x,y);
        if(mid<y)   res+=query(k*2+1,mid+1,r,x,y);
        return res;
    }
    void clear(int k,int l,int r)
    {
        tag[k]=t[k]=0;
        if(l==r)  return;
        int mid=(l+r)/2;
        clear(k*2,l,mid);
        clear(k*2+1,mid+1,r);
    }
}S;
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)  b[i]=a[i];
    b[n+1]=inf;
    for(int i=1;i<=n;i++)  a[i]=lower_bound(b+1,b+n+1,a[i])-b;
    for(int i=1;i<=m;i++)
    {
        p[i].l=read();p[i].r=read();
        p[i].l=lower_bound(b+1,b+n+2,p[i].l)-b;
        p[i].r=upper_bound(b+1,b+n+2,p[i].r)-b-1;
        if(p[i].l<=p[i].r)
        {
            v[p[i].l].push_back(mp(p[i].r,1));
            v[p[i].r+1].push_back(mp(p[i].l,-1));
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            if(v[i][j].se==1)  S.modi(1,1,n,i,v[i][j].fi);
            else               S.modi(1,1,n,v[i][j].fi,i-1);
        }
        if(i>1)  deg[i]+=i-1-S.query(1,1,n,1,i-1);
    }
    S.clear(1,1,n);
    for(int i=1;i<=n;i++)  v[i].clear();
    for(int i=1;i<=m;i++)
      if(p[i].l<=p[i].l)  v[p[i].r].push_back(mp(p[i].l,1)),v[p[i].l-1].push_back(mp(p[i].r,-1));
    for(int i=n;i>=1;i--)
    {
        for(int j=0;j<v[i].size();j++)
          if(v[i][j].se==1)  S.modi(1,1,n,v[i][j].fi,i);
          else               S.modi(1,1,n,i+1,v[i][j].fi);
        if(i<n)  deg[i]+=S.query(1,1,n,i+1,n);
    }
    ll ans=1ll*n*(n-1)*(n-2)/6;
    for(int i=1;i<=n;i++)  ans-=1ll*deg[i]*(deg[i]-1)/2;
    cout<<ans<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bitset>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 100010
#define maxm 100010
#define inf 1000000007
#define mod 998244353
#define inv 499122177
#define pi acos(-1)
#define G 3
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
typedef long double ld;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-+'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m;
struct P{
    int l,r;
}p[maxn];
int a[maxn],b[maxn],top,deg[maxn];
vector<pii>v[maxn];
struct Segment_Tree{
    int t[maxn*4],tag[maxn*4];
    void pushdown(int k,int l,int r)
    {
        if(!tag[k])  return;
        int mid=(l+r)/2;
        t[k*2]=mid-l+1-t[k*2];tag[k*2]^=1;
        t[k*2+1]=r-mid-t[k*2+1];tag[k*2+1]^=1;
        tag[k]=0;
    }
    void modi(int k,int l,int r,int x,int y)
    {
        if(l>=x&&r<=y)
        {
            t[k]=r-l+1-t[k];tag[k]^=1;
            return;
        }
        pushdown(k,l,r);
        int mid=(l+r)/2;
        if(mid>=x)  modi(k*2,l,mid,x,y);
        if(mid<y)   modi(k*2+1,mid+1,r,x,y);
        t[k]=t[k*2]+t[k*2+1];
    }
    int query(int k,int l,int r,int x,int y)
    {
        if(l>=x&&r<=y)  return t[k];
        pushdown(k,l,r);
        int mid=(l+r)/2,res=0;
        if(mid>=x)  res+=query(k*2,l,mid,x,y);
        if(mid<y)   res+=query(k*2+1,mid+1,r,x,y);
        return res;
    }
    void clear(int k,int l,int r)
    {
        tag[k]=t[k]=0;
        if(l==r)  return;
        int mid=(l+r)/2;
        clear(k*2,l,mid);
        clear(k*2+1,mid+1,r);
    }
}S;
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)  b[i]=a[i];
    b[n+1]=inf;
    for(int i=1;i<=n;i++)  a[i]=lower_bound(b+1,b+n+1,a[i])-b;
    for(int i=1;i<=m;i++)
    {
        p[i].l=read();p[i].r=read();
        p[i].l=lower_bound(b+1,b+n+2,p[i].l)-b;
        p[i].r=upper_bound(b+1,b+n+2,p[i].r)-b-1;
        if(p[i].l<=p[i].r)
        {
            v[p[i].l].push_back(mp(p[i].r,1));
            v[p[i].r+1].push_back(mp(p[i].l,-1));
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            if(v[i][j].se==1)  S.modi(1,1,n,i,v[i][j].fi);
            else               S.modi(1,1,n,v[i][j].fi,i-1);
        }
        if(i>1)  deg[i]+=i-1-S.query(1,1,n,1,i-1);
    }
    S.clear(1,1,n);
    for(int i=1;i<=n;i++)  v[i].clear();
    for(int i=1;i<=n;i++)  v[p[i].r].push_back(mp(p[i].l,1)),v[p[i].l-1].push_back(mp(p[i].r,-1));
    for(int i=n;i>=1;i--)
    {
        for(int j=0;j<v[i].size();j++)
          if(v[i][j].se==1)  S.modi(1,1,n,v[i][j].fi,i);
          else               S.modi(1,1,n,i+1,v[i][j].fi);
        if(i<n)  deg[i]+=S.query(1,1,n,i+1,n);
    }
    ll ans=1ll*n*(n-1)*(n-2)/6;
    for(int i=1;i<=n;i++)  ans-=1ll*deg[i]*(deg[i]-1)/2;
    cout<<ans<<endl;
    return 0;
}


//Nipah!~☆
#include<bits/stdc++.h>
using namespace std;

const long long maxn = 1e5 + 10;

long long ans;
long long n, k;
long long s[maxn];
long long l[maxn];
long long r[maxn];
long long seg[4 * maxn];
long long lazy[4 * maxn];
vector<long long> bois[maxn];

void in();
void solve();
long long doaz(long long);
long long get(long long, long long, long long, long long, long long);
void upd(long long, long long, long long, long long, long long);
void push(long long, long long, long long);
void out();

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	in();
	solve();
	out();
}

void in(){
	cin >> n >> k;
	for(long long i = 0; i < n; i++)
		cin >> s[i];
	for(long long i = 0; i < k; i++)
		cin >> l[i] >> r[i];
}

void solve(){
	sort(s, s + n);
	for(long long i = 0; i < k; i++){
		l[i] = lower_bound(s, s + n, l[i]) - s;
		r[i] = upper_bound(s, s + n, r[i]) - s;
		bois[l[i]].push_back(i);
		bois[r[i]].push_back(i);
	}
	for(long long i = 0; i < n; i++){
		l[k + i] = i;
		r[k + i] = i + 1;
		bois[i].push_back(k + i);
	}
	ans = n * (n - 1) * (n - 2) / 6;
	for(long long i = 0; i < n; i ++){
		for(auto j: bois[i])
			upd(1, 0, n, l[j], r[j]);
		ans -= doaz(get(1, 0, n, 0, n) - get(1, 0, n, i, i + 1));
	}
}

long long get(long long id, long long l, long long r, long long L, long long R){
	if(r <= L || R <= l)
		return 0;
	if(L <= l && r <= R)
		return seg[id];
	if(lazy[id])
		push(id, l, r);
	long long mid = (l + r) >> 1;
	return get(id << 1, l, mid, L, R) + get(id << 1 | 1, mid, r, L, R);
}

void upd(long long id, long long l, long long r, long long L, long long R){
	if(r <= L || R <= l)
		return;
	if(L <= l && r <= R){
		seg[id] = r - l - seg[id];
		lazy[id] = 1 - lazy[id];
		return;
	}
	if(lazy[id])
		push(id, l, r);
	long long mid = (l + r) >> 1;
	upd(id << 1, l, mid, L, R);
	upd(id << 1 | 1, mid, r, L, R);
	seg[id] = seg[id << 1] + seg[id << 1 | 1];
}

void push(long long id, long long l, long long r){
	long long mid = (l + r) >> 1;
	lazy[id] = 0;
	lazy[id << 1] = 1 - lazy[id << 1];
	lazy[id << 1 | 1] = 1 - lazy[id << 1 | 1];
	seg[id << 1] = mid - l - seg[id << 1];
	seg[id << 1 | 1] = r - mid - seg[id << 1 | 1];
}

bool cmp(long long i, long long j){
	return s[i] < s[j];
}

long long doaz(long long x){
	return x * (x - 1) / 2;
}

void out(){
	cout << ans;
}


//Nipah!~☆
#include<bits/stdc++.h>
using namespace std;

const long long maxn = 3e5 + 10;

long long ans;
long long n, k;
long long s[maxn];
long long l[maxn];
long long r[maxn];
long long seg[4 * maxn];
long long lazy[4 * maxn];
vector<long long> bois[maxn];

void in();
void solve();
long long doaz(long long);
long long get(long long, long long, long long, long long, long long);
void upd(long long, long long, long long, long long, long long);
void push(long long, long long, long long);
void out();

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	in();
	solve();
	out();
}

void in(){
	cin >> n >> k;
	for(long long i = 0; i < n; i++)
		cin >> s[i];
	for(long long i = 0; i < k; i++)
		cin >> l[i] >> r[i];
}

void solve(){
	sort(s, s + n);
	for(long long i = 0; i < k; i++){
		l[i] = lower_bound(s, s + n, l[i]) - s;
		r[i] = upper_bound(s, s + n, r[i]) - s;
		bois[l[i]].push_back(i);
		bois[r[i]].push_back(i);
	}
	for(long long i = 0; i < n; i++){
		l[k + i] = i;
		r[k + i] = i + 1;
		bois[i].push_back(k + i);
	}
	ans = n * (n - 1) * (n - 2) / 6;
	for(long long i = 0; i < n; i ++){
		for(auto j: bois[i])
			upd(1, 0, n, l[j], r[j]);
		ans -= doaz(get(1, 0, n, 0, n) - get(1, 0, n, i, i + 1));
	}
}

long long get(long long id, long long l, long long r, long long L, long long R){
	if(r <= L || R <= l)
		return 0;
	if(L <= l && r <= R)
		return seg[id];
	if(lazy[id])
		push(id, l, r);
	long long mid = (l + r) >> 1;
	return get(id << 1, l, mid, L, R) + get(id << 1 | 1, mid, r, L, R);
}

void upd(long long id, long long l, long long r, long long L, long long R){
	if(r <= L || R <= l)
		return;
	if(L <= l && r <= R){
		seg[id] = r - l - seg[id];
		lazy[id] = 1 - lazy[id];
		return;
	}
	if(lazy[id])
		push(id, l, r);
	long long mid = (l + r) >> 1;
	upd(id << 1, l, mid, L, R);
	upd(id << 1 | 1, mid, r, L, R);
	seg[id] = seg[id << 1] + seg[id << 1 | 1];
}

void push(long long id, long long l, long long r){
	long long mid = (l + r) >> 1;
	lazy[id] = 0;
	lazy[id << 1] = 1 - lazy[id << 1];
	lazy[id << 1 | 1] = 1 - lazy[id << 1 | 1];
	seg[id << 1] = mid - l - seg[id << 1];
	seg[id << 1 | 1] = r - mid - seg[id << 1 | 1];
}

bool cmp(long long i, long long j){
	return s[i] < s[j];
}

long long doaz(long long x){
	return x * (x - 1) / 2;
}

void out(){
	cout << ans;
}


#include<bits/stdc++.h>
#define ci const int&
#define Upd(x) (t[x].num=t[x<<1].num+t[x<<1|1].num)
#define Psd(x) (t[x].tg?t[x<<1].tg^=1,t[x<<1].num=t[x<<1].len-t[x<<1].num,t[x<<1|1].tg^=1,t[x<<1|1].num=t[x<<1|1].len-t[x<<1|1].num,t[x].tg=0:0)
using namespace std;
struct Que{
	int l,r,id;
}q[200010];
struct node{
	int l,r,len,num,tg;
}t[400010];
int n,k,sz,u,v,s[100010],d[100010],l,r,mid,ql,qr,nw,tmp;
long long tot=1;
bool cmp(Que x,Que y){
	return x.id<y.id;
}
void Build(ci x,ci l,ci r){
	t[x].l=l,t[x].r=r,t[x].len=r-l+1;
	if(l==r)return;
	int mid=l+r>>1;
	Build(x<<1,l,mid),Build(x<<1|1,mid+1,r);
}
void Change(ci x,ci l,ci r){
	if(t[x].r<l||t[x].l>r)return;
	if(l<=t[x].l&&t[x].r<=r)return(void)(t[x].tg^=1,t[x].num=t[x].len-t[x].num);
	Psd(x),Change(x<<1,l,r),Change(x<<1|1,l,r),Upd(x);
}
int Query(ci x,ci id){
	if(t[x].l==t[x].r)return t[x].num;
	Psd(x);
	return (t[x].l+t[x].r>>1)>=id?Query(x<<1,id):Query(x<<1|1,id);
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=n-2;i<=n;++i){
		tmp=i;
		if(!(i&1)&&i<n)tmp>>=1;
		if(i%3==0)tmp/=3;
		tot*=tmp;
	}
	for(int i=1;i<=n;++i)scanf("%d",&s[i]);
	sort(s+1,s+n+1),Build(1,1,n);
	while(k--){
		scanf("%d%d",&u,&v);
		l=1,r=n+1;
		while(l<r)mid=l+r>>1,s[mid]>=u?r=mid:l=mid+1;
		ql=l;
		l=0,r=n;
		while(l<r)mid=l+r+1>>1,s[mid]<=v?l=mid:r=mid-1;
		qr=l,q[++sz]=(Que){ql,qr,ql},q[++sz]=(Que){ql,qr,qr+1};
	}
	sort(q+1,q+sz+1,cmp),nw=1;
	for(int i=1;i<=n;++i){
		if(i!=1)Change(1,i-1,i-1);
		while(nw<=sz&&q[nw].id==i)Change(1,q[nw].l,q[nw].r),++nw;
		tmp=t[1].num-Query(1,i),tot-=(1ll*tmp*(tmp-1)>>1ll);
	}
	printf("%I64d",tot);
	return 0;
}


//In the name of ALLAH
//Cow Tennis Tournament - 283E
//segment tree + sweep line [)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

#define err(x) cout << #x << ":" << x << '\n';
typedef long long llint;
const int N = 100010;

int n, s[N], o[N<<2], z[N<<2];
bool lazy[N<<2];
vector<int> st[N], en[N];
int qx[N], qy[N];

inline void shift(int i,int lo,int hi){
	int c1 = i<<1, c2 = c1|1;
	lazy[c1] ^= 1;
	swap(o[c1], z[c1]);
	lazy[c2] ^= 1;
	swap(o[c2], z[c2]);
	lazy[i] = 0;
}

inline void flip(int i,int lo,int hi,int ql,int qr){
	if (hi <= ql || qr <= lo) return;
	if (ql <= lo && hi <= qr){
		lazy[i] ^= 1;
		swap(o[i], z[i]);
		return;
	}
	int mid = lo + hi >> 1, c1 = i<<1, c2 = c1|1;
	if (lazy[i])
		shift(i,lo,hi);
	flip(c1,lo,mid,ql,qr);
	flip(c2,mid,hi,ql,qr);
	o[i] = o[c1] + o[c2];
	z[i] = z[c1] + z[c2];
}

inline int ask(int i,int lo,int hi,int ql,int qr){
	if (hi <= ql || qr <= lo) return 0;
	if (ql <= lo && hi <= qr)
		return o[i];
	if (lazy[i])
		shift(i,lo,hi);
	int mid = lo + hi >> 1;
	return ask(i << 1, lo, mid, ql, qr) + ask(i << 1 | 1, mid, hi, ql, qr);
}

inline void build(int i,int lo,int hi){
	if (lo + 1 == hi){
		z[i] = 1;
		return;
	}
	int mid = lo + hi >> 1;
	build(i << 1, lo, mid);
	build(i << 1 | 1, mid, hi);
	z[i] = hi - lo;
}

int main(){
	int k;
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;i++)
		scanf("%d",s+i);
	sort(s,s+n);
	int x,y;
	while (k--){
		scanf("%d%d",&x,&y);
		qx[k] = lower_bound(s,s+n,x) - s;
		qy[k] = upper_bound(s,s+n,y) - s;
		st[qx[k]].push_back(k);
		en[qy[k]].push_back(k);
	}

	build(1,0,n);
	llint ans = (llint)n * (n-1) * (n-2) / 6LL, bad = 0;
	llint win, r, s, lose;
	for (int i=0;i<n;i++){
		for (int u:st[i])
			if (qx[u] < qy[u])
				flip(1,0,n,qx[u],qy[u]);
		for (int u:en[i])
			if (qx[u] < qy[u])
				flip(1,0,n,qx[u],qy[u]);
		r = s = 0;
		if (i) r = ask(1,0,n,0,i);
		if (i < n-1) s = ask(1,0,n,i+1,n);
		win = i-r + s;
		lose = r + (n-i-1 - s);
		bad += win * (win-1) >> 1LL;
		//bad += lose * (lose-1) >> 1LL;
	}
	cout << ans - bad << '\n';

	return 0;
}


//In the name of ALLAH
//Cow Tennis Tournament - 283E
//segment tree + sweep line [)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

#define err(x) cout << #x << ":" << x << '\n';
typedef long long llint;
const int N = 100010;

int n, s[N], o[N<<2], z[N<<2];
bool lazy[N<<2];
vector<int> st[N], en[N];
int qx[N], qy[N];

inline void shift(int i,int lo,int hi){
	int c1 = i<<1, c2 = c1|1;
	lazy[c1] ^= 1;
	swap(o[c1], z[c1]);
	lazy[c2] ^= 1;
	swap(o[c2], z[c2]);
	lazy[i] = 0;
}

inline void flip(int i,int lo,int hi,int ql,int qr){
	if (hi <= ql || qr <= lo) return;
	if (ql <= lo && hi <= qr){
		lazy[i] ^= 1;
		swap(o[i], z[i]);
		return;
	}
	int mid = lo + hi >> 1, c1 = i<<1, c2 = c1|1;
	if (lazy[i])
		shift(i,lo,hi);
	flip(c1,lo,mid,ql,qr);
	flip(c2,mid,hi,ql,qr);
	o[i] = o[c1] + o[c2];
	z[i] = z[c1] + z[c2];
}

inline int ask(int i,int lo,int hi,int ql,int qr){
	if (hi <= ql || qr <= lo) return 0;
	if (ql <= lo && hi <= qr)
		return o[i];
	if (lazy[i])
		shift(i,lo,hi);
	int mid = lo + hi >> 1;
	return ask(i << 1, lo, mid, ql, qr) + ask(i << 1 | 1, mid, hi, ql, qr);
}

inline void build(int i,int lo,int hi){
	if (lo + 1 == hi){
		z[i] = 1;
		return;
	}
	int mid = lo + hi >> 1;
	build(i << 1, lo, mid);
	build(lo << 1 | 1, mid, hi);
	z[i] = hi - lo;
}

int main(){
	int k;
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;i++)
		scanf("%d",s+i);
	sort(s,s+n);
	int x,y;
	while (k--){
		scanf("%d%d",&x,&y);
		qx[k] = lower_bound(s,s+n,x) - s;
		qy[k] = upper_bound(s,s+n,y) - s;
		st[qx[k]].push_back(k);
		en[qy[k]].push_back(k);
	}

	build(1,0,n);
	llint ans = (llint)n * (n-1) * (n-2) / 6LL;
	llint win, r, s;
	for (int i=0;i<n;i++){
		for (int u:st[i])
			if (qx[u] < qy[u])
				flip(1,0,n,qx[u],qy[u]);
		for (int u:en[i])
			if (qx[u] < qy[u])
				flip(1,0,n,qx[u],qy[u]);
		r = s = 0;
		if (i) r = ask(1,0,n,0,i);
		if (i < n-1) s = ask(1,0,n,i+1,n);
		win = i-r + s;
		ans -= win * (win-1) >> 1LL;
	}
	cout << (llint)n * (n-1) * (n-2) / 6LL - ans << '\n';

	return 0;
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

#define l first
#define r second

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

struct node {
    int val, flag;
    int a,b;
    node *l,*r;

    node(int a, int b): a(a), b(b), l(0), r(0), val(0), flag(0) {}

    void push() {
        if (flag) {
            if (l) l->flag = !l->flag;
            if (r) r->flag = !r->flag;
            flag = 0;
            val = b-a-val;
        }
    }

    void pull() {
        val = 0;
        if (l) val += l->eval();
        if (r) val += r->eval();
    }

    int eval() {
        push();
        return val;
    }
};

struct lazy {
    node *root;

    void init(int n) {
        root = build(0,n);
    }

    node* build(int a, int b) {
        node *res = new node(a,b);
        if (a+1 == b) return res;
        else {
            int m = (a+b)/2;
            res->l = build(a,m);
            res->r = build(m,b);
            res->pull();
            return res;
        }
    }

    void update(node *x, int a, int b) {
        if (a <= x->a && x->b <= b) return void(x->flag = !x->flag);
        if (b <= x->a || x->b <= a) return;
        x->push();
        update(x->l, a, b);
        update(x->r, a, b);
        x->pull();
    }
    void update(int a, int b) { update(root,a,b); }

    int get(node *x, int a, int b) {
        if (a <= x->a && x->b <= b) return x->eval();
        if (b <= x->a || x->b <= a) return 0;
        int res = 0;
        x->push();
        res += get(x->l, a, b);
        res += get(x->r, a, b);
        x->pull();
        return res;
    }

    int ones(int a, int b) { return get(root,a,b); }
    int zeros(int a, int b) { return b-a-ones(a,b); }

};

const int N = 1e5 + 100;

int n, s[N], lose[N];
bool open[N], close[N];
pii sw[N];

int main() {
    int k; scanf("%d %d", &n, &k);
    forn(i,n) scanf("%d", s+i);
    sort(s, s+n);
    forn(i,k) {
        int a,b; scanf("%d %d", &a, &b);
        a = lower_bound(s, s+n, a) - s;
        b = upper_bound(s, s+n, b) - s;
        open[a] = !open[a];
        close[b] = !close[b];
        sw[i] = {a,b};
    }

    sort(sw, sw+k, [&](pii x, pii y) { return x.r < y.r; });
    lazy st;
    {
        int ind = 0;
        st.init(n+2);
        forn(i,n) {
            while (ind < k && sw[ind].r <= i) st.update(sw[ind++].l, n);
            if (open[i]) st.update(i,n);

            lose[i] += st.ones(0,i);
        }
    }

    sort(sw, sw+k, [&](pii x, pii y) { return x.l < y.l; });
    {
        st.init(n+2);
        int ind = k-1;
        dforsn(i,0,n) {
            while (ind >= 0 && sw[ind].l > i) st.update(0, sw[ind--].r);
            if (close[i+1]) st.update(0,i+1);
            lose[i] += st.zeros(i+1,n);
        }
    }

    ll res = (ll) n * (n-1) * (n-2) / 6;
    forn(i,n) res -= lose[i] * ll(lose[i]-1) / 2;
    printf("%lld\n", res);

    return 0;
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

#define l first
#define r second

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

struct node {
    int val, flag;
    int a,b;
    node *l,*r;

    node(int a, int b): a(a), b(b), l(0), r(0), val(0), flag(0) {}

    void push() {
        if (flag) {
            if (l) l->flag = !l->flag;
            if (r) r->flag = !r->flag;
            flag = 0;
            val = b-a-val;
        }
    }

    void pull() {
        val = 0;
        if (l) val += l->eval();
        if (r) val += r->eval();
    }

    int eval() {
        push();
        return val;
    }
};

struct lazy {
    node *root;

    void init(int n) {
        root = build(0,n);
    }

    node* build(int a, int b) {
        node *res = new node(a,b);
        if (a+1 == b) return res;
        else {
            int m = (a+b)/2;
            res->l = build(a,m);
            res->r = build(m,b);
            res->pull();
            return res;
        }
    }

    void update(node *x, int a, int b) {
        if (a <= x->a && x->b <= b) return void(x->flag = !x->flag);
        if (b <= x->a || x->b <= a) return;
        x->push();
        update(x->l, a, b);
        update(x->r, a, b);
        x->pull();
    }
    void update(int a, int b) { update(root,a,b); }

    int get(node *x, int a, int b) {
        if (a <= x->a && x->b <= b) return x->eval();
        if (b <= x->a || x->b <= a) return 0;
        int res = 0;
        x->push();
        res += get(x->l, a, b);
        res += get(x->r, a, b);
        x->pull();
        return res;
    }

    int ones(int a, int b) { return get(root,a,b); }
    int zeros(int a, int b) { return b-a-ones(a,b); }

};

const int MOD = 1e9 + 7;
const int INV2 = MOD/2 + 1;
const int INV6 = 166666668;

const int N = 1e5 + 100;

int n, s[N], lose[N];
bool open[N], close[N];
pii sw[N];

int comb2(ll n) {
    return n*(n-1)/2%MOD;
}

int main() {
    int k; scanf("%d %d", &n, &k);
    forn(i,n) scanf("%d", s+i);
    sort(s, s+n);
    forn(i,k) {
        int a,b; scanf("%d %d", &a, &b);
        a = lower_bound(s, s+n, a) - s;
        b = upper_bound(s, s+n, b) - s;
        open[a] = !open[a];
        close[b] = !close[b];
        sw[i] = {a,b};
    }

    sort(sw, sw+k, [&](pii x, pii y) { return x.r < y.r; });
    lazy st;
    {
        int ind = 0;
        st.init(n+2);
        forn(i,n) {
            while (ind < k && sw[ind].r <= i) st.update(sw[ind++].l, n);
            if (open[i]) st.update(i,n);

            lose[i] += st.ones(0,i);
        }
    }

    sort(sw, sw+k, [&](pii x, pii y) { return x.l < y.l; });
    {
        st.init(n+2);
        int ind = k-1;
        dforsn(i,0,n) {
            while (ind >= 0 && sw[ind].l > i) st.update(0, sw[ind--].r);
            if (close[i+1]) st.update(0,i+1);
            lose[i] += st.zeros(i+1,n);
        }
    }

    ll res = (ll) n * (n-1) % MOD * (n-2) % MOD * INV6 % MOD;
    forn(i,n) {
        res -= (ll) lose[i] * (lose[i] - 1) % MOD * INV2 % MOD;
    }
    res %= MOD; if (res < 0) res += MOD;
    printf("%d\n", (int) res);

    return 0;
}


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

#define ll long long
using namespace std;

const int MAXN = 1e5+10;

int n,k,cow[MAXN],sum[MAXN<<2];
ll ans,lz[MAXN<<2];

vector <int> backdo[MAXN];

struct qujian{
	int x,y;
	bool operator < (const qujian & b) const{
		if(x == b.x) return y < b.y;
		return x < b.x;
	}
}t[MAXN];

void build(int o,int l,int r){
	if(l ==  r) return;
	int mid = l+r>>1;
	build(o<<1,l,mid);
	build(o<<1|1,mid+1,r);
}

void pushdown(int o,int l,int r){
	if(lz[o]){
		lz[o<<1] ^=1;
		lz[o<<1|1] ^= 1;
		int mid = l + r>>1;
		sum[o<<1] = mid - l + 1 -sum[o<<1];
		sum[o<<1|1] = r - mid - sum[o<<1|1];
		lz[o] = 0;
	}
}

void update(int o,int l,int r,int xl,int xr){
	if(xl <= l && r <= xr){
		lz[o] ^= 1;
		sum[o] = r - l + 1 -sum[o];
		return;
	}
	if(xl > r|| xr < l) return;
	pushdown(o,l,r);
	int mid = l + r>>1;
	update(o<<1,l,mid,xl,xr);
	update(o<<1|1,mid+1,r,xl,xr);
	sum[o] = sum[o<<1]+sum[o<<1|1];
	return;
}

int query(int o,int l,int r,int xl,int xr){
	if(xl <= l && r <= xr) return sum[o];
	if(xl > r || xr < l) return 0;
	pushdown(o,l,r);
	int mid = l + r>>1;
	int val = 0 ;
	val += query(o<<1,l,mid,xl,xr);
	val += query(o<<1|1,mid+1,r,xl,xr);
	return val;
}

int main (){
	scanf("%d %d",&n,&k);
	for(int i = 1;i <= n;i++) scanf("%d",&cow[i]);
	sort(cow+1,cow+n+1);
	cow[n+1] = 1e9;
	build(1,1,n);
	ans = (ll)n *(n-1)*(n-2) / 6;
	for(int i = 0;i < k;i++) {
		int x,y;
		scanf("%d %d",&x,&y);
		t[i].x = lower_bound(cow+1,cow+n+1,x) - cow;
		t[i].y = upper_bound(cow+1,cow+n+2,y) - cow - 1;
//		cout << t[i].x << ".."<<t[i].y<<endl;
		if(t[i].x > t[i].y) t[i].x = 1e9,t[i].y = 1e9;
	}
	sort(t+0,t+k);
	int now = 0;
	for(int i = 1;i <= n;i++){
		while(t[now].x == i && now <= k) update(1,1,n,t[now].x,t[now].y),backdo[t[now].y].push_back(t[now].x),now++;
		ll beat = 0;
		if(i > 1)beat += query(1,1,n,1,i-1);
		if(i < n)beat += n - i - query(1,1,n,i+1,n);
		ans -= beat * (beat-1) /2;
//		cout <<beat<<".."<< ans<<endl;
		for(int j = 0;j < backdo[i].size();j++) update(1,1,n,backdo[i][j],i);
	}
	cout << ans << endl;
	return 0;
}


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

#define ll long long
using namespace std;

const int MAXN = 1e5+10;

int n,k,cow[MAXN],sum[MAXN];
ll ans,lz[MAXN];

vector <int> backdo[MAXN];

struct qujian{
	int x,y;
	bool operator < (const qujian & b) const{
		if(x == b.x) return y < b.y;
		return x < b.x;
	}
}t[MAXN];

void build(int o,int l,int r){
	if(l ==  r) return;
	int mid = l+r>>1;
	build(o<<1,l,mid);
	build(o<<1|1,mid+1,r);
}

void pushdown(int o,int l,int r){
	if(lz[o]){
		lz[o<<1] ^=1;
		lz[o<<1|1] ^= 1;
		int mid = l + r>>1;
		sum[o<<1] = mid - l + 1 -sum[o<<1];
		sum[o<<1|1] = r - mid - sum[o<<1|1];
		lz[o] = 0;
	}
}

void update(int o,int l,int r,int xl,int xr){
	if(xl <= l && r <= xr){
		lz[o] ^= 1;
		sum[o] = r - l + 1 -sum[o];
		return;
	}
	if(xl > r|| xr < l) return;
	pushdown(o,l,r);
	int mid = l + r>>1;
	update(o<<1,l,mid,xl,xr);
	update(o<<1|1,mid+1,r,xl,xr);
	sum[o] = sum[o<<1]+sum[o<<1|1];
	return;
}

int query(int o,int l,int r,int xl,int xr){
	if(xl <= l && r <= xr) return sum[o];
	if(xl > r || xr < l) return 0;
	pushdown(o,l,r);
	int mid = l + r>>1;
	int val = 0 ;
	val += query(o<<1,l,mid,xl,xr);
	val += query(o<<1|1,mid+1,r,xl,xr);
	return val;
}

int main (){
	scanf("%d %d",&n,&k);
	for(int i = 1;i <= n;i++) scanf("%d",&cow[i]);
	sort(cow+1,cow+n+1);
	cow[n+1] = 1e9;
	build(1,1,n);
	ans = (ll)n *(n-1)*(n-2) / 6;
	for(int i = 0;i < k;i++) {
		int x,y;
		scanf("%d %d",&x,&y);
		t[i].x = lower_bound(cow+1,cow+n+1,x) - cow;
		t[i].y = upper_bound(cow+1,cow+n+2,y) - cow - 1;
//		cout << t[i].x << ".."<<t[i].y<<endl;
		if(t[i].x > t[i].y) t[i].x = 1e9,t[i].y = 1e9;
	}
	sort(t+0,t+k);
	int now = 0;
	for(int i = 1;i <= n;i++){
		while(t[now].x == i && now <= k) update(1,1,n,t[now].x,t[now].y),backdo[t[now].y].push_back(t[now].x),now++;
		ll beat = 0;
		if(i > 1)beat += query(1,1,n,1,i-1);
		if(i < n)beat += n - i - query(1,1,n,i+1,n);
		ans -= beat * (beat-1) /2;
//		cout <<beat<<".."<< ans<<endl;
		for(int j = 0;j < backdo[i].size();j++) update(1,1,n,backdo[i][j],i);
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+9;
int l,r,n,k,seg[MAX*4],lz[MAX*4],a[MAX];
long long ans,t;
vector<pair<int,int> > o[MAX];
void shift(int s,int e,int m,int id)
{
	if (lz[id])
	{
		lz[id*2+1]^=1,lz[id*2+2]^=1;
		seg[id*2+1]=m-s-seg[id*2+1];
		seg[id*2+2]=e-m-seg[id*2+2];
		lz[id]^=1;
	}
}
void upd(int l,int r,int s=0,int e=n,int id=0)
{
	if (r<=s || e<=l) return ;
	if (l<=s && e<=r){seg[id]=e-s-seg[id],lz[id]^=1;return ;}
	int mid=s+e>>1;
	shift(s,e,mid,id);
	upd(l,r,s,mid,id*2+1),upd(l,r,mid,e,id*2+2);
	seg[id]=seg[id*2+1]+seg[id*2+2];
}
int get(int l,int r,int s=0,int e=n,int id=0)
{
	if (r<=s || e<=l) return 0;
	if (l<=s && e<=r) return seg[id];
	int mid=s+e>>1;
	shift(s,e,mid,id);
	return get(l,r,s,mid,id*2+1)+get(l,r,mid,e,id*2+2);
}
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>k,ans=-1LL*n*(n-2)*(n-1)/6;
	for (int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for (int i=0;i<k;i++)
		cin>>l>>r,l=lower_bound(a,a+n,l)-a,r=upper_bound(a,a+n,r)-a,o[l].push_back({l,r}),o[r].push_back({l,r});
	for (int i=0;i<n;i++)
	{
		for (auto j:o[i]) upd(j.first,j.second);
		if (i) upd(i-1,i);
		t=get(0,n);
		if (get(i,i+1)) t--;
		ans+=t*(n-t-1);
	}
	cout<<ans/2;
	return 0;
}


#include<bits/stdc++.h>
#define lp long long
using namespace std;
const lp ml=2e5+10;
struct wxz{
	lp l,r;
	lp sum,add;
}t[ml];
lp n,m;
lp a[ml],b[ml];
lp ans;
lp inline read(){
   lp r=0,f=1;
   char c=getchar();
   while(c<'0'||c>'9'){if(c=='-')f=-12;c=getchar();}
   while(c>='0'&&c<='9')r=(r<<1)+(r<<3)+(c^48),c=getchar();
   return r*f;
}
vector < lp > a1[ml],a2[ml];
void spread(lp bh){
	if(t[bh].add==1){
		t[bh].add=0;
		t[bh<<1].sum=t[bh<<1].r-t[bh<<1].l+1-t[bh<<1].sum;
		t[bh<<1|1].sum=t[bh<<1|1].r-t[bh<<1|1].l+1-t[bh<<1|1].sum;
		t[bh<<1].add^=1;
		t[bh<<1|1].add^=1;
	}
}
void build(lp l,lp r,lp bh){
	t[bh].l=l,t[bh].r=r;
	if(l==r)return;
	lp mid=(l+r)>>1;
	build(l,mid,bh<<1);
	build(mid+1,r,bh<<1|1);
}
void change(lp l,lp r,lp bh){
	if(l<=t[bh].l&&r>=t[bh].r){t[bh].add^=1;t[bh].sum=t[bh].r-t[bh].l+1-t[bh].sum;return;}
	lp mid=(t[bh].l+t[bh].r)>>1;
	spread(bh);
	if(l<=mid)change(l,r,bh<<1);
	if(r>mid)change(l,r,bh<<1|1);
	t[bh].sum=t[bh<<1].sum+t[bh<<1|1].sum;
}
lp ask(lp l,lp r,lp bh){
	if(l<=t[bh].l&&r>=t[bh].r)return t[bh].sum;
	lp mid=(t[bh].l+t[bh].r)>>1,res=0;
	spread(bh);
	if(l<=mid)res+=ask(l,r,bh<<1);
	if(r>mid)res+=ask(l,r,bh<<1|1);
	return res;
}
int main()
{
	n=read(),m=read();
	for(lp i=1;i<=n;i++)a[i]=read(),b[i]=a[i];
	sort(b+1,b+1+n);
	for(lp i=1;i<=m;i++){
		lp x=read(),y=read();
		lp k1=lower_bound(b+1,b+1+n,x)-b,k2=upper_bound(b+1,b+1+n,y)-b-1;
		a1[k1].push_back(k2);
		a2[k2+1].push_back(k1);
	}
	ans=n*(n-1)*(n-2)/6;
	build(1,n,1);
	for(lp i=1;i<=n;i++){
		for(lp j=0;j<a1[i].size();j++)change(i,a1[i][j],1);
		for(lp j=0;j<a2[i].size();j++)change(a2[i][j],i-1,1);
		lp kp=0;
		if(i>1)kp+=i-1-ask(1,i-1,1);
		if(i<n)kp+=ask(i+1,n,1);
		ans-=kp*(kp-1)/2;
	}
	cout<<ans;
return 0;
}